Search in sources :

Example 16 with BadRequestException

use of ninja.exceptions.BadRequestException in project ninja by ninjaframework.

the class NinjaDefaultTest method testOnExceptionBadRequest.

@Test
public void testOnExceptionBadRequest() {
    BadRequestException badRequestException = new BadRequestException();
    Result result = ninjaDefault.onException(contextImpl, badRequestException);
    verify(ninjaDefault).getBadRequestResult(contextImpl, badRequestException);
    assertThat(result.getStatusCode(), equalTo(Result.SC_400_BAD_REQUEST));
}
Also used : BadRequestException(ninja.exceptions.BadRequestException) Test(org.junit.Test)

Example 17 with BadRequestException

use of ninja.exceptions.BadRequestException in project ninja by ninjaframework.

the class NinjaDefaultTest method testOnRouteRequestWhenOnBadRequestInDiagnosticMode.

@Test
public void testOnRouteRequestWhenOnBadRequestInDiagnosticMode() {
    FilterChain filterChain = Mockito.mock(FilterChain.class);
    Mockito.when(route.getFilterChain()).thenReturn(filterChain);
    BadRequestException badRequest = new BadRequestException("That's a BadRequest that should be handled by onBadRequest");
    Mockito.when(filterChain.next(contextImpl)).thenThrow(badRequest);
    when(ninjaProperties.isDev()).thenReturn(true);
    when(ninjaProperties.getBooleanWithDefault(NinjaConstant.DIAGNOSTICS_KEY_NAME, true)).thenReturn(true);
    ninjaDefault.onRouteRequest(contextImpl);
    Result localResult = ninjaDefault.getBadRequestResult(contextImpl, badRequest);
    assertThat(localResult.getRenderable(), CoreMatchers.instanceOf(DiagnosticError.class));
}
Also used : DiagnosticError(ninja.diagnostics.DiagnosticError) BadRequestException(ninja.exceptions.BadRequestException) Test(org.junit.Test)

Aggregations

BadRequestException (ninja.exceptions.BadRequestException)17 Test (org.junit.Test)16 ByteArrayInputStream (java.io.ByteArrayInputStream)10 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)5 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Calendar (java.util.Calendar)3 Optional (java.util.Optional)1 Result (ninja.Result)1 Route (ninja.Route)1 DiagnosticError (ninja.diagnostics.DiagnosticError)1 Message (ninja.utils.Message)1