// Copyright Yahoo. 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.InstanceName; import com.yahoo.config.provision.RegionName; import org.junit.Test; import org.w3c.dom.Document; import java.io.File; 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 Exception { String expectedDev = "" + "\n" + " \n" + " \n" + " \n" + " \n" + " 1\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + ""; TestBase.assertDocument(expectedDev, new XmlPreProcessor(appDir, services, InstanceName.defaultName(), Environment.dev, RegionName.defaultName()).run()); String expectedStaging = "" + "\n" + " \n" + " \n" + // Difference from dev: node1 " \n" + " \n" + " 1\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "" + // Difference from dev: no TestBar " \n" + " \n" + " \n" + " \n" + ""; TestBase.assertDocument(expectedStaging, new XmlPreProcessor(appDir, services, InstanceName.defaultName(), Environment.staging, RegionName.defaultName()).run()); 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" + ""; TestBase.assertDocument(expectedUsWest, new XmlPreProcessor(appDir, services, InstanceName.defaultName(), Environment.prod, RegionName.from("us-west")).run()); String expectedUsEastAndCentral = "" + "\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" + ""; TestBase.assertDocument(expectedUsEastAndCentral, new XmlPreProcessor(appDir, services, InstanceName.defaultName(), Environment.prod, RegionName.from("us-east")).run()); TestBase.assertDocument(expectedUsEastAndCentral, new XmlPreProcessor(appDir, services, InstanceName.defaultName(), Environment.prod, RegionName.from("us-central")).run()); } @Test public void testPropertiesWithOverlappingNames() throws Exception { 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), InstanceName.defaultName(), Environment.prod, RegionName.defaultName()).run()); TestBase.assertDocument(expectedProd, docDev); } }