List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse
MockHttpServletResponse
From source file:org.sventon.web.AbstractHttpAuthenticationHandlerTest.java
@Test public void testSendChallenge() throws Exception { final MockHttpServletResponse response = new MockHttpServletResponse(); handler.sendChallenge(response);//from w w w . jav a2 s . co m assertEquals("basic realm=\"realm\"", response.getHeader(AbstractHttpAuthenticationHandler.AUTHENTICATE_HEADER)); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus()); }
From source file:org.openmrs.web.controller.program.ProgramFormControllerTest.java
/** * @see ProgramFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException) *//*from w w w . j av a 2 s .c o m*/ @Test @Transactional(readOnly = true) @Verifies(value = "should save workflows with program", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)") public void onSubmit_shouldSaveWorkflowsWithProgram() throws Exception { // sanity check to make sure that program #3 doesn't have any workflows already: Assert.assertEquals(0, Context.getProgramWorkflowService().getProgram(3).getAllWorkflows().size()); MockHttpServletRequest request = new MockHttpServletRequest("POST", ""); request.setParameter("programId", "3"); request.setParameter("allWorkflows", ":3"); // set one workflow on this program ProgramFormController controller = (ProgramFormController) applicationContext.getBean("programForm"); controller.handleRequest(request, new MockHttpServletResponse()); Assert.assertNotSame(0, Context.getProgramWorkflowService().getProgram(3).getAllWorkflows().size()); Assert.assertEquals(1, Context.getProgramWorkflowService().getProgram(3).getAllWorkflows().size()); }
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:com.sse.abtester.VariantSelectionFilterTest.java
/** * Reinit./*from w ww . j a v a2 s . c om*/ */ @Before public void reinit() { // make a Mockito mock of the FC so we can verify it gets called fc = mock(FilterChain.class); mockReq = new MockHttpServletRequest(); mockReq.setSession(new MockHttpSession()); mockRes = new MockHttpServletResponse(); VM = mock(VariantManager.class); vsf = new VariantSelectionFilter(); try { vsf.init(new MockFilterConfig()); } catch (ServletException e) { // TODO Auto-generated catch block e.printStackTrace(); } vsf.setVariantManager(VM); vsf.setVSKEY(VSKEY); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.PatientIdentifierTypeControllerTest.java
@Before public void before() { this.service = Context.getPatientService(); this.controller = new PatientIdentifierTypeController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); }
From source file:org.openmrs.web.controller.ForgotPasswordFormControllerTest.java
/** * Check to see if the admin's secret question comes back * * @throws Exception/*from w ww .j ava 2 s . com*/ */ @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:edu.northwestern.bioinformatics.studycalendar.web.WebTestCase.java
@Override protected void setUp() throws Exception { super.setUp(); servletContext = new MockServletContext(); session = new MockHttpSession(servletContext); request = new MockHttpServletRequest(servletContext); request.setMethod("POST"); request.setSession(session);/* ww w.j a va 2s. c om*/ response = new MockHttpServletResponse(); templateService = new TestingTemplateService(); controllerTools = new ControllerTools(); controllerTools.setTemplateService(templateService); }
From source file:ch.rasc.extclassgenerator.ModelGeneratorBeanWithValidationTest.java
@Test public void testWriteModelHttpServletRequestHttpServletResponseClassOfQOutputFormatBoolean() throws IOException { MockHttpServletResponse response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithValidation.class, OutputFormat.EXTJS4, IncludeValidation.ALL, true); GeneratorTestUtil.compareExtJs4Code("BeanWithValidation", response.getContentAsString(), true, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithValidation.class, OutputFormat.TOUCH2, IncludeValidation.ALL, false); GeneratorTestUtil.compareTouch2Code("BeanWithValidation", response.getContentAsString(), false, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithValidation.class, OutputFormat.EXTJS4, IncludeValidation.ALL, true); GeneratorTestUtil.compareExtJs4Code("BeanWithValidation", response.getContentAsString(), true, false); response = new MockHttpServletResponse(); ModelGenerator.writeModel(new MockHttpServletRequest(), response, BeanWithValidation.class, OutputFormat.TOUCH2, IncludeValidation.ALL, true); GeneratorTestUtil.compareTouch2Code("BeanWithValidation", response.getContentAsString(), true, false); }
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.araneaframework.tests.servlet.router.StandardServletSessionRouterServiceTests.java
public void setUp() throws Exception { service = new StandardServletSessionRouterService(); child = new MockEventfulBaseService(); ServiceFactory factory = new ServiceFactory() { public Service buildService() { return child; }/*from w w w . j a v a 2s. c o m*/ }; service.setSessionServiceFactory(factory); MockLifeCycle.begin(service); req = new MockHttpServletRequest(); res = new MockHttpServletResponse(); input = new StandardServletInputData(req); output = new StandardServletOutputData(req, res); }