Search in sources :

Example 1 with ApplicationException

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;
}
Also used : ApplicationException(org.sklsft.commons.api.exception.ApplicationException) TechnicalError(org.sklsft.commons.api.exception.TechnicalError) ApplicationException(org.sklsft.commons.api.exception.ApplicationException) IOException(java.io.IOException)

Example 2 with ApplicationException

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();
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) ApplicationException(org.sklsft.commons.api.exception.ApplicationException) Test(org.junit.Test)

Example 3 with ApplicationException

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());
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) ApplicationException(org.sklsft.commons.api.exception.ApplicationException) Test(org.junit.Test)

Example 4 with ApplicationException

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();
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) ApplicationException(org.sklsft.commons.api.exception.ApplicationException) Test(org.junit.Test)

Example 5 with ApplicationException

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);
}
Also used : ErrorReport(org.sklsft.commons.api.exception.ErrorReport) ApplicationException(org.sklsft.commons.api.exception.ApplicationException) Test(org.junit.Test)

Aggregations

ApplicationException (org.sklsft.commons.api.exception.ApplicationException)6 Test (org.junit.Test)4 ErrorReport (org.sklsft.commons.api.exception.ErrorReport)4 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Around (org.aspectj.lang.annotation.Around)1 MethodSignature (org.aspectj.lang.reflect.MethodSignature)1 TechnicalError (org.sklsft.commons.api.exception.TechnicalError)1 AjaxMethod (org.sklsft.commons.mvc.annotations.AjaxMethod)1