Search in sources :

Example 1 with ArtifactStore

use of com.thoughtworks.go.config.ArtifactStore in project gocd by gocd.

the class ArtifactExtensionTest method shouldSubmitFetchArtifactRequest.

@Test
public void shouldSubmitFetchArtifactRequest() throws JSONException {
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(""));
    final FetchPluggableArtifactTask pluggableArtifactTask = new FetchPluggableArtifactTask(null, null, "artifactId", create("Filename", false, "build/libs/foo.jar"));
    artifactExtension.fetchArtifact(PLUGIN_ID, new ArtifactStore("s3", "cd.go.s3"), pluggableArtifactTask.getConfiguration(), Collections.singletonMap("Version", "10.12.0"), "/temp");
    final GoPluginApiRequest request = requestArgumentCaptor.getValue();
    final String requestBody = "{\n" + "  \"artifact_metadata\": {\n" + "    \"Version\": \"10.12.0\"\n" + "  },\n" + "  \"store_configuration\": {},\n" + "  \"fetch_artifact_configuration\": {\n" + "      \"Filename\": \"build/libs/foo.jar\"\n" + "  },\n" + "  \"agent_working_directory\": \"/temp\"\n" + "}";
    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_FETCH_ARTIFACT));
    JSONAssert.assertEquals(requestBody, request.requestBody(), true);
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) FetchPluggableArtifactTask(com.thoughtworks.go.config.FetchPluggableArtifactTask) Test(org.junit.Test)

Example 2 with ArtifactStore

use of com.thoughtworks.go.config.ArtifactStore in project gocd by gocd.

the class ArtifactExtensionTest method shouldSubmitPublishArtifactRequest.

@Test
public void shouldSubmitPublishArtifactRequest() throws JSONException {
    final String responseBody = "{\n" + "  \"metadata\": {\n" + "    \"artifact-version\": \"10.12.0\"\n" + "  }\n" + "}";
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
    final PublishArtifactResponse response = artifactExtension.publishArtifact(PLUGIN_ID, new ArtifactPlan("{\"id\":\"installer\",\"storeId\":\"docker\"}"), new ArtifactStore("docker", "cd.go.docker"), "/temp");
    final GoPluginApiRequest request = requestArgumentCaptor.getValue();
    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT));
    final String expectedJSON = "{\n" + "  \"artifact_plan\": {\n" + "    \"id\": \"installer\",\n" + "    \"storeId\": \"docker\"\n" + "  },\n" + "  \"artifact_store\": {\n" + "    \"configuration\": {},\n" + "    \"id\": \"docker\"\n" + "  },\n" + "  \"agent_working_directory\": \"/temp\"\n" + "}";
    JSONAssert.assertEquals(expectedJSON, request.requestBody(), true);
    assertThat(response.getMetadata().size(), is(1));
    assertThat(response.getMetadata(), hasEntry("artifact-version", "10.12.0"));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) ArtifactPlan(com.thoughtworks.go.domain.ArtifactPlan) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) Test(org.junit.Test)

Example 3 with ArtifactStore

use of com.thoughtworks.go.config.ArtifactStore in project gocd by gocd.

the class ArtifactsPublisherTest method shouldDeletePluggableArtifactMetadataDirectory.

@Test
public void shouldDeletePluggableArtifactMetadataDirectory() throws Exception {
    TestFileUtil.createTestFile(workingFolder, "installer.zip");
    TestFileUtil.createTestFile(workingFolder, "testreports.xml");
    final ArtifactStore artifactStore = new ArtifactStore("s3", "cd.go.s3", create("Foo", false, "Bar"));
    final ArtifactStores artifactStores = new ArtifactStores(artifactStore);
    final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
    List<ArtifactPlan> artifactPlans = Arrays.asList(new ArtifactPlan(ArtifactType.file, "installer.zip", "dist"), new ArtifactPlan(ArtifactType.unit, "testreports.xml", "testreports"), artifactPlan);
    when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString())).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
    final GoPublisher publisher = mock(GoPublisher.class);
    assertThat(Arrays.asList(workingFolder.list()), containsInAnyOrder("testreports.xml", "installer.zip", "cruise-output"));
    new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(artifactPlans);
    assertThat(Arrays.asList(workingFolder.list()), containsInAnyOrder("testreports.xml", "installer.zip", "cruise-output"));
}
Also used : PluggableArtifactConfig(com.thoughtworks.go.config.PluggableArtifactConfig) ArtifactStores(com.thoughtworks.go.config.ArtifactStores) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) GoPublisher(com.thoughtworks.go.work.GoPublisher) Test(org.junit.Test)

Example 4 with ArtifactStore

use of com.thoughtworks.go.config.ArtifactStore in project gocd by gocd.

