LoginClientImpl implements LoginClient { public LoginResponse login(final String serengetiURL, String userName, String password) throws IOException { String url = serengetiURL + Constants.REST_PATH_LOGIN; HttpPost loginPost = new HttpPost(url); NameValuePair[] loginCredentials = new NameValuePair[] { new BasicNameValuePair("j_username", userName) , new BasicNameValuePair("j_password", password) }; HttpEntity requestEntity = new UrlEncodedFormEntity(Arrays.asList(loginCredentials), Charset.forName("UTF-8")); loginPost.setEntity(requestEntity); HttpResponse response; try { response = client1.execute(loginPost); LOGGER.debug("resp code is: " + response.getStatusLine()); int responseCode = response.getStatusLine().getStatusCode(); LoginResponse loginResponse; if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String cookieValue = null; Header[] setCookieHeaders = response.getHeaders(SET_COOKIE_HEADER); if (ArrayUtils.isNotEmpty(setCookieHeaders)) { cookieValue = setCookieHeaders[0].getValue(); if (StringUtils.isNotBlank(cookieValue) && cookieValue.contains(";")) { cookieValue = cookieValue.split(";")[0]; } } loginResponse = new LoginResponse(responseCode, cookieValue); } else { loginResponse = new LoginResponse(responseCode, null); } return loginResponse; } finally { loginPost.releaseConnection(); } }  LoginResponse login(final String serengetiURL, String userName, String password);  }
@Test(dataProvider = "loginClientImplTest.Default") public void testLogin(String userName, String passWord, int responseCode, String sessionId) throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { LoginTestTemplate testTemplate = new LoginTestTemplate(userName, passWord, responseCode, sessionId); testTemplate.start(); try { LoginResponse loginResponse = loginClient.login("http: Assert.assertEquals(loginResponse.getResponseCode(), responseCode); Assert.assertEquals(loginResponse.toString(), String.format("responseCode:%1s;sessionId:%2s", loginResponse.getResponseCode(), loginResponse.getSessionId())); if(sessionId != null) { Assert.assertEquals(loginResponse.getSessionId(), "JSESSIONID=" + sessionId); } } finally { testTemplate.stop(); } }