Skip to content

Commit 5ffa72d

Browse files
authored
Test if Environment Repositories are being saved in different MongoDB collections (#337)
* Restrict http test configs to profile 'httptests' * Add 'httptests' profile to affected tests * Add 'authorization' profile for auth related tests not using 'httptests' config file * Add aasenv test for checking if collections are being correctly created * Add close statement to appContext * Manually triggering the CI * Add basyx.mongodbcore to test aasenv.component pom
1 parent 700059e commit 5ffa72d

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

basyx.aasenvironment/basyx.aasenvironment.component/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
<classifier>tests</classifier>
5050
<scope>test</scope>
5151
</dependency>
52+
<dependency>
53+
<groupId>org.eclipse.digitaltwin.basyx</groupId>
54+
<artifactId>basyx.mongodbcore</artifactId>
55+
<scope>test</scope>
56+
</dependency>
5257
<dependency>
5358
<groupId>org.eclipse.digitaltwin.basyx</groupId>
5459
<artifactId>basyx.conceptdescriptionrepository.component</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2024 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
26+
package org.eclipse.digitaltwin.basyx.aasenvironment.component;
27+
28+
import static org.junit.Assert.assertTrue;
29+
30+
import org.eclipse.digitaltwin.basyx.common.mongocore.MongoDBUtilities;
31+
import org.junit.AfterClass;
32+
import org.junit.BeforeClass;
33+
import org.junit.Test;
34+
import org.springframework.boot.builder.SpringApplicationBuilder;
35+
import org.springframework.context.ConfigurableApplicationContext;
36+
import org.springframework.data.mongodb.core.MongoTemplate;
37+
38+
import com.mongodb.client.MongoClient;
39+
import com.mongodb.client.MongoClients;
40+
41+
/**
42+
* TestMongoDbCollections
43+
*
44+
* @author mateusmolina
45+
*
46+
*/
47+
public class TestMongoDbCollections {
48+
private static ConfigurableApplicationContext appContext;
49+
50+
// MongoDB configuration
51+
private static final String CONNECTION_URL = "mongodb://mongoAdmin:mongoPassword@localhost:27017/";
52+
private static final String DB_NAME = "aas-env";
53+
private static final String AAS_REPO_COLLECTION = "aas-repo";
54+
private static final String SM_REPO_COLLECTION = "submodel-repo";
55+
private static final String CD_REPO_COLLECTION = "cd-repo";
56+
57+
private static final MongoTemplate mongoTemplate = buildMongoTemplate(CONNECTION_URL, DB_NAME);
58+
59+
@BeforeClass
60+
public static void startAASEnvironment() throws Exception {
61+
appContext = new SpringApplicationBuilder(AasEnvironmentComponent.class).profiles("mongodb").run(new String[] {});
62+
}
63+
64+
@AfterClass
65+
public static void deleteDatabase() {
66+
appContext.close();
67+
MongoDBUtilities.clearCollection(mongoTemplate, AAS_REPO_COLLECTION);
68+
MongoDBUtilities.clearCollection(mongoTemplate, SM_REPO_COLLECTION);
69+
MongoDBUtilities.clearCollection(mongoTemplate, CD_REPO_COLLECTION);
70+
}
71+
72+
@Test
73+
public void aasRepoCollectionIsCorrectlyDefined() {
74+
assertMongoDBCollectionExists(AAS_REPO_COLLECTION);
75+
}
76+
77+
@Test
78+
public void smRepoCollectionIsCorrectlyDefined() {
79+
assertMongoDBCollectionExists(SM_REPO_COLLECTION);
80+
}
81+
82+
@Test
83+
public void cdRepoCollectionIsCorrectlyDefined() {
84+
assertMongoDBCollectionExists(CD_REPO_COLLECTION);
85+
}
86+
87+
private void assertMongoDBCollectionExists(String collectionName) {
88+
assertTrue(mongoTemplate.collectionExists(collectionName));
89+
}
90+
91+
private static MongoTemplate buildMongoTemplate(String connectionUrl, String dbName) {
92+
MongoClient client = MongoClients.create(connectionUrl);
93+
return new MongoTemplate(client, dbName);
94+
}
95+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
basyx.backend = MongoDB
2+
3+
spring.data.mongodb.host=127.0.0.1
4+
spring.data.mongodb.port=27017
5+
spring.data.mongodb.database=aas-env
6+
spring.data.mongodb.authentication-database=admin
7+
spring.data.mongodb.username=mongoAdmin
8+
spring.data.mongodb.password=mongoPassword
9+
10+
# default values
11+
basyx.aasrepository.mongodb.collectionName=aas-repo
12+
basyx.submodelrepository.mongodb.collectionName=submodel-repo
13+
basyx.cdrepository.mongodb.collectionName=cd-repo

0 commit comments

Comments
 (0)