Skip to content

Commit

Permalink
Remove notifying when createSubmodel with the submodelAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusmolina-iese committed Dec 13, 2023
1 parent 265974d commit 42fb24f
Show file tree
Hide file tree
Showing 2 changed files with 29 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 @@ -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,25 @@ 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 testCreateSubmodelViaApi() {
ISubmodelAPI smApi = new VABSubmodelAPI(new VABModelProvider(createTestSubmodel(), new VABMapHandler()));

String lastPayload = listener.lastPayload;

observedSubmodelAggregator.createSubmodel(smApi);

// No event is expected when creating a Submodel via its API
assertEquals(lastPayload, listener.lastPayload);
}

@Test
public void testUpdateSubmodel() {
submodel.setCategory("newCategory");
Expand Down Expand Up @@ -174,4 +185,15 @@ 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 42fb24f

Please sign in to comment.