@Override public synchronized Set<Integer> getBoundPorts() { return isBound() ? Collections.unmodifiableSet(boundPorts) : getContainerPorts(); }
@Before public void setup() { Yaml yaml = new Yaml(); @SuppressWarnings("unchecked") Map<String, Object> content = (Map<String, Object>) yaml.load(CONTENT); when(cube.getId()).thenReturn(CUBE_ID); when(cube.configuration()).thenReturn(content); when(cube.getMetadata(HasPortBindings.class)).thenReturn( new TestPortBindings(new Binding("localhost").addPortBinding(8089, 8090))); when(container.getName()).thenReturn(CUBE_ID); when(container.getDeployableContainer()).thenReturn(deployableContainer); when(deployableContainer.getConfigurationClass()).thenReturn(ContainerConfiguration.class); when(container.getContainerConfiguration()).thenReturn(containerDef); when(containerRegistry.getContainers()).thenReturn(Arrays.asList(container)); registry = new LocalCubeRegistry(); registry.addCube(cube); bind(ApplicationScoped.class, CubeRegistry.class, registry); bind(ApplicationScoped.class, ContainerRegistry.class, containerRegistry); }
@Test // equal ip, different ports public void shouldUpdateWithPortFromDocker() throws Exception { Binding binding = new Binding(LOCALHOST); binding.addPortBinding(EXPOSED_PORT, BOUND_PORT); Mockito.when(cube.getMetadata(HasPortBindings.class)).thenReturn(new TestPortBindings(binding)); bind(ContainerScoped.class, Container.class, new ContainerImpl(CUBE_CONTAINER_NAME, deployableContainer, new ContainerDefImpl("arquillian.xml"))); ProtocolMetaData metadata = new ProtocolMetaData(); metadata.addContext(new HTTPContext(LOCALHOST, EXPOSED_PORT).add(new Servlet("A", "B"))); bind(DeploymentScoped.class, ProtocolMetaData.class, metadata); fire(metadata); ProtocolMetaData updated = getManager().getContext(DeploymentContext.class) .getObjectStore().get(ProtocolMetaData.class); Assert.assertEquals(BOUND_PORT.intValue(), updated.getContexts(HTTPContext.class).iterator().next().getPort()); Assert.assertEquals(LOCALHOST, updated.getContexts(HTTPContext.class).iterator().next().getHost()); assertEventFired(ProtocolMetaData.class, 1); // twice, but original fire is intercepted and never hit the Counter }
@Test // equal ports, different ip public void shouldUpdateWithIPFromDocker() throws Exception { Binding binding = new Binding(GATEWAY_IP); binding.addPortBinding(EXPOSED_PORT, EXPOSED_PORT); Mockito.when(cube.getMetadata(HasPortBindings.class)).thenReturn(new TestPortBindings(binding)); bind(ContainerScoped.class, Container.class, new ContainerImpl(CUBE_CONTAINER_NAME, deployableContainer, new ContainerDefImpl("arquillian.xml"))); ProtocolMetaData metadata = new ProtocolMetaData(); metadata.addContext(new HTTPContext(LOCALHOST, EXPOSED_PORT).add(new Servlet("A", "B"))); bind(DeploymentScoped.class, ProtocolMetaData.class, metadata); fire(metadata); ProtocolMetaData updated = getManager().getContext(DeploymentContext.class) .getObjectStore().get(ProtocolMetaData.class); Assert.assertEquals(EXPOSED_PORT.intValue(), updated.getContexts(HTTPContext.class).iterator().next().getPort()); Assert.assertEquals(GATEWAY_IP, updated.getContexts(HTTPContext.class).iterator().next().getHost()); assertEventFired(ProtocolMetaData.class, 1); // twice, but original fire is intercepted and never hit the Counter }
@Test public void shouldNotUpdateIfContainerNotMapped() throws Exception { Binding binding = new Binding(GATEWAY_IP); binding.addPortBinding(EXPOSED_PORT, EXPOSED_PORT); Mockito.when(cube.getMetadata(HasPortBindings.class)).thenReturn(new TestPortBindings(binding)); bind(ContainerScoped.class, Container.class, new ContainerImpl("_UNMAPPED_", deployableContainer, new ContainerDefImpl("arquillian.xml"))); ProtocolMetaData metadata = new ProtocolMetaData(); metadata.addContext(new HTTPContext(LOCALHOST, EXPOSED_PORT).add(new Servlet("A", "B"))); bind(DeploymentScoped.class, ProtocolMetaData.class, metadata); fire(metadata); ProtocolMetaData updated = getManager().getContext(DeploymentContext.class) .getObjectStore().get(ProtocolMetaData.class); Assert.assertEquals(metadata.getContexts(HTTPContext.class).iterator().next(), updated.getContexts(HTTPContext.class).iterator().next()); assertEventFired(ProtocolMetaData.class, 1); } }