List of usage examples for javax.servlet.http HttpServletResponse getStatus
public int getStatus();
From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptorTest.java
@Test public void testPreHandlePutPreconditionFailedNoStoredETag() throws Exception { // Request value String path = "/path/to/resource/"; String etag = "etag"; // Set the request/response HttpServletRequest request = put(path).ifMatch(etag).build(); HttpServletResponse response = response().build(); // Execute//from ww w . java2 s. co m boolean handle = interceptor.preHandle(request, response, new Object()); // Validate Assert.assertFalse(handle); Assert.assertEquals(412, response.getStatus()); verify(service).get(createURI(path)); }
From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptorTest.java
@Test public void testPreHandleDeletePreconditionFailedNoStoredETag() throws Exception { // Request value String path = "/path/to/resource/"; String etag = "etag"; // Set the request/response HttpServletRequest request = delete(path).ifMatch(etag).build(); HttpServletResponse response = response().build(); // Execute//from w w w.ja va 2 s .c om boolean handle = interceptor.preHandle(request, response, new Object()); // Validate Assert.assertFalse(handle); Assert.assertEquals(412, response.getStatus()); verify(service).get(createURI(path)); }
From source file:com.cognitivabrasil.repositorio.web.FileControllerTest.java
@Test public void testGetThumbnail() throws IOException { HttpServletResponse response = new MockHttpServletResponse(); HttpServletResponse response2 = new MockHttpServletResponse(); FileController fileController = mockFiles(); // proves response and response2 are not comitted yet. Assert.assertFalse(response.isCommitted()); Assert.assertFalse(response2.isCommitted()); // tests id = null. fileController.getThumbnail(null, response); Assert.assertTrue(response.isCommitted()); assertThat(HttpServletResponse.SC_NOT_FOUND, equalTo(response.getStatus())); // tests id = 1 Long id = 1L;//from ww w. j a v a 2s .c om //proves response2 is only commited after flushbuffer. Assert.assertFalse(response2.isCommitted()); fileController.getThumbnail(id, response2); Assert.assertTrue(response2.isCommitted()); assertThat(HttpServletResponse.SC_CREATED, equalTo(response2.getStatus())); }
From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptorTest.java
@Test public void testPreHandleGetNotModified() throws Exception { // Request value String path = "/path/to/resource/"; String query = "query=string"; String etag = "etag"; // Set ETag value to return by service setETag(path, query, etag);//from w w w. j ava 2 s .c o m // Set the request/response HttpServletRequest request = get(path, query).ifNoneMatch(etag).build(); HttpServletResponse response = response().build(); // Execute boolean handle = interceptor.preHandle(request, response, new Object()); // Validate Assert.assertFalse(handle); Assert.assertEquals(304, response.getStatus()); }
From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptorTest.java
@Test public void testPreHandleHeadNotModified() throws Exception { // Request value String path = "/path/to/resource/"; String query = "query=string"; String etag = "etag"; // Set ETag value to return by service setETag(path, query, etag);/*from w w w . j a va 2s . c om*/ // Set the request HttpServletRequest request = head(path, query).ifNoneMatch(etag).build(); HttpServletResponse response = response().build(); // Execute boolean handle = interceptor.preHandle(request, response, new Object()); // Validate Assert.assertFalse(handle); Assert.assertEquals(304, response.getStatus()); }
From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptorTest.java
@Test public void testPreHandlePutPreconditionFailedETagIfMatchNoMatch() throws Exception { // Request value String path = "/path/to/resource/"; String etag = "etag-a"; // Set ETag value to return by service setETag(path, null, "etag-b"); // Set the request/response HttpServletRequest request = put(path).ifMatch(etag).build(); HttpServletResponse response = response().build(); // Execute//from w w w. j ava 2 s . co m boolean handle = interceptor.preHandle(request, response, new Object()); // Validate Assert.assertFalse(handle); Assert.assertEquals(412, response.getStatus()); verify(service).get(createURI(path)); }
From source file:net.eusashead.hateoas.conditional.interceptor.ConditionalResponseInterceptorTest.java
@Test public void testPreHandleDeletePreconditionFailedETagIfMatchNoMatch() throws Exception { // Request value String path = "/path/to/resource/"; String etag = "etag-a"; // Set ETag value to return by service setETag(path, null, "etag-b"); // Set the request/response HttpServletRequest request = delete(path).ifMatch(etag).build(); HttpServletResponse response = response().build(); // Execute//from www . java 2 s .c o m boolean handle = interceptor.preHandle(request, response, new Object()); // Validate Assert.assertFalse(handle); Assert.assertEquals(412, response.getStatus()); verify(service).get(createURI(path)); }
From source file:org.cloudfoundry.identity.uaa.metrics.UaaMetricsFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { UrlGroup uriGroup = getUriGroup(request); if (uriGroup != null) { RequestMetric metric = RequestMetric.start(request.getRequestURI(), uriGroup, timeService.getCurrentTimeMillis()); try {//from www .j a v a 2s . c o m MetricsAccessor.setCurrent(metric); inflight.startRequest(); filterChain.doFilter(request, response); } finally { MetricsAccessor.clear(); inflight.endRequest(); metric.stop(response.getStatus(), timeService.getCurrentTimeMillis()); for (String group : Arrays.asList(uriGroup.getGroup(), MetricsUtil.GLOBAL_GROUP)) { MetricsQueue queue = getMetricsQueue(group); queue.offer(metric); } } } else { filterChain.doFilter(request, response); } }
From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java
@Test public void testInvoke_SystemExceptionResolver_responseCode_4xx() 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(400); when(mockMethodInvocation.getArguments()) .thenReturn(new Object[] { null, mockResponse, null, occurException }); // do test./* w w w . ja v a2 s . c o m*/ testTarget.invoke(mockMethodInvocation); // do assert. verify(mockExceptionLogger, times(1)).warn((Exception) any()); }
From source file:org.terasoluna.gfw.web.exception.HandlerExceptionResolverLoggingInterceptorTest.java
@Test public void testInvoke_responseCode_499() 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(499); when(mockMethodInvocation.getArguments()) .thenReturn(new Object[] { null, mockResponse, null, occurException }); // do test./* w ww .j av a 2 s . c o m*/ testTarget.invoke(mockMethodInvocation); // do assert. verify(mockExceptionLogger, times(1)).warn((Exception) any()); }