@Test public void testRelogin() throws IOException { Mockito.when( loginClient.login(Matchers.anyString(), Matchers.anyString(), Matchers.anyString())) .thenReturn(new LoginResponse(200, "JSESSIONID=B6926322AF4D8A8B9CEF3906D5735D41")); Connect.ConnectType connectType = restClient.connect("127.0.0.1:8443", "root", "vmware"); Assert.assertEquals(connectType, Connect.ConnectType.SUCCESS); Mockito.when( loginClient.login(Matchers.anyString(), Matchers.anyString(), Matchers.anyString())) .thenReturn(new LoginResponse(200, null)); connectType = restClient.connect("127.0.0.1:8443", "root", "vmware"); Assert.assertEquals(connectType, Connect.ConnectType.SUCCESS); }
@Test public void testLoginWithException() throws IOException { Mockito.when( loginClient.login(Matchers.anyString(), Matchers.anyString(), Matchers.anyString())) .thenThrow(new IOException("can't connect to network")); Connect.ConnectType connectType = restClient.connect("127.0.0.1:8443", "root", "vmware"); Assert.assertEquals(connectType, Connect.ConnectType.ERROR); }
@Test(dataProvider = "RestClientTest.LoginDP") public void testLogin(LoginResponse loginResponse, Connect.ConnectType expectedConnectType) throws IOException { Mockito.when( loginClient.login(Matchers.anyString(), Matchers.anyString(), Matchers.anyString())) .thenReturn(loginResponse); Connect.ConnectType connectType = restClient.connect("127.0.0.1:8443", "root", "vmware"); Assert.assertEquals(connectType, expectedConnectType); if (loginResponse.getSessionId() != null) { Assert.assertEquals(loginResponse.getSessionId(), CookieCache.get(CookieCache.COOKIE)); } }