List of usage examples for org.springframework.mock.web MockHttpServletRequest MockHttpServletRequest
public MockHttpServletRequest()
From source file:fr.paris.lutece.plugins.mylutece.util.SecurityUtilsTest.java
public void testBuildResetConnectionLogUrl() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRemoteAddr("127.0.0.1"); String strUrl = SecurityUtils.buildResetConnectionLogUrl(1, request); assertNotNull(strUrl);/* w w w. j av a 2 s. c om*/ assertTrue(strUrl.contains("jsp/site/plugins/mylutece/DoResetConnectionLog.jsp")); Pattern pattern = Pattern.compile("[\\?&]([^=]+)=([^&]+)"); Matcher matcher = pattern.matcher(strUrl); int matchCount = 0; for (int i = 0; i < 4; i++) { assertTrue(matcher.find()); String strParamName = matcher.group(1); String strParamValue = matcher.group(2); if ("ip".equals(strParamName)) { assertEquals("127.0.0.1", strParamValue); matchCount++; } else if ("date_login".equals(strParamName)) { assertTrue(StringUtils.isNumeric(strParamValue)); matchCount++; } else if ("interval".equals(strParamName)) { assertEquals("1", strParamValue); matchCount++; } else if ("key".equals(strParamName)) { assertTrue(strParamValue.matches("[0-9a-f]{64}")); matchCount++; } } assertEquals(4, matchCount); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.DrugControllerTest.java
@Before public void before() { this.service = Context.getConceptService(); this.controller = new DrugController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); }
From source file:com.healthcit.cacure.web.controller.LoginControllerTest.java
@SuppressWarnings("unchecked") @Test/*w ww. j a va2 s . co m*/ public void testOnSubmitForWithoutValidationErrors() { String expected = "login"; Map inputMap = new HashMap(); inputMap.put(ContentElementEditController.FORM_ID_NAME, 2l); UserCredentials userCredentials = new UserCredentials(); userCredentials.setUserName("Testing"); userCredentials.setPassword("TestPassword"); BindingResult bindingResult = new BeanPropertyBindingResult(userCredentials, "userCredentials"); String actual = loginController.onSubmit(userCredentials, bindingResult, new MockHttpServletRequest(), new MockHttpServletResponse()); Assert.assertNotNull(actual); Assert.assertEquals(expected, actual); }
From source file:fi.okm.mpass.idp.authn.impl.FacebookIdentityTest.java
@Test public void testUnforcedAuthRedirect() { final String redirectUrl = identity.getRedirectUrl(new MockHttpServletRequest()); Assert.assertNotNull(redirectUrl);/*from w w w . j ava 2 s .c o m*/ Assert.assertFalse(redirectUrl.contains("&auth_type=")); }
From source file:com.enonic.cms.itest.client.InternalClientImpl_changeUserPasswordTest.java
@Before public void before() throws IOException, JDOMException { fixture.initSystemData();//from ww w .j a va 2 s . co m MockHttpServletRequest request = new MockHttpServletRequest(); request.setRemoteAddr("127.0.0.1"); ServletRequestAccessor.setRequest(request); PortalSecurityHolder.setAnonUser(fixture.findUserByName("anonymous").getKey()); }
From source file:com.thoughtworks.go.server.web.FileViewTest.java
@Before public void setUp() throws Exception { temporaryFolder.create();// w w w. j a va 2 s. c o m mockRequest = new MockHttpServletRequest(); mockResponse = new MockHttpServletResponse(); mockServletContext = mock(ServletContext.class); view = new FileView(); view.setServletContext(mockServletContext); file = temporaryFolder.newFile("file.txt"); FileUtils.writeStringToFile(file, "hello", UTF_8); }
From source file:com.sse.abtester.VariantSelectionFilterTest.java
/** * Reinit./* w w w. java 2 s . co m*/ */ @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.PersonAddressControllerTest.java
@Before public void before() { this.service = Context.getPersonService(); this.controller = new PersonAddressController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); }
From source file:com.jl.crm.web.OAuthTest.java
@Before public void setup() { request = new MockHttpServletRequest(); request.setMethod("GET"); response = new MockHttpServletResponse(); chain = new MockFilterChain(); }
From source file:org.openmrs.module.kenyaemr.rest.AccessReportsByRestWebServiceTest.java
@Test public void shouldListDataSetDefinitionsByWebService() throws Exception { // equivalent to doing "GET .../datasetdefinition" SimpleObject result = dsdController.getAll(new MockHttpServletRequest(), new MockHttpServletResponse()); List<SimpleObject> simpleDSDs = (List<SimpleObject>) result.get("results"); Assert.assertNotNull(simpleDSDs);//from w w w. j a v a 2 s .c o m for (SimpleObject simpleDSD : simpleDSDs) { Assert.assertNotNull(simpleDSD); Assert.assertNotNull(simpleDSD.get("uuid")); Assert.assertNotNull(simpleDSD.get("display")); Assert.assertNotNull(simpleDSD.get("links")); } //printJson(result); }