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

Search schemaLocation along service file #602

Open
wants to merge 16 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -470,5 +470,11 @@
<TranslationTemplate language="en" name="TR.manual.GetSpatialDataSetIdentifier">The recommended identifier 'http://inspire.ec.europa.eu/operation/download/GetSpatialDataSet' should be used for serving pre-defined Spatial Data Sets.</TranslationTemplate>
</translationTemplates>
</LangTranslationTemplateCollection>

<LangTranslationTemplateCollection name="TR.XmlNotValidAgainstSchemaLocation">
<translationTemplates>
<TranslationTemplate language="en" name="TR.XmlNotValidAgainstSchemaLocation">The WFS is not valid against the '{xsd}' schema. Reason: '{reason}'</TranslationTemplate>
</translationTemplates>
</LangTranslationTemplateCollection>
</translationTemplateCollections>
</TranslationTemplateBundle>
97 changes: 95 additions & 2 deletions service/dis-csw-core-soapui-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1691,9 +1691,102 @@ if(defaultLanguage.size() != 1){
</con:settings>
<con:endpoint>${#Project#serviceEndpoint}</con:endpoint>
<con:request />
<con:assertion type="Simple Schema Validator" id="d487f7f6-3744-4a91-97ba-4b21b59c4161" name="Simple Schema Validator">
<con:assertion type="GroovyScriptAssertion" id="750c3343-c095-4488-aa17-1e78e5685f59" name="Response validates agains schema">
<con:configuration>
<pathToXSD>xsi:schemaLocation</pathToXSD>
<scriptText>import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator
import javax.xml.XMLConstants;
import java.io.*;
import org.xml.sax.SAXException;
import de.interactive_instruments.etf.suim.*;
import com.eviware.soapui.support.XmlHolder;
import javax.xml.transform.Source;
Assert a = new Assert(messageExchange, context, log, Assert.INSPIRE_DS_NS);

XmlHolder xml = new XmlHolder(messageExchange.responseContentAsXml);
def xmlText = xml.getXml();
def xsds = ["http://schemas.opengis.net/csw/2.0/csw.xsd", "http://inspire.ec.europa.eu/schemas/inspire_ds/1.0/inspire_ds.xsd"];

if(xml.getNodeValue("/*:GetRecords/@*:schemaLocation") != null){
xsds = xml.getNodeValue("/*:GetRecords/@*:schemaLocation");
def splittedXsds = xsds.split(" ");
validationProccess(xmlText, splittedXsds);
}else{
validationProccess(xmlText, xsds);
}

public void validationProccess(String xmlText, String[] xsds){
def errorMessages = [];
def isValid = false;
xsds.each{ xsd ->
errorMessages.add(hasValidSchema(xmlText, xsd))
}

for (i = 0; i &lt; errorMessages.size() ; i++){
if(isValid == false &amp;&amp; errorMessages[i] == "valid"){
isValid = true;
}
}

if(isValid == false){
xsds.each{ xsd ->
log.debug("xsd");
errorMessages.add(validateFile(xmlText, xsd))
}
}
}

public boolean validateFile(String xml, String strSchemaLocation) {
Source xmlFile = null;

try {
URL schemaFile = new URL(strSchemaLocation);
xmlFile = new StreamSource(createFile(xml));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);

} catch (SAXException e) {
String[] assertParams = ['xsd', strSchemaLocation, 'reason', e.getLocalizedMessage()];
throw new TranslatableAssertionError('TR.XmlNotValidAgainstSchemaLocation', assertParams);

} catch (IOException ioe) {
System.out.println("IOException");
}
}

public String hasValidSchema(String xml, String strSchemaLocation) {
Source xmlFile = null;

try {
URL schemaFile = new URL(strSchemaLocation);
xmlFile = new StreamSource(createFile(xml));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);
return "valid";

} catch (SAXException e) {
String[] assertParams = ['xsd', strSchemaLocation, 'reason', e.getLocalizedMessage()];
return "invalid";

} catch (IOException ioe) {
System.out.println("IOException");
return "invalid";
}
}

