List of usage examples for org.springframework.mock.web MockHttpServletRequest MockHttpServletRequest
public MockHttpServletRequest()
From source file:ru.org.linux.topic.TopicListControllerTest.java
@Before public void setUp() { request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); }
From source file:org.mifos.ui.loan.controller.AppInfoControllerTest.java
@SuppressWarnings("PMD.SignatureDeclareThrowsException") // Exception is thrown by AppInfoController.handleRequest public void testHandleRequestView() throws Exception { applicationInformationDto = new ApplicationInformationDto(); String expectedSvnRevision = "123456"; applicationInformationDto.setSvnRevision(expectedSvnRevision); String expectedBuildId = "fooId"; applicationInformationDto.setBuildId(expectedBuildId); String expectedBuildTag = "bar-baz-tag-1"; applicationInformationDto.setBuildTag(expectedBuildTag); AppInfoController controller = new AppInfoController(); controller.setAppInfo(applicationInformationDto); MockHttpServletRequest mockRequest = new MockHttpServletRequest(); mockRequest.setMethod("GET"); mockRequest.setRequestURI("/appInfo.ftl"); MockHttpServletResponse mockResponse = new MockHttpServletResponse(); ModelAndView modelAndView = controller.handleRequest(mockRequest, mockResponse); Assert.assertNotNull(modelAndView.getModel()); Map<String, Object> modelMap = (Map<String, Object>) modelAndView.getModel().get("model"); Assert.assertNotNull(modelMap);//from w w w . j a v a 2 s.co m ApplicationInformationDto actualApplicationInformationDto = (ApplicationInformationDto) modelMap .get("appInfo"); Assert.assertNotNull(actualApplicationInformationDto); Assert.assertEquals(actualApplicationInformationDto.getSvnRevision(), expectedSvnRevision); Assert.assertEquals(actualApplicationInformationDto.getBuildId(), expectedBuildId); Assert.assertEquals(actualApplicationInformationDto.getBuildTag(), expectedBuildTag); }
From source file:com.google.api.server.spi.request.AuthTest.java
@Before public void setUp() throws Exception { request = new MockHttpServletRequest(); attr = Attribute.from(request); attr.set(Attribute.API_METHOD_CONFIG, config); auth = Auth.from(request);//from w ww . j a v a 2s. c o m System.setProperty(EnvUtil.ENV_APPENGINE_RUNTIME, "Production"); }
From source file:com.hastybox.lesscss.compileservice.controller.spring.UrlBasedSpringLessControllerTest.java
/** * @throws java.lang.Exception/*from ww w .j a v a 2s . c o m*/ */ @Before public void setUp() throws Exception { controller = new UrlBasedSpringLessController(); compileService = mock(LessCompileService.class); resourceLoader = mock(ResourceLoader.class); resource = mock(Resource.class); controller.setCompileService(compileService); controller.setResourceLoader(resourceLoader); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); }
From source file:org.jasig.cas.web.support.WebUtilTests.java
public void testFoundNoService() { final SamlArgumentExtractor openIdArgumentExtractor = new SamlArgumentExtractor(); final ArgumentExtractor[] argumentExtractors = new ArgumentExtractor[] { openIdArgumentExtractor }; final MockHttpServletRequest request = new MockHttpServletRequest(); request.setParameter("service", "test"); final Service service = WebUtils.getService(Arrays.asList(argumentExtractors), request); assertNull(service);//from w w w . j a v a 2 s .c o m }
From source file:org.openmrs.web.controller.ForgotPasswordFormControllerTest.java
/** * Check to see if the admin's secret question comes back * * @throws Exception// ww w. j a va 2 s. c o m */ @Test public void shouldSetARandomSecretQuestionWhenTheUsernameIsInvalid() throws Exception { ForgotPasswordFormController controller = new ForgotPasswordFormController(); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.setParameter("uname", "invaliduser"); request.setMethod("POST"); controller.handleRequest(request, response); Assert.assertEquals("invaliduser", request.getAttribute("uname")); List<String> questions = new ArrayList<String>(); questions.add(Context.getMessageSourceService().getMessage("What is your best friend's name?")); questions.add(Context.getMessageSourceService().getMessage("What is your grandfather's home town?")); questions.add(Context.getMessageSourceService().getMessage("What is your mother's maiden name?")); questions.add(Context.getMessageSourceService().getMessage("What is your favorite band?")); questions.add(Context.getMessageSourceService().getMessage("What is your first pet's name?")); questions.add(Context.getMessageSourceService().getMessage("What is your brother's middle name?")); questions.add(Context.getMessageSourceService().getMessage("Which city were you born in?")); //Check that one of the fake questions is assigned to the invalid username Assert.assertTrue(questions.contains(request.getAttribute("secretQuestion"))); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.RoleControllerTest.java
/** * @see RoleController#create(SimpleObject, javax.servlet.http.HttpServletRequest, HttpServletResponse) * @verifies create a new Role/* w w w .j a v a 2 s .co m*/ */ @Test public void createRole_shouldCreateANewRole() throws Exception { int before = Context.getUserService().getAllRoles().size(); String json = "{\"name\":\"test\",\"description\":\"This is a test role for RoleControllerTest.\"}}"; SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class); Object newRole = new RoleController().create(post, new MockHttpServletRequest(), new MockHttpServletResponse()); Assert.assertEquals(before + 1, Context.getUserService().getAllRoles().size()); }
From source file:org.openmrs.web.servlet.ShowGraphServletTest.java
/** * @see ShowGraphServlet#getChart(HttpServletRequest) *//*from www . ja v a 2 s. c o m*/ @Test @Verifies(value = "should set value axis label to concept numeric units if given units is null", method = "getChart(HttpServletRequest)") public void getChart_shouldSetValueAxisLabelToConceptNumericUnitsIfGivenUnitsIsNull() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.setParameter("patientId", "7"); request.setParameter("conceptId", "5497"); // cd4 JFreeChart chart = new ShowGraphServlet().getChart(request); Assert.assertEquals("cells/mmL", chart.getXYPlot().getRangeAxis().getLabel()); }
From source file:org.openmrs.module.webservices.rest19ext.web.v1_0.controller.LocationAttributeControllerTest.java
@Before public void before() throws Exception { executeDataSet(Rest19ExtTestConstants.TEST_DATASET); this.service = Context.getLocationService(); this.controller = new LocationAttributeController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); }
From source file:org.terasoluna.gfw.web.logging.mdc.XTrackMDCPutFilterTest.java
@Test public void testGetMDCValue_default_attributeName() throws ServletException { xTrackMDCPutFilter.init(mockFilterConfig); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); String xTrack = xTrackMDCPutFilter.getMDCValue(request, response); assertThat(xTrack, is(notNullValue())); assertThat(xTrack.matches("^[a-f0-9]{32}$"), is(true)); assertThat(response.getHeader("X-Track"), is(xTrack)); assertThat((String) request.getAttribute("X-Track"), is(xTrack)); }