Esempio n. 1
0
  @Test
  public void requestLastBuildStatus_callback_records_build_on_build_type() throws Exception {
    // Setup
    final BuildTypeData bt1 = new BuildTypeData("bt1", "btName", "pname", "pId");
    _buildTypeManager.registerBuildTypes(ImmutableList.of(bt1));
    _buildTypeManager.activateMonitoring(bt1);

    final BuildList buildList = new BuildList();
    final Build b12246 =
        new Build(
            12246,
            new BuildType("bt1", "btname", "btprojectName", "btProjectid"),
            BuildStatus.FAILURE,
            BuildState.finished,
            false);
    buildList.addBuild(b12246);

    when(_mockRequestController.sendRequest(
            getApiVersion(),
            "builds/?locator=buildType:bt1,running:any,branch:(default:any),count:"
                + ApiController.MAX_BUILDS_TO_CONSIDER,
            BuildList.class))
        .thenReturn(Futures.immediateFuture(buildList));
    when(_mockRequestController.sendRequest(getApiVersion(), "builds/id:12246", Build.class))
        .thenReturn(Futures.immediateFuture(b12246));
    // Exercise
    _apiController.requestLastBuildStatus(bt1);
    // Verify
    assertThat(bt1.getBuildById(12246), is(notNullValue()));
  }
Esempio n. 2
0
  @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));
  }
Esempio n. 3
0
  @Test
  public void
      loadBuildTypeList_callback_registers_project_to_BuildTypeManager_and_dispatch_it_on_event_bus()
          throws Exception {
    // Setup
    final BuildTypeList buildTypelist = new BuildTypeList();
    buildTypelist.addBuildType(new BuildType("bt1", "btName", "btProjectName", "btProjectId"));
    buildTypelist.addBuildType(new BuildType("bt2", "btName", "btProjectName", "btProjectId"));

    when(_mockRequestController.sendRequest(getApiVersion(), "buildTypes", BuildTypeList.class))
        .thenReturn(Futures.immediateFuture(buildTypelist));
    // Exercise
    final ListenableFuture<Void> ackFuture = _apiController.loadBuildTypeList();
    // Verify
    assertThat(_buildTypeManager.getBuildTypes().size(), is(2));
    assertThat(_buildTypeManager.getBuildTypes().get(0).getId(), is("bt1"));
    assertThat(_buildTypeManager.getBuildTypes().get(1).getId(), is("bt2"));
    assertThat(_dispatchedObjects, hasItem(_buildTypeManager));
    assertThat(ackFuture.isDone(), is(true));
  }
Esempio n. 4
0
  @Test
  public void requestLastBuildStatus_callback_starts_requests_to_retreive_last_build_status()
      throws Exception {
    // Setup
    final BuildTypeData bt1 = new BuildTypeData("bt1", "btName", "pname", "pId");
    _buildTypeManager.registerBuildTypes(ImmutableList.of(bt1));
    _buildTypeManager.activateMonitoring(bt1);

    final BuildList buildList = new BuildList();
    final Build b12246 =
        new Build(
            12246,
            new BuildType("bt1", "btname", "btprojectName", "btProjectid"),
            BuildStatus.FAILURE,
            BuildState.finished,
            false);
    final Build b12247 =
        new Build(
            12247,
            new BuildType("bt1", "btname", "btprojectName", "btProjectid"),
            BuildStatus.FAILURE,
            BuildState.finished,
            false);
    final Build b12248 =
        new Build(
            12248,
            new BuildType("bt1", "btname", "btprojectName", "btProjectid"),
            BuildStatus.FAILURE,
            BuildState.finished,
            false);
    final Build b12249 =
        new Build(
            12249,
            new BuildType("bt1", "btname", "btprojectName", "btProjectid"),
            BuildStatus.FAILURE,
            BuildState.finished,
            false);
    buildList.addBuild(b12249);
    buildList.addBuild(b12248);
    buildList.addBuild(b12247);
    buildList.addBuild(b12246);

    when(_mockRequestController.sendRequest(
            getApiVersion(),
            "builds/?locator=buildType:bt1,running:any,branch:(default:any),count:"
                + ApiController.MAX_BUILDS_TO_CONSIDER,
            BuildList.class))
        .thenReturn(Futures.immediateFuture(buildList));

    when(_mockRequestController.sendRequest(getApiVersion(), "builds/id:12246", Build.class))
        .thenReturn(Futures.immediateFuture(b12246));
    when(_mockRequestController.sendRequest(getApiVersion(), "builds/id:12247", Build.class))
        .thenReturn(Futures.immediateFuture(b12247));
    when(_mockRequestController.sendRequest(getApiVersion(), "builds/id:12248", Build.class))
        .thenReturn(Futures.immediateFuture(b12248));
    when(_mockRequestController.sendRequest(getApiVersion(), "builds/id:12249", Build.class))
        .thenReturn(Futures.immediateFuture(b12249));
    // Exercise
    _apiController.requestLastBuildStatus(bt1);
    // Verify
    verify(_mockRequestController)
        .sendRequest(
            getApiVersion(),
            "builds/?locator=buildType:bt1,running:any,branch:(default:any),count:"
                + ApiController.MAX_BUILDS_TO_CONSIDER,
            BuildList.class);
    verify(_mockRequestController, atLeastOnce())
        .sendRequest(getApiVersion(), "builds/id:12249", Build.class);
    verify(_mockRequestController, atLeastOnce())
        .sendRequest(getApiVersion(), "builds/id:12248", Build.class);
    verify(_mockRequestController, atLeastOnce())
        .sendRequest(getApiVersion(), "builds/id:12247", Build.class);
    verify(_mockRequestController, never())
        .sendRequest(getApiVersion(), "builds/id:12246", Build.class);
  }