aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java')
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java240
1 files changed, 123 insertions, 117 deletions
diff --git a/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java b/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java
index 9b2e6161..1e51cfec 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * 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.
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policy.drools.persistence.test;
import static org.junit.Assert.assertEquals;
@@ -43,145 +44,150 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * (File) System Persistence Tests
+ * (File) System Persistence Tests.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SystemPersistenceTest {
- /**
- * logger
- */
- private static final Logger logger = LoggerFactory.getLogger(SystemPersistenceTest.class);
-
- /**
- * sample configuration dir
- */
- public static final String OTHER_CONFIG_DIR = "tmp";
-
- /**
- * Test JUnit Controller Name
- */
- public static final String TEST_CONTROLLER_NAME = "foo";
-
- /**
- * Test JUnit Controller Name
- */
- public static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
-
- /**
- * Test JUnit Controller Name Backup
- */
- public static final String TEST_CONTROLLER_FILE_BAK = TEST_CONTROLLER_FILE + ".bak";
-
- /**
- * Test JUnit Environment/Engine properties
- */
- private static final String ENV_PROPS = "envProps";
- private static final String ENV_PROPS_FILE = ENV_PROPS + ".environment";
- private static final String POLICY_ENGINE_PROPERTIES_FILE = "policy-engine.properties";
-
- @BeforeClass
- public static void setUp() throws IOException {
- cleanUpWorkingDirs();
- }
-
- @AfterClass
- public static void tearDown() throws IOException {
- cleanUpWorkingDirs();
- }
-
- @Test
- public void test1NonDefaultConfigDir() throws IOException {
- logger.info("enter");
-
- SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
- assertTrue(
- SystemPersistence.manager.getConfigurationPath().toString().equals(OTHER_CONFIG_DIR));
-
- SystemPersistence.manager.setConfigurationDir(null);
- assertTrue(SystemPersistence.manager.getConfigurationPath().toString()
- .equals(SystemPersistence.DEFAULT_CONFIGURATION_DIR));
- }
-
- @Test
- public void test2Engine() throws IOException {
- logger.info("enter");
-
- SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
-
- final Path policyEnginePropsPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(),
- FileSystemPersistence.PROPERTIES_FILE_ENGINE);
-
- final Properties engineProps = new Properties();
- engineProps.setProperty("foo", "bar");
- engineProps.setProperty("fiz", "buz");
- if (Files.notExists(policyEnginePropsPath)) {
- try (final OutputStream fout = new FileOutputStream(policyEnginePropsPath.toFile())) {
- engineProps.store(fout, "");
- }
+ /**
+ * logger.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(SystemPersistenceTest.class);
+
+ /**
+ * sample configuration dir.
+ */
+ public static final String OTHER_CONFIG_DIR = "tmp";
+
+ /**
+ * Test JUnit Controller Name.
+ */
+ public static final String TEST_CONTROLLER_NAME = "foo";
+
+ /**
+ * Test JUnit Controller Name.
+ */
+ public static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
+
+ /**
+ * Test JUnit Controller Name Backup.
+ */
+ public static final String TEST_CONTROLLER_FILE_BAK = TEST_CONTROLLER_FILE + ".bak";
+
+ /**
+ * Test JUnit Environment/Engine properties.
+ */
+ private static final String ENV_PROPS = "envProps";
+ private static final String ENV_PROPS_FILE = ENV_PROPS + ".environment";
+ private static final String POLICY_ENGINE_PROPERTIES_FILE = "policy-engine.properties";
+
+ @BeforeClass
+ public static void setUp() throws IOException {
+ cleanUpWorkingDirs();
+ }
+
+ @AfterClass
+ public static void tearDown() throws IOException {
+ cleanUpWorkingDirs();
}
- assertEquals(SystemPersistence.manager.getEngineProperties(), engineProps);
+ @Test
+ public void test1NonDefaultConfigDir() throws IOException {
+ logger.info("enter");
+
+ SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
+ assertTrue(
+ SystemPersistence.manager.getConfigurationPath().toString().equals(OTHER_CONFIG_DIR));
- final Path environmentPropertiesPath =
- Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), ENV_PROPS_FILE);
- if (Files.notExists(environmentPropertiesPath)) {
- Files.createFile(environmentPropertiesPath);
+ SystemPersistence.manager.setConfigurationDir(null);
+ assertTrue(SystemPersistence.manager.getConfigurationPath().toString()
+ .equals(SystemPersistence.DEFAULT_CONFIGURATION_DIR));
}
- assertTrue(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS).isEmpty());
- assertTrue(SystemPersistence.manager.getEnvironmentProperties().size() == 1);
- }
- @Test
- public void test3PersistConfiguration() {
- logger.info("enter");
+ @Test
+ public void test2Engine() throws IOException {
+ logger.info("enter");
+
+ SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
+
+ final Path policyEnginePropsPath =
+ Paths.get(SystemPersistence.manager.getConfigurationPath().toString(),
+ FileSystemPersistence.PROPERTIES_FILE_ENGINE);
+
+ final Properties engineProps = new Properties();
+ engineProps.setProperty("foo", "bar");
+ engineProps.setProperty("fiz", "buz");
+ if (Files.notExists(policyEnginePropsPath)) {
+ try (final OutputStream fout = new FileOutputStream(policyEnginePropsPath.toFile())) {
+ engineProps.store(fout, "");
+ }
+ }
+
+ assertEquals(SystemPersistence.manager.getEngineProperties(), engineProps);
+
+ final Path environmentPropertiesPath =
+ Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), ENV_PROPS_FILE);
+ if (Files.notExists(environmentPropertiesPath)) {
+ Files.createFile(environmentPropertiesPath);
+ }
+ assertTrue(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS).isEmpty());
+ assertTrue(SystemPersistence.manager.getEnvironmentProperties().size() == 1);
+ }
+
+ @Test
+ public void test3PersistConfiguration() {
+ logger.info("enter");
- SystemPersistence.manager.setConfigurationDir(null);
+ SystemPersistence.manager.setConfigurationDir(null);
- final Path controllerPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
+ final Path controllerPath = Paths
+ .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
- final Path controllerBakPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
+ final Path controllerBakPath = Paths
+ .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
- assertTrue(Files.notExists(controllerPath));
- assertTrue(Files.notExists(controllerBakPath));
+ assertTrue(Files.notExists(controllerPath));
+ assertTrue(Files.notExists(controllerBakPath));
- Properties properties = new Properties();
- properties.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
- SystemPersistence.manager.storeController(TEST_CONTROLLER_NAME, properties);
+ Properties properties = new Properties();
+ properties.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
+ SystemPersistence.manager.storeController(TEST_CONTROLLER_NAME, properties);
- assertTrue(Files.exists(controllerPath));
+ assertTrue(Files.exists(controllerPath));
- properties = SystemPersistence.manager.getControllerProperties(TEST_CONTROLLER_NAME);
- assertTrue(properties != null);
+ properties = SystemPersistence.manager.getControllerProperties(TEST_CONTROLLER_NAME);
+ assertTrue(properties != null);
- SystemPersistence.manager.backupController(TEST_CONTROLLER_NAME);
- assertTrue(Files.exists(controllerBakPath));
+ SystemPersistence.manager.backupController(TEST_CONTROLLER_NAME);
+ assertTrue(Files.exists(controllerBakPath));
- assertFalse(SystemPersistence.manager.getControllerProperties().isEmpty());
+ assertFalse(SystemPersistence.manager.getControllerProperties().isEmpty());
- SystemPersistence.manager.deleteController(TEST_CONTROLLER_NAME);
- assertTrue(Files.notExists(controllerPath));
- }
+ SystemPersistence.manager.deleteController(TEST_CONTROLLER_NAME);
+ assertTrue(Files.notExists(controllerPath));
+ }
- public static void cleanUpWorkingDirs() throws IOException {
+ /**
+ * Clean up the working directories.
+ *
+ * @throws IOException throws IO exception
+ */
+ public static void cleanUpWorkingDirs() throws IOException {
- SystemPersistence.manager.setConfigurationDir(null);
+ SystemPersistence.manager.setConfigurationDir(null);
- final Path testControllerPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
- final Path testControllerBakPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
+ final Path testControllerPath = Paths
+ .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
+ final Path testControllerBakPath = Paths
+ .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE_BAK);
- final Path policyEnginePath = Paths.get(OTHER_CONFIG_DIR, POLICY_ENGINE_PROPERTIES_FILE);
- final Path environmentPath = Paths.get(OTHER_CONFIG_DIR, ENV_PROPS_FILE);
+ final Path policyEnginePath = Paths.get(OTHER_CONFIG_DIR, POLICY_ENGINE_PROPERTIES_FILE);
+ final Path environmentPath = Paths.get(OTHER_CONFIG_DIR, ENV_PROPS_FILE);
- Files.deleteIfExists(testControllerPath);
- Files.deleteIfExists(testControllerBakPath);
- Files.deleteIfExists(policyEnginePath);
- Files.deleteIfExists(environmentPath);
- }
+ Files.deleteIfExists(testControllerPath);
+ Files.deleteIfExists(testControllerBakPath);
+ Files.deleteIfExists(policyEnginePath);
+ Files.deleteIfExists(environmentPath);
+ }
}