Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added JUnit test for SoapParser. #467

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Document parse(URLConnection uc, Element instruction,
*
* @author Simone Gianfranceschi
*/
private Document parse(Object xml, Element instruction, PrintWriter logger)
public Document parse(Object xml, Element instruction, PrintWriter logger)
throws Exception {
Document soapMessage = null;
String returnType = instruction.getAttribute("return");// envelope or
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.occamlab.te.parsers;

import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;

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

import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class SoapParserTest {

private static DocumentBuilder docBuilder;

@BeforeClass
public static void initFixture() throws ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
docBuilder = dbf.newDocumentBuilder();
}

@Test
public void parseWithSchema() throws Exception {
Document schemaRefs = parseResourceDocument("/conf/soap-schema.xml");
Document doc = parseResourceDocument("/soap-response.xml");
StringWriter strWriter = new StringWriter();
PrintWriter logger = new PrintWriter(strWriter);
SoapParser iut = new SoapParser();
Document result = iut.parse(doc, schemaRefs.getDocumentElement(), logger);
assertNotNull(result);
}

/**
* Parses an XML Document from a classpath resource.
*
* @param resourcePath
* relative to the current class
* @return never null
*/
private Document parseResourceDocument(final String resourcePath)
throws SAXException, IOException {
final URL url = getClass().getResource(resourcePath);
final Document doc = docBuilder.parse(url.toString());
doc.setDocumentURI(url.toString());
return doc;
}
}
5 changes: 5 additions & 0 deletions teamengine-core/src/test/resources/conf/soap-schema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ctlp:SoapParser
xmlns:ctlp="http://www.occamlab.com/te/parsers" ignoreErrors="false"
ignoreWarnings="true" return="content">
</ctlp:SoapParser>
32 changes: 32 additions & 0 deletions teamengine-core/src/test/resources/soap-response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sos="http://www.opengis.net/sos/2.0"
xmlns:om="http://www.opengis.net/om/2.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="http://www.opengis.net/om/2.0 http://schemas.opengis.net/om/2.0/observation.xsd http://www.opengis.net/sos/2.0 http://schemas.opengis.net/sos/2.0/sosGetObservation.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gmlBase.xsd http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope">
<soap:Header />
<soap:Body>
<sos:GetObservationResponse>
<sos:observationData>
<om:OM_Observation gml:id="o_0D4447DFB5AFBEDEDE5CF243F25B47F69D1B7BE1">
<gml:description>test description for this observation</gml:description>
<gml:identifier codeSpace="http://www.opengis.net/def/nil/OGC/0/unknown">http:/www.tsuruoka-nct.ac.jp/test/observation/0</gml:identifier>
<om:type xlink:href="http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement" />
<om:phenomenonTime>
<gml:TimeInstant gml:id="phenomenonTime_430">
<gml:timePosition>2012-11-19T17:45:15.000Z</gml:timePosition>
</gml:TimeInstant>
</om:phenomenonTime>
<om:resultTime xlink:href="#phenomenonTime_430" />
<om:procedure xlink:href="http://www.tsuruoka-nct.ac.jp/test/procedure/0" />
<om:observedProperty xlink:href="http://www.tsuruoka-nct.ac.jp/test/observableProperty/Temperature" />
<om:featureOfInterest xlink:href="http://www.52north.org/test/featureOfInterest/9" />
<om:result xmlns:ns="http://www.opengis.net/gml/3.2" uom="test_unit_9_3" xsi:type="ns:MeasureType">0.28</om:result>
</om:OM_Observation>
</sos:observationData>
</sos:GetObservationResponse>
</soap:Body>
</soap:Envelope>