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

Invoke test suite using REST API interface. #34

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
50 changes: 35 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<artifactId>ets-csw20</artifactId>
<groupId>org.opengis.cite</groupId>
<version>1.19-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Conformance Test Suite - CSW 2.0.2</name>
<description>
Expand Down Expand Up @@ -54,7 +53,7 @@
<ets-code>csw</ets-code>
<spec-version>2.0.2</spec-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<teamengine.version>4.10</teamengine.version>
<teamengine.version>5.4</teamengine.version>
</properties>

<build>
Expand Down Expand Up @@ -94,13 +93,18 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-jar</id>
<phase>disable</phase>
</execution>
</executions>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
<Build-Revision>${buildNumber}</Build-Revision>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -155,7 +159,9 @@
</goals>
<configuration>
<descriptors>
<descriptor>src/assembly/ctl.xml</descriptor>
<descriptor>${basedir}/src/assembly/ctl.xml</descriptor>
<descriptor>${basedir}/src/assembly/aio.xml</descriptor>
<descriptor>${basedir}/src/assembly/deps.xml</descriptor>
</descriptors>
</configuration>
</execution>
Expand Down Expand Up @@ -188,10 +194,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<version>3.6.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -250,6 +256,21 @@
</plugin>
</plugins>

<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>${basedir}/src/main/scripts</directory>
<targetPath>${ets-code}/${spec-version}</targetPath>
</resource>
<resource>
<directory>src/main/javadoc</directory>
<filtering>true</filtering>
<targetPath>doc/${ets-code}/${project.version}</targetPath>
</resource>
</resources>
<testResources>
<testResource>
<directory>${basedir}/src/test/resources</directory>
Expand Down Expand Up @@ -280,9 +301,8 @@
<dependencies>
<dependency>
<groupId>org.opengis.cite.teamengine</groupId>
<artifactId>teamengine-core</artifactId>
<artifactId>teamengine-spi-ctl</artifactId>
<version>${teamengine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
20 changes: 20 additions & 0 deletions src/assembly/aio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3">
<!-- Generate all-in-one jar including dependencies -->
<id>aio</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
<excludes>
<exclude>com.sun.jersey:jersey-server</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
25 changes: 25 additions & 0 deletions src/assembly/deps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2
http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>deps</id>
<formats>
<format>zip</format>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<excludes>
<exclude>org.opengis.cite.teamengine:teamengine-spi-ctl</exclude>
</excludes>
<outputDirectory>/</outputDirectory>
<unpack>false</unpack>
<scope>runtime</scope>
<useTransitiveDependencies>true</useTransitiveDependencies>
<useTransitiveFiltering>true</useTransitiveFiltering>
</dependencySet>
</dependencySets>
</assembly>
17 changes: 17 additions & 0 deletions src/main/java/org/opengis/cite/csw20/CSW20.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.opengis.cite.csw20;

/**
* Contains various constants defined in the CSW 2.0.2 specification, such as test
* run parameters.
*
* @see "OGC 07-006r1: OGC Catalog Service for the Web Implementation Specification, Version 2.0.2"
*/
public class CSW20 {

private CSW20() {
}

/** Supplies reference to CSW capabilities document (URI). */
public static final String CAPABILITIES_URL = "capabilities.url";

}
127 changes: 127 additions & 0 deletions src/main/java/org/opengis/cite/csw20/CtlController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package org.opengis.cite.csw20;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

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

import org.w3c.dom.Document;

import com.occamlab.te.SetupOptions;
import com.occamlab.te.spi.ctl.CtlExecutor;
import com.occamlab.te.spi.executors.TestRunExecutor;
import com.occamlab.te.spi.jaxrs.TestSuiteController;

public class CtlController implements TestSuiteController {

private TestRunExecutor executor;
private Properties etsProperties = new Properties();

/**
* Constructs a controller object for this test suite. The location of the
* main CTL script is read from the "main-script" property in the
* ets.properties file (a classpath resource).
*/
public CtlController() {
SetupOptions setupOpts = new SetupOptions();
try (InputStream is = getClass().getResourceAsStream("ets.properties")) {
this.etsProperties.load(is);
String mainScriptPath = etsProperties.getProperty("main-script");
File ctlFile = findScriptFile(URI.create(mainScriptPath));
setupOpts.addSource(ctlFile);
this.executor = new CtlExecutor(setupOpts);
} catch (IOException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to initialize CtlController. {0}",
ex.getMessage());
}
}

/**
* A convenience method for running the test suite using a command-line
* interface.
*
* @param args
* Test run arguments (optional). The first argument must refer
* to a local XML properties file containing the expected set of
* test run arguments. If no argument is supplied, the file
* located at ${user.home}/test-run-props.xml will be used.
* @throws Exception
* If an error errors during the test run.
*/
public static void main(String[] args) throws Exception {
File propsFile;
if (args.length == 0) {
propsFile = new File(System.getProperty("user.home"), "test-run-props.xml");
} else {
String xmlProps = args[0];
propsFile = (xmlProps.startsWith("file:")) ? new File(URI.create(xmlProps)) : new File(xmlProps);
}
if (!propsFile.isFile()) {
throw new IllegalArgumentException("Test run arguments not found at " + propsFile);
}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document testRunArgs = db.parse(propsFile);
TestSuiteController controller = new CtlController();
Source results = controller.doTestRun(testRunArgs);
Logger.getLogger(CtlController.class.getName()).log(Level.INFO, "Test results: {0}", results.getSystemId());
}

public String getCode() {
return etsProperties.getProperty("ets-code");
}

public String getVersion() {
return etsProperties.getProperty("ets-version");
}

public String getTitle() {
return etsProperties.getProperty("ets-title");
}

public Source doTestRun(Document testRunArgs) throws Exception {
Properties validArgs = TestRunArguments.validateArguments(testRunArgs);

return executor.execute(TestRunArguments.propertiesAsDocument(validArgs));
}

/**
* Creates a File from the given URI reference. If the URI is not absolute,
* is is resolved against the location of the TE_BASE/scripts directory; if
* a file does not exist at this location the URI is assumed to be a
* classpath reference.
*
* @param uri
* An absolute or relative URI.
* @return A File object, or null if one could not be created.
*/
final File findScriptFile(URI uri) {
File ctlFile = null;
File baseDir = SetupOptions.getBaseConfigDirectory();
if (!uri.isAbsolute()) {
File scriptsDir = new File(baseDir, "scripts");
ctlFile = new File(scriptsDir, uri.getPath());
}
if (null == ctlFile || !ctlFile.isFile()) {
URL resource = getClass().getResource(uri.getPath());
try {
ctlFile = new File(resource.toURI());
} catch (URISyntaxException ex) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "Invalid URI: {0}", ex);
}
}
Logger.getLogger(getClass().getName()).log(Level.CONFIG, "Created File object: {0}", ctlFile);
return ctlFile;
}

}

