use of com.sequenceiq.cloudbreak.common.exception.ExceptionResponse in project cloudbreak by hortonworks.
the class ConstraintViolationExceptionMapperTest method testToResponseWhenHasTwoValidationError.
@Test
public void testToResponseWhenHasTwoValidationError() {
ConstraintViolation<Object> constraintViolation1 = mock(ConstraintViolation.class);
ConstraintViolation<Object> constraintViolation2 = mock(ConstraintViolation.class);
when(constraintViolation1.getMessage()).thenReturn("something validation error occurred");
when(constraintViolation1.getPropertyPath()).thenReturn(PathImpl.createPathFromString("path.smgth"));
when(constraintViolation2.getMessage()).thenReturn("other validation error happened");
ConstraintViolationException exception = new ConstraintViolationException("Error message", Set.of(constraintViolation1, constraintViolation2));
Response response = underTest.toResponse(exception);
ExceptionResponse entity = (ExceptionResponse) response.getEntity();
Assertions.assertTrue(entity.getMessage().contains("More than one validation errors happened: \n"));
Assertions.assertTrue(entity.getMessage().contains("something validation error occurred"));
Assertions.assertTrue(entity.getMessage().contains("other validation error happened"));
List<String> result = ((List<ValidationResultResponse>) entity.getPayload()).stream().map(v -> v.getField() + ":" + v.getResult()).collect(Collectors.toList());
Assertions.assertTrue(result.contains("path.smgth:something validation error occurred"));
Assertions.assertTrue(result.contains(":other validation error happened"));
}
use of com.sequenceiq.cloudbreak.common.exception.ExceptionResponse in project cloudbreak by hortonworks.
the class FreeIpaServiceTest method internalDescribeFreeipaNotFoundTest.
@Test
void internalDescribeFreeipaNotFoundTest() {
ExceptionResponse exceptionResponse = new ExceptionResponse("Freeipa not found");
final Response response = mock(Response.class);
Mockito.when(response.readEntity(Mockito.any(Class.class))).thenReturn(exceptionResponse);
NotFoundException notFoundException = mock(NotFoundException.class);
when(notFoundException.getResponse()).thenReturn(response);
when(freeIpaV1Endpoint.describeInternal(eq(ENVCRN), eq("1111"))).thenThrow(notFoundException);
Optional<DescribeFreeIpaResponse> describeFreeIpaResponse = underTest.internalDescribe(ENVCRN, "1111");
assertThat(describeFreeIpaResponse.isEmpty()).isEqualTo(true);
}
use of com.sequenceiq.cloudbreak.common.exception.ExceptionResponse in project cloudbreak by hortonworks.
the class ConstraintViolationExceptionMapperTest method testToResponseWhenHasOneValidationError.
@Test
public void testToResponseWhenHasOneValidationError() {
ConstraintViolation<Object> constraintViolation = mock(ConstraintViolation.class);
when(constraintViolation.getMessage()).thenReturn("something validation error occurred");
when(constraintViolation.getPropertyPath()).thenReturn(PathImpl.createPathFromString("path.smgth"));
ConstraintViolationException exception = new ConstraintViolationException("Error message", Set.of(constraintViolation));
Response response = underTest.toResponse(exception);
ExceptionResponse entity = (ExceptionResponse) response.getEntity();
String actual = JsonUtil.writeValueAsStringSilentSafe(entity);
String expected = "{\"message\":\"something validation error occurred\"," + "\"payload\":[{\"field\":\"path.smgth\",\"result\":\"something validation error occurred\"}]}";
Assertions.assertEquals(expected, actual);
}
Aggregations