Skip to content

Commit

Permalink
Add core conformance classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bpross-52n committed Sep 14, 2021
1 parent 6cccf78 commit ee75152
Show file tree
Hide file tree
Showing 13 changed files with 1,619 additions and 34 deletions.
30 changes: 26 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>org.opengis.cite</groupId>
<artifactId>ets-ogcapi-processes10</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
Expand Down Expand Up @@ -89,6 +88,11 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.openapi4j</groupId>
<artifactId>openapi-operation-validator</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>net.jadler</groupId>
<artifactId>jadler-core</artifactId>
Expand Down Expand Up @@ -159,7 +163,6 @@
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<tagNameFormat>@{project.version}</tagNameFormat>
Expand All @@ -169,7 +172,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
<executions>
<execution>
<id>site-package</id>
Expand Down Expand Up @@ -211,7 +213,7 @@
<configuration>
<images>
<image>
<name>ogccite/${project.artifactId}</name>
<name>ogccite/${project.artifactId}:latest</name>
<build>
<dockerFileDir>${project.basedir}/src/docker</dockerFileDir>
<tags>
Expand All @@ -234,6 +236,7 @@
</assembly>
</build>
<run>
<!-- <containerNamePattern>%a</containerNamePattern> -->
<ports>
<port>8081:8080</port>
</ports>
Expand Down Expand Up @@ -335,6 +338,25 @@
</plugins>
</build>
</profile>
<profile>
<id>docker-remove</id>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<executions>
<execution>
<id>remove</id>
<goals>
<goal>remove</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<build>
Expand Down
5 changes: 3 additions & 2 deletions src/main/config/test-run-props.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties version="1.0">
<comment>Sample test run arguments (ets-ogcapi-processes10)</comment>
<entry key="iut">https://www.ldproxy.nrw.de/rest/services/kataster/</entry>
<entry key="noofcollections">3</entry>
<entry key="iut">http://tb17.geolabs.fr:8101/ogc-api</entry>
<!-- <entry key="iut">http://geoprocessing.demo.52north.org:8080/javaps/rest/</entry> -->
<entry key="echoprocessid">echo</entry>
</properties>
215 changes: 215 additions & 0 deletions src/main/java/org/opengis/cite/ogcapiprocesses10/CommonFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.openapi4j.core.validation.ValidationResults;
import org.openapi4j.core.validation.ValidationResults.ValidationItem;
import org.openapi4j.parser.model.v3.OpenApi3;
import org.openapi4j.parser.model.v3.Server;
import org.opengis.cite.ogcapiprocesses10.util.ClientUtils;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;