85 changes: 85 additions & 0 deletions src/main/java/org/opengis/cite/csw20/TestRunArguments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.opengis.cite.csw20;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

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

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
* Provides utility methods that assist with the handling of test run arguments.
*/
public class TestRunArguments {

/**
* Validates the given test run arguments. An
* <code>IllegalArgumentException</code> is thrown if a required argument is
* missing or invalid. The recognized arguments are listed below.
* <ul>
* <li>{@value org.opengis.cite.csw20.CSW20#CAPABILITIES_URL}
* (required)</li>
* </ul>
*
* @param testRunArgs
* A Document containing a set of XML properties; each entry
* (key-value pair) is a test run argument.
* @return A valid set of test run arguments.
*/
public static Properties validateArguments(Document testRunArgs) {
NodeList entries = testRunArgs.getDocumentElement().getElementsByTagName("entry");
if (entries.getLength() == 0) {
throw new IllegalArgumentException("No test run arguments.");
}
// load defaults?
Properties args = new Properties();
for (int i = 0; i < entries.getLength(); i++) {
Element entry = (Element) entries.item(i);
args.setProperty(entry.getAttribute("key"), entry.getTextContent().trim());
}
String capabilitiesUrl = args.getProperty(CSW20.CAPABILITIES_URL);
try {
URI uriRef = new URI(capabilitiesUrl);
if (!uriRef.isAbsolute()) {
throw new IllegalArgumentException(String.format("Not an absolute URI: %s", uriRef));
}
} catch (URISyntaxException e1) {
throw new IllegalArgumentException(String.format("Invalid URI reference: %s", capabilitiesUrl));
} catch (NullPointerException e2) {
throw new IllegalArgumentException(String.format("Missing required argument: %s", CSW20.CAPABILITIES_URL));
}
return args;
}

/**
* Creates a document that contains a simple XML representation of the given
* set of properties.
*
* @param props
* A set of properties (key-value pairs).
* @return A Document node, wherein each property is represented by an
* entry[@key] element.
*/
public static Document propertiesAsDocument(Properties props) {
Document doc = null;
try {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
props.storeToXML(outStream, "Test run arguments");
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
doc = builder.parse(new ByteArrayInputStream(outStream.toByteArray()));
} catch (Exception e) { // very unlikely
Logger.getLogger(TestRunArguments.class.getName()).log(Level.WARNING, "Failed to create Document node. {0}",
e.getMessage());
}
return doc;
}

}
10 changes: 10 additions & 0 deletions src/main/javadoc/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="0; url=overview.html" />
<title />
</head>
<body>
</body>
</html>
Loading