@Test
  public void testPerformReturnsUnstableAndInvokesOtherPublishersWhenContinueOnErrorSet()
      throws Exception {
    final BapPublisher mockPub1 = createAndAddMockPublisher(hostConfiguration.getName());
    mockPub1.perform(hostConfiguration, buildInfo);
    EasyMock.expectLastCall().andThrow(new RuntimeException("Bad stuff here!"));
    final BapPublisher mockPub2 = createAndAddMockPublisher(hostConfiguration.getName());
    mockPub2.perform(hostConfiguration, buildInfo);

    final BPInstanceConfig instanceConfig = createInstanceConfig(publishers, true, false, false);
    instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess);

    assertResult(Result.UNSTABLE, instanceConfig);
  }
  @Test
  public void testPerformReturnsSuccessIfNoExceptionsThrown() throws Exception {
    final BPInstanceConfig instanceConfig = createInstanceConfig(publishers, false, false, false);
    instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess);
    final BapPublisher mockPublisher = createAndAddMockPublisher(hostConfiguration.getName());
    mockPublisher.perform(hostConfiguration, buildInfo);

    assertResult(Result.SUCCESS, instanceConfig);
  }
  @Test
  public void testDoNotCreateNodeName() throws Exception {
    final BPInstanceConfig instanceConfig =
        createInstanceConfig(publishers, false, false, false, "master");
    instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess);
    final BapPublisher mockPublisher = createAndAddMockPublisher(hostConfiguration.getName());
    mockPublisher.perform(hostConfiguration, buildInfo);
    assertResult(Result.SUCCESS, instanceConfig);

    assertFalse(buildInfo.getCurrentBuildEnv().getEnvVars().containsKey(BPBuildInfo.ENV_NODE_NAME));
  }
  @Test
  public void testPerformReturnsFailureIfFailOnError() throws Exception {
    final BapPublisher mockPub1 = createAndAddMockPublisher(hostConfiguration.getName());
    mockPub1.perform(hostConfiguration, buildInfo);
    EasyMock.expectLastCall().andThrow(new RuntimeException("Bad stuff here!"));
    createAndAddMockPublisher(null);

    final BPInstanceConfig instanceConfig = createInstanceConfig(publishers, false, true, false);
    instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess);

    assertResult(Result.FAILURE, instanceConfig);
  }
 private BapPublisher createLabeledPublisher(final String label, final boolean expectPerform)
     throws Exception {
   final BapPublisher mockPublisher = mockControl.createMock(BapPublisher.class);
   mockPublisher.setEffectiveEnvironmentInBuildInfo(
       (AbstractBuild) EasyMock.anyObject(), (BPBuildInfo) EasyMock.anyObject());
   expect(mockPublisher.getLabel()).andReturn(new PublisherLabel(label)).anyTimes();
   EasyMock.expect(mockPublisher.getConfigName())
       .andReturn(hostConfiguration.getName())
       .anyTimes();
   if (expectPerform) {
     mockPublisher.perform(hostConfiguration, buildInfo);
   }
   publishers.add(mockPublisher);
   return mockPublisher;
 }
  private void assertFixNodeName(
      final Map<String, String> envVars,
      final String nodeName,
      final String masterNodeName,
      final String expectedNodeName)
      throws Exception {
    envVars.put(BPBuildInfo.ENV_NODE_NAME, nodeName);
    final BPInstanceConfig instanceConfig =
        createInstanceConfig(publishers, false, false, false, masterNodeName);
    instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess);
    final BapPublisher mockPublisher = createAndAddMockPublisher(hostConfiguration.getName());
    mockPublisher.perform(hostConfiguration, buildInfo);
    assertResult(Result.SUCCESS, instanceConfig);

    assertEquals(expectedNodeName, envVars.get(BPBuildInfo.ENV_NODE_NAME));
  }