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

The following examples show how to use io.reactivex.observers.TestObserver#assertNotComplete() . 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: TokenRequestResolverTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotResolveTokenRequest_invalidScope_withUser() {
    final String scope = "read";
    TokenRequest tokenRequest = new TokenRequest();
    tokenRequest.setScopes(Collections.singleton(scope));
    Client client = new Client();
    client.setScopes(Collections.singletonList("write"));

    User user = new User();
    Role role = new Role();
    role.setOauthScopes(Collections.singletonList("user"));
    user.setRolesPermissions(Collections.singleton(role));

    TestObserver<TokenRequest> testObserver = tokenRequestResolver.resolve(tokenRequest, client, user).test();
    testObserver.assertNotComplete();
    testObserver.assertError(InvalidScopeException.class);
}
 
Example 2
Source File: OnErrorRetryIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenSubscriberAndError_whenRetryConditionallyOnError_thenRetryConfirmed() {
    TestObserver<String> testObserver = new TestObserver<>();

    AtomicInteger atomicCounter = new AtomicInteger(0);

    Observable
      .<String>error(() -> {
          atomicCounter.incrementAndGet();
          return UNKNOWN_ERROR;
      })
      .retry((integer, throwable) -> integer < 4)
      .subscribe(testObserver);

    testObserver.assertError(UNKNOWN_ERROR);
    testObserver.assertNotComplete();
    testObserver.assertNoValues();
    assertTrue("should call 4 times", atomicCounter.get() == 4);
}
 
Example 3
Source File: RoleServiceTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreate_uniquenessException() {
    NewRole newRole = Mockito.mock(NewRole.class);
    when(newRole.getName()).thenReturn("existing-role-name");

    Role role = new Role();
    role.setId("existing-role-id");
    role.setName("existing-role-name");
    role.setReferenceType(ReferenceType.DOMAIN);
    role.setReferenceId("domain#1");

    when(roleRepository.findAll(ReferenceType.DOMAIN, DOMAIN)).thenReturn(Flowable.just(role));

    TestObserver testObserver = new TestObserver();
    roleService.create(DOMAIN, newRole).subscribe(testObserver);

    testObserver.assertError(RoleAlreadyExistsException.class);
    testObserver.assertNotComplete();

    verify(roleRepository, never()).create(any(Role.class));
}
 
Example 4
Source File: OnErrorRetryIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenSubscriberAndError_whenRetryOnError_thenRetryConfirmed() {
    TestObserver<String> testObserver = new TestObserver<>();
    AtomicInteger atomicCounter = new AtomicInteger(0);

    Observable
      .<String>error(() -> {
          atomicCounter.incrementAndGet();
          return UNKNOWN_ERROR;
      })
      .retry(1)
      .subscribe(testObserver);

    testObserver.assertError(UNKNOWN_ERROR);
    testObserver.assertNotComplete();
    testObserver.assertNoValues();
    assertTrue("should call twice", atomicCounter.get() == 2);
}
 
Example 5
Source File: RxFirebaseDatabaseTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void testDataChangesOfClazz_Query() {
    TestObserver<DataValue<String>> sub = TestObserver.create();

    RxFirebaseDatabase.dataChangesOf(mockQuery, String.class)
            .subscribe(sub);

    verifyQueryAddValueEventListener();
    callValueEventOnDataChange("Foo");

    sub.assertNotComplete();

    sub.assertValue(new Predicate<DataValue<String>>() {
        @Override
        public boolean test(DataValue<String> value) throws Exception {
            return value.isPresent() && "Foo".equals(value.get());
        }
    });

    sub.dispose();

    callValueEventOnDataChange("Foo");

    // Ensure no more values are emitted after unsubscribe
    sub.assertValueCount(1);
}
 
Example 6
Source File: UserServiceTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldCreateUser_invalid_identity_provider() {
    final String domainId = "domain";

    User newUser = mock(User.class);
    when(newUser.getSource()).thenReturn("unknown-idp");
    when(newUser.getUserName()).thenReturn("username");

    when(domain.getId()).thenReturn(domainId);
    when(userRepository.findByDomainAndUsernameAndSource(anyString(), anyString(), anyString())).thenReturn(Maybe.empty());
    when(identityProviderManager.getUserProvider(anyString())).thenReturn(Maybe.empty());

    TestObserver<User> testObserver = userService.create(newUser, "/").test();
    testObserver.assertNotComplete();
    testObserver.assertError(InvalidValueException.class);
}
 
Example 7
Source File: IdentityProviderServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDelete_notExistingIdentityProvider() {
    when(identityProviderRepository.findById(eq(ReferenceType.DOMAIN), eq(DOMAIN), eq("my-identity-provider"))).thenReturn(Maybe.empty());

    TestObserver testObserver = identityProviderService.delete(DOMAIN, "my-identity-provider").test();

    testObserver.assertError(IdentityProviderNotFoundException.class);
    testObserver.assertNotComplete();

    verify(applicationService, never()).findByIdentityProvider(anyString());
    verify(identityProviderRepository, never()).delete(anyString());
}
 
