Java Code Examples for io.reactivex.observers.TestObserver#assertComplete()

The following examples show how to use io.reactivex.observers.TestObserver#assertComplete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoAccessTokenRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFindToken() {
    AccessToken token = new AccessToken();
    token.setId(RandomString.generate());
    token.setToken("my-token");

    TestObserver<AccessToken> observer = accessTokenRepository
            .create(token)
            .toCompletable()
            .andThen(accessTokenRepository.findByToken("my-token"))
            .test();

    observer.awaitTerminalEvent();

    observer.assertComplete();
    observer.assertValueCount(1);
    observer.assertNoErrors();
}
 
Example 2
Source File: MongoOrganizationRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() {
    Organization organization = new Organization();
    organization.setName("testName");
    Organization organizationCreated = organizationRepository.create(organization).blockingGet();

    Organization organizationUpdated = new Organization();
    organizationUpdated.setId(organizationCreated.getId());
    organizationUpdated.setName("testNameUpdated");

    TestObserver<Organization> obs = organizationRepository.update(organizationUpdated).test();
    obs.awaitTerminalEvent();

    obs.assertComplete();
    obs.assertNoErrors();
    obs.assertValue(o -> o.getName().equals(organizationUpdated.getName()) && o.getId().equals(organizationCreated.getId()));
}
 
Example 3
Source File: IdentityProviderServiceTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreate() {
    NewIdentityProvider newIdentityProvider = Mockito.mock(NewIdentityProvider.class);
    IdentityProvider idp = new IdentityProvider();
    idp.setReferenceType(ReferenceType.DOMAIN);
    idp.setReferenceId("domain#1");
    when(identityProviderRepository.create(any(IdentityProvider.class))).thenReturn(Single.just(idp));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));

    TestObserver testObserver = identityProviderService.create(DOMAIN, newIdentityProvider).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();

    verify(identityProviderRepository, times(1)).create(any(IdentityProvider.class));
    verify(eventService, times(1)).create(any());
}
 
Example 4
Source File: MongoResourceRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindByDomainAndClientAndUserAndResources() throws TechnicalException {
    // create resource_set, resource_scopes being the most important field.
    Resource resource1 = new Resource().setResourceScopes(Arrays.asList("a")).setDomain(DOMAIN_ID).setClientId(CLIENT_ID).setUserId(USER_ID);
    Resource resource2 = new Resource().setResourceScopes(Arrays.asList("b")).setDomain(DOMAIN_ID).setClientId(CLIENT_ID).setUserId(USER_ID);
    Resource resource3 = new Resource().setResourceScopes(Arrays.asList("c")).setDomain("another").setClientId(CLIENT_ID).setUserId(USER_ID);
    Resource resource4 = new Resource().setResourceScopes(Arrays.asList("d")).setDomain(DOMAIN_ID).setClientId("another").setUserId(USER_ID);
    Resource resource5 = new Resource().setResourceScopes(Arrays.asList("d")).setDomain(DOMAIN_ID).setClientId(CLIENT_ID).setUserId("another");

    Resource rsCreated1 = repository.create(resource1).blockingGet();
    Resource rsCreated2 = repository.create(resource2).blockingGet();
    Resource rsCreated3 = repository.create(resource3).blockingGet();
    Resource rsCreated4 = repository.create(resource4).blockingGet();
    Resource rsCreated5 = repository.create(resource5).blockingGet();

    // fetch applications
    TestObserver<List<Resource>> testObserver = repository.findByDomainAndClientAndResources(DOMAIN_ID, CLIENT_ID, Arrays.asList(
            rsCreated1.getId(),rsCreated2.getId(),rsCreated3.getId(),rsCreated4.getId(),rsCreated5.getId(),"unknown"
    )).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(resources -> resources.size() == 3);
}
 
Example 5
Source File: UserServiceTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldResetPassword_externalIdEmpty() {
    final String domain = "domain";
    final String password = "password";

    User user = mock(User.class);
    when(user.getId()).thenReturn("user-id");
    when(user.getUsername()).thenReturn("username");
    when(user.getSource()).thenReturn("default-idp");

    io.gravitee.am.identityprovider.api.User idpUser = mock(io.gravitee.am.identityprovider.api.DefaultUser.class);
    when(idpUser.getId()).thenReturn("idp-id");

    UserProvider userProvider = mock(UserProvider.class);
    when(userProvider.findByUsername(user.getUsername())).thenReturn(Maybe.just(idpUser));
    when(userProvider.update(anyString(), any())).thenReturn(Single.just(idpUser));

    when(commonUserService.findById(eq(ReferenceType.DOMAIN), eq(domain), eq("user-id"))).thenReturn(Single.just(user));
    when(identityProviderManager.getUserProvider(user.getSource())).thenReturn(Maybe.just(userProvider));
    when(commonUserService.update(any())).thenReturn(Single.just(user));
    when(loginAttemptService.reset(any())).thenReturn(Completable.complete());

    TestObserver testObserver = userService.resetPassword(domain, user.getId(), password).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
}
 
