-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invoke test suite using REST API interface. #33
- Loading branch information
Keshav Nangare
committed
Sep 10, 2019
1 parent
5513782
commit 634f729
Showing
12 changed files
with
529 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
127
src/main/java/org/opengis/cite/csw20/CtlController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
85
src/main/java/org/opengis/cite/csw20/TestRunArguments.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.