diff --git a/.github/actions/startdeps/action.yml b/.github/actions/startdeps/action.yml index f015a4b4c..d6c5f23db 100644 --- a/.github/actions/startdeps/action.yml +++ b/.github/actions/startdeps/action.yml @@ -20,7 +20,11 @@ runs: shell: pwsh #run: docker-compose -f docker/MAQSService/docker-compose.yml -p OpenMAQS/maqs-java up -d run: Start-Process -FilePath "dotnet" -ArgumentList "run --project docker/MAQSService/MainTestService/MainTestService.csproj" - - name: Build the docker-compose stack + - name: Build the MAQS database docker stack if: inputs.module-name == 'openmaqs-database' shell: bash run: docker-compose -f docker/MAQSSQLServer/docker-compose.yml -p OpenMAQS/openmaqs-java up -d + - name: Build the MAQS MongoDB docker stack + if: inputs.module-name == 'openmaqs-nosql' + shell: bash + run: docker-compose -f docker/MAQSMongoDB/docker-compose.yml -p OpenMAQS/openmaqs-java up -d \ No newline at end of file diff --git a/.github/labeler.yml b/.github/labeler.yml index e00c3d4db..65387e057 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -25,6 +25,10 @@ database: - openmaqs-database/* - openmaqs-database/**/* +nosql: + - openmaqs-nosql/* + - openmaqs-nosql/**/* + devops: - .dependabot/* - .github/* @@ -36,4 +40,4 @@ accessibility: playwright: - openmaqs-playwright/* - - openmaqs-playwright/**/* + - openmaqs-playwright/**/* \ No newline at end of file diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ab01a6fc3..465f9666a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -129,7 +129,7 @@ jobs: strategy: fail-fast: false matrix: - module-name: [ openmaqs-utilities, openmaqs-base, openmaqs-appium, openmaqs-selenium, openmaqs-webservices, openmaqs-cucumber, openmaqs-accessibility, openmaqs-database, openmaqs-playwright ] + module-name: [ openmaqs-utilities, openmaqs-base, openmaqs-appium, openmaqs-selenium, openmaqs-webservices, openmaqs-cucumber, openmaqs-accessibility, openmaqs-database, openmaqs-nosql, openmaqs-playwright ] steps: - name: Check if tests can be run if: matrix.module-name == 'openmaqs-appium' && github.actor == 'dependabot[bot]' diff --git a/Docker/MAQSMongoDB/docker-compose.yml b/Docker/MAQSMongoDB/docker-compose.yml new file mode 100644 index 000000000..10479a005 --- /dev/null +++ b/Docker/MAQSMongoDB/docker-compose.yml @@ -0,0 +1,23 @@ +version: '2' + +services: + mongo: + image: mongo + restart: always + ports: + - "27017:27017" + volumes: + - ./seed/seed.js:/docker-entrypoint-initdb.d/seed.js + mongo-express: + image: mongo-express + restart: always + ports: + - 8081:8081 + links: + - mongo + environment: + ME_CONFIG_MONGODB_ADMINUSERNAME: + ME_CONFIG_MONGODB_ADMINPASSWORD: + + # Run a custom bash script that bootstraps the database after it is started. + command: [ '/bin/bash', '/mnt/host/initialize_and_start_sqlserver.sh' ] \ No newline at end of file diff --git a/Docker/MAQSMongoDB/seed/seed.js b/Docker/MAQSMongoDB/seed/seed.js new file mode 100644 index 000000000..badfaf331 --- /dev/null +++ b/Docker/MAQSMongoDB/seed/seed.js @@ -0,0 +1,22 @@ +db = db.getSiblingDB('MongoDatabaseTest') +db.MongoTestCollection.drop(); +db.MongoTestCollection.insertMany([ + { + "lid": "test1", + "isChanged": true, + "order": 1 + }, + { + "lid": "test2", + "isChanged": false, + "order": 2 + }, + { + "lid": "test3", + "isChanged": false + }, + { + "lid": "test4", + "isChanged": false + } +]) \ No newline at end of file diff --git a/Docker/docker-compose.yml b/Docker/docker-compose.yml new file mode 100644 index 000000000..44c3c95f1 --- /dev/null +++ b/Docker/docker-compose.yml @@ -0,0 +1,15 @@ +# The extends functionality is not yet available in +# Docker config files versioned 3 and higher. +# If the version is bumped, this config file will have to change. +# See https://github.com/moby/moby/issues/31101. +version: '2' + +services: + mssql: + extends: + file: ./MAQSSQLServer/docker-compose.yml + service: mssql + mongo: + extends: + file: ./MAQSMongoDB/docker-compose.yml + service: mongo \ No newline at end of file diff --git a/docker/MAQSMongoDB/docker-compose.yml b/docker/MAQSMongoDB/docker-compose.yml index 5be3b1e86..10479a005 100644 --- a/docker/MAQSMongoDB/docker-compose.yml +++ b/docker/MAQSMongoDB/docker-compose.yml @@ -3,11 +3,11 @@ version: '2' services: mongo: image: mongo - restart: always + restart: always ports: - - "27017:27017" + - "27017:27017" volumes: - - ./seed/seed.js:/docker-entrypoint-initdb.d/seed.js + - ./seed/seed.js:/docker-entrypoint-initdb.d/seed.js mongo-express: image: mongo-express restart: always @@ -16,5 +16,8 @@ services: links: - mongo environment: - ME_CONFIG_MONGODB_ADMINUSERNAME: - ME_CONFIG_MONGODB_ADMINPASSWORD: \ No newline at end of file + ME_CONFIG_MONGODB_ADMINUSERNAME: + ME_CONFIG_MONGODB_ADMINPASSWORD: + + # Run a custom bash script that bootstraps the database after it is started. + command: [ '/bin/bash', '/mnt/host/initialize_and_start_sqlserver.sh' ] \ No newline at end of file diff --git a/docker/MAQSMongoDB/seed/seed.js b/docker/MAQSMongoDB/seed/seed.js index 81d443938..badfaf331 100644 --- a/docker/MAQSMongoDB/seed/seed.js +++ b/docker/MAQSMongoDB/seed/seed.js @@ -19,4 +19,4 @@ db.MongoTestCollection.insertMany([ "lid": "test4", "isChanged": false } -]) +]) \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 2b04f0b3c..44c3c95f1 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -6,18 +6,10 @@ version: '2' services: mssql: - extends: + extends: file: ./MAQSSQLServer/docker-compose.yml service: mssql mongo: extends: file: ./MAQSMongoDB/docker-compose.yml - service: mongo - imap: - extends: - file: ./MAQSEmail/docker-compose.yml - service: imap - webservice: - extends: - service: webservice - file: ./MAQSService/docker-compose.yml + service: mongo \ No newline at end of file diff --git a/openmaqs-accessibility/src/test/resources/testFiles/integration-test-target-complex.html b/openmaqs-accessibility/src/test/resources/testFiles/integration-test-target-complex.html index 525a22ca7..3404b8684 100644 --- a/openmaqs-accessibility/src/test/resources/testFiles/integration-test-target-complex.html +++ b/openmaqs-accessibility/src/test/resources/testFiles/integration-test-target-complex.html @@ -1,5 +1,5 @@ diff --git a/openmaqs-accessibility/src/test/resources/testFiles/integration-test-target.html b/openmaqs-accessibility/src/test/resources/testFiles/integration-test-target.html index b079563d8..3acb7ed7b 100644 --- a/openmaqs-accessibility/src/test/resources/testFiles/integration-test-target.html +++ b/openmaqs-accessibility/src/test/resources/testFiles/integration-test-target.html @@ -1,5 +1,5 @@ diff --git a/openmaqs-appium/config.xml b/openmaqs-appium/config.xml index 14607a7d0..d1fa629fa 100644 --- a/openmaqs-appium/config.xml +++ b/openmaqs-appium/config.xml @@ -70,7 +70,7 @@ - JMAQS + maqs-Framework NEVER_CHECKIN_A_REAL_KEY portrait Chrome diff --git a/openmaqs-appium/src/test/java/io/github/openmaqs/appium/AppiumConfigUnitTest.java b/openmaqs-appium/src/test/java/io/github/openmaqs/appium/AppiumConfigUnitTest.java index f4d0453a4..b72df3dad 100644 --- a/openmaqs-appium/src/test/java/io/github/openmaqs/appium/AppiumConfigUnitTest.java +++ b/openmaqs-appium/src/test/java/io/github/openmaqs/appium/AppiumConfigUnitTest.java @@ -75,7 +75,7 @@ public void testGetCapabilitiesAsStrings() { SoftAssert softAssert = new SoftAssert(); softAssert.assertTrue(capabilitiesAsStrings.containsKey(username)); - softAssert.assertEquals(capabilitiesAsStrings.get(username), "JMAQS"); + softAssert.assertEquals(capabilitiesAsStrings.get(username), "maqs-Framework"); softAssert.assertTrue(capabilitiesAsStrings.containsKey(accessKey)); softAssert .assertNotEquals(capabilitiesAsStrings.get(accessKey), ""); @@ -95,7 +95,7 @@ public void testGetCapabilitiesAsObjects() { SoftAssert softAssert = new SoftAssert(); softAssert.assertTrue(capabilitiesAsObjects.containsKey(username)); - softAssert.assertEquals(capabilitiesAsObjects.get(username), "JMAQS"); + softAssert.assertEquals(capabilitiesAsObjects.get(username), "maqs-Framework"); softAssert.assertTrue(capabilitiesAsObjects.containsKey(accessKey)); softAssert .assertNotEquals(capabilitiesAsObjects.get(accessKey), ""); diff --git a/openmaqs-nosql/config.xml b/openmaqs-nosql/config.xml new file mode 100644 index 000000000..65cb1a9c5 --- /dev/null +++ b/openmaqs-nosql/config.xml @@ -0,0 +1,41 @@ + + + + + + 100 + + + 10000 + + + YES + + + VERBOSE + + + TXT + + + ./target/logs + + + mongodb://localhost:27017 + MongoDatabaseTest + MongoTestCollection + 30 + + diff --git a/openmaqs-nosql/pom.xml b/openmaqs-nosql/pom.xml new file mode 100644 index 000000000..48aef81e0 --- /dev/null +++ b/openmaqs-nosql/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + + io.github.openmaqs + openmaqs-java + ${revision} + + + io.github.openmaqs.nosql + openmaqs-nosql + OpenMAQS NoSQL Testing Module + ${revision} + + + 4.10.2 + + + + + io.github.openmaqs.base + openmaqs-base + ${project.version} + + + io.github.openmaqs.utilities + openmaqs-utilities + ${project.version} + compile + + + org.mongodb + mongodb-driver-sync + ${mongoDB.version} + + + org.testng + testng + + + diff --git a/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/BaseMongoTest.java b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/BaseMongoTest.java new file mode 100644 index 000000000..453c72844 --- /dev/null +++ b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/BaseMongoTest.java @@ -0,0 +1,107 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + + +import com.mongodb.client.MongoCollection; +import io.github.openmaqs.base.BaseExtendableTest; +import java.util.function.Supplier; +import org.bson.Document; +import org.testng.ITestResult; + +/** + * The Base Mongo Test class. + */ +public class BaseMongoTest extends BaseExtendableTest { + + /** + * Initializes a new instance of the BaseMongoTest class, + * Set up the database client for each test class. + */ + public BaseMongoTest() { + // Currently, not populated with any logic + } + + /** + * Gets the mongoDB driver. + * @return the mongoDB driver + */ + public MongoDBDriver getMongoDBDriver() { + return this.getTestObject().getMongoDBDriver(); + } + + /** + * Sets the MongoDB driver. + * @param driver the MongoDB driver to be set. + */ + public void setMongoDBDriver(MongoDBDriver driver) { + this.getTestObject().overrideMongoDBDriver(driver); + } + + /** + * Override the Mongo driver - does not lazy load. + * @param driver New Mongo driver + */ + public void overrideConnectionDriver(MongoDBDriver driver) { + this.getTestObject().overrideMongoDBDriver(driver); + } + + /** + * Override the Mongo driver - respects lazy loading. + * @param overrideCollectionConnection The collection function + */ + public void overrideConnectionDriver(Supplier> overrideCollectionConnection) { + this.getTestObject().overrideMongoDBDriver(overrideCollectionConnection); + } + + /** + * Override the Mongo driver - respects lazy loading. + * @param connectionString Client connection string + * @param databaseString Database connection string + * @param collectionString Mongo collection string + */ + public void overrideConnectionDriver(String connectionString, String databaseString, String collectionString) { + this.getTestObject().overrideMongoDBDriver(connectionString, databaseString, collectionString); + } + + /** + * Get the base web service url. + * @return The base web service url + */ + protected String getBaseConnectionString() { + return MongoDBConfig.getConnectionString(); + } + + /** + * Get the base web service url. + * @return The base web service url + */ + protected String getBaseDatabaseString() { + return MongoDBConfig.getDatabaseString(); + } + + /** + * Get the base web service url. + * @return The base web service url + */ + protected String getBaseCollectionString() { + return MongoDBConfig.getCollectionString(); + } + + @Override + protected void createNewTestObject() { + this.setTestObject(new MongoTestObject(this.getBaseConnectionString(), this.getBaseDatabaseString(), + this.getBaseCollectionString(), this.createLogger(), this.getFullyQualifiedTestClassName())); + } + + /** + * Steps to take before logging teardown results. + * @param resultType The test result + */ + @Override + protected void beforeLoggingTeardown(ITestResult resultType) { + // Currently, not populated with any logic + } +} diff --git a/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/IMongoTestObject.java b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/IMongoTestObject.java new file mode 100644 index 000000000..9b9cf3e34 --- /dev/null +++ b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/IMongoTestObject.java @@ -0,0 +1,48 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import com.mongodb.client.MongoCollection; +import io.github.openmaqs.base.ITestObject; +import java.util.function.Supplier; +import org.bson.Document; + +/** + * The Mongo Test Object interface. + */ +public interface IMongoTestObject extends ITestObject { + + /** + * Gets the Mongo driver. + * @return the mongo database driver + */ + MongoDBDriver getMongoDBDriver(); + + /** + * Gets the Mongo driver manager. + * @return the mongo database manager + */ + MongoDriverManager getMongoDBManager(); + + /** + * Override the Mongo driver a collection function. + * @param overrideCollectionConnection The collection function + */ + void overrideMongoDBDriver(Supplier> overrideCollectionConnection); + + /** + * Override the Mongo driver settings. + * @param driver New Mongo driver + */ + void overrideMongoDBDriver(MongoDBDriver driver); + + /** + * Override the Mongo driver settings. + * @param connectionString Client connection string + * @param databaseString Database connection string + * @param collectionString Mongo collection string + */ + void overrideMongoDBDriver(String connectionString, String databaseString, String collectionString); +} diff --git a/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDBConfig.java b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDBConfig.java new file mode 100644 index 000000000..b30fb9e35 --- /dev/null +++ b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDBConfig.java @@ -0,0 +1,55 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import io.github.openmaqs.utilities.helper.Config; +import io.github.openmaqs.utilities.helper.ConfigSection; + +/** + * The MongoDB Config class. + */ +public class MongoDBConfig { + + private MongoDBConfig() { + } + + /** + * The MongoDB configuration section. + */ + private static final ConfigSection NOSQL_MAQS = ConfigSection.NOSQL_MAQS; + + /** + * Get the client connection string. + * @return The connection type + */ + public static String getConnectionString() { + return Config.getValueForSection(NOSQL_MAQS, "MongoConnectionString"); + } + + /** + * Get the database connection string. + * @return The database name + */ + public static String getDatabaseString() { + return Config.getValueForSection(NOSQL_MAQS, "MongoDatabase"); + } + + /** + * Get the mongo collection string. + * @return The mongo collection string + */ + public static String getCollectionString() { + return Config.getValueForSection(NOSQL_MAQS, "MongoCollection"); + } + + /** + * Get the database timeout in seconds. + * @return The timeout in seconds from the config file or default + * of 30 seconds when no config.xml key is found + */ + public static int getQueryTimeout() { + return Integer.parseInt(Config.getValueForSection(NOSQL_MAQS, "MongoTimeout", "30")); + } +} diff --git a/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDBDriver.java b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDBDriver.java new file mode 100644 index 000000000..bad9e7df1 --- /dev/null +++ b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDBDriver.java @@ -0,0 +1,169 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import com.mongodb.MongoClientSettings; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import java.util.ArrayList; +import java.util.List; +import org.bson.Document; + +/** + * The MongoDB Driver class. + * Wraps the MongoCollection and related helper functions. + */ +public class MongoDBDriver { + + /** + * Initializes a new instance of the MongoDBDriver class. + * @param collection The collection object + */ + public MongoDBDriver(MongoCollection collection) { + setCollection(collection); + } + + /** + * Initializes a new instance of the MongoDBDriver class. + * @param connectionString Server address + * @param databaseString Name of the database + * @param collectionString Name of the collection + */ + public MongoDBDriver(String connectionString, String databaseString, String collectionString) { + setMongoClient(connectionString); + setDatabase(this.getMongoClient(), databaseString); + setCollection(this.getDatabase(), collectionString); + } + + /** + * Initializes a new instance of the MongoDBDriver class. + * @param collectionString Name of the collection + */ + public MongoDBDriver(String collectionString) { + setCollection(MongoFactory.getCollection(MongoDBConfig.getConnectionString(), + MongoDBConfig.getDatabaseString(), collectionString)); + } + + /** + * Initializes a new instance of the MongoDBDriver class. + * @param clientSettings the mongo client settings + * @param collectionString Name of the collection + */ + public MongoDBDriver(MongoClientSettings clientSettings, String databaseString, String collectionString) { + this.setMongoClient(clientSettings); + setCollection(this.getMongoClient().getDatabase(databaseString).getCollection(collectionString)); + } + + /** + * Initializes a new instance of the MongoDBDriver class. + */ + public MongoDBDriver() { + setCollection(MongoFactory.getDefaultCollection()); + } + + /** + * The Mongo DB client. + */ + private MongoClient client; + + /** + * Gets the client object. + * @return the mongo client + */ + public MongoClient getMongoClient() { + return this.client; + } + + /** + * Sets the client object. + * @param connectionString the new mongo Client to be set. + */ + public void setMongoClient(String connectionString) { + this.client = MongoClients.create(connectionString); + } + + public void setMongoClient(MongoClientSettings mongoClientSettings) { + this.client = MongoClients.create(mongoClientSettings); + } + + /** + * The MongoDB Database. + */ + private MongoDatabase database; + + /** + * Gets the database object. + * @return the MongoDB database object + */ + public MongoDatabase getDatabase() { + return this.database; + } + + /** + * Sets the database object. + * @param mongoDatabase the name of the mongo database + */ + public void setDatabase(String mongoDatabase) { + this.database = this.getMongoClient().getDatabase(mongoDatabase); + } + + /** + * Sets the database object. + * @param mongoClient the mongo DB client of the database + * @param mongoDatabase the name of the mongo database + */ + public void setDatabase(MongoClient mongoClient, String mongoDatabase) { + this.client = mongoClient; + setDatabase(mongoDatabase); + } + + /** + * The MongoDB collection. + */ + private MongoCollection collection; + + /** + * Gets the collection object. + * @return a mongo collection + */ + public MongoCollection getCollection() { + return collection; + } + + /** + * Sets the Mongo Collection object. + * @param newCollection the collection to be set + */ + private void setCollection(MongoCollection newCollection) { + this.collection = newCollection; + } + + /** + * Sets the Mongo Collection object. + * @param database the mongo DB database of the collection + * @param collection the string value of the collection + */ + private void setCollection(MongoDatabase database, String collection) { + this.collection = database.getCollection(collection); + } + + /** + * List all the items in the collection. + * @return List of the items in the collection + */ + public List listAllCollectionItems() { + return this.getCollection().find().into(new ArrayList<>()); + } + + /** + * Checks if the collection contains any records. + * @return True if the collection is empty, false otherwise + */ + public boolean isCollectionEmpty() { + return this.getCollection().countDocuments() == 0; + } +} diff --git a/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDriverManager.java b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDriverManager.java new file mode 100644 index 000000000..a160d9b3c --- /dev/null +++ b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoDriverManager.java @@ -0,0 +1,108 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import com.mongodb.client.MongoCollection; +import io.github.openmaqs.base.BaseTestObject; +import io.github.openmaqs.base.DriverManager; +import io.github.openmaqs.utilities.logging.LoggingConfig; +import io.github.openmaqs.utilities.logging.LoggingEnabled; +import io.github.openmaqs.utilities.logging.MessageType; +import java.util.function.Supplier; +import org.bson.Document; + +/** + * The Mongo Driver Manager class. + */ +public class MongoDriverManager extends DriverManager { + + /** + * Cached copy of the connection driver. + */ + private MongoDBDriver driver; + + /** + * Initializes a new instance of the MongoDriverManager class. + * @param connectionString Client connection string + * @param databaseString Database connection string + * @param collectionString Mongo collection string + * @param testObject Test object this driver is getting added to + */ + public MongoDriverManager(String connectionString, String databaseString, + String collectionString, BaseTestObject testObject) { + super(() -> new MongoDBDriver( + MongoFactory.getCollection(connectionString, databaseString, collectionString)), testObject); + } + + /** + * Initializes a new instance of the MongoDriverManager class. + * @param getCollection Function for getting a Mongo collection connection + * @param testObject Test object this driver is getting added to + */ + public MongoDriverManager(Supplier getCollection, BaseTestObject testObject) { + super(getCollection, testObject); + } + + /** + * Override the Mongo driver. + * @param overrideDriver The new Mongo driver + */ + public void overrideDriver(MongoDBDriver overrideDriver) { + driver = overrideDriver; + this.setBaseDriver(new MongoDBDriver(overrideDriver.getCollection())); + } + + /** + * Override the Mongo driver - respects lazy loading. + * @param connectionString Connection string of mongo DB + * @param databaseString Database string to use + * @param collectionString Collection string to use + */ + public void overrideDriver(String connectionString, String databaseString, String collectionString) { + driver = null; + this.overrideDriverGet(() -> MongoFactory.getCollection(connectionString, databaseString, collectionString)); + } + + /** + * Override the Mongo driver - respects lazy loading. + * @param overrideCollectionConnection The new collection connection + */ + public void overrideDriver(Supplier> overrideCollectionConnection) { + driver = null; + this.overrideDriverGet(overrideCollectionConnection); + } + + /** + * Get the Mongo driver. + * @return The Mongo driver + */ + public MongoDBDriver getMongoDriver() { + // Create default Web Service Driver if null. + if (this.driver == null) { + MongoCollection temp = getBase().getCollection(); + + if (LoggingConfig.getLoggingEnabledSetting() == LoggingEnabled.NO) { + this.getLogger().logMessage(MessageType.INFORMATION, "Getting Mongo driver"); + } + + this.driver = new MongoDBDriver(temp); + } + return this.driver; + } + + protected void overrideDriverGet(Supplier> driverGet) { + this.getMongoDriver(); + } + + @Override + public void close() { + if (!this.isDriverInitialized()) { + return; + } + + driver.getMongoClient().close(); + this.baseDriver = null; + } +} diff --git a/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoFactory.java b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoFactory.java new file mode 100644 index 000000000..f50d74d33 --- /dev/null +++ b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoFactory.java @@ -0,0 +1,50 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import com.mongodb.MongoClientException; +import com.mongodb.MongoException; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import org.bson.Document; + +/** + * The Mongo Factory Class. + */ +public class MongoFactory { + + private MongoFactory() { + } + + /** + * Get the email client using connection information from the test run configuration. + * @return The email connection + */ + public static MongoCollection getDefaultCollection() { + return getCollection(MongoDBConfig.getConnectionString(), + MongoDBConfig.getDatabaseString(), MongoDBConfig.getCollectionString()); + } + + /** + * Get the email client using connection information from the test run configuration. + * @param connectionString the connection string + * @param databaseString the database string + * @param collectionString the collection string + * @return The email connection + */ + public static MongoCollection getCollection( + String connectionString, String databaseString, String collectionString) { + try (MongoClient mongoClient = MongoClients.create(connectionString)) { + MongoDatabase database = mongoClient.getDatabase(databaseString); + return database.getCollection(collectionString); + } catch (MongoClientException e) { + throw new MongoClientException("connection was not created"); + } catch (MongoException e) { + throw new MongoException("database does not exist"); + } + } +} diff --git a/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoTestObject.java b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoTestObject.java new file mode 100644 index 000000000..a9c98bea0 --- /dev/null +++ b/openmaqs-nosql/src/main/java/io/github/openmaqs/nosql/MongoTestObject.java @@ -0,0 +1,69 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import com.mongodb.client.MongoCollection; +import io.github.openmaqs.base.BaseTestObject; +import io.github.openmaqs.utilities.logging.ILogger; +import java.util.function.Supplier; +import org.bson.Document; + +/** + * The Mongo Test Object class. + */ +public class MongoTestObject extends BaseTestObject implements IMongoTestObject { + + /** + * Initializes a new instance of the MongoTestObject class. + * @param connectionString Client connection string + * @param databaseString Database connection string + * @param collectionString Mongo collection string + * @param logger The test's logger + * @param fullyQualifiedTestName The test's fully qualified test name + */ + public MongoTestObject(String connectionString, String databaseString, String collectionString, + ILogger logger, String fullyQualifiedTestName) { + super(logger, fullyQualifiedTestName); + this.getManagerStore().put((MongoDriverManager.class).getCanonicalName(), + new MongoDriverManager(connectionString,databaseString,collectionString, this)); + } + + /** + * {@inheritDoc} + */ + public MongoDriverManager getMongoDBManager() { + return this.getManagerStore().getDriver(MongoDriverManager.class.getCanonicalName()); + } + + /** + * {@inheritDoc} + */ + public MongoDBDriver getMongoDBDriver() { + return this.getMongoDBManager().getMongoDriver(); + } + + /** + * {@inheritDoc} + */ + public void overrideMongoDBDriver(String connectionString, String databaseString, String collectionString) { + this.getMongoDBManager().overrideDriver(connectionString, databaseString, collectionString); + } + + /** + * {@inheritDoc} + */ + public void overrideMongoDBDriver(MongoDBDriver driver) { + this.getManagerStore().put(MongoDriverManager.class.getCanonicalName(), + new MongoDriverManager(() -> driver, this)); + } + + /** + * {@inheritDoc} + */ + @Override + public void overrideMongoDBDriver(Supplier> overrideCollectionConnection) { + this.getMongoDBManager().overrideDriver(overrideCollectionConnection); + } +} diff --git a/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/BaseMongoUnitTest.java b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/BaseMongoUnitTest.java new file mode 100644 index 000000000..aaadacff7 --- /dev/null +++ b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/BaseMongoUnitTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import io.github.openmaqs.utilities.helper.TestCategories; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * The Base Mongo unit test class. + */ +public class BaseMongoUnitTest extends BaseMongoTest { + + /** + * Test the get mongo db driver. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetMongoDBDriver() { + this.setMongoDBDriver(new MongoDBDriver( + MongoDBConfig.getConnectionString(), MongoDBConfig.getDatabaseString(), MongoDBConfig.getCollectionString())); + MongoDBDriver mongoDBDriver = this.getMongoDBDriver(); + Assert.assertNotNull(mongoDBDriver, + "Checking that MongoDB Driver is not null through BaseMongoTest"); + } + + /** + * Test the set mongo db driver. + */ + @Test(groups = TestCategories.NOSQL) + public void testSetMongoDBDriver() { + this.setMongoDBDriver(new MongoDBDriver()); + int hashCode = this.getMongoDBDriver().hashCode(); + try { + this.setMongoDBDriver(new MongoDBDriver()); + } catch (Exception e) { + e.printStackTrace(); + } + int hashCode1 = this.getMongoDBDriver().hashCode(); + Assert.assertNotEquals(hashCode, hashCode1); + } + + /** + * Test the override connection driver with the mongo db driver. + */ + @Test(groups = TestCategories.NOSQL) + public void testOverrideConnectionDriverWithMongoDBDriver() { + this.setMongoDBDriver(new MongoDBDriver()); + overrideConnectionDriver(this.getMongoDBDriver()); + Assert.assertNotNull(getMongoDBDriver()); + overrideConnectionDriver(this.getBaseConnectionString(), + this.getBaseDatabaseString(), this.getBaseCollectionString()); + Assert.assertNotNull(getMongoDBDriver()); + } + + /** + * Test getting the connection string. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetBaseMongoConnectionStringTest() { + String connection = this.getBaseConnectionString(); + Assert.assertEquals(connection, "mongodb://localhost:27017", "connection strings do not match"); + } + + /** + * Test getting the database string. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetBaseMongoStringTest() { + String databaseString = this.getBaseDatabaseString(); + Assert.assertEquals(databaseString, "MongoDatabaseTest", "database string do not match"); + } + + /** + * Test getting the connection string. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetBaseMongoCollectionStringTest() { + String collection = this.getBaseCollectionString(); + Assert.assertEquals(collection, "MongoTestCollection", "collection strings do not match"); + } +} diff --git a/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBConfigUnitTest.java b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBConfigUnitTest.java new file mode 100644 index 000000000..cdd3a58fe --- /dev/null +++ b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBConfigUnitTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import io.github.openmaqs.utilities.helper.TestCategories; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * The Mongo Database Config unit test class. + */ +public class MongoDBConfigUnitTest { + + /** + * Test getting the connection string. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetMongoDBConnectionStringTest() { + String connection = MongoDBConfig.getConnectionString(); + Assert.assertEquals(connection, "mongodb://localhost:27017", "connection strings do not match"); + } + + /** + * Test getting the database string. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetMongoDBDatabaseStringTest() { + String databaseString = MongoDBConfig.getDatabaseString(); + Assert.assertEquals(databaseString, "MongoDatabaseTest", "database string do not match"); + } + + /** + * Test getting the connection string. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetMongoDBCollectionStringTest() { + String collection = MongoDBConfig.getCollectionString(); + Assert.assertEquals(collection, "MongoTestCollection", "collection strings do not match"); + } + + /** + * Test getting the timeout value. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetMongoDBQueryTimeout() { + int databaseTimeout = MongoDBConfig.getQueryTimeout(); + Assert.assertEquals(databaseTimeout, 30, "Timeout is incorrect"); + } +} diff --git a/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBDriverUnitTest.java b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBDriverUnitTest.java new file mode 100644 index 000000000..fc107e27b --- /dev/null +++ b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBDriverUnitTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoCollection; +import io.github.openmaqs.utilities.helper.TestCategories; +import org.bson.Document; +import org.testng.Assert; +import org.testng.annotations.Test; +import java.util.List; + +/** + * The Mongo Database Driver unit test class. + */ +public class MongoDBDriverUnitTest extends BaseMongoTest { + + /** + * Test setting up the mongo db driver. + */ + @Test(groups = TestCategories.NOSQL) + public void testMongoDBDriver() { + MongoCollection collection = MongoFactory.getDefaultCollection(); + MongoDBDriver driver = new MongoDBDriver(collection); + Assert.assertNotNull(driver); + + driver = new MongoDBDriver(MongoDBConfig.getConnectionString(), + MongoDBConfig.getDatabaseString(), MongoDBConfig.getConnectionString()); + Assert.assertNotNull(driver); + + driver = new MongoDBDriver(MongoDBConfig.getCollectionString()); + Assert.assertNotNull(driver); + } + + /** + * Test getting the mongo client. + */ + @Test(groups = TestCategories.NOSQL) + public void testGetMongoClient() { + this.setMongoDBDriver(new MongoDBDriver()); + MongoClient client = this.getMongoDBDriver().getMongoClient(); + Assert.assertNotNull(client); + } + + /** + * Test setting the mongo client. + */ + @Test(groups = TestCategories.NOSQL) + public void testSetMongoClient() { + this.setMongoDBDriver(new MongoDBDriver()); + this.getMongoDBDriver().setMongoClient(MongoDBConfig.getConnectionString()); + Assert.assertNotNull(this.getMongoDBDriver().getMongoClient()); + } + + /** + * Test the list all collection items helper function. + */ + @Test(groups = TestCategories.NOSQL) + public void testListAllCollectionItems() { + this.setMongoDBDriver(new MongoDBDriver()); + List collectionItems = this.getMongoDBDriver().listAllCollectionItems(); + for (Document bson : collectionItems){ + Assert.assertTrue(bson.containsKey("lid")); + } + + Assert.assertEquals(collectionItems.size(), 4); + } + + @Test(groups = TestCategories.NOSQL) + public void testIsCollectionEmpty() { + boolean collection = this.getMongoDBDriver().isCollectionEmpty(); + Assert.assertTrue(collection); + } + + /** + * Test the count all collection items helper function + */ + @Test(groups = TestCategories.NOSQL) + public void testCountAllItemsInCollection() { + Assert.assertEquals(this.getMongoDBDriver().getCollection().countDocuments(), 4); + } +} diff --git a/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBFunctionalUnitTest.java b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBFunctionalUnitTest.java new file mode 100644 index 000000000..f9b4e0227 --- /dev/null +++ b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDBFunctionalUnitTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import com.mongodb.client.model.Filters; +import io.github.openmaqs.utilities.helper.TestCategories; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * The Mongo Database Functional unit test class. + */ +public class MongoDBFunctionalUnitTest extends BaseMongoTest { + + /** + * Test the collection works as expected when getting the login id. + */ + @Test(groups = TestCategories.NOSQL) + public void testMongoGetLoginID() { + Bson filter = Filters.eq("lid", "test3"); + //String value = this.getMongoDBDriver().getCollection().find(filter).ToList()[0]["lid"].ToString(); + List value = this.getMongoDBDriver().getCollection().find(filter).into(new ArrayList<>()); + Assert.assertEquals(value.get(0).toString(), "test3"); + } + + /** + * Test the collection works as expected when running a query and returning the first result. + */ + @Test(groups = TestCategories.NOSQL) + public void testMongoQueryAndReturnFirst() { + Bson filter = Filters.eq("lid", "test3"); + // MongoCollection document = this.getMongoDBDriver().getCollection().find(filter).ToList().First(); + Document document = this.getMongoDBDriver().getCollection().find(filter).first(); + Assert.assertEquals(Objects.requireNonNull(document).get("lid").toString(), "test3"); + } + + /** + * Test the collection works as expected when finding a list with a key. + */ + @Test(groups = TestCategories.NOSQL) + public void testMongoFindListWithKey() { + //var filter = Builders.Filter.Exists("lid"); + Bson filter = Filters.exists("lid"); + List documentList = this.getMongoDBDriver().getCollection().find(filter).into(new ArrayList<>()); + + for (Document documents : documentList) { + Assert.assertNotEquals(documents.get("lid").toString(), ""); + } + Assert.assertEquals(documentList.size(), 4); + } + + /** + * Test the collection works as expected. + */ + @Test(groups = TestCategories.NOSQL) + public void testMongoLinqQuery() { + /* + QueryBuilder queries = + from e in this.getMongoDBDriver().getCollection() + where e["lid"] == "test1" + select e; + */ + + Bson filter = Filters.eq("lid", "test1"); + List retList = this.getMongoDBDriver().getCollection().find(filter).into(new ArrayList<>()); + + for (Document value : retList) { + Assert.assertEquals(value.get("lid"), "test1"); + } + } +} diff --git a/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDriverManagerUnitTest.java b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDriverManagerUnitTest.java new file mode 100644 index 000000000..674d3d0a9 --- /dev/null +++ b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoDriverManagerUnitTest.java @@ -0,0 +1,123 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + +import com.mongodb.client.MongoCollection; +import io.github.openmaqs.utilities.helper.TestCategories; +import org.bson.Document; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * The Mongo Driver Manager unit test class. + */ +public class MongoDriverManagerUnitTest extends BaseMongoTest{ + + /** + * Test overriding the default driver. + */ + @Test(groups = TestCategories.NOSQL) + public void respectDefaultDriverOverride() { + MongoDBDriver mongoDriver = new MongoDBDriver(); + this.getTestObject().getMongoDBManager().overrideDriver(mongoDriver); + Assert.assertEquals(mongoDriver.getCollection(), this.getMongoDBDriver().getCollection()); + Assert.assertEquals(mongoDriver.getDatabase(), this.getMongoDBDriver().getDatabase()); + Assert.assertEquals(mongoDriver.getMongoClient(), this.getMongoDBDriver().getMongoClient()); + } + + /** + * Override driver with the collection string. + */ + @Test(groups = TestCategories.NOSQL) + public void respectCollectionDriverOverride() { + // MongoDBConfig.GetConnectionString(), MongoDBConfig.GetDatabaseString(), collectionString + MongoDBDriver mongoDriver = new MongoDBDriver(MongoDBConfig.getCollectionString()); + this.getTestObject().getMongoDBManager().overrideDriver(mongoDriver); + Assert.assertEquals(mongoDriver.getCollection(), this.getMongoDBDriver().getCollection()); + } + + /** + * Override drive with all 3 connection parameters. + */ + @Test(groups = TestCategories.NOSQL) + public void respectDriverConnectionsOverride() { + MongoDBDriver mongoDriver = new MongoDBDriver(MongoDBConfig.getConnectionString(), + MongoDBConfig.getDatabaseString(), MongoDBConfig.getCollectionString()); + this.getTestObject().getMongoDBManager().overrideDriver(mongoDriver); + Assert.assertEquals(mongoDriver.getCollection(), this.getMongoDBDriver().getCollection()); + } + + /** + * Override driver directly. + */ + @Test(groups = TestCategories.NOSQL) + public void respectDirectDriverOverride() { + MongoDBDriver mongoDriver = new MongoDBDriver(MongoDBConfig.getCollectionString()); + this.setMongoDBDriver(mongoDriver); + Assert.assertEquals(mongoDriver.getCollection(), this.getMongoDBDriver().getCollection()); + } + + /** + * Override driver with new driver. + */ + @Test(groups = TestCategories.NOSQL) + public void respectNewDriverOverride() { + MongoDBDriver mongoDriver = new MongoDBDriver(MongoDBConfig.getCollectionString()); + this.getTestObject().overrideMongoDBDriver(mongoDriver); + Assert.assertEquals(mongoDriver.getCollection(), this.getMongoDBDriver().getCollection()); + } + + /** + * Override drive with collection function. + */ + @Test(groups = TestCategories.NOSQL) + public void respectCollectionOverride() { + MongoCollection collection = MongoFactory.getDefaultCollection(); + this.getTestObject().overrideMongoDBDriver(() -> collection); + Assert.assertEquals(collection, this.getMongoDBDriver().getCollection()); + } + + /** + * Override drive with all 3 connection strings. + */ + @Test(groups = TestCategories.NOSQL) + public void respectDriverConnectionStingsOverride() { + MongoCollection collection = this.getMongoDBDriver().getCollection(); + this.getTestObject().overrideMongoDBDriver(MongoDBConfig.getConnectionString(), + MongoDBConfig.getDatabaseString(), MongoDBConfig.getCollectionString()); + Assert.assertNotEquals(collection, this.getMongoDBDriver().getCollection()); + } + + /** + * Override in base with collection function. + */ + @Test(groups = TestCategories.NOSQL) + public void respectCollectionOverrideInBase() { + MongoCollection collection = MongoFactory.getDefaultCollection(); + this.overrideConnectionDriver(() -> collection); + Assert.assertEquals(collection, this.getMongoDBDriver().getCollection()); + } + + /** + * Override in base with new driver. + */ + @Test(groups = TestCategories.NOSQL) + public void RespectDriverOverrideInBase() { + MongoCollection collection = MongoFactory.getDefaultCollection(); + this.overrideConnectionDriver(new MongoDBDriver(collection)); + Assert.assertEquals(collection, this.getMongoDBDriver().getCollection()); + } + + /** + * Override drive with strings in base. + */ + @Test(groups = TestCategories.NOSQL) + public void RespectConnectionStingsOverrideInBase() { + MongoCollection collection = this.getMongoDBDriver().getCollection(); + this.overrideConnectionDriver(MongoDBConfig.getConnectionString(), + MongoDBConfig.getDatabaseString(), MongoDBConfig.getCollectionString()); + Assert.assertNotEquals(collection, this.getMongoDBDriver().getCollection()); + } +} diff --git a/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoTestObjectUnitTest.java b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoTestObjectUnitTest.java new file mode 100644 index 000000000..f38120d37 --- /dev/null +++ b/openmaqs-nosql/src/test/java/io/github/openmaqs/nosql/MongoTestObjectUnitTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2023 (C) OpenMAQS, All rights Reserved + */ + +package io.github.openmaqs.nosql; + + +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.client.MongoCollection; +import io.github.openmaqs.utilities.helper.TestCategories; +import org.bson.Document; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * The Mongo Test Object unit test class. + */ +public class MongoTestObjectUnitTest extends BaseMongoTest { + + /** + * Tests if the collection override is respected. + */ + @Test(groups = TestCategories.NOSQL) + public void overrideCollectionFunction() { + MongoCollection collection = this.getMongoDBDriver().getCollection(); + MongoCollection newCollection = MongoFactory.getDefaultCollection(); + + this.getTestObject().overrideMongoDBDriver(() -> newCollection); + Assert.assertNotEquals(collection, this.getMongoDBDriver().getCollection()); + Assert.assertEquals(newCollection, this.getMongoDBDriver().getCollection()); + Assert.assertFalse(this.getMongoDBDriver().isCollectionEmpty()); + } + + /** + * Tests if the connection string overrides respected. + */ + @Test(groups = TestCategories.NOSQL) + public void overrideConnectionStrings() { + MongoCollection collection = this.getMongoDBDriver().getCollection(); + this.getTestObject().overrideMongoDBDriver(MongoDBConfig.getConnectionString(), + MongoDBConfig.getDatabaseString(), MongoDBConfig.getCollectionString()); + + Assert.assertNotEquals(collection, this.getMongoDBDriver().getCollection()); + Assert.assertFalse(this.getMongoDBDriver().isCollectionEmpty()); + } + + /** + * Tests if the driver override respected. + */ + @Test(groups = TestCategories.NOSQL) + public void overrideDriver() { + MongoDBDriver firstDriver = this.getMongoDBDriver(); + MongoDBDriver newDriver = new MongoDBDriver(MongoFactory.getDefaultCollection()); + this.getTestObject().overrideMongoDBDriver(newDriver); + + Assert.assertNotEquals(firstDriver, this.getMongoDBDriver()); + Assert.assertEquals(newDriver, this.getMongoDBDriver()); + Assert.assertFalse(this.getMongoDBDriver().isCollectionEmpty()); + } + + /** + * Tests if the custom driver is overridable. + */ + @Test(groups = TestCategories.NOSQL) + public void overrideWithCustomDriver() { + MongoDBDriver firstDriver = this.getMongoDBDriver(); + + MongoClientSettings settings = MongoClientSettings.builder() + .applyConnectionString(new ConnectionString(MongoDBConfig.getConnectionString())) + .build(); + + MongoDBDriver newDriver = new MongoDBDriver(settings, + MongoDBConfig.getDatabaseString(), MongoDBConfig.getCollectionString()); + this.getTestObject().overrideMongoDBDriver(newDriver); + + Assert.assertNotEquals(firstDriver, this.getMongoDBDriver()); + Assert.assertEquals(newDriver, this.getMongoDBDriver()); + Assert.assertFalse(this.getMongoDBDriver().isCollectionEmpty()); + } + + /** + * Make sure the test objects map properly. + */ + @Test(groups = TestCategories.NOSQL) + public void TestMongoDBTestObjectMapCorrectly() { + Assert.assertEquals(this.getTestObject().getLogger(), this.getLogger(), "Logs don't match"); + //Assert.assertEquals(this.getTestObject().getPerfTimerCollection(), this.getPerfTimerCollection(), "Perf Timer Collections don't match"); + Assert.assertEquals(this.getTestObject().getMongoDBDriver(), this.getMongoDBDriver(), "Web service driver don't match"); + } +} diff --git a/openmaqs-utilities/src/main/java/io/github/openmaqs/utilities/helper/ConfigSection.java b/openmaqs-utilities/src/main/java/io/github/openmaqs/utilities/helper/ConfigSection.java index e25f2a3f1..739ea40ff 100644 --- a/openmaqs-utilities/src/main/java/io/github/openmaqs/utilities/helper/ConfigSection.java +++ b/openmaqs-utilities/src/main/java/io/github/openmaqs/utilities/helper/ConfigSection.java @@ -40,6 +40,11 @@ public enum ConfigSection { */ GLOBAL_MAQS("GlobalMaqs"), + /** + * The default no sql maqs section. + */ + NOSQL_MAQS("NoSQLMaqs"), + /** * The default playwright maqs section. */ diff --git a/openmaqs-utilities/src/main/java/io/github/openmaqs/utilities/helper/TestCategories.java b/openmaqs-utilities/src/main/java/io/github/openmaqs/utilities/helper/TestCategories.java index b1b039eb7..86a2fc60a 100644 --- a/openmaqs-utilities/src/main/java/io/github/openmaqs/utilities/helper/TestCategories.java +++ b/openmaqs-utilities/src/main/java/io/github/openmaqs/utilities/helper/TestCategories.java @@ -42,6 +42,11 @@ private TestCategories() { */ public static final String FRAMEWORK = "Base Framework Unit Tests"; + /** + * String for no sql unit test category. + */ + public static final String NOSQL = "No SQL Framework Unit Tests"; + /** * String for playwright unit test category. */ diff --git a/pom.xml b/pom.xml index c571fb4bb..7cc7220a6 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,7 @@ openmaqs-appium openmaqs-webservices openmaqs-database + openmaqs-nosql openmaqs-cucumber openmaqs-accessibility openmaqs-playwright