Search in sources :

Example 1 with NullProgressIndicator

use of jetbrains.communicator.ide.NullProgressIndicator in project intellij-plugins by JetBrains.

the class JabberUserFinderTest method testRegisterAndFindUser.

public void testRegisterAndFindUser() throws Throwable {
    URL url = new URL(JabberUserFinderImpl.TEST_URL);
    try {
        url.getContent();
    } catch (IOException e) {
        System.out.println("WARNING: " + JabberUserFinderImpl.TEST_URL + " not available");
        return;
    }
    myUserFinder.registerForProject("kir@localhost");
    Thread.sleep(400);
    User[] users = myUserFinder.findUsers(new NullProgressIndicator());
    assertEquals(1, users.length);
    assertEquals("kir@localhost", users[0].getName());
}
Also used : User(jetbrains.communicator.core.users.User) NullProgressIndicator(jetbrains.communicator.ide.NullProgressIndicator) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with NullProgressIndicator

use of jetbrains.communicator.ide.NullProgressIndicator in project intellij-plugins by JetBrains.

the class P2PTransportTest method testSetOwnPresence.

public void testSetOwnPresence() throws Exception {
    registerResponseProviders(myUserModel, myIdeFacade);
    // Add self to contact list
    User self = myUserModel.createUser(StringUtil.getMyUsername(), myTransport.getName());
    myUserModel.addUser(self);
    // Wait for next cycle of user finding
    new WaitFor(1000) {

        @Override
        protected boolean condition() {
            return !myTransport.getUserMonitorThread().isFinding();
        }
    };
    // make self away
    UserPresence presence = new UserPresence(PresenceMode.AWAY);
    assert presence.isOnline();
    myTransport.setOwnPresence(presence);
    // make sure that away status will be updated
    myTransport.findUsers(new NullProgressIndicator());
    assert PresenceMode.AWAY == self.getPresence().getPresenceMode();
    // Now, test itself. We go online and want this status to be updated almost immediately.
    myEvents.clear();
    addEventListener();
    myTransport.setOwnPresence(new UserPresence(PresenceMode.AVAILABLE));
    final User self1 = self;
    new WaitFor(200) {

        @Override
        protected boolean condition() {
            return self1.getPresence().getPresenceMode() == PresenceMode.AVAILABLE;
        }
    };
    assertSame("Should provide correct presence mode", PresenceMode.AVAILABLE, myTransport.getUserPresence(self).getPresenceMode());
    UserEvent.Updated event = (UserEvent.Updated) checkEvent(true);
    assertNotNull("Expect go online event", event);
    assertEquals("presence", event.getPropertyName());
}
Also used : MockUser(jetbrains.communicator.mock.MockUser) WaitFor(jetbrains.communicator.util.WaitFor) NullProgressIndicator(jetbrains.communicator.ide.NullProgressIndicator)

Example 3 with NullProgressIndicator

use of jetbrains.communicator.ide.NullProgressIndicator in project intellij-plugins by JetBrains.

the class ClearHistoryCommandTest method testClearHistory.

public void testClearHistory() throws Exception {
    myIdeMock.expects(once()).method("askQuestion").with(eq(StringUtil.getMsg("ClearHistoryCommand.title")), eq(StringUtil.getMsg("ClearHistoryCommand.text"))).will(returnValue(true));
    myIdeMock.expects(once()).method("runLongProcess").will(new CustomStub("runner") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            ((IDEFacade.Process) invocation.parameterValues.get(1)).run(new NullProgressIndicator());
            return null;
        }
    });
    myIdeMock.expects(once()).method("runOnPooledThread").will(new CustomStub("foo") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            final FutureTask task = new FutureTask((Runnable) invocation.parameterValues.get(0), null);
            task.run();
            return task;
        }
    });
    myDispatcherMock.expects(once()).method("clearHistory");
    myCommand.execute();
}
Also used : Invocation(org.jmock.core.Invocation) FutureTask(java.util.concurrent.FutureTask) CustomStub(org.jmock.core.stub.CustomStub) NullProgressIndicator(jetbrains.communicator.ide.NullProgressIndicator) IDEFacade(jetbrains.communicator.ide.IDEFacade)

Example 4 with NullProgressIndicator

use of jetbrains.communicator.ide.NullProgressIndicator in project intellij-plugins by JetBrains.

the class P2PTransport method initializeProject.

@Override
public void initializeProject(final String projectName, MutablePicoContainer projectLevelContainer) {
    getIdeFacade().runOnPooledThread(() -> {
        User[] users = findUsers(new NullProgressIndicator());
        Set<User> ourUsers = new HashSet<>();
        for (User user : users) {
            if (Arrays.asList(user.getProjects()).contains(projectName)) {
                ourUsers.add(user);
            }
        }
        if (canAddUsers(projectName, ourUsers)) {
            for (User user : ourUsers) {
                if (!myUserModel.hasUser(user)) {
                    user.setGroup(projectName, myUserModel);
                    myUserModel.addUser(user);
                }
            }
        }
    });
}
Also used : NullProgressIndicator(jetbrains.communicator.ide.NullProgressIndicator) THashSet(gnu.trove.THashSet)

Example 5 with NullProgressIndicator

use of jetbrains.communicator.ide.NullProgressIndicator in project intellij-plugins by JetBrains.

the class P2PTransportTest method testFindUsers.

public void testFindUsers() throws Exception {
    User[] users = myTransport.findUsers(new NullProgressIndicator());
    assertTrue("At least self should be found", users.length >= 1);
    User self = null;
    for (User user : users) {
        if (user.getName().equals(StringUtil.getMyUsername())) {
            self = user;
            break;
        }
    }
    assertNotNull("Self user not found in " + Arrays.asList(users), self);
    assertTrue("Self should be online", self.isOnline());
    InetAddress address = myTransport.getAddress(self);
    assertTrue("Self address is expected:" + address, NetworkUtil.isOwnAddress(address));
    assertEquals("Projects should be set", PROJECT_NAME, self.getProjects()[0]);
}
Also used : MockUser(jetbrains.communicator.mock.MockUser) NullProgressIndicator(jetbrains.communicator.ide.NullProgressIndicator) InetAddress(java.net.InetAddress)

Aggregations

NullProgressIndicator (jetbrains.communicator.ide.NullProgressIndicator)5 MockUser (jetbrains.communicator.mock.MockUser)2 THashSet (gnu.trove.THashSet)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 FutureTask (java.util.concurrent.FutureTask)1 User (jetbrains.communicator.core.users.User)1 IDEFacade (jetbrains.communicator.ide.IDEFacade)1 WaitFor (jetbrains.communicator.util.WaitFor)1 Invocation (org.jmock.core.Invocation)1 CustomStub (org.jmock.core.stub.CustomStub)1