public void testRequestFileAnnouncement() { mockDispatcher.setTestListener( new TestListener() { public void sendBackAction(Action action) { assertEquals("Bob", action.peer); assertEquals(ActionType.REQUEST_ANNOUNCE, action.actionType); } }); int status = announcer.requestFileAnnouncement("Bob"); assertEquals(StatusCode.NO_FILE_ANNOUNCEMENT_LISTENER, status); announcer.setFileAnnouncementReceivedListener(new Application()); status = announcer.requestFileAnnouncement("Bob"); assertEquals(StatusCode.OK, status); }
public void testHandleAnnouncementRequest() { testAnnounce(); mockDispatcher.setTestListener( new TestListener() { public void sendBackAction(Action action) { FileDescriptor[] files = (FileDescriptor[]) action.parameters.get(0); boolean isFileIdResponse = (Boolean) action.parameters.get(1); assertEquals(6, files.length); assertFalse(isFileIdResponse); assertNotNull(action.peer); assertEquals(ActionType.ANNOUNCE, action.actionType); } }); announcer.handleAnnouncementRequest("Steve"); }
public void testStopAnnounce() { testAnnounce(); mockDispatcher.setTestListener( new TestListener() { public void sendBackAction(Action action) { FileDescriptor[] files = (FileDescriptor[]) action.parameters.get(0); boolean isFileIdResponse = (Boolean) action.parameters.get(1); assertEquals(3, files.length); assertFalse(isFileIdResponse); assertNull(action.peer); assertEquals(ActionType.ANNOUNCE, action.actionType); } }); ArrayList<String> failedPaths = announcer.stopAnnounce(generatePathsToUnannounce()); assertEquals(1, failedPaths.size()); ArrayList<FileDescriptor> announcedFiles = mockPermissionsManager.getAnnouncedLocalFiles(); assertEquals(3, announcedFiles.size()); }
public void testAnnounce() { ArrayList<FileDescriptor> announcedFiles = mockPermissionsManager.getAnnouncedLocalFiles(); assertEquals(0, announcedFiles.size()); mockDispatcher.setTestListener( new TestListener() { public void sendBackAction(Action action) { FileDescriptor[] files = (FileDescriptor[]) action.parameters.get(0); boolean isFileIdResponse = (Boolean) action.parameters.get(1); assertEquals(6, files.length); assertFalse(isFileIdResponse); assertNull(action.peer); assertEquals(ActionType.ANNOUNCE, action.actionType); } }); announcer.setFileAnnouncmentSentListener( new FileAnnouncementSentListener() { public void announcementSent(ArrayList<String> failedPaths) { System.out.println( "AnnouncementSentListener - callback to announcementSent() executing"); assertEquals(4, failedPaths.size()); } }); ArrayList<String> pathList = new ArrayList<String>(); announcer.announce(pathList); try { Thread.sleep(5000); } catch (Exception ex) { System.out.println("Exception caught in thread sleep try catch block"); } announcedFiles = mockPermissionsManager.getAnnouncedLocalFiles(); assertEquals(6, announcedFiles.size()); }