public static Collection<Link> valuesOf(Collection<String> links) { if (links == null) { return null; } List<Link> result = new ArrayList<Link>(); for (String link : links) { result.add(valueOf(link)); } return result; }
public static Collection<Link> valuesOf(Collection<String> links) { if (links == null) { return null; } List<Link> result = new ArrayList<Link>(); for (String link : links) { result.add(valueOf(link)); } return result; }
private static Link linkFromCubeAnnotatedField(Field cubeField) { final String linkName = linkNameFromCubeAnnotatedField(cubeField); return Link.valueOf(linkName); }
private static Link linkFromCubeAnnotatedField(Field cubeField) { final String linkName = linkNameFromCubeAnnotatedField(cubeField); return Link.valueOf(linkName); }
public ContainerBuilder addLinks(Collection<String> links) { Collection<Link> listOfLinks = new HashSet<Link>(); for (String link : links) { listOfLinks.add(Link.valueOf(link)); } if (configuration.getLinks() != null) { Collection<Link> oldLinks = configuration.getLinks(); oldLinks.addAll(listOfLinks); } else { configuration.setLinks(listOfLinks); } return this; }
public ContainerBuilder addLinks(Collection<String> links) { Collection<Link> listOfLinks = new HashSet<Link>(); for (String link : links) { listOfLinks.add(Link.valueOf(link)); } if (configuration.getLinks() != null) { Collection<Link> oldLinks = configuration.getLinks(); oldLinks.addAll(listOfLinks); } else { configuration.setLinks(listOfLinks); } return this; }
@Override public Object construct(Node node) { if (node.getType() == PortBinding.class) { String value = constructScalar((ScalarNode) node).toString(); return PortBinding.valueOf(value); } else if (node.getType() == ExposedPort.class) { String value = constructScalar((ScalarNode) node).toString(); return ExposedPort.valueOf(value); } else if (node.getType() == Image.class) { String value = constructScalar((ScalarNode) node).toString(); return Image.valueOf(value); } else if (node.getType() == Link.class) { String value = constructScalar((ScalarNode) node).toString(); return Link.valueOf(value); } return super.construct(node); } }
@Override public Object construct(Node node) { if (node.getType() == PortBinding.class) { String value = constructScalar((ScalarNode) node).toString(); return PortBinding.valueOf(value); } else if (node.getType() == ExposedPort.class) { String value = constructScalar((ScalarNode) node).toString(); return ExposedPort.valueOf(value); } else if (node.getType() == Image.class) { String value = constructScalar((ScalarNode) node).toString(); return Image.valueOf(value); } else if (node.getType() == Link.class) { String value = constructScalar((ScalarNode) node).toString(); return Link.valueOf(value); } return super.construct(node); } }
private static CubeContainer createVncContainer(final Path dockerVolume, String seleniumContainerName) { CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setImage(Image.valueOf(VNC_IMAGE)); cubeContainer.setBinds( Arrays.asList(convertToBind(dockerVolume, VOLUME_DIR, "Z")) ); final Link link = Link.valueOf(seleniumContainerName + ":" + VNC_HOSTNAME); cubeContainer.setLinks(Arrays.asList(link)); // Using sleeping strategy since VNC client is a CLI without exposing a port Await await = new Await(); await.setStrategy("sleeping"); await.setSleepTime("100 ms"); cubeContainer.setAwait(await); cubeContainer.setCmd(Arrays.asList(FLVREC_COMMAND)); // sets container as manual because we need to start and stop for each test case cubeContainer.setManual(true); return cubeContainer; }
private static CubeContainer createVncContainer(final Path dockerVolume, String seleniumContainerName, String dockerRegistry) { CubeContainer cubeContainer = new CubeContainer(); cubeContainer.setImage(Image.valueOf(dockerRegistry + VNC_IMAGE)); cubeContainer.setBinds( Arrays.asList(convertToBind(dockerVolume, VOLUME_DIR, "Z")) ); final Link link = Link.valueOf(seleniumContainerName + ":" + VNC_HOSTNAME); cubeContainer.setLinks(Arrays.asList(link)); // Using sleeping strategy since VNC client is a CLI without exposing a port Await await = new Await(); await.setStrategy("sleeping"); await.setSleepTime("100 ms"); cubeContainer.setAwait(await); cubeContainer.setCmd(Arrays.asList(FLVREC_COMMAND)); // sets container as manual because we need to start and stop for each test case cubeContainer.setManual(true); return cubeContainer; }
@Test public void shouldLinkInnerContainers() { CubeContainerObjectTestEnricher cubeContainerObjectTestEnricher = new CubeContainerObjectTestEnricher(); cubeContainerObjectTestEnricher.containerObjectFactoryInstance = () -> dockerContainerObjectFactory; when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(cubeContainerObjectTestEnricher)); ThirdInjetableTest thirdInjetableTest = new ThirdInjetableTest(); cubeContainerObjectTestEnricher.enrich(thirdInjetableTest); final org.arquillian.cube.spi.Cube<?> outterContainer = cubeRegistry.getCube("outter"); assertThat(outterContainer, is(notNullValue())); DockerCube dockerCube = (DockerCube) outterContainer; final Collection<org.arquillian.cube.docker.impl.client.config.Link> links = dockerCube.configuration().getLinks(); assertThat(links.size(), is(1)); assertThat(links, hasItem(org.arquillian.cube.docker.impl.client.config.Link.valueOf("db:db"))); final org.arquillian.cube.spi.Cube<?> innerContainer = cubeRegistry.getCube("inner"); assertThat(innerContainer, is(notNullValue())); verify(cubeController, times(1)).start("outter"); verify(cubeController, times(1)).create("outter"); verify(cubeController, times(1)).start("inner"); verify(cubeController, times(1)).create("inner"); }
@Test public void shouldLinkInnerContainersWithoutLink() { CubeContainerObjectTestEnricher cubeContainerObjectTestEnricher = new CubeContainerObjectTestEnricher(); cubeContainerObjectTestEnricher.containerObjectFactoryInstance = () -> dockerContainerObjectFactory; when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(cubeContainerObjectTestEnricher)); FifthInjetableTest fifthInjetableTest = new FifthInjetableTest(); cubeContainerObjectTestEnricher.enrich(fifthInjetableTest); final org.arquillian.cube.spi.Cube<?> outterContainer = cubeRegistry.getCube("outter"); assertThat(outterContainer, is(notNullValue())); DockerCube dockerCube = (DockerCube) outterContainer; final Collection<org.arquillian.cube.docker.impl.client.config.Link> links = dockerCube.configuration().getLinks(); assertThat(links.size(), is(1)); assertThat(links, hasItem(org.arquillian.cube.docker.impl.client.config.Link.valueOf("inner:inner"))); final org.arquillian.cube.spi.Cube<?> innerContainer = cubeRegistry.getCube("inner"); assertThat(innerContainer, is(notNullValue())); verify(cubeController, times(1)).start("outter"); verify(cubeController, times(1)).create("outter"); verify(cubeController, times(1)).start("inner"); verify(cubeController, times(1)).create("inner"); }
@Test public void shouldLinkInnerContainersWithLink() { final AtomicReference<DockerCube> cubeRef = new AtomicReference<>(); try { TestContainerObjectWithAnnotatedLink containerObject = new DockerContainerObjectBuilder<TestContainerObjectWithAnnotatedLink>( dockerClientExecutor, cubeController, cubeRegistry) .withContainerObjectClass(TestContainerObjectWithAnnotatedLink.class) .withEnrichers(enrichers) .onCubeCreated(cubeRef::set) .build(); assertThat(containerObject, is(notNullValue())); assertThat(containerObject.linkedContainerObject, is(notNullValue())); } catch (IllegalAccessException|InvocationTargetException|IOException e) { fail(); } DockerCube cube = cubeRef.get(); assertThat(cube, is(notNullValue())); assertThat(cube.hasMetadata(IsContainerObject.class), is(true)); assertThat(cube.getMetadata(IsContainerObject.class).getTestClass(), is(nullValue())); Collection<org.arquillian.cube.docker.impl.client.config.Link> links = cube.configuration().getLinks(); assertThat(links, is(notNullValue())); assertThat(links.size(), is(1)); assertThat(links, hasItem(org.arquillian.cube.docker.impl.client.config.Link.valueOf("db:db"))); verify(cubeController, times(1)).create("containerWithAnnotatedLink"); verify(cubeController, times(1)).start("containerWithAnnotatedLink"); verify(cubeContainerObjectTestEnricher, times(1)).enrich(any(TestContainerObjectWithAnnotatedLink.class)); }
@Test public void shouldLinkInnerContainersWithoutLink() { final AtomicReference<DockerCube> cubeRef = new AtomicReference<>(); try { TestContainerObjectWithNonAnnotatedLink containerObject = new DockerContainerObjectBuilder<TestContainerObjectWithNonAnnotatedLink>(dockerClientExecutor, cubeController, cubeRegistry) .withContainerObjectClass(TestContainerObjectWithNonAnnotatedLink.class) .withEnrichers(enrichers) .onCubeCreated(cubeRef::set) .build(); assertThat(containerObject, is(notNullValue())); assertThat(containerObject.linkedContainerObject, is(notNullValue())); } catch (IllegalAccessException|InvocationTargetException|IOException e) { fail(); } DockerCube cube = cubeRef.get(); assertThat(cube, is(notNullValue())); assertThat(cube.hasMetadata(IsContainerObject.class), is(true)); assertThat(cube.getMetadata(IsContainerObject.class).getTestClass(), is(nullValue())); Collection<org.arquillian.cube.docker.impl.client.config.Link> links = cube.configuration().getLinks(); assertThat(links, is(notNullValue())); assertThat(links.size(), is(1)); assertThat(links, hasItem(org.arquillian.cube.docker.impl.client.config.Link.valueOf("inner:inner"))); verify(cubeController, times(1)).create("containerWithNonAnnotatedLink"); verify(cubeController, times(1)).start("containerWithNonAnnotatedLink"); verify(cubeContainerObjectTestEnricher, times(1)).enrich(any(TestContainerObjectWithAnnotatedLink.class)); }
@Test public void should_create_container_with_link() { // given ContainerDsl containerDsl = new ContainerDsl("fedora") .withLink("mylink"); // when final Container container = containerDsl.buildContainer(); // then assertThat(container.getContainerName()).isEqualTo("fedora"); assertThat(container.getCubeContainer().getLinks()) .hasSize(1) .containsExactlyInAnyOrder(Link.valueOf("mylink")); }
@Test public void shouldTransformSimpleDockerComposeV2FormatWithNetworksByDefaultDriver() throws URISyntaxException, IOException { URI simpleDockerCompose = DockerComposeConverterTest.class.getResource("/simple-docker-compose-networks-v2.yml").toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(simpleDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.getContainers().get("webapp"); assertThat(webapp.getBuildImage(), is(notNullValue())); assertThat(webapp.getPortBindings(), is(notNullValue())); Collection<PortBinding> ports = webapp.getPortBindings(); assertThat(ports, containsInAnyOrder(PortBinding.valueOf("8000->8000"))); assertThat(webapp.getDevices(), is(notNullValue())); assertThat(webapp.getVolumes(), is(notNullValue())); Collection<String> webappVolumes = (Collection<String>) webapp.getVolumes(); assertThat(webappVolumes, containsInAnyOrder("/data")); CubeContainer webapp2 = convert.getContainers().get("webapp2"); assertThat(webapp2.getImage(), is(notNullValue())); assertThat(webapp2.getPortBindings(), is(notNullValue())); assertThat(webapp2.getLinks(), is(notNullValue())); Collection<Link> links = webapp2.getLinks(); assertThat(links, containsInAnyOrder(Link.valueOf("webapp:webapp"))); assertThat(webapp2.getEnv(), is(notNullValue())); Collection<String> env = webapp2.getEnv(); assertThat(env, containsInAnyOrder("RACK_ENV=development")); Map<String, Network> networks = convert.getNetworks(); Network network = networks.get("front-tier"); assertThat(network.getDriver(), is("bridge")); Network network2 = networks.get("back-tier"); assertThat(network2.getDriver(), is("bridge")); }
@Test public void shouldTransformSimpleDockerComposeFormat() throws URISyntaxException, IOException { URI simpleDockerCompose = DockerComposeConverterTest.class.getResource("/simple-docker-compose.yml").toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(simpleDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.get("webapp"); assertThat(webapp.getBuildImage(), is(notNullValue())); assertThat(webapp.getPortBindings(), is(notNullValue())); Collection<PortBinding> ports = webapp.getPortBindings(); assertThat(ports, containsInAnyOrder(PortBinding.valueOf("8000->8000"))); assertThat(webapp.getDevices(), is(notNullValue())); assertThat(webapp.getVolumes(), is(notNullValue())); Collection<String> volumes = (Collection<String>) webapp.getVolumes(); assertThat(volumes, containsInAnyOrder("/data")); CubeContainer webapp2 = convert.get("webapp2"); assertThat(webapp2.getImage(), is(notNullValue())); assertThat(webapp2.getPortBindings(), is(notNullValue())); assertThat(webapp2.getLinks(), is(notNullValue())); Collection<Link> links = webapp2.getLinks(); assertThat(links, containsInAnyOrder(Link.valueOf("webapp:webapp"))); assertThat(webapp2.getEnv(), is(notNullValue())); Collection<String> env = webapp2.getEnv(); assertThat(env, containsInAnyOrder("RACK_ENV=development")); }
@Test public void shouldTransformSimpleDockerComposeV2FormatWithNetworks() throws URISyntaxException, IOException { URI simpleDockerCompose = DockerComposeConverterTest.class.getResource("/simple-docker-compose-v2.yml").toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(simpleDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.getContainers().get("webapp"); assertThat(webapp.getBuildImage(), is(notNullValue())); assertThat(webapp.getPortBindings(), is(notNullValue())); Collection<PortBinding> ports = webapp.getPortBindings(); assertThat(ports, containsInAnyOrder(PortBinding.valueOf("8000->8000"))); assertThat(webapp.getDevices(), is(notNullValue())); assertThat(webapp.getVolumes(), is(notNullValue())); Collection<String> webappVolumes = (Collection<String>) webapp.getVolumes(); assertThat(webappVolumes, containsInAnyOrder("/data")); CubeContainer webapp2 = convert.getContainers().get("webapp2"); assertThat(webapp2.getImage(), is(notNullValue())); assertThat(webapp2.getPortBindings(), is(notNullValue())); assertThat(webapp2.getLinks(), is(notNullValue())); Collection<Link> links = webapp2.getLinks(); assertThat(links, containsInAnyOrder(Link.valueOf("webapp:webapp"))); assertThat(webapp2.getEnv(), is(notNullValue())); Collection<String> env = webapp2.getEnv(); assertThat(env, containsInAnyOrder("RACK_ENV=development")); Map<String, Network> networks = convert.getNetworks(); Network network = networks.get("front-tier"); assertThat(network.getDriver(), is("bridge")); Network network2 = networks.get("back-tier"); assertThat(network2.getDriver(), is("bridge")); }