Example 8
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_missingRedirectUri() {
    TestObserver<Client> testObserver = dcrService.create(new DynamicClientRegistrationRequest(), BASE_PATH).test();
    testObserver.assertError(InvalidRedirectUriException.class);
    testObserver.assertErrorMessage("Missing or invalid redirect_uris.");//redirect_uri metadata can be null but is mandatory
    testObserver.assertNotComplete();
}
 
Example 9
Source File: PermissionTicketServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_errorSingleResource_missingScope() {
    //Prepare request & resource
    List<PermissionRequest> request = Arrays.asList(new PermissionRequest().setResourceId("one").setResourceScopes(Arrays.asList("a","b")));
    List<Resource> found = Arrays.asList(new Resource().setId("one").setResourceScopes(Arrays.asList("not","same")));

    when(resourceService.findByDomainAndClientAndResources(DOMAIN_ID, CLIENT_ID, Arrays.asList("one"))).thenReturn(Single.just(found));
    TestObserver<PermissionTicket> testObserver = service.create(request, DOMAIN_ID, CLIENT_ID).test();

    testObserver.assertNotComplete();
    testObserver.assertError(err -> ((InvalidPermissionRequestException)err).getOAuth2ErrorCode().equals("invalid_scope"));
    verify(repository, times(0)).create(any());
}
 
Example 10
Source File: DomainServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUpdate_technicalException() {
    UpdateDomain updateDomain = Mockito.mock(UpdateDomain.class);
    when(domainRepository.findById("my-domain")).thenReturn(Maybe.error(TechnicalException::new));

    TestObserver testObserver = domainService.update("my-domain", updateDomain).test();
    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();

    verify(domainRepository, times(1)).findById(anyString());
    verify(domainRepository, never()).update(any(Domain.class));
}
 
Example 11
Source File: UserServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadUserByUsernameAndDomain_technicalException() {
    when(userRepository.findByUsernameAndDomain(DOMAIN, "my-user")).thenReturn(Maybe.error(TechnicalException::new));
    TestObserver testObserver = new TestObserver();
    userService.findByDomainAndUsername(DOMAIN, "my-user").subscribe(testObserver);

    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
}
 
Example 12
Source File: EventServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotCreate_technicalException() {
    Event newEvent = Mockito.mock(Event.class);
    when(eventRepository.create(any(Event.class))).thenReturn(Single.error(TechnicalException::new));

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

    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
}
 
Example 13
Source File: ScopeApprovalServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindById_technicalException() {
    when(scopeApprovalRepository.findById("my-consent")).thenReturn(Maybe.error(TechnicalException::new));
    TestObserver testObserver = new TestObserver();
    scopeApprovalService.findById("my-consent").subscribe(testObserver);

    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
}
 
Example 14
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_unknownResponseTypePayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setResponseTypes(Optional.of(Arrays.asList("unknownResponseType")));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("Invalid response type.");
    testObserver.assertNotComplete();
}
 
Example 15
Source File: DomainServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindAll_technicalException() {
    when(domainRepository.findAll()).thenReturn(Single.error(TechnicalException::new));

    TestObserver testObserver = new TestObserver<>();
    domainService.findAll().subscribe(testObserver);

    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
}
 
Example 16
Source File: ReadRssiTest.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
@Test
public void read_success_verifyOnlyOnce() {
  readRssi.execute(peripheral);

  int result = 100;
  readOperationSingle.onSuccess(result);

  readResultTestObserver.assertValue(result);

  TestObserver<Integer> invalidObserver = readRssi.result().test();
  invalidObserver.assertNotComplete();

  verify(peripheral, times(1)).readRssi();
}
 
Example 17
Source File: OnErrorRetryIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenSubscriberAndError_whenRetryUntilOnError_thenRetryConfirmed() {
    TestObserver<String> testObserver = new TestObserver<>();
    AtomicInteger atomicCounter = new AtomicInteger(0);

    Observable
      .<String>error(UNKNOWN_ERROR)
      .retryUntil(() -> atomicCounter.incrementAndGet() > 3)
      .subscribe(testObserver);

    testObserver.assertError(UNKNOWN_ERROR);
    testObserver.assertNotComplete();
    testObserver.assertNoValues();
    assertTrue("should call 4 times", atomicCounter.get() == 4);
}
 
Example 18
Source File: ApplicationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindTotalClients_technicalException() {
    when(applicationRepository.count()).thenReturn(Single.error(TechnicalException::new));

    TestObserver testObserver = new TestObserver<>();
    applicationService.count().subscribe(testObserver);

    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
}
 
Example 19
Source File: RoleServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFindByDomain_technicalException() {
    when(roleRepository.findAll(ReferenceType.DOMAIN, DOMAIN)).thenReturn(Flowable.error(TechnicalManagementException::new));

    TestObserver testObserver = roleService.findByDomain(DOMAIN).test();

    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
}
 
Example 20
Source File: IdentityProviderServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDelete_technicalException() {
    when(identityProviderRepository.findById(eq(ReferenceType.DOMAIN), eq(DOMAIN), eq("my-identity-provider"))).thenReturn(Maybe.just(new IdentityProvider()));

    TestObserver testObserver = identityProviderService.delete(DOMAIN, "my-identity-provider").test();

    testObserver.assertError(TechnicalManagementException.class);
    testObserver.assertNotComplete();
}