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

Remove observer notifying when creating submodel with the API #378

Merged
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
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;
}

}