From db1cca1d26714021a069b2aedeaf83d7325d7493 Mon Sep 17 00:00:00 2001 From: "George, Lina (lg941u)" Date: Tue, 9 Jan 2018 13:46:51 -0500 Subject: Updates to config audit bundle Issue-ID: APPC-381 Change-Id: I822df3e4352964bfd14e5b1a81a6e0739d409c5c Signed-off-by: George, Lina (lg941u) --- .../sdnc/config/audit/node/CompareXmlData.java | 59 +++++++++++++++------- 1 file changed, 41 insertions(+), 18 deletions(-) (limited to 'appc-config/appc-config-audit/provider/src/main/java') 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 { -- cgit 1.2.3-korg