use of com.oracle.bedrock.runtime.docker.commands.Remove in project oracle-bedrock by coherence-community.
the class DockerImageTest method shouldRemoveImage.
@Test
public void shouldRemoveImage() throws Exception {
Docker docker = Docker.auto();
Platform platform = mock(Platform.class);
Application application = mock(Application.class, "App");
Application removeApp = mock(Application.class, "Inspect");
DockerImage image = new DockerImage(Arrays.asList("foo"), OptionsByType.of(docker));
when(application.getPlatform()).thenReturn(platform);
when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
image.onAddingTo(application);
image.remove();
ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
verify(platform).launch(captor.capture(), anyVararg());
Remove.RemoveImage remove = (Remove.RemoveImage) captor.getValue();
assertThat(remove, is(notNullValue()));
OptionsByType optionsByType = OptionsByType.empty();
remove.onLaunch(platform, optionsByType);
Arguments arguments = optionsByType.get(Arguments.class);
List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
assertThat(values, contains("rmi", "foo"));
}
use of com.oracle.bedrock.runtime.docker.commands.Remove in project oracle-bedrock by coherence-community.
the class DockerContainerTest method shouldRemoveContainer.
@Test
public void shouldRemoveContainer() throws Exception {
Docker docker = Docker.auto();
Platform platform = mock(Platform.class);
Application application = mock(Application.class, "App");
Application removeApp = mock(Application.class, "Inspect");
DockerContainer container = new DockerContainer("foo", OptionsByType.of(docker));
when(application.getPlatform()).thenReturn(platform);
when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
container.onAddingTo(application);
container.remove(false);
ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
verify(platform).launch(captor.capture(), anyVararg());
OptionsByType optionsByType = OptionsByType.empty();
Remove.RemoveContainer remove = (Remove.RemoveContainer) captor.getValue();
assertThat(remove, is(notNullValue()));
remove.onLaunch(platform, optionsByType);
Arguments arguments = optionsByType.get(Arguments.class);
List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
assertThat(values, contains("rm", "foo"));
}
use of com.oracle.bedrock.runtime.docker.commands.Remove in project oracle-bedrock by coherence-community.
the class DockerContainer method remove.
/**
* Remove this {@link DockerContainer}.
* <p>
* This equates to running the <code>docker rm</code> command for
* this {@link DockerContainer}.
* <p>
* This command will fail to execute if the {@link DockerContainer} is still running.
*
* @param force whether to add --force to the Docker rm command
*
* @throws IllegalStateException if this {@link DockerContainer} has not been added
* to an {@link Application} as a {@link Feature}.
*/
public void remove(boolean force) {
if (platform == null) {
throw new IllegalStateException("No Platform is available, is this container a feature of an Application");
}
Docker docker = optionsByType.get(Docker.class);
Remove.RemoveContainer removeCommand;
if (force) {
removeCommand = Remove.containers(name).force(true);
} else {
removeCommand = Remove.containers(name);
}
try (Application app = platform.launch(removeCommand, docker)) {
app.waitFor();
}
}
use of com.oracle.bedrock.runtime.docker.commands.Remove in project oracle-bedrock by coherence-community.
the class DockerContainerTest method shouldRemoveContainerWithForce.
@Test
public void shouldRemoveContainerWithForce() throws Exception {
Docker docker = Docker.auto();
Platform platform = mock(Platform.class);
Application application = mock(Application.class, "App");
Application removeApp = mock(Application.class, "Inspect");
DockerContainer container = new DockerContainer("foo", OptionsByType.of(docker));
when(application.getPlatform()).thenReturn(platform);
when(platform.launch(any(MetaClass.class), anyVararg())).thenReturn(removeApp);
container.onAddingTo(application);
container.remove(true);
ArgumentCaptor<MetaClass> captor = ArgumentCaptor.forClass(MetaClass.class);
verify(platform).launch(captor.capture(), anyVararg());
OptionsByType optionsByType = OptionsByType.empty();
Remove.RemoveContainer remove = (Remove.RemoveContainer) captor.getValue();
assertThat(remove, is(notNullValue()));
remove.onLaunch(platform, optionsByType);
Arguments arguments = optionsByType.get(Arguments.class);
List<String> values = arguments.resolve(mock(Platform.class), OptionsByType.empty());
assertThat(values, contains("rm", "--force", "foo"));
}
Aggregations