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

Fix MongoDBAASAggregator sending createSubmodel events when loading Submodels #403

Closed
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 @@ -60,7 +60,7 @@ public abstract class MqttV2AASServerSuite extends AASServerSuite {
protected static AASServerComponent component;
protected static Server mqttBroker;
protected MqttTestListener listener;
private static final String AAS_SERVER_ID = "aas-server";
protected static final String AAS_SERVER_ID = "aas-server";

@Override
protected String getURL() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright (C) 2023 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.basyx.regression.AASServer;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
import org.eclipse.basyx.aas.metamodel.map.descriptor.CustomId;
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.MongoDBAASAggregator;
import org.eclipse.basyx.components.aas.mqtt.MqttV2AASServerFeature;
import org.eclipse.basyx.components.configuration.BaSyxContextConfiguration;
import org.eclipse.basyx.components.configuration.BaSyxMongoDBConfiguration;
import org.eclipse.basyx.components.configuration.BaSyxMqttConfiguration;
import org.eclipse.basyx.extensions.shared.encoding.Base64URLEncoder;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
import org.eclipse.basyx.submodel.metamodel.map.Submodel;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* Test MQTT Observer behavior with MongoDB as backend
*
* @author mateusmolina
*
*/
public class TestAASServerWithMongoDBMqttV2 extends MqttV2AASServerSuite {

private static BaSyxMongoDBConfiguration mongoDBConfig = buildBasyxMongoDBConfiguration("TestAASServerWithMongoDBMqttV2");
private static IIdentifier mongoDBTestShell = new CustomId("mongoDBTestShellId");

@BeforeClass
public static void setUpClass() throws IOException {
BaSyxAASServerConfiguration serverConfig = new BaSyxAASServerConfiguration();
serverConfig.setAASBackend(AASServerBackend.MONGODB);

startMqttBroker();
BaSyxContextConfiguration contextConfig = createBaSyxContextConfiguration();
BaSyxMqttConfiguration mqttConfig = createMqttConfig();

resetMongoDBTestData();

component = new AASServerComponent(contextConfig, serverConfig, mongoDBConfig);
component.addAASServerFeature(new MqttV2AASServerFeature(mqttConfig, "MqttAASServerSuiteClientId", AAS_SERVER_ID, new Base64URLEncoder()));
component.startComponent();
}

@Test
public void observerIsNotTriggered_WhenGettingAAS() {
addMongoDBTestShellToServer();

int expectedMsgCounter = listener.msgCounter;

restartAASServerComponent();
manager.retrieveAAS(mongoDBTestShell);

assertEquals(expectedMsgCounter, listener.msgCounter);
}

private void restartAASServerComponent() {
component.stopComponent();
component.startComponent();
}

private void addMongoDBTestShellToServer() {
AssetAdministrationShell shell = createShell(mongoDBTestShell.getId(), mongoDBTestShell);
manager.createAAS(shell, getURL());

Submodel submodel = createSubmodel(submodelIdentifier.getId(), submodelIdentifier);
manager.createSubmodel(mongoDBTestShell, submodel);
}

@SuppressWarnings("deprecation")
private static void resetMongoDBTestData() {
new MongoDBAASAggregator(mongoDBConfig).reset();
}

private static BaSyxMongoDBConfiguration buildBasyxMongoDBConfiguration(String collectionPrefix) {
BaSyxMongoDBConfiguration mongoDBConfig;
mongoDBConfig = new BaSyxMongoDBConfiguration();
mongoDBConfig.setAASCollection(collectionPrefix + "_AAS");
mongoDBConfig.setSubmodelCollection(collectionPrefix + "_SM");
return mongoDBConfig;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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
Expand Down Expand Up @@ -301,4 +300,5 @@ public static void tearDownClass() {

component.stopComponent();
}

}
8 changes: 7 additions & 1 deletion basyx.components/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,14 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- Mockito for mocking in JUnit tests -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- Specifies dependency settings for all submodules using these dependencies -->
<dependencyManagement>
<dependencies>
Expand Down
Loading