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

The following examples show how to use io.reactivex.observers.TestObserver#assertErrorMessage() . 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: Modern_Testing.java    From Reactive-Programming-With-Java-9 with MIT License 6 votes vote down vote up
@Test
public void test_error() {
	Observable<String> observable = Observable.error(new Exception("We got an Exception"));
	TestObserver<String> testObserver = new TestObserver<>();

	observable.subscribe(testObserver);

	testObserver.assertError(Exception.class);
	testObserver.assertNotComplete();
	testObserver.assertErrorMessage("We got an Exception");
	testObserver.assertFailure(exception -> {
		return exception instanceof Exception;
	});

	testObserver.assertFailureAndMessage(Exception.class, "We got an Exception");
}
 
Example 2
Source File: RxNeuroSkyTest.java    From neurosky-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked call")
public void shouldNotConnectToDevice() {
  // given
  when(preconditions.isBluetoothAdapterInitialized()).thenReturn(true);
  when(preconditions.isBluetoothEnabled()).thenReturn(true);
  RxNeuroSky neuroSky = spy(new RxNeuroSky(deviceMessageListener, preconditions));
  when(preconditions.canConnect(neuroSky.getDevice())).thenReturn(false);
  TestObserver testObserver = new TestObserver();

  // when
  neuroSky.connect().subscribe(testObserver);

  // then
  testObserver.assertError(BluetoothConnectingOrConnectedException.class);
  testObserver.assertErrorMessage(new BluetoothConnectingOrConnectedException().getMessage());
  verify(neuroSky, times(0)).openConnection();
}
 
Example 3
Source File: RxNeuroSkyTest.java    From neurosky-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked call")
public void shouldNotDisconnectFromDevice() {
  // given
  when(preconditions.isBluetoothAdapterInitialized()).thenReturn(true);
  when(preconditions.isBluetoothEnabled()).thenReturn(true);
  RxNeuroSky neuroSky = spy(new RxNeuroSky(deviceMessageListener, preconditions));
  when(preconditions.isConnected(neuroSky.getDevice())).thenReturn(false);
  TestObserver testObserver = new TestObserver();

  // when
  neuroSky.disconnect().subscribe(testObserver);

  // then
  testObserver.assertError(BluetoothNotConnectedException.class);
  testObserver.assertErrorMessage(new BluetoothNotConnectedException().getMessage());
  verify(neuroSky, times(0)).closeConnection();
}
 
Example 4
Source File: RxNeuroSkyTest.java    From neurosky-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked call")
public void shouldNotStartMonitoring() {
  // given
  when(preconditions.isBluetoothAdapterInitialized()).thenReturn(true);
  when(preconditions.isBluetoothEnabled()).thenReturn(true);
  RxNeuroSky neuroSky = spy(new RxNeuroSky(deviceMessageListener, preconditions));
  when(preconditions.isConnected(neuroSky.getDevice())).thenReturn(false);
  TestObserver testObserver = new TestObserver();

  // when
  neuroSky.start().subscribe(testObserver);

  // then
  testObserver.assertError(BluetoothNotConnectedException.class);
  testObserver.assertErrorMessage(new BluetoothNotConnectedException().getMessage());
  verify(neuroSky, times(0)).startMonitoring();
}
 
Example 5
Source File: RxNeuroSkyTest.java    From neurosky-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked call")
public void shouldNotMonitoring() {
  // given
  when(preconditions.isBluetoothAdapterInitialized()).thenReturn(true);
  when(preconditions.isBluetoothEnabled()).thenReturn(true);
  RxNeuroSky neuroSky = spy(new RxNeuroSky(deviceMessageListener, preconditions));
  when(preconditions.isConnected(neuroSky.getDevice())).thenReturn(false);
  TestObserver testObserver = new TestObserver();

  // when
  neuroSky.stop().subscribe(testObserver);

  // then
  testObserver.assertError(BluetoothNotConnectedException.class);
  testObserver.assertErrorMessage(new BluetoothNotConnectedException().getMessage());
  verify(neuroSky, times(0)).stopMonitoring();
}
 
