public void test_for_issue() throws Exception { MockHttpServletRequest mockReq = new MockHttpServletRequest(); DefaultSavedRequest request = new DefaultSavedRequest(mockReq, new PortResolver() { public int getServerPort(ServletRequest servletRequest) { return 0; } }); String str = JSON.toJSONString(request, SerializerFeature.WriteClassName); // System.out.println(str); JSON.parseObject(str, Object.class, config); JSON.parseObject(str); }
@Test public void testDisplayLoginPageWithOriginalSavedRequestIfSetupComplete() throws Exception { when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true"); when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred"); when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE); when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE); when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.TRUE); MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest(); mockOriginalRequest.setScheme("https"); mockOriginalRequest.setServerName("example.org"); mockOriginalRequest.setServerPort(3333); mockOriginalRequest.setRequestURI("/foo/bar/baz"); PortResolver mockPortResolver = mock(PortResolver.class); when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333); // spring security will have put the original request in the session mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver)); ModelAndView mav = c.login(mockRequest, mockResponse); assertThat(mav.getViewName(), equalTo("/auth/login")); assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred")); }
@Test public void testDisplayLoginPageAfterAjaxRequestWhichFailedDueToExpiredSession() throws Exception { when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true"); when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred"); when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE); when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE); when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.TRUE); MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest(); mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest"); mockOriginalRequest.setScheme("https"); mockOriginalRequest.setServerName("example.org"); mockOriginalRequest.setServerPort(3333); mockOriginalRequest.setRequestURI("/foo/bar/baz"); PortResolver mockPortResolver = mock(PortResolver.class); when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333); // spring security will have put the original request in the session mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver)); ModelAndView mav = c.login(mockRequest, mockResponse); assertThat(mav.getViewName(), equalTo("/auth/login")); assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred")); }
@Test public void testDisplaySyncStatusPageWhenOperationalSyncIncomplete() throws Exception { when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true"); when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred"); when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.TRUE); MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest(); mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest"); mockOriginalRequest.setScheme("https"); mockOriginalRequest.setServerName("example.org"); mockOriginalRequest.setServerPort(3333); mockOriginalRequest.setRequestURI("/foo/bar/baz"); PortResolver mockPortResolver = mock(PortResolver.class); when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333); // spring security will have put the original request in the session mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver)); ModelAndView mav = c.login(mockRequest, mockResponse); assertThat(mav.getViewName(), equalTo("/auth/initializing")); assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred")); }
@Test public void testDisplayReindexStatusPageWhenReindexingIncomplete() throws Exception { when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true"); when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred"); when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE); when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.FALSE); MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest(); mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest"); mockOriginalRequest.setScheme("https"); mockOriginalRequest.setServerName("example.org"); mockOriginalRequest.setServerPort(3333); mockOriginalRequest.setRequestURI("/foo/bar/baz"); PortResolver mockPortResolver = mock(PortResolver.class); when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333); // spring security will have put the original request in the session mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver)); ModelAndView mav = c.login(mockRequest, mockResponse); assertThat(mav.getViewName(), equalTo("/auth/reindexing")); assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred")); }
@Test public void testDisplayDataStreamErrorPageWhenDataStreamFailure() throws Exception { when(mockEnvironment.getProperty(SETUP_COMPLETE)).thenReturn("true"); when(mockEnvironment.getProperty(HmpProperties.VERSION)).thenReturn("fred"); when(mockSyncService.isReindexAllComplete()).thenReturn(Boolean.TRUE); when(mockSyncService.isOperationalSynching()).thenReturn(Boolean.FALSE); when(mockSyncService.isDataStreamEnabled()).thenReturn(Boolean.FALSE); Map<String, Object> derr = new HashMap<>(); derr.put("disableMsg","There's a bar stuck in the foo"); when(mockSyncService.getDataStreamErrorDetails()).thenReturn(derr); MockHttpServletRequest mockOriginalRequest = new MockHttpServletRequest(); mockOriginalRequest.addHeader("X-Requested-With", "XMLHttpRequest"); mockOriginalRequest.setScheme("https"); mockOriginalRequest.setServerName("example.org"); mockOriginalRequest.setServerPort(3333); mockOriginalRequest.setRequestURI("/foo/bar/baz"); PortResolver mockPortResolver = mock(PortResolver.class); when(mockPortResolver.getServerPort(mockOriginalRequest)).thenReturn(3333); // spring security will have put the original request in the session mockSession.setAttribute("SPRING_SECURITY_SAVED_REQUEST", new DefaultSavedRequest(mockOriginalRequest, mockPortResolver)); ModelAndView mav = c.login(mockRequest, mockResponse); assertThat(mav.getViewName(), equalTo("/auth/dataStreamError")); assertThat(((String) mav.getModel().get("hmpVersion")), equalTo("fred")); }
public void setPortResolver(PortResolver portResolver) { this.portResolver = portResolver; }
protected PortResolver getPortResolver() { return portResolver; }
protected PortResolver getPortResolver() { return this.portResolver; }
@Before public void setUp() throws Exception { mockPortResolver = mock(PortResolver.class); }
/** * The port resolver. * * @return The port resolver. */ public PortResolver getPortResolver() { return portResolver; }
/** * The port resolver. * * @param portResolver The port resolver. */ public void setPortResolver(PortResolver portResolver) { this.portResolver = portResolver; }