ServiceLinker implements EntityLinker<Service> { @Override public void link(Service service, Bundle bundle, Bundle targetBundle) { try { Element policyElement = DocumentUtils.stringToXML(documentTools, service.getPolicy()); policyXMLSimplifier.simplifyPolicyXML(policyElement, service.getName(), bundle, targetBundle); service.setPolicyXML(policyElement); } catch (DocumentParseException e) { throw new WriteException("Exception linking and simplifying service: " + service.getName() + " Message: " + e.getMessage(), e); } service.setPath(getServicePath(bundle, service)); Element servicePropertiesElement = getSingleChildElement(service.getServiceDetailsElement(), PROPERTIES); NodeList propertyNodes = servicePropertiesElement.getElementsByTagName(PROPERTY); for (int i = 0; i < propertyNodes.getLength(); i++) { if (propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().startsWith("property.ENV.")) { ServiceEnvironmentProperty serviceEnvironmentProperty = new ServiceEnvironmentProperty( service.getName() + "." + propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().substring(13), getSingleChildElement((Element) propertyNodes.item(i), STRING_VALUE).getTextContent()); targetBundle.getEntities(ServiceEnvironmentProperty.class).put(serviceEnvironmentProperty.getName(), serviceEnvironmentProperty); } } } @Inject  ServiceLinker(DocumentTools documentTools, PolicyXMLSimplifier policyXMLSimplifier); @Override Class<Service> getEntityClass(); @Override void link(Service service, Bundle bundle, Bundle targetBundle);  }
@Test void linkInvalidPolicy() { Service service = new Service(); service.setPolicy("policy"); assertThrows(WriteException.class, () -> linker.link(service, null, null)); }
@Test void linkNoServiceProperties() { Bundle bundle = new Bundle(); link(bundle, false); assertTrue(bundle.getServiceEnvironmentProperties().isEmpty()); }
@Test void linkWithServiceProperties() { Bundle bundle = new Bundle(); link(bundle, true); assertFalse(bundle.getServiceEnvironmentProperties().isEmpty()); assertEquals(1, bundle.getServiceEnvironmentProperties().size()); ServiceEnvironmentProperty property = bundle.getServiceEnvironmentProperties().get("service.prop"); assertNotNull(property); assertEquals("value2", property.getValue()); assertEquals("service.prop", property.getKey()); }