Skip to content

Commit

Permalink
Added tests for Conformance Declaration and Landing Page
Browse files Browse the repository at this point in the history
  • Loading branch information
ghobona committed Nov 19, 2020
1 parent 493b64a commit ac31e9c
Show file tree
Hide file tree
Showing 35 changed files with 1,915 additions and 1,255 deletions.
43 changes: 43 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/javadoc">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ets-ogcapi-processes10</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
7 changes: 7 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/javadoc=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
8 changes: 8 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.reprezen.kaizen</groupId>
<artifactId>openapi-parser</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -73,6 +88,18 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>net.jadler</groupId>
<artifactId>jadler-core</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jadler</groupId>
<artifactId>jadler-jetty</artifactId>
<version>1.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;

import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import io.restassured.specification.RequestSpecification;

import static io.restassured.RestAssured.given;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.util.Map;
import javax.ws.rs.core.MediaType;
import org.opengis.cite.ogcapiprocesses10.util.ClientUtils;
import org.opengis.cite.ogcapiprocesses10.SuiteAttribute;
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
Expand All @@ -19,6 +29,16 @@
*/
public class CommonFixture {


protected RequestLoggingFilter requestLoggingFilter;

protected ResponseLoggingFilter responseLoggingFilter;

private ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream();

private ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream();


/**
* Root test suite package (absolute path).
*/
Expand All @@ -35,6 +55,9 @@ public class CommonFixture {
* An HTTP response message.
*/
protected ClientResponse response;


protected URI rootUri;

/**
* Initializes the common test fixture with a client component for
Expand All @@ -45,16 +68,15 @@ public class CommonFixture {
*/
@BeforeClass
public void initCommonFixture(ITestContext testContext) {
Object obj = testContext.getSuite().getAttribute(SuiteAttribute.CLIENT.getName());
if (null != obj) {
this.client = Client.class.cast(obj);
}
obj = testContext.getSuite().getAttribute(SuiteAttribute.TEST_SUBJECT.getName());
if (null == obj) {
throw new SkipException("Test subject not found in ITestContext.");
}
initLogging();
rootUri = (URI) testContext.getSuite().getAttribute( SuiteAttribute.IUT.getName() );

}

protected RequestSpecification init() {
return given().filters( requestLoggingFilter, responseLoggingFilter ).log().all();
}

@BeforeMethod
public void clearMessages() {
this.request = null;
Expand Down Expand Up @@ -95,5 +117,25 @@ public ClientRequest buildGetRequest(URI endpoint,
Map<String, String> qryParams, MediaType... mediaTypes) {
return ClientUtils.buildGetRequest(endpoint, qryParams, mediaTypes);
}

/**
* Builds an HTTP request message that uses the GET method. This convenience method wraps a static method call to
* facilitate unit testing (Mockito workaround).
*
* @return A ClientRequest object.
*
* @see ClientUtils#buildGetRequest public ClientRequest buildGetRequest( URI endpoint, Map<String, String>
* qryParams, MediaType... mediaTypes ) { return ClientUtils.buildGetRequest( endpoint, qryParams, mediaTypes
* ); }
*/

private void initLogging() {
this.requestOutputStream = new ByteArrayOutputStream();
this.responseOutputStream = new ByteArrayOutputStream();
PrintStream requestPrintStream = new PrintStream( requestOutputStream, true );
PrintStream responsePrintStream = new PrintStream( responseOutputStream, true );
requestLoggingFilter = new RequestLoggingFilter( requestPrintStream );
responseLoggingFilter = new ResponseLoggingFilter( responsePrintStream );
}

}
53 changes: 18 additions & 35 deletions src/main/java/org/opengis/cite/ogcapiprocesses10/ETSAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,41 +170,24 @@ public static void assertDescendantElementCount(Document xmlEntity, QName elemen
}

/**
* Asserts that the given response message contains an OGC exception report.
* The message body must contain an XML document that has a document element
* with the following properties:
*
* <ul>
* <li>[local name] = "ExceptionReport"</li>
* <li>[namespace name] = "http://www.opengis.net/ows/2.0"</li>
* </ul>
*
* @param rsp
* A ClientResponse object representing an HTTP response message.
* @param exceptionCode
* The expected OGC exception code.
* @param locator
* A case-insensitive string value expected to occur in the
* locator attribute (e.g. a parameter name); the attribute value
* will be ignored if the argument is null or empty.
* @param valueToAssert
* the boolean to assert to be <code>true</code>
* @param failureMsg
* the message to throw in case of a failure, should not be <code>null</code>
*/
public static void assertExceptionReport(ClientResponse rsp, String exceptionCode, String locator) {
Assert.assertEquals(rsp.getStatus(), ClientResponse.Status.BAD_REQUEST.getStatusCode(),
ErrorMessage.get(ErrorMessageKeys.UNEXPECTED_STATUS));
Document doc = rsp.getEntity(Document.class);
String expr = String.format("//ows:Exception[@exceptionCode = '%s']", exceptionCode);
NodeList nodeList = null;
try {
nodeList = XMLUtils.evaluateXPath(doc, expr, null);
} catch (XPathExpressionException xpe) {
// won't happen
}
Assert.assertTrue(nodeList.getLength() > 0, "Exception not found in response: " + expr);
if (null != locator && !locator.isEmpty()) {
Element exception = (Element) nodeList.item(0);
String locatorValue = exception.getAttribute("locator").toLowerCase();
Assert.assertTrue(locatorValue.contains(locator.toLowerCase()),
String.format("Expected locator attribute to contain '%s']", locator));
}
public static void assertTrue( boolean valueToAssert, String failureMsg ) {
if ( !valueToAssert )
throw new AssertionError( failureMsg );
}

/**
* @param valueToAssert
* the boolean to assert to be <code>false</code>
* @param failureMsg
* the message to throw in case of a failure, should not be <code>null</code>
*/
public static void assertFalse( boolean valueToAssert, String failureMsg ) {
if ( valueToAssert )
throw new AssertionError( failureMsg );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.opengis.cite.ogcapiprocesses10;

/**
* Contains various constants pertaining to WFS 3.0 specification and related standards.
*
* @author <a href="mailto:[email protected]">Lyn Goltz </a>
*/
public class OgcApiProcesses10 {

private OgcApiProcesses10() {
}

public static final String OPEN_API_MIME_TYPE = "application/vnd.oai.openapi+json;version=3.0";

public static final String GEOJSON_MIME_TYPE = "application/geo+json";

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.opengis.cite.ogcapiprocesses10;

import com.reprezen.kaizen.oasparser.model3.OpenApi3;
import com.sun.jersey.api.client.Client;

import java.io.File;
import java.net.URI;
import java.util.List;
import java.util.Map;

import org.w3c.dom.Document;

Expand All @@ -16,19 +20,53 @@ public enum SuiteAttribute {
/**
* A client component for interacting with HTTP endpoints.
*/
CLIENT("httpClient", Client.class),
CLIENT( "httpClient", Client.class ),

/**
* The root URL.
*/
IUT( "instanceUnderTest", URI.class ),

/**
* A DOM Document that represents the test subject or metadata about it.
* A File containing the test subject or a description of it.
*/
TEST_SUBJECT("testSubject", Document.class),
TEST_SUBJ_FILE( "testSubjectFile", File.class ),

/**
* A File containing the test subject or a description of it.
*/
TEST_SUBJ_FILE("testSubjectFile", File.class);
TEST_SUBJECT( "testSubject", File.class ),

/**
* The number of collections to test.
*/
NO_OF_COLLECTIONS( "noOfCollections", Integer.class ),

/**
* Parsed OpenApi3 document resource /api; Added during execution.
*/
API_MODEL( "apiModel", OpenApi3.class ),

/**
* Requirement classes parsed from /conformance; Added during execution.
*/
REQUIREMENTCLASSES( "requirementclasses", List.class ),

/**
* Parsed collections from resource /collections; Added during execution.
*/
COLLECTIONS( "collections", List.class ),

/**
* Collection names assigned to a feature id parsed from resource /collections/{name}/items; Added during execution.
*/
FEATUREIDS( "featureIds", Map.class );

private final Class attrType;

private final String attrName;

private SuiteAttribute(String attrName, Class attrType) {
SuiteAttribute( String attrName, Class attrType ) {
this.attrName = attrName;
this.attrType = attrType;
}
Expand All @@ -43,8 +81,8 @@ public String getName() {

@Override
public String toString() {
StringBuilder sb = new StringBuilder(attrName);
sb.append('(').append(attrType.getName()).append(')');
StringBuilder sb = new StringBuilder( attrName );
sb.append( '(' ).append( attrType.getName() ).append( ')' );
return sb.toString();
}
}
Loading

0 comments on commit ac31e9c

Please sign in to comment.