Here are the examples of the java api class org.springframework.mock.web.MockHttpServletResponse taken from open source projects.
1. WebRequestTraceFilterTests#filterHasError()
Project: spring-boot
File: WebRequestTraceFilterTests.java
File: WebRequestTraceFilterTests.java
@Test public void filterHasError() { this.filter.setErrorAttributes(new DefaultErrorAttributes()); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); MockHttpServletResponse response = new MockHttpServletResponse(); response.setStatus(500); request.setAttribute("javax.servlet.error.exception", new IllegalStateException("Foo")); response.addHeader("Content-Type", "application/json"); Map<String, Object> trace = this.filter.getTrace(request); this.filter.enhanceTrace(trace, response); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) trace.get("error"); System.err.println(map); assertThat(map.get("message").toString()).isEqualTo("Foo"); }
2. WebRequestTraceFilterTests#filterHasResponseStatus()
Project: spring-boot
File: WebRequestTraceFilterTests.java
File: WebRequestTraceFilterTests.java
@Test public void filterHasResponseStatus() { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); MockHttpServletResponse response = new MockHttpServletResponse(); response.setStatus(404); response.addHeader("Content-Type", "application/json"); Map<String, Object> trace = this.filter.getTrace(request); this.filter.enhanceTrace(trace, response); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) trace.get("headers")).get("response"); assertThat(map.get("status").toString()).isEqualTo("404"); }
3. WebRequestTraceFilterTests#filterDoesNotAddResponseCookiesWithCookiesExclude()
Project: spring-boot
File: WebRequestTraceFilterTests.java
File: WebRequestTraceFilterTests.java
@Test @SuppressWarnings({ "unchecked" }) public void filterDoesNotAddResponseCookiesWithCookiesExclude() throws ServletException, IOException { this.properties.setInclude(Collections.singleton(Include.RESPONSE_HEADERS)); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); MockHttpServletResponse response = new MockHttpServletResponse(); response.addHeader("Content-Type", "application/json"); response.addHeader("Set-Cookie", "testCookie=testValue;"); Map<String, Object> trace = this.filter.getTrace(request); this.filter.enhanceTrace(trace, response); Map<String, Object> map = (Map<String, Object>) trace.get("headers"); assertThat(map.get("response").toString()).isEqualTo("{Content-Type=application/json, status=200}"); }
4. InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests#loginUnsuccessfully()
Project: cas
File: InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
File: InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
@Override protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setMethod("POST"); request.setParameter("username", username); request.setRemoteAddr(fromAddress); final MockRequestContext context = new MockRequestContext(); context.setCurrentEvent(new Event("", "error")); request.setAttribute("flowRequestContext", context); ClientInfoHolder.setClientInfo(new ClientInfo(request)); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); getThrottle().preHandle(request, response, null); try { authenticationManager.authenticate(AuthenticationTransaction.wrap(TestUtils.getService(), badCredentials(username))); } catch (final AuthenticationException e) { getThrottle().postHandle(request, response, null, null); return response; } fail("Expected AbstractAuthenticationException"); return null; }
5. AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests#loginUnsuccessfully()
Project: cas
File: AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests.java
File: AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests.java
@Override protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setMethod("POST"); request.setParameter("username", username); request.setRemoteAddr(fromAddress); final MockRequestContext context = new MockRequestContext(); context.setCurrentEvent(new Event("", "error")); request.setAttribute("flowRequestContext", context); response.setStatus(HttpStatus.UNAUTHORIZED.value()); getThrottle().preHandle(request, response, null); getThrottle().postHandle(request, response, null, null); return response; }
6. WebRequestTraceFilterTests#filterDoesNotAddResponseHeadersWithoutResponseHeadersInclude()
Project: spring-boot
File: WebRequestTraceFilterTests.java
File: WebRequestTraceFilterTests.java
@Test @SuppressWarnings({ "unchecked" }) public void filterDoesNotAddResponseHeadersWithoutResponseHeadersInclude() throws ServletException, IOException { this.properties.setInclude(Collections.singleton(Include.REQUEST_HEADERS)); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo"); MockHttpServletResponse response = new MockHttpServletResponse(); response.addHeader("Content-Type", "application/json"); this.filter.doFilterInternal(request, response, new FilterChain() { @Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { } }); Map<String, Object> info = this.repository.findAll().iterator().next().getInfo(); Map<String, Object> headers = (Map<String, Object>) info.get("headers"); assertThat(headers.get("response") == null).isTrue(); }
7. InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests#loginUnsuccessfully()
Project: passport
File: InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
File: InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests.java
@Override protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setMethod("POST"); request.setParameter("username", username); request.setRemoteAddr(fromAddress); final MockRequestContext context = new MockRequestContext(); context.setCurrentEvent(new Event("", "error")); request.setAttribute("flowRequestContext", context); ClientInfoHolder.setClientInfo(new ClientInfo(request)); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); getThrottle().preHandle(request, response, null); try { authenticationManager.authenticate(AuthenticationTransaction.wrap(TestUtils.getService(), badCredentials(username))); } catch (final AuthenticationException e) { getThrottle().postHandle(request, response, null, null); return response; } fail("Expected AbstractAuthenticationException"); return null; }
8. AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests#loginUnsuccessfully()
Project: passport
File: AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests.java
File: AbstractInMemoryThrottledSubmissionHandlerInterceptorAdapterTests.java
@Override protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setMethod("POST"); request.setParameter("username", username); request.setRemoteAddr(fromAddress); final MockRequestContext context = new MockRequestContext(); context.setCurrentEvent(new Event("", "error")); request.setAttribute("flowRequestContext", context); response.setStatus(HttpStatus.UNAUTHORIZED.value()); getThrottle().preHandle(request, response, null); getThrottle().postHandle(request, response, null, null); return response; }
9. SlashEndingUriTest#testFinalSlash()
Project: wink
File: SlashEndingUriTest.java
File: SlashEndingUriTest.java
// public void testFinalSlash() throws Exception { final String withSlash = "service/hello/collection/subcollection/"; final String withoutSlash = withSlash.substring(0, withSlash.length() - 1); MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", withSlash, "*/*"); MockHttpServletResponse response = invoke(request); assertEquals("should end with slash", "http://localhost:8080/rest/" + withSlash, response.getContentAsString()); MockHttpServletRequest request2 = MockRequestConstructor.constructMockRequest("GET", withoutSlash, "*/*"); MockHttpServletResponse response2 = invoke(request2); assertEquals("must not end with slash", "http://localhost:8080/rest/" + withoutSlash, response2.getContentAsString()); }
10. HeadTest#testHead()
Project: wink
File: HeadTest.java
File: HeadTest.java
public void testHead() throws Exception { MockHttpServletRequest getRequest = MockRequestConstructor.constructMockRequest("GET", PATH, "*/*"); MockHttpServletResponse getResponse = invoke(getRequest); assertEquals("get OK", HttpStatus.OK.getCode(), getResponse.getStatus()); assertEquals("get content", CONTENT, getResponse.getContentAsString()); MockHttpServletRequest headRequest = MockRequestConstructor.constructMockRequest("HEAD", PATH, "*/*"); MockHttpServletResponse headResponse = invoke(headRequest); assertEquals("head OK", HttpStatus.OK.getCode(), headResponse.getStatus()); assertEquals("content-type", getResponse.getContentType(), headResponse.getContentType()); assertEquals("content-length", CONTENT.length(), headResponse.getContentLength()); assertEquals("head content", "", headResponse.getContentAsString()); }
11. BaseUriDetectionTest#testDetection()
Project: wink
File: BaseUriDetectionTest.java
File: BaseUriDetectionTest.java
// class GetBaseUriResource public void testDetection() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/context/baseUri", "*/*"); request.setScheme("http"); request.setServerName("myServer"); request.setContextPath("/context"); request.setServerPort(9090); MockHttpServletResponse response = invoke(request); String content = response.getContentAsString(); assertEquals("base URI in content", "http://myServer:9090/context/", content); request = MockRequestConstructor.constructMockRequest("GET", "/con%20text/baseUri", "*/*"); request.setScheme("https"); request.setServerName("backupSrv"); request.setContextPath("/con%20text"); request.setServerPort(2); MockHttpServletResponse response2 = invoke(request); String content2 = response2.getContentAsString(); assertEquals("escaped base URI in content", "https://backupSrv:2/con%20text/", content2); }
12. HelloWorldTest#testHelloWorld()
Project: wink
File: HelloWorldTest.java
File: HelloWorldTest.java
public void testHelloWorld() throws Exception { // prepare a mock request and an empty mock response MockHttpServletRequest request = constructMockRequest("GET", "/world", MediaTypeUtils.ATOM_ENTRY); MockHttpServletResponse response = invoke(request); // check resulting mock response assertEquals("HTTP status", HttpStatus.OK.getCode(), response.getStatus()); /* * avoid a bug in the MockServletResponse#setContentType where it tries * to parse the charset there could be a * "text/plain;charset=UTF-8;otherParam=otherValue" but * MockServletResponse will treat charset as * "UTF-8;otherParam=otherValue" instead of just "UTF-8" */ String charset = MediaType.valueOf(response.getContentType()).getParameters().get("charset"); response.setCharacterEncoding(charset); AtomEntry entry = AtomEntry.unmarshal(new StringReader(response.getContentAsString())); String id = entry.getId(); assertEquals("entry id", HelloWorld.ID, id); }
13. PortletRendererImplTest#doServeResourceMarkupCaptureNegativeExpirationTime()
Project: uPortal
File: PortletRendererImplTest.java
File: PortletRendererImplTest.java
/** * No cached data exists, but mock a {@link CacheControl} with a negative value for expirationtime. * Will trigger the portletContainer#doServeResource, * capture the output, and give to the portlet cachecontrol service. * * negative value for cacheControl expiration time means "cache forever." * * @throws PortletException * @throws IOException * @throws PortletContainerException */ @Test public void doServeResourceMarkupCaptureNegativeExpirationTime() throws PortletException, IOException, PortletContainerException { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); response.setContentType("application/octet-stream"); TestingCacheState<CachedPortletResourceData<Long>, Long> cacheState = new TestingCacheState<CachedPortletResourceData<Long>, Long>(); CacheControl cacheControl = cacheState.getCacheControl(); cacheControl.setUseCachedContent(false); cacheControl.setExpirationTime(-1); setupPortletExecutionMocks(request); when(portletCacheControlService.getPortletResourceState(request, portletWindowId)).thenReturn(cacheState); when(portletCacheControlService.shouldOutputBeCached(cacheControl)).thenReturn(true); ResourcePortletOutputHandler handler = new ResourcePortletOutputHandler(response); portletRenderer.doServeResource(portletWindowId, request, response, handler); verify(portletCacheControlService, times(1)).getPortletResourceState(request, portletWindowId); verify(portletCacheControlService, times(1)).getCacheSizeThreshold(); verify(portletContainer, times(1)).doServeResource(eq(plutoPortletWindow), isA(PortletHttpServletRequestWrapper.class), isA(PortletResourceHttpServletResponseWrapper.class)); verify(portletCacheControlService, times(1)).shouldOutputBeCached(isA(CacheControl.class)); verifyNoMoreInteractions(portletContainer, portletCacheControlService); }
14. SimpleUrlAuthenticationSuccessHandlerTests#targetUrlParameterIsUsedIfPresentAndParameterNameIsSet()
Project: spring-security
File: SimpleUrlAuthenticationSuccessHandlerTests.java
File: SimpleUrlAuthenticationSuccessHandlerTests.java
/** * SEC-213 */ @Test public void targetUrlParameterIsUsedIfPresentAndParameterNameIsSet() throws Exception { SimpleUrlAuthenticationSuccessHandler ash = new SimpleUrlAuthenticationSuccessHandler("/defaultTarget"); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.setParameter("targetUrl", "/target"); ash.onAuthenticationSuccess(request, response, mock(Authentication.class)); assertThat(response.getRedirectedUrl()).isEqualTo("/defaultTarget"); // Try with parameter set ash.setTargetUrlParameter("targetUrl"); response = new MockHttpServletResponse(); ash.onAuthenticationSuccess(request, response, mock(Authentication.class)); assertThat(response.getRedirectedUrl()).isEqualTo("/target"); }
15. AbstractRememberMeServicesTests#logoutShouldCancelCookie()
Project: spring-security
File: AbstractRememberMeServicesTests.java
File: AbstractRememberMeServicesTests.java
@Test public void logoutShouldCancelCookie() throws Exception { MockRememberMeServices services = new MockRememberMeServices(uds); services.setCookieDomain("spring.io"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("contextpath"); request.setCookies(createLoginCookie("cookie:1:2")); MockHttpServletResponse response = new MockHttpServletResponse(); services.logout(request, response, Mockito.mock(Authentication.class)); // Try again with null Authentication response = new MockHttpServletResponse(); services.logout(request, response, null); assertCookieCancelled(response); Cookie returnedCookie = response.getCookie(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY); assertThat(returnedCookie.getDomain()).isEqualTo("spring.io"); }
16. AbstractRememberMeServicesTests#autoLoginShouldReturnNullIfNoLoginCookieIsPresented()
Project: spring-security
File: AbstractRememberMeServicesTests.java
File: AbstractRememberMeServicesTests.java
@Test public void autoLoginShouldReturnNullIfNoLoginCookieIsPresented() { MockRememberMeServices services = new MockRememberMeServices(uds); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); assertThat(services.autoLogin(request, response)).isNull(); // shouldn't try to invalidate our cookie assertThat(response.getCookie(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY)).isNull(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); // set non-login cookie request.setCookies(new Cookie("mycookie", "cookie")); assertThat(services.autoLogin(request, response)).isNull(); assertThat(response.getCookie(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY)).isNull(); }
17. SimpleUrlLogoutSuccessHandlerTests#doesntRedirectIfResponseIsCommitted()
Project: spring-security
File: SimpleUrlLogoutSuccessHandlerTests.java
File: SimpleUrlLogoutSuccessHandlerTests.java
@Test public void doesntRedirectIfResponseIsCommitted() throws Exception { SimpleUrlLogoutSuccessHandler lsh = new SimpleUrlLogoutSuccessHandler(); lsh.setDefaultTargetUrl("/target"); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); response.setCommitted(true); lsh.onLogoutSuccess(request, response, mock(Authentication.class)); assertThat(request.getSession(false)).isNull(); assertThat(response.getRedirectedUrl()).isNull(); assertThat(response.getForwardedUrl()).isNull(); }
18. CookieClearingLogoutHandlerTests#configuredCookiesAreCleared()
Project: spring-security
File: CookieClearingLogoutHandlerTests.java
File: CookieClearingLogoutHandlerTests.java
@Test public void configuredCookiesAreCleared() { MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("/app"); CookieClearingLogoutHandler handler = new CookieClearingLogoutHandler("my_cookie", "my_cookie_too"); handler.logout(request, response, mock(Authentication.class)); assertThat(response.getCookies().length).isEqualTo(2); for (Cookie c : response.getCookies()) { assertThat(c.getPath()).isEqualTo("/app"); assertThat(c.getMaxAge()).isEqualTo(0); } }
19. CookieClearingLogoutHandlerTests#emptyContextRootIsConverted()
Project: spring-security
File: CookieClearingLogoutHandlerTests.java
File: CookieClearingLogoutHandlerTests.java
// SEC-2036 @Test public void emptyContextRootIsConverted() { MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath(""); CookieClearingLogoutHandler handler = new CookieClearingLogoutHandler("my_cookie"); handler.logout(request, response, mock(Authentication.class)); assertThat(response.getCookies().length).isEqualTo(1); for (Cookie c : response.getCookies()) { assertThat(c.getPath()).isEqualTo("/"); assertThat(c.getMaxAge()).isEqualTo(0); } }
20. HttpPathParameterStrippingTests#adminFilePatternCannotBeBypassedByAddingPathParameters()
Project: spring-security
File: HttpPathParameterStrippingTests.java
File: HttpPathParameterStrippingTests.java
@Test public void adminFilePatternCannotBeBypassedByAddingPathParameters() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setServletPath("/secured/admin.html;x=user.html"); request.setSession(createAuthenticatedSession("ROLE_USER")); MockHttpServletResponse response = new MockHttpServletResponse(); fcp.doFilter(request, response, new MockFilterChain()); assertThat(response.getStatus()).isEqualTo(403); // Try with pathInfo request = new MockHttpServletRequest(); request.setServletPath("/secured"); request.setPathInfo("/admin.html;x=user.html"); request.setSession(createAuthenticatedSession("ROLE_USER")); response = new MockHttpServletResponse(); fcp.doFilter(request, response, new MockFilterChain()); assertThat(response.getStatus()).isEqualTo(403); }
21. WebDAVDocumentResourceTest#testNonExistingEntry()
Project: wink
File: WebDAVDocumentResourceTest.java
File: WebDAVDocumentResourceTest.java
public void testNonExistingEntry() throws Exception { // request String path = WebDAVCollectionResource.PATH + "/non-existing"; Propfind propfind = new Propfind(); propfind.setPropname(new Propname()); MockHttpServletRequest request = constructPropfindRequest(propfind, path, -1); MockHttpServletResponse response = invoke(request); // response Assert.assertEquals(HttpStatus.NOT_FOUND.getCode(), response.getStatus()); }
22. RegistrarTest#testRegistration()
Project: wink
File: RegistrarTest.java
File: RegistrarTest.java
public void testRegistration() throws Exception { MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/" + RESOURCE_PATH, MediaType.WILDCARD_TYPE); for (int i = 0; i < RESOURCE_INVOCATIONS; ++i) { MockHttpServletResponse mockResponse = invoke(mockRequest); assertEquals(HttpServletResponse.SC_OK, mockResponse.getStatus()); assertEquals(HELLO_FROM_RESOURCE, mockResponse.getContentAsString()); } assertEquals(RESOURCE_INVOCATIONS, resource_counter); mockRequest = MockRequestConstructor.constructMockRequest("GET", "/" + PATH, MediaType.WILDCARD_TYPE); MockHttpServletResponse mockResponse = invoke(mockRequest); assertEquals(HttpServletResponse.SC_OK, mockResponse.getStatus()); assertEquals(HELLO_2, mockResponse.getContentAsString()); assertEquals(1, provider_counter); }
23. LinksBuilderTest#testSystemLinksThroughSubResourceLocator()
Project: wink
File: LinksBuilderTest.java
File: LinksBuilderTest.java
public void testSystemLinksThroughSubResourceLocator() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/systemLinksThroughSubResourceLocator/sub1", MediaType.APPLICATION_ATOM_XML); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); request = MockRequestConstructor.constructMockRequest("GET", "/systemLinksThroughSubResourceLocator/sub1/sub2", MediaType.APPLICATION_ATOM_XML); response = invoke(request); assertEquals(200, response.getStatus()); }
24. ServiceabilityTest#testBadURLLogOutput1()
Project: wink
File: ServiceabilityTest.java
File: ServiceabilityTest.java
public void testBadURLLogOutput1() throws Exception { WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.INFO); MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/root/BAD", MediaType.TEXT_PLAIN); MockHttpServletResponse mockResponse = invoke(mockRequest); assertEquals(404, mockResponse.getStatus()); WinkLogHandler.turnLoggingCaptureOff(); List<LogRecord> records = WinkLogHandler.getRecords(); assertEquals(1, records.size()); assertEquals("The following error occurred during the invocation of the handlers chain: WebApplicationException (404 - Not Found) with message 'null' while processing GET request sent to http://localhost:80/root/BAD", records.get(0).getMessage()); // when NOT in debug mode, assertNull(records.get(0).getThrown()); // exception should NOT show up // in the debug trace }
25. ServiceabilityTest#testGoodURLLogOutput4()
Project: wink
File: ServiceabilityTest.java
File: ServiceabilityTest.java
public void testGoodURLLogOutput4() throws Exception { WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG); MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/root/2", MediaType.TEXT_PLAIN); MockHttpServletResponse mockResponse = invoke(mockRequest); assertEquals(200, mockResponse.getStatus()); assertEquals("some text 2", mockResponse.getContentAsString()); WinkLogHandler.turnLoggingCaptureOff(); List<LogRecord> records = WinkLogHandler.getRecords(); assertEquals(9, records.size()); assertEquals("Processing GET request to http://localhost:80/root/2, source content type is null, acceptable media types include text/plain", records.get(0).getMessage()); }
26. ServiceabilityTest#testGoodURLLogOutput3()
Project: wink
File: ServiceabilityTest.java
File: ServiceabilityTest.java
public void testGoodURLLogOutput3() throws Exception { WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG); MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/root", MediaType.TEXT_PLAIN); mockRequest.setQueryString("param1=value1"); MockHttpServletResponse mockResponse = invoke(mockRequest); assertEquals(200, mockResponse.getStatus()); assertEquals("some text", mockResponse.getContentAsString()); WinkLogHandler.turnLoggingCaptureOff(); List<LogRecord> records = WinkLogHandler.getRecords(); assertEquals(9, records.size()); assertEquals("Processing GET request to http://localhost:80/root?param1=value1, source content type is null, acceptable media types include text/plain", records.get(0).getMessage()); }
27. ServiceabilityTest#testGoodURLLogOutput2()
Project: wink
File: ServiceabilityTest.java
File: ServiceabilityTest.java
public void testGoodURLLogOutput2() throws Exception { WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG); MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/root", MediaType.TEXT_HTML); MockHttpServletResponse mockResponse = invoke(mockRequest); assertEquals(200, mockResponse.getStatus()); assertEquals("some html", mockResponse.getContentAsString()); WinkLogHandler.turnLoggingCaptureOff(); List<LogRecord> records = WinkLogHandler.getRecords(); assertEquals(9, records.size()); assertEquals("Processing GET request to http://localhost:80/root, source content type is null, acceptable media types include text/html", records.get(0).getMessage()); }
28. ServiceabilityTest#testGoodURLLogOutput1()
Project: wink
File: ServiceabilityTest.java
File: ServiceabilityTest.java
public void testGoodURLLogOutput1() throws Exception { WinkLogHandler.turnLoggingCaptureOn(WinkLogHandler.LEVEL.DEBUG); MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/root", MediaType.TEXT_PLAIN); MockHttpServletResponse mockResponse = invoke(mockRequest); assertEquals(200, mockResponse.getStatus()); assertEquals("some text", mockResponse.getContentAsString()); WinkLogHandler.turnLoggingCaptureOff(); List<LogRecord> records = WinkLogHandler.getRecords(); assertEquals(9, records.size()); assertEquals("Processing GET request to http://localhost:80/root, source content type is null, acceptable media types include text/plain", records.get(0).getMessage()); }
29. InfoNoMessageBodyWriter406Test#testLogNoWriterForMediaType()
Project: wink
File: InfoNoMessageBodyWriter406Test.java
File: InfoNoMessageBodyWriter406Test.java
public void testLogNoWriterForMediaType() throws Exception { List<LogRecord> records = handler.getRecords(); MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "noWriterForMediaType", MediaType.WILDCARD); MockHttpServletResponse response = invoke(request); assertEquals(406, response.getStatus()); assertEquals("", response.getContentAsString()); assertEquals(Level.SEVERE, records.get(5).getLevel()); assertEquals("The system could not find a javax.ws.rs.ext.MessageBodyWriter or a DataSourceProvider class for the javax.xml.transform.dom.DOMSource type and application/json mediaType. Ensure that a javax.ws.rs.ext.MessageBodyWriter exists in the JAX-RS application for the type and media type specified.", records.get(5).getMessage()); assertEquals(7, records.size()); }
30. InfoNoMessageBodyWriter406Test#testLogNoWriterForJavaType()
Project: wink
File: InfoNoMessageBodyWriter406Test.java
File: InfoNoMessageBodyWriter406Test.java
public void testLogNoWriterForJavaType() throws Exception { List<LogRecord> records = handler.getRecords(); MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "noWriterForJavaType", MediaType.WILDCARD); MockHttpServletResponse response = invoke(request); assertEquals(406, response.getStatus()); assertEquals("", response.getContentAsString()); assertEquals(Level.SEVERE, records.get(5).getLevel()); assertTrue(records.get(5).getMessage().indexOf("The system could not find a javax.ws.rs.ext.MessageBodyWriter or a DataSourceProvider class for the org.apache.wink.server.serviceability.InfoNoMessageBodyWriter406Test$MyObject type and") != -1 && records.get(5).getMessage().indexOf("Ensure that a javax.ws.rs.ext.MessageBodyWriter exists in the JAX-RS application for the type and media type specified.") != -1); assertEquals(7, records.size()); }
31. DebugNoMessageBodyWriter406Test#testLogNoWriterForJavaType()
Project: wink
File: DebugNoMessageBodyWriter406Test.java
File: DebugNoMessageBodyWriter406Test.java
public void testLogNoWriterForJavaType() throws Exception { List<LogRecord> records = handler.getRecords(); MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "noWriterForJavaType", MediaType.WILDCARD); MockHttpServletResponse response = invoke(request); assertEquals(406, response.getStatus()); assertEquals("", response.getContentAsString()); assertEquals(Level.SEVERE, records.get(21).getLevel()); assertTrue(records.get(21).getMessage().indexOf("The system could not find a javax.ws.rs.ext.MessageBodyWriter or a DataSourceProvider class for the org.apache.wink.server.serviceability.DebugNoMessageBodyWriter406Test$MyObject type and") != -1 && records.get(21).getMessage().indexOf("mediaType. Ensure that a javax.ws.rs.ext.MessageBodyWriter exists in the JAX-RS application for the type and media type specified.") != -1); assertEquals(30, records.size()); }
32. WebSphereParametersTest#testPostParametersFilter()
Project: wink
File: WebSphereParametersTest.java
File: WebSphereParametersTest.java
/* * Test POST (+GET) parameters. */ public void testPostParametersFilter() throws Exception { // create mock servlet objects MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("POST"); request.setQueryString("a&b=&c=1&c=2"); request.setContentType(WebSphereParametersFilter.CONTENT_TYPE_WWW_FORM_URLENCODED); request.setContent("d&e=&f=1&f=2".getBytes()); MockHttpServletResponse response = new MockHttpServletResponse(); MockFilterChain chain = new MockFilterChain(); // test query parameters before parsing assertEquals("Query parameters are not empty before parsing", 0, request.getParameterMap().size()); // invoke filter new WebSphereParametersFilter().doFilter(request, response, chain); // test query and POST parameters assertEquals("There are not 6 query parameters", 6, chain.getRequest().getParameterMap().size()); assertParameters(chain.getRequest(), "a", "b", "c"); assertParameters(chain.getRequest(), "d", "e", "f"); }
33. WebSphereParametersTest#testGetParametersFilter()
Project: wink
File: WebSphereParametersTest.java
File: WebSphereParametersTest.java
/* * Test GET parameters. */ public void testGetParametersFilter() throws Exception { // create mock servlet objects MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.setQueryString("a&b=&c=1&c=2"); MockHttpServletResponse response = new MockHttpServletResponse(); MockFilterChain chain = new MockFilterChain(); // test query parameters before parsing assertEquals("Query parameters are not empty before parsing", 0, request.getParameterMap().size()); // invoke filter new WebSphereParametersFilter().doFilter(request, response, chain); // test query parameters assertEquals("There are not 3 query parameters", 3, chain.getRequest().getParameterMap().size()); assertParameters(chain.getRequest(), "a", "b", "c"); }
34. StreamResponseTest#testStreamResponse()
Project: wink
File: StreamResponseTest.java
File: StreamResponseTest.java
// public void testStreamResponse() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "path", MediaTypeUtils.IMAGE_JPEG_TYPE); MockHttpServletResponse response = invoke(request); byte[] responseBytes = response.getContentAsByteArray(); assertEquals("len", BYTES.length, responseBytes.length); for (int pos = 0; pos < BYTES.length; pos++) { assertEquals("byte " + pos, BYTES[pos], responseBytes[pos]); } }
35. SlashEndingUriTest#testSeveralSlashes()
Project: wink
File: SlashEndingUriTest.java
File: SlashEndingUriTest.java
public void testSeveralSlashes() throws Exception { final String withSlash = "service/hello/collection/subcollection/"; final String withSlash2 = withSlash + "/"; final String withSlash3 = withSlash2 + "/"; final String withSlash4 = withSlash3 + "/"; MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", withSlash2, "*/*"); final String requestUriWithSlash = "http://localhost:8080/rest/" + withSlash; MockHttpServletResponse response = invoke(request); assertEquals("should end with slash", requestUriWithSlash, response.getContentAsString()); request = MockRequestConstructor.constructMockRequest("GET", withSlash3, "*/*"); response = invoke(request); assertEquals("should end with slash", requestUriWithSlash, response.getContentAsString()); request = MockRequestConstructor.constructMockRequest("GET", withSlash4, "*/*"); response = invoke(request); assertEquals("should end with slash", requestUriWithSlash, response.getContentAsString()); }
36. RequestsTest#testMultipleEncoding()
Project: wink
File: RequestsTest.java
File: RequestsTest.java
public void testMultipleEncoding() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/root/encoding", MediaType.TEXT_PLAIN); request.addHeader(HttpHeaders.ACCEPT_ENCODING, "gzip;q=0.8,deflate;q=0.7"); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals(MediaType.TEXT_PLAIN, response.getContentType()); assertEquals("gzip", response.getHeader(HttpHeaders.CONTENT_ENCODING)); assertEquals(HttpHeaders.ACCEPT_ENCODING, response.getHeader(HttpHeaders.VARY)); request = MockRequestConstructor.constructMockRequest("GET", "/root/encoding", MediaType.TEXT_PLAIN); request.addHeader(HttpHeaders.ACCEPT_ENCODING, "deflate;q=0.8,gzip;q=0.7"); response = invoke(request); assertEquals(200, response.getStatus()); assertEquals(MediaType.TEXT_PLAIN, response.getContentType()); assertEquals("deflate", response.getHeader(HttpHeaders.CONTENT_ENCODING)); assertEquals(HttpHeaders.ACCEPT_ENCODING, response.getHeader(HttpHeaders.VARY)); }
37. RequestsTest#testMultipleLanguagesSelect()
Project: wink
File: RequestsTest.java
File: RequestsTest.java
public void testMultipleLanguagesSelect() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/root/language", MediaType.TEXT_PLAIN); request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, "en;q=0.6,fr;q=0.5"); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals(MediaType.TEXT_PLAIN, response.getContentType()); assertEquals("en", response.getHeader(HttpHeaders.CONTENT_LANGUAGE)); assertEquals(HttpHeaders.ACCEPT_LANGUAGE, response.getHeader(HttpHeaders.VARY)); request = MockRequestConstructor.constructMockRequest("GET", "/root/language", MediaType.TEXT_PLAIN); request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, "en;q=0.6,fr;q=0.7"); response = invoke(request); assertEquals(200, response.getStatus()); assertEquals(MediaType.TEXT_PLAIN, response.getContentType()); assertEquals("fr", response.getHeader(HttpHeaders.CONTENT_LANGUAGE)); assertEquals(HttpHeaders.ACCEPT_LANGUAGE, response.getHeader(HttpHeaders.VARY)); }
38. RequestsTest#testSimpleLanguagesSelect()
Project: wink
File: RequestsTest.java
File: RequestsTest.java
public void testSimpleLanguagesSelect() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/root/language", MediaType.TEXT_PLAIN); request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, "en"); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals(MediaType.TEXT_PLAIN, response.getContentType()); assertEquals("en", response.getHeader(HttpHeaders.CONTENT_LANGUAGE)); assertEquals(HttpHeaders.ACCEPT_LANGUAGE, response.getHeader(HttpHeaders.VARY)); assertNull(response.getHeader(HttpHeaders.CONTENT_ENCODING)); request = MockRequestConstructor.constructMockRequest("GET", "/root/language", MediaType.TEXT_PLAIN); request.addHeader(HttpHeaders.ACCEPT_LANGUAGE, "fr"); response = invoke(request); assertEquals(200, response.getStatus()); assertEquals(MediaType.TEXT_PLAIN, response.getContentType()); assertEquals("fr", response.getHeader(HttpHeaders.CONTENT_LANGUAGE)); assertEquals(HttpHeaders.ACCEPT_LANGUAGE, response.getHeader(HttpHeaders.VARY)); assertNull(response.getHeader(HttpHeaders.CONTENT_ENCODING)); }
39. ResponseDispatchTest#testPut()
Project: wink
File: ResponseDispatchTest.java
File: ResponseDispatchTest.java
// class ResponseResource public void testPut() throws Exception { MockHttpServletRequest servletRequest = MockRequestConstructor.constructMockRequest("PUT", "a", "*/*"); servletRequest.setContentType("text/xml"); MockHttpServletResponse response = invoke(servletRequest); assertEquals("status", 201, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier("<entry xmlns=\"http://www.w3.org/2005/Atom\"/>", response.getContentAsString().trim()); assertNull(msg, msg); }
40. FindResourceMethod2Test#testContinuedSearch_3_2()
Project: wink
File: FindResourceMethod2Test.java
File: FindResourceMethod2Test.java
public void testContinuedSearch_3_2() throws Exception { MockHttpServletRequest request = null; MockHttpServletResponse response = null; // 3.2. make sure that ContinuedSearchResource is reachable when // continued search policy is activated request = MockRequestConstructor.constructMockRequest("PUT", "/continuedSearchResourceLocatorBad/1/2", "text/plain", "text/plain", null); response = invoke(request); FindResourceMethodTest.assertMethodFound(response, FindResourceMethod1Test.LocatedContinuedSearchResource.class, "subPut"); }
41. FindResourceMethod2Test#testContinuedSearch_2_2()
Project: wink
File: FindResourceMethod2Test.java
File: FindResourceMethod2Test.java
public void testContinuedSearch_2_2() throws Exception { MockHttpServletRequest request = null; MockHttpServletResponse response = null; // 2.2. make sure that ContinuedSearchResource is reachable when // continued search policy is activated request = MockRequestConstructor.constructMockRequest("PUT", "/subResourceMethodSimpleGet/1", "text/plain", "text/plain", null); response = invoke(request); FindResourceMethodTest.assertMethodFound(response, FindResourceMethod1Test.ContinuedSearchResource.class, "subPut"); }
42. FindResourceMethod2Test#testContinuedSearch_1_2()
Project: wink
File: FindResourceMethod2Test.java
File: FindResourceMethod2Test.java
public void testContinuedSearch_1_2() throws Exception { MockHttpServletRequest request = null; MockHttpServletResponse response = null; // 1.2. make sure that ContinuedSearchResource is reachable when // continued search policy is activated request = MockRequestConstructor.constructMockRequest("PUT", "/simpleGet", "text/plain", "text/plain", null); response = invoke(request); FindResourceMethodTest.assertMethodFound(response, FindResourceMethod1Test.ContinuedSearchResource.class, "put"); }
43. FindResourceMethod1Test#testContinuedSearch_3_1()
Project: wink
File: FindResourceMethod1Test.java
File: FindResourceMethod1Test.java
public void testContinuedSearch_3_1() throws Exception { MockHttpServletRequest request = null; MockHttpServletResponse response = null; // 3. test sub-resource locator // 3.1. negative test - make sure that ContinuedSearchResource is not // reachable when continued search policy is off request = MockRequestConstructor.constructMockRequest("PUT", "/continuedSearchResourceLocatorBad/1/2", "text/plain", "text/plain", null); response = invoke(request); assertEquals(405, response.getStatus()); }
44. FindResourceMethod1Test#testContinuedSearch_2_1()
Project: wink
File: FindResourceMethod1Test.java
File: FindResourceMethod1Test.java
public void testContinuedSearch_2_1() throws Exception { MockHttpServletRequest request = null; MockHttpServletResponse response = null; // 2. test sub-resource method // 2.1. negative test - make sure that ContinuedSearchResource is not // reachable when continued search policy is off request = MockRequestConstructor.constructMockRequest("PUT", "/subResourceMethodSimpleGet/1", "text/plain", "text/plain", null); response = invoke(request); assertEquals(405, response.getStatus()); }
45. FindResourceMethod1Test#testContinuedSearch_1_1()
Project: wink
File: FindResourceMethod1Test.java
File: FindResourceMethod1Test.java
// /// -- Tests -- public void testContinuedSearch_1_1() throws Exception { MockHttpServletRequest request = null; MockHttpServletResponse response = null; // 1. test resource method // 1.1. negative test - make sure that ContinuedSearchResource is not // reachable when continued search policy is off request = MockRequestConstructor.constructMockRequest("PUT", "/simpleGet", "text/plain", "text/plain", null); response = invoke(request); assertEquals(405, response.getStatus()); }
46. DefaultValueTest#testAll()
Project: wink
File: DefaultValueTest.java
File: DefaultValueTest.java
public void testAll() throws Exception { MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/a", MediaType.TEXT_PLAIN); MockHttpServletResponse mockResponse = invoke(mockRequest); assertEquals(200, mockResponse.getStatus()); assertEquals("null:" + DEFAULT_VALUE + ":[]:[" + DEFAULT_VALUE + "]:12345:0", mockResponse.getContentAsString()); // Test @DefaultValue on method mockRequest = MockRequestConstructor.constructMockRequest("GET", "/a", MediaType.TEXT_HTML); mockResponse = invoke(mockRequest); assertEquals(200, mockResponse.getStatus()); assertEquals("null:" + DEFAULT_VALUE + ":[]:[" + DEFAULT_VALUE + "]:98765:98765", mockResponse.getContentAsString()); }
47. SourceProviderTest#testSaxWithDTD()
Project: wink
File: SourceProviderTest.java
File: SourceProviderTest.java
public void testSaxWithDTD() throws Exception { String path = getPath(); final String SOURCE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE data [<!ENTITY file SYSTEM \"" + path + "/etc/SourceProviderTest.txt\">]>" + "<message>&file;</message>"; final byte[] SOURCE_BYTES = SOURCE.getBytes(); MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/source/saxwithdtd", "application/xml", "application/xml", SOURCE_BYTES); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertFalse("File content is visible but should not be.", response.getContentAsString().contains("YOU SHOULD NOT BE ABLE TO SEE THIS")); assertEquals(SOURCE, response.getContentAsString().trim()); }
48. SourceProviderDTDSupportedTest#testDomWithDTDSupported()
Project: wink
File: SourceProviderDTDSupportedTest.java
File: SourceProviderDTDSupportedTest.java
public void testDomWithDTDSupported() throws Exception { final byte[] SOURCE_BYTES = SOURCE.getBytes(); MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/source/domwithdtd", "application/xml", "application/xml", SOURCE_BYTES); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals("YOU SHOULD NOT BE ABLE TO SEE THIS", response.getContentAsString().trim()); // as a sanity check, let's make sure our xml is good: DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(SOURCE)); Document d = builder.parse(is); assertEquals("xml is bad", "YOU SHOULD NOT BE ABLE TO SEE THIS", d.getElementsByTagName("message").item(0).getTextContent().trim()); }
49. JAXBUnmarshalOptionsTest#testGenericEntityAnnotatedJAXB()
Project: wink
File: JAXBUnmarshalOptionsTest.java
File: JAXBUnmarshalOptionsTest.java
public void testGenericEntityAnnotatedJAXB() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/root", MediaType.APPLICATION_XML, MediaType.APPLICATION_XML, /* * note order of elements matter for test */ ("<bookstore>" + "<bookLink idref=\"abcd\"/>" + "<authorLink idref=\"abcd\"/>" + "<book id=\"abcd\"/>" + "<author id=\"abcd\"/>" + "<book id=\"lmnop\"/>" + "<bookLink idref=\"lmnop\"/>" + "</bookstore>").getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals("hello", response.getContentAsString()); }
50. JAXBUnmarshalNoOptionsTest#testGenericEntityAnnotatedJAXB()
Project: wink
File: JAXBUnmarshalNoOptionsTest.java
File: JAXBUnmarshalNoOptionsTest.java
public void testGenericEntityAnnotatedJAXB() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/root", MediaType.APPLICATION_XML, MediaType.APPLICATION_XML, /* * note order of elements matter for test */ ("<bookstore>" + "<bookLink idref=\"abcd\"/>" + "<authorLink idref=\"abcd\"/>" + "<book id=\"abcd\"/>" + "<author id=\"abcd\"/>" + "<book id=\"lmnop\"/>" + "<bookLink idref=\"lmnop\"/>" + "</bookstore>").getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals("hello", response.getContentAsString()); }
51. JAXBProvidersWithXmlAdapterTest#testCollection()
Project: wink
File: JAXBProvidersWithXmlAdapterTest.java
File: JAXBProvidersWithXmlAdapterTest.java
public void testCollection() throws Exception { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<addNumberss>" + "<addNumbers><arg0>2</arg0><arg1>3</arg1></addNumbers>" + "<addNumbers><arg0>4</arg0><arg1>5</arg1></addNumbers>" + "</addNumberss>"; MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/jaxbelementcollection", MediaType.APPLICATION_XML, MediaType.APPLICATION_XML, xml.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); // make sure the round trip really was successful assertEquals(xml, response.getContentAsString()); // make sure the adapter was called the right number of times assertEquals(2, adapterMarshalMethodCalled); assertEquals(2, adapterUnmarshalMethodCalled); }
52. JAXBProvidersWithXmlAdapterTest#testArray()
Project: wink
File: JAXBProvidersWithXmlAdapterTest.java
File: JAXBProvidersWithXmlAdapterTest.java
public void testArray() throws Exception { String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<addNumberss>" + "<addNumbers><arg0>2</arg0><arg1>3</arg1></addNumbers>" + "<addNumbers><arg0>4</arg0><arg1>5</arg1></addNumbers>" + "</addNumberss>"; MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/jaxbelementarray", MediaType.APPLICATION_XML, MediaType.APPLICATION_XML, xml.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); // make sure the round trip really was successful assertEquals(xml, response.getContentAsString()); // make sure the adapter was called the right number of times assertEquals(2, adapterMarshalMethodCalled); assertEquals(2, adapterUnmarshalMethodCalled); }
53. JAXBProviderInheritanceTest#testGenericEntityNotAnnotatedJAXB()
Project: wink
File: JAXBProviderInheritanceTest.java
File: JAXBProviderInheritanceTest.java
public void testGenericEntityNotAnnotatedJAXB() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/jaxbresourceinherited/getnotannotated", MediaType.APPLICATION_XML); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); ByteArrayInputStream bais = new ByteArrayInputStream(response.getContentAsByteArray()); JAXBContext context = JAXBContext.newInstance(new Class[] { AddIntsAnnotated.class, AddNumbers.class }); Unmarshaller unmarshaller = context.createUnmarshaller(); // JAXB cannot unmarshal to AddIntsNotAnnotated because there is no @XmlRootElement annotation on it, so... AddNumbers addNumbers = (AddNumbers) unmarshaller.unmarshal(bais); assertEquals(15, addNumbers.getArg0()); assertEquals(16, addNumbers.getArg1()); }
54. JAXBProviderInheritanceTest#testGenericEntityAnnotatedJAXB()
Project: wink
File: JAXBProviderInheritanceTest.java
File: JAXBProviderInheritanceTest.java
public void testGenericEntityAnnotatedJAXB() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/jaxbresourceinherited/getannotated", MediaType.APPLICATION_XML); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); ByteArrayInputStream bais = new ByteArrayInputStream(response.getContentAsByteArray()); JAXBContext context = JAXBContext.newInstance(AddIntsAnnotated.class); Unmarshaller unmarshaller = context.createUnmarshaller(); AddIntsAnnotated addInts = (AddIntsAnnotated) unmarshaller.unmarshal(bais); assertEquals(11, addInts.getArg0()); assertEquals(12, addInts.getArg1()); }
55. JAXBProviderInheritanceTest#testInheritance()
Project: wink
File: JAXBProviderInheritanceTest.java
File: JAXBProviderInheritanceTest.java
public void testInheritance() throws Exception { AddIntsAnnotated addInts = new AddIntsAnnotated(); addInts.setArg0(2); addInts.setArg1(3); // JAXBContext can handle inherited types JAXBContext context = JAXBContext.newInstance(AddIntsAnnotated.class); Marshaller marshaller = context.createMarshaller(); Writer writer = new StringWriter(); marshaller.marshal(addInts, writer); MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresourceinherited/jaxbelement", MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML, writer.toString().getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals("5", response.getContentAsString()); }
56. JAXBProviderInheritanceTest#testNormal()
Project: wink
File: JAXBProviderInheritanceTest.java
File: JAXBProviderInheritanceTest.java
public void testNormal() throws Exception { AddNumbers addNumbers = new AddNumbers(); addNumbers.setArg0(2); addNumbers.setArg1(3); JAXBContext context = JAXBContext.newInstance(AddNumbers.class); Marshaller marshaller = context.createMarshaller(); Writer writer = new StringWriter(); marshaller.marshal(addNumbers, writer); MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/jaxbelement", MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML, writer.toString().getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals("5", response.getContentAsString()); }
57. JAXBNoEntityLogTest#testNoEntityRefLog()
Project: wink
File: JAXBNoEntityLogTest.java
File: JAXBNoEntityLogTest.java
/** * Tests that a Provider is logged at the debug level. */ public void testNoEntityRefLog() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "res1", MediaType.WILDCARD, MediaType.APPLICATION_XML, "".getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(400, response.getStatus()); assertEquals(0, handler.getRecords().size()); }
58. JAXBElementProviderTest#testJAXBXmlElementProviderInvocationXmlAsset()
Project: wink
File: JAXBElementProviderTest.java
File: JAXBElementProviderTest.java
public void testJAXBXmlElementProviderInvocationXmlAsset() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmlasset", "text/xml", "text/xml", JAXBXmlType_REQUEST_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlType_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
59. JAXBElementProviderTest#testJAXBXmlElementProviderInvocationXmlRoot()
Project: wink
File: JAXBElementProviderTest.java
File: JAXBElementProviderTest.java
public void testJAXBXmlElementProviderInvocationXmlRoot() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmlrootnofactory", "text/xml", "text/xml", JAXBXmlRootElement_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlRootElement_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmlrootnofactory", "text/xml", "text/xml", "<BadRequest/>".getBytes()); invoke = invoke(request); assertEquals(400, invoke.getStatus()); }
60. JAXBElementProviderTest#testJAXBXmlElementProviderInvocationXmltype()
Project: wink
File: JAXBElementProviderTest.java
File: JAXBElementProviderTest.java
public void testJAXBXmlElementProviderInvocationXmltype() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmltype", "text/xml", "text/xml", JAXBXmlType_REQUEST_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlType_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
61. JAXBElementProviderTest#testJAXBXmlElementProviderInvocationXmltypeNoFactory()
Project: wink
File: JAXBElementProviderTest.java
File: JAXBElementProviderTest.java
public void testJAXBXmlElementProviderInvocationXmltypeNoFactory() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/jaxbresource/xmltypenofactory", "text/xml", "text/xml", null); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlType_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
62. JAXBElementProviderTest#testJAXBXmlElementProviderInvocation()
Project: wink
File: JAXBElementProviderTest.java
File: JAXBElementProviderTest.java
@SuppressWarnings("unchecked") public void testJAXBXmlElementProviderInvocation() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmlrootwithfactory", "text/xml", "text/xml", SOURCE_REQUEST_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); JAXBContext context = JAXBContext.newInstance(AtomFeed.class); Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement<AtomFeed> expectedResponse = (JAXBElement<AtomFeed>) unmarshaller.unmarshal(new ByteArrayInputStream(SOURCE_RESPONSE.getBytes())); JAXBElement<AtomFeed> response = (JAXBElement<AtomFeed>) unmarshaller.unmarshal(new ByteArrayInputStream(invoke.getContentAsByteArray())); assertEquals(expectedResponse.getValue().getId(), response.getValue().getId()); }
63. JAXBElementProviderTest#testJAXBElementProviderInvocation()
Project: wink
File: JAXBElementProviderTest.java
File: JAXBElementProviderTest.java
@SuppressWarnings("unchecked") public void testJAXBElementProviderInvocation() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/jaxbelement", "text/xml", "text/xml", SOURCE_REQUEST_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); JAXBContext context = JAXBContext.newInstance(AtomFeed.class); Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement<AtomFeed> expectedResponse = (JAXBElement<AtomFeed>) unmarshaller.unmarshal(new ByteArrayInputStream(SOURCE_RESPONSE.getBytes())); JAXBElement<AtomFeed> response = (JAXBElement<AtomFeed>) unmarshaller.unmarshal(new ByteArrayInputStream(invoke.getContentAsByteArray())); assertEquals(expectedResponse.getValue().getId(), response.getValue().getId()); }
64. JAXBElementProviderCustomNSTest#testJAXBElementFeedProviderInvocationCacheCheck()
Project: wink
File: JAXBElementProviderCustomNSTest.java
File: JAXBElementProviderCustomNSTest.java
public void testJAXBElementFeedProviderInvocationCacheCheck() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/jaxbfeed", "text/xml", "text/xml", SOURCE_FEED_REQUEST_BYTES); MyApp2 myApp2 = new MyApp2(); myApp2.setUp(); MockHttpServletResponse invoke = myApp2.invoke(request); assertEquals(200, invoke.getStatus()); // make sure the MyXmlFormattingOptionsResolver DOES NOT MODIFY the message in MyApp2. MyApp2 is a // unique Application subclass. The ContextResolver registered under MyApp1 should not affect MyApp2. // we're checking to make sure the cache of marshallers/unmarshallers in AbstractJAXBProvider String responseAsString = invoke.getContentAsString(); assertFalse(responseAsString.contains(customNSPrefix)); }
65. JAXBElementProviderCustomNSTest#testJAXBElementFeedProviderInvocation()
Project: wink
File: JAXBElementProviderCustomNSTest.java
File: JAXBElementProviderCustomNSTest.java
public void testJAXBElementFeedProviderInvocation() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/jaxbfeed", "text/xml", "text/xml", SOURCE_FEED_REQUEST_BYTES); MyApp1 myApp1 = new MyApp1(); myApp1.setUp(); MockHttpServletResponse invoke = myApp1.invoke(request); assertEquals(200, invoke.getStatus()); // make sure the MyXmlFormattingOptionsResolver had the intended effect String responseAsString = invoke.getContentAsString(); assertTrue(responseAsString.contains("myCustomNSPrefix")); }
66. JAXBCollectionXMLProviderTest#testXmlRootArray()
Project: wink
File: JAXBCollectionXMLProviderTest.java
File: JAXBCollectionXMLProviderTest.java
public void testXmlRootArray() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmlrootnofactoryarray", "text/xml", "text/xml", JAXBXmlRootElement_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlRootElement_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
67. JAXBCollectionXMLProviderTest#testXmlRootCollection()
Project: wink
File: JAXBCollectionXMLProviderTest.java
File: JAXBCollectionXMLProviderTest.java
public void testXmlRootCollection() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmlrootnofactorycollection", "text/xml", "text/xml", JAXBXmlRootElement_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlRootElement_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
68. JAXBCollectionXMLProviderTest#testXMLTypeArray()
Project: wink
File: JAXBCollectionXMLProviderTest.java
File: JAXBCollectionXMLProviderTest.java
public void testXMLTypeArray() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmltypearray", "text/xml", "text/xml", JAXBXmlType_REQUEST_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlType_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
69. JAXBCollectionXMLProviderTest#testXMLTypeCollection()
Project: wink
File: JAXBCollectionXMLProviderTest.java
File: JAXBCollectionXMLProviderTest.java
public void testXMLTypeCollection() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/jaxbresource/xmltypecollection", "text/xml", "text/xml", JAXBXmlType_REQUEST_BYTES); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); System.out.println(invoke.getContentAsString()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlType_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
70. JAXBCollectionXMLProviderTest#testXMLTypeNoFactoryArray()
Project: wink
File: JAXBCollectionXMLProviderTest.java
File: JAXBCollectionXMLProviderTest.java
public void testXMLTypeNoFactoryArray() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/jaxbresource/xmltypenofactoryarray", "text/xml", "text/xml", null); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlType_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
71. JAXBCollectionXMLProviderTest#testXMLTypeNoFactoryCollection()
Project: wink
File: JAXBCollectionXMLProviderTest.java
File: JAXBCollectionXMLProviderTest.java
public void testXMLTypeNoFactoryCollection() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/jaxbresource/xmltypenofactorycollection", "text/xml", "text/xml", null); MockHttpServletResponse invoke = invoke(request); assertEquals(200, invoke.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(JAXBXmlType_RESPONSE, invoke.getContentAsString()); assertNull(msg, msg); }
72. InheritedProviderAnnTest#testInheritedProvider()
Project: wink
File: InheritedProviderAnnTest.java
File: InheritedProviderAnnTest.java
/** * Tests that a {@link Provider} can be inherited from the superclass. While * this is not required by the specification, it is in order to promote * better compatibility with providers (i.e. Jackson) that expected this * behavior. * * @throws Exception */ public void testInheritedProvider() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/string", MediaType.TEXT_PLAIN); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); assertEquals("hello", response.getContentAsString()); request = MockRequestConstructor.constructMockRequest("GET", "/string", "abcd/efgh"); response = invoke(request); assertEquals(200, response.getStatus()); assertEquals("child", response.getContentAsString()); }
73. FormMultivaluedMapProviderTest#testFormMultivaluedMapInvocation()
Project: wink
File: FormMultivaluedMapProviderTest.java
File: FormMultivaluedMapProviderTest.java
public void testFormMultivaluedMapInvocation() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/form", MediaType.APPLICATION_FORM_URLENCODED, MediaType.APPLICATION_FORM_URLENCODED, FORM_BYTES); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); // all parameter values should be in lower case assertEquals(FORM.toLowerCase(), response.getContentAsString()); }
74. AtomFeedProviderTest#testPostAtomSyndFeed()
Project: wink
File: AtomFeedProviderTest.java
File: AtomFeedProviderTest.java
public void testPostAtomSyndFeed() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomsyndfeed", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(FEED.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(FEED, response.getContentAsString()); assertNull(msg, msg); }
75. AtomFeedProviderTest#testPostAtomFeedElement()
Project: wink
File: AtomFeedProviderTest.java
File: AtomFeedProviderTest.java
public void testPostAtomFeedElement() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomfeedelement", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(FEED.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(FEED, response.getContentAsString()); assertNull(msg, msg); }
76. AtomFeedProviderTest#testPostAtomFeed()
Project: wink
File: AtomFeedProviderTest.java
File: AtomFeedProviderTest.java
public void testPostAtomFeed() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomfeed", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(FEED.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(FEED, response.getContentAsString()); assertNull(msg, msg); }
77. AtomEntryProviderTest#testPostAtomSyndEntry()
Project: wink
File: AtomEntryProviderTest.java
File: AtomEntryProviderTest.java
public void testPostAtomSyndEntry() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomsyndentry", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(ENTRY.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString()); assertNull(msg, msg); }
78. AtomEntryProviderTest#testPostAtomEntryElement()
Project: wink
File: AtomEntryProviderTest.java
File: AtomEntryProviderTest.java
public void testPostAtomEntryElement() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomentryelement", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(ENTRY.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString()); assertNull(msg, msg); }
79. AtomEntryProviderTest#testPostAtomEntry()
Project: wink
File: AtomEntryProviderTest.java
File: AtomEntryProviderTest.java
public void testPostAtomEntry() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomentry", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(ENTRY.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString()); assertNull(msg, msg); }
80. AtomEntryInResponseProviderTest#testPostAtomSyndEntry()
Project: wink
File: AtomEntryInResponseProviderTest.java
File: AtomEntryInResponseProviderTest.java
public void testPostAtomSyndEntry() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomsyndentry", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(ENTRY.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString()); assertNull(msg, msg); }
81. AtomEntryInResponseProviderTest#testPostAtomEntryElement()
Project: wink
File: AtomEntryInResponseProviderTest.java
File: AtomEntryInResponseProviderTest.java
public void testPostAtomEntryElement() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomentryelement", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(ENTRY.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString()); assertNull(msg, msg); }
82. AtomEntryInResponseProviderTest#testPostAtomEntry()
Project: wink
File: AtomEntryInResponseProviderTest.java
File: AtomEntryInResponseProviderTest.java
public void testPostAtomEntry() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test/atomentry", "application/atom+xml"); request.setContentType("application/atom+xml"); request.setContent(ENTRY.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(ENTRY, response.getContentAsString()); assertNull(msg, msg); }
83. AssetProviderTest#testAssetPostStringGetXml()
Project: wink
File: AssetProviderTest.java
File: AssetProviderTest.java
public void testAssetPostStringGetXml() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test", "application/xml", "text/plain", STRING.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(XML, response.getContentAsString()); assertNull(msg, msg); }
84. AssetProviderTest#testAssetPostXmlGetXml()
Project: wink
File: AssetProviderTest.java
File: AssetProviderTest.java
public void testAssetPostXmlGetXml() throws Exception { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("POST", "/test", "application/xml", "application/xml", XML.getBytes()); MockHttpServletResponse response = invoke(request); assertEquals(200, response.getStatus()); String msg = TestUtils.diffIgnoreUpdateWithAttributeQualifier(XML, response.getContentAsString()); assertNull(msg, msg); }
85. PreconditionsTest#testConditionalIfNotUnModified()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
public void testConditionalIfNotUnModified() throws Exception { Date date_to_return = new GregorianCalendar(2007, 11, 07, 10, 0, 0).getTime(); Date modified_since = new GregorianCalendar(2007, 11, 06, 10, 0, 0).getTime(); // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + String.valueOf(date_to_return.getTime()), "*/*"); request.addHeader(HttpHeaders.IF_UNMODIFIED_SINCE, HttpDateParser.toHttpDate(modified_since)); MockHttpServletResponse response = invoke(request); assertEquals("status", 412, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + String.valueOf(date_to_return.getTime()), "*/*"); request.addHeader(HttpHeaders.IF_UNMODIFIED_SINCE, HttpDateParser.toHttpDate(modified_since)); response = invoke(request); assertEquals("status", 412, response.getStatus()); }
86. PreconditionsTest#testConditionalIfUnModified()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
public void testConditionalIfUnModified() throws Exception { Date date_to_return = new GregorianCalendar(2007, 11, 06, 10, 0, 0).getTime(); Date modified_since = new GregorianCalendar(2007, 11, 07, 10, 0, 0).getTime(); // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + String.valueOf(date_to_return.getTime()), "*/*"); request.addHeader(HttpHeaders.IF_UNMODIFIED_SINCE, HttpDateParser.toHttpDate(modified_since)); MockHttpServletResponse response = invoke(request); assertEquals("status", 200, response.getStatus()); assertEquals("content", THE_CONTENT, response.getContentAsString()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + String.valueOf(date_to_return.getTime()), "*/*"); request.addHeader(HttpHeaders.IF_UNMODIFIED_SINCE, HttpDateParser.toHttpDate(modified_since)); response = invoke(request); assertEquals("status", 200, response.getStatus()); assertEquals("content", THE_CONTENT, response.getContentAsString()); }
87. PreconditionsTest#testConditionNoteIfNoneMatches()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
public void testConditionNoteIfNoneMatches() throws Exception { String etag = "blablabla"; // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_NONE_MATCH, "\"" + etag + "\""); MockHttpServletResponse response = invoke(request); assertEquals("status", 304, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_NONE_MATCH, "\"" + etag + "\""); response = invoke(request); assertEquals("status", 412, response.getStatus()); }
88. PreconditionsTest#testConditionIfNoneMatchesMultipleOnSingleHeader()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
/** * ensure multiple etags are supported. These are strange tests; I need to * ensure it goes through the IF_NONE_MATCH code and hits the second string * in the IF_NONE_MATCH header, so I want a 304 or 412 response. */ public void testConditionIfNoneMatchesMultipleOnSingleHeader() throws Exception { String etag = "blablabla"; // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_NONE_MATCH, "\"atlantic\",\"" + etag + "\",\"pacific\""); MockHttpServletResponse response = invoke(request); assertEquals("status", 304, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_NONE_MATCH, "\"atlantic\",\"" + etag + "\",\"pacific\""); response = invoke(request); assertEquals("status", 412, response.getStatus()); }
89. PreconditionsTest#testConditionIfNoneMatches()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
public void testConditionIfNoneMatches() throws Exception { String etag = "blablabla"; // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_NONE_MATCH, "\"notmatch\""); MockHttpServletResponse response = invoke(request); assertEquals("status", 200, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_NONE_MATCH, "\"notmatch\""); response = invoke(request); assertEquals("status", 200, response.getStatus()); }
90. PreconditionsTest#testConditionGetNotIfMatches()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
public void testConditionGetNotIfMatches() throws Exception { String etag = "blablabla"; // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_MATCH, "\"notmatch\""); MockHttpServletResponse response = invoke(request); assertEquals("status", 412, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_MATCH, "\"notmatch\""); response = invoke(request); assertEquals("status", 412, response.getStatus()); }
91. PreconditionsTest#testConditionIfNoneMatchesUnquoted()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
/** * ETags not wrapped in quotes are invalid. See * http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11 */ public void testConditionIfNoneMatchesUnquoted() throws Exception { String etag = "blablabla"; MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); // no quotes request.addHeader(HttpHeaders.IF_NONE_MATCH, etag); MockHttpServletResponse response = invoke(request); assertEquals("status", 400, response.getStatus()); request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); // beginning quote only request.addHeader(HttpHeaders.IF_NONE_MATCH, "\"" + etag); response = invoke(request); assertEquals("status", 400, response.getStatus()); request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); // end quote only request.addHeader(HttpHeaders.IF_NONE_MATCH, etag + "\""); response = invoke(request); assertEquals("status", 400, response.getStatus()); }
92. PreconditionsTest#testConditionIfMatchesUnquoted()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
/** * ETags not wrapped in quotes are invalid. See * http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.11 */ public void testConditionIfMatchesUnquoted() throws Exception { String etag = "blablabla"; MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); // no quotes request.addHeader(HttpHeaders.IF_MATCH, etag); MockHttpServletResponse response = invoke(request); assertEquals("status", 400, response.getStatus()); request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); // beginning quote only request.addHeader(HttpHeaders.IF_MATCH, "\"" + etag); response = invoke(request); assertEquals("status", 400, response.getStatus()); request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); // end quote only request.addHeader(HttpHeaders.IF_MATCH, etag + "\""); response = invoke(request); assertEquals("status", 400, response.getStatus()); }
93. PreconditionsTest#testConditionIfMatchesMultipleOnSingleHeader()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
/** * ensure multiple etags are supported */ public void testConditionIfMatchesMultipleOnSingleHeader() throws Exception { String etag = "blablabla"; // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_MATCH, "\"atlantic\",\"" + etag + "\",\"pacific\""); MockHttpServletResponse response = invoke(request); assertEquals("status", 200, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_MATCH, "\"atlantic\",\"" + etag + "\",\"pacific\""); response = invoke(request); assertEquals("status", 200, response.getStatus()); }
94. PreconditionsTest#testConditionIfMatches()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
public void testConditionIfMatches() throws Exception { String etag = "blablabla"; // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_MATCH, "\"" + etag + "\""); MockHttpServletResponse response = invoke(request); assertEquals("status", 200, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + etag, "*/*"); request.addHeader(HttpHeaders.IF_MATCH, "\"" + etag + "\""); response = invoke(request); assertEquals("status", 200, response.getStatus()); }
95. PreconditionsTest#testConditionNotModified()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
public void testConditionNotModified() throws Exception { Date date_to_return = new GregorianCalendar(2007, 11, 07, 10, 0, 0).getTime(); Date modified_since = new GregorianCalendar(2007, 11, 06, 10, 0, 0).getTime(); // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + String.valueOf(date_to_return.getTime()), "*/*"); request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, HttpDateParser.toHttpDate(modified_since)); MockHttpServletResponse response = invoke(request); assertEquals("status", 200, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + String.valueOf(date_to_return.getTime()), "*/*"); request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, HttpDateParser.toHttpDate(modified_since)); response = invoke(request); assertEquals("status", 200, response.getStatus()); }
96. PreconditionsTest#testConditionModified()
Project: wink
File: PreconditionsTest.java
File: PreconditionsTest.java
public void testConditionModified() throws Exception { Date date_to_return = new GregorianCalendar(2007, 11, 06, 10, 0, 0).getTime(); Date modified_since = new GregorianCalendar(2007, 11, 07, 10, 0, 0).getTime(); // GET MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "get/" + String.valueOf(date_to_return.getTime()), "*/*"); request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, HttpDateParser.toHttpDate(modified_since)); MockHttpServletResponse response = invoke(request); assertEquals("status", 304, response.getStatus()); // PUT request = MockRequestConstructor.constructMockRequest("PUT", "get/" + String.valueOf(date_to_return.getTime()), "*/*"); request.addHeader(HttpHeaders.IF_MODIFIED_SINCE, HttpDateParser.toHttpDate(modified_since)); response = invoke(request); assertEquals("status", 304, response.getStatus()); }
97. ResourceLifecycle6Test#testResourceRemoveInstanceCalled()
Project: wink
File: ResourceLifecycle6Test.java
File: ResourceLifecycle6Test.java
/** * Tests that the resource ObjectFactory's remove call is still made when an * ExceptionMapper throws an exception. Also, the removeInstance call should * be made after the response processing is done. * * @throws Throwable */ public void testResourceRemoveInstanceCalled() throws Throwable { MockHttpServletRequest request = MockRequestConstructor.constructMockRequest("GET", "/exception1", "text/plain"); MockHttpServletResponse response = null; try { response = invoke(request); assertTrue(response.getStatus() == Status.INTERNAL_SERVER_ERROR.getStatusCode()); assertEquals("", response.getContentAsString()); ofMockery.assertIsSatisfied(); } catch (ServletException e) { throw e.getRootCause(); } }
98. UriInfoImplTest#testCustomContextAttrInjectionAfterInstantiation()
Project: wink
File: UriInfoImplTest.java
File: UriInfoImplTest.java
@Test public void testCustomContextAttrInjectionAfterInstantiation() throws Exception { /* * Order of operations could be that 1) a root resource is instantiated, * 2) fields are injected normally but there is something missing on the * context, 3) later, the developer adds the missing context attribute */ MockHttpServletRequest servletRequest = MockRequestConstructor.constructMockRequest("GET", "customcontext/injectaftersub", "text/plain"); MockHttpServletResponse response = invoke(servletRequest); assertEquals(200, response.getStatus()); assertEquals("Hello world!", response.getContentAsString()); }
99. UserHandlersTest#testExceptionHandlers()
Project: wink
File: UserHandlersTest.java
File: UserHandlersTest.java
public void testExceptionHandlers() throws Exception { requestHandlerInvoked = false; responseHandlerInvoked = false; errorHandlerInvoked = false; MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/h", MediaType.TEXT_PLAIN); MockHttpServletResponse response = invoke(mockRequest); assertEquals(404, response.getStatus()); assertFalse(requestHandlerInvoked); assertFalse(responseHandlerInvoked); assertTrue(errorHandlerInvoked); }
100. UserHandlersTest#testRequestAndResponseHandlers()
Project: wink
File: UserHandlersTest.java
File: UserHandlersTest.java
public void testRequestAndResponseHandlers() throws Exception { requestHandlerInvoked = false; responseHandlerInvoked = false; errorHandlerInvoked = false; MockHttpServletRequest mockRequest = MockRequestConstructor.constructMockRequest("GET", "/hello", MediaType.TEXT_PLAIN); MockHttpServletResponse response = invoke(mockRequest); assertEquals(200, response.getStatus()); assertTrue(requestHandlerInvoked); assertTrue(responseHandlerInvoked); assertFalse(errorHandlerInvoked); }