List of usage examples for org.springframework.mock.web MockHttpServletRequest MockHttpServletRequest
public MockHttpServletRequest()
From source file:org.esgf.web.LiveSearchController.java
public static void main(String[] args) { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); String queryStr = "model=kkk1&project=jjj&institute=ll&search=true&variable"; String searchConstraints = "&offset=0&type=Dataset&project=CMIP5&institute=INM&latest=true&replica=false&distrib=false"; mockRequest.addParameter("facet_param_list", queryStr); mockRequest.addParameter("search_constraint_list", searchConstraints); mockRequest.addParameter("useURLParams", "true"); LiveSearchController fc = new LiveSearchController(); fc.getFacetListHelper(mockRequest);/*from w ww . j a v a 2 s . co m*/ //fc.getDocElement(mockRequest); }
From source file:org.esgf.legacydatacart.LegacyOldFileTemplateController.java
/** * Main method to test the controller using Mock Objects * //from w w w. j av a 2 s .c om * @param args */ public static void main(String[] args) { final MockHttpServletRequest mockRequest = new MockHttpServletRequest(); /* String [] id = {"obs4MIPs.NASA-JPL.AIRS.mon.v1:esg-datanode.jpl.nasa.gov"}; String peer = "undefined"; String showAll = "true"; mockRequest.addParameter("id", id); mockRequest.addParameter("peer", peer); mockRequest.addParameter("showAll", showAll); String queryString = "format=application%2Fsolr%2Bjson&type=File&shards=localhost:8983/solr&variable=hus"; */ //JSONArray ja = getJSONArrayUsingSearchAPI(queryString,dataset_id); //String dc = getDataCartUsingSearchAPI(mockRequest); //System.out.println("dc\n" + dc); /* FileDownloadTemplateController fc = new FileDownloadTemplateController(); try { String output = fc.doGet(mockRequest); System.out.println("output\n" + output); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ String queryString = "format=application%2Fsolr%2Bjson&type=File&shards=localhost:8983/solr&variable=hus"; String dataset_id = "obs4MIPs.NASA-JPL.AIRS.mon.v1:esg-datanode.jpl.nasa.gov"; String[] fqArr = { "" }; String peer = "localhost:8983/solr"; LegacyDocElement docElement = getDocElement(queryString, dataset_id, fqArr, peer); System.out.println("docelement\n" + docElement.toXML()); }
From source file:ch.rasc.extclassgenerator.GeneratorTestUtil.java
public static void testWriteModel(Class<?> clazz, String modelName) { try {//w w w. j av a2 s.c o m MockHttpServletResponse response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS4, false); GeneratorTestUtil.compareExtJs4Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS5, false); GeneratorTestUtil.compareExtJs5Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.TOUCH2, false); GeneratorTestUtil.compareTouch2Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS4, IncludeValidation.NONE, false); GeneratorTestUtil.compareExtJs4Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS5, IncludeValidation.NONE, false); GeneratorTestUtil.compareExtJs5Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.TOUCH2, IncludeValidation.NONE, false); GeneratorTestUtil.compareTouch2Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS4); GeneratorTestUtil.compareExtJs4Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS5); GeneratorTestUtil.compareExtJs5Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.TOUCH2); GeneratorTestUtil.compareTouch2Code(modelName, response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS4, true); GeneratorTestUtil.compareExtJs4Code(modelName, response.getContentAsString(), true, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS5, true); GeneratorTestUtil.compareExtJs5Code(modelName, response.getContentAsString(), true, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.TOUCH2, true); GeneratorTestUtil.compareTouch2Code(modelName, response.getContentAsString(), true, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS4, IncludeValidation.NONE, true); GeneratorTestUtil.compareExtJs4Code(modelName, response.getContentAsString(), true, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.EXTJS5, IncludeValidation.NONE, true); GeneratorTestUtil.compareExtJs5Code(modelName, response.getContentAsString(), true, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, clazz, OutputFormat.TOUCH2, IncludeValidation.NONE, true); GeneratorTestUtil.compareTouch2Code(modelName, response.getContentAsString(), true, false); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.piraso.server.CommonMockObjects.java
public static MockHttpServletRequest mockRequest(String monitoredAddr, String activityId) { MockHttpServletRequest request = spy(new MockHttpServletRequest()); request.setRemoteAddr(monitoredAddr); if (activityId != null) { request.addParameter("activity_uuid", activityId); }/*from w w w .j a v a 2 s .co m*/ return request; }
From source file:com.xyxy.platform.modules.core.web.ServletsTest.java
@Test public void checkIfModified() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); // Header,true,? assertThat(Servlets.checkIfModifiedSince(request, response, (new Date().getTime() - 2000))).isTrue(); // If-Modified-Since Header request.addHeader("If-Modified-Since", new Date().getTime()); // Header?,, false. assertThat(Servlets.checkIfModifiedSince(request, response, (new Date().getTime() - 2000))).isFalse(); // Header,, true,?. assertThat(Servlets.checkIfModifiedSince(request, response, (new Date().getTime() + 2000))).isTrue(); }
From source file:net.formio.servlet.MockServletRequests.java
/** * Creates new servlet request that contains given resource as multi part. * @param paramName//from w ww . j ava 2s .c om * @param resourceName * @return */ public static MockHttpServletRequest newRequest(String paramName, String resourceName, String mimeType) { try { MockHttpServletRequest request = new MockHttpServletRequest(); // Load resource being uploaded ByteArrayOutputStream bos = new ByteArrayOutputStream(); Streams.copy(MockServletRequests.class.getResourceAsStream(resourceName), bos, true); byte[] fileContent = bos.toByteArray(); // Create part & entity from resource Part[] parts = new Part[] { new FilePart(paramName, new ByteArrayPartSource(resourceName, fileContent), mimeType, (String) null) }; MultipartRequestEntity multipartRequestEntity = new MultipartRequestEntity(parts, new PostMethod().getParams()); ByteArrayOutputStream requestContent = new ByteArrayOutputStream(); multipartRequestEntity.writeRequest(requestContent); request.setContent(requestContent.toByteArray()); // Set content type of request (important, includes MIME boundary string) String contentType = multipartRequestEntity.getContentType(); request.setContentType(contentType); request.setMethod("POST"); return request; } catch (IOException ex) { throw new RuntimeException(ex.getMessage(), ex); } }
From source file:gov.nih.nci.cabig.ctms.lookandfeel.AssetServletTest.java
@Override protected void setUp() throws Exception { super.setUp(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); servlet = new AssetServlet(); request.setMethod("GET"); }
From source file:org.openmrs.module.logmanager.web.util.WebUtilsTest.java
@Test public void getSessionedIntParameter() { MockHttpServletRequest request = new MockHttpServletRequest(); // Should sue default when parameter doesn't exist Assert.assertEquals(123, WebUtils.getSessionedIntParameter(request, "test1", 123, "test.")); // Should use request value when it exists request.addParameter("test1", "" + 456); Assert.assertEquals(456, WebUtils.getSessionedIntParameter(request, "test1", 123, "test.")); // Should remember in session when request doesn't exist request.removeParameter("test1"); Assert.assertEquals(456, WebUtils.getSessionedIntParameter(request, "test1", 123, "test.")); }
From source file:au.gov.dto.dibp.appointments.security.csrf.CookieBasedCsrfTokenRepositoryTest.java
@Test public void testSaveAndLoadToken() throws Exception { CookieBasedCsrfTokenRepository repo = new CookieBasedCsrfTokenRepository(); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); CsrfToken token = repo.generateToken(request); repo.saveToken(token, request, response); Cookie cookie = response.getCookie(token.getParameterName()); assertNotNull(cookie);/* ww w . j a v a 2 s . com*/ assertEquals(token.getToken(), cookie.getValue()); assertEquals(true, cookie.isHttpOnly()); request.setCookies(cookie); CsrfToken saved = repo.loadToken(request); assertEquals(token.getToken(), saved.getToken()); assertEquals(token.getHeaderName(), saved.getHeaderName()); assertEquals(token.getParameterName(), saved.getParameterName()); }
From source file:com.healthcit.cacure.web.controller.LogoutControllerTest.java
@Test public void testProcessLogout() { MockHttpServletRequest request = new MockHttpServletRequest(); UserCredentials userCredentials = new UserCredentials(); userCredentials.setUserName("Testing"); userCredentials.setPassword("TestPassword"); MockHttpSession session = new MockHttpSession(); session.setAttribute(Constants.CREDENTIALS, userCredentials); request.setSession(session);//from www. j av a 2 s . c o m RedirectView actual = (RedirectView) logoutController.processLogout(request); RedirectView expected = new RedirectView(Constants.HOME_URI, true); Assert.assertNotNull(actual); Assert.assertNull(session.getAttribute(Constants.CREDENTIALS)); Assert.assertEquals(expected.getUrl(), actual.getUrl()); }