List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse
MockHttpServletResponse
From source file:org.terasoluna.gfw.web.logging.TraceLoggingInterceptorTest.java
@Before public void setUp() throws Exception { // reset log// ww w . ja va 2s . c om new SimpleDriverDataSource(Driver.load(), "jdbc:h2:mem:terasolung-gfw-web;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'classpath:h2.sql'", "sa", "") .getConnection().close(); // prepare request object request = new MockHttpServletRequest(); // prepare response object response = new MockHttpServletResponse(); controller = new TraceLoggingInterceptorController(); method = controller.getClass().getMethods(); model = mock(ModelAndView.class); interceptor = new TraceLoggingInterceptor(); }
From source file:org.unidle.social.SignInAdapterImplTest.java
@Test public void testSignIn() throws Exception { final ConnectionStub<Object> connection = new ConnectionStub<>( new ConnectionData("provider id", "provider user id", "display name", "profile url", "image url", "access token", "secret", "refresh token", 1234L)); final MockHttpServletResponse response = new MockHttpServletResponse(); subject.signIn("userId", connection, new ServletWebRequest(new MockHttpServletRequest(), response)); final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); assertThat(principal).isEqualTo("userId"); assertThat(response.getCookie(LAST_LOGIN_SOURCE.getName()).getValue()).isEqualTo("provider id"); }
From source file:org.energyos.espi.datacustodian.web.customer.UsagePointControllerTests.java
@Test @Ignore("TODO: come back to it b/f we're finished") public void feed_returnsAtomFeedOfUsagePointsForCurrentUser() throws Exception { Authentication auth = mock(Authentication.class); when(auth.getPrincipal()).thenReturn(mock(RetailCustomer.class)); MockHttpServletResponse response = new MockHttpServletResponse(); HashMap<String, String> params = new HashMap<>(); // controller.feed(response, auth, params); verify(exportService).exportUsagePoints(anyLong(), anyLong(), any(OutputStream.class), eq(new ExportFilter(params))); }
From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerMacroTests.java
public void setUp() throws Exception { wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); //final Template expectedTemplate = new Template(); fc = new FreeMarkerConfigurer(); fc.setPreferFileSystemAccess(false); fc.afterPropertiesSet();//www . j a v a2 s .co m wac.getDefaultListableBeanFactory().registerSingleton("freeMarkerConfigurer", fc); wac.refresh(); request = new MockHttpServletRequest(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver()); request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver()); response = new MockHttpServletResponse(); }
From source file:cherry.foundation.download.TableDownloadTemplateTest.java
@Test public void testDownloadCsvWithHeader() throws IOException { // /* w ww. jav a2 s.c o m*/ MockHttpServletResponse response = new MockHttpServletResponse(); // tableDownloadOperation.downloadCsv(response, StandardCharsets.UTF_8, "test_{0}.csv", new LocalDateTime(2015, 1, 23, 12, 34, 56), asList("HEAD0"), createCommonClause(), createOrderByClause(), constant("TEST00")); // assertEquals("text/csv", response.getContentType()); assertEquals("UTF-8", response.getCharacterEncoding()); assertEquals("text/csv;charset=UTF-8", response.getHeader("Content-Type")); assertEquals("attachment; filename=\"test_20150123123456.csv\"", response.getHeader("Content-Disposition")); assertEquals("\"HEAD0\"\r\n\"TEST00\"\r\n", response.getContentAsString()); }
From source file:org.piraso.server.service.ResponseLoggerServiceImplTest.java
@Before public void setUp() throws Exception { ObjectMapper mapper = JacksonUtils.createMapper(); request = new MockHttpServletRequest(); pirasoRequest = new TestPirasoRequest(request); response = spy(new MockHttpServletResponse()); pirasoResponse = new TestPirasoResponse(response); user = new User(pirasoRequest); preferences = new Preferences(); preferences.addProperty(GeneralPreferenceEnum.STACK_TRACE_ENABLED.getPropertyName(), true); request.addParameter("watchedAddr", EXPECTED_MONITORED_ADDRESS); request.addParameter("preferences", mapper.writeValueAsString(preferences)); service = new ResponseLoggerServiceImpl(user, pirasoRequest, pirasoResponse); }
From source file:org.jasig.cas.web.LogoutControllerTests.java
@Test public void testLogoutForServiceWithFollowRedirects() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("service", "TestService"); this.logoutController.setFollowServiceRedirects(true); assertTrue(this.logoutController.handleRequestInternal(request, new MockHttpServletResponse()) .getView() instanceof RedirectView); }
From source file:org.openmrs.contrib.metadatarepository.webapp.controller.UserFormControllerTest.java
@Test public void testEdit() throws Exception { log.debug("testing edit..."); request = newGet("/userform.html"); request.addParameter("id", "1"); // regular user request.addUserRole(Constants.ADMIN_ROLE); User user = c.showForm(request, new MockHttpServletResponse()); assertEquals("Tomcat User", user.getFullName()); }
From source file:org.sventon.util.HTMLCreatorTest.java
@Test public void testCreateChangedPathsTable() throws Exception { final String result = "<table class=\"changedPathsTable\">\n" + " <tr>\n" + " <th align=\"left\">Action</th>\n" + " <th align=\"left\">Path</th>\n" + " </tr>\n" + " <tr>\n" + " <td valign=\"top\"><i>Modified</i></td>\n" + " <td><a href=\"repos/sandbox/diff/file1.java?revision=1&entries=/file1.java@1&entries=/file1.java@0\" title=\"Diff with previous version\"><i>/file1.java</i></a></td>\n" + " </tr>\n" + " <tr>\n" + " <td valign=\"top\"><i>Deleted</i></td>\n" + " <td><a href=\"repos/sandbox/goto/file2.html?revision=0\" title=\"Show previous revision\"><del>/file2.html</del></a></td>\n" + " </tr>\n" + " <tr>\n" + " <td valign=\"top\"><i>Added</i></td>\n" + " <td><a href=\"repos/sandbox/goto/file3.abc?revision=1\" title=\"Show\">/file3.abc</a><br>(<i>Copy from</i> <a href=\"repos/sandbox/goto/branch/file3.abc?revision=1\" title=\"Show\">/branch/file3.abc</a> @ <a href=\"repos/sandbox/info?revision=1\">1</a>)</td>\n" + " </tr>\n" + " <tr>\n" + " <td valign=\"top\"><i>Replaced</i></td>\n" + " <td><a href=\"repos/sandbox/goto/file4.def?revision=1\" title=\"Show\">/file4.def</a></td>\n" + " </tr>\n" + "</table>"; final SortedSet<ChangedPath> 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", "/branch/file3.abc", 1, ChangeType.ADDED)); changedPaths.add(new ChangedPath("/file4.def", null, 1, ChangeType.REPLACED)); final LogEntry logEntry = TestUtils.createLogEntry(1, "jesper", new Date(), "Testing", changedPaths); assertEquals(result, HTMLCreator.createChangedPathsTable(logEntry.getChangedPaths(), logEntry.getRevision(), "/file1.java", "", new RepositoryName("sandbox"), false, false, new MockHttpServletResponse())); }
From source file:com.spotify.apollo.http.server.AsyncContextOngoingRequestTest.java
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); response = new MockHttpServletResponse(); when(asyncContext.getResponse()).thenReturn(response); ongoingRequest = new AsyncContextOngoingRequest(REQUEST, asyncContext, logger, RequestMetadataImpl.create(Instant.EPOCH, Optional.empty(), Optional.empty())); }