Updates to config audit bundle 79/28079/2
authorGeorge, Lina (lg941u) <lg941u@att.com>
Fri, 12 Jan 2018 21:26:53 +0000 (16:26 -0500)
committerSkip Wonnell <skip@att.com>
Fri, 12 Jan 2018 23:23:31 +0000 (23:23 +0000)
Issue-ID: APPC-399
Change-Id: If60b628fb78e44b803bc91a4e96ed4b2700b6734
Signed-off-by: George, Lina (lg941u) <lg941u@att.com>
appc-config/appc-config-audit/features/src/main/resources/features.xml
appc-config/appc-config-audit/pom.xml
appc-config/appc-config-audit/provider/pom.xml
appc-config/appc-config-audit/provider/src/main/java/org/onap/sdnc/config/audit/node/CompareXmlData.java

index baca107..969fd4b 100644 (file)
@@ -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>
index 9f8b9ce..c05148c 100644 (file)
@@ -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>
 
index 7a8dc6a..2329f99 100644 (file)
             <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>
index 1b0fc8c..af66f47 100644 (file)
@@ -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