Example usage for javax.servlet.http HttpServletResponse getStatus

List of usage examples for javax.servlet.http HttpServletResponse getStatus

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse getStatus.

Prototype

public int getStatus();

Source Link

Document

Gets the current status code of this response.

Usage

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_responseCode_599() throws Throwable {

    // do setup for test case.
    NullPointerException occurException = new NullPointerException("null pointer exception.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    SystemExceptionResolver resolver = new SystemExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(599);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    // do test./*from ww  w .j  ava 2  s . com*/
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(1)).error((Exception) any());

}

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_SystemExceptionResolver_ResourceNotFoundException_not_ignore_responseCode_5xx()
        throws Throwable {

    // do setup for test case.
    ResourceNotFoundException occurException = new ResourceNotFoundException("error.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    SystemExceptionResolver resolver = new SystemExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(500);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    testTarget.setIgnoreExceptions(null);

    // do test.//from w w  w  .  jav a  2  s  .co  m
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(1)).error((Exception) any());

}

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_responseCode_under_100() throws Throwable {

    // do setup for test case.
    NullPointerException occurException = new NullPointerException("null pointer exception.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    SystemExceptionResolver resolver = new SystemExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(99);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    // do test.//from  w  ww. j  a  v  a 2 s  .co  m
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(0)).log((Exception) any());
    verify(mockExceptionLogger, times(0)).info((Exception) any());
    verify(mockExceptionLogger, times(0)).warn((Exception) any());
    verify(mockExceptionLogger, times(0)).error((Exception) any());

}

From source file:org.wso2.carbon.device.mgt.iot.services.sensebot.SenseBotControllerService.java

@Path("/pushsonardata")
@POST//from  w  ww. ja va 2 s.  c  o m
@Consumes(MediaType.APPLICATION_JSON)
public String pushSonarData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
    String result = null;

    String sonar = dataMsg.value; //TEMP-PIR-SONAR-LDR

    if (sonar.equals("-1")) {
        log.info("Recieved a 'No Obstacle' Sonar value. (Means there are no abstacles within 30cm)");
    } else {
        log.info("Recieved Sonar Sensor Data Value: " + sonar + " cm");

        result = DeviceControllerService.pushData(dataMsg.owner, "SenseBot", dataMsg.deviceId,
                System.currentTimeMillis(), "DeviceData", sonar, "SONAR", response);

        if (response.getStatus() != HttpStatus.SC_ACCEPTED) {
            return result;
        }
    }

    return result;
}

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_DefaultHandlerExceptionResolver_responseCode_2xx() throws Throwable {

    // do setup for test case.
    NullPointerException occurException = new NullPointerException("null pointer exception.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    DefaultHandlerExceptionResolver resolver = new DefaultHandlerExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(200);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    // do test.//  ww w  .  j a va2 s . c o m
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(1)).info((Exception) any());

}

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_ResponseStatusExceptionResolver_responseCode_3xx() throws Throwable {

    // do setup for test case.
    NullPointerException occurException = new NullPointerException("null pointer exception.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    ResponseStatusExceptionResolver resolver = new ResponseStatusExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(300);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    // do test.//w w w  .ja  va 2 s  . c  o  m
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(1)).info((Exception) any());

}

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_responseCode_299() throws Throwable {

    // do setup for test case.
    NullPointerException occurException = new NullPointerException("null pointer exception.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    DefaultHandlerExceptionResolver resolver = new DefaultHandlerExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(299);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    // do test./*from   w  w  w. j a  v a 2 s. c  o  m*/
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(1)).info((Exception) any());

}

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_responseCode_399() throws Throwable {

    // do setup for test case.
    NullPointerException occurException = new NullPointerException("null pointer exception.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    ResponseStatusExceptionResolver resolver = new ResponseStatusExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(399);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    // do test.//from  ww  w. java2  s.  c om
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(1)).info((Exception) any());

}

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_ExceptionHandlerExceptionResolver_responseCode_1xx() throws Throwable {

    // do setup for test case.
    NullPointerException occurException = new NullPointerException("null pointer exception.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(100);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    // do test.// w  w w  .j  a va 2 s . c om
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(1)).info((Exception) any());

}

From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java

@Test
public void testInvoke_responseCode_199() throws Throwable {

    // do setup for test case.
    NullPointerException occurException = new NullPointerException("null pointer exception.");
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);

    ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();

    when(mockMethodInvocation.proceed()).thenReturn("viewname");
    when(mockMethodInvocation.getThis()).thenReturn(resolver);
    when(mockResponse.getStatus()).thenReturn(199);
    when(mockMethodInvocation.getArguments())
            .thenReturn(new Object[] { null, mockResponse, null, occurException });

    // do test./*w  w  w . ja  v  a  2 s.co m*/
    testTarget.invoke(mockMethodInvocation);

    // do assert.
    verify(mockExceptionLogger, times(1)).info((Exception) any());

}