Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package nz.ac.auckland.morc;
import au.com.bytecode.opencsv.CSVReader;
import groovy.text.GStringTemplateEngine;
import groovy.text.TemplateEngine;
import nz.ac.auckland.morc.processor.MatchedResponseProcessor;
import nz.ac.auckland.morc.processor.SelectorProcessor;
import nz.ac.auckland.morc.resource.*;
import nz.ac.auckland.morc.utility.XmlUtilities;
import org.apache.camel.Exchange;
import org.apache.camel.Predicate;
import org.apache.camel.Processor;
import org.apache.camel.builder.SimpleBuilder;
import org.apache.camel.builder.xml.XPathBuilder;
import org.apache.camel.jsonpath.JsonPathExpression;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URL;
import java.util.*;
public interface MorcMethods {
XmlUtilities xmlUtilities = new XmlUtilities();
default XmlUtilities getXmlUtilities() {
return xmlUtilities;
}
default QName soapFaultClient() {
return qname("http://schemas.xmlsoap.org/soap/envelope/", "Client");
}
default QName soapFaultServer() {
return qname("http://schemas.xmlsoap.org/soap/envelope/", "Server");
}
/**
* @param data An XML string which will be used for seeding a message, or comparing a value
*/
default XmlTestResource xml(String data) {
return new XmlTestResource(getXmlUtilities().getXmlAsDocument(data), getXmlUtilities());
}
/**
* @param file A file containing an XML document
*/
default XmlTestResource xml(File file) {
return new XmlTestResource(file, getXmlUtilities());
}
/**
* @param url A url pointing to an XML document
*/
default XmlTestResource xml(URL url) {
return new XmlTestResource(url, getXmlUtilities());
}
default XmlTestResource[] xml(final InputStream... inputs) {
XmlTestResource[] resources = new XmlTestResource[inputs.length];
for (int i = 0; i < inputs.length; i++) {
resources[i] = new XmlTestResource(inputs[i], getXmlUtilities());
}
return resources;
}
/**
* @param data A JSON string which will be used for seeding a message, or comparing a value
*/
default JsonTestResource json(String data) {
return new JsonTestResource(data);
}
/**
* @param file A file containing a JSON document
*/
default JsonTestResource json(File file) {
return new JsonTestResource(file);
}
/**
* @param url A url pointing to a JSON document
*/
default JsonTestResource json(URL url) {
return new JsonTestResource(url);
}
default JsonTestResource[] json(final InputStream... inputs) {
JsonTestResource[] resources = new JsonTestResource[inputs.length];
for (int i = 0; i < inputs.length; i++) {
resources[i] = new JsonTestResource(inputs[i]);
}
return resources;
}
/**
* @param data A standard Java string which will be used for seeding a message, or comparing a value
*/
@SuppressWarnings("unchecked")
default PlainTextTestResource text(String data) {
return new PlainTextTestResource(data);
}
/**
* @param file A file containing plain text
*/
@SuppressWarnings("unchecked")
default PlainTextTestResource text(File file) {
return new PlainTextTestResource(file);
}
/**
* @param url A url pointing to a plain text document
*/
@SuppressWarnings("unchecked")
default PlainTextTestResource text(URL url) {
return new PlainTextTestResource(url);
}
default PlainTextTestResource[] text(final InputStream... inputs) {
PlainTextTestResource[] resources = new PlainTextTestResource[inputs.length];
for (int i = 0; i < inputs.length; i++) {
resources[i] = new PlainTextTestResource(inputs[i]);
}
return resources;
}
default ContentTypeTestResource contentType(String contentType) {
return new ContentTypeTestResource(contentType);
}
/**
* @param data A map of headers and corresponding data that will be used for seeding a message, or comparing an expected value
*/
default HeadersTestResource headers(Map data) {
return new HeadersTestResource(data);
}
/**
* @param file A Java Properties file containing header=value values
*/
default HeadersTestResource headers(File file) {
return new HeadersTestResource(file);
}
/**
* @param url A pointer to a Java Properties resource containing header=value values
*/
default HeadersTestResource headers(URL url) {
return new HeadersTestResource(url);
}
/**
* @param inputs An InputStream reference to a headers (name=value pairs) resource
*/
default HeadersTestResource[] headers(final InputStream[] inputs) {
HeadersTestResource[] resources = new HeadersTestResource[inputs.length];
for (int i = 0; i < inputs.length; i++) {
resources[i] = new HeadersTestResource(inputs[i]);
}
return resources;
}
/**
* @param header A header to add to an outgoing or expected message
* @param value The value that should be assigned to this header
*/
default HeaderValue header(String header, Object value) {
return new HeaderValue(header, value);
}
/**
* @param headers A vararg list of headers which can be added to with the header(string,value) function
*/
default HeadersTestResource headers(HeaderValue... headers) {
Map headersMap = new HashMap<>();
for (HeaderValue header : headers) {
headersMap.put(header.header, header.value);
}
return headers(headersMap);
}
/**
* @param faultCode The fault code to use for the SOAP Fault
* @param message The message to use in the SOAP Fault
*/
default SoapFaultTestResource soapFault(QName faultCode, String message) {
return new SoapFaultTestResource(faultCode, message);
}
/**
* @param faultCode The fault code to use for the SOAP Fault
* @param message The message to use in the SOAP Fault
* @param xmlDetail The XML detail to use in the SOAP Fault
*/
default SoapFaultTestResource soapFault(QName faultCode, String message, XmlTestResource xmlDetail) {
return new SoapFaultTestResource(faultCode, message, xmlDetail);
}
/**
* @return A resource for ensuring an exception occurs, or return back to the client -- will simply use a standard Java Exception instance
*/
default ExceptionTestResource exception() {
return new ExceptionTestResource();
}
/**
* @param exception The exception we expect to validate against or return to caller
* @return A validator for ensuring an exception occurs
*/
default ExceptionTestResource exception(Exception exception) {
return new ExceptionTestResource(exception);
}
/**
* @param path A path to a resource on the current classpath
*/
default URL classpath(String path) {
URL resource = MorcTest.class.getResource(path);
if (resource == null) throw new RuntimeException("The classpath resource could not be found: " + path);
return resource;
}
/**
* @param path A path to a file
*/
default File file(String path) {
return new File(path);
}
/**
* A convenience method for specifying matched input to output answers for expectations
*/
@SuppressWarnings("unchecked")
default MatchedResponseProcessor matchedResponse(MatchedResponseProcessor.MatchedResponse... responses) {
return new MatchedResponseProcessor(responses);
}
/**
* A convenience method for specifying matched input validators to an output processor
*/
@SuppressWarnings("unchecked")
default MatchedResponseProcessor.MatchedResponse answer(Predicate predicate, Processor... processors) {
try {
return new MatchedResponseProcessor.MatchedResponse(predicate, processors);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* A way of paramaterizing resources so that values are updated according to Groovy GStrings
*
* @param template A template of the string resource containing GString variables for substitution
* @param dataSource A list of name=value pairs that will be used for var substitution. Each entry in the
* list will result in another resource being returned
*/
default GroovyTemplateTestResource[] groovy(TestResource template, List