protected static void singleServer(Server<?> server, Server<?> empty) { singleServer((StatelessServer) server, (StatelessServer) empty); assertNull(server.getAuthenticator()); assertEquals(TEST_MANAGER, server.getSessionManager()); assertNull(empty.getAuthenticator()); assertNull(empty.getSessionManager()); }
@Test public void session() throws Exception { Client c = new Client(); Server<Object> s = new Server<Object>(TEST_AUTHENTICATOR, TEST_MANAGER); assertEquals(TEST_AUTHENTICATOR, s.getAuthenticator()); try { c.assertValidSession(); fail(); } catch (I18NException ex) { assertEquals(Messages.NOT_LOGGED_IN, ex.getI18NBoundMessage()); } c.login(TEST_USER, TEST_PASSWORD); SessionId id = c.getSessionId(); assertNotNull(id); assertEquals(id, c.getContext().getSessionId()); assertEquals(TEST_USER, TEST_MANAGER.get(id).getUser()); try { c.login(TEST_USER, TEST_PASSWORD); fail(); } catch (I18NException ex) { assertEquals(Messages.ALREADY_LOGGED_IN, ex.getI18NBoundMessage()); } assertEquals(id, c.getSessionId()); assertEquals(TEST_USER, TEST_MANAGER.get(id).getUser()); c.logout(); assertNull(c.getSessionId()); assertNull(c.getContext().getSessionId()); assertNull(TEST_MANAGER.get(id)); try { c.login(TEST_USER_D, TEST_PASSWORD); fail(); } catch (RemoteException ex) { assertEquals(Messages.BAD_CREDENTIALS, ((I18NException) ex.getCause()).getI18NBoundMessage()); } assertNull(c.getSessionId()); c.logout(); s.stop(); try { c.login(TEST_USER, TEST_PASSWORD); fail(); } catch (WebServiceException ex) { // Desired. } }
private static <T> void calls(Server<T> server, Client client) { Client client2 = new Client(client.getHost(), client.getPort() + 1, client.getAppId()); calls( server, client, getStatelessContext(client).toString(), new Server<T>( client2.getHost(), client2.getPort(), server.getAuthenticator(), server.getSessionManager()), client2, getStatelessContext(client2).toString()); }