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

The following examples show how to use io.reactivex.observers.TestObserver#assertNoErrors() . 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: RxFirebaseDatabaseTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveValue() {
    when(mockDatabaseReference.removeValue())
            .thenReturn(mockTask);

    TestObserver sub = TestObserver.create();

    RxFirebaseDatabase.removeValue(mockDatabaseReference)
            .subscribe(sub);

    verifyAddOnCompleteListenerForTask();
    callTaskOnComplete();

    sub.assertComplete();
    sub.assertNoErrors();

    sub.dispose();
}
 
Example 2
Source File: MongoAccessPolicyRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void update() throws TechnicalException {
    AccessPolicy accessPolicy = new AccessPolicy();
    accessPolicy.setName("accessPolicyName");
    AccessPolicy apCreated = repository.create(accessPolicy).blockingGet();

    AccessPolicy toUpdate = new AccessPolicy();
    toUpdate.setId(apCreated.getId());
    toUpdate.setName("accessPolicyUpdatedName");

    TestObserver<AccessPolicy> testObserver = repository.update(toUpdate).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(ap -> ap.getName().equals("accessPolicyUpdatedName"));
}
 
Example 3
Source File: MongoResourceRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindByDomain() throws TechnicalException {
    // create resource_set, resource_scopes being the most important field.
    Resource resource1 = new Resource().setResourceScopes(Arrays.asList("a","b","c")).setDomain(DOMAIN_ID).setClientId(CLIENT_ID).setUserId(USER_ID);
    Resource resource2 = new Resource().setResourceScopes(Arrays.asList("d","e","f")).setDomain(DOMAIN_ID).setClientId(CLIENT_ID).setUserId(USER_ID);

    repository.create(resource1).blockingGet();
    repository.create(resource2).blockingGet();

    // fetch applications
    TestObserver<Page<Resource>> testObserver = repository.findByDomain(DOMAIN_ID, 0, Integer.MAX_VALUE).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(resources -> resources.getData().size() == 2);
}
 
Example 4
Source File: QueryOperatorTest.java    From sqlitemagic with Apache License 2.0 6 votes vote down vote up
@Test
public void runListQueryObservesChanges() {
  final List<Author> expected = new ArrayList<>(6);
  final List<Author> expectedFirst = insertAuthors(3);
  expected.addAll(expectedFirst);
  final TestObserver<List<Author>> ts =
      selectAuthors.observe()
          .runQuery()
          .take(2)
          .test();

  expected.addAll(insertAuthors(3));

  awaitTerminalEvent(ts);
  ts.assertNoErrors();
  ts.assertValues(expectedFirst, expected);
}
 
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_idpUserNotFound() {
    Client client = mock(Client.class);

    User user = mock(User.class);
    when(user.getUsername()).thenReturn("username");
    when(user.isInactive()).thenReturn(false);
    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.empty());
    when(userProvider.create(any())).thenReturn(Single.just(idpUser));

    when(identityProviderManager.getUserProvider(user.getSource())).thenReturn(Maybe.just(userProvider));
    when(commonUserService.update(any())).thenReturn(Single.just(user));
    when(commonUserService.enhance(any())).thenReturn(Single.just(user));
    when(loginAttemptService.reset(any())).thenReturn(Completable.complete());

    TestObserver testObserver = userService.resetPassword(client, user).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(userProvider, times(1)).create(any());
}
 
Example 6
Source File: RxFirebaseAuthTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendPasswordResetEmail() {
    when(mockFirebaseAuth.sendPasswordResetEmail("email"))
            .thenReturn(mockSendPasswordResetEmailTask);

    mockSuccessfulSendPasswordResetEmailResult();

    TestObserver obs = TestObserver.create();

    RxFirebaseAuth
            .sendPasswordResetEmail(mockFirebaseAuth, "email")
            .subscribe(obs);

    callOnComplete(mockSendPasswordResetEmailTask);
    obs.dispose();

    verify(mockFirebaseAuth)
            .sendPasswordResetEmail("email");

    obs.assertNoErrors();
    obs.assertComplete();
}
 
Example 7
Source File: AuthorizationCodeServiceTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreate_noExistingCode() {
    AuthorizationRequest authorizationRequest = new AuthorizationRequest();
    authorizationRequest.setClientId("my-client-id");

    User user = new User();
    user.setUsername("my-username-id");

    when(authorizationCodeRepository.create(any())).thenReturn(Single.just(new AuthorizationCode()));

    TestObserver<AuthorizationCode> testObserver = authorizationCodeService.create(authorizationRequest, user).test();
    testObserver.assertComplete();
    testObserver.assertNoErrors();

    verify(authorizationCodeRepository, times(1)).create(any());
}
 
