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

Fixes AAS Environment Test #441

Merged
merged 1 commit into from
Sep 11, 2024
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
@@ -0,0 +1,22 @@
package org.eclipse.digitaltwin.basyx.aasenvironment.component;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

@Configuration
public class MongoDbCollectionsTestConfig {
protected static final String CONNECTION_URL = "mongodb://mongoAdmin:mongoPassword@localhost:27017/";
protected static final String DB_NAME = "aas-env";
protected static final String AAS_REPO_COLLECTION = "aas-repo";
protected static final String SM_REPO_COLLECTION = "submodel-repo";
protected static final String CD_REPO_COLLECTION = "cd-repo";

@Bean
public static MongoTemplate buildMongoTemplate() {
MongoClient client = MongoClients.create(CONNECTION_URL);
return new MongoTemplate(client, DB_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ public class TestMongoDbCollections {
private static ConfigurableApplicationContext appContext;

// MongoDB configuration
private static final String CONNECTION_URL = "mongodb://mongoAdmin:mongoPassword@localhost:27017/";
private static final String DB_NAME = "aas-env";
private static final String AAS_REPO_COLLECTION = "aas-repo";
private static final String SM_REPO_COLLECTION = "submodel-repo";
private static final String CD_REPO_COLLECTION = "cd-repo";

private static final MongoTemplate mongoTemplate = buildMongoTemplate(CONNECTION_URL, DB_NAME);
private static final MongoTemplate mongoTemplate = MongoDbCollectionsTestConfig.buildMongoTemplate();

@BeforeClass
public static void startAASEnvironment() throws Exception {
Expand All @@ -64,32 +59,28 @@ public static void startAASEnvironment() throws Exception {
@AfterClass
public static void deleteDatabase() {
appContext.close();
MongoDBUtilities.clearCollection(mongoTemplate, AAS_REPO_COLLECTION);
MongoDBUtilities.clearCollection(mongoTemplate, SM_REPO_COLLECTION);
MongoDBUtilities.clearCollection(mongoTemplate, CD_REPO_COLLECTION);
MongoDBUtilities.clearCollection(mongoTemplate, MongoDbCollectionsTestConfig.AAS_REPO_COLLECTION);
MongoDBUtilities.clearCollection(mongoTemplate, MongoDbCollectionsTestConfig.SM_REPO_COLLECTION);
MongoDBUtilities.clearCollection(mongoTemplate, MongoDbCollectionsTestConfig.CD_REPO_COLLECTION);
}

@Test
public void aasRepoCollectionIsCorrectlyDefined() {
assertMongoDBCollectionExists(AAS_REPO_COLLECTION);
assertMongoDBCollectionExists(MongoDbCollectionsTestConfig.AAS_REPO_COLLECTION);
}

@Test
public void smRepoCollectionIsCorrectlyDefined() {
assertMongoDBCollectionExists(SM_REPO_COLLECTION);
assertMongoDBCollectionExists(MongoDbCollectionsTestConfig.SM_REPO_COLLECTION);
}

@Test
public void cdRepoCollectionIsCorrectlyDefined() {
assertMongoDBCollectionExists(CD_REPO_COLLECTION);
assertMongoDBCollectionExists(MongoDbCollectionsTestConfig.CD_REPO_COLLECTION);
}

private void assertMongoDBCollectionExists(String collectionName) {
assertTrue(mongoTemplate.collectionExists(collectionName));
}

private static MongoTemplate buildMongoTemplate(String connectionUrl, String dbName) {
MongoClient client = MongoClients.create(connectionUrl);
return new MongoTemplate(client, dbName);
}
}