/** * Used by functions testing the queryContactStatus method of the presence operation set. * * @param taStatusLong the icq status as specified by FullUserInfo, that the tester agent should * switch to. * @param expectedReturn the PresenceStatus that the presence operation set should see the tester * agent in once it has switched to taStatusLong. * @throws java.lang.Exception if querying the status causes some exception. */ public void subtestQueryContactStatus(long taStatusLong, PresenceStatus expectedReturn) throws Exception { if (!fixture.testerAgent.enterStatus(taStatusLong)) { throw new RuntimeException( "Tester UserAgent Failed to switch to the " + expectedReturn.getStatusName() + " state."); } PresenceStatus actualReturn = operationSetPresence.queryContactStatus(fixture.testerAgent.getIcqUIN()); assertEquals( "Querying a " + expectedReturn.getStatusName() + " state did not return as expected", expectedReturn, actualReturn); }
/** * Used by methods testing state transiotions * * @param newStatus the IcqStatusEnum field corresponding to the status that we'd like the * opeation set to enter. * @throws Exception in case changing the state causes an exception */ public void subtestStateTransition(IcqStatusEnum newStatus) throws Exception { logger.trace(" --=== beginning state transition test ===--"); PresenceStatus oldStatus = operationSetPresence.getPresenceStatus(); String oldStatusMessage = operationSetPresence.getCurrentStatusMessage(); String newStatusMessage = statusMessageRoot + newStatus; logger.debug( "old status is=" + oldStatus.getStatusName() + " new status=" + newStatus.getStatusName()); // First register a listener to make sure that all corresponding // events have been generated. PresenceStatusEventCollector statusEventCollector = new PresenceStatusEventCollector(); operationSetPresence.addProviderPresenceStatusListener(statusEventCollector); // change the status operationSetPresence.publishPresenceStatus(newStatus, newStatusMessage); // test event notification. statusEventCollector.waitForPresEvent(10000); statusEventCollector.waitForStatMsgEvent(10000); // sometimes we don't get response from the server for the // changed status. we will query it once again. // and wait for the response if (statusEventCollector.collectedPresEvents.size() == 0) { logger.trace("Will query again status as we haven't received one"); operationSetPresence.queryContactStatus(fixture.icqAccountID.getUserID()); statusEventCollector.waitForPresEvent(10000); } operationSetPresence.removeProviderPresenceStatusListener(statusEventCollector); assertEquals( "Events dispatched during an event transition.", 1, statusEventCollector.collectedPresEvents.size()); assertEquals( "A status changed event contained wrong old status.", oldStatus, ((ProviderPresenceStatusChangeEvent) statusEventCollector.collectedPresEvents.get(0)) .getOldStatus()); assertEquals( "A status changed event contained wrong new status.", newStatus, ((ProviderPresenceStatusChangeEvent) statusEventCollector.collectedPresEvents.get(0)) .getNewStatus()); // verify that the operation set itself is aware of the status change assertEquals( "opSet.getPresenceStatus() did not return properly.", newStatus, operationSetPresence.getPresenceStatus()); IcqStatusEnum actualStatus = fixture.testerAgent.getBuddyStatus(fixture.icqAccountID.getUserID()); assertEquals( "The underlying implementation did not switch to the " + "requested presence status.", newStatus, actualStatus); // check whether the server returned the status message that we've set. assertEquals( "No status message events.", 1, statusEventCollector.collectedStatMsgEvents.size()); assertEquals( "A status message event contained wrong old value.", oldStatusMessage, ((PropertyChangeEvent) statusEventCollector.collectedStatMsgEvents.get(0)).getOldValue()); assertEquals( "A status message event contained wrong new value.", newStatusMessage, ((PropertyChangeEvent) statusEventCollector.collectedStatMsgEvents.get(0)).getNewValue()); // verify that the operation set itself is aware of the new status msg. assertEquals( "opSet.getCurrentStatusMessage() did not return properly.", newStatusMessage, operationSetPresence.getCurrentStatusMessage()); logger.trace(" --=== finished test ===--"); // make it sleep a bit cause the aol server gets mad otherwise. pauseBetweenStateChanges(); }