use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse 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"));
}
use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.
the class ArtifactsPublisher method publishPluggableArtifact.
private void publishPluggableArtifact(PluggableArtifactMetadata pluggableArtifactMetadata, ArtifactPlan artifactPlan, ArtifactStore artifactStore) {
try {
final String pluginId = artifactStore.getPluginId();
final String message = format("[%s] Start to upload pluggable artifact using plugin `%s`.", PRODUCT_NAME, pluginId);
goPublisher.taggedConsumeLine(GoPublisher.PUBLISH, message);
LOGGER.info(message);
final PublishArtifactResponse publishArtifactResponse = artifactExtension.publishArtifact(pluginId, artifactPlan, artifactStore, workingDirectory.getAbsolutePath());
if (!publishArtifactResponse.getMetadata().isEmpty()) {
final String artifactId = (String) artifactPlan.getPluggableArtifactConfiguration().get("id");
pluggableArtifactMetadata.addMetadata(pluginId, artifactId, publishArtifactResponse.getMetadata());
}
} catch (RuntimeException e) {
failedArtifact.add(artifactPlan);
goPublisher.taggedConsumeLine(GoPublisher.ERR, format("[%s] %s", PRODUCT_NAME, e.getMessage()));
LOGGER.error(e.getMessage(), e);
}
}
use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse 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"));
}
use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.
the class ArtifactMessageConverterV1Test method publishArtifactResponse_shouldDeserializeFromJson.
@Test
public void publishArtifactResponse_shouldDeserializeFromJson() {
final ArtifactMessageConverterV1 converter = new ArtifactMessageConverterV1();
final PublishArtifactResponse response = converter.publishArtifactResponse("{\n" + " \"metadata\": {\n" + " \"artifact-version\": \"10.12.0\"\n" + " }\n" + "}");
MatcherAssert.assertThat(response.getMetadata().size(), is(1));
MatcherAssert.assertThat(response.getMetadata(), hasEntry("artifact-version", "10.12.0"));
}
use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse 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(), eq(env))).thenThrow(new RuntimeException("Interaction with plugin `cd.go.s3` failed."));
when(artifactExtension.publishArtifact(eq("cd.go.docker"), eq(dockerArtifactPlan), eq(dockerArtifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("tag", "10.12.0")));
try {
new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(Arrays.asList(s3ArtifactPlan, dockerArtifactPlan), env);
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]."));
}
}
Aggregations