import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import io.restassured.specification.RequestSpecification;
Expand All @@ -28,8 +40,12 @@ public class CommonFixture {
protected RequestLoggingFilter requestLoggingFilter;

protected ResponseLoggingFilter responseLoggingFilter;

protected URI specURI;

protected URI rootUri;

protected final String CONTENT_TYPE = "Content-Type";

/**
* Initializes the common test fixture with a client component for interacting with HTTP endpoints.
Expand All @@ -41,6 +57,11 @@ public class CommonFixture {
public void initCommonFixture( ITestContext testContext ) {
initLogging();
rootUri = (URI) testContext.getSuite().getAttribute( SuiteAttribute.IUT.getName() );
try {
specURI = new URI("https://raw.githubusercontent.com/opengeospatial/ogcapi-processes/master/openapi.yaml");
} catch (URISyntaxException e) {
e.printStackTrace();
}
}

@BeforeMethod
Expand Down Expand Up @@ -93,5 +114,199 @@ private void initLogging() {
requestLoggingFilter = new RequestLoggingFilter( requestPrintStream );
responseLoggingFilter = new ResponseLoggingFilter( responsePrintStream );
}

protected String printResults(ValidationResults validationResults) {

List<ValidationItem> validationItems = validationResults.items();

StringBuilder printedResultsStringBuilder = new StringBuilder();

for (ValidationItem validationItem : validationItems) {
printedResultsStringBuilder.append(validationItem + "\n");
}

return printedResultsStringBuilder.toString();
}

protected void addServerUnderTest(OpenApi3 openApi3) {
Server serverUnderTest = new Server();
String authority = rootUri.getAuthority();
String scheme = rootUri.getScheme();
serverUnderTest.setUrl(scheme + "://" + authority);
openApi3.addServer(serverUnderTest);
}

protected Input createInput(JsonNode schemaNode, String id) {
Input input = new Input(id);
JsonNode typeNode = schemaNode.get("type");
if(typeNode != null) {
String typeDefinition = typeNode.asText();
Type type = new Type(typeDefinition);
if(typeDefinition.equals("object")) {
JsonNode propertiesNode = schemaNode.get("properties");
if(propertiesNode != null) {
Iterator<String> propertyNames = propertiesNode.fieldNames();
while (propertyNames.hasNext()) {
String propertyName = (String) propertyNames.next();
if(propertyName.equals("bbox")) {
input.setBbox(true);
break;
}
}
}
} else if(typeDefinition.equals("string")) {
JsonNode formatNode = schemaNode.get("format");
if(formatNode != null) {
String format = formatNode.asText();
if(format.equals("byte")) {
type.setBinary(true);
}
}

}
input.addType(type);
}else {
//oneOf, allOf, anyOf
JsonNode oneOfNode = schemaNode.get("oneOf");
if(oneOfNode != null) {
if(oneOfNode instanceof ArrayNode) {
ArrayNode oneOfArrayNode = (ArrayNode)oneOfNode;
for (int i = 0; i < oneOfArrayNode.size(); i++) {
JsonNode oneOfChildNode = oneOfArrayNode.get(i);
JsonNode oneOfTypeNode = oneOfChildNode.get("type");
if(oneOfTypeNode != null) {
String typeDefinition = oneOfTypeNode.asText();
Type type = new Type(typeDefinition);
if(typeDefinition.equals("object")) {
JsonNode propertiesNode = oneOfChildNode.get("properties");
if(propertiesNode != null) {
Iterator<String> propertyNames = propertiesNode.fieldNames();
while (propertyNames.hasNext()) {
String propertyName = (String) propertyNames.next();
if(propertyName.equals("bbox")) {
input.setBbox(true);
break;
}
}
}
} else if(typeDefinition.equals("string")) {
JsonNode formatNode = oneOfChildNode.get("format");
if(formatNode != null) {
String format = formatNode.asText();
if(format.equals("byte")) {
type.setBinary(true);
}
}

}
input.addType(type);
}
}
}
}
}
return input;
}

class Type {

private String typeDefinition;
private String contentEncoding;
private String contentMediaType;
private boolean isBinary;

public Type(String typeDefinition) {
this.typeDefinition = typeDefinition;
}
public boolean isBinary() {
return isBinary;
}

public void setBinary(boolean isBinary) {
this.isBinary = isBinary;
}

public String getContentEncoding() {
return contentEncoding;
}

public void setContentEncoding(String contentEncoding) {
this.contentEncoding = contentEncoding;
}

public String getContentMediaType() {
return contentMediaType;
}

public void setContentMediaType(String contentMediaType) {
this.contentMediaType = contentMediaType;
}

public String getTypeDefinition() {
return typeDefinition;
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("\tType definition: " + typeDefinition + "\n");
builder.append("\tContent Encoding: " + contentEncoding + "\n");
builder.append("\tType Content MediaType: " + contentMediaType + "\n");
builder.append("\tIs binary: " + isBinary + "\n");
return builder.toString();
}
}

class Input {

private String id;
private List<Type> types;
private boolean isBbox;

public Input(String id, List<Type> types, boolean isBbox) {
this.id = id;
this.types = types;
this.isBbox = isBbox;
}

public Input(String id, Type type) {
this(id, Arrays.asList(new Type[] {type}), false);
}

public Input(String id) {
this(id, new ArrayList<Type>(), false);
}

public boolean isBbox() {
return isBbox;
}

public void setBbox(boolean isBbox) {
this.isBbox = isBbox;
}

public String getId() {
return id;
}

public List<Type> getTypes() {
return types;
}

public boolean addType(Type type) {
return types.add(type);
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Id: " + id + "\n");
builder.append("\tType: " + types + "\n");
builder.append("\tIs bbox: " + isBbox);
return builder.toString();
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public enum SuiteAttribute {
* The number of collections to test.
*/
NO_OF_COLLECTIONS( "noOfCollections", Integer.class ),

/**
* The id of the echo process.
*/
ECHO_PROCESS_ID( "echoProcessId", String.class ),

/**
* Parsed OpenApi3 document resource /api; Added during execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,16 @@ void processSuiteParameters( ISuite suite ) {
TestSuiteLogger.log( Level.FINE, String.format( "Wrote test subject to file: %s (%d bytes)",
entityFile.getAbsolutePath(), entityFile.length() ) );
suite.setAttribute( SuiteAttribute.TEST_SUBJ_FILE.getName(), entityFile );

String noOfCollections = params.get( TestRunArg.NOOFCOLLECTIONS.toString() );
String echoProcessId = params.get( TestRunArg.ECHOPROCESSID.toString() );
try {
if ( noOfCollections != null ) {
int noOfCollectionsInt = Integer.parseInt( noOfCollections );
suite.setAttribute( SuiteAttribute.NO_OF_COLLECTIONS.getName(), noOfCollectionsInt );
}
if ( echoProcessId != null ) {
suite.setAttribute( SuiteAttribute.ECHO_PROCESS_ID.getName(), echoProcessId );
}
} catch ( NumberFormatException e ) {
TestSuiteLogger.log( Level.WARNING,
String.format( "Could not parse parameter %s: %s. Expected is a valid integer",
TestRunArg.NOOFCOLLECTIONS.toString(), noOfCollections ) );
TestSuiteLogger.log( Level.WARNING,
String.format( "Could not parse parameter %s: %s. Expected is a valid string",
TestRunArg.ECHOPROCESSID.toString(), echoProcessId ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ public enum TestRunArg {
/**
* The number of collections to test (a value less or equal to 0 means all collections).
*/
NOOFCOLLECTIONS;
NOOFCOLLECTIONS,

/**
* The id of the echo process.
*/
ECHOPROCESSID;

@Override
public String toString() {
Expand Down
Loading

0 comments on commit ee75152

Please sign in to comment.