ListenPortEntityBuilder implements EntityBuilder { @Override public List<Entity> build(Bundle bundle, BundleType bundleType, Document document) { if (bundle instanceof AnnotatedBundle) { Map<String, ListenPort> listenPortMap = Optional.ofNullable(bundle.getListenPorts()).orElse(Collections.emptyMap()); return buildEntities(listenPortMap, ((AnnotatedBundle) bundle).getFullBundle(), bundleType, document); } else { return buildEntities(bundle.getListenPorts(), bundle, bundleType, document); } } @Inject  ListenPortEntityBuilder(IdGenerator idGenerator); @Override List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @NotNull @Override Integer getOrder();  }
@Test void buildFromEmptyDeploymentBundle() { ListenPortEntityBuilder builder = new ListenPortEntityBuilder(ID_GENERATOR); final Bundle bundle = new Bundle(); final List<Entity> listenPortEntities = builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertTrue(listenPortEntities.isEmpty()); }
@Test void buildFromEmptyEnvironmentBundle() { ListenPortEntityBuilder builder = new ListenPortEntityBuilder(ID_GENERATOR); final Bundle bundle = new Bundle(); final List<Entity> listenPortEntities = builder.build(bundle, BundleType.ENVIRONMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertEquals(2, listenPortEntities.size(), "Expecting only the 2 default ports"); checkExpectedPorts(listenPortEntities, ListenPort.HTTP_DEFAULT_PORT, ListenPort.HTTPS_DEFAULT_PORT); }
@Test void buildWithCustomPortDeploymentBundle_expectCustomOnly() { ListenPortEntityBuilder builder = new ListenPortEntityBuilder(ID_GENERATOR); final Bundle bundle = new Bundle(); addPortToBundle(bundle, buildPort()); final List<Entity> listenPortEntities = builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertEquals(1, listenPortEntities.size(),"More than 1 expected ports"); checkExpectedPorts(listenPortEntities, TEST_HTTP_PORT); }
@Test void buildWithCustomPortEnvironmentBundle_expectCustomAndDefaults() { ListenPortEntityBuilder builder = new ListenPortEntityBuilder(ID_GENERATOR); final Bundle bundle = new Bundle(); addPortToBundle(bundle, buildPort()); final List<Entity> listenPortEntities = builder.build(bundle, BundleType.ENVIRONMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertEquals(3, listenPortEntities.size(),"More than 3 expected ports"); checkExpectedPorts(listenPortEntities, ListenPort.HTTP_DEFAULT_PORT, ListenPort.HTTPS_DEFAULT_PORT, TEST_HTTP_PORT); }
@Test void buildWithCustomPortReferencingService_expectedException() { ListenPortEntityBuilder builder = new ListenPortEntityBuilder(ID_GENERATOR); final Bundle bundle = new Bundle(); addPortToBundle(bundle, buildPortWithServiceRef()); assertThrows(BundleLoadException.class, () -> builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument())); }
@Test void buildWithCustomPortReferencingService() { ListenPortEntityBuilder builder = new ListenPortEntityBuilder(ID_GENERATOR); final Bundle bundle = new Bundle(); addPortToBundle(bundle, buildPortWithServiceRef()); Service service = new Service(); service.setId("service-id"); service.setName(SERVICE_REFERENCE); bundle.getEntities(Service.class).put(SERVICE_REFERENCE, service); final List<Entity> listenPortEntities = builder.build(bundle, BundleType.DEPLOYMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); checkExpectedPorts(listenPortEntities, TEST_HTTP_PORT); }