PropertiesProcessor implements PreProcessor { public Document process(Document input) throws TransformerException { Document doc = Xml.copyDocument(input); final Document document = buildProperties(doc); applyProperties(document.getDocumentElement()); return document; } PropertiesProcessor(); Document process(Document input); LinkedHashMap<String, String> getProperties();  }
@Test public void testPropertyApplying() throws TransformerException { String input = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">" + " <preprocess:properties>" + " <slobrok.port>4099</slobrok.port>" + " <redundancy>2</redundancy>" + " <doctype>music</doctype>" + " <zero>0</zero>" + " </preprocess:properties>" + " <admin version=\"2.0\">" + " <adminserver hostalias=\"node0\"/>" + " <slobroks>" + " <slobrok hostalias=\"node1\" baseport=\"${slobrok.port}\"/>" + " </slobroks>" + " </admin>" + " <content id=\"foo\" version=\"1.0\">" + " <redundancy>${redundancy}</redundancy>" + " <documents>" + " <document mode=\"index\" type=\"${doctype}.sd\"/>" + " </documents>" + " <nodes>" + " <node distribution-key=\"${zero}\" hostalias=\"node${zero}\"/>" + " </nodes>" + " </content>" + "</services>"; String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">" + " <admin version=\"2.0\">" + " <adminserver hostalias=\"node0\"/>" + " <slobroks>" + " <slobrok hostalias=\"node1\" baseport=\"4099\"/>" + " </slobroks>" + " </admin>" + " <content id=\"foo\" version=\"1.0\">" + " <redundancy>2</redundancy>" + " <documents>" + " <document mode=\"index\" type=\"music.sd\"/>" + " </documents>" + " <nodes>" + " <node distribution-key=\"0\" hostalias=\"node0\"/>" + " </nodes>" + " </content>" + "</services>"; Document inputDoc = Xml.getDocument(new StringReader(input)); Document newDoc = new PropertiesProcessor().process(inputDoc); TestBase.assertDocument(expected, newDoc); }
@Test public void testWarnIfDuplicatePropertyForSameEnvironment() throws TransformerException { String input = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">" + " <preprocess:properties>" + " <slobrok.port>4099</slobrok.port>" + " <slobrok.port>5000</slobrok.port>" + " <redundancy>2</redundancy>" + " </preprocess:properties>" + " <admin version=\"2.0\">" + " <adminserver hostalias=\"node0\"/>" + " <slobroks>" + " <slobrok hostalias=\"node1\" baseport=\"${slobrok.port}\"/>" + " </slobroks>" + " </admin>" + "</services>"; String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<services xmlns:deploy=\"vespa\" xmlns:preprocess=\"properties\" version=\"1.0\">" + " <admin version=\"2.0\">" + " <adminserver hostalias=\"node0\"/>" + " <slobroks>" + " <slobrok hostalias=\"node1\" baseport=\"5000\"/>" + " </slobroks>" + " </admin>" + "</services>"; Document inputDoc = Xml.getDocument(new StringReader(input)); Document newDoc = new PropertiesProcessor().process(inputDoc); TestBase.assertDocument(expected, newDoc); }