List of usage examples for org.springframework.mock.web MockHttpServletRequest addParameter
public void addParameter(String name, String... values)
From source file:eu.trentorise.smartcampus.permissionprovider.test.AuthorityMappingTest.java
@Test public void testUsers() { MockHttpServletRequest req = new MockHttpServletRequest(); req.addParameter("openid.ext1.value.name", "mario"); req.addParameter("openid.ext1.value.surname", "rossi"); req.addParameter("openid.ext1.value.email", "mario.rossi@gmail.com"); providerServiceAdapter.updateUser("google", new HashMap<String, String>(), req); List<User> users = userRepository.findByFullNameLike("mario rossi"); Assert.assertNotNull(users);//from w w w . j a v a 2 s . c om Assert.assertEquals(1, users.size()); providerServiceAdapter.updateUser("googlelocal", new HashMap<String, String>(), req); users = userRepository.findByFullNameLike("mario rossi"); Assert.assertNotNull(users); Assert.assertEquals(1, users.size()); req = new MockHttpServletRequest(); req.addParameter("openid.ext1.value.name", "mario"); req.addParameter("openid.ext1.value.surname", "rossi"); req.addParameter("openid.ext1.value.email", "mario.rossi2@gmail.com"); providerServiceAdapter.updateUser("google", new HashMap<String, String>(), req); users = userRepository.findByFullNameLike("mario rossi"); Assert.assertNotNull(users); Assert.assertEquals(2, users.size()); }
From source file:org.jasig.cas.web.ProxyControllerTests.java
@Test public void testExistingPGT() throws Exception { final TicketGrantingTicket ticket = new TicketGrantingTicketImpl("ticketGrantingTicketId", TestUtils.getAuthentication(), new NeverExpiresExpirationPolicy()); getTicketRegistry().addTicket(ticket); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("pgt", ticket.getId()); request.addParameter("targetService", "testDefault"); assertTrue(this.proxyController.handleRequestInternal(request, new MockHttpServletResponse()).getModel() .containsKey("ticket")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.CohortMemberControllerTest.java
@Test public void getAllCohortMembers_shouldGetADefaultRepresentationOfAllCohortMembers() throws Exception { int size = service.getCohortByUuid(cohortUuid).getMemberIds().size(); MockHttpServletRequest req = new MockHttpServletRequest(); req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL); SimpleObject result = controller.getAll(cohortUuid, req, response); Assert.assertNotNull(result);//from w w w .j av a 2 s . co m Util.log("Cohort member fetched (default)", result); Assert.assertEquals(Util.getResultsSize(result), size); }
From source file:org.sventon.web.ctrl.template.SearchLogsControllerTest.java
@Test public void testSvnHandle() throws Exception { final CacheGateway mockCache = EasyMock.createMock(CacheGateway.class); final MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter(SEARCH_STRING_PARAMETER, "abc"); request.addParameter(START_DIR_PARAMETER, "/trunk/"); final BaseCommand command = new BaseCommand(); command.setPath("trunk/test"); command.setName(new RepositoryName("test")); command.setRevision(Revision.create(12)); final SearchLogsController ctrl = new SearchLogsController(); ctrl.setCacheGateway(mockCache);// www .j a v a2s . c o m final List<LogMessageSearchItem> result = new ArrayList<LogMessageSearchItem>(); result.add(new LogMessageSearchItem( TestUtils.createLogEntry(123, "jesper", new Date(), "Revision 123.", null))); expect(mockCache.find(command.getName(), "abc", "/trunk/")).andStubReturn(result); replay(mockCache); final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, request, null, null); final Map model = modelAndView.getModel(); verify(mockCache); assertEquals(4, model.size()); assertEquals("abc", model.get(SEARCH_STRING_PARAMETER)); assertEquals("/trunk/", model.get(START_DIR_PARAMETER)); assertEquals(result, model.get("logEntries")); assertTrue((Boolean) model.get("isLogSearch")); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.search.openmrs1_8.LocationSearchHandlerTest.java
/** * @verifies return location by tag name * @see LocationSearchHandler#getSearchConfig() *//*from w w w .ja va 2 s. c om*/ @Test public void getSearchConfig_shouldReturnLocationByTagName() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("tag", "General Hospital"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(1, hits.size()); Assert.assertEquals(service.getLocation(1).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); }
From source file:com.xyxy.platform.modules.core.web.ServletsTest.java
@Test public void getParametersStartingWith() { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("pre_a", "aa"); request.addParameter("pre_b", "bb"); request.addParameter("c", "c"); Map<String, Object> result = Servlets.getParametersStartingWith(request, "pre_"); assertThat(result).containsOnly(entry("a", "aa"), entry("b", "bb")); result = Servlets.getParametersStartingWith(request, "error_"); assertThat(result).isEmpty();/* ww w . jav a2 s .c om*/ result = Servlets.getParametersStartingWith(request, null); assertThat(result).hasSize(3); }
From source file:org.zilverline.web.TestZilverController.java
public void testFlushCacheHandler() { try {// www . j a v a 2 s . c o m ZilverController zilverC = (ZilverController) applicationContext.getBean("zilverController"); assertNotNull(zilverC); CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); // get testdate collection DocumentCollection testdata = colMan.getCollectionByName("testdata"); assertNotNull(testdata); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("collection", "testdata"); HttpServletResponse response = new MockHttpServletResponse(); ModelAndView mv = zilverC.flushCacheHandler(request, response); assertNotNull(mv); } catch (BeansException e) { fail(e.getMessage()); } catch (ServletException e) { fail(e.getMessage()); } }
From source file:org.openmrs.module.webservices.rest.web.v1_0.search.openmrs1_8.LocationSearchHandlerTest.java
/** * @verifies return location by tag uuid * @see LocationSearchHandler#getSearchConfig() *//*from w w w . jav a2 s . c om*/ @Test public void getSearchConfig_shouldReturnLocationByTagUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI()); req.addParameter("tag", "0940c6d4-47ed-11df-bc8b-001e378eb67e"); SimpleObject result = deserialize(handle(req)); List<Object> hits = (List<Object>) result.get("results"); Assert.assertEquals(2, hits.size()); List<Location> locations = service.getAllLocations(); Assert.assertEquals(service.getLocation(1).getUuid(), PropertyUtils.getProperty(hits.get(0), "uuid")); Assert.assertEquals(service.getLocation(2).getUuid(), PropertyUtils.getProperty(hits.get(1), "uuid")); }
From source file:org.zilverline.web.TestZilverController.java
public void testFailFlushCacheHandler() { try {/*from ww w.j a va 2 s.c om*/ ZilverController zilverC = (ZilverController) applicationContext.getBean("zilverController"); assertNotNull(zilverC); CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan"); // get testdate collection DocumentCollection testdata = colMan.getCollectionByName("testdata3"); assertNull(testdata); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("collection", "testdata3"); HttpServletResponse response = new MockHttpServletResponse(); ModelAndView mv = zilverC.flushCacheHandler(request, response); assertNotNull(mv); fail("Should throw ServletException"); } catch (BeansException e) { fail(e.getMessage()); } catch (ServletException e) { assertNotNull(e.getMessage()); } }
From source file:org.openmrs.contrib.metadatarepository.webapp.filter.LocaleFilterTest.java
public void testJstlLocaleIsSet() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("locale", "es"); MockHttpServletResponse response = new MockHttpServletResponse(); request.setSession(new MockHttpSession(null)); filter.doFilter(request, response, new MockFilterChain()); assertNotNull(Config.get(request.getSession(), Config.FMT_LOCALE)); }