Search in sources :

Example 1 with VolumeCreateConfig

use of io.fabric8.maven.docker.access.VolumeCreateConfig in project docker-maven-plugin by fabric8io.

the class VolumeServiceTest method testRemoveVolume.

@Test
public void testRemoveVolume() throws Exception {
    VolumeConfiguration vc = new VolumeConfiguration.Builder().name("testVolume").driver("test").opts(withMap("opts")).labels(withMap("labels")).build();
    new Expectations() {

        {
            docker.createVolume((VolumeCreateConfig) any);
            result = "testVolume";
            docker.removeVolume("testVolume");
        }
    };
    VolumeService volumeService = new VolumeService(docker);
    String name = volumeService.createVolume(vc);
    volumeService.removeVolume(name);
}
Also used : Expectations(mockit.Expectations) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) Test(org.junit.Test)

Example 2 with VolumeCreateConfig

use of io.fabric8.maven.docker.access.VolumeCreateConfig in project docker-maven-plugin by fabric8io.

the class VolumeServiceTest method testCreateVolumeConfig.

@Test
public void testCreateVolumeConfig() throws Exception {
    final VolumeConfiguration config = new VolumeConfiguration.Builder().name("testVolume").driver("test").opts(withMap("opts")).labels(withMap("labels")).build();
    new Expectations() {

        {
            // Use a 'delegate' to verify the argument given directly. No need
            // for an 'intermediate' return method in the service just to check this.
            docker.createVolume(with(new Delegate<VolumeCreateConfig>() {

                void check(VolumeCreateConfig vcc) {
                    assertThat(vcc.getName(), is("testVolume"));
                    JsonObject vccJson = JsonFactory.newJsonObject(vcc.toJson());
                    assertEquals("test", vccJson.get("Driver").getAsString());
                }
            }));
            result = "testVolume";
        }
    };
    String volume = new VolumeService(docker).createVolume(config);
    assertEquals(volume, "testVolume");
}
Also used : Expectations(mockit.Expectations) VolumeCreateConfig(io.fabric8.maven.docker.access.VolumeCreateConfig) Delegate(mockit.Delegate) JsonObject(com.google.gson.JsonObject) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) Test(org.junit.Test)

Example 3 with VolumeCreateConfig

use of io.fabric8.maven.docker.access.VolumeCreateConfig in project docker-maven-plugin by fabric8io.

the class VolumeServiceTest method testCreateVolume.

@Test
public void testCreateVolume() throws Exception {
    VolumeConfiguration vc = new VolumeConfiguration.Builder().name("testVolume").driver("test").opts(withMap("opts")).labels(withMap("labels")).build();
    new Expectations() {

        {
            docker.createVolume((VolumeCreateConfig) any);
            result = "testVolume";
        }
    };
    assertThat(vc.getName(), is("testVolume"));
    String name = new VolumeService(docker).createVolume(vc);
    assertThat(name, is("testVolume"));
}
Also used : Expectations(mockit.Expectations) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) Test(org.junit.Test)

Example 4 with VolumeCreateConfig

use of io.fabric8.maven.docker.access.VolumeCreateConfig in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method createVolume.

@Override
public String createVolume(VolumeCreateConfig containerConfig) throws DockerAccessException {
    String createJson = containerConfig.toJson();
    log.debug("Volume create config: %s", createJson);
    try {
        String url = urlBuilder.createVolume();
        log.verbose(Logger.LogVerboseCategory.API, API_LOG_FORMAT_POST_WITH_REQUEST, url, createJson);
        String response = delegate.post(url, createJson, new ApacheHttpClientDelegate.BodyResponseHandler(), HTTP_CREATED);
        JsonObject json = JsonFactory.newJsonObject(response);
        logWarnings(json);
        return json.get("Name").getAsString();
    } catch (IOException e) {
        throw new DockerAccessException(e, "Unable to create volume for [%s]", containerConfig.getName());
    }
}
Also used : DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Aggregations

VolumeConfiguration (io.fabric8.maven.docker.config.VolumeConfiguration)3 Expectations (mockit.Expectations)3 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)2 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 VolumeCreateConfig (io.fabric8.maven.docker.access.VolumeCreateConfig)1 IOException (java.io.IOException)1 Delegate (mockit.Delegate)1