Example 6
Source File: JWKServiceTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGetJWKSet_multipleKeys() {
    io.gravitee.am.model.jose.JWK key = new io.gravitee.am.model.jose.RSAKey();
    key.setKid("my-test-key");
    io.gravitee.am.model.jose.JWK key2 = new io.gravitee.am.model.jose.RSAKey();
    key.setKid("my-test-key-2");

    CertificateProvider certificateProvider = mock(CertificateProvider.class);
    when(certificateProvider.keys()).thenReturn(Flowable.just(key));
    CertificateProvider certificateProvider2 = mock(CertificateProvider.class);
    when(certificateProvider2.keys()).thenReturn(Flowable.just(key2));

    List<io.gravitee.am.gateway.certificate.CertificateProvider> certificateProviders = new ArrayList<>();
    certificateProviders.add(new io.gravitee.am.gateway.certificate.CertificateProvider(certificateProvider));
    certificateProviders.add(new io.gravitee.am.gateway.certificate.CertificateProvider(certificateProvider2));

    when(certificateManager.providers()).thenReturn(certificateProviders);

    TestObserver<JWKSet> testObserver = jwkService.getKeys().test();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(jwkSet -> jwkSet.getKeys().size() == 2);
}
 
Example 7
Source File: RxFirebaseUserTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendEmailVerification() {
    mockSuccessfulVoidResult();
    when(mockFirebaseUser.sendEmailVerification())
            .thenReturn(mockVoidTaskResult);

    TestObserver obs = TestObserver.create();

    RxFirebaseUser.sendEmailVerification(mockFirebaseUser)
            .subscribe(obs);

    callOnComplete(mockVoidTaskResult);
    obs.dispose();

    obs.assertComplete();
}
 
Example 8
Source File: MongoIdentityProviderRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void testDelete() throws TechnicalException {
    // create idp
    IdentityProvider identityProvider = new IdentityProvider();
    identityProvider.setName("testName");
    IdentityProvider identityProviderCreated = identityProviderRepository.create(identityProvider).blockingGet();

    // fetch idp
    TestObserver<IdentityProvider> testObserver = identityProviderRepository.findById(identityProviderCreated.getId()).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(idp -> idp.getName().equals(identityProvider.getName()));

    // delete idp
    TestObserver testObserver1 = identityProviderRepository.delete(identityProviderCreated.getId()).test();
    testObserver1.awaitTerminalEvent();

    // fetch idp
    identityProviderRepository.findById(identityProviderCreated.getId()).test().assertEmpty();
}
 
Example 9
Source File: RxFirebaseAuthTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignInWithCredential() {
    mockSuccessfulAuthResult();

    when(mockFirebaseAuth.signInWithCredential(mockAuthCredential))
            .thenReturn(mockAuthResultTask);

    TestObserver<FirebaseUser> obs = TestObserver.create();

    RxFirebaseAuth
            .signInWithCredential(mockFirebaseAuth, mockAuthCredential)
            .subscribe(obs);

    callOnComplete(mockAuthResultTask);
    obs.dispose();

    // Ensure no more values are emitted after unsubscribe
    callOnComplete(mockAuthResultTask);

    obs.assertComplete();
    obs.assertValueCount(1);
}
 
Example 10
Source File: OnErrorRetryIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenSubscriberAndError_whenRetryWhenOnError_thenResubscribed() {
    TestObserver<String> testObserver = new TestObserver<>();
    AtomicInteger atomicCounter = new AtomicInteger(0);

    Observable
      .<String>error(() -> {
          atomicCounter.incrementAndGet();
          return UNKNOWN_ERROR;
      })
      .retryWhen(throwableObservable -> Observable.just("anything"))
      .subscribe(testObserver);

    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertNoValues();
    assertTrue("should retry once", atomicCounter.get() == 1);
}
 
Example 11
Source File: WalletRepoTest.java    From ETHWallet with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetBalance() {
    importAccount(STORE_1, PASS_1);
    TestObserver<BigInteger> subscriber = accountRepository
            .balanceInWei(new Wallet(ADDRESS_1))
            .test();
    subscriber.awaitTerminalEvent();
    subscriber.assertComplete();
    Log.d("BALANCE", subscriber.values().get(0).toString());
    deleteAccount(ADDRESS_1, PASS_1);
}
 
Example 12
Source File: MongoApplicationRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindById() throws TechnicalException {
    // create app
    Application app = new Application();
    app.setName("testClientId");
    Application appCreated = applicationRepository.create(app).blockingGet();

    // fetch app
    TestObserver<Application> testObserver = applicationRepository.findById(appCreated.getId()).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(a -> a.getName().equals("testClientId"));
}
 
Example 13
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void delete() {
    TestObserver<Client> testObserver = dcrService.delete(new Client()).test();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    verify(clientService, times(1)).delete(any());
}
 
Example 14
Source File: JWTServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
private void testEncodeUserinfo(String algorithm, String clientCertificate, String expectedResult) {
    Client client = new Client();
    client.setUserinfoSignedResponseAlg(algorithm);
    client.setCertificate(clientCertificate);

    TestObserver testObserver = jwtService.encodeUserinfo(new JWT(), client).test();
    testObserver.assertComplete();
    testObserver.assertValue(o -> o.equals(expectedResult));
}
 
