List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse
MockHttpServletResponse
From source file:org.openmrs.module.feedback.web.AddStatusFormControllerTest.java
@Before public void setUp() throws Exception { /* executed before the test is run */ this.service = Context.getService(FeedbackService.class); this.controller = new FeedbackAdminListController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); /* this file is in the same folder of test resources where the hibernate mapping file is located */ initializeInMemoryDatabase();// www . j a v a 2 s. c o m executeDataSet("StatusDataset.xml"); /* Sample data is loaded into the system */ authenticate(); }
From source file:org.openmrs.module.feedback.web.AddSeverityFormControllerTest.java
@Before public void setUp() throws Exception { /* executed before the test is run */ this.service = Context.getService(FeedbackService.class); this.controller = new FeedbackAdminListController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); /* this file is in the same folder of test resources where the hibernate mapping file is located */ initializeInMemoryDatabase();/*from w ww. ja v a 2s . com*/ executeDataSet("SeverityDataset.xml"); /* Sample data is loaded into the system */ authenticate(); }
From source file:org.openmrs.module.atomfeed.web.AtomFeedDownloadServletTest.java
/** * @see AtomFeedDownloadServlet#doHead(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) * @verifies send not modified error if atom feed has not changed *//*from w ww.j a v a 2 s .c o m*/ @Test public void doHead_shouldSendNotModifiedErrorIfAtomFeedHasNotChanged() throws Exception { // create servlet and corresponding request and response object to be sent AtomFeedDownloadServlet atomFeedDownloadServlet = new AtomFeedDownloadServlet(); MockHttpServletRequest request = new MockHttpServletRequest("HEAD", "/atomfeed"); request.setContextPath("/somecontextpath"); MockHttpServletResponse response = new MockHttpServletResponse(); // intentionally change atom feed in order to not depend from other tests AtomFeedUtil.objectCreated(new Encounter()); // read atom feed header specific information from the header file String headerFileContent = AtomFeedUtil.readFeedHeaderFile(); int contentLength = 0; String etagToken = ""; Date lastModified = null; if (StringUtils.isNotBlank(headerFileContent)) { contentLength = headerFileContent.length() + Integer .valueOf(StringUtils.substringBetween(headerFileContent, "<entriesSize>", "</entriesSize>")); etagToken = StringUtils.substringBetween(headerFileContent, "<versionId>", "</versionId>"); try { lastModified = new SimpleDateFormat(AtomFeedUtil.RFC_3339_DATE_FORMAT) .parse(StringUtils.substringBetween(headerFileContent, "<updated>", "</updated>")); } catch (ParseException e) { // ignore it here } } // set request headers request.addHeader("If-None-Match", '"' + etagToken + '"'); request.addHeader("If-Modified-Since", lastModified); atomFeedDownloadServlet.service(request, response); // check response headers Assert.assertEquals(contentLength, response.getContentLength()); Assert.assertEquals("application/atom+xml", response.getContentType()); Assert.assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus()); Assert.assertNotNull(response.getHeader("Last-Modified")); }
From source file:org.eclipse.virgo.snaps.core.SnapHostFilterTests.java
@Test public void testRouteToSnap() throws ServletException, IOException { MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setServletPath("/hotels/booking"); Snap snap = createMock(Snap.class); snap.handleRequest(request, response); expectLastCall();//from w w w . ja v a 2 s . co m this.stubRegistry.snaps.put("/hotels", snap); MockServletContext servletContext = new MockServletContext(); MockFilterConfig config = new MockFilterConfig(servletContext); MockFilterChain chain = new MockFilterChain(); replay(snap); TestFilter filter = new TestFilter(); filter.init(config); filter.doFilter(request, response, chain); filter.destroy(); verify(snap); }
From source file:org.jasig.cas.web.flow.SendTicketGrantingTicketActionTests.java
@Test public void testNoTgtToSet() throws Exception { this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse())); assertEquals("success", this.action.execute(this.context).getId()); }
From source file:alpha.portal.webapp.filter.LocaleFilterTest.java
/** * Test set locale in session when session is null. * /*from w ww .j a va2s . com*/ * @throws Exception * the exception */ public void testSetLocaleInSessionWhenSessionIsNull() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("locale", "es"); final MockHttpServletResponse response = new MockHttpServletResponse(); this.filter.doFilter(request, response, new MockFilterChain()); // no session, should result in null Assert.assertNull(request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY)); // thread locale should always have it, regardless of session Assert.assertNotNull(LocaleContextHolder.getLocale()); }
From source file:org.openmrs.module.feedback.web.StatusFormControllerTest.java
@Before public void setUp() throws Exception { /* executed before the test is run */ this.service = Context.getService(FeedbackService.class); this.controller = new StatusFormController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); /* this file is in the same folder of test resources where the hibernate mapping file is located */ initializeInMemoryDatabase();//w w w. j a va 2 s .co m executeDataSet("StatusDataset.xml"); /* Sample data is loaded into the system */ authenticate(); }
From source file:piazza.services.ingest.test.ControllerTests.java
/** * Tests admin/stats endpoint/* w ww . j ava 2 s.c om*/ */ @Test public void testAdminStats() throws IOException { // Ensuring no Exceptions are thrown MockHttpServletResponse mockResponse = new MockHttpServletResponse(); controller.stats(mockResponse); }
From source file:org.openmrs.module.feedback.web.AddPredefinedSubjectFormControllerTest.java
@Before public void setUp() throws Exception { /* executed before the test is run */ this.service = Context.getService(FeedbackService.class); this.controller = new FeedbackAdminListController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); /* this file is in the same folder of test resources where the hibernate mapping file is located */ initializeInMemoryDatabase();//www. ja v a 2s . co m executeDataSet("PredefinedSubjectDataset.xml"); /* Sample data is loaded into the system */ authenticate(); }
From source file:org.openmrs.web.servlet.LoginServletTest.java
/** * If a user logs in correctly, they should never be redirected back to the login screen because * this would cause confusion//from w w w . jav a2 s . co m * * @throws Exception */ @Test public void shouldNotRedirectBackToLoginScreenWithCorrectUsernameAndPassword() throws Exception { // this test depends on being able to log in as "admin:test". Context.logout(); Context.authenticate("admin", "test"); Assert.assertTrue(Context.isAuthenticated()); // do the test now LoginServlet loginServlet = new LoginServlet(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/loginServlet"); request.setContextPath("/somecontextpath"); MockHttpServletResponse response = new MockHttpServletResponse(); request.setParameter("uname", "admin"); request.setParameter("pw", "test"); loginServlet.service(request, response); Assert.assertNotSame("/somecontextpath/login.htm", response.getRedirectedUrl()); }