List of usage examples for org.springframework.mock.web MockHttpServletRequest addParameter
public void addParameter(String name, String... values)
From source file:test.com.tsc9526.monalisa.service.actions.DeleteActionTest.java
public void testDeleteDbTableByWhere() throws Exception { MockHttpServletRequest req = createRequest("/db1/test_record_v2"); req.addParameter("record_id>", "8"); Response resp = getRespone(req); Assert.assertEquals(resp.getStatus(), 200); Assert.assertEquals(resp.getData().toString(), "3"); }
From source file:org.openmrs.web.controller.form.FieldTypeListControllerTest.java
/** * @see FieldTypeListController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) * @verifies display a user friendly error message *//*ww w . j a va2 s. c o m*/ @Test @Transactional(propagation = Propagation.NOT_SUPPORTED) public void onSubmit_shouldDisplayAUserFriendlyErrorMessage() throws Exception { MockHttpServletRequest post = webTestHelper.newPOST("/admin/forms/fieldType.list"); post.addParameter("fieldTypeId", "1"); Response response = webTestHelper.handle(post); Assert.assertNotNull(response.session.getAttribute(WebConstants.OPENMRS_ERROR_ATTR)); }
From source file:org.sventon.web.ctrl.template.ShowThumbnailsControllerTest.java
@Test public void testSvnHandle() throws Exception { final ConfigurableMimeFileTypeMap fileTypeMap = new ConfigurableMimeFileTypeMap(); fileTypeMap.afterPropertiesSet();/*from w ww . j a v a 2s. co m*/ final MultipleEntriesCommand command = new MultipleEntriesCommand(); final ShowThumbnailsController ctrl = new ShowThumbnailsController(fileTypeMap); final String[] pathEntries = new String[] { "file1.gif@123", "file2.jpg@123", "file.abc@123" }; command.setEntries(PathRevision.parse(pathEntries)); final MockHttpServletRequest req = new MockHttpServletRequest(); req.addParameter(GetFileController.DISPLAY_REQUEST_PARAMETER, GetFileController.CONTENT_DISPOSITION_INLINE); final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, req, null, null); final Map model = modelAndView.getModel(); final List entries = (List) model.get("thumbnailentries"); assertEquals(2, entries.size()); final PathRevision entry0 = (PathRevision) entries.get(0); assertEquals("file1.gif", entry0.getPath()); assertEquals(123, entry0.getRevision().getNumber()); }
From source file:test.com.tsc9526.monalisa.service.actions.PutActionTest.java
public void testPutDbTableRow1() throws Exception { MockHttpServletRequest req = createRequest("/db1/test_record_v2"); req.addParameter("name", "new_002"); Response resp = getRespone(req); Assert.assertEquals(resp.getStatus(), 403, resp.getMessage()); }
From source file:org.jmesa.worksheet.servlet.WorksheetServletTest.java
@Test public void getWorksheet() { WorksheetUpdaterTemp servlet = new WorksheetUpdaterTemp(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("id", ID); WebContext webContext = new HttpServletRequestWebContext(request); Worksheet worksheet = servlet.getAccessToWorksheet(null, webContext); WorksheetRow row = new WorksheetRow(new UniqueProperty(null, null)); worksheet.addRow(row);//from w ww . java2 s . co m assertNotNull(worksheet); assertTrue("There are no rows in the worksheet.", worksheet.getRows().size() == 1); Worksheet worksheet2 = servlet.getAccessToWorksheet(null, webContext); assertNotNull(worksheet2); assertTrue("Did not return the same worksheet.", worksheet == worksheet2); }
From source file:test.com.tsc9526.monalisa.service.actions.PutActionTest.java
public void testPutDbTableByPk() throws Exception { Assert.assertNotEquals(selectByPrimaryKey(1).get("name"), "ppyyzz001"); MockHttpServletRequest req = createRequest("/db1/test_record_v2/1"); req.addParameter("name", "ppyyzz001"); Response resp = getRespone(req); Assert.assertEquals(resp.getStatus(), 200, resp.getMessage()); Assert.assertEquals(selectByPrimaryKey(1).get("name"), "ppyyzz001"); }
From source file:org.openmrs.module.webservices.rest.web.RequestContextTest.java
/** * @see RequestContext#getParameter(String) * @verifies return the request parameter of given name if present in the request */// w ww. j a v a 2s . co m @Test public void getParameter_shouldReturnTheRequestParameterOfGivenNameIfPresentInTheRequest() throws Exception { RequestContext requestContext = new RequestContext(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("includeAll", "true"); requestContext.setRequest(request); assertThat(requestContext.getParameter("includeAll"), is("true")); }
From source file:alpha.portal.webapp.controller.PasswordHintControllerTest.java
/** * Test execute./*from w ww . j a v a 2s .co m*/ * * @throws Exception * the exception */ @Test public void testExecute() throws Exception { final MockHttpServletRequest request = this.newGet("/passwordHint.html"); request.addParameter("username", "user"); // start SMTP Server final Wiser wiser = new Wiser(); wiser.setPort(this.getSmtpPort()); wiser.start(); this.c.handleRequest(request); // verify an account information e-mail was sent wiser.stop(); Assert.assertTrue(wiser.getMessages().size() == 1); // verify that success messages are in the session Assert.assertNotNull(request.getSession().getAttribute(BaseFormController.MESSAGES_KEY)); }
From source file:org.jasig.cas.web.flow.DynamicRedirectViewSelectorTests.java
public void testWithCasService() { final MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("service", "http://www.cnn.com"); final SimpleWebApplicationServiceImpl impl = SimpleWebApplicationServiceImpl.createServiceFrom(request); final MockRequestContext context = new MockRequestContext(); context.getFlowScope().put("service", impl); context.setExternalContext(new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), new MockHttpServletResponse())); assertTrue(this.selector.makeEntrySelection(context) instanceof ExternalRedirect); assertTrue(this.selector.makeRefreshSelection(context) instanceof ExternalRedirect); }
From source file:org.openmrs.web.controller.user.RoleFormControllerTest.java
@Test public void shouldUpdateRoleWithParent() throws Exception { Role child = new Role("child", "child"); getUS().saveRole(child);/* w ww. j av a 2s. c o m*/ Role parent = new Role("parent", "parent"); parent.setChildRoles(new HashSet<Role>()); parent.getChildRoles().add(child); getUS().saveRole(parent); MockHttpServletRequest requestGET = wth.newGET("/admin/users/role.form"); requestGET.addParameter("roleName", "child"); Response responseGET = wth.handle(requestGET); MockHttpServletRequest requestPOST = wth.newPOST("/admin/users/role.form", responseGET); requestPOST.addParameter("roleName", "child"); requestPOST.addParameter("description", "updated child"); requestPOST.addParameter("inheritedRoles", "parent"); wth.handle(requestPOST); Assert.assertEquals("updated child", getUS().getRole("child").getDescription()); deleteAllData(); }