diff options
author | George, Lina (lg941u) <lg941u@att.com> | 2018-01-09 13:46:51 -0500 |
---|---|---|
committer | Skip Wonnell <skip@att.com> | 2018-01-09 19:10:59 +0000 |
commit | db1cca1d26714021a069b2aedeaf83d7325d7493 (patch) | |
tree | fa509abff9e1c29e64a648a0eb11d9afbebccc93 /appc-config/appc-config-audit/provider/src | |
parent | 531ba500e19e30b7d4ff0ee8c585f407f6ee295a (diff) |
Updates to config audit bundle
Issue-ID: APPC-381
Change-Id: I822df3e4352964bfd14e5b1a81a6e0739d409c5c
Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
Diffstat (limited to 'appc-config/appc-config-audit/provider/src')
2 files changed, 43 insertions, 25 deletions
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); |