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

Nested expand #32

Open
wants to merge 6 commits 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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ets-sta10</artifactId>
<version>0.8-SNAPSHOT</version>
<version>1.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>SensorThings API (STA)</name>
Expand Down Expand Up @@ -76,7 +76,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<version>20171018</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Buffers the (response) entity so it can be read multiple times.
* <p>
* <p><strong>WARNING:</strong> The entity InputStream must be reset after each
* <strong>WARNING:</strong> The entity InputStream must be reset after each
* read attempt.</p>
*/
public class ReusableEntityFilter extends ClientFilter {
Expand Down
107 changes: 28 additions & 79 deletions src/main/java/org/opengis/cite/sta10/SuiteFixtureListener.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.opengis.cite.sta10;

import com.sun.jersey.api.client.Client;

import java.io.*;
import java.net.*;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -46,9 +44,8 @@ public void onFinish(ISuite suite) {
* entity referenced by the {@link TestRunArg#IUT iut} argument is parsed
* and the resulting Document is set as the value of the "testSubject"
* attribute.
*
* @param suite
* An ISuite object representing a TestNG test suite.
*
* @param suite An ISuite object representing a TestNG test suite.
*/
void processSuiteParameters(ISuite suite) {
Map<String, String> params = suite.getXmlSuite().getParameters();
Expand All @@ -67,7 +64,7 @@ void processSuiteParameters(ISuite suite) {
String iutParam = params.get(TestRunArg.IUT.toString());

String response = checkServiceRootUri(iutParam);
if(!response.equals("")){
if (!response.equals("")) {
throw new IllegalArgumentException(
response);
}
Expand All @@ -76,7 +73,7 @@ void processSuiteParameters(ISuite suite) {
StringBuilder logMsg = new StringBuilder(
"Parsed resource retrieved from ");
logMsg.append(TestRunArg.IUT).append("\n");
// logMsg.append(XMLUtils.writeNodeToString(iutDoc));
// logMsg.append(XMLUtils.writeNodeToString(iutDoc));
TestSuiteLogger.log(Level.FINE, logMsg.toString());
}
}
Expand All @@ -97,13 +94,16 @@ void registerClientComponent(ISuite suite) {

/**
* Checking the service root URL to be compliant with SensorThings API
*
* @param rootUri The root URL for the service under test
* @return If the root URL of the service is not compliant to SensorThings API, it will return the reason it is not compliant. Otherwise it returns empty String.
* @return If the root URL of the service is not compliant to SensorThings
* API, it will return the reason it is not compliant. Otherwise it returns
* empty String.
*/
private String checkServiceRootUri(String rootUri) {
rootUri = rootUri.trim();
if(rootUri.lastIndexOf('/')==rootUri.length()-1){
rootUri = rootUri.substring(0,rootUri.length()-1);
if (rootUri.lastIndexOf('/') == rootUri.length() - 1) {
rootUri = rootUri.substring(0, rootUri.length() - 1);
}
HttpURLConnection connection = null;
String response = null;
Expand All @@ -112,7 +112,7 @@ private String checkServiceRootUri(String rootUri) {
try {
url = new URL(rootUri);

connection = (HttpURLConnection) url.openConnection();
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type",
"application/json");
Expand All @@ -133,13 +133,13 @@ private String checkServiceRootUri(String rootUri) {
rd.close();
} catch (MalformedURLException e) {
e.printStackTrace();
return "Cannot connect to "+rootUri+".";
return "Cannot connect to " + rootUri + ".";
} catch (ProtocolException e) {
e.printStackTrace();
return "Cannot connect to "+rootUri+".";
return "Cannot connect to " + rootUri + ".";
} catch (IOException e) {
e.printStackTrace();
return "Cannot connect to "+rootUri+".";
return "Cannot connect to " + rootUri + ".";
}
JSONObject jsonResponse = null;
JSONArray entities = null;
Expand All @@ -148,13 +148,14 @@ private String checkServiceRootUri(String rootUri) {
entities = jsonResponse.getJSONArray("value");
} catch (JSONException e) {
e.printStackTrace();
return "The service response for the root URI \""+rootUri+"\" is not JSON.";
return "The service response for the root URI \"" + rootUri + "\" is not JSON.";
}
Map<String, Boolean> addedLinks = new HashMap<>();
addedLinks.put("Things", false);
addedLinks.put("Locations", false);
addedLinks.put("HistoricalLocations", false);
addedLinks.put("Datastreams", false);
addedLinks.put("MultiDatastreams", true);
addedLinks.put("Sensors", false);
addedLinks.put("Observations", false);
addedLinks.put("ObservedProperties", false);
Expand All @@ -164,82 +165,30 @@ private String checkServiceRootUri(String rootUri) {
String name, nameUrl;
try {
entity = entities.getJSONObject(i);
if(entity.get("name") == null){
if (entity.get("name") == null) {
return "The name component of Service root URI response is not available.";
}
if(entity.get("url") == null){
if (entity.get("url") == null) {
return "The name component of Service root URI response is not available.";
}
name = entity.getString("name");
nameUrl = entity.getString("url");
} catch (JSONException e) {
e.printStackTrace();
return "The service response for the root URI \""+rootUri+"\" is not JSON.";
return "The service response for the root URI \"" + rootUri + "\" is not JSON.";
}
switch (name) {
case "Things":
if(!nameUrl.equals(rootUri + "/Things") ){
return "The URL for Things in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.remove("Things");
addedLinks.put(name, true);
break;
case "Locations":
if(!nameUrl.equals(rootUri + "/Locations")) {
return "The URL for Locations in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.remove("Locations");
addedLinks.put(name, true);
break;
case "HistoricalLocations":
if(!nameUrl.equals(rootUri + "/HistoricalLocations")) {
return "The URL for HistoricalLocations in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.remove("HistoricalLocations");
addedLinks.put(name, true);
break;
case "Datastreams":
if(!nameUrl.equals(rootUri + "/Datastreams")) {
return "The URL for Datastreams in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.remove("Datastreams");
addedLinks.put(name, true);
break;
case "Sensors":
if(!nameUrl.equals(rootUri + "/Sensors")) {
return "The URL for Sensors in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.remove("Sensors");
addedLinks.put(name, true);
break;
case "Observations":
if(!nameUrl.equals(rootUri + "/Observations")) {
return "The URL for Observations in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.remove("Observations");
addedLinks.put(name, true);
break;
case "ObservedProperties":
if(!nameUrl.equals(rootUri + "/ObservedProperties")) {
return "The URL for ObservedProperties in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.remove("ObservedProperties");
addedLinks.put(name, true);
break;
case "FeaturesOfInterest":
if(!nameUrl.equals(rootUri + "/FeaturesOfInterest")) {
return "The URL for FeaturesOfInterest in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.remove("FeaturesOfInterest");
addedLinks.put(name, true);
break;
default:
return "There is a component in Service Root URI response that is not in SensorThings API : " + name;
if (addedLinks.containsKey(name)) {
if (!nameUrl.equals(rootUri + "/" + name)) {
return "The URL for " + name + " in Service Root URI is not compliant to SensorThings API.";
}
addedLinks.put(name, true);
} else {
return "There is a component in Service Root URI response that is not in SensorThings API : " + name;
}
}
for (String key : addedLinks.keySet()) {
if(addedLinks.get(key) == false){
return "The Service Root URI response does not contain ";
if (addedLinks.get(key) == false) {
return "The Service Root URI response does not contain ";
}
}
return "";
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/opengis/cite/sta10/TestRunListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* A listener that is invoked before and after a test run. It is often used to
* configure a shared fixture that endures for the duration of the entire test
* run. A FixtureManager may be used to manage such a fixture.
*
* <p>
* <p>A shared fixture should be used with caution in order to avoid undesirable
* A shared fixture should be used with caution in order to avoid undesirable
* test interactions. In general, it should be populated with "read-only"
* objects that are not modified during the test run.</p>
*
Expand Down
Loading