Search in sources :

Example 1 with DefaultGoPublisher

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()));
    }
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) ArgumentCaptor(org.mockito.ArgumentCaptor) BuildLogElement(com.thoughtworks.go.domain.BuildLogElement) ExecutionResult(com.thoughtworks.go.plugin.api.response.execution.ExecutionResult) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) ActionWithReturn(com.thoughtworks.go.plugin.infra.ActionWithReturn) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 2 with DefaultGoPublisher

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();
}
Also used : Expectations(org.jmock.Expectations) ArtifactPlan(com.thoughtworks.go.config.ArtifactPlan) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) File(java.io.File) Test(org.junit.Test)

Example 3 with DefaultGoPublisher

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);
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) GoArtifactsManipulatorStub(com.thoughtworks.go.remote.work.GoArtifactsManipulatorStub) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) BuildRepositoryRemoteStub(com.thoughtworks.go.remote.work.BuildRepositoryRemoteStub) Before(org.junit.Before)

Example 4 with DefaultGoPublisher

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);
}
Also used : AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) TimeProvider(com.thoughtworks.go.util.TimeProvider) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher)

Example 5 with DefaultGoPublisher

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"));
    }
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) ArgumentCaptor(org.mockito.ArgumentCaptor) BuildLogElement(com.thoughtworks.go.domain.BuildLogElement) ExecutionResult(com.thoughtworks.go.plugin.api.response.execution.ExecutionResult) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) CruiseControlException(com.thoughtworks.go.util.command.CruiseControlException) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) ActionWithReturn(com.thoughtworks.go.plugin.infra.ActionWithReturn) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Aggregations

DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)7 Test (org.junit.Test)5 BuildLogElement (com.thoughtworks.go.domain.BuildLogElement)4 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)4 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)3 ExecutionResult (com.thoughtworks.go.plugin.api.response.execution.ExecutionResult)3 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)2 ActionWithReturn (com.thoughtworks.go.plugin.infra.ActionWithReturn)2 CruiseControlException (com.thoughtworks.go.util.command.CruiseControlException)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ArtifactPlan (com.thoughtworks.go.config.ArtifactPlan)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 KillAllChildProcessTask (com.thoughtworks.go.domain.KillAllChildProcessTask)1 Builder (com.thoughtworks.go.domain.builder.Builder)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 BuildRepositoryRemoteStub (com.thoughtworks.go.remote.work.BuildRepositoryRemoteStub)1 GoArtifactsManipulatorStub (com.thoughtworks.go.remote.work.GoArtifactsManipulatorStub)1 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)1 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)1