public void testIsOnline() throws Exception { User mockUser = myTransport.createUser( "mock", new OnlineUserInfo(InetAddress.getLocalHost(), myTransport.getPort())); assertFalse(mockUser.isOnline()); myTransport.setOnlineUsers(Arrays.asList(mockUser)); assertTrue("should be online now", mockUser.isOnline()); assertTrue(UserImpl.create("mock", P2PTransport.CODE).isOnline()); }
public void testGetPort() throws Exception { User mockUser = UserImpl.create("mock", P2PTransport.CODE); assertEquals("Sanity check", -1, myTransport.getPort(mockUser)); new AddOnlineUserP2PCommand(myTransport.getUserMonitorThread()) .addOnlineUser("localhost", "mock", 3354, null, null); myTransport.flushCurrentUsers(); assertEquals( "Port should be set from available online user", 3354, myTransport.getPort(mockUser)); myTransport.setOnlineUsers(new HashSet<User>()); assertEquals("Port should be reset", -1, myTransport.getPort(mockUser)); }
public void testGetProjects() throws Exception { User mockUser = UserImpl.create("mock", P2PTransport.CODE); assertEquals("Sanity check", 0, myTransport.getProjects(mockUser).length); Vector<String> projects = new Vector<String>(Arrays.asList("project1", "project2")); new AddOnlineUserP2PCommand(myTransport.getUserMonitorThread()) .addOnlineUser("localhost", "mock", 0, projects, null); myTransport.flushCurrentUsers(); assertEquals( "Projects should be set from available online user", projects.toString(), Arrays.asList(myTransport.getProjects(mockUser)).toString()); myTransport.setOnlineUsers(new HashSet<User>()); assertEquals("Projects should be reset", 0, myTransport.getProjects(mockUser).length); }
public void testGetUserPresence() throws Exception { User mockUser = UserImpl.create("mock", P2PTransport.CODE); assertEquals( "Sanity check", PresenceMode.UNAVAILABLE, myTransport.getUserPresence(mockUser).getPresenceMode()); new AddOnlineUserP2PCommand(myTransport.getUserMonitorThread()) .addOnlineUser( "localhost", "mock", 3354, null, new UserPresence(PresenceMode.DND).toVector()); myTransport.flushCurrentUsers(); assertEquals( "User status should be set from available online user", PresenceMode.DND, myTransport.getUserPresence(mockUser).getPresenceMode()); myTransport.setOnlineUsers(new HashSet<User>()); assertEquals( "Presence should be reset", PresenceMode.UNAVAILABLE, myTransport.getUserPresence(mockUser).getPresenceMode()); }
public void testOnUserAdd_AnotherTransport() throws Exception { User mockUser = UserImpl.create("user", MockTransport.NAME); getBroadcaster().fireEvent(new UserEvent.Added(mockUser)); assertEquals("Should not send notification for another transport:" + myLog, "", myLog); }
public void testOnUserAdd() throws Exception { User mockUser = UserImpl.create("user", myTransport.getName()); getBroadcaster().fireEvent(new UserEvent.Added(mockUser)); assertEquals("Should send notification", "sendUserAddedCallback" + mockUser, myLog); }