Example 8
Source File: RxQueryTest.java    From storio with Apache License 2.0 6 votes vote down vote up
@Test
public void queryListOfObjectsAsSingle() {
    final List<User> users = putUsersBlocking(10);

    final Single<List<User>> usersSingle = storIOSQLite
            .get()
            .listOfObjects(User.class)
            .withQuery(UserTableMeta.QUERY_ALL)
            .prepare()
            .asRxSingle();

    TestObserver<List<User>> testObserver = new TestObserver<List<User>>();
    usersSingle.subscribe(testObserver);

    testObserver.awaitTerminalEvent(5, SECONDS);
    testObserver.assertNoErrors();
    testObserver.assertValue(users);
    testObserver.assertComplete();
}
 
Example 9
Source File: RxPermissionsTest.java    From RxPermissions with Apache License 2.0 6 votes vote down vote up
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_severalPermissions_oneRevoked() {
    TestObserver<Permission> sub = new TestObserver<>();
    String[] permissions = new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.CAMERA};
    when(mRxPermissions.isGranted(Matchers.<String>anyVararg())).thenReturn(false);
    when(mRxPermissions.isRevoked(Manifest.permission.CAMERA)).thenReturn(true);

    trigger().compose(mRxPermissions.ensureEach(permissions)).subscribe(sub);
    mRxPermissions.onRequestPermissionsResult(
            new String[]{Manifest.permission.READ_PHONE_STATE},
            new int[]{PackageManager.PERMISSION_GRANTED});

    sub.assertNoErrors();
    sub.assertTerminated();
    sub.assertValues(new Permission(permissions[0], true), new Permission(permissions[1], false));
}
 
Example 10
Source File: MongoScopeRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdate() {
    // create scope
    Scope scope = new Scope();
    scope.setName("testName");
    Scope scopeCreated = scopeRepository.create(scope).blockingGet();

    // update scope
    Scope updatedScope = new Scope();
    updatedScope.setId(scopeCreated.getId());
    updatedScope.setName("testUpdatedName");

    TestObserver<Scope> testObserver = scopeRepository.update(updatedScope).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(s -> s.getName().equals(updatedScope.getName()));
}
 
Example 11
Source File: ApplicationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindAll() {
    when(applicationRepository.findAll(0, Integer.MAX_VALUE)).thenReturn(Single.just(new Page(Collections.singleton(new Application()), 0, 1)));
    TestObserver<Set<Application>> testObserver = applicationService.findAll().test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(extensionGrants -> extensionGrants.size() == 1);
}
 
