From da7e2bae87e8985ff092e3bcc66302eb08e4777a Mon Sep 17 00:00:00 2001 From: Robert Wroblewski Date: Tue, 26 May 2020 16:25:41 -0500 Subject: [PATCH 01/21] Initial POC of Testing JUnit 5 Support in JMAQS * Created Custom TestResult interface and Implementation to pass to set the TestResult of the test instance * Created a TestWatcher implementation to catch test failure and successes since JUnit doesn't provide their own test result * Added RegisterExtension Annotation to BaseGenericTest to register the Custom test watcher programmatically so that we can provide the test instance in the constructor * Added appropriate Annotations for test lifecycle to BaseTest along with ExtensionContext and TestResult to replace ITestContext and ITestResult used by TestNG * Created Test to see if junit and TestNG can be used in the same test class * Created Copy of Test class with many tests using JUnit * Updated base pom to include junit-api and junit-engine dependencies * Created a properties file to run the JUnit tests in parallel --- jmaqs-base/pom.xml | 10 + .../magenic/jmaqs/base/BaseGenericTest.java | 11 +- .../java/com/magenic/jmaqs/base/BaseTest.java | 78 +++++ .../base/interfaces/JunitTestResult.java | 22 ++ .../jmaqs/base/interfaces/TestResult.java | 9 + .../jmaqs/base/watcher/JunitTestWatcher.java | 32 ++ .../jmaqs/base/BaseGenericTestUnitTest.java | 5 + .../base/JUnit_BaseTestObjectUnitTest.java | 312 ++++++++++++++++++ .../test/resources/junit-platform.properties | 3 + 9 files changed, 481 insertions(+), 1 deletion(-) create mode 100644 jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/JunitTestResult.java create mode 100644 jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/TestResult.java create mode 100644 jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java create mode 100644 jmaqs-base/src/test/java/com/magenic/jmaqs/base/JUnit_BaseTestObjectUnitTest.java create mode 100644 jmaqs-base/src/test/resources/junit-platform.properties diff --git a/jmaqs-base/pom.xml b/jmaqs-base/pom.xml index b35d5f60d..1dbd0b27d 100644 --- a/jmaqs-base/pom.xml +++ b/jmaqs-base/pom.xml @@ -32,5 +32,15 @@ testng 7.1.0 + + org.junit.jupiter + junit-jupiter-api + 5.6.2 + + + org.junit.jupiter + junit-jupiter-engine + 5.6.2 + diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseGenericTest.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseGenericTest.java index a9344ba2a..17fc23b86 100644 --- a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseGenericTest.java +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseGenericTest.java @@ -4,6 +4,8 @@ package com.magenic.jmaqs.base; +import com.magenic.jmaqs.base.watcher.JunitTestWatcher; +import org.junit.jupiter.api.extension.RegisterExtension; import org.testng.ITestResult; /** @@ -11,6 +13,13 @@ */ public class BaseGenericTest extends BaseExtendableTest { + @RegisterExtension + public JunitTestWatcher testWatcher; + + public BaseGenericTest() { + this.testWatcher = new JunitTestWatcher(this); + } + @Override protected void beforeLoggingTeardown(ITestResult resultType) { //No before logging steps needed in this scenario @@ -19,6 +28,6 @@ protected void beforeLoggingTeardown(ITestResult resultType) { @Override protected void createNewTestObject() { this.setTestObject( - new BaseTestObject(this.createLogger(), this.getFullyQualifiedTestClassName())); + new BaseTestObject(this.createLogger(), this.getFullyQualifiedTestClassName())); } } \ No newline at end of file diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java index 1d3c5b9b2..6fde719cc 100644 --- a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java @@ -6,6 +6,7 @@ import static java.lang.System.out; +import com.magenic.jmaqs.base.interfaces.TestResult; import com.magenic.jmaqs.utilities.helper.StringProcessor; import com.magenic.jmaqs.utilities.logging.ConsoleLogger; import com.magenic.jmaqs.utilities.logging.FileLogger; @@ -15,6 +16,7 @@ import com.magenic.jmaqs.utilities.logging.MessageType; import com.magenic.jmaqs.utilities.logging.TestResultType; import com.magenic.jmaqs.utilities.performance.PerfTimerCollection; + import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Paths; @@ -25,6 +27,12 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ExtensionContext; import org.testng.ITestContext; import org.testng.ITestResult; import org.testng.annotations.AfterMethod; @@ -50,6 +58,8 @@ public abstract class BaseTest { */ private ITestResult testResult; + private TestResult junitTestResult; + /** * The Collection of Base Test Objects to use. */ @@ -65,6 +75,8 @@ public abstract class BaseTest { */ private ITestContext testContextInstance; + private ExtensionContext context; + /** * The Fully Qualified Test Class Name. */ @@ -228,6 +240,18 @@ public void setup(Method method, ITestContext testContext) { this.createNewTestObject(); } + @BeforeEach + public void setup(TestInfo info) { + //this.context = context; + + // Get the Fully Qualified Test Class Name and set it in the object + String testName = info.getTestClass().get().getName() + "." + info.getTestMethod().get().getName(); + testName = testName.replaceFirst("class ", ""); + this.fullyQualifiedTestClassName.set(testName); + + this.createNewTestObject(); + } + /** * Cleanup after a test. */ @@ -276,6 +300,54 @@ public void teardown() { this.fullyQualifiedTestClassName.remove(); } + /** + * Cleanup after a test. + */ + //@AfterEach + public void teardown_junit() { +// try { +// this.beforeLoggingTeardown(junitTestResult); +// } catch (Exception e) { +// this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); +// } + + // Log the test result + if (junitTestResult.getStatus() == TestResultType.PASS) { + this.tryToLog(MessageType.SUCCESS, "Test Passed"); + } else if (junitTestResult.getStatus() == TestResultType.FAIL) { + this.tryToLog(MessageType.ERROR, "Test Failed"); + } else if (junitTestResult.getStatus() == TestResultType.SKIP) { + this.tryToLog(MessageType.INFORMATION, "Test was skipped"); + } else { + this.tryToLog(MessageType.WARNING, "Test had an unexpected result."); + } + + // Cleanup log files we don't want + try { + if ((this.getLogger() instanceof FileLogger) && junitTestResult.getStatus() == TestResultType.PASS + && this.loggingEnabledSetting == LoggingEnabled.ONFAIL) { + Files.delete(Paths.get(((FileLogger) this.getLogger()).getFilePath())); + } + } catch (Exception e) { + this.tryToLog(MessageType.WARNING, "Failed to cleanup log files because: %s", e.getMessage()); + } + + // Get the Fully Qualified Test Name + String fullyQualifiedTestName = this.fullyQualifiedTestClassName.get(); + + try (BaseTestObject baseTestObject = this.getTestObject()) { + // Release logged messages + this.loggedExceptions.remove(fullyQualifiedTestName); + + // Release the Base Test Object + this.baseTestObjects.remove(fullyQualifiedTestName, baseTestObject); + } + + // Create console logger to log subsequent messages + this.setTestObject(new BaseTestObject(new ConsoleLogger(), fullyQualifiedTestName)); + this.fullyQualifiedTestClassName.remove(); + } + /** * Set the test result after each test execution. * @@ -287,6 +359,12 @@ public void setTestResult(ITestResult testResult) { this.testResult = testResult; } + //@AfterEach + public void setTestResult(TestResult testResult, ExtensionContext context) { + this.context = context; + this.junitTestResult = testResult; + } + /** * Steps to do before logging teardown results. * diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/JunitTestResult.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/JunitTestResult.java new file mode 100644 index 000000000..b332694c6 --- /dev/null +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/JunitTestResult.java @@ -0,0 +1,22 @@ +package com.magenic.jmaqs.base.interfaces; + + +import com.magenic.jmaqs.utilities.logging.TestResultType; + +public class JunitTestResult implements TestResult { + private TestResultType currentStatus; + + public JunitTestResult(TestResultType status) { + this.currentStatus = status; + } + + @Override + public TestResultType getStatus() { + return this.currentStatus; + } + + @Override + public boolean isSuccess() { + return currentStatus == TestResultType.PASS; + } +} diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/TestResult.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/TestResult.java new file mode 100644 index 000000000..54f6f283c --- /dev/null +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/TestResult.java @@ -0,0 +1,9 @@ +package com.magenic.jmaqs.base.interfaces; + +import com.magenic.jmaqs.utilities.logging.TestResultType; + +public interface TestResult { + TestResultType getStatus(); + + boolean isSuccess(); +} diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java new file mode 100644 index 000000000..76f8835ec --- /dev/null +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java @@ -0,0 +1,32 @@ +package com.magenic.jmaqs.base.watcher; + +import com.magenic.jmaqs.base.BaseTest; +import com.magenic.jmaqs.base.interfaces.JunitTestResult; +import com.magenic.jmaqs.utilities.logging.TestResultType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestWatcher; + +public class JunitTestWatcher implements TestWatcher { + /** + * Test instance of the test being executed per each thread + */ + ThreadLocal testInstance; + + public JunitTestWatcher(BaseTest testInstance) { + this.testInstance = new ThreadLocal<>(); + this.testInstance.set(testInstance); + } + + @Override + public void testSuccessful(ExtensionContext context) { + this.testInstance.get().setTestResult(new JunitTestResult(TestResultType.PASS), context); + this.testInstance.get().teardown_junit(); + } + + @Override + public void testFailed(ExtensionContext context, Throwable cause) { + this.testInstance.get().setTestResult(new JunitTestResult(TestResultType.FAIL), context); + this.testInstance.get().teardown_junit(); + } +} \ No newline at end of file diff --git a/jmaqs-base/src/test/java/com/magenic/jmaqs/base/BaseGenericTestUnitTest.java b/jmaqs-base/src/test/java/com/magenic/jmaqs/base/BaseGenericTestUnitTest.java index 1d6ad358e..ede506c2a 100644 --- a/jmaqs-base/src/test/java/com/magenic/jmaqs/base/BaseGenericTestUnitTest.java +++ b/jmaqs-base/src/test/java/com/magenic/jmaqs/base/BaseGenericTestUnitTest.java @@ -14,4 +14,9 @@ public class BaseGenericTestUnitTest extends BaseGenericTest { public void testCreateTestObject() { Assert.assertNotNull(this.getTestObject()); } + + @org.junit.jupiter.api.Test + public void testCreateTestObject_junit() { + Assert.assertNotNull(this.getTestObject()); + } } \ No newline at end of file diff --git a/jmaqs-base/src/test/java/com/magenic/jmaqs/base/JUnit_BaseTestObjectUnitTest.java b/jmaqs-base/src/test/java/com/magenic/jmaqs/base/JUnit_BaseTestObjectUnitTest.java new file mode 100644 index 000000000..aa1c809f5 --- /dev/null +++ b/jmaqs-base/src/test/java/com/magenic/jmaqs/base/JUnit_BaseTestObjectUnitTest.java @@ -0,0 +1,312 @@ +/* + * Copyright 2020 (C) Magenic, All rights Reserved + */ + +package com.magenic.jmaqs.base; + +import com.magenic.jmaqs.utilities.helper.TestCategories; +import com.magenic.jmaqs.utilities.logging.Logger; +import com.magenic.jmaqs.utilities.performance.PerfTimerCollection; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; + +import java.io.File; +import java.io.IOException; +import java.util.function.Supplier; + +/** + * The type Base test object test. + */ +public class JUnit_BaseTestObjectUnitTest extends BaseGenericTest { + + /** + * Test Constructor with Log and Method. + */ + @Test////(groups = TestCategories.FRAMEWORK) + public void testBaseTestObject1() { + final BaseTestObject testObject = this.getTestObject(); + + // final String methodName = this.method.getName(); + BaseTestObject baseTestObject = new BaseTestObject(testObject.getLogger(), "FakeTestName"); + Assertions.assertNotNull(baseTestObject, "Checking that Base Test Object instantiated correctly"); + } + + /** + * Test Constructor with Test Object. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testBaseTestObject2() { + final BaseTestObject testObject = this.getTestObject(); + BaseTestObject baseTestObject = new BaseTestObject(testObject); + Assertions.assertNotNull(baseTestObject, "Checking that Base Test Object instantiated correctly"); + + } + + /** + * Test set value. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testSetValue() { + BaseTestObject testObject = this.getTestObject(); + final String key = "SetKey"; + final String value = "SetKey Value"; + testObject.setValue(key, value); + Assertions.assertTrue(testObject.getValues().containsKey(key), "Checking that key exists in test object dictionary"); + Assertions.assertEquals(testObject.getValues().get(key), value, "Checking that value set correctly"); + } + + /** + * Test set object. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testSetObject() { + + BaseTestObject testObject = this.getTestObject(); + final String key = "SetObject"; + final Object object = new Object(); + testObject.setObject(key, object); + Assertions.assertTrue(testObject.getObjects().containsKey(key), "Checking that key exists in test object dictionary"); + Assertions.assertEquals(testObject.getObjects().get(key), object, "Checking that value set correctly"); + } + + /** + * Test get log. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testGetLog() { + BaseTestObject testObject = this.getTestObject(); + Assertions.assertNotNull(testObject.getLogger(), "Checking that logger is not null."); + } + + /** + * Test set log. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testSetLog() { + BaseTestObject testObject = this.getTestObject(); + final Logger logger = this.getLogger(); + testObject.setLogger(logger); + Assertions.assertEquals(testObject.getLogger(), logger, "Checking that logger set correctly."); + } + + /** + * Test Get Perf Collection Timer - Not Null. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testGetPerfTimerCollectionNotNull() { + BaseTestObject testObject = this.getTestObject(); + Assertions.assertNotNull(testObject.getPerfTimerCollection(), "Checking that logger is not null."); + } + + /** + * Test Set Perf Collection Timer - Get/Set. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testSetPerfTimerCollectionGetSet() { + BaseTestObject testObject = this.getTestObject(); + final PerfTimerCollection perfTimerCollection = new PerfTimerCollection(testObject.getLogger(), "FakeTestName"); + testObject.setPerfTimerCollection(perfTimerCollection); + Assertions.assertEquals(testObject.getPerfTimerCollection(), perfTimerCollection, + "Checking that perf timer collection set correctly."); + } + + /** + * Test get values. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testGetValues() { + BaseTestObject testObject = this.getTestObject(); + Assertions.assertNotNull(testObject.getValues(), "Checking that values is not null."); + } + + /** + * Test get objects. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testGetObjects() { + BaseTestObject testObject = this.getTestObject(); + Assertions.assertNotNull(testObject.getObjects(), "Checking that objects is not null."); + } + + /** + * Test Get Manager Store - Not Null. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testGetManagerStoreNotNull() { + BaseTestObject testObject = this.getTestObject(); + Assertions.assertNotNull(testObject.getManagerStore(), "Checking that objects is not null."); + } + + /** + * Test add driver manager. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testAddDriverManager() { + BaseTestObject testObject = this.getTestObject(); + final Supplier supplier = () -> null; + DriverManager driverManager = getDriverManager(testObject, supplier); + Assertions.assertEquals(testObject.getManagerStore().size(), 0, "Checking that manager store is empty"); + testObject.addDriverManager(driverManager); + Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + + } + + /** + * Test add driver manager - Overwrite True. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testAddDriverManagerTrue() { + BaseTestObject testObject = this.getTestObject(); + final Supplier supplier = () -> null; + final DriverManager driverManager = getDriverManager(testObject, supplier); + final DriverManager driverManager2 = getDriverManager(testObject, supplier); + Assertions.assertEquals(testObject.getManagerStore().size(), 0, "Checking that manager store is empty"); + testObject.addDriverManager(driverManager, true); + Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + testObject.addDriverManager(driverManager2, true); + Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + } + + /** + * Test add driver manager - Overwrite False. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testAddDriverManagerFalse() { + BaseTestObject testObject = this.getTestObject(); + final Supplier supplier = () -> null; + final DriverManager driverManager = getDriverManager(testObject, supplier); + + Assertions.assertEquals(testObject.getManagerStore().size(), 0, "Checking that manager store is empty"); + testObject.addDriverManager(driverManager, false); + Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + } + + /** + * Test add driver manager 2. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testAddDriverManager2() { + BaseTestObject testObject = this.getTestObject(); + final Supplier supplier = () -> null; + final DriverManager driverManager = getDriverManager(testObject, supplier); + final String key = "DriverManager1"; + Assertions.assertEquals(testObject.getManagerStore().size(), 0, "Checking that manager store is empty"); + testObject.addDriverManager(key, driverManager); + Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + Assertions.assertTrue(testObject.getManagerStore().containsKey(key), "Checking if key exists in Manager Store"); + } + + /** + * Test close. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testClose() { + BaseTestObject testObject = this.getTestObject(); + final Supplier supplier = () -> null; + final DriverManager driverManager = getDriverManager(testObject, supplier); + final String key = "DriverManager1"; + testObject.addDriverManager(key, driverManager); + testObject.close(); + Assertions.assertNull(testObject.getManagerStore(), "Checking that manager store has been closed"); + Assertions.assertEquals(testObject.getValues().size(), 0, "Checking if values in manager store are closed"); + + } + + /** + * Test add associated file. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testAddAssociatedFile() { + BaseTestObject testObject = this.getTestObject(); + File temp = null; + try { + temp = File.createTempFile("tempfile", ".tmp"); + } catch (IOException e) { + e.printStackTrace(); + } + assert temp.exists(); + + Assertions.assertTrue(testObject.addAssociatedFile(temp.getAbsolutePath()), "Checking that associated file was added"); + Assertions.assertEquals((testObject.getArrayOfAssociatedFiles()).length, 1, + "Checking that one file was added to array."); + } + + /** + * Test remove associated file. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testRemoveAssociatedFile() { + BaseTestObject testObject = this.getTestObject(); + File temp = null; + try { + temp = File.createTempFile("tempfile", ".tmp"); + } catch (IOException e) { + e.printStackTrace(); + } + assert temp.exists(); + final String path = temp.getAbsolutePath(); + + Assertions.assertTrue(testObject.addAssociatedFile(path), "Checking that associated file was added"); + Assertions.assertTrue(testObject.removeAssociatedFile(path), "Checking that assocai"); + } + + /** + * Test get array of associated files. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testGetArrayOfAssociatedFiles() { + BaseTestObject testObject = this.getTestObject(); + File temp = null; + try { + temp = File.createTempFile("tempfile", ".tmp"); + } catch (IOException e) { + e.printStackTrace(); + } + assert temp.exists(); + final String path = temp.getAbsolutePath(); + Assertions.assertTrue(testObject.addAssociatedFile(path), "Checking that associated file was added"); + Assertions.assertNotNull(testObject.getArrayOfAssociatedFiles(), "Checking that array is instantiated"); + Assertions.assertEquals(testObject.getArrayOfAssociatedFiles().length, 1, "Checking that array is not empty"); + } + + /** + * Test contains associated file. + */ + @Test//(groups = TestCategories.FRAMEWORK) + public void testContainsAssociatedFile() { + BaseTestObject testObject = this.getTestObject(); + File temp = null; + try { + temp = File.createTempFile("tempfile", ".tmp"); + } catch (IOException e) { + e.printStackTrace(); + } + assert temp.exists(); + final String path = temp.getAbsolutePath(); + Assertions.assertTrue(testObject.addAssociatedFile(path), "Checking that associated file was added"); + Assertions.assertNotNull(testObject.getArrayOfAssociatedFiles(), "Checking that array is instantiated"); + Assertions.assertTrue(testObject.containsAssociatedFile(path), "Checking if array contains file"); + } + + // Test Setup Objects + /* + * private Logger getLogger() { return new Logger() { + * + * @Override public void logMessage(MessageType messageType, String message, + * Object... args) { + * + * } + * + * @Override public void logMessage(String message, Object... args) { + * + * } }; } + */ + + private DriverManager getDriverManager(BaseTestObject testObject, Supplier supplier) { + return new DriverManager(supplier, testObject) { + @Override + public void close() throws Exception { + } + }; + } +} \ No newline at end of file diff --git a/jmaqs-base/src/test/resources/junit-platform.properties b/jmaqs-base/src/test/resources/junit-platform.properties new file mode 100644 index 000000000..85c81a9f2 --- /dev/null +++ b/jmaqs-base/src/test/resources/junit-platform.properties @@ -0,0 +1,3 @@ +junit.jupiter.execution.parallel.enabled=true +junit.jupiter.execution.parallel.mode.default=concurrent +junit.jupiter.execution.parallel.mode.classes.default=concurrent \ No newline at end of file From 1d5c27a74a5537f78e9a245b632d364f40b44121 Mon Sep 17 00:00:00 2001 From: Robert Wroblewski Date: Wed, 27 May 2020 17:07:54 -0500 Subject: [PATCH 02/21] Initial POC of Testing JUnit 5 Support in JMAQS * Removed threadlocal since TestWatcher is created for each test --- .../com/magenic/jmaqs/base/BaseGenericTest.java | 7 ------- .../main/java/com/magenic/jmaqs/base/BaseTest.java | 7 +++++++ .../jmaqs/base/watcher/JunitTestWatcher.java | 13 ++++++------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseGenericTest.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseGenericTest.java index 17fc23b86..571bea6a8 100644 --- a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseGenericTest.java +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseGenericTest.java @@ -13,13 +13,6 @@ */ public class BaseGenericTest extends BaseExtendableTest { - @RegisterExtension - public JunitTestWatcher testWatcher; - - public BaseGenericTest() { - this.testWatcher = new JunitTestWatcher(this); - } - @Override protected void beforeLoggingTeardown(ITestResult resultType) { //No before logging steps needed in this scenario diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java index 6fde719cc..7c67a0c5c 100644 --- a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java @@ -7,6 +7,7 @@ import static java.lang.System.out; import com.magenic.jmaqs.base.interfaces.TestResult; +import com.magenic.jmaqs.base.watcher.JunitTestWatcher; import com.magenic.jmaqs.utilities.helper.StringProcessor; import com.magenic.jmaqs.utilities.logging.ConsoleLogger; import com.magenic.jmaqs.utilities.logging.FileLogger; @@ -33,6 +34,7 @@ import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; import org.testng.ITestContext; import org.testng.ITestResult; import org.testng.annotations.AfterMethod; @@ -82,12 +84,17 @@ public abstract class BaseTest { */ ThreadLocal fullyQualifiedTestClassName = new ThreadLocal<>(); + @RegisterExtension + public JunitTestWatcher testWatcher; + + /** * Initializes a new instance of the BaseTest class. */ public BaseTest() { this.loggedExceptions = new ConcurrentHashMap<>(); this.baseTestObjects = new ConcurrentManagerHashMap(); + this.testWatcher = new JunitTestWatcher(this); } /** diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java index 76f8835ec..aea29f673 100644 --- a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java +++ b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java @@ -11,22 +11,21 @@ public class JunitTestWatcher implements TestWatcher { /** * Test instance of the test being executed per each thread */ - ThreadLocal testInstance; + BaseTest testInstance; public JunitTestWatcher(BaseTest testInstance) { - this.testInstance = new ThreadLocal<>(); - this.testInstance.set(testInstance); + this.testInstance = testInstance; } @Override public void testSuccessful(ExtensionContext context) { - this.testInstance.get().setTestResult(new JunitTestResult(TestResultType.PASS), context); - this.testInstance.get().teardown_junit(); + this.testInstance.setTestResult(new JunitTestResult(TestResultType.PASS), context); + this.testInstance.teardown_junit(); } @Override public void testFailed(ExtensionContext context, Throwable cause) { - this.testInstance.get().setTestResult(new JunitTestResult(TestResultType.FAIL), context); - this.testInstance.get().teardown_junit(); + this.testInstance.setTestResult(new JunitTestResult(TestResultType.FAIL), context); + this.testInstance.teardown_junit(); } } \ No newline at end of file From f418a2049359bff3126fb746c2f34a52175501a8 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Fri, 6 May 2022 12:31:44 -0500 Subject: [PATCH 03/21] pull in main --- maqs-base/pom.xml | 14 +++++++++ .../maqs/base/BaseGenericTest.java | 2 +- .../maqs/base/BaseTest.java | 4 ++- .../maqs/base/interfaces/JunitTestResult.java | 22 ++++++++++++++ .../maqs/base/interfaces/TestResult.java | 9 ++++++ .../maqs/base/watcher/JunitTestWatcher.java | 30 +++++++++++++++++++ .../test/resources/junit-platform.properties | 3 ++ 7 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java create mode 100644 maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java create mode 100644 maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java create mode 100644 maqs-base/src/test/resources/junit-platform.properties diff --git a/maqs-base/pom.xml b/maqs-base/pom.xml index 6c08f6fb6..f96e787c9 100644 --- a/maqs-base/pom.xml +++ b/maqs-base/pom.xml @@ -15,6 +15,10 @@ ${revision} jar + + 5.8.1 + + com.cognizantsoftvision.maqs.utilities @@ -24,5 +28,15 @@ org.testng testng + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseGenericTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseGenericTest.java index 5805791c2..19c15ca8f 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseGenericTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseGenericTest.java @@ -4,7 +4,7 @@ package com.cognizantsoftvision.maqs.base; -import com.magenic.jmaqs.base.watcher.JunitTestWatcher; +import com.cognizantsoftvision.maqs.base.watcher.JunitTestWatcher; import org.junit.jupiter.api.extension.RegisterExtension; import org.testng.ITestResult; diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index 1050704f9..566f433bf 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -7,6 +7,8 @@ import static java.lang.System.out; import com.cognizantsoftvision.maqs.base.exceptions.MAQSRuntimeException; +import com.cognizantsoftvision.maqs.base.interfaces.TestResult; +import com.cognizantsoftvision.maqs.base.watcher.JunitTestWatcher; import com.cognizantsoftvision.maqs.utilities.helper.StringProcessor; import com.cognizantsoftvision.maqs.utilities.logging.ConsoleLogger; import com.cognizantsoftvision.maqs.utilities.logging.FileLogger; @@ -356,7 +358,7 @@ public void teardown_junit() { // Get the Fully Qualified Test Name String fullyQualifiedTestName = this.fullyQualifiedTestClassName.get(); - try (BaseTestObject baseTestObject = this.getTestObject()) { + try (BaseTestObject baseTestObject = (BaseTestObject) this.getTestObject()) { // Release logged messages this.loggedExceptions.remove(fullyQualifiedTestName); diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java new file mode 100644 index 000000000..234fa3b02 --- /dev/null +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java @@ -0,0 +1,22 @@ +package com.cognizantsoftvision.maqs.base.interfaces; + + +import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; + +public class JunitTestResult implements TestResult { + private TestResultType currentStatus; + + public JunitTestResult(TestResultType status) { + this.currentStatus = status; + } + + @Override + public TestResultType getStatus() { + return this.currentStatus; + } + + @Override + public boolean isSuccess() { + return currentStatus == TestResultType.PASS; + } +} diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java new file mode 100644 index 000000000..42dd17b1e --- /dev/null +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java @@ -0,0 +1,9 @@ +package com.cognizantsoftvision.maqs.base.interfaces; + +import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; + +public interface TestResult { + TestResultType getStatus(); + + boolean isSuccess(); +} diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java new file mode 100644 index 000000000..ddfc9842c --- /dev/null +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java @@ -0,0 +1,30 @@ +package com.cognizantsoftvision.maqs.base.watcher; + +import com.cognizantsoftvision.maqs.base.BaseTest; +import com.cognizantsoftvision.maqs.base.interfaces.JunitTestResult; +import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestWatcher; + +public class JunitTestWatcher implements TestWatcher { + /** + * Test instance of the test being executed per each thread + */ + BaseTest testInstance; + + public JunitTestWatcher(BaseTest testInstance) { + this.testInstance = testInstance; + } + + @Override + public void testSuccessful(ExtensionContext context) { + this.testInstance.setTestResult(new JunitTestResult(TestResultType.PASS), context); + this.testInstance.teardown_junit(); + } + + @Override + public void testFailed(ExtensionContext context, Throwable cause) { + this.testInstance.setTestResult(new JunitTestResult(TestResultType.FAIL), context); + this.testInstance.teardown_junit(); + } +} \ No newline at end of file diff --git a/maqs-base/src/test/resources/junit-platform.properties b/maqs-base/src/test/resources/junit-platform.properties new file mode 100644 index 000000000..85c81a9f2 --- /dev/null +++ b/maqs-base/src/test/resources/junit-platform.properties @@ -0,0 +1,3 @@ +junit.jupiter.execution.parallel.enabled=true +junit.jupiter.execution.parallel.mode.default=concurrent +junit.jupiter.execution.parallel.mode.classes.default=concurrent \ No newline at end of file From 29aa53361a04da87a058e16e40da8722b2ce3729 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Fri, 6 May 2022 12:34:49 -0500 Subject: [PATCH 04/21] delete old base content, put junit content in the new maqs base --- jmaqs-base/pom.xml | 46 ------------------- .../base/interfaces/JunitTestResult.java | 22 --------- .../jmaqs/base/interfaces/TestResult.java | 9 ---- .../jmaqs/base/watcher/JunitTestWatcher.java | 31 ------------- .../test/resources/junit-platform.properties | 3 -- 5 files changed, 111 deletions(-) delete mode 100644 jmaqs-base/pom.xml delete mode 100644 jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/JunitTestResult.java delete mode 100644 jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/TestResult.java delete mode 100644 jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java delete mode 100644 jmaqs-base/src/test/resources/junit-platform.properties diff --git a/jmaqs-base/pom.xml b/jmaqs-base/pom.xml deleted file mode 100644 index 1dbd0b27d..000000000 --- a/jmaqs-base/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - 4.0.0 - - - com.magenic.jmaqs - jmaqs-framework - 2.0.1-SNAPSHOT - ../pom.xml - - - com.magenic.jmaqs.base - jmaqs-base - JMAQS Base Testing Module - jar - http://maven.apache.org - - - UTF-8 - 7.0.0 - 1.1.4 - 4.2.2 - - - - - com.magenic.jmaqs.utilities - jmaqs-utilities - ${project.version} - - - org.testng - testng - 7.1.0 - - - org.junit.jupiter - junit-jupiter-api - 5.6.2 - - - org.junit.jupiter - junit-jupiter-engine - 5.6.2 - - - diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/JunitTestResult.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/JunitTestResult.java deleted file mode 100644 index b332694c6..000000000 --- a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/JunitTestResult.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.magenic.jmaqs.base.interfaces; - - -import com.magenic.jmaqs.utilities.logging.TestResultType; - -public class JunitTestResult implements TestResult { - private TestResultType currentStatus; - - public JunitTestResult(TestResultType status) { - this.currentStatus = status; - } - - @Override - public TestResultType getStatus() { - return this.currentStatus; - } - - @Override - public boolean isSuccess() { - return currentStatus == TestResultType.PASS; - } -} diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/TestResult.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/TestResult.java deleted file mode 100644 index 54f6f283c..000000000 --- a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/interfaces/TestResult.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.magenic.jmaqs.base.interfaces; - -import com.magenic.jmaqs.utilities.logging.TestResultType; - -public interface TestResult { - TestResultType getStatus(); - - boolean isSuccess(); -} diff --git a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java b/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java deleted file mode 100644 index aea29f673..000000000 --- a/jmaqs-base/src/main/java/com/magenic/jmaqs/base/watcher/JunitTestWatcher.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.magenic.jmaqs.base.watcher; - -import com.magenic.jmaqs.base.BaseTest; -import com.magenic.jmaqs.base.interfaces.JunitTestResult; -import com.magenic.jmaqs.utilities.logging.TestResultType; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.api.extension.TestWatcher; - -public class JunitTestWatcher implements TestWatcher { - /** - * Test instance of the test being executed per each thread - */ - BaseTest testInstance; - - public JunitTestWatcher(BaseTest testInstance) { - this.testInstance = testInstance; - } - - @Override - public void testSuccessful(ExtensionContext context) { - this.testInstance.setTestResult(new JunitTestResult(TestResultType.PASS), context); - this.testInstance.teardown_junit(); - } - - @Override - public void testFailed(ExtensionContext context, Throwable cause) { - this.testInstance.setTestResult(new JunitTestResult(TestResultType.FAIL), context); - this.testInstance.teardown_junit(); - } -} \ No newline at end of file diff --git a/jmaqs-base/src/test/resources/junit-platform.properties b/jmaqs-base/src/test/resources/junit-platform.properties deleted file mode 100644 index 85c81a9f2..000000000 --- a/jmaqs-base/src/test/resources/junit-platform.properties +++ /dev/null @@ -1,3 +0,0 @@ -junit.jupiter.execution.parallel.enabled=true -junit.jupiter.execution.parallel.mode.default=concurrent -junit.jupiter.execution.parallel.mode.classes.default=concurrent \ No newline at end of file From ad127535edc344cc10391201ea0cebf0296039a8 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 13:17:31 -0500 Subject: [PATCH 05/21] updated and set JUnit tests up --- .../maqs/base/watcher/JunitTestWatcher.java | 7 + ....java => JUnitBaseTestObjectUnitTest.java} | 213 ++++++++++-------- 2 files changed, 124 insertions(+), 96 deletions(-) rename maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/{JUnit_BaseTestObjectUnitTest.java => JUnitBaseTestObjectUnitTest.java} (56%) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java index ddfc9842c..cc60a70fa 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java @@ -1,3 +1,7 @@ +/* + * Copyright 2022 (C) Cognizant SoftVision, All rights Reserved + */ + package com.cognizantsoftvision.maqs.base.watcher; import com.cognizantsoftvision.maqs.base.BaseTest; @@ -6,6 +10,9 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.TestWatcher; +/** + * The JUnit Test Watcher class. + */ public class JunitTestWatcher implements TestWatcher { /** * Test instance of the test being executed per each thread diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnit_BaseTestObjectUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java similarity index 56% rename from maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnit_BaseTestObjectUnitTest.java rename to maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java index aa1c809f5..4eb0218f9 100644 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnit_BaseTestObjectUnitTest.java +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java @@ -1,30 +1,32 @@ /* - * Copyright 2020 (C) Magenic, All rights Reserved + * Copyright 2022 (C) Cognizant SoftVision, All rights Reserved */ -package com.magenic.jmaqs.base; +package com.cognizantsoftvision.maqs.base; -import com.magenic.jmaqs.utilities.helper.TestCategories; -import com.magenic.jmaqs.utilities.logging.Logger; -import com.magenic.jmaqs.utilities.performance.PerfTimerCollection; +import com.cognizantsoftvision.maqs.utilities.helper.TestCategories; +import com.cognizantsoftvision.maqs.utilities.logging.ILogger; +import com.cognizantsoftvision.maqs.utilities.performance.PerfTimerCollection; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; - import java.io.File; import java.io.IOException; +import java.util.Objects; import java.util.function.Supplier; /** - * The type Base test object test. + * The JUnit Base Test Object unit test. */ -public class JUnit_BaseTestObjectUnitTest extends BaseGenericTest { +class JUnitBaseTestObjectUnitTest extends BaseGenericTest { /** * Test Constructor with Log and Method. */ - @Test////(groups = TestCategories.FRAMEWORK) - public void testBaseTestObject1() { - final BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testBaseTestObject1() { + final ITestObject testObject = this.getTestObject(); // final String methodName = this.method.getName(); BaseTestObject baseTestObject = new BaseTestObject(testObject.getLogger(), "FakeTestName"); @@ -34,9 +36,10 @@ public void testBaseTestObject1() { /** * Test Constructor with Test Object. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testBaseTestObject2() { - final BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testBaseTestObject2() { + final ITestObject testObject = this.getTestObject(); BaseTestObject baseTestObject = new BaseTestObject(testObject); Assertions.assertNotNull(baseTestObject, "Checking that Base Test Object instantiated correctly"); @@ -45,9 +48,10 @@ public void testBaseTestObject2() { /** * Test set value. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testSetValue() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testSetValue() { + ITestObject testObject = this.getTestObject(); final String key = "SetKey"; final String value = "SetKey Value"; testObject.setValue(key, value); @@ -58,10 +62,10 @@ public void testSetValue() { /** * Test set object. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testSetObject() { - - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testSetObject() { + ITestObject testObject = this.getTestObject(); final String key = "SetObject"; final Object object = new Object(); testObject.setObject(key, object); @@ -72,19 +76,21 @@ public void testSetObject() { /** * Test get log. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testGetLog() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testGetLog() { + ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getLogger(), "Checking that logger is not null."); } /** * Test set log. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testSetLog() { - BaseTestObject testObject = this.getTestObject(); - final Logger logger = this.getLogger(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testSetLog() { + ITestObject testObject = this.getTestObject(); + final ILogger logger = this.getLogger(); testObject.setLogger(logger); Assertions.assertEquals(testObject.getLogger(), logger, "Checking that logger set correctly."); } @@ -92,18 +98,20 @@ public void testSetLog() { /** * Test Get Perf Collection Timer - Not Null. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testGetPerfTimerCollectionNotNull() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testGetPerfTimerCollectionNotNull() { + ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getPerfTimerCollection(), "Checking that logger is not null."); } /** * Test Set Perf Collection Timer - Get/Set. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testSetPerfTimerCollectionGetSet() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testSetPerfTimerCollectionGetSet() { + ITestObject testObject = this.getTestObject(); final PerfTimerCollection perfTimerCollection = new PerfTimerCollection(testObject.getLogger(), "FakeTestName"); testObject.setPerfTimerCollection(perfTimerCollection); Assertions.assertEquals(testObject.getPerfTimerCollection(), perfTimerCollection, @@ -113,175 +121,189 @@ public void testSetPerfTimerCollectionGetSet() { /** * Test get values. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testGetValues() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testGetValues() { + ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getValues(), "Checking that values is not null."); } /** * Test get objects. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testGetObjects() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testGetObjects() { + ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getObjects(), "Checking that objects is not null."); } /** * Test Get Manager Store - Not Null. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testGetManagerStoreNotNull() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testGetManagerStoreNotNull() { + ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getManagerStore(), "Checking that objects is not null."); } /** * Test add driver manager. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testAddDriverManager() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testAddDriverManager() { + ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; DriverManager driverManager = getDriverManager(testObject, supplier); - Assertions.assertEquals(testObject.getManagerStore().size(), 0, "Checking that manager store is empty"); + Assertions.assertEquals(0, testObject.getManagerStore().size(), "Checking that manager store is empty"); testObject.addDriverManager(driverManager); - Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + Assertions.assertEquals(1, testObject.getManagerStore().size(), "Checking that manager store has 1 object added"); } /** * Test add driver manager - Overwrite True. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testAddDriverManagerTrue() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testAddDriverManagerTrue() { + ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; final DriverManager driverManager = getDriverManager(testObject, supplier); final DriverManager driverManager2 = getDriverManager(testObject, supplier); - Assertions.assertEquals(testObject.getManagerStore().size(), 0, "Checking that manager store is empty"); + Assertions.assertEquals( 0, testObject.getManagerStore().size(), "Checking that manager store is empty"); testObject.addDriverManager(driverManager, true); - Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + Assertions.assertEquals(1, testObject.getManagerStore().size(), "Checking that manager store has 1 object added"); testObject.addDriverManager(driverManager2, true); - Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + Assertions.assertEquals(1, testObject.getManagerStore().size(), "Checking that manager store has 1 object added"); } /** * Test add driver manager - Overwrite False. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testAddDriverManagerFalse() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testAddDriverManagerFalse() { + ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; final DriverManager driverManager = getDriverManager(testObject, supplier); - Assertions.assertEquals(testObject.getManagerStore().size(), 0, "Checking that manager store is empty"); + Assertions.assertEquals(0, testObject.getManagerStore().size(), "Checking that manager store is empty"); testObject.addDriverManager(driverManager, false); - Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + Assertions.assertEquals(1, testObject.getManagerStore().size(), "Checking that manager store has 1 object added"); } /** * Test add driver manager 2. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testAddDriverManager2() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testAddDriverManager2() { + ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; final DriverManager driverManager = getDriverManager(testObject, supplier); final String key = "DriverManager1"; - Assertions.assertEquals(testObject.getManagerStore().size(), 0, "Checking that manager store is empty"); + Assertions.assertEquals(0, testObject.getManagerStore().size(), "Checking that manager store is empty"); testObject.addDriverManager(key, driverManager); - Assertions.assertEquals(testObject.getManagerStore().size(), 1, "Checking that manager store has 1 object added"); + Assertions.assertEquals(1, testObject.getManagerStore().size(), "Checking that manager store has 1 object added"); Assertions.assertTrue(testObject.getManagerStore().containsKey(key), "Checking if key exists in Manager Store"); } /** * Test close. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testClose() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testClose() throws Exception { + ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; final DriverManager driverManager = getDriverManager(testObject, supplier); final String key = "DriverManager1"; testObject.addDriverManager(key, driverManager); testObject.close(); Assertions.assertNull(testObject.getManagerStore(), "Checking that manager store has been closed"); - Assertions.assertEquals(testObject.getValues().size(), 0, "Checking if values in manager store are closed"); + Assertions.assertEquals(0, testObject.getValues().size(), "Checking if values in manager store are closed"); } /** * Test add associated file. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testAddAssociatedFile() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testAddAssociatedFile() { + ITestObject testObject = this.getTestObject(); File temp = null; try { - temp = File.createTempFile("tempfile", ".tmp"); + temp = File.createTempFile("tempFile", ".tmp"); } catch (IOException e) { e.printStackTrace(); } - assert temp.exists(); + Assertions.assertTrue(Objects.requireNonNull(temp).exists()); Assertions.assertTrue(testObject.addAssociatedFile(temp.getAbsolutePath()), "Checking that associated file was added"); - Assertions.assertEquals((testObject.getArrayOfAssociatedFiles()).length, 1, - "Checking that one file was added to array."); + Assertions.assertEquals(1, testObject.getArrayOfAssociatedFiles().length, "Checking that one file was added to array."); } /** * Test remove associated file. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testRemoveAssociatedFile() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testRemoveAssociatedFile() { + ITestObject testObject = this.getTestObject(); File temp = null; try { - temp = File.createTempFile("tempfile", ".tmp"); + temp = File.createTempFile("tempFile", ".tmp"); } catch (IOException e) { e.printStackTrace(); } - assert temp.exists(); + + Assertions.assertTrue(Objects.requireNonNull(temp).exists()); final String path = temp.getAbsolutePath(); Assertions.assertTrue(testObject.addAssociatedFile(path), "Checking that associated file was added"); - Assertions.assertTrue(testObject.removeAssociatedFile(path), "Checking that assocai"); + Assertions.assertTrue(testObject.removeAssociatedFile(path), "Checking that associated file was removed"); } /** * Test get array of associated files. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testGetArrayOfAssociatedFiles() { - BaseTestObject testObject = this.getTestObject(); + @Test + @Tag(TestCategories.FRAMEWORK) + void testGetArrayOfAssociatedFiles() { + ITestObject testObject = this.getTestObject(); File temp = null; try { - temp = File.createTempFile("tempfile", ".tmp"); + temp = File.createTempFile("tempFile", ".tmp"); } catch (IOException e) { e.printStackTrace(); } - assert temp.exists(); + + Assertions.assertTrue(Objects.requireNonNull(temp).exists()); final String path = temp.getAbsolutePath(); Assertions.assertTrue(testObject.addAssociatedFile(path), "Checking that associated file was added"); Assertions.assertNotNull(testObject.getArrayOfAssociatedFiles(), "Checking that array is instantiated"); - Assertions.assertEquals(testObject.getArrayOfAssociatedFiles().length, 1, "Checking that array is not empty"); + Assertions.assertEquals(1, testObject.getArrayOfAssociatedFiles().length, "Checking that array is not empty"); } /** * Test contains associated file. */ - @Test//(groups = TestCategories.FRAMEWORK) - public void testContainsAssociatedFile() { - BaseTestObject testObject = this.getTestObject(); + @Test() + @Tag(TestCategories.FRAMEWORK) + void testContainsAssociatedFile() { + ITestObject testObject = this.getTestObject(); File temp = null; try { - temp = File.createTempFile("tempfile", ".tmp"); + temp = File.createTempFile("tempFile", ".tmp"); } catch (IOException e) { e.printStackTrace(); } - assert temp.exists(); + + Assertions.assertTrue(Objects.requireNonNull(temp).exists()); final String path = temp.getAbsolutePath(); Assertions.assertTrue(testObject.addAssociatedFile(path), "Checking that associated file was added"); Assertions.assertNotNull(testObject.getArrayOfAssociatedFiles(), "Checking that array is instantiated"); @@ -302,10 +324,9 @@ public void testContainsAssociatedFile() { * } }; } */ - private DriverManager getDriverManager(BaseTestObject testObject, Supplier supplier) { - return new DriverManager(supplier, testObject) { - @Override - public void close() throws Exception { + private DriverManager getDriverManager(ITestObject testObject, Supplier supplier) { + return new DriverManager<>(supplier, testObject) { + @Override public void close() { } }; } From 8d8971ca3b7ac330783440a55f7076b9a2c3bb0d Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:49:48 -0500 Subject: [PATCH 06/21] comments and copyright update --- .../maqs/base/BaseTest.java | 68 ++++++++++--------- .../maqs/base/interfaces/JunitTestResult.java | 19 +++--- .../maqs/base/interfaces/TestResult.java | 4 ++ .../maqs/base/watcher/JunitTestWatcher.java | 5 +- 4 files changed, 53 insertions(+), 43 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index 566f433bf..c5b1e1b72 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -20,6 +20,7 @@ import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; import com.cognizantsoftvision.maqs.utilities.performance.IPerfTimerCollection; import com.cognizantsoftvision.maqs.utilities.performance.PerfTimerCollection; + import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Paths; @@ -30,10 +31,10 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.RegisterExtension; import org.testng.ITestContext; @@ -85,9 +86,7 @@ public abstract class BaseTest { */ ThreadLocal fullyQualifiedTestClassName = new ThreadLocal<>(); - @RegisterExtension - public JunitTestWatcher testWatcher; - + @RegisterExtension public JunitTestWatcher testWatcher; /** * Initializes a new instance of the BaseTest class. @@ -173,7 +172,8 @@ public List getLoggedExceptions() { * @param loggedExceptionList ArrayList of logged exceptions to use. */ public void setLoggedExceptions(List loggedExceptionList) { - this.loggedExceptions.put(this.fullyQualifiedTestClassName.get(), (ArrayList) loggedExceptionList); + this.loggedExceptions.put(this.fullyQualifiedTestClassName.get(), + (ArrayList) loggedExceptionList); } /** @@ -231,13 +231,12 @@ public void setTestObject(BaseTestObject baseTestObject) { } /** - * Setup before a test. + * Setup before a testng unit test. * * @param method The initial executing Method object * @param testContext The initial executing Test Context object */ - @BeforeMethod(alwaysRun = true) - public void setup(Method method, ITestContext testContext) { + @BeforeMethod(alwaysRun = true) public void setup(Method method, ITestContext testContext) { this.testContextInstance = testContext; // Get the Fully Qualified Test Class Name and set it in the object @@ -260,12 +259,17 @@ public void customSetup(String testName, ITestContext testContext) { this.createNewTestObject(); } - @BeforeEach - public void setup(TestInfo info) { + /** + * Setup before a JUnit test. + * + * @param info the test info of the unit test being run + */ + @BeforeEach public void setup(TestInfo info) { //this.context = context; // Get the Fully Qualified Test Class Name and set it in the object - String testName = info.getTestClass().get().getName() + "." + info.getTestMethod().get().getName(); + String testName = + info.getTestClass().get().getName() + "." + info.getTestMethod().get().getName(); testName = testName.replaceFirst("class ", ""); this.fullyQualifiedTestClassName.set(testName); @@ -273,14 +277,14 @@ public void setup(TestInfo info) { } /** - * Cleanup after a test. + * Cleanup after a TestNG test. */ - @AfterMethod(alwaysRun = true) - public void teardown() { + @AfterMethod(alwaysRun = true) public void teardown() { try { this.beforeLoggingTeardown(testResult); } catch (Exception e) { - this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); + this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", + e.getMessage()); } // Log the test result @@ -324,15 +328,14 @@ public void teardown() { } /** - * Cleanup after a test. + * Cleanup after a JUnit test. */ - //@AfterEach - public void teardown_junit() { -// try { -// this.beforeLoggingTeardown(junitTestResult); -// } catch (Exception e) { -// this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); -// } + @AfterEach public void teardownJunit() { + // try { + // this.beforeLoggingTeardown(junitTestResult); + // } catch (Exception e) { + // this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); + // } // Log the test result if (junitTestResult.getStatus() == TestResultType.PASS) { @@ -347,8 +350,9 @@ public void teardown_junit() { // Cleanup log files we don't want try { - if ((this.getLogger() instanceof FileLogger) && junitTestResult.getStatus() == TestResultType.PASS - && this.loggingEnabledSetting == LoggingEnabled.ONFAIL) { + if ((this.getLogger() instanceof FileLogger) + && junitTestResult.getStatus() == TestResultType.PASS + && this.loggingEnabledSetting == LoggingEnabled.ONFAIL) { Files.delete(Paths.get(((FileLogger) this.getLogger()).getFilePath())); } } catch (Exception e) { @@ -376,8 +380,7 @@ public void teardown_junit() { * * @param testResult The result object */ - @AfterMethod(alwaysRun = true) - public void setTestResult(ITestResult testResult) { + @AfterMethod(alwaysRun = true) public void setTestResult(ITestResult testResult) { this.testContextInstance = testResult.getTestContext(); this.testResult = testResult; } @@ -407,9 +410,10 @@ protected Logger createLogger() { this.setLoggedExceptions(new ArrayList<>()); if (this.loggingEnabledSetting != LoggingEnabled.NO) { - log = LoggingConfig.getLogger(StringProcessor.safeFormatter("%s - %s", this.fullyQualifiedTestClassName.get(), - DateTimeFormatter.ofPattern("uuuu-MM-dd-HH-mm-ss-SSSS", Locale.getDefault()) - .format(LocalDateTime.now(Clock.systemUTC())))); + log = LoggingConfig.getLogger( + StringProcessor.safeFormatter("%s - %s", this.fullyQualifiedTestClassName.get(), + DateTimeFormatter.ofPattern("uuuu-MM-dd-HH-mm-ss-SSSS", Locale.getDefault()) + .format(LocalDateTime.now(Clock.systemUTC())))); } else { log = new ConsoleLogger(); } @@ -500,8 +504,8 @@ protected void logVerbose(String message, Object... args) { for (StackTraceElement element : Thread.currentThread().getStackTrace()) { // If the stack trace element is from this package (excluding this method) append the stack trace line - if (element.toString().startsWith("com.cognizantsoftvision") - && !element.toString().contains("BaseTest.logVerbose")) { + if (element.toString().startsWith("com.cognizantsoftvision") && !element.toString() + .contains("BaseTest.logVerbose")) { messages.append(element).append(System.lineSeparator()); } } diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java index 234fa3b02..9e6430a3b 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java @@ -1,22 +1,23 @@ -package com.cognizantsoftvision.maqs.base.interfaces; +/* + * Copyright 2022 (C) Cognizant SoftVision, All rights Reserved + */ +package com.cognizantsoftvision.maqs.base.interfaces; import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; public class JunitTestResult implements TestResult { - private TestResultType currentStatus; + private final TestResultType currentStatus; public JunitTestResult(TestResultType status) { - this.currentStatus = status; + this.currentStatus = status; } - @Override - public TestResultType getStatus() { - return this.currentStatus; + @Override public TestResultType getStatus() { + return this.currentStatus; } - @Override - public boolean isSuccess() { - return currentStatus == TestResultType.PASS; + @Override public boolean isSuccess() { + return currentStatus == TestResultType.PASS; } } diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java index 42dd17b1e..ec55c4ea9 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java @@ -1,3 +1,7 @@ +/* + * Copyright 2022 (C) Cognizant SoftVision, All rights Reserved + */ + package com.cognizantsoftvision.maqs.base.interfaces; import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java index cc60a70fa..8cb105e48 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java @@ -14,6 +14,7 @@ * The JUnit Test Watcher class. */ public class JunitTestWatcher implements TestWatcher { + /** * Test instance of the test being executed per each thread */ @@ -26,12 +27,12 @@ public JunitTestWatcher(BaseTest testInstance) { @Override public void testSuccessful(ExtensionContext context) { this.testInstance.setTestResult(new JunitTestResult(TestResultType.PASS), context); - this.testInstance.teardown_junit(); + this.testInstance.teardownJunit(); } @Override public void testFailed(ExtensionContext context, Throwable cause) { this.testInstance.setTestResult(new JunitTestResult(TestResultType.FAIL), context); - this.testInstance.teardown_junit(); + this.testInstance.teardownJunit(); } } \ No newline at end of file From 3f8d3dd35df8d919e8bb8eb0569c98b312585dba Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 14:56:23 -0500 Subject: [PATCH 07/21] checkstyle updates --- .../maqs/base/BaseTest.java | 2 -- .../maqs/base/interfaces/JunitTestResult.java | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index c5b1e1b72..eaaf02b32 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -20,7 +20,6 @@ import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; import com.cognizantsoftvision.maqs.utilities.performance.IPerfTimerCollection; import com.cognizantsoftvision.maqs.utilities.performance.PerfTimerCollection; - import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Paths; @@ -31,7 +30,6 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java index 9e6430a3b..a1e5f174d 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/JunitTestResult.java @@ -7,17 +7,17 @@ import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; public class JunitTestResult implements TestResult { - private final TestResultType currentStatus; + private final TestResultType currentStatus; - public JunitTestResult(TestResultType status) { - this.currentStatus = status; - } + public JunitTestResult(TestResultType status) { + this.currentStatus = status; + } - @Override public TestResultType getStatus() { - return this.currentStatus; - } + @Override public TestResultType getStatus() { + return this.currentStatus; + } - @Override public boolean isSuccess() { - return currentStatus == TestResultType.PASS; - } + @Override public boolean isSuccess() { + return currentStatus == TestResultType.PASS; + } } From 01a0ab254775d8acd0d522527b47d92fcc964be9 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:00:55 -0500 Subject: [PATCH 08/21] checkstyle updates --- .../maqs/base/watcher/JunitTestWatcher.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java index 8cb105e48..20f3f2656 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java @@ -15,24 +15,24 @@ */ public class JunitTestWatcher implements TestWatcher { - /** - * Test instance of the test being executed per each thread - */ - BaseTest testInstance; + /** + * Test instance of the test being executed per each thread + */ + BaseTest testInstance; - public JunitTestWatcher(BaseTest testInstance) { - this.testInstance = testInstance; - } + public JunitTestWatcher(BaseTest testInstance) { + this.testInstance = testInstance; +} - @Override - public void testSuccessful(ExtensionContext context) { - this.testInstance.setTestResult(new JunitTestResult(TestResultType.PASS), context); - this.testInstance.teardownJunit(); - } + @Override + public void testSuccessful(ExtensionContext context) { + this.testInstance.setTestResult(new JunitTestResult(TestResultType.PASS), context); + this.testInstance.teardownJunit(); + } - @Override - public void testFailed(ExtensionContext context, Throwable cause) { - this.testInstance.setTestResult(new JunitTestResult(TestResultType.FAIL), context); - this.testInstance.teardownJunit(); - } + @Override + public void testFailed(ExtensionContext context, Throwable cause) { + this.testInstance.setTestResult(new JunitTestResult(TestResultType.FAIL), context); + this.testInstance.teardownJunit(); + } } \ No newline at end of file From 8c8e3f325eb4316a0e55885b4b0557b19f2d1345 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:05:08 -0500 Subject: [PATCH 09/21] checkstyle updates --- .../maqs/base/BaseTest.java | 37 ++++++++++--------- .../maqs/base/interfaces/TestResult.java | 4 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index eaaf02b32..c84d669b3 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -228,13 +228,31 @@ public void setTestObject(BaseTestObject baseTestObject) { } } + /** + * Setup before a JUnit test. + * + * @param info the test info of the unit test being run + */ + @BeforeEach public void setup(TestInfo info) { + //this.context = context; + + // Get the Fully Qualified Test Class Name and set it in the object + String testName = + info.getTestClass().get().getName() + "." + info.getTestMethod().get().getName(); + testName = testName.replaceFirst("class ", ""); + this.fullyQualifiedTestClassName.set(testName); + + this.createNewTestObject(); + } + /** * Setup before a testng unit test. * * @param method The initial executing Method object * @param testContext The initial executing Test Context object */ - @BeforeMethod(alwaysRun = true) public void setup(Method method, ITestContext testContext) { + @BeforeMethod(alwaysRun = true) + public void setup(Method method, ITestContext testContext) { this.testContextInstance = testContext; // Get the Fully Qualified Test Class Name and set it in the object @@ -257,23 +275,6 @@ public void customSetup(String testName, ITestContext testContext) { this.createNewTestObject(); } - /** - * Setup before a JUnit test. - * - * @param info the test info of the unit test being run - */ - @BeforeEach public void setup(TestInfo info) { - //this.context = context; - - // Get the Fully Qualified Test Class Name and set it in the object - String testName = - info.getTestClass().get().getName() + "." + info.getTestMethod().get().getName(); - testName = testName.replaceFirst("class ", ""); - this.fullyQualifiedTestClassName.set(testName); - - this.createNewTestObject(); - } - /** * Cleanup after a TestNG test. */ diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java index ec55c4ea9..eefbbb0d9 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/interfaces/TestResult.java @@ -7,7 +7,7 @@ import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; public interface TestResult { - TestResultType getStatus(); + TestResultType getStatus(); - boolean isSuccess(); + boolean isSuccess(); } From a908d4677ddc174df30d4e8f8fa9883fc6d1300f Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:07:11 -0500 Subject: [PATCH 10/21] checkstyle updates --- .../main/java/com/cognizantsoftvision/maqs/base/BaseTest.java | 3 ++- .../maqs/base/watcher/JunitTestWatcher.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index c84d669b3..311bd678a 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -278,7 +278,8 @@ public void customSetup(String testName, ITestContext testContext) { /** * Cleanup after a TestNG test. */ - @AfterMethod(alwaysRun = true) public void teardown() { + @AfterMethod(alwaysRun = true) + public void teardown() { try { this.beforeLoggingTeardown(testResult); } catch (Exception e) { diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java index 20f3f2656..0836db0ea 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java @@ -22,7 +22,7 @@ public class JunitTestWatcher implements TestWatcher { public JunitTestWatcher(BaseTest testInstance) { this.testInstance = testInstance; -} + } @Override public void testSuccessful(ExtensionContext context) { From 11c9b879f2faa28fab7553265a44463217b9dce4 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:10:23 -0500 Subject: [PATCH 11/21] checkstyle updates --- .../main/java/com/cognizantsoftvision/maqs/base/BaseTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index 311bd678a..9b7ddb54d 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -380,7 +380,8 @@ public void teardown() { * * @param testResult The result object */ - @AfterMethod(alwaysRun = true) public void setTestResult(ITestResult testResult) { + @AfterMethod(alwaysRun = true) + public void setTestResult(ITestResult testResult) { this.testContextInstance = testResult.getTestContext(); this.testResult = testResult; } From 42ea7e9497c05e2b00d3511392f8775e076f0f26 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 15:11:45 -0500 Subject: [PATCH 12/21] checkstyle updates --- .../maqs/base/watcher/JunitTestWatcher.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java index 0836db0ea..0859933bc 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java @@ -15,9 +15,7 @@ */ public class JunitTestWatcher implements TestWatcher { - /** - * Test instance of the test being executed per each thread - */ + // Test instance of the test being executed per each thread. BaseTest testInstance; public JunitTestWatcher(BaseTest testInstance) { From 4c70b59113afbdea78aed391c584b5b1f58fbf7b Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 16:44:38 -0500 Subject: [PATCH 13/21] code smells --- .../maqs/base/BaseGenericTest.java | 2 -- .../maqs/base/BaseGenericJUnitTest.java | 16 ++++++++++++++++ .../maqs/base/BaseGenericTestUnitTest.java | 5 ----- 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericJUnitTest.java diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseGenericTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseGenericTest.java index 19c15ca8f..abbcf1116 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseGenericTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseGenericTest.java @@ -4,8 +4,6 @@ package com.cognizantsoftvision.maqs.base; -import com.cognizantsoftvision.maqs.base.watcher.JunitTestWatcher; -import org.junit.jupiter.api.extension.RegisterExtension; import org.testng.ITestResult; /** diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericJUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericJUnitTest.java new file mode 100644 index 000000000..745b4c4c7 --- /dev/null +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericJUnitTest.java @@ -0,0 +1,16 @@ +/* + * Copyright 2022 (C) Cognizant SoftVision, All rights Reserved + */ + +package com.cognizantsoftvision.maqs.base; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class BaseGenericJUnitTest extends BaseGenericTest { + + @Test + public void testCreateTestObject() { + Assertions.assertNotNull(this.getTestObject()); + } +} \ No newline at end of file diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java index 20827a51a..01843afc3 100644 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java @@ -14,9 +14,4 @@ public class BaseGenericTestUnitTest extends BaseGenericTest { public void testCreateTestObject() { Assert.assertNotNull(this.getTestObject()); } - - @org.junit.jupiter.api.Test - public void testCreateTestObject_junit() { - Assert.assertNotNull(this.getTestObject()); - } } \ No newline at end of file From 8d55c697c78d8cf4cf80d5d6bdbe691b156c73cc Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Thu, 11 Aug 2022 16:45:03 -0500 Subject: [PATCH 14/21] code smells --- ...{BaseGenericJUnitTest.java => BaseGenericTestJUnitTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/{BaseGenericJUnitTest.java => BaseGenericTestJUnitTest.java} (83%) diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericJUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestJUnitTest.java similarity index 83% rename from maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericJUnitTest.java rename to maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestJUnitTest.java index 745b4c4c7..e8438c406 100644 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericJUnitTest.java +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestJUnitTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -class BaseGenericJUnitTest extends BaseGenericTest { +class BaseGenericTestJUnitTest extends BaseGenericTest { @Test public void testCreateTestObject() { From 9781d7eedab33091f6e168eef5b0d4af8d060130 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Fri, 12 Aug 2022 11:34:55 -0500 Subject: [PATCH 15/21] fixing code smells and bugs --- .../maqs/base/BaseTest.java | 49 +++++++++++++------ ...st.java => BaseGenericTestNGUnitTest.java} | 2 +- .../base/JUnitBaseTestObjectUnitTest.java | 22 --------- 3 files changed, 35 insertions(+), 38 deletions(-) rename maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/{BaseGenericTestUnitTest.java => BaseGenericTestNGUnitTest.java} (85%) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index 9b7ddb54d..33f5ed74e 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -29,8 +29,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.extension.ExtensionContext; @@ -233,16 +233,29 @@ public void setTestObject(BaseTestObject baseTestObject) { * * @param info the test info of the unit test being run */ - @BeforeEach public void setup(TestInfo info) { + @BeforeEach + public void setup(TestInfo info) { //this.context = context; + String testClassName = null; + String testMethodName = null; // Get the Fully Qualified Test Class Name and set it in the object - String testName = - info.getTestClass().get().getName() + "." + info.getTestMethod().get().getName(); - testName = testName.replaceFirst("class ", ""); - this.fullyQualifiedTestClassName.set(testName); + if (info.getTestClass().isPresent()) { + Optional> optional = info.getTestClass(); + if (optional.isPresent()) { + testClassName = optional.get().getName(); + } + } - this.createNewTestObject(); + if (info.getTestMethod().isPresent()) { + Optional optional = info.getTestMethod(); + if (optional.isPresent()) { + testMethodName = optional.get().getName(); + } + } + + String testName = testClassName + "." + testMethodName; + customSetup(testName); } /** @@ -269,9 +282,15 @@ public void setup(Method method, ITestContext testContext) { public void customSetup(String testName, ITestContext testContext) { this.testContextInstance = testContext; +// testName = testName.replaceFirst("class ", ""); +// this.fullyQualifiedTestClassName.set(testName); +// this.createNewTestObject(); + customSetup(testName); + } + + public void customSetup(String testName) { testName = testName.replaceFirst("class ", ""); this.fullyQualifiedTestClassName.set(testName); - this.createNewTestObject(); } @@ -330,12 +349,13 @@ public void teardown() { /** * Cleanup after a JUnit test. */ - @AfterEach public void teardownJunit() { - // try { - // this.beforeLoggingTeardown(junitTestResult); - // } catch (Exception e) { - // this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); - // } +// @AfterEach + public void teardownJunit() { +// try { +// this.beforeLoggingTeardown(junitTestResult); +// } catch (Exception e) { +// this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); +// } // Log the test result if (junitTestResult.getStatus() == TestResultType.PASS) { @@ -386,7 +406,6 @@ public void setTestResult(ITestResult testResult) { this.testResult = testResult; } - //@AfterEach public void setTestResult(TestResult testResult, ExtensionContext context) { this.context = context; this.junitTestResult = testResult; diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestNGUnitTest.java similarity index 85% rename from maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java rename to maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestNGUnitTest.java index 01843afc3..af847eb9e 100644 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestNGUnitTest.java @@ -8,7 +8,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -public class BaseGenericTestUnitTest extends BaseGenericTest { +public class BaseGenericTestNGUnitTest extends BaseGenericTest { @Test(groups = TestCategories.FRAMEWORK) public void testCreateTestObject() { diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java index 4eb0218f9..61126f751 100644 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java @@ -4,10 +4,8 @@ package com.cognizantsoftvision.maqs.base; -import com.cognizantsoftvision.maqs.utilities.helper.TestCategories; import com.cognizantsoftvision.maqs.utilities.logging.ILogger; import com.cognizantsoftvision.maqs.utilities.performance.PerfTimerCollection; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions; import java.io.File; @@ -24,7 +22,6 @@ class JUnitBaseTestObjectUnitTest extends BaseGenericTest { * Test Constructor with Log and Method. */ @Test - @Tag(TestCategories.FRAMEWORK) void testBaseTestObject1() { final ITestObject testObject = this.getTestObject(); @@ -37,7 +34,6 @@ void testBaseTestObject1() { * Test Constructor with Test Object. */ @Test - @Tag(TestCategories.FRAMEWORK) void testBaseTestObject2() { final ITestObject testObject = this.getTestObject(); BaseTestObject baseTestObject = new BaseTestObject(testObject); @@ -49,7 +45,6 @@ void testBaseTestObject2() { * Test set value. */ @Test - @Tag(TestCategories.FRAMEWORK) void testSetValue() { ITestObject testObject = this.getTestObject(); final String key = "SetKey"; @@ -63,7 +58,6 @@ void testSetValue() { * Test set object. */ @Test - @Tag(TestCategories.FRAMEWORK) void testSetObject() { ITestObject testObject = this.getTestObject(); final String key = "SetObject"; @@ -77,7 +71,6 @@ void testSetObject() { * Test get log. */ @Test - @Tag(TestCategories.FRAMEWORK) void testGetLog() { ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getLogger(), "Checking that logger is not null."); @@ -87,7 +80,6 @@ void testGetLog() { * Test set log. */ @Test - @Tag(TestCategories.FRAMEWORK) void testSetLog() { ITestObject testObject = this.getTestObject(); final ILogger logger = this.getLogger(); @@ -99,7 +91,6 @@ void testSetLog() { * Test Get Perf Collection Timer - Not Null. */ @Test - @Tag(TestCategories.FRAMEWORK) void testGetPerfTimerCollectionNotNull() { ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getPerfTimerCollection(), "Checking that logger is not null."); @@ -109,7 +100,6 @@ void testGetPerfTimerCollectionNotNull() { * Test Set Perf Collection Timer - Get/Set. */ @Test - @Tag(TestCategories.FRAMEWORK) void testSetPerfTimerCollectionGetSet() { ITestObject testObject = this.getTestObject(); final PerfTimerCollection perfTimerCollection = new PerfTimerCollection(testObject.getLogger(), "FakeTestName"); @@ -122,7 +112,6 @@ void testSetPerfTimerCollectionGetSet() { * Test get values. */ @Test - @Tag(TestCategories.FRAMEWORK) void testGetValues() { ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getValues(), "Checking that values is not null."); @@ -132,7 +121,6 @@ void testGetValues() { * Test get objects. */ @Test - @Tag(TestCategories.FRAMEWORK) void testGetObjects() { ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getObjects(), "Checking that objects is not null."); @@ -142,7 +130,6 @@ void testGetObjects() { * Test Get Manager Store - Not Null. */ @Test - @Tag(TestCategories.FRAMEWORK) void testGetManagerStoreNotNull() { ITestObject testObject = this.getTestObject(); Assertions.assertNotNull(testObject.getManagerStore(), "Checking that objects is not null."); @@ -152,7 +139,6 @@ void testGetManagerStoreNotNull() { * Test add driver manager. */ @Test - @Tag(TestCategories.FRAMEWORK) void testAddDriverManager() { ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; @@ -167,7 +153,6 @@ void testAddDriverManager() { * Test add driver manager - Overwrite True. */ @Test - @Tag(TestCategories.FRAMEWORK) void testAddDriverManagerTrue() { ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; @@ -184,7 +169,6 @@ void testAddDriverManagerTrue() { * Test add driver manager - Overwrite False. */ @Test - @Tag(TestCategories.FRAMEWORK) void testAddDriverManagerFalse() { ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; @@ -199,7 +183,6 @@ void testAddDriverManagerFalse() { * Test add driver manager 2. */ @Test - @Tag(TestCategories.FRAMEWORK) void testAddDriverManager2() { ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; @@ -215,7 +198,6 @@ void testAddDriverManager2() { * Test close. */ @Test - @Tag(TestCategories.FRAMEWORK) void testClose() throws Exception { ITestObject testObject = this.getTestObject(); final Supplier supplier = () -> null; @@ -232,7 +214,6 @@ void testClose() throws Exception { * Test add associated file. */ @Test - @Tag(TestCategories.FRAMEWORK) void testAddAssociatedFile() { ITestObject testObject = this.getTestObject(); File temp = null; @@ -251,7 +232,6 @@ void testAddAssociatedFile() { * Test remove associated file. */ @Test - @Tag(TestCategories.FRAMEWORK) void testRemoveAssociatedFile() { ITestObject testObject = this.getTestObject(); File temp = null; @@ -272,7 +252,6 @@ void testRemoveAssociatedFile() { * Test get array of associated files. */ @Test - @Tag(TestCategories.FRAMEWORK) void testGetArrayOfAssociatedFiles() { ITestObject testObject = this.getTestObject(); File temp = null; @@ -293,7 +272,6 @@ void testGetArrayOfAssociatedFiles() { * Test contains associated file. */ @Test() - @Tag(TestCategories.FRAMEWORK) void testContainsAssociatedFile() { ITestObject testObject = this.getTestObject(); File temp = null; From 4a21f15cf5c8b4fd621027a775304eec273e1d15 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Fri, 12 Aug 2022 12:04:04 -0500 Subject: [PATCH 16/21] fixing code smells and bugs --- .../maqs/base/BaseTest.java | 40 +++++++------------ .../maqs/base/BaseTestUnitTest.java | 1 + 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index 33f5ed74e..fef838f31 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -248,9 +248,9 @@ public void setup(TestInfo info) { } if (info.getTestMethod().isPresent()) { - Optional optional = info.getTestMethod(); - if (optional.isPresent()) { - testMethodName = optional.get().getName(); + Optional optional = info.getTestMethod(); + if (optional.isPresent()) { + testMethodName = optional.get().getName(); } } @@ -281,10 +281,6 @@ public void setup(Method method, ITestContext testContext) { */ public void customSetup(String testName, ITestContext testContext) { this.testContextInstance = testContext; - -// testName = testName.replaceFirst("class ", ""); -// this.fullyQualifiedTestClassName.set(testName); -// this.createNewTestObject(); customSetup(testName); } @@ -327,23 +323,7 @@ public void teardown() { this.tryToLog(MessageType.WARNING, "Failed to cleanup log files because: %s", e.getMessage()); } - // Get the Fully Qualified Test Name - String fullyQualifiedTestName = this.fullyQualifiedTestClassName.get(); - - try { - ITestObject baseTestObject = this.getTestObject(); - // Release logged messages - this.loggedExceptions.remove(fullyQualifiedTestName); - - // Release the Base Test Object - this.baseTestObjects.remove(fullyQualifiedTestName, baseTestObject); - } catch (Exception e) { - throw new MAQSRuntimeException("there was an issue cleaning up", e); - } - - // Create console logger to log subsequent messages - this.setTestObject(new BaseTestObject(new ConsoleLogger(), fullyQualifiedTestName)); - this.fullyQualifiedTestClassName.remove(); + cleanUpFiles(); } /** @@ -379,15 +359,25 @@ public void teardownJunit() { this.tryToLog(MessageType.WARNING, "Failed to cleanup log files because: %s", e.getMessage()); } + cleanUpFiles(); + } + + /** + * Cleans up logs and files after the test. + */ + private void cleanUpFiles() { // Get the Fully Qualified Test Name String fullyQualifiedTestName = this.fullyQualifiedTestClassName.get(); - try (BaseTestObject baseTestObject = (BaseTestObject) this.getTestObject()) { + try { + ITestObject baseTestObject = this.getTestObject(); // Release logged messages this.loggedExceptions.remove(fullyQualifiedTestName); // Release the Base Test Object this.baseTestObjects.remove(fullyQualifiedTestName, baseTestObject); + } catch (Exception e) { + throw new MAQSRuntimeException("there was an issue cleaning up", e); } // Create console logger to log subsequent messages diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseTestUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseTestUnitTest.java index 15c6a2484..365e393a7 100644 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseTestUnitTest.java +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseTestUnitTest.java @@ -51,6 +51,7 @@ public void fileLoggerTest() { @Test(groups = TestCategories.FRAMEWORK) public void logVerboseTest() { this.logVerbose("This is a test to log verbose."); + this.logVerbose("Logging a verbose message"); } /** From 607fb74e90eed741da1b2072aad2599f889e95f2 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Fri, 12 Aug 2022 12:06:09 -0500 Subject: [PATCH 17/21] fixing code smells --- .../com/cognizantsoftvision/maqs/base/BaseTest.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index fef838f31..db14ff140 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -251,7 +251,7 @@ public void setup(TestInfo info) { Optional optional = info.getTestMethod(); if (optional.isPresent()) { testMethodName = optional.get().getName(); - } + } } String testName = testClassName + "." + testMethodName; @@ -329,13 +329,12 @@ public void teardown() { /** * Cleanup after a JUnit test. */ -// @AfterEach public void teardownJunit() { -// try { -// this.beforeLoggingTeardown(junitTestResult); -// } catch (Exception e) { -// this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); -// } + // try { + // this.beforeLoggingTeardown(junitTestResult); + // } catch (Exception e) { + // this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); + // } // Log the test result if (junitTestResult.getStatus() == TestResultType.PASS) { From 01b372b3cac3ec0cfa01c1182521cccf0801978d Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Fri, 12 Aug 2022 12:53:29 -0500 Subject: [PATCH 18/21] fixing code smells --- .../maqs/base/BaseTest.java | 15 ++------------- .../maqs/base/watcher/JunitTestWatcher.java | 4 ++-- .../maqs/base/BaseGenericTestJUnitTest.java | 16 ---------------- ...tTest.java => BaseGenericTestUnitTest.java} | 2 +- .../junit/JUnitBaseGenericTestUnitTest.java | 18 ++++++++++++++++++ .../JUnitBaseTestObjectUnitTest.java | 6 +++++- 6 files changed, 28 insertions(+), 33 deletions(-) delete mode 100644 maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestJUnitTest.java rename maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/{BaseGenericTestNGUnitTest.java => BaseGenericTestUnitTest.java} (85%) create mode 100644 maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/junit/JUnitBaseGenericTestUnitTest.java rename maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/{ => junit}/JUnitBaseTestObjectUnitTest.java (97%) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index db14ff140..20459ce54 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -33,7 +33,6 @@ import java.util.concurrent.ConcurrentHashMap; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; -import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.RegisterExtension; import org.testng.ITestContext; import org.testng.ITestResult; @@ -77,8 +76,6 @@ public abstract class BaseTest { */ private ITestContext testContextInstance; - private ExtensionContext context; - /** * The Fully Qualified Test Class Name. */ @@ -235,7 +232,6 @@ public void setTestObject(BaseTestObject baseTestObject) { */ @BeforeEach public void setup(TestInfo info) { - //this.context = context; String testClassName = null; String testMethodName = null; @@ -284,7 +280,7 @@ public void customSetup(String testName, ITestContext testContext) { customSetup(testName); } - public void customSetup(String testName) { + private void customSetup(String testName) { testName = testName.replaceFirst("class ", ""); this.fullyQualifiedTestClassName.set(testName); this.createNewTestObject(); @@ -330,12 +326,6 @@ public void teardown() { * Cleanup after a JUnit test. */ public void teardownJunit() { - // try { - // this.beforeLoggingTeardown(junitTestResult); - // } catch (Exception e) { - // this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage()); - // } - // Log the test result if (junitTestResult.getStatus() == TestResultType.PASS) { this.tryToLog(MessageType.SUCCESS, "Test Passed"); @@ -395,8 +385,7 @@ public void setTestResult(ITestResult testResult) { this.testResult = testResult; } - public void setTestResult(TestResult testResult, ExtensionContext context) { - this.context = context; + public void setTestResult(TestResult testResult) { this.junitTestResult = testResult; } diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java index 0859933bc..487e1f34d 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/watcher/JunitTestWatcher.java @@ -24,13 +24,13 @@ public JunitTestWatcher(BaseTest testInstance) { @Override public void testSuccessful(ExtensionContext context) { - this.testInstance.setTestResult(new JunitTestResult(TestResultType.PASS), context); + this.testInstance.setTestResult(new JunitTestResult(TestResultType.PASS)); this.testInstance.teardownJunit(); } @Override public void testFailed(ExtensionContext context, Throwable cause) { - this.testInstance.setTestResult(new JunitTestResult(TestResultType.FAIL), context); + this.testInstance.setTestResult(new JunitTestResult(TestResultType.FAIL)); this.testInstance.teardownJunit(); } } \ No newline at end of file diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestJUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestJUnitTest.java deleted file mode 100644 index e8438c406..000000000 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestJUnitTest.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2022 (C) Cognizant SoftVision, All rights Reserved - */ - -package com.cognizantsoftvision.maqs.base; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -class BaseGenericTestJUnitTest extends BaseGenericTest { - - @Test - public void testCreateTestObject() { - Assertions.assertNotNull(this.getTestObject()); - } -} \ No newline at end of file diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestNGUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java similarity index 85% rename from maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestNGUnitTest.java rename to maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java index af847eb9e..01843afc3 100644 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestNGUnitTest.java +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/BaseGenericTestUnitTest.java @@ -8,7 +8,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -public class BaseGenericTestNGUnitTest extends BaseGenericTest { +public class BaseGenericTestUnitTest extends BaseGenericTest { @Test(groups = TestCategories.FRAMEWORK) public void testCreateTestObject() { diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/junit/JUnitBaseGenericTestUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/junit/JUnitBaseGenericTestUnitTest.java new file mode 100644 index 000000000..6533c9126 --- /dev/null +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/junit/JUnitBaseGenericTestUnitTest.java @@ -0,0 +1,18 @@ +/* + * Copyright 2022 (C) Cognizant SoftVision, All rights Reserved + */ + +package com.cognizantsoftvision.maqs.base.junit; + +import com.cognizantsoftvision.maqs.base.BaseGenericTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; + +class JUnitBaseGenericTestUnitTest extends BaseGenericTest { + + @Test + void testCreateTestObject() { + Assertions.assertNotNull(this.getTestObject()); + } +} \ No newline at end of file diff --git a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/junit/JUnitBaseTestObjectUnitTest.java similarity index 97% rename from maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java rename to maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/junit/JUnitBaseTestObjectUnitTest.java index 61126f751..08f95cf88 100644 --- a/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/JUnitBaseTestObjectUnitTest.java +++ b/maqs-base/src/test/java/com/cognizantsoftvision/maqs/base/junit/JUnitBaseTestObjectUnitTest.java @@ -2,8 +2,12 @@ * Copyright 2022 (C) Cognizant SoftVision, All rights Reserved */ -package com.cognizantsoftvision.maqs.base; +package com.cognizantsoftvision.maqs.base.junit; +import com.cognizantsoftvision.maqs.base.BaseGenericTest; +import com.cognizantsoftvision.maqs.base.BaseTestObject; +import com.cognizantsoftvision.maqs.base.DriverManager; +import com.cognizantsoftvision.maqs.base.ITestObject; import com.cognizantsoftvision.maqs.utilities.logging.ILogger; import com.cognizantsoftvision.maqs.utilities.performance.PerfTimerCollection; import org.junit.jupiter.api.Test; From 38b308b3c8f8aba5a1faf4c5b7c7a1a439c10ff2 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Mon, 15 Aug 2022 12:18:16 -0500 Subject: [PATCH 19/21] organizing code --- .../java/com/cognizantsoftvision/maqs/base/BaseTest.java | 6 +++--- .../maqs/selenium/exceptions/ElementHandlerException.java | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index 20459ce54..87e960f8e 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -319,7 +319,7 @@ public void teardown() { this.tryToLog(MessageType.WARNING, "Failed to cleanup log files because: %s", e.getMessage()); } - cleanUpFiles(); + cleanUpTest(); } /** @@ -348,13 +348,13 @@ public void teardownJunit() { this.tryToLog(MessageType.WARNING, "Failed to cleanup log files because: %s", e.getMessage()); } - cleanUpFiles(); + cleanUpTest(); } /** * Cleans up logs and files after the test. */ - private void cleanUpFiles() { + private void cleanUpTest() { // Get the Fully Qualified Test Name String fullyQualifiedTestName = this.fullyQualifiedTestClassName.get(); diff --git a/maqs-selenium/src/main/java/com/cognizantsoftvision/maqs/selenium/exceptions/ElementHandlerException.java b/maqs-selenium/src/main/java/com/cognizantsoftvision/maqs/selenium/exceptions/ElementHandlerException.java index e0a4840f6..72dde459f 100644 --- a/maqs-selenium/src/main/java/com/cognizantsoftvision/maqs/selenium/exceptions/ElementHandlerException.java +++ b/maqs-selenium/src/main/java/com/cognizantsoftvision/maqs/selenium/exceptions/ElementHandlerException.java @@ -31,7 +31,4 @@ public ElementHandlerException(String message) { public ElementHandlerException(String message, Exception exception) { super(message, exception); } - - - } From 7c07dcca617fcaab42fe09067a907bafcdb1fb29 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Mon, 24 Oct 2022 09:00:47 -0500 Subject: [PATCH 20/21] merge with main --- .../maqs/base/BaseTest.java | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index 6106de173..0d6c42d9c 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -10,14 +10,7 @@ import com.cognizantsoftvision.maqs.base.interfaces.TestResult; import com.cognizantsoftvision.maqs.base.watcher.JunitTestWatcher; import com.cognizantsoftvision.maqs.utilities.helper.StringProcessor; -import com.cognizantsoftvision.maqs.utilities.logging.ConsoleLogger; -import com.cognizantsoftvision.maqs.utilities.logging.FileLogger; -import com.cognizantsoftvision.maqs.utilities.logging.ILogger; -import com.cognizantsoftvision.maqs.utilities.logging.Logger; -import com.cognizantsoftvision.maqs.utilities.logging.LoggerFactory; -import com.cognizantsoftvision.maqs.utilities.logging.LoggingConfig; -import com.cognizantsoftvision.maqs.utilities.logging.LoggingEnabled; -import com.cognizantsoftvision.maqs.utilities.logging.MessageType; +import com.cognizantsoftvision.maqs.utilities.logging.*; import com.cognizantsoftvision.maqs.utilities.performance.IPerfTimerCollection; import com.cognizantsoftvision.maqs.utilities.performance.PerfTimerCollection; import java.lang.reflect.Method; @@ -424,24 +417,6 @@ protected ILogger createLogger() { } } - /** - * Get the type of test result. - * - * @return The type of test result - */ - protected TestResultType getResultType() { - switch (this.testResult.getStatus()) { - case ITestResult.SUCCESS: - return TestResultType.PASS; - case ITestResult.FAILURE: - return TestResultType.FAIL; - case ITestResult.SKIP: - return TestResultType.SKIP; - default: - return TestResultType.OTHER; - } - } - /** * Get the fully qualified test name. * From 40b663960f3a34b0d5e8deb223e275252a3061b7 Mon Sep 17 00:00:00 2001 From: jredingcvs <97762469+jredingcvs@users.noreply.github.com> Date: Mon, 24 Oct 2022 09:04:58 -0500 Subject: [PATCH 21/21] checkstyle changes --- .../cognizantsoftvision/maqs/base/BaseTest.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java index 0d6c42d9c..678863213 100644 --- a/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java +++ b/maqs-base/src/main/java/com/cognizantsoftvision/maqs/base/BaseTest.java @@ -10,7 +10,15 @@ import com.cognizantsoftvision.maqs.base.interfaces.TestResult; import com.cognizantsoftvision.maqs.base.watcher.JunitTestWatcher; import com.cognizantsoftvision.maqs.utilities.helper.StringProcessor; -import com.cognizantsoftvision.maqs.utilities.logging.*; +import com.cognizantsoftvision.maqs.utilities.logging.ConsoleLogger; +import com.cognizantsoftvision.maqs.utilities.logging.FileLogger; +import com.cognizantsoftvision.maqs.utilities.logging.ILogger; +import com.cognizantsoftvision.maqs.utilities.logging.Logger; +import com.cognizantsoftvision.maqs.utilities.logging.LoggerFactory; +import com.cognizantsoftvision.maqs.utilities.logging.LoggingConfig; +import com.cognizantsoftvision.maqs.utilities.logging.LoggingEnabled; +import com.cognizantsoftvision.maqs.utilities.logging.MessageType; +import com.cognizantsoftvision.maqs.utilities.logging.TestResultType; import com.cognizantsoftvision.maqs.utilities.performance.IPerfTimerCollection; import com.cognizantsoftvision.maqs.utilities.performance.PerfTimerCollection; import java.lang.reflect.Method; @@ -24,10 +32,10 @@ import java.util.Locale; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.extension.RegisterExtension; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.testng.ITestContext; import org.testng.ITestResult; import org.testng.annotations.AfterMethod; @@ -406,7 +414,9 @@ protected ILogger createLogger() { if (this.loggingEnabledSetting != LoggingEnabled.NO) { return LoggerFactory.getLogger( StringProcessor.safeFormatter("%s - %s", this.fullyQualifiedTestClassName.get(), - DateTimeFormatter.ofPattern(Logger.DEFAULT_DATE_TIME_FORMAT, Locale.getDefault()).format(LocalDateTime.now(Clock.systemUTC())))); + DateTimeFormatter.ofPattern( + Logger.DEFAULT_DATE_TIME_FORMAT, + Locale.getDefault()).format(LocalDateTime.now(Clock.systemUTC())))); } else { return LoggerFactory.getConsoleLogger(); }