Search in sources :

Example 1 with ArtifactPlan

use of com.thoughtworks.go.domain.ArtifactPlan 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 2 with ArtifactPlan

use of com.thoughtworks.go.domain.ArtifactPlan in project gocd by gocd.

the class ArtifactExtensionTestBase method shouldSubmitPublishArtifactRequest.

@Test
public void shouldSubmitPublishArtifactRequest() {
    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));
    ArtifactPlan artifactPlan = new ArtifactPlan("{\"id\":\"installer\",\"storeId\":\"docker\"}");
    ArtifactStore artifactStore = new ArtifactStore("docker", "cd.go.docker");
    EnvironmentVariableContext env = new EnvironmentVariableContext("foo", "bar");
    final PublishArtifactResponse response = artifactExtension.publishArtifact(PLUGIN_ID, artifactPlan, artifactStore, "/temp", env);
    final GoPluginApiRequest request = requestArgumentCaptor.getValue();
    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT));
    final String expectedJSON = "{" + "  \"artifact_plan\": {" + "    \"id\": \"installer\"," + "    \"storeId\": \"docker\"" + "  }," + "  \"artifact_store\": {" + "    \"configuration\": {}," + "    \"id\": \"docker\"" + "  }," + "  \"environment_variables\": {" + "    \"foo\": \"bar\"" + "  }," + "  \"agent_working_directory\": \"/temp\"" + "}";
    assertThatJson(expectedJSON).isEqualTo(request.requestBody());
    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) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.jupiter.api.Test)

Example 3 with ArtifactPlan

use of com.thoughtworks.go.domain.ArtifactPlan in project gocd by gocd.

the class ArtifactPlanFilter method getBuiltInMergedArtifactPlans.

public List<ArtifactPlan> getBuiltInMergedArtifactPlans(List<ArtifactPlan> artifactPlans) {
    MergedTestArtifactPlan testArtifactPlan = null;
    final List<ArtifactPlan> mergedPlans = new ArrayList<>();
    for (ArtifactPlan artifactPlan : artifactPlans) {
        if (artifactPlan.getArtifactPlanType().isTest()) {
            if (testArtifactPlan == null) {
                testArtifactPlan = new MergedTestArtifactPlan(artifactPlan);
                mergedPlans.add(testArtifactPlan);
            } else {
                testArtifactPlan.add(artifactPlan);
            }
        } else if (artifactPlan.getArtifactPlanType() == ArtifactPlanType.file) {
            mergedPlans.add(artifactPlan);
        }
    }
    return mergedPlans;
}
Also used : ArtifactPlan(com.thoughtworks.go.domain.ArtifactPlan) MergedTestArtifactPlan(com.thoughtworks.go.domain.MergedTestArtifactPlan) ArrayList(java.util.ArrayList) MergedTestArtifactPlan(com.thoughtworks.go.domain.MergedTestArtifactPlan)

Example 4 with ArtifactPlan

use of com.thoughtworks.go.domain.ArtifactPlan in project gocd by gocd.

the class ArtifactsPublisher method artifactStoresToPlugin.

private Map<ArtifactPlan, ArtifactStore> artifactStoresToPlugin(List<ArtifactPlan> artifactPlans) {
    final HashMap<ArtifactPlan, ArtifactStore> artifactPlanToArtifactStoreMap = new HashMap<>();
    for (ArtifactPlan artifactPlan : artifactPlans) {
        final String storeId = (String) artifactPlan.getPluggableArtifactConfiguration().get("storeId");
        artifactPlanToArtifactStoreMap.put(artifactPlan, artifactStores.find(storeId));
    }
    return artifactPlanToArtifactStoreMap;
}
Also used : ArtifactPlan(com.thoughtworks.go.domain.ArtifactPlan) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) HashMap(java.util.HashMap)

Example 5 with ArtifactPlan

use of com.thoughtworks.go.domain.ArtifactPlan in project gocd by gocd.

the class ArtifactMessageConverterV1Test method publishArtifactMessage_shouldSerializeToJson.

@Test
public void publishArtifactMessage_shouldSerializeToJson() {
    final ArtifactMessageConverterV1 converter = new ArtifactMessageConverterV1();
    final ArtifactStore artifactStore = new ArtifactStore("s3-store", "pluginId", create("Foo", false, "Bar"));
    final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3-store", create("Baz", true, "Car")));
    final Map<String, String> environmentVariables = new HashMap<>();
    environmentVariables.put("foo", "bar");
    final String publishArtifactMessage = converter.publishArtifactMessage(artifactPlan, artifactStore, "/temp", environmentVariables);
    final String expectedStr = "{" + "  \"artifact_plan\": {" + "    \"configuration\": {" + "      \"Baz\": \"Car\"" + "    }," + "    \"id\": \"installers\"," + "    \"storeId\": \"s3-store\"" + "  }," + "  \"artifact_store\": {" + "    \"configuration\": {" + "      \"Foo\": \"Bar\"" + "    }," + "    \"id\": \"s3-store\"" + "  }," + "  \"agent_working_directory\": \"/temp\"," + "  \"environment_variables\": {" + "       \"foo\": \"bar\"" + "   }" + "}";
    assertThatJson(expectedStr).isEqualTo(publishArtifactMessage);
}
Also used : PluggableArtifactConfig(com.thoughtworks.go.config.PluggableArtifactConfig) ArtifactPlan(com.thoughtworks.go.domain.ArtifactPlan) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Aggregations

ArtifactPlan (com.thoughtworks.go.domain.ArtifactPlan)6 ArtifactStore (com.thoughtworks.go.config.ArtifactStore)4 PublishArtifactResponse (com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse)2 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 PluggableArtifactConfig (com.thoughtworks.go.config.PluggableArtifactConfig)1 MergedTestArtifactPlan (com.thoughtworks.go.domain.MergedTestArtifactPlan)1 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1