Example 6
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 6 votes vote down vote up
@Test
public void createFromTemplate_isNotTemplate() {
    Client template = new Client();
    template.setId("123");
    template.setClientName("shouldBeRemoved");
    template.setClientId("shouldBeReplaced");
    template.setClientSecret("shouldBeRemoved");
    template.setRedirectUris(Arrays.asList("shouldBeRemoved"));
    template.setSectorIdentifierUri("shouldBeRemoved");
    template.setJwks(new JWKSet());

    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setSoftwareId(Optional.of("123"));
    request.setApplicationType(Optional.of("app"));

    when(domain.isDynamicClientRegistrationTemplateEnabled()).thenReturn(true);
    when(clientService.findById("123")).thenReturn(Maybe.just(template));

    TestObserver<Client> testObserver = dcrService.create(request,BASE_PATH).test();
    testObserver.assertNotComplete();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("Client behind software_id is not a template");
    verify(clientService, times(0)).create(any());
}
 
Example 7
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_validateJWKsDuplicatedSource() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setJwks(Optional.of(new JWKSet()));
    request.setJwksUri(Optional.of("something"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("The jwks_uri and jwks parameters MUST NOT be used together.");
    testObserver.assertNotComplete();
}
 
Example 8
Source File: GrpcRetryTest.java    From reactive-grpc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void noRetryMakesErrorSingle() {
    TestObserver<Integer> test = newThreeErrorSingle()
            .as(new SingleConverter<Integer, Single<Integer>>() {
                @Override
                public Single<Integer> apply(Single<Integer> single) {
                    return single;
                }
            })
            .test();

    test.awaitTerminalEvent(1, TimeUnit.SECONDS);
    test.assertErrorMessage("Not yet!");
}
 
Example 9
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_unsupportedIdTokenResponseEncPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setIdTokenEncryptedResponseAlg(Optional.of("RSA-OAEP-256"));
    request.setIdTokenEncryptedResponseEnc(Optional.of("unknownEncryptionAlg"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("Unsupported id_token_encrypted_response_enc value");
    testObserver.assertNotComplete();
}
 
Example 10
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_missingIdTokenResponseAlgPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setIdTokenEncryptedResponseEnc(Optional.of("unknownEncryptionAlg"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("When id_token_encrypted_response_enc is included, id_token_encrypted_response_alg MUST also be provided");
    testObserver.assertNotComplete();
}
 
Example 11
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_unsupportedIdTokenResponseAlgPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setIdTokenEncryptedResponseAlg(Optional.of("unknownEncryptionAlg"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("Unsupported id_token_encrypted_response_alg value");
    testObserver.assertNotComplete();
}
 
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_unsupportedIdTokenSigningAlgorithmPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setIdTokenSignedResponseAlg(Optional.of("unknownSigningAlg"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("Unsupported id_token signing algorithm");
    testObserver.assertNotComplete();
}
 
Example 13
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_unsupportedUserinfoResponseEncPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setUserinfoEncryptedResponseAlg(Optional.of("RSA-OAEP-256"));
    request.setUserinfoEncryptedResponseEnc(Optional.of("unknownEncryptionAlg"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("Unsupported userinfo_encrypted_response_enc value");
    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_missingUserinfoResponseAlgPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setUserinfoEncryptedResponseEnc(Optional.of("unknownEncryptionAlg"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("When userinfo_encrypted_response_enc is included, userinfo_encrypted_response_alg MUST also be provided");
    testObserver.assertNotComplete();
}
 
Example 15
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_unsupportedUserinfoResponseAlgPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setUserinfoEncryptedResponseAlg(Optional.of("unknownEncryptionAlg"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("Unsupported userinfo_encrypted_response_alg value");
    testObserver.assertNotComplete();
}
 
Example 16
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_unsupportedUserinfoSigningAlgorithmPayload() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setUserinfoSignedResponseAlg(Optional.of("unknownSigningAlg"));

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("Unsupported userinfo signing algorithm");
    testObserver.assertNotComplete();
}
 
Example 17
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void update_missingRedirectUri() {
    TestObserver<Client> testObserver = dcrService.update(new Client(), 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 18
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 19
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 20
Source File: DynamicClientRegistrationServiceTest.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
@Test
public void create_validateJWKsUriWithoutJwkSet() {
    DynamicClientRegistrationRequest request = new DynamicClientRegistrationRequest();
    request.setRedirectUris(Optional.empty());
    request.setJwksUri(Optional.of("something"));

    when(jwkService.getKeys(anyString())).thenReturn(Maybe.empty());

    TestObserver<Client> testObserver = dcrService.create(request, BASE_PATH).test();
    testObserver.assertError(InvalidClientMetadataException.class);
    testObserver.assertErrorMessage("No JWK found behind jws uri...");
    testObserver.assertNotComplete();
}