use of com.thoughtworks.go.config.FetchPluggableArtifactTask in project gocd by gocd.
the class TaskViewServiceTest method shouldNotGetViewModelForPluggableFetchArtifactTaskWhenToggleIsOff.
@Test
public void shouldNotGetViewModelForPluggableFetchArtifactTaskWhenToggleIsOff() {
List<Class<? extends Task>> taskClasses = taskImplementations();
taskClasses.add(FetchPluggableArtifactTask.class);
when(featureToggleService.isToggleOn(Toggles.ARTIFACT_EXTENSION_KEY)).thenReturn(false);
when(registry.implementersOf(Task.class)).thenReturn(taskClasses);
when(registry.getViewModelFor(new FetchPluggableArtifactTask(), "new")).thenReturn(viewModel(new FetchPluggableArtifactTask()));
when(registry.getViewModelFor(new ExecTask(), "new")).thenReturn(new TaskViewModel(new ExecTask(), ""));
List<PluggableViewModel> taskViewModels = taskViewService.getTaskViewModels();
assertThat(taskViewModels.size(), is(3));
assertThat(taskViewModels, hasItem((PluggableViewModel) new TaskViewModel(new ExecTask(), "")));
assertThat(taskViewModels.indexOf(viewModel(new FetchPluggableArtifactTask())), is(-1));
}
use of com.thoughtworks.go.config.FetchPluggableArtifactTask 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);
}
use of com.thoughtworks.go.config.FetchPluggableArtifactTask in project gocd by gocd.
the class FetchPluggableArtifactBuilderTest method setUp.
@Before
public void setUp() throws Exception {
publisher = mock(DefaultGoPublisher.class);
artifactExtension = mock(ArtifactExtension.class);
checksumFileHandler = mock(ChecksumFileHandler.class);
registry = mock(PluginRequestProcessorRegistry.class);
metadataDest = new File(temporaryFolder.newFolder("dest"), "cd.go.s3.json");
FileUtils.writeStringToFile(metadataDest, "{\"artifactId\":{}}", StandardCharsets.UTF_8);
jobIdentifier = new JobIdentifier("cruise", -10, "1", "dev", "1", "windows", 1L);
artifactStore = new ArtifactStore("s3", "cd.go.s3", ConfigurationPropertyMother.create("ACCESS_KEY", true, "hksjdfhsksdfh"));
fetchPluggableArtifactTask = new FetchPluggableArtifactTask(new CaseInsensitiveString("dev"), new CaseInsensitiveString("windows"), "artifactId", ConfigurationPropertyMother.create("Destination", false, "build/"));
sourceOnServer = format("%s/%s", PLUGGABLE_ARTIFACT_METADATA_FOLDER, "cd.go.s3.json");
when(checksumFileHandler.handleResult(SC_OK, publisher)).thenReturn(true);
}
use of com.thoughtworks.go.config.FetchPluggableArtifactTask in project gocd by gocd.
the class ArtifactMessageConverterV1Test method fetchArtifactMessage_shouldSerializeToJson.
@Test
public void fetchArtifactMessage_shouldSerializeToJson() throws JSONException {
final ArtifactMessageConverterV1 converter = new ArtifactMessageConverterV1();
final ArtifactStore artifactStore = new ArtifactStore("s3-store", "pluginId", create("Foo", false, "Bar"));
final Map<String, Object> metadata = Collections.singletonMap("Version", "10.12.0");
final FetchPluggableArtifactTask pluggableArtifactTask = new FetchPluggableArtifactTask(null, null, "artifactId", create("Filename", false, "build/libs/foo.jar"));
final String fetchArtifactMessage = converter.fetchArtifactMessage(artifactStore, pluggableArtifactTask.getConfiguration(), metadata, "/temp");
final String expectedStr = "{\n" + " \"artifact_metadata\": {\n" + " \"Version\": \"10.12.0\"\n" + " },\n" + " \"store_configuration\": {\n" + " \"Foo\": \"Bar\"\n" + " },\n" + " \"fetch_artifact_configuration\": {\n" + " \"Filename\": \"build/libs/foo.jar\"\n" + " },\n" + " \"agent_working_directory\": \"/temp\"\n" + "}";
JSONAssert.assertEquals(expectedStr, fetchArtifactMessage, true);
}
use of com.thoughtworks.go.config.FetchPluggableArtifactTask in project gocd by gocd.
the class TaskViewServiceTest method shouldGetViewModelForPluggableFetchArtifactTaskWhenToggleIsOn.
@Test
public void shouldGetViewModelForPluggableFetchArtifactTaskWhenToggleIsOn() {
List<Class<? extends Task>> taskClasses = taskImplementations();
taskClasses.add(FetchPluggableArtifactTask.class);
when(featureToggleService.isToggleOn(Toggles.ARTIFACT_EXTENSION_KEY)).thenReturn(true);
when(registry.implementersOf(Task.class)).thenReturn(taskClasses);
when(registry.getViewModelFor(new FetchPluggableArtifactTask(), "new")).thenReturn(viewModel(new FetchPluggableArtifactTask()));
when(registry.getViewModelFor(new ExecTask(), "new")).thenReturn(new TaskViewModel(new ExecTask(), ""));
List<PluggableViewModel> taskViewModels = taskViewService.getTaskViewModels();
assertThat(taskViewModels.size(), is(4));
assertThat(taskViewModels, hasItem((PluggableViewModel) new TaskViewModel(new ExecTask(), "")));
assertThat(taskViewModels, hasItem((PluggableViewModel) new TaskViewModel(new FetchPluggableArtifactTask(), "")));
}
Aggregations