private static void assertInvalidStatistics(PartitionStatistics partitionStatistics, String expectedMessage) { assertThatThrownBy(() -> validatePartitionStatistics(TABLE, ImmutableMap.of(PARTITION, partitionStatistics))) .isInstanceOf(PrestoException.class) .hasFieldOrPropertyWithValue("errorCode", HIVE_CORRUPTED_COLUMN_STATISTICS.toErrorCode()) .hasMessage(expectedMessage); }
@Test public void itDeserializesPojoExceptionsWithJsonCreatorConstructor() { ObjectNode response = response( error( ThrowableSerializationMixin.ERROR_CODE, VALID_MESSAGE, data(PojoTestException.class.getTypeName(), "someValue=foo", "anotherValue=bar"))); Throwable throwable = resolver.resolveException(response); assertThat(throwable) .isInstanceOf(PojoTestException.class) .hasMessage("foo:bar") .hasFieldOrPropertyWithValue("someValue", "foo") .hasFieldOrPropertyWithValue("anotherValue", "bar"); }
@Test public void test() throws Exception { assertThat(client("").hello("a")).isEqualTo("none:a"); assertThat(client("foo").hello("b")).isEqualTo("foo:b"); assertThat(client("bar").hello("c")).isEqualTo("bar:c"); assertThatThrownBy(() -> client("baz").hello("d")) .isInstanceOf(TApplicationException.class) .hasFieldOrPropertyWithValue("type", TApplicationException.UNKNOWN_METHOD); assertThat(methodNames).containsExactly("hello", "foo:hello", "bar:hello"); }
@Test public void decodeWhenJwtValidationHasTwoErrorsThenJwtExceptionMessageShowsFirstError() { OAuth2Error firstFailure = new OAuth2Error("mock-error", "mock-description", "mock-uri"); OAuth2Error secondFailure = new OAuth2Error("another-error", "another-description", "another-uri"); OAuth2TokenValidatorResult result = OAuth2TokenValidatorResult.failure(firstFailure, secondFailure); OAuth2TokenValidator<Jwt> jwtValidator = mock(OAuth2TokenValidator.class); when(jwtValidator.validate(any(Jwt.class))).thenReturn(result); this.jwtDecoder.setJwtValidator(jwtValidator); assertThatCode(() -> this.jwtDecoder.decode(SIGNED_JWT)) .isInstanceOf(JwtValidationException.class) .hasMessageContaining("mock-description") .hasFieldOrPropertyWithValue("errors", Arrays.asList(firstFailure, secondFailure)); }
@Test public void authenticateWhenDecoderThrowsIncompatibleErrorMessageThenWrapsWithGenericOne() { BearerTokenAuthenticationToken token = this.authentication(); when(this.jwtDecoder.decode(token.getToken())).thenThrow(new JwtException("with \"invalid\" chars")); assertThatCode(() -> this.provider.authenticate(token)) .isInstanceOf(OAuth2AuthenticationException.class) .hasFieldOrPropertyWithValue( "error.description", "An error occurred while attempting to decode the Jwt: Invalid token"); }
@Test public void itMapsPojoExceptionsFromFailingMethods() { TestService server = (input) -> { throw new TestException(input, "beta"); }; JsonRpcLambdaHandler<TestService> handler = new JsonRpcLambdaHandler<>(mapper, TestService.class, server); JsonRpcLambdaClient lambdaClient = new JsonRpcLambdaClient(mapper, new FakeLambdaClient<>(handler), "foo"); TestService client = lambdaClient.newProxy(TestService.class); assertThatThrownBy(() -> client.throwsException("foo")) .isInstanceOf(TestException.class) .hasMessage("foo:beta") .hasFieldOrPropertyWithValue("value", "foo") .hasFieldOrPropertyWithValue("otherValue", "beta"); } }
@Test public void decodeWhenJwtValidationHasTwoErrorsThenJwtExceptionMessageShowsFirstError() throws Exception { try ( MockWebServer server = new MockWebServer() ) { server.enqueue(new MockResponse().setBody(JWK_SET)); String jwkSetUrl = server.url("/.well-known/jwks.json").toString(); NimbusJwtDecoderJwkSupport decoder = new NimbusJwtDecoderJwkSupport(jwkSetUrl); OAuth2Error firstFailure = new OAuth2Error("mock-error", "mock-description", "mock-uri"); OAuth2Error secondFailure = new OAuth2Error("another-error", "another-description", "another-uri"); OAuth2TokenValidatorResult result = OAuth2TokenValidatorResult.failure(firstFailure, secondFailure); OAuth2TokenValidator<Jwt> jwtValidator = mock(OAuth2TokenValidator.class); when(jwtValidator.validate(any(Jwt.class))).thenReturn(result); decoder.setJwtValidator(jwtValidator); assertThatCode(() -> decoder.decode(SIGNED_JWT)) .isInstanceOf(JwtValidationException.class) .hasMessageContaining("mock-description") .hasFieldOrPropertyWithValue("errors", Arrays.asList(firstFailure, secondFailure)); } }
ImmutableList.of(partition(partitionName)))) .isInstanceOf(PrestoException.class) .hasFieldOrPropertyWithValue("errorCode", HIVE_CORRUPTED_COLUMN_STATISTICS.toErrorCode()); TestingConnectorSession ignoreSession = new TestingConnectorSession(new HiveSessionProperties( new HiveClientConfig().setIgnoreCorruptedStatistics(true),
@Test public void testNegativeHeaderLength() throws Exception { byte[] data = Ints.toByteArray(-1); Throwable thrown = catchThrowable( () -> new ProtobufRpcResponse(data)); assertThat(thrown).isExactlyInstanceOf(RpcCallException.class); assertThat(thrown).hasFieldOrPropertyWithValue("category", RpcCallException.Category.InternalServerError); }
private static void assertInvalidStatistics(PartitionStatistics partitionStatistics, String expectedMessage) { assertThatThrownBy(() -> validatePartitionStatistics(TABLE, ImmutableMap.of(PARTITION, partitionStatistics))) .isInstanceOf(PrestoException.class) .hasFieldOrPropertyWithValue("errorCode", HIVE_CORRUPTED_COLUMN_STATISTICS.toErrorCode()) .hasMessage(expectedMessage); }
private static void assertInvalidStatistics(PartitionStatistics partitionStatistics, String expectedMessage) { assertThatThrownBy(() -> validatePartitionStatistics(TABLE, ImmutableMap.of(PARTITION, partitionStatistics))) .isInstanceOf(PrestoException.class) .hasFieldOrPropertyWithValue("errorCode", HIVE_CORRUPTED_COLUMN_STATISTICS.toErrorCode()) .hasMessage(expectedMessage); }
private static void assertInvalidStatistics(PartitionStatistics partitionStatistics, String expectedMessage) { assertThatThrownBy(() -> validatePartitionStatistics(TABLE, ImmutableMap.of(PARTITION, partitionStatistics))) .isInstanceOf(PrestoException.class) .hasFieldOrPropertyWithValue("errorCode", HIVE_CORRUPTED_COLUMN_STATISTICS.toErrorCode()) .hasMessage(expectedMessage); }
protected void assertClientException(ThrowableAssert.ThrowingCallable callable, int expectedHttpCode, String restMessage, String jmsMessage) { if(configuration.isRest()) { Assertions.assertThatThrownBy(callable) .isInstanceOf(KieServicesHttpException.class) .hasFieldOrPropertyWithValue("httpCode", expectedHttpCode) .hasMessageContaining(restMessage); } else { Assertions.assertThatThrownBy(callable) .isInstanceOf(KieServicesException.class) .hasMessageContaining(jmsMessage); } } }
@Test public void whenGetWithValueLoaderThrowsExceptionThenValueRetrievalException() { when(memcachedClient.get(namespaceKey)) .thenReturn(NAMESPACE_KEY_VALUE) .thenReturn(null); assertThatThrownBy(() -> memcachedCache.get(CACHED_OBJECT_KEY, () -> { throw new Exception("exception to be wrapped"); })) .isInstanceOf(Cache.ValueRetrievalException.class) .hasFieldOrPropertyWithValue("key", CACHED_OBJECT_KEY); verify(memcachedClient, times(2)).get(namespaceKey); verify(memcachedClient, times(2)).get(matches(CACHED_KEY_REGEX)); verify(memcachedClient).set(eq(namespaceKey), eq(CACHE_EXPIRATION), anyString()); }
@Test public void shouldNotGetWorkflowByNonExistingKey() { assertThatThrownBy( () -> apiRule .createControlMessageRequest() .messageType(ControlMessageType.GET_WORKFLOW) .data() .put(PROP_WORKFLOW_KEY, 1231) .put(PROP_WORKFLOW_BPMN_PROCESS_ID, "") .put(PROP_WORKFLOW_VERSION, -1) .done() .sendAndAwait()) .isInstanceOf(ErrorResponseException.class) .hasFieldOrPropertyWithValue("errorCode", ErrorCode.WORKFLOW_NOT_FOUND); }
@Test public void shouldNotGetWorkflowByNonExistingKey() { assertThatThrownBy( () -> apiRule .createControlMessageRequest() .messageType(ControlMessageType.GET_WORKFLOW) .data() .put(PROP_WORKFLOW_KEY, 1231) .put(PROP_WORKFLOW_BPMN_PROCESS_ID, "") .put(PROP_WORKFLOW_VERSION, -1) .done() .sendAndAwait()) .isInstanceOf(ErrorResponseException.class) .hasFieldOrPropertyWithValue("errorCode", ErrorCode.WORKFLOW_NOT_FOUND); }
@Test public void shouldNotGetWorkflowByNonExistingBpmnProcessKey() { assertThatThrownBy( () -> apiRule .createControlMessageRequest() .messageType(ControlMessageType.GET_WORKFLOW) .data() .put(PROP_WORKFLOW_KEY, -1) .put(PROP_WORKFLOW_BPMN_PROCESS_ID, "notExisting") .put(PROP_WORKFLOW_VERSION, -1) .done() .sendAndAwait()) .isInstanceOf(ErrorResponseException.class) .hasFieldOrPropertyWithValue("errorCode", ErrorCode.WORKFLOW_NOT_FOUND); }
@Test public void shouldNotGetWorkflowByNonExistingBpmnProcessKeyAndVersion() { assertThatThrownBy( () -> apiRule .createControlMessageRequest() .messageType(ControlMessageType.GET_WORKFLOW) .data() .put(PROP_WORKFLOW_KEY, -1) .put(PROP_WORKFLOW_BPMN_PROCESS_ID, "notExisting") .put(PROP_WORKFLOW_VERSION, 99) .done() .sendAndAwait()) .isInstanceOf(ErrorResponseException.class) .hasFieldOrPropertyWithValue("errorCode", ErrorCode.WORKFLOW_NOT_FOUND); }
@Test public void shouldNotGetWorkflowByNonExistingBpmnProcessKey() { assertThatThrownBy( () -> apiRule .createControlMessageRequest() .messageType(ControlMessageType.GET_WORKFLOW) .data() .put(PROP_WORKFLOW_KEY, -1) .put(PROP_WORKFLOW_BPMN_PROCESS_ID, "notExisting") .put(PROP_WORKFLOW_VERSION, -1) .done() .sendAndAwait()) .isInstanceOf(ErrorResponseException.class) .hasFieldOrPropertyWithValue("errorCode", ErrorCode.WORKFLOW_NOT_FOUND); }
@Test public void shouldNotGetWorkflowByNonExistingBpmnProcessKeyAndVersion() { assertThatThrownBy( () -> apiRule .createControlMessageRequest() .messageType(ControlMessageType.GET_WORKFLOW) .data() .put(PROP_WORKFLOW_KEY, -1) .put(PROP_WORKFLOW_BPMN_PROCESS_ID, "notExisting") .put(PROP_WORKFLOW_VERSION, 99) .done() .sendAndAwait()) .isInstanceOf(ErrorResponseException.class) .hasFieldOrPropertyWithValue("errorCode", ErrorCode.WORKFLOW_NOT_FOUND); }