// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.application; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.RegionName; import org.junit.Test; import org.w3c.dom.Document; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLStreamException; import javax.xml.transform.TransformerException; import java.io.File; import java.io.IOException; import java.io.StringReader; /** * @author hmusum */ public class XmlPreprocessorTest { private static final File appDir = new File("src/test/resources/multienvapp"); private static final File services = new File(appDir, "services.xml"); @Test public void testPreProcessing() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException { String expectedDev = "\n" + " \n" + " \n" + " \n" + " \n" + " 1\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; Document docDev = (new XmlPreProcessor(appDir, services, Environment.dev, RegionName.from("default")).run()); TestBase.assertDocument(expectedDev, docDev); String expectedUsWest = "\n" + " \n" + " \n" + " \n" + " \n" + " 1\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; Document docUsWest = (new XmlPreProcessor(appDir, services, Environment.prod, RegionName.from("us-west"))).run(); // System.out.println(Xml.documentAsString(docUsWest)); TestBase.assertDocument(expectedUsWest, docUsWest); String expectedUsEast = "\n" + " \n" + " \n" + " \n" + " \n" + " 1\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; Document docUsEast = (new XmlPreProcessor(appDir, services, Environment.prod, RegionName.from("us-east"))).run(); TestBase.assertDocument(expectedUsEast, docUsEast); } @Test public void testPropertiesWithOverlappingNames() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException { String input = "" + "" + " " + " gamma-usnc1.dht.yahoo.com" + " 4080" + " 3600" + " 36000" + " 50000" + " 50000000" + " 0.01" + " 0.91" + " " + " " + " ${lidspacecompaction_interval}" + " ${lidspacecompaction_allowedlidbloat}" + " ${lidspacecompaction_allowedlidbloatfactor}" + " ${sherpa.host}" + " ${sherpa.port}" + " " + " " + " " + " " + ""; String expectedProd = "" + "" + " " + " 36000" + " 50000000" + " 0.91" + " gamma-usnc1.dht.yahoo.com" + " 4080" + " " + " " + " " + " " + ""; Document docDev = (new XmlPreProcessor(appDir, new StringReader(input), Environment.prod, RegionName.from("default")).run()); TestBase.assertDocument(expectedProd, docDev); } }