public File createFile(String file) throws IOException {
File tempFile = File.createTempFile("temporaryfile",".xml")
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write(file);
writer.close()
return tempFile;
}</scriptText>
</con:configuration>
</con:assertion>
<con:credentials>
Expand Down
97 changes: 95 additions & 2 deletions service/ds-sos-pre-defined-soapui-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,102 @@ else if(defaultLanguage.size() != 1){
</con:settings>
<con:endpoint>${#Project#serviceEndpoint}</con:endpoint>
<con:request />
<con:assertion type="Simple Schema Validator" id="5fdb4222-f0c7-44e8-99c3-8c635d1fa130" name="Simple Schema Validator">
<con:assertion type="GroovyScriptAssertion" id="84d12d11-591e-4a11-bc41-39061b0e1465" name="Response validates agains schema">
<con:configuration>
<pathToXSD>xsi:schemaLocation</pathToXSD>
<scriptText>import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator
import javax.xml.XMLConstants;
import java.io.*;
import org.xml.sax.SAXException;
import de.interactive_instruments.etf.suim.*;
import com.eviware.soapui.support.XmlHolder;
import javax.xml.transform.Source;
Assert a = new Assert(messageExchange, context, log, Assert.INSPIRE_DS_NS);

XmlHolder xml = new XmlHolder(messageExchange.responseContentAsXml);
def xmlText = xml.getXml();
def xsds = ["http://schemas.opengis.net/sos/2.0/sos.xsd", "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd"];

if(xml.getNodeValue("/*:ExtendedCapabilities/@*:schemaLocation") != null){
xsds = xml.getNodeValue("/*:ExtendedCapabilities/@*:schemaLocation");
def splittedXsds = xsds.split(" ");
validationProccess(xmlText, splittedXsds);
}else{
validationProccess(xmlText, xsds);
}

public void validationProccess(String xmlText, String[] xsds){
def errorMessages = [];
def isValid = false;
xsds.each{ xsd ->
errorMessages.add(hasValidSchema(xmlText, xsd))
}

for (i = 0; i &lt; errorMessages.size() ; i++){
if(isValid == false &amp;&amp; errorMessages[i] == "valid"){
isValid = true;
}
}

if(isValid == false){
xsds.each{ xsd ->
log.debug("xsd");
errorMessages.add(validateFile(xmlText, xsd))
}
}
}

public boolean validateFile(String xml, String strSchemaLocation) {
Source xmlFile = null;

try {
URL schemaFile = new URL(strSchemaLocation);
xmlFile = new StreamSource(createFile(xml));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);

} catch (SAXException e) {
String[] assertParams = ['xsd', strSchemaLocation, 'reason', e.getLocalizedMessage()];
throw new TranslatableAssertionError('TR.XmlNotValidAgainstSchemaLocation', assertParams);

} catch (IOException ioe) {
System.out.println("IOException");
}
}

public String hasValidSchema(String xml, String strSchemaLocation) {
Source xmlFile = null;

try {
URL schemaFile = new URL(strSchemaLocation);
xmlFile = new StreamSource(createFile(xml));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);
return "valid";

} catch (SAXException e) {
String[] assertParams = ['xsd', strSchemaLocation, 'reason', e.getLocalizedMessage()];
return "invalid";

} catch (IOException ioe) {
System.out.println("IOException");
return "invalid";
}
}

public File createFile(String file) throws IOException {
File tempFile = File.createTempFile("temporaryfile",".xml")
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write(file);
writer.close()
return tempFile;
}</scriptText>
</con:configuration>
</con:assertion>
<con:credentials>
Expand Down
97 changes: 95 additions & 2 deletions service/ds-wcs-core-soapui-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,102 @@ a.exists(
<codes>200</codes>
</con:configuration>
</con:assertion>
<con:assertion type="Simple Schema Validator" id="a7dc0611-bb10-4716-ac6a-f8ebe89333f7" name="Simple Schema Validator">
<con:assertion type="GroovyScriptAssertion" id="c931c076-f135-47a0-a43b-97a8d980c834" name="Response validates agains schema">
<con:configuration>
<pathToXSD>xsi:schemaLocation</pathToXSD>
<scriptText>import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Schema;
import javax.xml.validation.Validator
import javax.xml.XMLConstants;
import java.io.*;
import org.xml.sax.SAXException;
import de.interactive_instruments.etf.suim.*;
import com.eviware.soapui.support.XmlHolder;
import javax.xml.transform.Source;
Assert a = new Assert(messageExchange, context, log, Assert.INSPIRE_DS_NS);

XmlHolder xml = new XmlHolder(messageExchange.responseContentAsXml);
def xmlText = xml.getXml();
def xsds = ["http://schemas.opengis.net/wcs/2.1/gml/wcsAll.xsd", "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd"];

if(xml.getNodeValue("/*:GetCapabilities/@*:schemaLocation") != null){
xsds = xml.getNodeValue("/*:GetCapabilities/@*:schemaLocation");
def splittedXsds = xsds.split(" ");
validationProccess(xmlText, splittedXsds);
}else{
validationProccess(xmlText, xsds);
}

public void validationProccess(String xmlText, String[] xsds){
def errorMessages = [];
def isValid = false;
xsds.each{ xsd ->
errorMessages.add(hasValidSchema(xmlText, xsd))
}

for (i = 0; i &lt; errorMessages.size() ; i++){
if(isValid == false &amp;&amp; errorMessages[i] == "valid"){
isValid = true;
}
}

if(isValid == false){
xsds.each{ xsd ->
log.debug("xsd");
errorMessages.add(validateFile(xmlText, xsd))
}
}
}

public boolean validateFile(String xml, String strSchemaLocation) {
Source xmlFile = null;

try {
URL schemaFile = new URL(strSchemaLocation);
xmlFile = new StreamSource(createFile(xml));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);

} catch (SAXException e) {
String[] assertParams = ['xsd', strSchemaLocation, 'reason', e.getLocalizedMessage()];
throw new TranslatableAssertionError('TR.XmlNotValidAgainstSchemaLocation', assertParams);

} catch (IOException ioe) {
System.out.println("IOException");
}
}

public String hasValidSchema(String xml, String strSchemaLocation) {
Source xmlFile = null;

try {
URL schemaFile = new URL(strSchemaLocation);
xmlFile = new StreamSource(createFile(xml));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);
return "valid";

} catch (SAXException e) {
String[] assertParams = ['xsd', strSchemaLocation, 'reason', e.getLocalizedMessage()];
return "invalid";

} catch (IOException ioe) {
System.out.println("IOException");
return "invalid";
}
}

public File createFile(String file) throws IOException {
File tempFile = File.createTempFile("temporaryfile",".xml")
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write(file);
writer.close()
return tempFile;
}</scriptText>
</con:configuration>
</con:assertion>
<con:credentials>
Expand Down
Loading