@Test public void requestQueuedBuilds_callback_reccords_queued_status_and_dispatches_modified_build_type_on_event_bus() throws Exception { // Setup final BuildTypeData bt1 = new BuildTypeData("bt1", "btName", "pname", "pId"); final BuildTypeData bt2 = new BuildTypeData("bt2", "btName", "pname", "pId"); final BuildTypeData bt3 = new BuildTypeData("bt3", "btName", "pname", "pId"); bt3.setQueued(true); final BuildTypeData bt4 = new BuildTypeData("bt4", "btName", "pname", "pId"); bt4.setQueued(true); _buildTypeManager.registerBuildTypes(ImmutableList.of(bt1, bt2, bt3, bt4)); _buildTypeManager.activateMonitoring(bt1); _buildTypeManager.activateMonitoring(bt2); _buildTypeManager.activateMonitoring(bt3); _buildTypeManager.activateMonitoring(bt4); final QueuedBuildList queuedBuildList = new QueuedBuildList(); queuedBuildList.addBuildType(new QueueBuild("bt2")); queuedBuildList.addBuildType(new QueueBuild("bt3")); when(_mockRequestController.sendRequest(getApiVersion(), "buildQueue", QueuedBuildList.class)) .thenReturn(Futures.immediateFuture(queuedBuildList)); // Exercise _apiController.requestQueuedBuilds(); // Verify assertThat(bt1.isQueued(), is(false)); assertThat(bt2.isQueued(), is(true)); assertThat(bt3.isQueued(), is(true)); assertThat(bt4.isQueued(), is(false)); assertThat(_dispatchedObjects, not(hasItem(bt1))); assertThat(_dispatchedObjects, hasItem(bt2)); assertThat(_dispatchedObjects, not(hasItem(bt3))); assertThat(_dispatchedObjects, hasItem(bt4)); }
@Test public void requestQueuedBuilds_starts_a_request_to_controller_with_correct_path() throws Exception { // Setup // Exercise _apiController.requestQueuedBuilds(); // Verify verify(_mockRequestController) .sendRequest(getApiVersion(), "buildQueue", QueuedBuildList.class); }
@Test public void requestQueuedBuilds_callback_registers_exception_on_ack_future() throws Exception { // Setup when(_mockRequestController.sendRequest(getApiVersion(), "buildQueue", QueuedBuildList.class)) .thenReturn( Futures.immediateFailedFuture(new RuntimeException("Unexpected test exception"))); // Exercise final ListenableFuture<Void> ackFuture = _apiController.requestQueuedBuilds(); // Verify try { ackFuture.get(); } catch (ExecutionException e) { if (e.getCause().getClass() == RuntimeException.class && e.getCause().getMessage().equals("Unexpected test exception")) return; } TestCase.fail(); }