use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.
the class RunServiceTest method testWithMultipleStopExceptions.
@Test
public void testWithMultipleStopExceptions() throws Exception {
GavLabel testLabel = new GavLabel("Im:A:Test");
String firstName = "first-container:latest";
ImageConfiguration first = new ImageConfiguration();
first.setName(firstName);
String secondName = "second-container:latest";
ImageConfiguration second = new ImageConfiguration();
second.setName(secondName);
tracker.registerContainer(firstName, first, testLabel);
tracker.registerContainer(secondName, second, testLabel);
LogOutputSpecFactory logOutputSpecFactory = new LogOutputSpecFactory(true, true, null);
new Expectations() {
{
docker.stopContainer(firstName, 0);
result = new DockerAccessException("TEST one");
docker.stopContainer(secondName, 0);
result = new DockerAccessException("TEST two");
}
};
runService = new RunService(docker, queryService, tracker, logOutputSpecFactory, log);
Exception thrownException = assertThrows(DockerAccessException.class, () -> runService.stopStartedContainers(false, true, true, testLabel));
assertEquals("(TEST two,TEST one)", thrownException.getLocalizedMessage());
}
use of io.fabric8.maven.docker.service.RunService in project docker-maven-plugin by fabric8io.
the class StartContainerExecutorTest method testStartContainers.
@Test
public void testStartContainers(@Mocked ServiceHub hub, @Mocked DockerAccess dockerAccess, @Mocked ContainerTracker containerTracker, @Mocked Logger log) throws IOException, ExecException {
// Given
new Expectations() {
{
dockerAccess.createContainer((ContainerCreateConfig) any, anyString);
result = "container-name";
dockerAccess.getContainer(anyString);
result = new ContainerDetails(JsonFactory.newJsonObject("{\"NetworkSettings\":{\"IPAddress\":\"192.168.1.2\"}}"));
QueryService queryService = new QueryService(dockerAccess);
hub.getQueryService();
result = queryService;
hub.getRunService();
result = new RunService(dockerAccess, queryService, containerTracker, new LogOutputSpecFactory(true, true, null), log);
}
};
Properties projectProps = new Properties();
StartContainerExecutor startContainerExecutor = new StartContainerExecutor.Builder().serviceHub(hub).projectProperties(projectProps).portMapping(new PortMapping(Collections.emptyList(), projectProps)).gavLabel(new GavLabel("io.fabric8:test:0.1.0")).basedir(new File("/tmp/foo")).containerNamePattern("test-").buildTimestamp(new Date()).exposeContainerProps("docker.container").imageConfig(new ImageConfiguration.Builder().name("name").alias("alias").runConfig(new RunImageConfiguration.Builder().build()).build()).build();
// When
String containerId = startContainerExecutor.startContainer();
// Then
assertEquals("container-name", containerId);
assertEquals("container-name", projectProps.getProperty("docker.container.alias.id"));
assertEquals("192.168.1.2", projectProps.getProperty("docker.container.alias.ip"));
}
Aggregations