summaryrefslogtreecommitdiffstats
path: root/feature-test-transaction/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'feature-test-transaction/src/test/java')
-rw-r--r--feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java172
1 files changed, 82 insertions, 90 deletions
diff --git a/feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java b/feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java
index fd373a1d..09be93f9 100644
--- a/feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java
+++ b/feature-test-transaction/src/test/java/org/onap/policy/drools/testtransaction/TestTransactionTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* feature-test-transaction
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,101 +40,93 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestTransactionTest {
- /**
- * Test JUnit Controller Name
- */
- public static final String TEST_CONTROLLER_NAME = "unnamed";
- /**
- * Controller Configuration File
- */
- public static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
-
- /**
- * Controller Configuration Backup File
- */
- public static final String TEST_CONTROLLER_FILE_BAK =
- TEST_CONTROLLER_NAME + "-controller.properties.bak";
-
-
- /**
- * logger
- */
- private static Logger logger = LoggerFactory.getLogger(TestTransactionTest.class);
-
-
-
- @BeforeClass
- public static void startUp() throws IOException {
- logger.info("enter");
-
- cleanUpWorkingDir();
-
- /* ensure presence of config directory */
- SystemPersistence.manager.setConfigurationDir(null);
- }
-
- @Test
- public void registerUnregisterTest() throws InterruptedException {
- final Properties controllerProperties = new Properties();
- controllerProperties.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
- final PolicyController controller =
- PolicyEngine.manager.createPolicyController(TEST_CONTROLLER_NAME, controllerProperties);
- assertNotNull(PolicyController.factory.get(TEST_CONTROLLER_NAME));
- logger.info(controller.toString());
-
- Thread ttThread = null;
-
- TestTransaction.manager.register(controller);
- assertNotNull(TestTransaction.manager);
-
- /*
- * Unregistering the controller should terminate its TestTransaction thread if it hasn't already
- * been terminated
+ /** Test JUnit Controller Name. */
+ public static final String TEST_CONTROLLER_NAME = "unnamed";
+ /** Controller Configuration File. */
+ public static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
+
+ /** Controller Configuration Backup File. */
+ public static final String TEST_CONTROLLER_FILE_BAK =
+ TEST_CONTROLLER_NAME + "-controller.properties.bak";
+
+ /** logger. */
+ private static Logger logger = LoggerFactory.getLogger(TestTransactionTest.class);
+
+ /**
+ * Start up.
+ *
+ * @throws IOException exception
*/
- TestTransaction.manager.unregister(controller);
-
- ttThread = this.getThread("tt-controller-task-" + TEST_CONTROLLER_NAME);
- assertEquals(null, ttThread);
-
-
- }
+ @BeforeClass
+ public static void startUp() throws IOException {
+ logger.info("enter");
- /*
- * Returns thread object based on String name
- */
- public Thread getThread(String threadName) throws InterruptedException {
- // give a chance to the transaction thread to be spawned/destroyed
- Thread.sleep(5000L);
-
- final Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
- for (final Thread thread : threadSet) {
- if (thread.getName().equals(threadName)) {
- return thread;
- }
+ cleanUpWorkingDir();
+ /* ensure presence of config directory */
+ SystemPersistence.manager.setConfigurationDir(null);
}
- return null;
- }
-
- /**
- * clean up working directory
- */
- protected static void cleanUpWorkingDir() {
- final Path testControllerPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
- try {
- Files.deleteIfExists(testControllerPath);
- } catch (final Exception e) {
- logger.info("Problem cleaning {}", testControllerPath, e);
+
+ @Test
+ public void registerUnregisterTest() throws InterruptedException {
+ final Properties controllerProperties = new Properties();
+ controllerProperties.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
+ final PolicyController controller =
+ PolicyEngine.manager.createPolicyController(TEST_CONTROLLER_NAME, controllerProperties);
+ assertNotNull(PolicyController.factory.get(TEST_CONTROLLER_NAME));
+ logger.info(controller.toString());
+
+ TestTransaction.manager.register(controller);
+ assertNotNull(TestTransaction.manager);
+
+ /*
+ * Unregistering the controller should terminate its TestTransaction thread if it hasn't already
+ * been terminated
+ */
+ TestTransaction.manager.unregister(controller);
+
+ Thread ttThread = this.getThread("tt-controller-task-" + TEST_CONTROLLER_NAME);
+ assertEquals(null, ttThread);
}
- final Path testControllerBakPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
- try {
- Files.deleteIfExists(testControllerBakPath);
- } catch (final Exception e) {
- logger.info("Problem cleaning {}", testControllerBakPath, e);
+ /**
+ * Returns thread object based on String name.
+ *
+ * @param threadName thread name
+ * @return the thread
+ * @throws InterruptedException exception
+ */
+ public Thread getThread(String threadName) throws InterruptedException {
+ // give a chance to the transaction thread to be spawned/destroyed
+ Thread.sleep(5000L);
+
+ final Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
+ for (final Thread thread : threadSet) {
+ if (thread.getName().equals(threadName)) {
+ return thread;
+ }
+ }
+ return null;
}
- }
+ /** clean up working directory. */
+ protected static void cleanUpWorkingDir() {
+ final Path testControllerPath =
+ Paths.get(
+ SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
+ try {
+ Files.deleteIfExists(testControllerPath);
+ } catch (final Exception e) {
+ logger.info("Problem cleaning {}", testControllerPath, e);
+ }
+
+ final Path testControllerBakPath =
+ Paths.get(
+ SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
+ try {
+ Files.deleteIfExists(testControllerBakPath);
+ } catch (final Exception e) {
+ logger.info("Problem cleaning {}", testControllerBakPath, e);
+ }
+ }
}