List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse
MockHttpServletResponse
From source file:org.jasig.cas.support.oauth.web.OAuth20MetadataPrincipalControllerTests.java
@Test public void verifyNoTokenOrAuthHeader() throws Exception { final MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", CONTEXT + OAuthConstants.METADATA_URL); final MockHttpServletResponse mockResponse = new MockHttpServletResponse(); final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController(); oauth20WrapperController.afterPropertiesSet(); final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse); assertNull(modelAndView);/*from ww w . j a v a 2 s . com*/ assertEquals(HttpStatus.SC_BAD_REQUEST, mockResponse.getStatus()); assertEquals(CONTENT_TYPE, mockResponse.getContentType()); final String expected = "{\"error\":\"" + OAuthConstants.MISSING_ACCESS_TOKEN + "\",\"error_description\":\"" + OAuthConstants.MISSING_ACCESS_TOKEN_DESCRIPTION + "\"}"; final ObjectMapper mapper = new ObjectMapper(); final JsonNode expectedObj = mapper.readTree(expected); final JsonNode receivedObj = mapper.readTree(mockResponse.getContentAsString()); assertEquals(expectedObj.get("error").asText(), receivedObj.get("error").asText()); assertEquals(expectedObj.get("error_description").asText(), receivedObj.get("error_description").asText()); }
From source file:org.jasig.cas.web.flow.InitialFlowSetupActionTests.java
public void testSettingContextPath() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final String CONST_CONTEXT_PATH = "/test"; request.setContextPath(CONST_CONTEXT_PATH); final MockRequestContext context = new MockRequestContext(); context.setExternalContext(//ww w . j a v a 2 s . co m new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse())); this.action.doExecute(context); assertEquals(CONST_CONTEXT_PATH + "/", this.warnCookieGenerator.getCookiePath()); assertEquals(CONST_CONTEXT_PATH + "/", this.tgtCookieGenerator.getCookiePath()); }
From source file:org.openmrs.web.controller.observation.ObsFormControllerTest.java
/** * Test to make sure a new patient form can save a person relationship * //w w w.ja va2s . c o m * @throws Exception */ @Test public void shouldSaveObsFormNormally() throws Exception { ObsService os = Context.getObsService(); // set up the controller ObsFormController controller = new ObsFormController(); controller.setApplicationContext(applicationContext); controller.setSuccessView("encounter.form"); controller.setFormView("obs.form"); // set up the request and do an initial "get" as if the user loaded the // page for the first time MockHttpServletRequest request = new MockHttpServletRequest("GET", "/admin/observations/obs.form"); request.setSession(new MockHttpSession(null)); HttpServletResponse response = new MockHttpServletResponse(); controller.handleRequest(request, response); // set this to be a page submission request.setMethod("POST"); // add all of the parameters that are expected // all but the relationship "3a" should match the stored data request.addParameter("person", "2"); request.addParameter("encounter", "3"); request.addParameter("location", "1"); request.addParameter("obsDatetime", "05/05/2005"); request.addParameter("concept", "4"); // CIVIL_STATUS (conceptid=4) concept request.addParameter("valueCoded", "5"); // conceptNameId=2458 for SINGLE concept request.addParameter("saveObs", "Save Obs"); // so that the form is processed // send the parameters to the controller controller.handleRequest(request, response); // make sure an obs was created List<Obs> obsForPatient = os.getObservationsByPerson(new Person(2)); assertEquals(1, obsForPatient.size()); assertEquals(3, obsForPatient.get(0).getEncounter().getId().intValue()); assertEquals(1, obsForPatient.get(0).getLocation().getId().intValue()); }
From source file:nl.surfnet.coin.selfservice.filter.ApiOAuthFilterTest.java
@Before public void setUp() throws Exception { filter = new ApiOAuthFilter(); MockitoAnnotations.initMocks(this); request = new MockHttpServletRequest("GET", "/anyUrl"); response = new MockHttpServletResponse(); SecurityContextHolder.getContext().setAuthentication(null); }
From source file:org.sventon.web.tags.UrlTagTest.java
protected MockPageContext createPageContext() { final MockServletContext sc = new MockServletContext(); final MockHttpServletRequest request = new MockHttpServletRequest(sc); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, Mockito.mock(WebApplicationContext.class)); return new MockPageContext(sc, request, response); }
From source file:org.sventon.rss.RssFeedGeneratorTest.java
@Test public void testGenerateFeedRSS20() throws Exception { final DefaultRssFeedGenerator generator = new DefaultRssFeedGenerator(); generator.setFeedType("rss_2.0"); generator.setLogMessageLength(20);//ww w.java 2 s. c o m generator.setDateFormat("yyyyMMdd HH:mm:ss"); List<LogEntry> logEntries = new ArrayList<LogEntry>(); SortedSet<ChangedPath> changedPaths; final String logMessage = "< > / & ' ; \\"; changedPaths = new TreeSet<ChangedPath>(); changedPaths.add(new ChangedPath("/file1.java", null, 1, ChangeType.MODIFIED)); changedPaths.add(new ChangedPath("/file2.html", null, 1, ChangeType.DELETED)); changedPaths.add(new ChangedPath("/file3.abc", null, 1, ChangeType.ADDED)); changedPaths.add(new ChangedPath("/file4.def", null, 1, ChangeType.REPLACED)); logEntries.add(TestUtils.createLogEntry(1, "jesper", new Date(), logMessage, changedPaths)); changedPaths = new TreeSet<ChangedPath>(); changedPaths.add(new ChangedPath("/file1.java", null, 2, ChangeType.MODIFIED)); changedPaths.add(new ChangedPath("/file2.html", null, 2, ChangeType.DELETED)); changedPaths.add(new ChangedPath("/file3.abc", null, 2, ChangeType.ADDED)); changedPaths.add(new ChangedPath("/file4.def", "/file44.def", 1, ChangeType.REPLACED)); logEntries.add(TestUtils.createLogEntry(2, "jesper", new Date(), "Another\nlog message.", changedPaths)); final File tempFile = File.createTempFile("sventon-rss-test", null); final PrintWriter pw = new PrintWriter(tempFile); final MockHttpServletRequest req = new MockHttpServletRequest("get", "http://localhost:8888/svn/"); final MockHttpServletResponse res = new MockHttpServletResponse() { public PrintWriter getWriter() throws UnsupportedEncodingException { return pw; } }; generator.outputFeed(new RepositoryConfiguration("defaultsvn"), logEntries, req, res); pw.flush(); pw.close(); if (tempFile.exists()) { tempFile.delete(); } else { fail("No rss feed file was created in " + TestUtils.TEMP_DIR); } }
From source file:de.otto.jsonhome.registry.controller.RegistriesControllerTest.java
@Test public void shouldReturnRegistriesWithSingleEntry() { // given: an empty registry registriesController.putRegistry("live", registryLiveWithSingleLinkTo("foo"), new MockHttpServletResponse()); // when://from w w w . jav a2 s.c o m final MockHttpServletResponse response = new MockHttpServletResponse(); final Map<String, ?> registries = registriesController.getRegistries(response); // then: assertEquals(registries, oneRegistryNamed("live")); assertEquals(response.getStatus(), SC_OK); }
From source file:org.terasoluna.gfw.web.download.FileDownloadViewTest.java
@Before public void setup() throws FileNotFoundException { inputStream = this.getClass().getResourceAsStream("test.txt"); fileDownloadView = new FileDownloadView(); fileDownloadView.setInputStream(inputStream); fileDownloadView.setThrowIOException(false); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); model = new HashMap<String, Object>(); }
From source file:com.thoughtworks.go.server.controller.actions.JsonActionTest.java
@Test public void shouldReturnJsonConflictInCaseOfPostMergeValidationError() throws Exception { when(configValidity.isType(GoConfigValidity.VT_MERGE_POST_VALIDATION_ERROR)).thenReturn(true); JsonAction action = JsonAction.jsonByValidity(jsonAware, configValidity); MockHttpServletResponse response = new MockHttpServletResponse(); action.respond(response);//from www . j ava 2 s . c o m assertThat(response.getStatus(), is(SC_CONFLICT)); verify(configValidity).isType(GoConfigValidity.VT_MERGE_POST_VALIDATION_ERROR); }
From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML1ArtifactResolutionTest.java
public void testArtifactResolution() throws Exception { String relyingPartyId = "urn:example.org:sp1"; SAMLArtifactMapEntry artifactEntry = stageArtifact(relyingPartyId); String soapMessage = buildRequestMessage(relyingPartyId, artifactEntry.getArtifact()); MockHttpServletRequest servletRequest = new MockHttpServletRequest(); servletRequest.setMethod("POST"); servletRequest.setPathInfo("/saml1/SOAP/ArtifactResolution"); servletRequest.setContent(soapMessage.getBytes()); MockHttpServletResponse servletResponse = new MockHttpServletResponse(); ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext() .getBean("shibboleth.HandlerManager"); ProfileHandler handler = handlerManager.getProfileHandler(servletRequest); assertNotNull(handler);/*ww w. ja va 2s . c o m*/ // Process request HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest); HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false); handler.processRequest(profileRequest, profileResponse); String response = servletResponse.getContentAsString(); assertTrue(response.contains("saml1p:Success")); assertTrue(response.contains("saml1:Assertion")); }