Example 12
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_defaultIdTokenResponseEncPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setIdTokenEncryptedResponseAlg(Optional.of("RSA-OAEP-256"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValue(client -> defaultAssertion(client) && client.getIdTokenEncryptedResponseEnc()!=null);
}
 
Example 13
Source File: JWKServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetKey_noKFound() {

    JWK jwk = Mockito.mock(JWK.class);
    JWKSet jwkSet = new JWKSet();
    jwkSet.setKeys(Arrays.asList(jwk));

    when(jwk.getKid()).thenReturn("notTheExpectedOne");

    TestObserver testObserver = jwkService.getKey(jwkSet,"expectedKid").test();

    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertResult();//Expect empty result
}
 
Example 14
Source File: MongoFactorRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreate() throws TechnicalException {
    Factor factor = new Factor();
    factor.setName("testName");

    TestObserver<Factor> testObserver = factorRepository.create(factor).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(f -> f.getName().equals(factor.getName()));
}
 
Example 15
Source File: RoleServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUpdate_defaultRolePermissions() {
    UpdateRole updateRole = new UpdateRole();
    updateRole.setName(DefaultRole.DOMAIN_USER.name());
    updateRole.setPermissions(Permission.flatten(Collections.singletonMap(Permission.DOMAIN, Collections.singleton(Acl.READ))));

    Role role = new Role();
    role.setName(DefaultRole.DOMAIN_USER.name());
    role.setDefaultRole(true); // should be able to update a default role.
    role.setReferenceType(ReferenceType.ORGANIZATION);
    role.setReferenceId(ORGANIZATION_ID);

    when(roleRepository.findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role")).thenReturn(Maybe.just(role));
    when(roleRepository.findAll(ReferenceType.ORGANIZATION, ORGANIZATION_ID)).thenReturn(Flowable.empty());
    when(roleRepository.update(argThat(r -> r.getPermissionAcls().equals(Permission.unflatten(updateRole.getPermissions()))))).thenReturn(Single.just(role));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));

    TestObserver testObserver = roleService.update(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role", updateRole, null).test();
    testObserver.awaitTerminalEvent();

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

    verify(roleRepository, times(1)).findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role");
    verify(roleRepository, times(1)).findAll(ReferenceType.ORGANIZATION, ORGANIZATION_ID);
    verify(roleRepository, times(1)).update(any(Role.class));
}
 
Example 16
Source File: MongoOrganizationRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreate() {

    Organization organization = new Organization();
    organization.setName("testName");

    TestObserver<Organization> obs = organizationRepository.create(organization).test();
    obs.awaitTerminalEvent();

    obs.assertComplete();
    obs.assertNoErrors();
    obs.assertValue(o -> o.getName().equals(organization.getName()) && o.getId() != null);
}
 
Example 17
Source File: RxCommandTest.java    From RxCommand with MIT License 5 votes vote down vote up
@Test
public void anErrorOccurredDuringExecution_noValue() {
    final Throwable throwable = new Exception("something wrong");
    RxCommand<String> command = RxCommand.create(o -> Observable.error(throwable));

    TestObserver<String> testObserver = new TestObserver<>();
    command.switchToLatest().subscribe(testObserver);

    command.execute(null);

    testObserver.assertNoValues();
    testObserver.assertNoErrors();
    testObserver.assertNotComplete();
}
 
Example 18
Source File: RxPaperBookTest.java    From RxPaper2 with MIT License 5 votes vote down vote up
@Test
public void testGetPath() throws Exception {
    RxPaperBook book = RxPaperBook.with("PATH", Schedulers.trampoline());
    final TestObserver<String> emptyBookSubscriber = book.getPath().test();
    emptyBookSubscriber.awaitTerminalEvent();
    emptyBookSubscriber.assertNoErrors();
    emptyBookSubscriber.assertValueCount(1);
    final String key = "hello";
    book.write(key, ComplexObject.random()).subscribe();
    final TestObserver<String> foundSubscriber = book.getPath().test();
    foundSubscriber.awaitTerminalEvent();
    foundSubscriber.assertNoErrors();
    foundSubscriber.assertValueCount(1);
}
 
Example 19
Source File: MongoCertificateRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreate() throws TechnicalException {
    Certificate certificate = new Certificate();
    certificate.setName("testName");

    TestObserver<Certificate> testObserver = certificateRepository.create(certificate).test();
    testObserver.awaitTerminalEvent();

    testObserver.assertComplete();
    testObserver.assertNoErrors();
    testObserver.assertValue(domainCreated -> domainCreated.getName().equals(certificate.getName()));
}
 
Example 20
Source File: MongoUserRepositoryTest.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
@Test
public void testSearch_paged() {
    final String domain = "domain";
    // create user
    User user1 = new User();
    user1.setReferenceType(ReferenceType.DOMAIN);
    user1.setReferenceId(domain);
    user1.setUsername("testUsername1");
    userRepository.create(user1).blockingGet();

    User user2 = new User();
    user2.setReferenceType(ReferenceType.DOMAIN);
    user2.setReferenceId(domain);
    user2.setUsername("testUsername2");
    userRepository.create(user2).blockingGet();
    
    User user3 = new User();
    user3.setReferenceType(ReferenceType.DOMAIN);
    user3.setReferenceId(domain);
    user3.setUsername("testUsername3");
    userRepository.create(user3).blockingGet();

    // fetch user (page 0)
    TestObserver<Page<User>> testObserverP0 = userRepository.search(domain, "testUsername*", 0, 2).test();
    testObserverP0.awaitTerminalEvent();
    
    testObserverP0.assertComplete();
    testObserverP0.assertNoErrors();
    testObserverP0.assertValue(users -> users.getData().size() == 2);
    testObserverP0.assertValue(users -> {
    	Iterator<User> it = users.getData().iterator();
    	return it.next().getUsername().equals(user1.getUsername()) && it.next().getUsername().equals(user2.getUsername());
    });
    
    // fetch user (page 1)
    TestObserver<Page<User>> testObserverP1 = userRepository.search(domain, "testUsername*", 1, 2).test();
    testObserverP1.awaitTerminalEvent();
    
    testObserverP1.assertComplete();
    testObserverP1.assertNoErrors();
    testObserverP1.assertValue(users -> users.getData().size() == 1);
    testObserverP1.assertValue(users -> users.getData().iterator().next().getUsername().equals(user3.getUsername()));
}