Skip to content

Commit

Permalink
Bumped FROST-Client-Dynamic version
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Aug 15, 2024
1 parent a092e07 commit c601504
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsV11Sensing.EP_PHENOMENONTIME;
import static de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsV11Sensing.EP_TIME;
import static de.fraunhofer.iosb.ilt.frostclient.utils.ParserUtils.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.frostclient.utils.StringHelper.formatKeyValuesForUrl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -254,13 +254,13 @@ void test04PostInvalidPath() throws ServiceFailureException {

// PUT tests
String urlObsGood = serverSettings.getServiceUrl(version)
+ "/Things(" + formatKeyValuesForUrl(thing1.getPrimaryKeyValues()) + ")"
+ "/Datastreams(" + formatKeyValuesForUrl(datastream1.getPrimaryKeyValues()) + ")"
+ "/Observations(" + formatKeyValuesForUrl(obs1.getPrimaryKeyValues()) + ")";
+ "/Things(" + formatKeyValuesForUrl(thing1) + ")"
+ "/Datastreams(" + formatKeyValuesForUrl(datastream1) + ")"
+ "/Observations(" + formatKeyValuesForUrl(obs1) + ")";
String urlObsBad = serverSettings.getServiceUrl(version)
+ "/Things(" + formatKeyValuesForUrl(thing2.getPrimaryKeyValues()) + ")"
+ "/Datastreams(" + formatKeyValuesForUrl(datastream1.getPrimaryKeyValues()) + ")"
+ "/Observations(" + formatKeyValuesForUrl(obs1.getPrimaryKeyValues()) + ")";
+ "/Things(" + formatKeyValuesForUrl(thing2) + ")"
+ "/Datastreams(" + formatKeyValuesForUrl(datastream1) + ")"
+ "/Observations(" + formatKeyValuesForUrl(obs1) + ")";

testPut(urlObsGood, urlObsBad);
testPatch(urlObsGood, urlObsBad);
Expand All @@ -270,24 +270,24 @@ void test04PostInvalidPath() throws ServiceFailureException {
private void testGet(Entity thing1, Entity datastream1, Entity thing2) {
// GET tests
HTTPMethods.HttpResponse response;
String url = serverSettings.getServiceUrl(version) + "/Things(" + formatKeyValuesForUrl(thing1.getPrimaryKeyValues()) + ")/Datastreams(" + formatKeyValuesForUrl(datastream1.getPrimaryKeyValues()) + ")/Observations";
String url = serverSettings.getServiceUrl(version) + "/Things(" + formatKeyValuesForUrl(thing1) + ")/Datastreams(" + formatKeyValuesForUrl(datastream1) + ")/Observations";
response = HTTPMethods.doGet(url);
assertEquals(200, response.code, "Get should return 201 Created for url " + url);

url = serverSettings.getServiceUrl(version) + "/Things(" + formatKeyValuesForUrl(thing2.getPrimaryKeyValues()) + ")/Datastreams(" + formatKeyValuesForUrl(datastream1.getPrimaryKeyValues()) + ")/Observations";
url = serverSettings.getServiceUrl(version) + "/Things(" + formatKeyValuesForUrl(thing2) + ")/Datastreams(" + formatKeyValuesForUrl(datastream1) + ")/Observations";
response = HTTPMethods.doGet(url);
assertEquals(404, response.code, "Get should return 404 Not Found for url " + url);

// POST tests
url = serverSettings.getServiceUrl(version) + "/Things(" + formatKeyValuesForUrl(thing1.getPrimaryKeyValues()) + ")/Datastreams(" + formatKeyValuesForUrl(datastream1.getPrimaryKeyValues()) + ")/Observations";
url = serverSettings.getServiceUrl(version) + "/Things(" + formatKeyValuesForUrl(thing1) + ")/Datastreams(" + formatKeyValuesForUrl(datastream1) + ")/Observations";
String observationJson = "{\n"
+ " \"phenomenonTime\": \"2015-03-01T03:00:00.000Z\",\n"
+ " \"result\": 300\n"
+ "}";
response = HTTPMethods.doPost(url, observationJson);
assertEquals(201, response.code, "Post should return 201 Created for url " + url);

url = serverSettings.getServiceUrl(version) + "/Things(" + formatKeyValuesForUrl(thing2.getPrimaryKeyValues()) + ")/Datastreams(" + formatKeyValuesForUrl(datastream1.getPrimaryKeyValues()) + ")/Observations";
url = serverSettings.getServiceUrl(version) + "/Things(" + formatKeyValuesForUrl(thing2) + ")/Datastreams(" + formatKeyValuesForUrl(datastream1) + ")/Observations";
response = HTTPMethods.doPost(url, observationJson);
assertNotEquals(201, response.code, "Post should not return 201 Created for url " + url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ private void createEntitiesForDelete() {
String urlString = ServiceUrlHelper.buildURLString(serverSettings.getServiceUrl(version), EntityType.THING, null, null, null);
HttpResponse responseMap = HTTPMethods.doPost(urlString, urlParameters);
String response = responseMap.response;
THING_IDS.add(Utils.pkFromPostResult(response)[0]);
THING_IDS.add(Utils.pkFromPostResult(response).get(0));

urlString = ServiceUrlHelper.buildURLString(serverSettings.getServiceUrl(version), EntityType.THING, THING_IDS.get(0), EntityType.LOCATION, null);
responseMap = HTTPMethods.doGet(urlString);
Expand Down Expand Up @@ -1949,7 +1949,7 @@ private void createEntitiesForDelete() {
}""";
responseMap = HTTPMethods.doPost(urlString, urlParameters);
response = responseMap.response;
OBSERVATION_IDS.add(Utils.pkFromPostResult(response)[0]);
OBSERVATION_IDS.add(Utils.pkFromPostResult(response).get(0));

//FeatureOfInterest
urlString = ServiceUrlHelper.buildURLString(serverSettings.getServiceUrl(version), EntityType.OBSERVATION, OBSERVATION_IDS.get(0), EntityType.FEATURE_OF_INTEREST, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ private void checkPropertiesForFilter(String response, List<String> properties,
String sValue = (String) value;
value = sValue.substring(1, sValue.length() - 1);
if (!(propertyValue instanceof String)) {
propertyValue = propertyValue.toString();
propertyValue = String.valueOf(propertyValue);
}
} else if (value instanceof ZonedDateTime) {
propertyValue = ZonedDateTime.parse(propertyValue.toString());
Expand Down Expand Up @@ -1459,7 +1459,7 @@ private void checkPropertiesForFilter(String response, List<String> properties,
private static Object postAndGetId(String urlString, String postContent) {
HttpResponse responseMap = HTTPMethods.doPost(urlString, postContent);
String response = responseMap.response;
return Utils.pkFromPostResult(response)[0];
return Utils.pkFromPostResult(response).get(0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static de.fraunhofer.iosb.ilt.frostclient.models.CommonProperties.EP_PROPERTIES;
import static de.fraunhofer.iosb.ilt.frostclient.utils.CollectionsHelper.propertiesBuilder;
import static de.fraunhofer.iosb.ilt.frostclient.utils.ParserUtils.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.frostclient.utils.StringHelper.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.statests.util.EntityUtils.createDatastream;
import static de.fraunhofer.iosb.ilt.statests.util.EntityUtils.createObservationSet;
import static de.fraunhofer.iosb.ilt.statests.util.EntityUtils.createObservedProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsV11Sensing.EP_PARAMETERS;
import static de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsV11Sensing.EP_RESULTQUALITY;
import static de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsV11Sensing.EP_UNITOFMEASUREMENT;
import static de.fraunhofer.iosb.ilt.frostclient.utils.ParserUtils.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.frostclient.utils.StringHelper.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.statests.util.EntityUtils.testFilterResults;
import static de.fraunhofer.iosb.ilt.statests.util.Utils.getFromList;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static de.fraunhofer.iosb.ilt.frostclient.models.CommonProperties.EP_NAME;
import static de.fraunhofer.iosb.ilt.frostclient.models.CommonProperties.EP_PROPERTIES;
import static de.fraunhofer.iosb.ilt.frostclient.utils.ParserUtils.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.frostclient.utils.StringHelper.formatKeyValuesForUrl;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

Expand Down Expand Up @@ -114,8 +114,8 @@ private static void createEntities() throws ServiceFailureException, URISyntaxEx
sSrvc.create(obsProp);
OBSERVED_PROPS.add(obsProp);

ID_TYPES.put(EntityType.THING, IdType.findFor(THINGS.get(0).getPrimaryKeyValues()[0]));
ID_TYPES.put(EntityType.OBSERVED_PROPERTY, IdType.findFor(OBSERVED_PROPS.get(0).getPrimaryKeyValues()[0]));
ID_TYPES.put(EntityType.THING, IdType.findFor(THINGS.get(0).getPrimaryKeyValues().get(0)));
ID_TYPES.put(EntityType.OBSERVED_PROPERTY, IdType.findFor(OBSERVED_PROPS.get(0).getPrimaryKeyValues().get(0)));
}

/**
Expand Down Expand Up @@ -236,7 +236,7 @@ void test02BatchRequestWithChangeSetReferencingNewEntities() {
+ " \"definition\": \"http://unitsofmeasure.org/ucum.html#para-30\"\r\n"
+ " },\n"
+ " \"observationType\": \"http://www.opengis.net/def/observationType/OGCOM/2.0/OM_Measurement\",\r\n"
+ " \"ObservedProperty\": {\"@iot.id\": " + Utils.quoteForJson(OBSERVED_PROPS.get(0).getPrimaryKeyValues()[0]) + "},\r\n"
+ " \"ObservedProperty\": {\"@iot.id\": " + Utils.quoteForJson(OBSERVED_PROPS.get(0).getPrimaryKeyValues().get(0)) + "},\r\n"
+ " \"Sensor\": {\"@iot.id\": \"$sensor1\"}\r\n"
+ "}";
final String batchContent = "--batch_36522ad7-fc75-4b56-8c71-56071383e77b\r\n"
Expand Down Expand Up @@ -496,7 +496,7 @@ void test07JsonBatchRequestWithChangeSetReferencingNewEntities() {
"ObservedProperty": {"@iot.id": $ObservedProperty0},
"Sensor": {"@iot.id": "$sensor1"}
}""";
post2 = StringUtils.replace(post2, "$ObservedProperty0", Utils.quoteForJson(OBSERVED_PROPS.get(0).getPrimaryKeyValues()[0]));
post2 = StringUtils.replace(post2, "$ObservedProperty0", Utils.quoteForJson(OBSERVED_PROPS.get(0).getPrimaryKeyValues().get(0)));
String request = """
{
"requests":[{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package de.fraunhofer.iosb.ilt.statests.c05multidatastream;

import static de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsV11MultiDatastream.EP_MULTIOBSERVATIONDATATYPES;
import static de.fraunhofer.iosb.ilt.frostclient.utils.ParserUtils.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.frostclient.utils.StringHelper.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.statests.util.Utils.getFromList;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -305,9 +305,9 @@ void test05UnLinkObsProp1() throws ServiceFailureException {
Entity md2 = MULTIDATASTREAMS.get(1);
Entity op2 = OBSERVED_PROPS.get(1);
Entity op3 = OBSERVED_PROPS.get(2);
String md2Id = formatKeyValuesForUrl(md2.getPrimaryKeyValues());
String op2Id = formatKeyValuesForUrl(op2.getPrimaryKeyValues());
String op3Id = formatKeyValuesForUrl(op3.getPrimaryKeyValues());
String md2Id = formatKeyValuesForUrl(md2);
String op2Id = formatKeyValuesForUrl(op2);
String op3Id = formatKeyValuesForUrl(op3);

HttpResponse response = HTTPMethods.doDelete(serverSettings.getServiceUrl(version) + "/MultiDatastreams(" + md2Id + ")/ObservedProperties/$ref?$id=../../Observations(" + op2Id + ")");
assertEquals(400, response.code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package de.fraunhofer.iosb.ilt.statests.c05multidatastream;

import static de.fraunhofer.iosb.ilt.frostclient.utils.ParserUtils.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.frostclient.utils.StringHelper.formatKeyValuesForUrl;
import static de.fraunhofer.iosb.ilt.statests.util.Utils.getFromList;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/
package de.fraunhofer.iosb.ilt.statests.c06dataarrays;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import com.fasterxml.jackson.databind.JsonNode;
import de.fraunhofer.iosb.ilt.frostclient.exception.ServiceFailureException;
import de.fraunhofer.iosb.ilt.frostclient.model.Entity;
import de.fraunhofer.iosb.ilt.frostclient.model.PkValue;
import de.fraunhofer.iosb.ilt.frostclient.models.ext.UnitOfMeasurement;
import de.fraunhofer.iosb.ilt.statests.AbstractTestClass;
import de.fraunhofer.iosb.ilt.statests.ServerSettings;
Expand Down Expand Up @@ -134,7 +134,7 @@ void test03PostDataArray() {
String jsonString = "[\n"
+ " {\n"
+ " \"Datastream\": {\n"
+ " \"@iot.id\": " + Utils.quoteForJson(ds1.getPrimaryKeyValues()[0]) + "\n"
+ " \"@iot.id\": " + Utils.quoteForJson(ds1.getPrimaryKeyValues().get(0)) + "\n"
+ " },\n"
+ " \"components\": [\n"
+ " \"phenomenonTime\",\n"
Expand All @@ -146,7 +146,7 @@ void test03PostDataArray() {
+ " [\n"
+ " \"2010-12-23T10:20:00-07:00\",\n"
+ " 20,\n"
+ " " + Utils.quoteForJson(foi1.getPrimaryKeyValues()[0]) + "\n"
+ " " + Utils.quoteForJson(foi1.getPrimaryKeyValues().get(0)) + "\n"
+ " ],\n"
+ " [\n"
+ " \"2010-12-23T10:21:00-07:00\",\n"
Expand All @@ -157,7 +157,7 @@ void test03PostDataArray() {
+ " },\n"
+ " {\n"
+ " \"Datastream\": {\n"
+ " \"@iot.id\": " + Utils.quoteForJson(ds2.getPrimaryKeyValues()[0]) + "\n"
+ " \"@iot.id\": " + Utils.quoteForJson(ds2.getPrimaryKeyValues().get(0)) + "\n"
+ " },\n"
+ " \"components\": [\n"
+ " \"phenomenonTime\",\n"
Expand Down Expand Up @@ -214,7 +214,7 @@ void test03PostDataArray() {
continue;
}

Object[] obsPk = Utils.pkFromPostResult(textValue);
PkValue obsPk = Utils.pkFromPostResult(textValue);
Entity obs;
try {
obs = sSrvc.dao(sMdl.etObservation).find(obsPk);
Expand All @@ -237,7 +237,7 @@ void test03PostDataArray() {
return;
}
message = "Autogenerated Features of interest should be equal.";
assertArrayEquals(foiObs8.getPrimaryKeyValues(), foiObs7.getPrimaryKeyValues(), message);
assertEquals(foiObs8.getPrimaryKeyValues(), foiObs7.getPrimaryKeyValues(), message);
}

@Test
Expand All @@ -252,7 +252,7 @@ void test04PostDataArrayMultiDatastream() {
String jsonString = "[\n"
+ " {\n"
+ " \"MultiDatastream\": {\n"
+ " \"@iot.id\": " + Utils.quoteForJson(mds1.getPrimaryKeyValues()[0]) + "\n"
+ " \"@iot.id\": " + Utils.quoteForJson(mds1.getPrimaryKeyValues().get(0)) + "\n"
+ " },\n"
+ " \"components\": [\n"
+ " \"phenomenonTime\",\n"
Expand Down Expand Up @@ -309,7 +309,7 @@ void test04PostDataArrayMultiDatastream() {
continue;
}

Object[] obsId = Utils.pkFromPostResult(textValue);
PkValue obsId = Utils.pkFromPostResult(textValue);
Entity obs;
try {
obs = sSrvc.dao(sMdl.etObservation).find(obsId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ private JsonNode getObservation() throws ServiceFailureException {
+ " \"validTime\": \"2016-01-01T01:01:01.000Z/2016-01-01T23:59:59.000Z\",\n"
+ " \"result\": " + value + ",\n"
+ " \"parameters\":{\"param1\": \"some value1\", \"param2\": \"some value2\"},\n"
+ " \"Datastream\":{\"@iot.id\": " + Utils.quoteForJson(datastream.getPrimaryKeyValues()[0]) + "},\n"
+ " \"FeatureOfInterest\": {\"@iot.id\": " + Utils.quoteForJson(featureOfInterest.getPrimaryKeyValues()[0]) + "} \n"
+ " \"Datastream\":{\"@iot.id\": " + Utils.quoteForJson(datastream.getPrimaryKeyValues().get(0)) + "},\n"
+ " \"FeatureOfInterest\": {\"@iot.id\": " + Utils.quoteForJson(featureOfInterest.getPrimaryKeyValues().get(0)) + "} \n"
+ "}");
} catch (IOException ex) {
LOGGER.error("Exception:", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import de.fraunhofer.iosb.ilt.frostclient.dao.Dao;
import de.fraunhofer.iosb.ilt.frostclient.exception.ServiceFailureException;
import de.fraunhofer.iosb.ilt.frostclient.model.Entity;
import de.fraunhofer.iosb.ilt.frostclient.model.PkValue;
import de.fraunhofer.iosb.ilt.frostclient.model.property.EntityPropertyMain;
import de.fraunhofer.iosb.ilt.frostclient.model.property.NavigationPropertyEntity;
import de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsV11Sensing;
Expand Down Expand Up @@ -231,7 +232,7 @@ public void createEntities() throws ServiceFailureException {
LOGGER.info(" Posted Batch with {} results.", result.getResponses().size());
for (BatchResponseJson.ResponsePart part : result.getResponses()) {
final String location = part.getLocation();
Object[] pk = pkFromSelfLink(location);
PkValue pk = pkFromSelfLink(location);
final String type = typeFromSelfLink(location);
switch (type) {
case "things":
Expand Down Expand Up @@ -279,7 +280,7 @@ public void createEntities() throws ServiceFailureException {

public abstract String getBatchPostData() throws IOException;

public static Object[] pkFromSelfLink(String selfLink) {
public static PkValue pkFromSelfLink(String selfLink) {
String idString = selfLink.substring(selfLink.indexOf('(') + 1, selfLink.indexOf(')'));
return ParserUtils.tryToParse(idString);
}
Expand Down Expand Up @@ -498,7 +499,7 @@ void test_08a_ObservationRead() {
@Test
void test_08b_ObservationReadFilter() {
LOGGER.info(" test_08b_ObservationReadFilter");
final String filter = "Datastreams/Observations/id eq " + StringHelper.quoteForUrl(OBSERVATIONS.get(0).getPrimaryKeyValues()[0]);
final String filter = "Datastreams/Observations/id eq " + StringHelper.quoteForUrl(OBSERVATIONS.get(0).getPrimaryKeyValues().get(0));
testFilterResults(ADMIN, serviceAdmin, mdlSensing.etObservedProperty, filter, Utils.getFromList(O_PROPS, 0));
testFilterResults(WRITE, serviceWrite, mdlSensing.etObservedProperty, filter, Utils.getFromList(O_PROPS, 0));
testFilterResults(READ, serviceRead, mdlSensing.etObservedProperty, filter, Utils.getFromList(O_PROPS, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import de.fraunhofer.iosb.ilt.frostclient.model.Entity;
import de.fraunhofer.iosb.ilt.frostclient.model.EntityType;
import de.fraunhofer.iosb.ilt.frostclient.model.ModelRegistry;
import de.fraunhofer.iosb.ilt.frostclient.model.PkValue;
import de.fraunhofer.iosb.ilt.frostclient.model.property.EntityProperty;
import de.fraunhofer.iosb.ilt.frostclient.model.property.EntityPropertyMain;
import de.fraunhofer.iosb.ilt.frostclient.model.property.NavigationPropertyEntity;
Expand Down Expand Up @@ -189,6 +190,11 @@ public Entity newUserProjectRole() {
}

public Entity newUserProjectRole(Object... pk) {
return newUserProjectRole()
.setPrimaryKeyValues(PkValue.of(pk));
}

public Entity newUserProjectRole(PkValue pk) {
return newUserProjectRole()
.setPrimaryKeyValues(pk);
}
Expand Down
Loading

0 comments on commit c601504

Please sign in to comment.