EffectiveServicesMojo extends AbstractVespaDeploymentMojo { static String effectiveServices(File servicesFile, ZoneId zone, InstanceName instance) throws Exception { Document processedServicesXml = new XmlPreProcessor(servicesFile.getParentFile(), servicesFile, instance, zone.environment(), zone.region()) .run(); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); Writer writer = new StringWriter(); transformer.transform(new DOMSource(processedServicesXml), new StreamResult(writer)); return writer.toString().replaceAll("\n(\\s*\n)+","\n"); }    }
@Test @DisplayName("when zone matches environment-only directive") void devServices() throws Exception { assertEquals(Files.readString(Paths.get("src/test/resources/effective-services/dev.xml")), effectiveServices(servicesFile, ZoneId.from("dev", "us-east-3"), InstanceName.defaultName())); }
@Test @DisplayName("when zone matches region-and-environment directive") void prodUsEast3() throws Exception { assertEquals(Files.readString(Paths.get("src/test/resources/effective-services/prod_us-east-3.xml")), effectiveServices(servicesFile, ZoneId.from("prod", "us-east-3"), InstanceName.defaultName())); }
@Test @DisplayName("when zone doesn't match any directives") void prodUsWest1Services() throws Exception { assertEquals(Files.readString(Paths.get("src/test/resources/effective-services/prod_us-west-1.xml")), effectiveServices(servicesFile, ZoneId.from("prod", "us-west-1"), InstanceName.defaultName())); }