diff --git a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/mongodb/TestMongoDBAggregator.java b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/mongodb/TestMongoDBAggregator.java index 380a0db0..3f257af9 100644 --- a/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/mongodb/TestMongoDBAggregator.java +++ b/basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/mongodb/TestMongoDBAggregator.java @@ -25,6 +25,10 @@ package org.eclipse.basyx.regression.AASServer.mongodb; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; import java.io.IOException; import java.util.List; @@ -43,10 +47,18 @@ import org.eclipse.basyx.components.aas.AASServerComponent; import org.eclipse.basyx.components.aas.configuration.AASServerBackend; import org.eclipse.basyx.components.aas.configuration.BaSyxAASServerConfiguration; +import org.eclipse.basyx.components.aas.mongodb.MongoDBAASAPIFactory; import org.eclipse.basyx.components.aas.mongodb.MongoDBAASAggregator; +import org.eclipse.basyx.components.aas.mongodb.MongoDBAASAggregatorFactory; +import org.eclipse.basyx.components.aas.mongodb.MongoDBSubmodelAPIFactory; +import org.eclipse.basyx.components.aas.mongodb.MongoDBSubmodelAggregatorFactory; import org.eclipse.basyx.components.configuration.BaSyxContextConfiguration; import org.eclipse.basyx.components.configuration.BaSyxMongoDBConfiguration; import org.eclipse.basyx.components.registry.mongodb.MongoDBRegistryHandler; +import org.eclipse.basyx.submodel.aggregator.api.ISubmodelAggregator; +import org.eclipse.basyx.submodel.aggregator.api.ISubmodelAggregatorFactory; +import org.eclipse.basyx.submodel.aggregator.observing.ISubmodelAggregatorObserverV2; +import org.eclipse.basyx.submodel.aggregator.observing.ObservableSubmodelAggregatorV2; import org.eclipse.basyx.submodel.metamodel.api.ISubmodel; import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier; import org.eclipse.basyx.submodel.metamodel.api.identifier.IdentifierType; @@ -66,7 +78,6 @@ import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; - /** * Testing various behaviors of MongoDBAASAggregator Using * MongoDBAASAggregator's constructors to set registry and adding AAS and @@ -279,6 +290,28 @@ public void checkNoExceptionIsObservedAfterPassingRegistry() { assertEquals(SM_IDSHORT, submodelObject.get(Referable.IDSHORT)); } + @Test + public void observerIsNotTriggered_WhenGettingAAS() { + MongoClient client = MongoClients.create(mongoDBConfig.getConnectionUrl()); + + MongoDBSubmodelAggregatorFactory aggregatorFactory = new MongoDBSubmodelAggregatorFactory(mongoDBConfig, new MongoDBSubmodelAPIFactory(mongoDBConfig, client), client); + + MockObservableSubmodelAggregatorV2Factory observableAggregatorFactory = new MockObservableSubmodelAggregatorV2Factory(aggregatorFactory, "aas-server"); + + MongoDBAASAggregatorFactory aasAggregatorFactory = new MongoDBAASAggregatorFactory(mongoDBConfig, registry, new MongoDBAASAPIFactory(mongoDBConfig, client), observableAggregatorFactory, client); + + IAASAggregator aggregator = aasAggregatorFactory.create(); + + // When + restartAasServer(); + aggregator.getAAS(registry.lookupAAS(new ModelUrn(AAS_ID)).getIdentifier()); + + // Expects + ISubmodelAggregatorObserverV2 observer = observableAggregatorFactory.getMockObserver(); + verify(observer, never()).submodelCreated(any(), any(), any()); + + } + private void restartAasServer() { component.stopComponent(); component.startComponent(); @@ -301,4 +334,38 @@ public static void tearDownClass() { component.stopComponent(); } + + + private class MockObservableSubmodelAggregatorV2Factory implements ISubmodelAggregatorFactory { + + private final ISubmodelAggregatorFactory smAggregatorFactory; + + private final String aasServerId; + + private ISubmodelAggregatorObserverV2 mockObserver; + + public MockObservableSubmodelAggregatorV2Factory(ISubmodelAggregatorFactory smAggregatorFactory, String aasServerId) { + this.smAggregatorFactory = smAggregatorFactory; + this.aasServerId = aasServerId; + mockObserver = mock(ISubmodelAggregatorObserverV2.class); + } + + @Override + public ISubmodelAggregator create() { + ObservableSubmodelAggregatorV2 smAggregator = new ObservableSubmodelAggregatorV2(smAggregatorFactory.create(), aasServerId); + smAggregator.addObserver(mockObserver); + return smAggregator; + } + + @Override + public ISubmodelAggregator create(IIdentifier aasIdentifier) { + return create(); + } + + public ISubmodelAggregatorObserverV2 getMockObserver() { + return mockObserver; + } + + } + } diff --git a/basyx.components/pom.xml b/basyx.components/pom.xml index 059ab2c7..95dd7036 100644 --- a/basyx.components/pom.xml +++ b/basyx.components/pom.xml @@ -262,8 +262,14 @@ 4.13.2 test + + + org.mockito + mockito-core + 5.5.0 + test + -