org.mule.modules.sugarcrm.automation.unit.TransformerXmlToCxfTest.java Source code

Java tutorial

Introduction

Here is the source code for org.mule.modules.sugarcrm.automation.unit.TransformerXmlToCxfTest.java

Source

/**
 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
 *
 * The software in this package is published under the terms of the CPAL v1.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE.md file.
 */
package org.mule.modules.sugarcrm.automation.unit;

import org.mule.modules.sugarcrm.cxf.transformer.XmlToCxfTransformer;
import org.mule.util.IOUtils;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.junit.Assert;
import org.junit.Test;
import org.w3c.dom.Document;

public class TransformerXmlToCxfTest {

    @Test
    public void validTransformationXmlFromSugar() throws Exception {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setCoalescing(true);
        dbf.setIgnoringElementContentWhitespace(true);
        dbf.setIgnoringComments(true);
        DocumentBuilder db = dbf.newDocumentBuilder();

        String xml = IOUtils.getResourceAsString("response-searchByModule.xml", getClass());
        String xmlTransform = new XmlToCxfTransformer().transform(xml);

        Document doc1 = db.parse(org.apache.commons.io.IOUtils.toInputStream(xmlTransform));
        doc1.normalizeDocument();

        Document doc2 = db.parse(IOUtils.getResourceAsStream("response-searchByModule-ok.xml", getClass()));
        doc2.normalizeDocument();

        Assert.assertTrue(doc1.isEqualNode(doc2));
    }

}