the class ArtifactsPublisherTest method shouldAddPluggableArtifactMetadataFileArtifactPlanAtTop.

@Test
public void shouldAddPluggableArtifactMetadataFileArtifactPlanAtTop() throws Exception {
    TestFileUtil.createTestFile(workingFolder, "installer.zip");
    TestFileUtil.createTestFile(workingFolder, "testreports.xml");
    final ArtifactStore artifactStore = new ArtifactStore("s3", "cd.go.s3", create("Foo", false, "Bar"));
    final ArtifactStores artifactStores = new ArtifactStores(artifactStore);
    final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
    List<ArtifactPlan> artifactPlans = Arrays.asList(new ArtifactPlan(ArtifactType.file, "installer.zip", "dist"), new ArtifactPlan(ArtifactType.unit, "testreports.xml", "testreports"), artifactPlan);
    when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString())).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
    final GoPublisher publisher = mock(GoPublisher.class);
    new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(artifactPlans);
    InOrder inOrder = inOrder(publisher);
    inOrder.verify(publisher).upload(any(), eq("pluggable-artifact-metadata"));
    inOrder.verify(publisher).upload(any(), eq("dist"));
    inOrder.verify(publisher).upload(any(), eq("testreports"));
}
Also used : PluggableArtifactConfig(com.thoughtworks.go.config.PluggableArtifactConfig) ArtifactStores(com.thoughtworks.go.config.ArtifactStores) InOrder(org.mockito.InOrder) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) GoPublisher(com.thoughtworks.go.work.GoPublisher) Test(org.junit.Test)

Example 5 with ArtifactStore

use of com.thoughtworks.go.config.ArtifactStore in project gocd by gocd.

the class ArtifactsPublisherTest method shouldContinueWithOtherPluginWhenPublishArtifactCallFailsForOnePlugin.

@Test
public void shouldContinueWithOtherPluginWhenPublishArtifactCallFailsForOnePlugin() throws IOException {
    final ArtifactStore s3ArtifactStore = new ArtifactStore("s3", "cd.go.s3", create("access_key", false, "some-key"));
    final ArtifactStore dockerArtifactStore = new ArtifactStore("docker", "cd.go.docker", create("registry-url", false, "docker.io"));
    final ArtifactStores artifactStores = new ArtifactStores(s3ArtifactStore, dockerArtifactStore);
    final ArtifactPlan s3ArtifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
    final ArtifactPlan dockerArtifactPlan = new ArtifactPlan(new PluggableArtifactConfig("test-reports", "docker", create("junit", false, "junit.xml")));
    when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(s3ArtifactPlan), eq(s3ArtifactStore), anyString())).thenThrow(new RuntimeException("Interaction with plugin `cd.go.s3` failed."));
    when(artifactExtension.publishArtifact(eq("cd.go.docker"), eq(dockerArtifactPlan), eq(dockerArtifactStore), anyString())).thenReturn(new PublishArtifactResponse(Collections.singletonMap("tag", "10.12.0")));
    try {
        new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(Arrays.asList(s3ArtifactPlan, dockerArtifactPlan));
        fail("Should throw error for pluggable artifact [installers].");
    } catch (Exception e) {
        assertThat(uploadedPluggableMetadataFiles(publisher.publishedFiles()), containsInAnyOrder("cd.go.docker.json"));
        assertThat(publisher.getMessage(), containsString("[go] Interaction with plugin `cd.go.s3` failed"));
        assertThat(e.getMessage(), containsString("[go] Uploading finished. Failed to upload [installers]."));
    }
}
Also used : PluggableArtifactConfig(com.thoughtworks.go.config.PluggableArtifactConfig) ArtifactStores(com.thoughtworks.go.config.ArtifactStores) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ArtifactStore (com.thoughtworks.go.config.ArtifactStore)13 Test (org.junit.Test)11 PluggableArtifactConfig (com.thoughtworks.go.config.PluggableArtifactConfig)8 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)7 PublishArtifactResponse (com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse)7 FetchPluggableArtifactTask (com.thoughtworks.go.config.FetchPluggableArtifactTask)3 ArtifactPlan (com.thoughtworks.go.domain.ArtifactPlan)3 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)2 GoPublisher (com.thoughtworks.go.work.GoPublisher)2 IOException (java.io.IOException)2 ExpectedException (org.junit.rules.ExpectedException)2 InOrder (org.mockito.InOrder)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 ChecksumFileHandler (com.thoughtworks.go.domain.ChecksumFileHandler)1 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 ArtifactExtension (com.thoughtworks.go.plugin.access.artifact.ArtifactExtension)1 PluginRequestProcessorRegistry (com.thoughtworks.go.plugin.infra.PluginRequestProcessorRegistry)1 DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)1 File (java.io.File)1 HashMap (java.util.HashMap)1