### Question:
SameServerDriverLifecycleEffectorTasks extends MachineLifecycleEffectorTasks { protected Collection<Integer> getRequiredOpenPorts() { Set<Integer> result = Sets.newLinkedHashSet(); result.addAll(getRequiredOpenPorts(entity())); LOG.debug("getRequiredOpenPorts detected aggregated default {} for {}", result, this); return result; }    }### Answer:
@Test public void testGetRequiredOpenPorts() { SameServerEntity entity = app.createAndManageChild(EntitySpec.create(SameServerEntity.class).child( EntitySpec.create(EntityWithConfig.class) .configure(EntityWithConfig.INTEGER, 1) .configure(EntityWithConfig.DOUBLE, 2.0) .configure(EntityWithConfig.STRING, "3"))); SameServerDriverLifecycleEffectorTasks effectorTasks = new SameServerDriverLifecycleEffectorTasks(); Collection<Integer> requiredPorts = effectorTasks.getRequiredOpenPorts(entity); final ImmutableSet<Integer> expected = ImmutableSet.of(22, 1234); assertEquals(requiredPorts, expected, "expected=" + Iterables.toString(expected) + ", actual=" + Iterables.toString(requiredPorts)); }
@Test public void testGetRequiredOpenPortsByConfigName() { SameServerEntity entity = app.createAndManageChild(EntitySpec.create(SameServerEntity.class).child( EntitySpec.create(EntityWithConfig.class) .configure(EntityWithConfig.INTEGER, 1) .configure(EntityWithConfig.DOUBLE, 2.0) .configure(EntityWithConfig.STRING, "3") .configure(EntityWithConfig.REGEX_PORT, 4321))); SameServerDriverLifecycleEffectorTasks effectorTasks = new SameServerDriverLifecycleEffectorTasks(); Collection<Integer> requiredPorts = effectorTasks.getRequiredOpenPorts(entity); final ImmutableSet<Integer> expected = ImmutableSet.of(22, 1234, 4321); assertEquals(requiredPorts, expected, "expected=" + Iterables.toString(expected) + ", actual=" + Iterables.toString(requiredPorts)); }
@Test public void testGetRequiredOpenPortsNoAutoInfer() { SameServerEntity entity = app.createAndManageChild(EntitySpec.create(SameServerEntity.class) .child( EntitySpec.create(EntityWithConfig.class) .configure(EntityWithConfig.INTEGER, 1) .configure(EntityWithConfig.DOUBLE, 2.0) .configure(EntityWithConfig.STRING, "3") .configure(EntityWithConfig.REGEX_PORT, 4321) .configure(SameServerEntity.INBOUND_PORTS_AUTO_INFER, false))); SameServerDriverLifecycleEffectorTasks effectorTasks = new SameServerDriverLifecycleEffectorTasks(); Collection<Integer> requiredPorts = effectorTasks.getRequiredOpenPorts(entity); final ImmutableSet<Integer> expected = ImmutableSet.of(22); assertEquals(requiredPorts, expected, "expected=" + Iterables.toString(expected) + ", actual=" + Iterables.toString(requiredPorts)); }
@Test public void testGetRequiredOpenPortsWithCustomLoginPort() { SameServerEntity entity = app.createAndManageChild(EntitySpec.create(SameServerEntity.class) .configure(SameServerEntity.REQUIRED_OPEN_LOGIN_PORTS, ImmutableSet.of(2022)) .child( EntitySpec.create(EntityWithConfig.class) .configure(EntityWithConfig.INTEGER, 1) .configure(EntityWithConfig.DOUBLE, 2.0) .configure(EntityWithConfig.STRING, "3"))); SameServerDriverLifecycleEffectorTasks effectorTasks = new SameServerDriverLifecycleEffectorTasks(); Collection<Integer> requiredPorts = effectorTasks.getRequiredOpenPorts(entity); final ImmutableSet<Integer> expected = ImmutableSet.of(2022, 1234); assertEquals(requiredPorts, expected, "expected=" + Iterables.toString(expected) + ", actual=" + Iterables.toString(requiredPorts)); }