diff options
Diffstat (limited to 'config-application-package/src/test')
3 files changed, 73 insertions, 32 deletions
diff --git a/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java index d3c2b672ee5..a456924673d 100644 --- a/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/application/IncludeProcessorTest.java @@ -13,44 +13,48 @@ import java.io.*; import java.nio.file.NoSuchFileException; /** - * @author lulf - * @since 5.22 + * @author Ulf Lilleengen */ public class IncludeProcessorTest { @Test - public void testInclude() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException { + public void testInclude() throws IOException, SAXException, ParserConfigurationException, TransformerException { File app = new File("src/test/resources/multienvapp"); DocumentBuilder docBuilder = Xml.getPreprocessDocumentBuilder(); - String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + + String expected = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + " <preprocess:properties>\n" + " <qrs.port>4099</qrs.port>\n" + " <qrs.port>5000</qrs.port>\n" + " </preprocess:properties>\n" + " <preprocess:properties deploy:environment='prod'>\n" + " <qrs.port deploy:region='us-west'>5001</qrs.port>" + - " <qrs.port deploy:region='us-east'>5002</qrs.port>" + + " <qrs.port deploy:region='us-east us-central'>5002</qrs.port>" + " </preprocess:properties>\n" + " <admin version=\"2.0\">\n" + " <adminserver hostalias=\"node0\"/>\n" + " </admin>\n" + - " <admin deploy:environment=\"prod\" version=\"2.0\">\n" + + " <admin deploy:environment=\"staging prod\" deploy:region=\"us-east us-central\" version=\"2.0\">\n" + " <adminserver hostalias=\"node1\"/>\n" + " </admin>\n" + " <content id=\"foo\" version=\"1.0\">\n" + " <redundancy>1</redundancy><documents>\n" + " <document mode=\"index\" type=\"music.sd\"/>\n" + - "</documents><nodes>\n" + + " </documents><nodes>\n" + " <node distribution-key=\"0\" hostalias=\"node0\"/>\n" + - "</nodes><nodes deploy:environment=\"prod\">\n" + + " </nodes>" + + " <nodes deploy:environment=\"prod\">\n" + " <node distribution-key=\"0\" hostalias=\"node0\"/>\n" + " <node distribution-key=\"1\" hostalias=\"node1\"/>\n" + - "</nodes><nodes deploy:environment=\"prod\" deploy:region=\"us-west\">\n" + + " </nodes>" + + " <nodes deploy:environment=\"prod\" deploy:region=\"us-west\">\n" + " <node distribution-key=\"0\" hostalias=\"node0\"/>\n" + " <node distribution-key=\"1\" hostalias=\"node1\"/>\n" + " <node distribution-key=\"2\" hostalias=\"node2\"/>\n" + - "</nodes></content>\n" + + " </nodes>" + + "</content>\n" + "<jdisc id=\"stateless\" version=\"1.0\">\n" + " <search deploy:environment=\"prod\">\n" + " <chain id=\"common\">\n" + @@ -68,7 +72,7 @@ public class IncludeProcessorTest { " </nodes>\n" + "</jdisc></services>"; - Document doc = (new IncludeProcessor(app)).process(docBuilder.parse(Xml.getServices(app))); + Document doc = new IncludeProcessor(app).process(docBuilder.parse(Xml.getServices(app))); // System.out.println(Xml.documentAsString(doc)); TestBase.assertDocument(expected, doc); } @@ -77,7 +81,7 @@ public class IncludeProcessorTest { public void testRequiredIncludeIsDefault() throws ParserConfigurationException, IOException, SAXException, TransformerException { File app = new File("src/test/resources/multienvapp_failrequired"); DocumentBuilder docBuilder = Xml.getPreprocessDocumentBuilder(); - (new IncludeProcessor(app)).process(docBuilder.parse(Xml.getServices(app))); + new IncludeProcessor(app).process(docBuilder.parse(Xml.getServices(app))); } } diff --git a/config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java b/config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java index b20437bc259..3827fe2ad42 100644 --- a/config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java +++ b/config-application-package/src/test/java/com/yahoo/config/application/XmlPreprocessorTest.java @@ -23,8 +23,10 @@ public class XmlPreprocessorTest { private static final File services = new File(appDir, "services.xml"); @Test - public void testPreProcessing() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException { - String expectedDev = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + + public void testPreProcessing() throws IOException, SAXException, ParserConfigurationException, TransformerException { + String expectedDev = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + " <admin version=\"2.0\">\n" + " <adminserver hostalias=\"node0\"/>\n" + " </admin>\n" + @@ -46,14 +48,40 @@ public class XmlPreprocessorTest { " </nodes>\n" + " </jdisc>\n" + "</services>"; + TestBase.assertDocument(expectedDev, new XmlPreProcessor(appDir, services, Environment.dev, RegionName.from("default")).run()); - Document docDev = (new XmlPreProcessor(appDir, services, Environment.dev, RegionName.from("default")).run()); - TestBase.assertDocument(expectedDev, docDev); - + String expectedStaging = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + + " <admin version=\"2.0\">\n" + + " <adminserver hostalias=\"node1\"/>\n" + // Difference from dev: node1 + " </admin>\n" + + " <content id=\"foo\" version=\"1.0\">\n" + + " <redundancy>1</redundancy>\n" + + " <documents>\n" + + " <document mode=\"index\" type=\"music.sd\"/>\n" + + " </documents>\n" + + " <nodes>\n" + + " <node distribution-key=\"0\" hostalias=\"node0\"/>\n" + + " </nodes>\n" + + " </content>\n" + + " <jdisc id=\"stateless\" version=\"1.0\">\n" + + " <search/>\n" + + " <component bundle=\"foobundle\" class=\"MyFoo\" id=\"foo\"/>\n" + + "" + // Difference from dev: no TestBar + " <nodes>\n" + + " <node hostalias=\"node0\" baseport=\"5000\"/>\n" + + " </nodes>\n" + + " </jdisc>\n" + + "</services>"; + // System.out.println(Xml.documentAsString(new XmlPreProcessor(appDir, services, Environment.staging, RegionName.from("default")).run())); + TestBase.assertDocument(expectedStaging, new XmlPreProcessor(appDir, services, Environment.staging, RegionName.from("default")).run()); - String expectedUsWest = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + + String expectedUsWest = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + " <admin version=\"2.0\">\n" + - " <adminserver hostalias=\"node1\"/>\n" + + " <adminserver hostalias=\"node0\"/>\n" + " </admin>\n" + " <content id=\"foo\" version=\"1.0\">\n" + " <redundancy>1</redundancy>\n" + @@ -81,12 +109,11 @@ public class XmlPreprocessorTest { " </nodes>\n" + " </jdisc>\n" + "</services>"; + TestBase.assertDocument(expectedUsWest, new XmlPreProcessor(appDir, services, Environment.prod, RegionName.from("us-west")).run()); - 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + + String expectedUsEastAndCentral = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">\n" + " <admin version=\"2.0\">\n" + " <adminserver hostalias=\"node1\"/>\n" + " </admin>\n" + @@ -115,14 +142,16 @@ public class XmlPreprocessorTest { " </nodes>\n" + " </jdisc>\n" + "</services>"; - - Document docUsEast = (new XmlPreProcessor(appDir, services, Environment.prod, RegionName.from("us-east"))).run(); - TestBase.assertDocument(expectedUsEast, docUsEast); + TestBase.assertDocument(expectedUsEastAndCentral, + new XmlPreProcessor(appDir, services, Environment.prod, RegionName.from("us-east")).run()); + TestBase.assertDocument(expectedUsEastAndCentral, + new XmlPreProcessor(appDir, services, Environment.prod, RegionName.from("us-central")).run()); } @Test - public void testPropertiesWithOverlappingNames() throws IOException, SAXException, XMLStreamException, ParserConfigurationException, TransformerException { - String input = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + + public void testPropertiesWithOverlappingNames() throws IOException, SAXException, ParserConfigurationException, TransformerException { + String input = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">" + " <preprocess:properties>" + " <sherpa.host>gamma-usnc1.dht.yahoo.com</sherpa.host>" + @@ -146,7 +175,8 @@ public class XmlPreprocessorTest { " </admin>" + "</services>"; - String expectedProd = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + + String expectedProd = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">" + " <config name='a'>" + " <a>36000</a>" + diff --git a/config-application-package/src/test/resources/multienvapp/services.xml b/config-application-package/src/test/resources/multienvapp/services.xml index 3d4a2087c57..d0f43f0b025 100644 --- a/config-application-package/src/test/resources/multienvapp/services.xml +++ b/config-application-package/src/test/resources/multienvapp/services.xml @@ -1,5 +1,6 @@ <!-- Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> <services version='1.0' xmlns:deploy="vespa" xmlns:preprocess="properties"> + <preprocess:properties> <qrs.port>4099</qrs.port> <qrs.port>5000</qrs.port> @@ -7,17 +8,23 @@ <preprocess:properties deploy:environment='prod'> <qrs.port deploy:region='us-west'>5001</qrs.port> - <qrs.port deploy:region='us-east'>5002</qrs.port> + <qrs.port deploy:region='us-east us-central'>5002</qrs.port> </preprocess:properties> + <admin version='2.0'> <adminserver hostalias='node0'/> </admin> - <admin version='2.0' deploy:environment='prod'> + + <admin version='2.0' deploy:environment='staging prod' deploy:region='us-east us-central'> <adminserver hostalias='node1'/> </admin> + <preprocess:include file='jdisc.xml'/> + <content version='1.0' id='foo'> <preprocess:include file='content/content_foo.xml'/> </content> + <preprocess:include file='doesnotexist.xml' required='false' /> + </services> |