Search in sources :

Example 1 with VolumeService

use of io.fabric8.maven.docker.service.VolumeService 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 = (JSONObject) JSONParser.parseJSON(vcc.toJson());
                    assertEquals(vccJson.get("Driver"), "test");
                }
            }));
            result = "testVolume";
        }
    };
    String volume = new VolumeService(docker).createVolume(config);
    assertEquals(volume, "testVolume");
}
Also used : Expectations(mockit.Expectations) VolumeCreateConfig(io.fabric8.maven.docker.access.VolumeCreateConfig) JSONObject(org.json.JSONObject) Delegate(mockit.Delegate) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) Test(org.junit.Test)

Example 2 with VolumeService

use of io.fabric8.maven.docker.service.VolumeService 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 3 with VolumeService

use of io.fabric8.maven.docker.service.VolumeService 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 VolumeService

use of io.fabric8.maven.docker.service.VolumeService in project docker-maven-plugin by fabric8io.

the class VolumeRemoveMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub serviceHub) throws DockerAccessException, MojoExecutionException {
    VolumeService volService = serviceHub.getVolumeService();
    for (VolumeConfiguration volume : getVolumes()) {
        log.info("Removing volume %s", volume.getName());
        volService.removeVolume(volume.getName());
    }
}
Also used : VolumeService(io.fabric8.maven.docker.service.VolumeService) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration)

Example 5 with VolumeService

use of io.fabric8.maven.docker.service.VolumeService in project docker-maven-plugin by fabric8io.

the class VolumeCreateMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub serviceHub) throws DockerAccessException, MojoExecutionException {
    VolumeService volService = serviceHub.getVolumeService();
    for (VolumeConfiguration volume : getVolumes()) {
        log.info("Creating volume '%s'", volume.getName());
        volService.createVolume(volume);
    }
}
Also used : VolumeService(io.fabric8.maven.docker.service.VolumeService) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration)

Aggregations

VolumeConfiguration (io.fabric8.maven.docker.config.VolumeConfiguration)5 Expectations (mockit.Expectations)3 Test (org.junit.Test)3 VolumeService (io.fabric8.maven.docker.service.VolumeService)2 VolumeCreateConfig (io.fabric8.maven.docker.access.VolumeCreateConfig)1 Delegate (mockit.Delegate)1 JSONObject (org.json.JSONObject)1