diff options
Diffstat (limited to 'appc-config/appc-config-audit/provider')
3 files changed, 50 insertions, 31 deletions
diff --git a/appc-config/appc-config-audit/provider/pom.xml b/appc-config/appc-config-audit/provider/pom.xml index 6e829da43..25f7f3418 100644 --- a/appc-config/appc-config-audit/provider/pom.xml +++ b/appc-config/appc-config-audit/provider/pom.xml @@ -22,12 +22,13 @@ <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sli-provider</artifactId> </dependency> - <dependency> - <groupId>xmlunit</groupId> - <artifactId>xmlunit</artifactId> - <version>${xmlunit.version}</version> - <scope>compile</scope> - </dependency> + <!-- https://mvnrepository.com/artifact/org.xmlunit/xmlunit-core --> + <dependency> + <groupId>org.xmlunit</groupId> + <artifactId>xmlunit-core</artifactId> + <version>${xmlunit-core.version}</version> + <scope>compile</scope> + </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> diff --git a/appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareXmlData.java b/appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareXmlData.java index b96f94764..1b0fc8c2f 100644 --- a/appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareXmlData.java +++ b/appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareXmlData.java @@ -9,15 +9,15 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ @@ -32,8 +32,13 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLUnit; +import org.xmlunit.diff.ComparisonResult; +import org.xmlunit.diff.ComparisonType; +import org.xmlunit.diff.DefaultNodeMatcher; +import org.xmlunit.diff.ElementSelectors; +import org.xmlunit.util.Nodes; +import org.xmlunit.builder.DiffBuilder; +import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -64,21 +69,38 @@ public class CompareXmlData implements CompareDataInterface log.debug("controlXml : " + controlXml); log.debug("testXml : " + testXml); - - doSetup(); + controlXml = controlXml.replace("junos:", ""); + testXml = testXml.replace("junos:", ""); + //doSetup(); try { - Diff diff = new Diff(getCompareDoc(controlXml), getCompareDoc(testXml)); - if(diff.similar()) - return true; - else + //Diff diff = new Diff(getCompareDoc(controlXml), getCompareDoc(testXml)); + final org.xmlunit.diff.Diff documentDiff = DiffBuilder + .compare(controlXml) + .withTest(testXml) + .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)) + .checkForSimilar() + .withDifferenceEvaluator((comparison, outcome) -> { + if (outcome != ComparisonResult.EQUAL && comparison.getType() == ComparisonType.ATTR_VALUE) { + Attr a = (Attr) comparison.getControlDetails().getTarget(); + if ("commit-seconds".equals(Nodes.getQName(a).getLocalPart()) || "commit-localtime".equals(Nodes.getQName(a).getLocalPart()) + && "configuration".equals(Nodes.getQName(a.getOwnerElement()).getLocalPart())) { + return ComparisonResult.EQUAL; + } + } + else + return ComparisonResult.SIMILAR; + + return outcome; + }) + .ignoreComments() + .ignoreWhitespace() + .build(); + if(documentDiff.hasDifferences()) return false; - } - catch(SAXException se) - { - se.printStackTrace(); - throw new Exception(se.getMessage()); + else + return true; } catch(Exception e) { @@ -87,13 +109,14 @@ public class CompareXmlData implements CompareDataInterface } } - private void doSetup() throws ParserConfigurationException, SAXException, IOException + /*private void doSetup() throws ParserConfigurationException, SAXException, IOException { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); - } + }*/ + public Document getCompareDoc(String inXml) throws ParserConfigurationException, SAXException, IOException { diff --git a/appc-config/appc-config-audit/provider/src/test/java/org/onap/sdnc/config/audit/node/TestCompareNodeXml.java b/appc-config/appc-config-audit/provider/src/test/java/org/onap/sdnc/config/audit/node/TestCompareNodeXml.java index c2c702ebe..df4be95ac 100644 --- a/appc-config/appc-config-audit/provider/src/test/java/org/onap/sdnc/config/audit/node/TestCompareNodeXml.java +++ b/appc-config/appc-config-audit/provider/src/test/java/org/onap/sdnc/config/audit/node/TestCompareNodeXml.java @@ -43,13 +43,8 @@ public class TestCompareNodeXml { SvcLogicContext ctx = new SvcLogicContext(); HashMap<String, String> testMap = new HashMap<String, String>(); CompareNode cmp = new CompareNode(); - String s = "<configuration xmlns=" + "\"http://xml.juniper.net/xnm/1.1/xnm\"" + " junos:commit-seconds=" - + "\"1473957536\" " + "junos:commit-localtime=" + "\"2016-09-15 16:38:56 UTC\" " + "junos:commit-user=" - + "\"root\"" + "><name>Test</name></configuration>"; - - String t = "<configuration xmlns=" + "\"http://xml.juniper.net/xnm/1.1/xnm\"" + " junos:commit-seconds=" - + "\"1473957536\" " + "junos:commit-localtime=" + "\"2016-09-15 16:38:56 UTC\" " + "junos:commit-user=" - + "\"root\"" + "><name>Test</name></configuration>"; + String s = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" junos:commit-seconds=\"1502141521\" junos:commit-localtime=\"2017-08-07 21:32:03 UTC\" junos:commit-user=\"root\"> </configuration>"; + String t = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\" junos:commit-localtime=\"2017-08-07 21:12:03 UTC\" junos:commit-seconds=\"15021523\" junos:commit-user=\"root\"> </configuration>"; testMap.put("compareDataType", "RESTCONF-XML"); testMap.put("requestIdentifier", "123"); testMap.put("sourceData", s); |