2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdnc.config.audit.node;
24 import java.io.IOException;
25 import java.io.StringReader;
27 import javax.xml.parsers.DocumentBuilder;
28 import javax.xml.parsers.DocumentBuilderFactory;
29 import javax.xml.parsers.ParserConfigurationException;
31 import org.custommonkey.xmlunit.Diff;
32 import org.custommonkey.xmlunit.XMLUnit;
33 import org.w3c.dom.Document;
34 import org.xml.sax.InputSource;
35 import org.xml.sax.SAXException;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
41 public class CompareXmlData implements CompareDataInterface
43 private static final EELFLogger log = EELFManager.getInstance().getLogger(CompareXmlData.class);
51 public CompareXmlData(String controlXml, String testXml) {
53 this.controlXml = controlXml;
54 this.testXml = testXml;
58 public boolean compare() throws Exception
61 log.debug("controlXml : " + controlXml);
62 log.debug("testXml : " + testXml);
68 Diff diff = new Diff(getCompareDoc(controlXml), getCompareDoc(testXml));
74 catch(SAXException se)
77 throw new Exception(se.getMessage());
82 throw new Exception(e.getMessage());
86 private void doSetup() throws ParserConfigurationException, SAXException, IOException
89 XMLUnit.setIgnoreAttributeOrder(true);
90 XMLUnit.setIgnoreComments(true);
91 XMLUnit.setIgnoreWhitespace(true);
94 public Document getCompareDoc(String inXml) throws ParserConfigurationException, SAXException, IOException
96 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
97 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
98 StringReader reader = new StringReader(inXml);
99 InputSource inputSource = new InputSource(reader);
100 Document doc = dBuilder.parse(inputSource);
101 doc.getDocumentElement().normalize();