Skip to content

Commit

Permalink
Remove observer notifying when creating submodel with the API (#378)
Browse files Browse the repository at this point in the history
* Remove notifying when createSubmodel with the submodelAPI

* Address review remarks

* Add msgCounter to MqttTestListener
  • Loading branch information
mateusmolina-iese authored Dec 14, 2023
1 parent 265974d commit 28353bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public void createSubmodel(Submodel submodel) {
@Override
public void createSubmodel(ISubmodelAPI submodelAPI) {
submodelAggregator.createSubmodel(submodelAPI);
observers.stream().forEach(observer -> observer.submodelCreated(getParentAASId(submodelAPI.getSubmodel()), submodelAPI.getSubmodel(), this.aasServerId));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class MqttTestListener implements InterceptHandler {
public String lastTopic;
public String lastPayload;
private ArrayList<String> topics = new ArrayList<>();
public int msgCounter;

@Override
public String getID() {
Expand Down Expand Up @@ -80,6 +81,7 @@ public synchronized void onPublish(InterceptPublishMessage msg) {
topics.add(msg.getTopicName());
lastTopic = msg.getTopicName();
lastPayload = msg.getPayload().toString(StandardCharsets.UTF_8);
msgCounter++;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@
import org.eclipse.basyx.submodel.metamodel.map.identifier.Identifier;
import org.eclipse.basyx.submodel.metamodel.map.submodelelement.SubmodelElementCollection;
import org.eclipse.basyx.submodel.metamodel.map.submodelelement.dataelement.property.Property;
import org.eclipse.basyx.submodel.restapi.api.ISubmodelAPI;
import org.eclipse.basyx.submodel.restapi.vab.VABSubmodelAPI;
import org.eclipse.basyx.testsuite.regression.extensions.shared.mqtt.MqttTestListener;
import org.eclipse.basyx.vab.coder.json.serialization.DefaultTypeFactory;
import org.eclipse.basyx.vab.coder.json.serialization.GSONTools;
import org.eclipse.basyx.vab.modelprovider.generic.VABModelProvider;
import org.eclipse.basyx.vab.modelprovider.map.VABMapHandler;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.junit.After;
Expand All @@ -62,7 +66,7 @@
/**
* Tests events emitting with the MqttSubmodelAggregatorObserver
*
* @author fischer, jungjan, siebert
* @author fischer, jungjan, siebert, mateusmolina
*
*/
public class TestMqttV2SubmodelAggregatorObserver {
Expand Down Expand Up @@ -120,18 +124,24 @@ public void tearDown() {

@Test
public void testCreateSubmodel() {
String newSubmodelIdShort = "newSubmodelIdShort";
String newSubmodelId = "newSubmodelId";
Identifier newSubmodelIdentifier = new Identifier(IdentifierType.IRDI, newSubmodelId);
Submodel newSubmodel = new Submodel(newSubmodelIdShort, newSubmodelIdentifier);
newSubmodel.addSubmodelElement(new SubmodelElementCollection("smeColl"));
newSubmodel.addSubmodelElement(new Property("prop", false));
Submodel newSubmodel = createTestSubmodel();
observedSubmodelAggregator.createSubmodel(newSubmodel);

assertEquals(removeSubmodelElements(newSubmodel), deserializePayload(listener.lastPayload));
assertEquals(payloadFactory.createCreateSubmodelTopic(null, observedSubmodelAggregator.getAasServerId()), listener.lastTopic);
}

@Test
public void noEventExpectedWhenSubmodelIsCreatedViaAPI() {
ISubmodelAPI smApi = new VABSubmodelAPI(new VABModelProvider(createTestSubmodel(), new VABMapHandler()));

String lastPayload = listener.lastPayload;

observedSubmodelAggregator.createSubmodel(smApi);

assertEquals(lastPayload, listener.lastPayload);
}

@Test
public void testUpdateSubmodel() {
submodel.setCategory("newCategory");
Expand Down Expand Up @@ -174,4 +184,18 @@ private Submodel removeSubmodelElements(Submodel submodel) {

return copy;
}

private static Submodel createTestSubmodel() {
String newSubmodelIdShort = "newSubmodelIdShort";
String newSubmodelId = "newSubmodelId";
Identifier newSubmodelIdentifier = new Identifier(IdentifierType.IRDI, newSubmodelId);

Submodel newSubmodel = new Submodel(newSubmodelIdShort, newSubmodelIdentifier);

newSubmodel.addSubmodelElement(new SubmodelElementCollection("smeColl"));
newSubmodel.addSubmodelElement(new Property("prop", false));

return newSubmodel;
}

}

0 comments on commit 28353bb

Please sign in to comment.