Search in sources :

Example 1 with VolumeConfiguration

use of io.fabric8.maven.docker.config.VolumeConfiguration 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 VolumeConfiguration

use of io.fabric8.maven.docker.config.VolumeConfiguration 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 VolumeConfiguration

use of io.fabric8.maven.docker.config.VolumeConfiguration 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 VolumeConfiguration

use of io.fabric8.maven.docker.config.VolumeConfiguration 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 VolumeConfiguration

use of io.fabric8.maven.docker.config.VolumeConfiguration in project docker-maven-plugin by fabric8io.

the class VolumeBindingUtilTest method testResolveVolumeBindingsWithRunVolumeConfiguration.

/**
 * Insures that relative paths in the host portion of a volume binding string are properly resolved against a base
 * directory when present in a {@link RunVolumeConfiguration}.
 */
@Test
public void testResolveVolumeBindingsWithRunVolumeConfiguration() {
    RunVolumeConfiguration.Builder builder = new RunVolumeConfiguration.Builder();
    builder.bind(singletonList(format(BIND_STRING_FMT, RELATIVE_PATH, CONTAINER_PATH)));
    RunVolumeConfiguration volumeConfiguration = builder.build();
    // './rel:/path/to/container/dir' to '/absolute/basedir/rel:/path/to/container/dir'
    resolveRelativeVolumeBindings(ABS_BASEDIR, volumeConfiguration);
    String expectedBindingString = format(BIND_STRING_FMT, join("", ABS_BASEDIR.getAbsolutePath(), stripLeadingPeriod(RELATIVE_PATH)), CONTAINER_PATH);
    assertEquals(expectedBindingString, volumeConfiguration.getBind().get(0));
}
Also used : RunVolumeConfiguration(io.fabric8.maven.docker.config.RunVolumeConfiguration) Test(org.junit.Test)

Aggregations

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