ListenPortEntityBuilder implements EntityBuilder { Entity buildListenPortEntity(Bundle bundle, String name, ListenPort listenPort, Document document) { Element listenPortElement = document.createElement(LISTEN_PORT); String id = idGenerator.generate(); listenPortElement.setAttribute(ATTRIBUTE_ID, id); listenPortElement.appendChild(createElementWithTextContent(document, NAME, name)); listenPortElement.appendChild(createElementWithTextContent(document, ENABLED, TRUE.toString())); listenPortElement.appendChild(createElementWithTextContent(document, PROTOCOL, listenPort.getProtocol())); listenPortElement.appendChild(createElementWithTextContent(document, PORT, Integer.toString(listenPort.getPort()))); Element enabledFeatures = document.createElement(ENABLED_FEATURES); listenPort.getEnabledFeatures().forEach(s -> enabledFeatures.appendChild(createElementWithTextContent(document, STRING_VALUE, s))); listenPortElement.appendChild(enabledFeatures); if (listenPort.getTargetServiceReference() != null) { listenPortElement.appendChild(createServiceElement(bundle, name, listenPort, document)); } if (listenPort.getTlsSettings() != null) { listenPortElement.appendChild(createTlsSettings(bundle, name, listenPort, document)); } buildAndAppendPropertiesElement(listenPort.getProperties(), document, listenPortElement); return EntityBuilderHelper.getEntityWithNameMapping(LISTEN_PORT_TYPE, name, id, listenPortElement); } @Inject  ListenPortEntityBuilder(IdGenerator idGenerator); @Override List<Entity> build(Bundle bundle, BundleType bundleType, Document document); @NotNull @Override Integer getOrder();  }
@Test void checkListenPortXmlElements() { ListenPortEntityBuilder builder = new ListenPortEntityBuilder(new IdGenerator()); Service service = new Service(); service.setId(ID_GENERATOR.generate()); final Bundle bundle = new Bundle(); bundle.putAllServices(ImmutableMap.of(SERVICE_REFERENCE, service)); PrivateKey privateKey = new PrivateKey(); privateKey.setId(ID_GENERATOR.generate()); bundle.putAllPrivateKeys(ImmutableMap.of(PRIVATE_KEY, privateKey)); final ListenPort listenPort = buildPortWithAllOptions(); final ListenPortTlsSettings tlsSettings = listenPort.getTlsSettings(); final Entity entity = builder.buildListenPortEntity(bundle, TEST_HTTP_PORT_NAME, listenPort, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()); assertNotNull(entity.getXml()); assertNotNull(entity.getId()); final Element xml = entity.getXml(); assertNotNull(xml.getAttribute(ATTRIBUTE_ID)); assertNotNull(getSingleChildElement(xml, NAME)); assertNotNull(getSingleChildElement(xml, ENABLED)); assertNotNull(getSingleChildElement(xml, PROTOCOL)); assertNotNull(getSingleChildElement(xml, PORT)); assertNotNull(getSingleChildElement(xml, ENABLED_FEATURES)); assertNotNull(getChildElements(getSingleChildElement(xml, ENABLED_FEATURES), STRING_VALUE)); assertFalse(getChildElements(getSingleChildElement(xml, ENABLED_FEATURES), STRING_VALUE).isEmpty()); assertNotNull(getSingleChildElement(xml, TARGET_SERVICE_REFERENCE)); assertNotNull(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), CLIENT_AUTHENTICATION)); assertNotNull(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), PRIVATE_KEY_REFERENCE)); assertNotNull(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), ENABLED_VERSIONS)); assertFalse(getChildElements(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), ENABLED_VERSIONS), STRING_VALUE).isEmpty()); assertNotNull(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), ENABLED_CIPHER_SUITES)); assertFalse(getChildElements(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), ENABLED_CIPHER_SUITES), STRING_VALUE).isEmpty()); assertNotNull(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), PROPERTIES)); assertNotNull(getSingleChildElement(xml, PROPERTIES)); assertEquals(entity.getId(), xml.getAttribute(ATTRIBUTE_ID)); assertEquals(TEST_HTTP_PORT_NAME, getSingleChildElementTextContent(xml, NAME)); assertEquals(TRUE.toString(), getSingleChildElementTextContent(xml, ENABLED)); assertEquals(listenPort.getProtocol(), getSingleChildElementTextContent(xml, PROTOCOL)); assertEquals(Integer.toString(listenPort.getPort()), getSingleChildElementTextContent(xml, PORT)); assertTrue(getChildElementsTextContents(getSingleChildElement(xml, ENABLED_FEATURES), STRING_VALUE).containsAll(listenPort.getEnabledFeatures())); assertEquals(service.getId(), getSingleChildElement(xml, TARGET_SERVICE_REFERENCE).getAttribute(ATTRIBUTE_ID)); assertEquals(tlsSettings.getClientAuthentication().getType(), getSingleChildElementTextContent(getSingleChildElement(xml, TLS_SETTINGS), CLIENT_AUTHENTICATION)); assertEquals(privateKey.getId(), getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), PRIVATE_KEY_REFERENCE).getAttribute(ATTRIBUTE_ID)); assertTrue(tlsSettings.getEnabledVersions().containsAll(getChildElementsTextContents(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), ENABLED_VERSIONS), STRING_VALUE))); assertTrue(tlsSettings.getEnabledCipherSuites().containsAll(getChildElementsTextContents(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), ENABLED_CIPHER_SUITES), STRING_VALUE))); assertPropertiesContent(tlsSettings.getProperties(), mapPropertiesElements(getSingleChildElement(getSingleChildElement(xml, TLS_SETTINGS), PROPERTIES), PROPERTIES)); assertPropertiesContent(listenPort.getProperties(), mapPropertiesElements(getSingleChildElement(xml, PROPERTIES), PROPERTIES)); }