-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
774 additions
and
65 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
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
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
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
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
208 changes: 208 additions & 0 deletions
208
...r.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c08mqttsubscribe/MqttCoreTests.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,208 @@ | ||
/* | ||
* Copyright (C) 2023 Fraunhofer Institut IOSB, Fraunhoferstr. 1, D 76131 | ||
* Karlsruhe, Germany. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package de.fraunhofer.iosb.ilt.statests.c08mqttsubscribe; | ||
|
||
import static de.fraunhofer.iosb.ilt.statests.util.mqtt.MqttHelper.WAIT_AFTER_CLEANUP; | ||
import static de.fraunhofer.iosb.ilt.statests.util.mqtt.MqttHelper.waitMillis; | ||
|
||
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.EntityType; | ||
import de.fraunhofer.iosb.ilt.frostclient.models.SensorThingsSensingV11; | ||
import de.fraunhofer.iosb.ilt.statests.AbstractTestClass; | ||
import de.fraunhofer.iosb.ilt.statests.ServerVersion; | ||
import de.fraunhofer.iosb.ilt.statests.util.EntityHelper2; | ||
import de.fraunhofer.iosb.ilt.statests.util.EntityUtils; | ||
import de.fraunhofer.iosb.ilt.statests.util.mqtt.MqttHelper2; | ||
import java.net.URISyntaxException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Test the standard MQTT functionality. | ||
*/ | ||
@TestMethodOrder(MethodOrderer.MethodName.class) | ||
public class MqttCoreTests extends AbstractTestClass { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MqttCoreTests.class); | ||
|
||
private List<EntityType> entityTypesForCreate; | ||
|
||
private static EntityHelper2 eh2; | ||
private static MqttHelper2 mqttHelper; | ||
|
||
public MqttCoreTests() { | ||
super(ServerVersion.v_1_1); | ||
} | ||
|
||
@Override | ||
protected void setUpVersion() throws ServiceFailureException, URISyntaxException { | ||
LOGGER.info("Setting up for version {}.", version.urlPart); | ||
eh2 = new EntityHelper2(sSrvc); | ||
mqttHelper = new MqttHelper2(sSrvc, serverSettings.getMqttUrl(), serverSettings.getMqttTimeOutMs()); | ||
entityTypesForCreate = Arrays.asList( | ||
sMdl.etThing, | ||
sMdl.etLocation, | ||
sMdl.etSensor, | ||
sMdl.etObservedProperty, | ||
sMdl.etFeatureOfInterest, | ||
sMdl.etDatastream, | ||
sMdl.etObservation, | ||
sMdl.etHistoricalLocation); | ||
} | ||
|
||
@Override | ||
protected void tearDownVersion() throws ServiceFailureException { | ||
cleanup(); | ||
} | ||
|
||
/** | ||
* This method is run after all the tests of this class is run and clean the | ||
* database. | ||
* | ||
* @throws ServiceFailureException if cleaning up fails, | ||
*/ | ||
@AfterAll | ||
public static void tearDown() throws ServiceFailureException { | ||
LOGGER.info("Tearing down."); | ||
cleanup(); | ||
} | ||
|
||
public static void cleanup() throws ServiceFailureException { | ||
EntityUtils.deleteAll(service); | ||
eh2.clearCaches(); | ||
eh2 = null; | ||
mqttHelper = null; | ||
|
||
} | ||
|
||
private void deleteCreatedEntities() throws ServiceFailureException { | ||
EntityUtils.deleteAll(service); | ||
eh2.clearCaches(); | ||
} | ||
|
||
@Test | ||
void check01SubscribeToEntitySetInsert() throws ServiceFailureException { | ||
LOGGER.info(" checkSubscribeToEntitySetInsert"); | ||
deleteCreatedEntities(); | ||
// Give the server a second to send out the messages created by the setup. | ||
waitMillis(WAIT_AFTER_CLEANUP); | ||
|
||
for (var entityType : entityTypesForCreate) { | ||
LOGGER.info(" {}", entityType); | ||
final CompletableFuture<JsonNode> future = new CompletableFuture<>(); | ||
final Callable<Object> insertAction = getInsertAction(entityType, future); | ||
final MqttHelper2.TestSubscription testSubscription = new MqttHelper2.TestSubscription(mqttHelper, "v1.1/" + entityType.mainContainer) | ||
.addExpectedJson(future) | ||
.createReceivedListener(sMdl.etObservation); | ||
MqttHelper2.MqttAction mqttAction = new MqttHelper2.MqttAction(insertAction) | ||
.add(testSubscription); | ||
mqttHelper.executeRequest(mqttAction); | ||
} | ||
} | ||
|
||
@Test | ||
void check02SubscribeAutoFeatureCreation() throws ServiceFailureException { | ||
LOGGER.info(" check02SubscribeAutoFeatureCreation"); | ||
|
||
// Now check if an Observation insert creates a new FoI and posts it over MQTT. | ||
LOGGER.debug(" FoI creation"); | ||
EntityUtils.deleteAll(sSrvc.dao(sMdl.etFeatureOfInterest)); | ||
EntityUtils.deleteAll(sSrvc.dao(sMdl.etObservation)); | ||
eh2.observations.clear(); | ||
|
||
final CompletableFuture<JsonNode> futureObs = new CompletableFuture<>(); | ||
final CompletableFuture<JsonNode> futureFoi = new CompletableFuture<>(); | ||
final Callable<Object> insertAction = getInsertActionObs(futureObs, futureFoi); | ||
|
||
final MqttHelper2.TestSubscription testSubscription1 = new MqttHelper2.TestSubscription(mqttHelper, "v1.1/Observations") | ||
.addExpectedJson(futureObs) | ||
.createReceivedListener(sMdl.etObservation); | ||
|
||
final MqttHelper2.TestSubscription testSubscription2 = new MqttHelper2.TestSubscription(mqttHelper, "v1.1/FeaturesOfInterest") | ||
.addExpectedJson(futureFoi) | ||
.createReceivedListener(sMdl.etFeatureOfInterest); | ||
|
||
MqttHelper2.MqttAction mqttAction = new MqttHelper2.MqttAction(insertAction) | ||
.add(testSubscription1) | ||
.add(testSubscription2); | ||
mqttHelper.executeRequest(mqttAction); | ||
|
||
} | ||
|
||
private Callable<Object> getInsertAction(final EntityType et, final CompletableFuture<JsonNode> future) { | ||
return () -> { | ||
Entity entity = createEntity(et); | ||
JsonNode jsonNode = eh2.getEntity(entity); | ||
future.complete(jsonNode); | ||
return null; | ||
}; | ||
} | ||
|
||
private Entity createEntity(EntityType et) throws ServiceFailureException { | ||
switch (et.entityName) { | ||
case SensorThingsSensingV11.NAME_THING: | ||
return eh2.createThing(); | ||
|
||
case SensorThingsSensingV11.NAME_SENSOR: | ||
return eh2.createSensor(); | ||
|
||
case SensorThingsSensingV11.NAME_LOCATION: | ||
return eh2.createLocation(eh2.things.get(0)); | ||
|
||
case SensorThingsSensingV11.NAME_OBSERVEDPROPERTY: | ||
return eh2.createObservedProperty(); | ||
|
||
case SensorThingsSensingV11.NAME_FEATUREOFINTEREST: | ||
return eh2.createFeatureOfInterest(); | ||
|
||
case SensorThingsSensingV11.NAME_DATASTREAM: | ||
return eh2.createDatastream(eh2.things.get(0), eh2.oProps.get(0), eh2.sensors.get(0)); | ||
|
||
case SensorThingsSensingV11.NAME_OBSERVATION: | ||
return eh2.createObservation(eh2.datastreams.get(0)); | ||
|
||
case SensorThingsSensingV11.NAME_HISTORICALLOCATION: | ||
return eh2.createHistoricalLocation(eh2.things.get(0), eh2.locations.get(0)); | ||
|
||
default: | ||
throw new IllegalArgumentException("Don't know how to create a " + et); | ||
} | ||
} | ||
|
||
private Callable<Object> getInsertActionObs(final CompletableFuture<JsonNode> futureObs, final CompletableFuture<JsonNode> futureFoi) { | ||
return () -> { | ||
Entity obs = eh2.createObservation(eh2.datastreams.get(0)); | ||
JsonNode jsonNode1 = eh2.getEntity(obs); | ||
futureObs.complete(jsonNode1); | ||
JsonNode jsonNode2 = eh2.getEntity(obs, sMdl.npObservationFeatureofinterest); | ||
futureFoi.complete(jsonNode2); | ||
return null; | ||
}; | ||
|
||
} | ||
} |
Oops, something went wrong.