use of org.sklsft.commons.api.exception.ApplicationException in project skeleton-commons by skeleton-software-community.
the class ErrorReportHandler method convertErrorReport.
/**
* instantiates the {@link ApplicationException} as described in the {@link ErrorReport} that a rest service can respond
* @param errorReport
*/
public void convertErrorReport(ErrorReport errorReport) {
ApplicationException exception;
try {
exception = (ApplicationException) Class.forName(errorReport.getExceptionClassName()).newInstance();
exception.setMessage(errorReport.getMessage());
exception.setDetails(errorReport.getDetails());
} catch (Exception e) {
exception = new TechnicalError(ApplicationException.ERROR_UNKNOWN, e);
}
throw exception;
}
use of org.sklsft.commons.api.exception.ApplicationException in project skeleton-commons by skeleton-software-community.
the class ErrorReportHandlerTest method testApplicationExceptionDummyDetails.
@Test
public void testApplicationExceptionDummyDetails() throws JsonProcessingException {
String message = "test";
Dummy dummy = new Dummy(1L, "test");
ErrorReport errorReport = new ErrorReport();
errorReport.setExceptionClassName(TestException.class.getName());
errorReport.setMessage(message);
errorReport.setDetails(dummy);
try {
errorReportHandler.convertErrorReport(errorReport);
} catch (ApplicationException e) {
Assert.assertEquals(e.getMessage(), message);
Assert.assertTrue(e instanceof TestException);
Assert.assertTrue(e.getDetails().equals(dummy));
return;
}
Assert.fail();
}
use of org.sklsft.commons.api.exception.ApplicationException in project skeleton-commons by skeleton-software-community.
the class RestExceptionHandlerTest method testApplicationExceptionNoDetails.
@Test
public void testApplicationExceptionNoDetails() {
String message = "test";
ApplicationException e = new TestException(message);
ErrorReport errorReport = restExceptionHandler.handleApplicationException(e);
Assert.assertEquals(errorReport.getMessage(), message);
Assert.assertTrue(errorReport.getExceptionClassName().equals(TestException.class.getName()));
Assert.assertNull(errorReport.getDetails());
}
use of org.sklsft.commons.api.exception.ApplicationException in project skeleton-commons by skeleton-software-community.
the class ErrorReportHandlerTest method testApplicationExceptionNoDetails.
@Test
public void testApplicationExceptionNoDetails() throws JsonProcessingException {
String message = "test";
ErrorReport errorReport = new ErrorReport();
errorReport.setExceptionClassName(TestException.class.getName());
errorReport.setMessage(message);
try {
errorReportHandler.convertErrorReport(errorReport);
} catch (ApplicationException e) {
Assert.assertEquals(e.getMessage(), message);
Assert.assertTrue(e instanceof TestException);
Assert.assertNull(e.getDetails());
return;
}
Assert.fail();
}
use of org.sklsft.commons.api.exception.ApplicationException in project skeleton-commons by skeleton-software-community.
the class RestExceptionHandlerTest method testApplicationExceptionDummyDetails.
@Test
public void testApplicationExceptionDummyDetails() {
Dummy dummy = new Dummy();
dummy.setLongField(1L);
dummy.setStringField("test");
String message = "test";
ApplicationException e = new TestException(message, dummy);
ErrorReport errorReport = restExceptionHandler.handleApplicationException(e);
Assert.assertEquals(errorReport.getMessage(), message);
Assert.assertTrue(errorReport.getExceptionClassName().equals(TestException.class.getName()));
Assert.assertNotNull(errorReport.getDetails());
Assert.assertTrue(errorReport.getDetails() instanceof Dummy);
}
Aggregations