aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/test/java/org
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-02-28 10:10:49 -0600
committerJorge Hernandez <jorge.hernandez-herrero@att.com>2019-03-01 09:56:11 -0600
commitb001c1ac5a0b4d938a69adb47f4613f64dc71c1a (patch)
treea83c2887edc25fd4eb24f3f6d485e8f860069c19 /policy-management/src/test/java/org
parent8e9ddde1bb1e3fc3f7b85af653d6251daf7e77d6 (diff)
move all hard install config to environment vars
+ support multiple system properties files with variable interpolation loaded at initialization + support of configurable JVM options (-X, etc ..). + rearrange aaf configuration to avoid {{}} installation variables and use dynamic enviroment variables. + miscellaneous clean up in areas touched and checkstyle. Change-Id: I71ad839778e17eb57c098a2c5cc2bf96e468669a Issue-ID: POLICY-1524 Signed-off-by: Jorge Hernandez <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-management/src/test/java/org')
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java (renamed from policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java)101
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java10
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java2
3 files changed, 67 insertions, 46 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/SystemPersistenceTest.java
index 1e51cfec..de0a7518 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/SystemPersistenceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
@@ -18,10 +18,10 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.drools.persistence.test;
+package org.onap.policy.drools.persistence;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.FileOutputStream;
@@ -30,56 +30,51 @@ import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.List;
import java.util.Properties;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import org.onap.policy.drools.persistence.FileSystemPersistence;
-import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.properties.DroolsProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* (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";
+ private static final String OTHER_CONFIG_DIR = "tmp";
/**
* Test JUnit Controller Name.
*/
- public static final String TEST_CONTROLLER_NAME = "foo";
+ private static final String TEST_CONTROLLER_NAME = "foo";
/**
* Test JUnit Controller Name.
*/
- public static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
+ private 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";
+ private 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 = TEST_CONTROLLER_NAME;
private static final String ENV_PROPS_FILE = ENV_PROPS + ".environment";
- private static final String POLICY_ENGINE_PROPERTIES_FILE = "policy-engine.properties";
+
+ /**
+ * Test JUnit system properties.
+ */
+ private static final String SYSTEM_PROPS = TEST_CONTROLLER_NAME;
+ private static final String SYSTEM_PROPS_FILE = SYSTEM_PROPS + "-system.properties";
@BeforeClass
public static void setUp() throws IOException {
@@ -92,22 +87,21 @@ public class SystemPersistenceTest {
}
@Test
- public void test1NonDefaultConfigDir() throws IOException {
- logger.info("enter");
-
+ public void test1NonDefaultConfigDir() {
SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
- assertTrue(
- SystemPersistence.manager.getConfigurationPath().toString().equals(OTHER_CONFIG_DIR));
+ assertEquals(OTHER_CONFIG_DIR, SystemPersistence.manager.getConfigurationPath().toString());
SystemPersistence.manager.setConfigurationDir(null);
- assertTrue(SystemPersistence.manager.getConfigurationPath().toString()
- .equals(SystemPersistence.DEFAULT_CONFIGURATION_DIR));
+ assertEquals(SystemPersistence.DEFAULT_CONFIGURATION_DIR,
+ SystemPersistence.manager.getConfigurationPath().toString());
+
+ SystemPersistence.manager.setConfigurationDir();
+ assertEquals(SystemPersistence.DEFAULT_CONFIGURATION_DIR,
+ SystemPersistence.manager.getConfigurationPath().toString());
}
@Test
- public void test2Engine() throws IOException {
- logger.info("enter");
-
+ public void test2Engine_Environment_System() throws IOException {
SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
final Path policyEnginePropsPath =
@@ -123,21 +117,33 @@ public class SystemPersistenceTest {
}
}
- assertEquals(SystemPersistence.manager.getEngineProperties(), engineProps);
+ assertEquals(engineProps, SystemPersistence.manager.getEngineProperties());
final Path environmentPropertiesPath =
Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), ENV_PROPS_FILE);
if (Files.notExists(environmentPropertiesPath)) {
Files.createFile(environmentPropertiesPath);
}
+ assertNotNull(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS));
assertTrue(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS).isEmpty());
- assertTrue(SystemPersistence.manager.getEnvironmentProperties().size() == 1);
+ assertEquals(1, SystemPersistence.manager.getEnvironmentProperties().size());
+ assertEquals(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS),
+ SystemPersistence.manager.getEnvironmentProperties().get(0));
+
+ Path systemPropertiesPath =
+ Paths.get(SystemPersistence.manager.getConfigurationPath().toString(), SYSTEM_PROPS_FILE);
+ if (Files.notExists(systemPropertiesPath)) {
+ Files.createFile(systemPropertiesPath);
+ }
+ assertNotNull(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS));
+ assertTrue(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS).isEmpty());
+ assertEquals(1, SystemPersistence.manager.getSystemProperties().size());
+ assertEquals(SystemPersistence.manager.getSystemProperties(SYSTEM_PROPS),
+ SystemPersistence.manager.getSystemProperties().get(0));
}
@Test
- public void test3PersistConfiguration() {
- logger.info("enter");
-
+ public void test3Controller() {
SystemPersistence.manager.setConfigurationDir(null);
final Path controllerPath = Paths
@@ -150,19 +156,21 @@ public class SystemPersistenceTest {
assertTrue(Files.notExists(controllerBakPath));
Properties properties = new Properties();
- properties.put(DroolsProperties.PROPERTY_CONTROLLER_NAME, TEST_CONTROLLER_NAME);
SystemPersistence.manager.storeController(TEST_CONTROLLER_NAME, properties);
assertTrue(Files.exists(controllerPath));
properties = SystemPersistence.manager.getControllerProperties(TEST_CONTROLLER_NAME);
- assertTrue(properties != null);
+ assertNotNull(properties);
+
+ List<Properties> controllerPropsList = SystemPersistence.manager.getControllerProperties();
+ assertEquals(1, controllerPropsList.size());
+ assertEquals(TEST_CONTROLLER_NAME, controllerPropsList
+ .get(0).getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME));
SystemPersistence.manager.backupController(TEST_CONTROLLER_NAME);
assertTrue(Files.exists(controllerBakPath));
- assertFalse(SystemPersistence.manager.getControllerProperties().isEmpty());
-
SystemPersistence.manager.deleteController(TEST_CONTROLLER_NAME);
assertTrue(Files.notExists(controllerPath));
}
@@ -172,22 +180,25 @@ public class SystemPersistenceTest {
*
* @throws IOException throws IO exception
*/
- public static void cleanUpWorkingDirs() throws IOException {
-
+ private static void cleanUpWorkingDirs() throws IOException {
SystemPersistence.manager.setConfigurationDir(null);
- final Path testControllerPath = Paths
- .get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
+ for (Properties properties : SystemPersistence.manager.getControllerProperties()) {
+ SystemPersistence.manager.deleteController(properties
+ .getProperty(DroolsProperties.PROPERTY_CONTROLLER_NAME));
+ }
+
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 policyEnginePath = Paths.get(OTHER_CONFIG_DIR, FileSystemPersistence.PROPERTIES_FILE_ENGINE);
final Path environmentPath = Paths.get(OTHER_CONFIG_DIR, ENV_PROPS_FILE);
+ final Path systemPath = Paths.get(OTHER_CONFIG_DIR, SYSTEM_PROPS_FILE);
- Files.deleteIfExists(testControllerPath);
Files.deleteIfExists(testControllerBakPath);
Files.deleteIfExists(policyEnginePath);
Files.deleteIfExists(environmentPath);
+ Files.deleteIfExists(systemPath);
}
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index 4b8357a2..8050b26a 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -368,6 +368,16 @@ public class PolicyEngineManagerTest {
assertNotNull(mgr.getEnvironmentProperty("PATH"));
assertNull(mgr.getEnvironmentProperty("unknown-env-property"));
+
+ System.setProperty("propS-a", "valueS-a");
+ assertEquals("valueS-a", mgr.getEnvironmentProperty("propS-a"));
+
+ Properties props3 = new Properties();
+ props3.put("prop3-a", "${env:HOME}");
+ mgr.setEnvironment(props3);
+ assertEquals(System.getenv("HOME"), mgr.getEnvironmentProperty("prop3-a"));
+ assertEquals("valueS-a", mgr.getEnvironmentProperty("propS-a"));
+ assertEquals(newValue, mgr.getEnvironmentProperty(propKey));
}
@Test
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
index a00d6db2..64af6d4f 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
@@ -163,7 +163,7 @@ public class PolicyEngineTest {
PolicyEngine.manager.configure(engineProps);
assertFalse(PolicyEngine.manager.isAlive());
- logger.info("policy-engine {} has configuration {}", PolicyEngine.manager, engineProps);
+ logger.info("engine {} has configuration {}", PolicyEngine.manager, engineProps);
gson.compareGson(PolicyEngine.manager, new File(PolicyEngineTest.class.getSimpleName() + "Config.json"));
}