use of org.mockito.ArgumentCaptor in project che by eclipse.
the class MachineProviderImplTest method shouldAddBindMountAndRegularVolumesOnInstanceCreationFromRecipe.
@Test
public void shouldAddBindMountAndRegularVolumesOnInstanceCreationFromRecipe() throws Exception {
String[] bindMountVolumesFromMachine = new String[] { "/my/bind/mount1:/from/host1", "/my/bind/mount2:/from/host2:ro", "/my/bind/mount3:/from/host3:ro,Z" };
String[] volumesFromMachine = new String[] { "/projects", "/something", "/something/else" };
String[] expectedBindMountVolumes = new String[] { "/my/bind/mount1:/from/host1", "/my/bind/mount2:/from/host2:ro", "/my/bind/mount3:/from/host3:ro,Z" };
Map<String, Volume> expectedVolumes = Stream.of("/projects", "/something", "/something/else").collect(toMap(Function.identity(), v -> new Volume()));
provider = new MachineProviderBuilder().setDevMachineVolumes(emptySet()).setAllMachineVolumes(emptySet()).build();
CheServiceImpl service = createService();
service.setVolumes(Stream.concat(Stream.of(bindMountVolumesFromMachine), Stream.of(volumesFromMachine)).collect(Collectors.toList()));
createInstanceFromRecipe(service, true);
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
String[] actualBindMountVolumes = argumentCaptor.getValue().getContainerConfig().getHostConfig().getBinds();
Map<String, Volume> actualVolumes = argumentCaptor.getValue().getContainerConfig().getVolumes();
assertEquals(actualVolumes, expectedVolumes);
assertEqualsNoOrder(actualBindMountVolumes, expectedBindMountVolumes);
}
use of org.mockito.ArgumentCaptor in project che by eclipse.
the class MachineProviderImplTest method shouldAddEnvVarsFromMachineConfigToContainerOnDevInstanceCreationFromRecipe.
@Test
public void shouldAddEnvVarsFromMachineConfigToContainerOnDevInstanceCreationFromRecipe() throws Exception {
// given
Map<String, String> envVarsFromConfig = new HashMap<>();
envVarsFromConfig.put("ENV_VAR1", "123");
envVarsFromConfig.put("ENV_VAR2", "234");
final boolean isDev = true;
CheServiceImpl machine = createService();
machine.setEnvironment(envVarsFromConfig);
// when
createInstanceFromRecipe(machine, isDev);
// then
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertTrue(asList(argumentCaptor.getValue().getContainerConfig().getEnv()).containsAll(envVarsFromConfig.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList())));
}
use of org.mockito.ArgumentCaptor in project che by eclipse.
the class MachineProviderImplTest method shouldAddEnvVarsFromMachineConfigToContainerOnNonDevInstanceCreationFromSnapshot.
@Test
public void shouldAddEnvVarsFromMachineConfigToContainerOnNonDevInstanceCreationFromSnapshot() throws Exception {
// given
Map<String, String> envVarsFromConfig = new HashMap<>();
envVarsFromConfig.put("ENV_VAR1", "123");
envVarsFromConfig.put("ENV_VAR2", "234");
final boolean isDev = false;
CheServiceImpl machine = createService();
machine.setEnvironment(envVarsFromConfig);
// when
createInstanceFromSnapshot(machine, isDev);
// then
ArgumentCaptor<CreateContainerParams> argumentCaptor = ArgumentCaptor.forClass(CreateContainerParams.class);
verify(dockerConnector).createContainer(argumentCaptor.capture());
assertTrue(asList(argumentCaptor.getValue().getContainerConfig().getEnv()).containsAll(envVarsFromConfig.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList())));
}
use of org.mockito.ArgumentCaptor in project gocd by gocd.
the class CcTrayConfigChangeHandlerTest method shouldUpdateCacheWithPipelineDetailsWhenPipelineConfigChanges.
@Test
public void shouldUpdateCacheWithPipelineDetailsWhenPipelineConfigChanges() {
String pipeline1Stage = "pipeline1 :: stage1";
String pipeline1job = "pipeline1 :: stage1 :: job1";
String pipeline2stage = "pipeline2 :: stage1";
String pipeline2job = "pipeline2 :: stage1 :: job1";
ProjectStatus statusOfPipeline1StageInCache = new ProjectStatus(pipeline1Stage, "OldActivity", "OldStatus", "OldLabel", new Date(), "p1-stage-url");
ProjectStatus statusOfPipeline1JobInCache = new ProjectStatus(pipeline1job, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "p1-job-url");
ProjectStatus statusOfPipeline2StageInCache = new ProjectStatus(pipeline1Stage, "OldActivity", "OldStatus", "OldLabel", new Date(), "p2-stage-url");
ProjectStatus statusOfPipeline2JobInCache = new ProjectStatus(pipeline1job, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "p2-job2-url");
when(cache.get(pipeline1Stage)).thenReturn(statusOfPipeline1StageInCache);
when(cache.get(pipeline1job)).thenReturn(statusOfPipeline1JobInCache);
when(cache.get(pipeline2stage)).thenReturn(statusOfPipeline2StageInCache);
when(cache.get(pipeline2job)).thenReturn(statusOfPipeline2JobInCache);
PipelineConfig pipeline1Config = GoConfigMother.pipelineHavingJob("pipeline1", "stage1", "job1", "arts", "dir").pipelineConfigByName(new CaseInsensitiveString("pipeline1"));
handler.call(pipeline1Config, "group1");
ArgumentCaptor<ArrayList<ProjectStatus>> argumentCaptor = new ArgumentCaptor<>();
verify(cache).putAll(argumentCaptor.capture());
List<ProjectStatus> allValues = argumentCaptor.getValue();
assertThat(allValues.get(0).name(), is(pipeline1Stage));
assertThat(allValues.get(1).name(), is(pipeline1job));
verify(cache, atLeastOnce()).get(pipeline1Stage);
verify(cache, atLeastOnce()).get(pipeline1job);
verifyNoMoreInteractions(cache);
}
use of org.mockito.ArgumentCaptor 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"));
}
}
Aggregations