@Test public void testConstructor() { try { WorkItemLookupOperation operation = new WorkItemLookupOperation(null); Assert.fail(); } catch (IllegalArgumentException e) { // expected when ServerContext is null } // construct correctly WorkItemLookupOperation operation1 = new WorkItemLookupOperation( RepositoryContext.createGitContext("/root/one", "repo1", "branch1", "gitRemoteUrl")); }
@Test public void testDoWork() throws InterruptedException, ExecutionException, TimeoutException { List<WorkItem> workItems = new ArrayList<WorkItem>(); WorkItem item = new WorkItem(); item.setId(1); item.setRev(1); workItems.add(item); setupLocalTests(workItems); WorkItemLookupOperation operation = new WorkItemLookupOperation( RepositoryContext.createGitContext("/root/one", "repo1", "branch1", "gitRemoteUrl")); final SettableFuture<Boolean> startedCalled = SettableFuture.create(); final SettableFuture<Boolean> completedCalled = SettableFuture.create(); final SettableFuture<WorkItemLookupOperation.WitResults> witResults = SettableFuture.create(); operation.addListener( new Operation.Listener() { @Override public void notifyLookupStarted() { startedCalled.set(true); } @Override public void notifyLookupCompleted() { completedCalled.set(true); } @Override public void notifyLookupResults(Operation.Results results) { if (!results.hasError() && ((WorkItemLookupOperation.WitResults) results).getWorkItems().size() == 0) { // Skip the initial results call if there aren't items, we don't care about this one return; } witResults.set((WorkItemLookupOperation.WitResults) results); } }); operation.doWork(new WorkItemLookupOperation.WitInputs("query")); Assert.assertTrue(startedCalled.get(1, TimeUnit.SECONDS)); Assert.assertTrue(completedCalled.get(1, TimeUnit.SECONDS)); WorkItemLookupOperation.WitResults results = witResults.get(1, TimeUnit.SECONDS); Assert.assertNull(results.getError()); Assert.assertEquals(1, results.getWorkItems().size()); }