use of com.thoughtworks.go.work.DefaultGoPublisher in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldPublishErrorMessageIfPluginThrowsAnException.
@Test
public void shouldPublishErrorMessageIfPluginThrowsAnException() throws CruiseControlException {
PluggableTask task = mock(PluggableTask.class);
when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, pluggableTask, TEST_PLUGIN_ID, "test-directory") {
@Override
protected ExecutionResult executeTask(Task task, BuildLogElement buildLogElement, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext) {
throw new RuntimeException("err");
}
};
when(pluginManager.doOn(eq(Task.class), eq(TEST_PLUGIN_ID), any(ActionWithReturn.class))).thenAnswer(new Answer<ExecutionResult>() {
@Override
public ExecutionResult answer(InvocationOnMock invocationOnMock) throws Throwable {
ActionWithReturn<Task, ExecutionResult> actionWithReturn = (ActionWithReturn<Task, ExecutionResult>) invocationOnMock.getArguments()[2];
return actionWithReturn.execute(mock(Task.class), pluginDescriptor);
}
});
try {
taskBuilder.build(buildLogElement, goPublisher, variableContext, taskExtension);
fail("expected exception to be thrown");
} catch (Exception e) {
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(goPublisher).consumeLine(captor.capture());
String error = "Error: err";
assertThat(captor.getValue(), is(error));
assertThat(e.getMessage(), is(new RuntimeException("err").toString()));
}
}
use of com.thoughtworks.go.work.DefaultGoPublisher in project gocd by gocd.
the class ArtifactPlanTest method shouldPublishArtifacts.
@Test
public void shouldPublishArtifacts() throws Exception {
final DefaultGoPublisher publisher = context.mock(DefaultGoPublisher.class);
final ArtifactPlan artifactPlan = new ArtifactPlan("src", "dest");
context.checking(new Expectations() {
{
one(publisher).upload(new File(testFolder, "src"), "dest");
}
});
artifactPlan.publish(publisher, testFolder);
context.assertIsSatisfied();
}
use of com.thoughtworks.go.work.DefaultGoPublisher in project gocd by gocd.
the class GoArtifactsManipulatorTest method setUp.
@Before
public void setUp() throws Exception {
httpService = mock(HttpService.class);
artifactFolder = TestFileUtil.createTempFolder("artifact_folder");
tempFile = TestFileUtil.createTestFile(artifactFolder, "file.txt");
goArtifactsManipulatorStub = new GoArtifactsManipulatorStub(httpService);
jobIdentifier = new JobIdentifier("pipeline1", 1, "label-1", "stage1", "1", "job1");
AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(new AgentIdentifier("h", "1", "u"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), null, false);
goPublisher = new DefaultGoPublisher(goArtifactsManipulatorStub, jobIdentifier, new BuildRepositoryRemoteStub(), agentRuntimeInfo);
}
use of com.thoughtworks.go.work.DefaultGoPublisher in project gocd by gocd.
the class BuildWork method initialize.
private void initialize(BuildRepositoryRemote remoteBuildRepository, GoArtifactsManipulator goArtifactsManipulator, AgentRuntimeInfo agentRuntimeInfo, TaskExtension taskExtension) {
timeProvider = new TimeProvider();
plan = assignment.getPlan();
agentRuntimeInfo.busy(new AgentBuildingInfo(plan.getIdentifier().buildLocatorForDisplay(), plan.getIdentifier().buildLocator()));
workingDirectory = assignment.getWorkingDirectory();
materialRevisions = assignment.materialRevisions();
buildLog = new GoControlLog(this.workingDirectory + "/cruise-output");
goPublisher = new DefaultGoPublisher(goArtifactsManipulator, plan.getIdentifier(), remoteBuildRepository, agentRuntimeInfo);
builders = new Builders(assignment.getBuilders(), goPublisher, buildLog, taskExtension);
}
use of com.thoughtworks.go.work.DefaultGoPublisher in project gocd by gocd.
the class PluggableTaskBuilderTest method shouldPublishErrorMessageIfPluginReturnsAFailureResponse.
@Test
public void shouldPublishErrorMessageIfPluginReturnsAFailureResponse() throws CruiseControlException {
PluggableTask task = mock(PluggableTask.class);
when(task.getPluginConfiguration()).thenReturn(new PluginConfiguration());
PluggableTaskBuilder taskBuilder = new PluggableTaskBuilder(runIfConfigs, cancelBuilder, pluggableTask, TEST_PLUGIN_ID, "test-directory") {
@Override
protected ExecutionResult executeTask(Task task, BuildLogElement buildLogElement, DefaultGoPublisher publisher, EnvironmentVariableContext environmentVariableContext) {
return ExecutionResult.failure("err");
}
};
when(pluginManager.doOn(eq(Task.class), eq(TEST_PLUGIN_ID), any(ActionWithReturn.class))).thenAnswer(new Answer<ExecutionResult>() {
@Override
public ExecutionResult answer(InvocationOnMock invocationOnMock) throws Throwable {
ActionWithReturn<Task, ExecutionResult> actionWithReturn = (ActionWithReturn<Task, ExecutionResult>) invocationOnMock.getArguments()[2];
return actionWithReturn.execute(mock(Task.class), pluginDescriptor);
}
});
try {
taskBuilder.build(buildLogElement, goPublisher, variableContext, taskExtension);
fail("expected exception to be thrown");
} catch (Exception e) {
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(goPublisher).consumeLine(captor.capture());
assertThat(captor.getValue(), is("err"));
assertThat(e.getMessage(), is("err"));
}
}
Aggregations