List of usage examples for org.springframework.mock.web MockHttpServletRequest addParameter
public void addParameter(String name, String... values)
From source file:org.openmrs.module.radiology.web.controller.RadiologyOrderFormControllerTest.java
/** * @see RadiologyOrderFormController#postDiscontinueRadiologyOrder(HttpServletRequest, * HttpServletResponse, Order, String, Date) *///from www .ja va 2s . c o m @Test @Verifies(value = "should not redirect if discontinuation failed through date in the future", method = "postDiscontinueRadiologyOrder(HttpServletRequest, HttpServletResponse, Order, String, Date)") public void postDiscontinueRadiologyOrder_shouldNotRedirectIfDiscontinuationFailedThroughDateInTheFuture() throws Exception { //given RadiologyOrder mockRadiologyOrderToDiscontinue = RadiologyTestData.getMockRadiologyOrder1(); mockRadiologyOrderToDiscontinue.getStudy().setMwlStatus(MwlStatus.DISCONTINUE_OK); String discontinueReason = "Wrong Procedure"; Date discontinueDate = new Date(); APIException apiException = new APIException("Discontinue date cannot be in the future"); Order mockDiscontinuationOrder = new Order(); mockDiscontinuationOrder.setOrderId(2); mockDiscontinuationOrder.setAction(Order.Action.DISCONTINUE); mockDiscontinuationOrder.setOrderer(mockRadiologyOrderToDiscontinue.getOrderer()); mockDiscontinuationOrder.setOrderReasonNonCoded(discontinueReason); mockDiscontinuationOrder.setDateActivated(discontinueDate); mockDiscontinuationOrder.setPreviousOrder(mockRadiologyOrderToDiscontinue); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.addParameter("discontinueOrder", "discontinueOrder"); MockHttpSession mockSession = new MockHttpSession(); mockRequest.setSession(mockSession); when(radiologyService.getRadiologyOrderByOrderId(mockRadiologyOrderToDiscontinue.getOrderId())) .thenReturn(mockRadiologyOrderToDiscontinue); when(radiologyService.discontinueRadiologyOrder(mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder.getOrderer(), mockDiscontinuationOrder.getDateActivated(), mockDiscontinuationOrder.getOrderReasonNonCoded())).thenThrow(apiException); assertThat(mockRadiologyOrderToDiscontinue.getAction(), is(Order.Action.NEW)); ModelAndView modelAndView = radiologyOrderFormController.postDiscontinueRadiologyOrder(mockRequest, null, mockRadiologyOrderToDiscontinue, mockDiscontinuationOrder); assertNotNull(modelAndView); assertThat(modelAndView.getViewName(), is("module/radiology/radiologyOrderForm")); assertThat(modelAndView.getModelMap(), hasKey("order")); Order order = (Order) modelAndView.getModelMap().get("order"); assertThat(order, is((Order) mockRadiologyOrderToDiscontinue)); assertThat(modelAndView.getModelMap(), hasKey("radiologyOrder")); RadiologyOrder radiologyOrder = (RadiologyOrder) modelAndView.getModelMap().get("radiologyOrder"); assertThat(radiologyOrder, is(mockRadiologyOrderToDiscontinue)); assertNotNull(mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR)); assertThat((String) mockSession.getAttribute(WebConstants.OPENMRS_ERROR_ATTR), is("Discontinue date cannot be in the future")); }
From source file:org.openmrs.module.htmlformentry19ext.IntegrationTest.java
@Test public void encounterProviderAndRole_testRemovingProviderFromEncounter() throws Exception { final Date date = new Date(); new RegressionTestHelper() { @Override//from ww w . j a v a 2 s.c o m protected String getXmlDatasetPath() { return "org/openmrs/module/htmlformentry19ext/include/"; } @Override public String getFormName() { return "specifyingEncounterRoleTwiceWithSameRole"; } @Override public String[] widgetLabels() { return new String[] { "Date:", "Location:", "Doctors:", "Doctors:!!1" }; } @Override public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) { // first set two providers request.addParameter(widgets.get("Date:"), dateAsString(date)); request.addParameter(widgets.get("Location:"), "2"); request.addParameter(widgets.get("Doctors:"), "2"); // Doctor Bob request.addParameter(widgets.get("Doctors:!!1"), "1"); // Superuser } @Override public boolean doEditEncounter() { return true; } @Override public String[] widgetLabelsForEdit() { return new String[] { "Date:", "Location:", "Doctors:", "Doctors:!!1" }; } @Override public void setupEditRequest(MockHttpServletRequest request, Map<String, String> widgets) { // now, in the edit request, only set a single provider request.setParameter(widgets.get("Doctors:"), "1"); // Superuser request.setParameter(widgets.get("Doctors:!!1"), ""); // set the second doctor field blank } @Override public void testEditedResults(SubmissionResults results) { results.assertNoErrors(); results.assertLocation(2); Map<EncounterRole, Set<Provider>> byRoles = results.getEncounterCreated().getProvidersByRoles(); Assert.assertEquals(1, byRoles.size()); Set<Provider> doctors = byRoles.get(Context.getEncounterService().getEncounterRole(3)); Assert.assertEquals(1, doctors.size()); Assert.assertEquals(1, doctors.size()); Assert.assertEquals(new Integer(1), doctors.iterator().next().getId()); } }.run(); }
From source file:fr.paris.lutece.portal.web.admin.AdminPageJspBeanTest.java
public void testGetRemovePageNotANumber() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.PAGE_ID, "foo"); _bean.getRemovePage(request);//ww w . j ava2 s .c o m AdminMessage message = AdminMessageService.getMessage(request); assertNotNull(message); assertEquals(AdminMessage.TYPE_ERROR, message.getType()); }
From source file:fr.paris.lutece.portal.web.admin.AdminPageJspBeanTest.java
public void testGetRemovePageNotExisting() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.PAGE_ID, Integer.toString(314159265)); _bean.getRemovePage(request);/*from w ww .ja v a2s . c om*/ AdminMessage message = AdminMessageService.getMessage(request); assertNotNull(message); assertEquals(AdminMessage.TYPE_ERROR, message.getType()); }
From source file:fr.paris.lutece.portal.web.admin.AdminPageJspBeanTest.java
public void testDoRemovePageNotANumber() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.PAGE_ID, "foo"); _bean.doRemovePage(request);//ww w .j a va2 s. c o m AdminMessage message = AdminMessageService.getMessage(request); assertNotNull(message); assertEquals(AdminMessage.TYPE_ERROR, message.getType()); }
From source file:fr.paris.lutece.portal.web.admin.AdminPageJspBeanTest.java
public void testDoRemovePageNotExisting() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.PAGE_ID, Integer.toString(314159265)); _bean.doRemovePage(request);//w w w . j a va2 s . co m AdminMessage message = AdminMessageService.getMessage(request); assertNotNull(message); assertEquals(AdminMessage.TYPE_ERROR, message.getType()); }
From source file:fr.paris.lutece.portal.web.admin.AdminPageJspBeanTest.java
public void testDoRemovePage() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.PAGE_ID, Integer.toString(_page.getId())); request.addParameter(SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance().getToken(request, "jsp/admin/site/DoRemovePage.jsp")); _bean.doRemovePage(request);//from www .j av a 2 s .com assertFalse(PageHome.checkPageExist(_page.getId())); }
From source file:fr.paris.lutece.portal.web.admin.AdminPageJspBeanTest.java
public void testDoRemovePageNoToken() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.PAGE_ID, Integer.toString(_page.getId())); try {/*from w w w. j a v a 2 s .co m*/ _bean.doRemovePage(request); fail("Should have thrown"); } catch (AccessDeniedException e) { assertTrue(PageHome.checkPageExist(_page.getId())); } }
From source file:fr.paris.lutece.portal.web.admin.AdminPageJspBeanTest.java
public void testDoRemovePageInvalidToken() throws AccessDeniedException { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(Parameters.PAGE_ID, Integer.toString(_page.getId())); request.addParameter(SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance().getToken(request, "jsp/admin/site/DoRemovePage.jsp") + "b"); try {// w ww .ja v a 2s .com _bean.doRemovePage(request); fail("Should have thrown"); } catch (AccessDeniedException e) { assertTrue(PageHome.checkPageExist(_page.getId())); } }