diff options
author | George, Lina (lg941u) <lg941u@att.com> | 2018-01-12 16:26:53 -0500 |
---|---|---|
committer | Skip Wonnell <skip@att.com> | 2018-01-12 23:23:31 +0000 |
commit | 48a99d5e01a756f2800937b17d3609f4373b475d (patch) | |
tree | f2ffae4cfb03e83663b5e9c6818839f4674edc45 /appc-config/appc-config-audit | |
parent | e630b22c7aff7cdccd37cfaca870aa47cbf278dd (diff) |
Updates to config audit bundle
Issue-ID: APPC-399
Change-Id: If60b628fb78e44b803bc91a4e96ed4b2700b6734
Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
Diffstat (limited to 'appc-config/appc-config-audit')
4 files changed, 51 insertions, 44 deletions
diff --git a/appc-config/appc-config-audit/features/src/main/resources/features.xml b/appc-config/appc-config-audit/features/src/main/resources/features.xml index baca10788..969fd4b6e 100644 --- a/appc-config/appc-config-audit/features/src/main/resources/features.xml +++ b/appc-config/appc-config-audit/features/src/main/resources/features.xml @@ -39,6 +39,7 @@ <bundle>wrap:mvn:com.att.eelf/eelf-core/${eelf.version}</bundle> <bundle>mvn:ch.qos.logback/logback-core/${logback.version}</bundle> <bundle>mvn:ch.qos.logback/logback-classic/${logback.version}</bundle> + <bundle>wrap:mvn:xmlunit/xmlunit/${xmlunit.version}</bundle> <bundle>wrap:mvn:org.xmlunit/xmlunit-core/${xmlunit-core.version}</bundle> <bundle>mvn:org.onap.appc/appc-config-audit-provider/${project.version}</bundle> </feature> diff --git a/appc-config/appc-config-audit/pom.xml b/appc-config/appc-config-audit/pom.xml index 9f8b9ce7f..c05148c9d 100644 --- a/appc-config/appc-config-audit/pom.xml +++ b/appc-config/appc-config-audit/pom.xml @@ -36,6 +36,7 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <xmlunit.version>1.6</xmlunit.version> <xmlunit-core.version>2.3.0</xmlunit-core.version> </properties> diff --git a/appc-config/appc-config-audit/provider/pom.xml b/appc-config/appc-config-audit/provider/pom.xml index 7a8dc6aad..2329f99b7 100644 --- a/appc-config/appc-config-audit/provider/pom.xml +++ b/appc-config/appc-config-audit/provider/pom.xml @@ -43,13 +43,19 @@ <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>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 1b0fc8c2f..af66f47e5 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 @@ -32,14 +32,14 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -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.custommonkey.xmlunit.Diff; +import org.custommonkey.xmlunit.Difference; +import org.custommonkey.xmlunit.DifferenceConstants; +import org.custommonkey.xmlunit.DifferenceListener; +import org.custommonkey.xmlunit.ElementNameQualifier; +import org.custommonkey.xmlunit.XMLUnit; import org.w3c.dom.Document; +import org.w3c.dom.Node; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -69,38 +69,37 @@ public class CompareXmlData implements CompareDataInterface log.debug("controlXml : " + controlXml); log.debug("testXml : " + testXml); - controlXml = controlXml.replace("junos:", ""); - testXml = testXml.replace("junos:", ""); - //doSetup(); + doSetup(); try { - //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; - else - return true; + Diff diff = new Diff(getCompareDoc(controlXml), getCompareDoc(testXml)); + diff.overrideElementQualifier(new ElementNameQualifier() { + @Override + protected boolean equalsNamespace(Node control, Node test) { + return true; + } + }); + diff.overrideDifferenceListener(new DifferenceListener() { + @Override + public int differenceFound(Difference diff) { + if (diff.getId() == DifferenceConstants.ATTR_VALUE_ID) { + return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; + } + return RETURN_ACCEPT_DIFFERENCE; + } + @Override + public void skippedComparison(Node arg0, Node arg1) { } + }); + if(diff.similar()) + return true; + else + return false; + } + catch(SAXException se) + { + se.printStackTrace(); + throw new Exception(se.getMessage()); } catch(Exception e) { @@ -109,13 +108,13 @@ 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 |