diff options
Diffstat (limited to 'appc-config/appc-config-audit')
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 @@ <features name="appc-config-audit-${project.version}" - 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"> + 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"> - <repository>mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features</repository> + <repository>mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features</repository> - <feature name='appc-config-audit' description="Application Controller Config Audit" - version='${project.version}'> - <!-- Most applications will have a dependency on the ODL MD-SAL Broker --> - <feature version="${odl.mdsal.version}">odl-mdsal-broker</feature> - <feature>sdnc-sli</feature> - <bundle>mvn:commons-lang/commons-lang/2.6</bundle> - <bundle>wrap:mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version}</bundle> - <bundle>wrap:mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version}</bundle> - <bundle>wrap:mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version}</bundle> + <feature name='appc-config-audit' description="Application Controller Config Audit" + version='${project.version}'> + <!-- Most applications will have a dependency on the ODL MD-SAL Broker --> + <feature version="${odl.mdsal.version}">odl-mdsal-broker</feature> + <feature>sdnc-sli</feature> + <bundle>mvn:commons-lang/commons-lang/2.6</bundle> + <bundle>wrap:mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version}</bundle> + <bundle>wrap:mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version}</bundle> + <bundle>wrap:mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version}</bundle> - <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>mvn:org.onap.appc/appc-config-audit-provider/${project.version}</bundle> - </feature> + <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:org.xmlunit/xmlunit-core/${xmlunit-core.version}</bundle> + <bundle>mvn:org.onap.appc/appc-config-audit-provider/${project.version}</bundle> + </feature> </features> 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 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.onap.appc</groupId> - <artifactId>appc-config</artifactId> - <version>1.3.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <packaging>pom</packaging> - <artifactId>appc-config-audit</artifactId> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>org.onap.appc</groupId> + <artifactId>appc-config</artifactId> + <version>1.3.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <packaging>pom</packaging> + <artifactId>appc-config-audit</artifactId> - <name>Config Audit Node</name> - <description>Common Utilities for DG</description> + <name>Config Audit Node</name> + <description>Common Utilities for DG</description> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <xmlunit.version>1.6</xmlunit.version> - </properties> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <xmlunit-core.version>2.3.0</xmlunit-core.version> + </properties> - <dependencyManagement> + <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.onap.appc</groupId> - <artifactId>appc-config-audit-features</artifactId> - <classifier>features</classifier> - <type>xml</type> - <version>${project.version}</version> - </dependency> + <dependencies> + <dependency> + <groupId>org.onap.appc</groupId> + <artifactId>appc-config-audit-features</artifactId> + <classifier>features</classifier> + <type>xml</type> + <version>${project.version}</version> + </dependency> - <dependency> - <groupId>org.onap.appc</groupId> - <artifactId>appc-config-audit-provider</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependency> + <groupId>org.onap.appc</groupId> + <artifactId>appc-config-audit-provider</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> - </dependencyManagement> + </dependencyManagement> - <profiles> - <profile> - <id>default</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <modules> - <module>features</module> - <module>provider</module> - <module>installer</module> - </modules> - </profile> - <profile> - <id>all</id> - <modules> - <module>features</module> - <module>provider</module> - <module>installer</module> - </modules> - </profile> - </profiles> + <profiles> + <profile> + <id>default</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <modules> + <module>features</module> + <module>provider</module> + <module>installer</module> + </modules> + </profile> + <profile> + <id>all</id> + <modules> + <module>features</module> + <module>provider</module> + <module>installer</module> + </modules> + </profile> + </profiles> </project> 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 @@ <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>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 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); |