Example 15
Source File: ScopeServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUpdateSystemScope() {
    UpdateSystemScope updateScope = new UpdateSystemScope();
    updateScope.setDiscovery(true);
    updateScope.setName("name");

    final String scopeId = "toUpdateId";

    Scope toUpdate = new Scope();
    toUpdate.setId(scopeId);
    toUpdate.setSystem(true);
    toUpdate.setDiscovery(false);
    toUpdate.setName("oldName");
    toUpdate.setDescription("oldDescription");

    ArgumentCaptor<Scope> argument = ArgumentCaptor.forClass(Scope.class);

    when(scopeRepository.findById(scopeId)).thenReturn(Maybe.just(toUpdate));
    when(scopeRepository.update(argument.capture())).thenReturn(Single.just(new Scope()));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));

    TestObserver testObserver = scopeService.update(DOMAIN,scopeId, updateScope).test();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(scopeRepository, times(1)).update(any(Scope.class));
    assertNotNull(argument.getValue());
    assertEquals("name",argument.getValue().getName());
    assertNull(argument.getValue().getDescription());
    assertTrue(argument.getValue().isDiscovery());
}
 
Example 16
Source File: AuthorizationRequestResolverTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldResolveAuthorizationRequest_noRequestedScope() {
    final String scope = "read";
    final String redirectUri = "http://localhost:8080/callback";
    AuthorizationRequest authorizationRequest = new AuthorizationRequest();
    authorizationRequest.setRedirectUri(redirectUri);
    Client client = new Client();
    client.setScopes(Collections.singletonList(scope));

    TestObserver<AuthorizationRequest> testObserver = authorizationRequestResolver.resolve(authorizationRequest, client, null).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(request -> request.getScopes().iterator().next().equals(scope));
}
 
Example 17
Source File: ApplicationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindByExtensionGrant() {
    when(applicationRepository.findByDomainAndExtensionGrant(DOMAIN, "client-extension-grant")).thenReturn(Single.just(Collections.singleton(new Application())));
    TestObserver<Set<Application>> testObserver = applicationService.findByDomainAndExtensionGrant(DOMAIN, "client-extension-grant").test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(extensionGrants -> extensionGrants.size() == 1);
}
 
Example 18
Source File: EventServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreate() {
    Event newEvent = Mockito.mock(Event.class);
    when(eventRepository.create(any(Event.class))).thenReturn(Single.just(newEvent));

    TestObserver testObserver = eventService.create(newEvent).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();

    verify(eventRepository, times(1)).create(any(Event.class));
}
 
Example 19
Source File: FingerprintAuthenticationTest.java    From RxFingerprint with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthenticationSuccessfulOnSecondTry() throws Exception {
    when(fingerprintApiWrapper.isUnavailable()).thenReturn(false);
    when(fingerprintApiWrapper.getFingerprintManager()).thenReturn(fingerprintManager);

    TestObserver<FingerprintAuthenticationResult> testObserver = observable.test();

    ArgumentCaptor<FingerprintManager.AuthenticationCallback> callbackCaptor = ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
    verify(fingerprintManager).authenticate(any(CryptoObject.class), any(CancellationSignal.class), anyInt(), callbackCaptor.capture(), any(Handler.class));
    callbackCaptor.getValue().onAuthenticationHelp(0, MESSAGE_HELP);

    testObserver.assertNotTerminated();
    testObserver.assertNoErrors();
    testObserver.assertNotComplete();
    testObserver.assertValueCount(1);

    FingerprintAuthenticationResult helpResult = testObserver.values().get(0);
    assertTrue("Authentication should not be successful", !helpResult.isSuccess());
    assertTrue("Result should be equal HELP", helpResult.getResult().equals(FingerprintResult.HELP));
    assertTrue("Should contain help message", helpResult.getMessage().equals(MESSAGE_HELP));

    callbackCaptor.getValue().onAuthenticationSucceeded(mock(AuthenticationResult.class));

    testObserver.awaitTerminalEvent();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValueCount(2);

    FingerprintAuthenticationResult successResult = testObserver.values().get(1);
    assertTrue("Authentication should be successful", successResult.isSuccess());
    assertTrue("Result should be equal AUTHENTICATED", successResult.getResult().equals(FingerprintResult.AUTHENTICATED));
    assertTrue("Should contain no message", successResult.getMessage() == null);
}
 
Example 20
Source File: RxFirebaseStorageTest.java    From rxfirebase with Apache License 2.0 4 votes vote down vote up
@Test public void testDelete() {
  mockSuccessfulResultForTask(mockTask);
  Mockito.when(mockStorageReference.delete()).thenReturn(mockTask);

  TestObserver<byte[]> obs = TestObserver.create();

  RxFirebaseStorage.delete(mockStorageReference).subscribe(obs);

  verifyAddOnCompleteListenerForTask(mockTask);

  callOnComplete(mockTask);
  obs.dispose();

  callOnComplete(mockTask);

  obs.assertNoErrors();
  obs.assertComplete();
}