From db1cca1d26714021a069b2aedeaf83d7325d7493 Mon Sep 17 00:00:00 2001 From: "George, Lina (lg941u)" Date: Tue, 9 Jan 2018 13:46:51 -0500 Subject: [PATCH] Updates to config audit bundle Issue-ID: APPC-381 Change-Id: I822df3e4352964bfd14e5b1a81a6e0739d409c5c Signed-off-by: George, Lina (lg941u) --- .../features/src/main/resources/features.xml | 40 ++++---- appc-config/appc-config-audit/pom.xml | 104 ++++++++++----------- appc-config/appc-config-audit/provider/pom.xml | 13 +-- .../sdnc/config/audit/node/CompareXmlData.java | 59 ++++++++---- .../sdnc/config/audit/node/TestCompareNodeXml.java | 9 +- 5 files changed, 122 insertions(+), 103 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 1bba6ee71..baca10788 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 @@ -8,9 +8,9 @@ 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. @@ -21,25 +21,25 @@ + xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0"> - mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features + mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features - - - odl-mdsal-broker - sdnc-sli - mvn:commons-lang/commons-lang/2.6 - wrap:mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version} - wrap:mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version} - wrap:mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version} + + + odl-mdsal-broker + sdnc-sli + mvn:commons-lang/commons-lang/2.6 + wrap:mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version} + wrap:mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version} + wrap:mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version} - wrap:mvn:com.att.eelf/eelf-core/${eelf.version} - mvn:ch.qos.logback/logback-core/${logback.version} - mvn:ch.qos.logback/logback-classic/${logback.version} - wrap:mvn:xmlunit/xmlunit/${xmlunit.version} - mvn:org.onap.appc/appc-config-audit-provider/${project.version} - + wrap:mvn:com.att.eelf/eelf-core/${eelf.version} + mvn:ch.qos.logback/logback-core/${logback.version} + mvn:ch.qos.logback/logback-classic/${logback.version} + wrap:mvn:org.xmlunit/xmlunit-core/${xmlunit-core.version} + mvn:org.onap.appc/appc-config-audit-provider/${project.version} + diff --git a/appc-config/appc-config-audit/pom.xml b/appc-config/appc-config-audit/pom.xml index 1fcced92e..d557cfaba 100644 --- a/appc-config/appc-config-audit/pom.xml +++ b/appc-config/appc-config-audit/pom.xml @@ -1,62 +1,62 @@ - - org.onap.appc - appc-config - 1.3.0-SNAPSHOT - - 4.0.0 - pom - appc-config-audit + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + org.onap.appc + appc-config + 1.3.0-SNAPSHOT + + 4.0.0 + pom + appc-config-audit - Config Audit Node - Common Utilities for DG + Config Audit Node + Common Utilities for DG - - UTF-8 - 1.6 - + + UTF-8 + 2.3.0 + - + - - - org.onap.appc - appc-config-audit-features - features - xml - ${project.version} - + + + org.onap.appc + appc-config-audit-features + features + xml + ${project.version} + - - org.onap.appc - appc-config-audit-provider - ${project.version} - - + + org.onap.appc + appc-config-audit-provider + ${project.version} + + - + - - - default - - true - - - features - provider - installer - - - - all - - features - provider - installer - - - + + + default + + true + + + features + provider + installer + + + + all + + features + provider + installer + + + 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 @@ org.onap.ccsdk.sli.core sli-provider - - xmlunit - xmlunit - ${xmlunit.version} - compile - + + + org.xmlunit + xmlunit-core + ${xmlunit-core.version} + compile + com.fasterxml.jackson.core jackson-databind 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 testMap = new HashMap(); CompareNode cmp = new CompareNode(); - String s = "Test"; - - String t = "Test"; + String s = " "; + String t = " "; testMap.put("compareDataType", "RESTCONF-XML"); testMap.put("requestIdentifier", "123"); testMap.put("sourceData", s); -- 2.16.6