List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse
MockHttpServletResponse
From source file:com.gopivotal.cla.security.AdminEmailDomainFilterTest.java
@Test(expected = AccessDeniedException.class) public void attemptAuthenticationNonValidAdminDomain() throws IOException, ServletException { Emails emails = new Emails(); when(this.gitHubClient.getEmails()).thenReturn(emails); emails.add(new Email("email@other.domain", false, true)); this.filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.ConceptControllerTest.java
@Before public void before() { this.service = Context.getConceptService(); this.controller = new ConceptController(); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); }
From source file:fragment.web.LogoControllerTest.java
@Test public void testGetUserLogo() { logoController.getUserLogo("B3B26BBF-119C-4F42-9DD3-36B6478D35E8", map, response); checkCorrectnessForNullPath();//from ww w . j av a2 s . c o m response = new MockHttpServletResponse(); logoController.getUserLogo("0e04370a-e407-490f-8256-40c4e8c4fb6b", map, response); checkCorrectnessOfMethod(response); }
From source file:org.sventon.web.ctrl.SubmitConfigurationsControllerTest.java
@Test public void testHandleRequestInternalNoAddedRepository() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); final SubmitConfigurationsController controller = new SubmitConfigurationsController(); application.setConfigured(false);/*from w w w. ja v a 2 s .c o m*/ controller.setApplication(application); final ModelAndView modelAndView = controller.handleRequestInternal(request, response); assertEquals("error/configurationError", modelAndView.getViewName()); }
From source file:com.hp.autonomy.frontend.find.hod.view.HodViewControllerTest.java
@Test public void handleKnownHodErrorException() { when(controllerUtils.getMessage(anyString(), any(Object[].class))).thenReturn("Some known error message"); assertNotNull(//from w ww. j a v a2 s. c o m viewController.handleHodErrorException(new HodErrorException(new HodError.Builder().build(), 400), new MockHttpServletRequest(), new MockHttpServletResponse())); verify(controllerUtils).buildErrorModelAndView(any(ErrorModelAndViewInfo.class)); }
From source file:ar.com.zauber.commons.spring.exceptions.HeaderBasedStatusSimpleMappingExceptionHandlerTest.java
/** test */ public final void testFoo() { final Properties views = new Properties(); views.put(NotOwnerException.class.getName(), "notowner"); views.put(IllegalArgumentException.class.getName(), "arguments"); views.put(DataAccessResourceFailureException.class.getName(), "data"); final Properties status = new Properties(); status.put("arguments", "400"); status.put("notowner", "403"); status.put("data", "500"); AbstractView view = new AbstractView() { @Override/* w w w. j ava 2s. c om*/ protected void renderMergedOutputModel(final Map<String, Object> model, final HttpServletRequest request, final HttpServletResponse response) throws Exception { } }; view.setBeanName("test"); final HeaderBasedStatusSimpleMappingExceptionHandler h = new HeaderBasedStatusSimpleMappingExceptionHandler( view, "application/json"); h.setDefaultStatusCode(200); h.setExceptionMappings(views); h.setStatusMappings(status); h.setDefaultErrorView("default"); MockHttpServletResponse response; ModelAndView v; response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("Accept", "application/json"); v = h.resolveException(request, response, null, new IllegalArgumentException("io!io!")); assertEquals(view, v.getView()); assertEquals(400, response.getStatus()); }
From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java
@Test public void testRedirect() throws Exception { final MockHttpSession session = new MockHttpSession(); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); final FilterChain filterChain = new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { // nothing to do }//from w ww . j av a 2s .c o m }; request.setSession(session); this.filter.doFilter(request, response, filterChain); assertEquals(CAS_LOGIN_URL + "?service=" + URLEncoder.encode(CAS_SERVICE_URL, "UTF-8"), response.getRedirectedUrl()); }
From source file:nl.eveoh.sakai.mytimetable.tool.ToolControllerTest.java
@Test public void testModel() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); request.setMethod("GET"); // Display two test events List<Event> testEvents = new ArrayList<Event>(); testEvents.add(new Event()); testEvents.add(new Event()); Mockito.when(myTimetableService.getUpcomingEvents(Mockito.anyString())).thenReturn(testEvents); Mockito.when(configuration.getApplicationUri()).thenReturn("https://timetable.institution.ac.uk/"); Mockito.when(configuration.getApplicationTarget()).thenReturn("_blank"); ModelAndView modelAndView = toolController.handleRequest(request, response); Assert.assertTrue("Should contain events attribute.", modelAndView.getModelMap().containsAttribute("events")); Assert.assertTrue(modelAndView.getModelMap().containsAttribute("applicationUri")); Assert.assertTrue(modelAndView.getModelMap().containsAttribute("applicationTarget")); Assert.assertEquals("Should display 5 events.", 2, ((List<Event>) modelAndView.getModelMap().get("events")).size()); Assert.assertEquals("https://timetable.institution.ac.uk/", modelAndView.getModelMap().get("applicationUri")); Assert.assertEquals("_blank", modelAndView.getModelMap().get("applicationTarget")); Assert.assertEquals(200, response.getStatus()); }
From source file:org.craftercms.security.processors.impl.SecurityExceptionProcessorTest.java
@Test public void testAuthenticationRequired() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext context = new RequestContext(request, response); RequestSecurityProcessorChain chain = mock(RequestSecurityProcessorChain.class); doThrow(AuthenticationRequiredException.class).when(chain).processRequest(context); processor.processRequest(context, chain); verify(chain).processRequest(context); verify(authenticationRequiredHandler).handle(eq(context), any(AuthenticationRequiredException.class)); }
From source file:org.jasig.cas.web.flow.SendTicketGrantingTicketActionTests.java
@Test public void testTgtToSet() throws Exception { final MockHttpServletResponse response = new MockHttpServletResponse(); final String TICKET_VALUE = "test"; WebUtils.putTicketGrantingTicketInRequestScope(this.context, TICKET_VALUE); this.context.setExternalContext( new ServletExternalContext(new MockServletContext(), new MockHttpServletRequest(), response)); assertEquals("success", this.action.execute(this.context).getId()); assertEquals(TICKET_VALUE, response.getCookies()[0].getValue()); }