private void verifyNecessaryChecks(String actionString) throws Exception { verifyStatic(org.mockito.Mockito.times(1)); ConnectionUtil.checkParameter(actionString); verifyStatic(org.mockito.Mockito.times(1)); ConnectionUtil.checkParameter(versionString); verifyStatic(org.mockito.Mockito.times(1)); ConnectionUtil.checkVersion(versionString); }
private void prepareEnterAuthenticateOneTimeUser(boolean authenticated) throws Exception { when(mockHttpServletRequest.getParameter(ServletUtil.VERSION)).thenReturn(versionString); when(mockHttpServletRequest.getParameter(ServletUtil.LOGIN)).thenReturn(loginString); when(mockHttpServletRequest.getParameter(ServletUtil.PASSWD)).thenReturn(passwdString); spy(ConnectionUtil.class); doNothing().when(ConnectionUtil.class); ConnectionUtil.checkParameter(versionString); doNothing().when(ConnectionUtil.class); ConnectionUtil.checkVersion(versionString); prepareForOtpManagerHelper(); when(otpManagerHelper.authenticateOneTimeUser(anyString(), (byte[]) any())) .thenReturn(authenticated); mockUserHelper = mock(UserHelper.class); whenNew(UserHelper.class).withNoArguments().thenReturn(mockUserHelper); User user = AdminFactory.eINSTANCE.createUser(); user.setLogin("*****@*****.**"); when(mockUserHelper.findByLogin(anyString())).thenReturn(user); }
@Test public void testListProjectsActionSentByCmdline() throws Exception { String actionString = Action.ListProjects.toString(); String loginString = ServletUtil.COMMAND_LIST_PROJECTS_HOOK; String passwdString = "any"; when(mockHttpServletRequest.getParameter(ServletUtil.ACTION)).thenReturn(actionString); when(mockHttpServletRequest.getParameter(ServletUtil.VERSION)).thenReturn(versionString); when(mockHttpServletRequest.getParameter(ServletUtil.LOGIN)).thenReturn(loginString); when(mockHttpServletRequest.getParameter(ServletUtil.PASSWD)).thenReturn(passwdString); spy(ConnectionUtil.class); doNothing().when(ConnectionUtil.class); ConnectionUtil.checkParameter(versionString); doNothing().when(ConnectionUtil.class); ConnectionUtil.checkVersion(versionString); String xmi = constructProjectsObjectsXmi(); doThrow( new org.talend.gwtadministrator.server.remoteconnection.ConnectionUtil .ResponseException(xmi)) .when(ConnectionUtil.class); ConnectionUtil.listAllProjects((User) any()); // RUN... defaultConnectionStrategy.execute(mockHttpServletRequest, mockHttpServletResponse); verifyNecessaryChecks(actionString); verifyStatic(org.mockito.Mockito.times(1)); ConnectionUtil.listAllProjects((User) any()); PrintWriter writer = mockHttpServletResponse.getWriter(); writer.flush(); System.out.println(outStringWriter.toString()); // ASSERT... assertThat(outStringWriter.toString(), is("RESPONSE:" + xmi)); }
@Test public void testGetWarningAction() throws Exception { String actionString = Action.GetWarning.toString(); String warningMsg = "It's a warning message"; String encodedMsg = EncryptionHelper.encode64(warningMsg.getBytes()); when(mockHttpServletRequest.getParameter(ServletUtil.ACTION)).thenReturn(actionString); when(mockHttpServletRequest.getParameter(ServletUtil.VERSION)).thenReturn(versionString); spy(ConnectionUtil.class); doNothing().when(ConnectionUtil.class); ConnectionUtil.checkParameter(versionString); doNothing().when(ConnectionUtil.class); ConnectionUtil.checkVersion(versionString); doThrow( new org.talend.gwtadministrator.server.remoteconnection.ConnectionUtil .ResponseException(encodedMsg)) .when(ConnectionUtil.class); ConnectionUtil.getWarnings(); // RUN... defaultConnectionStrategy.execute(mockHttpServletRequest, mockHttpServletResponse); verifyNecessaryChecks(actionString); verifyStatic(org.mockito.Mockito.times(1)); ConnectionUtil.getWarnings(); PrintWriter writer = mockHttpServletResponse.getWriter(); writer.flush(); System.out.println(outStringWriter.toString()); // ASSERT... assertThat(outStringWriter.toString(), is("RESPONSE:" + encodedMsg)); }