@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); }
private BapPublisher createAndAddMockPublisher(final String hostConfigurationName) { final BapPublisher mockPublisher = mockControl.createMock(BapPublisher.class); if (hostConfigurationName != null) { mockPublisher.setEffectiveEnvironmentInBuildInfo( (AbstractBuild) EasyMock.anyObject(), (BPBuildInfo) EasyMock.anyObject()); EasyMock.expect(mockPublisher.getConfigName()).andReturn(hostConfigurationName); } publishers.add(mockPublisher); return mockPublisher; }
@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); }
@Test public void testPerformReturnsUnstableAndDoesNotInvokeOtherPublishers() 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, false, false); instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess); assertResult(Result.UNSTABLE, 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)); }
@Test public void testPerformReturnsUnstableWhenNoHostConfigFound() throws Exception { final BapPublisher mockPublisher = createAndAddMockPublisher(null); mockPublisher.setEffectiveEnvironmentInBuildInfo( (AbstractBuild) EasyMock.anyObject(), (BPBuildInfo) EasyMock.anyObject()); EasyMock.expect(mockPublisher.getConfigName()).andReturn(hostConfiguration.getName()); Mockito.reset(mockHostConfigurationAccess); Mockito.when(mockHostConfigurationAccess.getConfiguration(hostConfiguration.getName())) .thenReturn(null); final BPInstanceConfig instanceConfig = createInstanceConfig(publishers, false, false, false); instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess); assertResult(Result.UNSTABLE, instanceConfig); Mockito.verify(mockHostConfigurationAccess).getConfiguration(hostConfiguration.getName()); }