summaryrefslogtreecommitdiffstats
path: root/policy-management
diff options
context:
space:
mode:
Diffstat (limited to 'policy-management')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java14
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java30
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java4
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java5
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java1
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java8
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/persistence/test/SystemPersistenceTest.java62
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java99
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java108
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java345
-rw-r--r--policy-management/src/test/resources/logback-test.xml2
11 files changed, 651 insertions, 27 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
index e217ee7d..905e50c2 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
@@ -27,6 +27,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Properties;
@@ -208,7 +209,7 @@ public class FileSystemPersistence implements SystemPersistence {
@Override
public List<Properties> getControllerProperties() {
final List<Properties> controllers = new ArrayList<>();
- final File[] controllerFiles = this.configurationDirectory.toFile().listFiles();
+ final File[] controllerFiles = this.sortedListFiles();
for (final File controllerFile : controllerFiles) {
if (controllerFile.getName().endsWith(PROPERTIES_FILE_CONTROLLER_SUFFIX)) {
final int idxSuffix = controllerFile.getName().indexOf(PROPERTIES_FILE_CONTROLLER_SUFFIX);
@@ -262,7 +263,7 @@ public class FileSystemPersistence implements SystemPersistence {
@Override
public List<Properties> getEnvironmentProperties() {
final List<Properties> envs = new ArrayList<>();
- final File[] envFiles = this.configurationDirectory.toFile().listFiles();
+ final File[] envFiles = this.sortedListFiles();
for (final File envFile : envFiles) {
if (envFile.getName().endsWith(ENV_SUFFIX)) {
final String name = envFile.getName().substring(0, envFile.getName().indexOf(ENV_SUFFIX));
@@ -290,6 +291,15 @@ public class FileSystemPersistence implements SystemPersistence {
}
}
+ /**
+ * provides a list of files sorted by name in ascending order in the configuration directory
+ */
+ protected File[] sortedListFiles() {
+ final File[] dirFiles = this.configurationDirectory.toFile().listFiles();
+ Arrays.sort(dirFiles, (a, b) -> a.getName().compareTo(b.getName()));
+ return dirFiles;
+ }
+
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
index 762f4476..6f14076f 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/EventProtocolCoder.java
@@ -670,13 +670,13 @@ abstract class GenericEventProtocolCoder {
* and consequently the second value will be the less likely.
*/
protected final HashMap<String, Pair<ProtocolCoderToolset,ProtocolCoderToolset>> coders =
- new HashMap<String, Pair<ProtocolCoderToolset,ProtocolCoderToolset>>();
+ new HashMap<>();
/**
* Mapping topic + classname -> Protocol Set
*/
protected final HashMap<String, List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>>> reverseCoders =
- new HashMap<String, List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>>>();
+ new HashMap<>();
protected boolean multipleToolsetRetries = false;
@@ -735,7 +735,7 @@ abstract class GenericEventProtocolCoder {
this, reverseKey, key, toolsets.first());
List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> reverseMappings =
- new ArrayList<Pair<ProtocolCoderToolset,ProtocolCoderToolset>>();
+ new ArrayList<>();
reverseMappings.add(toolsets);
reverseCoders.put(reverseKey, reverseMappings);
}
@@ -767,7 +767,7 @@ abstract class GenericEventProtocolCoder {
// are detected in the gson encoding
Pair<ProtocolCoderToolset,ProtocolCoderToolset> coderTools =
- new Pair<ProtocolCoderToolset,ProtocolCoderToolset>(gsonCoderTools,
+ new Pair<>(gsonCoderTools,
jacksonCoderTools);
logger.info("{}: adding coders for new {}: {}", this, key, coderTools.first());
@@ -800,7 +800,7 @@ abstract class GenericEventProtocolCoder {
}
} else {
List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> toolsets =
- new ArrayList<Pair<ProtocolCoderToolset,ProtocolCoderToolset>>();
+ new ArrayList<>();
toolsets.add(coderTools);
logger.info("{}: adding toolset for reverse key {}: {}", this, reverseKey, toolsets);
@@ -909,7 +909,7 @@ abstract class GenericEventProtocolCoder {
String key = this.codersKey(groupId, artifactId, topic);
synchronized(this) {
- return (coders.containsKey(key));
+ return coders.containsKey(key);
}
}
@@ -1102,7 +1102,7 @@ abstract class GenericEventProtocolCoder {
protected List<DroolsController> droolsCreators(String topic, Object encodedClass)
throws IllegalStateException, IllegalArgumentException {
- List<DroolsController> droolsControllers = new ArrayList<DroolsController>();
+ List<DroolsController> droolsControllers = new ArrayList<>();
String reverseKey = this.reverseCodersKey(topic, encodedClass.getClass().getCanonicalName());
if (!this.reverseCoders.containsKey(reverseKey)) {
@@ -1127,8 +1127,8 @@ abstract class GenericEventProtocolCoder {
// figure out the right toolset
String groupId = encoderSet.first().getGroupId();
String artifactId = encoderSet.first().getArtifactId();
- List<CoderFilters> coders = encoderSet.first().getCoders();
- for (CoderFilters coder : coders) {
+ List<CoderFilters> coderFilters = encoderSet.first().getCoders();
+ for (CoderFilters coder : coderFilters) {
if (coder.getCodedClass().equals(encodedClass.getClass().getCanonicalName())) {
DroolsController droolsController =
DroolsController.factory.get(groupId, artifactId, "");
@@ -1206,7 +1206,7 @@ abstract class GenericEventProtocolCoder {
String key = this.codersKey(groupId, artifactId, "");
- List<CoderFilters> codersFilters = new ArrayList<CoderFilters>();
+ List<CoderFilters> codersFilters = new ArrayList<>();
for (Map.Entry<String, Pair<ProtocolCoderToolset,ProtocolCoderToolset>> entry : coders.entrySet()) {
if (entry.getKey().startsWith(key)) {
codersFilters.addAll(entry.getValue().first().getCoders());
@@ -1235,7 +1235,7 @@ abstract class GenericEventProtocolCoder {
String key = this.codersKey(groupId, artifactId, "");
- List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> coderToolset = new ArrayList<Pair<ProtocolCoderToolset,ProtocolCoderToolset>>();
+ List<Pair<ProtocolCoderToolset,ProtocolCoderToolset>> coderToolset = new ArrayList<>();
for (Map.Entry<String, Pair<ProtocolCoderToolset,ProtocolCoderToolset>> entry : coders.entrySet()) {
if (entry.getKey().startsWith(key)) {
coderToolset.add(entry.getValue());
@@ -1293,12 +1293,12 @@ abstract class GenericEventProtocolCoder {
throw new IllegalArgumentException("No Coder found for " + key);
- List<CoderFilters> coders = new ArrayList<CoderFilters>();
+ List<CoderFilters> coderFilters = new ArrayList<>();
for (Pair<ProtocolCoderToolset,ProtocolCoderToolset> toolset: toolsets) {
- coders.addAll(toolset.first().getCoders());
+ coderFilters.addAll(toolset.first().getCoders());
}
- return coders;
+ return coderFilters;
}
/**
@@ -1390,4 +1390,4 @@ class EventProtocolEncoder extends GenericEventProtocolCoder {
builder.append("EventProtocolEncoder [toString()=").append(super.toString()).append("]");
return builder.toString();
}
-} \ No newline at end of file
+}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
index 6afeb26a..0a52d254 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/JsonProtocolFilter.java
@@ -119,7 +119,7 @@ public class JsonProtocolFilter {
/**
* all the filters to be applied
*/
- protected List<FilterRule> rules = new ArrayList<FilterRule>();
+ protected List<FilterRule> rules = new ArrayList<>();
/**
*
@@ -134,7 +134,7 @@ public class JsonProtocolFilter {
throw new IllegalArgumentException("No raw filters provided");
}
- List<FilterRule> filters = new ArrayList<FilterRule>();
+ List<FilterRule> filters = new ArrayList<>();
for (Pair<String, String> filterPair: rawFilters) {
if (filterPair.first() == null || filterPair.first().isEmpty()) {
continue;
diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
index 1c8dafea..df51473d 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java
@@ -87,7 +87,7 @@ public abstract class ProtocolCoderToolset {
/**
* Protocols and associated Filters
*/
- protected final List<CoderFilters> coders = new ArrayList<CoderFilters>();
+ protected final List<CoderFilters> coders = new ArrayList<>();
/**
* Tree model (instead of class model) generic parsing to be able to inspect elements
@@ -488,7 +488,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
* Adapter for ZonedDateTime
*/
public static class GsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
-
+ @Override
public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context)
throws JsonParseException {
try {
@@ -500,6 +500,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset {
return null;
}
+ @Override
public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) {
return new JsonPrimitive(datetime.format(format));
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java
index 48eedfa5..93bdc0b2 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java
@@ -375,6 +375,7 @@ public class RestManager {
if (controller != null)
return Response.status(Response.Status.NOT_MODIFIED).entity(controller).build();
} catch (final IllegalArgumentException e) {
+ logger.trace("OK ", e);
// This is OK
} catch (final IllegalStateException e) {
logger.info("{}: cannot get policy-controller because of {}", this, e.getMessage(), e);
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
index 34c8589f..d0b625d7 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
@@ -190,13 +190,13 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
* Policy Controller Name Index
*/
protected HashMap<String,PolicyController> policyControllers =
- new HashMap<String,PolicyController>();
+ new HashMap<>();
/**
* Group/Artifact Ids Index
*/
protected HashMap<String,PolicyController> coordinates2Controller =
- new HashMap<String,PolicyController>();
+ new HashMap<>();
/**
* produces key for indexing controller names
@@ -479,7 +479,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
@Override
public List<PolicyController> inventory() {
List<PolicyController> controllers =
- new ArrayList<PolicyController>(this.policyControllers.values());
+ new ArrayList<>(this.policyControllers.values());
return controllers;
}
@@ -488,7 +488,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
*/
@Override
public List<String> getFeatures() {
- List<String> features = new ArrayList<String>();
+ List<String> features = new ArrayList<>();
for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) {
features.add(feature.getName());
}
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 db8f306c..788da053 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
@@ -19,17 +19,23 @@
*/
package org.onap.policy.drools.persistence.test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.drools.persistence.FileSystemPersistence;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.properties.PolicyProperties;
import org.slf4j.Logger;
@@ -65,6 +71,14 @@ public class SystemPersistenceTest {
*/
public static final String TEST_CONTROLLER_FILE_BAK =
TEST_CONTROLLER_NAME + "-controller.properties.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";
+
@Test
public void nonDefaultConfigDir() throws IOException {
@@ -78,14 +92,51 @@ public class SystemPersistenceTest {
assertTrue(SystemPersistence.manager.getConfigurationPath().toString()
.equals(SystemPersistence.DEFAULT_CONFIGURATION_DIR));
+ this.engineConfiguration();
this.persistConfiguration();
cleanUpWorkingDirs();
}
+ public void engineConfiguration() {
+ SystemPersistence.manager.setConfigurationDir(OTHER_CONFIG_DIR);
+ final Path policyEnginePropsPath = Paths.get(OTHER_CONFIG_DIR + "/" + FileSystemPersistence.PROPERTIES_FILE_ENGINE);
+ final Path environmentPropertiesPath = Paths.get(OTHER_CONFIG_DIR + "/" + ENV_PROPS_FILE);
+
+ Properties policyEnginePropsObject, emptyProps;
+ emptyProps = new Properties();
+
+ List<Properties> envPropertesList = new ArrayList<>();
+ envPropertesList.add(emptyProps);
+
+ policyEnginePropsObject = new Properties();
+ policyEnginePropsObject.setProperty("foo", "bar");
+ policyEnginePropsObject.setProperty("fiz", "buz");
+
+ try {
+
+ if (Files.notExists(environmentPropertiesPath)) {
+ Files.createFile(environmentPropertiesPath);
+ }
+
+ if (Files.notExists(policyEnginePropsPath)) {
+ OutputStream fout = new FileOutputStream(policyEnginePropsPath.toFile());
+ policyEnginePropsObject.store(fout, "");
+ fout.close();
+ }
+ } catch (IOException e) {
+ logger.error("Problem creating {}", policyEnginePropsPath);
+ }
+
+ assertEquals(SystemPersistence.manager.getEngineProperties(), policyEnginePropsObject);
+ assertEquals(SystemPersistence.manager.getEnvironmentProperties(ENV_PROPS), emptyProps);
+ assertEquals(SystemPersistence.manager.getEnvironmentProperties(), envPropertesList);
+
+ }
+
public void persistConfiguration() {
logger.info("enter");
-
+
final Path controllerPath = Paths
.get(SystemPersistence.manager.getConfigurationPath().toString(), TEST_CONTROLLER_FILE);
@@ -121,9 +172,18 @@ public class SystemPersistenceTest {
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);
+
Files.deleteIfExists(testControllerPath);
Files.deleteIfExists(testControllerBakPath);
+ Files.deleteIfExists(policyEnginePath);
+ Files.deleteIfExists(environmentPath);
Files.deleteIfExists(Paths.get(OTHER_CONFIG_DIR));
+
}
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java
new file mode 100644
index 00000000..bfebeacf
--- /dev/null
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java
@@ -0,0 +1,99 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Configuration Test
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.drools.protocol.configuration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.junit.Test;
+
+public class ControllerConfigurationTest {
+
+
+ private static final String NAME = "name";
+ private static final String OPERATION = "operation";
+ private static final String NAME2 = "name2";
+ private static final String OPERATION2 = "operation2";
+
+ private static final String ARTIFACT = "org.onap.artifact";
+ private static final String GROUPID = "group";
+ private static final String VERSION = "1.0.0";
+
+ private static final String ARTIFACT2 = "org.onap.artifact2";
+ private static final String GROUPID2 = "group2";
+ private static final String VERSION2 = "1.0.1";
+
+ private static final String ADDITIONAL_PROPERTY_KEY = "foo";
+ private static final String ADDITIONAL_PROPERTY_VALUE = "bar";
+
+ private static final DroolsConfiguration DROOLS_CONFIG = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
+ private static final DroolsConfiguration DROOLS_CONFIG2 = new DroolsConfiguration(ARTIFACT2, GROUPID2, VERSION2);
+
+ private static final String DROOLS_STRING = "drools";
+ @Test
+ public void test() {
+
+ Properties additionalProperties = new Properties();
+ additionalProperties.put(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
+
+ ControllerConfiguration controllerConfig = new ControllerConfiguration(NAME, OPERATION, DROOLS_CONFIG);
+
+ assertTrue(controllerConfig.equals(controllerConfig));
+ assertFalse(controllerConfig.equals(new Object()));
+
+ ControllerConfiguration controllerConfig2 = new ControllerConfiguration();
+ controllerConfig2.setName(NAME2);
+ controllerConfig2.setOperation(OPERATION2);
+ controllerConfig2.setDrools(DROOLS_CONFIG2);
+
+ assertEquals(controllerConfig2.getName(), NAME2);
+ assertEquals(controllerConfig2.getOperation(), OPERATION2);
+ assertEquals(controllerConfig2.getDrools(), DROOLS_CONFIG2);
+
+ assertEquals(controllerConfig2, controllerConfig2.withName(NAME2));
+ assertEquals(controllerConfig2, controllerConfig2.withOperation(OPERATION2));
+ assertEquals(controllerConfig2, controllerConfig2.withDrools(DROOLS_CONFIG2));
+
+ controllerConfig2.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
+ assertEquals(controllerConfig2.getAdditionalProperties(), additionalProperties);
+
+ assertEquals(controllerConfig2, controllerConfig2.withAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE));
+
+ assertTrue(controllerConfig2.declaredProperty(NAME, NAME2));
+ assertTrue(controllerConfig2.declaredProperty(OPERATION, OPERATION2));
+ assertTrue(controllerConfig2.declaredProperty(DROOLS_STRING, DROOLS_CONFIG2));
+ assertFalse(controllerConfig2.declaredProperty("dummy", NAME));
+
+
+ assertEquals(controllerConfig2.declaredPropertyOrNotFound(NAME, NAME2), NAME2);
+ assertEquals(controllerConfig2.declaredPropertyOrNotFound(OPERATION, OPERATION2), OPERATION2);
+ assertEquals(controllerConfig2.declaredPropertyOrNotFound(DROOLS_STRING, DROOLS_CONFIG2), DROOLS_CONFIG2);
+ assertEquals(controllerConfig2.declaredPropertyOrNotFound("dummy", NAME), NAME);
+
+ int hashCode = new HashCodeBuilder().append(NAME2).append(OPERATION2).append(DROOLS_CONFIG2).append(additionalProperties).toHashCode();
+ assertEquals(controllerConfig2.hashCode(), hashCode);
+
+ }
+
+
+}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java
new file mode 100644
index 00000000..8ecda75d
--- /dev/null
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Configuration Test
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.drools.protocol.configuration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+
+import org.apache.commons.lang3.builder.HashCodeBuilder;
+import org.junit.Test;
+
+public class DroolsConfigurationTest {
+ private static final String ARTIFACT_ID_STRING = "artifactId";
+ private static final String GROUP_ID_STRING = "groupId";
+ private static final String VERSION_STRING = "version";
+
+
+ private static final String NAME = "name";
+ private static final String OPERATION = "operation";
+ private static final String NAME2 = "name2";
+ private static final String OPERATION2 = "operation2";
+
+ private static final String ARTIFACT = "org.onap.artifact";
+ private static final String GROUPID = "group";
+ private static final String VERSION = "1.0.0";
+
+ private static final String ARTIFACT2 = "org.onap.artifact2";
+ private static final String GROUPID2 = "group2";
+ private static final String VERSION2 = "1.0.1";
+
+ private static final String ADDITIONAL_PROPERTY_KEY = "foo";
+ private static final String ADDITIONAL_PROPERTY_VALUE = "bar";
+
+ private static final DroolsConfiguration DROOLS_CONFIG = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
+ private static final DroolsConfiguration DROOLS_CONFIG2 = new DroolsConfiguration(ARTIFACT2, GROUPID2, VERSION2);
+
+
+
+ @Test
+ public void test() {
+ Properties additionalProperties = new Properties();
+ additionalProperties.put(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
+
+ DroolsConfiguration droolsConfig = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
+ assertTrue(droolsConfig.equals(droolsConfig));
+
+ droolsConfig.set(ARTIFACT_ID_STRING, "foobar");
+ assertEquals(droolsConfig.get(ARTIFACT_ID_STRING),"foobar");
+
+ assertEquals(droolsConfig.with(ARTIFACT_ID_STRING, "foobar2"), droolsConfig);
+
+ DroolsConfiguration droolsConfig2 = new DroolsConfiguration();
+ droolsConfig2.setArtifactId(ARTIFACT2);
+ droolsConfig2.setGroupId(GROUPID2);
+ droolsConfig2.setVersion(VERSION2);
+
+ assertEquals(droolsConfig2.getArtifactId(), ARTIFACT2);
+ assertEquals(droolsConfig2.getGroupId(), GROUPID2);
+ assertEquals(droolsConfig2.getVersion(), VERSION2);
+
+ assertEquals(droolsConfig2.withArtifactId(ARTIFACT2), droolsConfig2);
+ assertEquals(droolsConfig2.withGroupId(GROUPID2), droolsConfig2);
+ assertEquals(droolsConfig2.withVersion(VERSION2), droolsConfig2);
+
+ droolsConfig2.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
+ assertEquals(droolsConfig2.getAdditionalProperties(), additionalProperties);
+
+ assertEquals(droolsConfig2, droolsConfig2.withAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE));
+
+ assertTrue(droolsConfig2.declaredProperty(ARTIFACT_ID_STRING, ARTIFACT2));
+ assertTrue(droolsConfig2.declaredProperty(GROUP_ID_STRING, GROUPID2));
+ assertTrue(droolsConfig2.declaredProperty(VERSION_STRING, VERSION2));
+ assertFalse(droolsConfig2.declaredProperty("dummy", NAME));
+
+ assertEquals(droolsConfig2.declaredPropertyOrNotFound(ARTIFACT_ID_STRING, ARTIFACT2), ARTIFACT2);
+ assertEquals(droolsConfig2.declaredPropertyOrNotFound(GROUP_ID_STRING, GROUPID2), GROUPID2);
+ assertEquals(droolsConfig2.declaredPropertyOrNotFound(VERSION_STRING, VERSION2), VERSION2);
+ assertEquals(droolsConfig2.declaredPropertyOrNotFound("dummy", ARTIFACT2), ARTIFACT2);
+
+ int hashCode = new HashCodeBuilder().append(ARTIFACT2).append(GROUPID2).append(VERSION2).append(additionalProperties).toHashCode();
+ assertEquals(droolsConfig2.hashCode(), hashCode);
+
+
+
+
+ }
+
+
+}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
new file mode 100644
index 00000000..c04db288
--- /dev/null
+++ b/policy-management/src/test/java/org/onap/policy/drools/server/restful/test/RestManagerTest.java
@@ -0,0 +1,345 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-management
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.server.restful.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.drools.properties.PolicyProperties;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+public class RestManagerTest {
+
+
+ public static final int DEFAULT_TELEMETRY_PORT = 9698;
+ private static final String HOST = "localhost";
+ private static final String REST_MANAGER_PATH = "/policy/pdp";
+ private static final String HOST_URL = "http://" + HOST + ":" + DEFAULT_TELEMETRY_PORT + REST_MANAGER_PATH;
+ private static final String FOO_CONTROLLER = "foo-controller";
+ private static CloseableHttpClient client;
+
+ private static final Logger logger = LoggerFactory.getLogger(RestManagerTest.class);
+
+ @BeforeClass
+ public static void setUp() {
+ /* override default port */
+ final Properties engineProps = PolicyEngine.manager.defaultTelemetryConfig();
+ engineProps.put(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
+ + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX,
+ "" + DEFAULT_TELEMETRY_PORT);
+ PolicyEngine.manager.configure(engineProps);
+ PolicyEngine.manager.start();
+
+ client = HttpClients.createDefault();
+
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ PolicyEngine.manager.shutdown();
+
+ }
+
+
+ @Test
+ public void GETTest() throws ClientProtocolException, IOException, InterruptedException {
+ assertTrue(PolicyEngine.manager.isAlive());
+
+ HttpGet httpGet;
+ CloseableHttpResponse response;
+ String responseBody;
+
+ httpGet = new HttpGet(HOST_URL + "/engine");
+ response = client.execute(httpGet);
+ logger.info("/engine response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/features");
+ response = client.execute(httpGet);
+ logger.info("/engine/features response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/features/inventory");
+ response = client.execute(httpGet);
+ logger.info("/engine/features/inventory response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/features/foobar");
+ response = client.execute(httpGet);
+ logger.info("/engine/features/foobar response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/inputs");
+ response = client.execute(httpGet);
+ logger.info("/engine/inputs response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/properties");
+ response = client.execute(httpGet);
+ logger.info("/engine/properties response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/environment");
+ response = client.execute(httpGet);
+ logger.info("/engine/environment response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ PolicyEngine.manager.setEnvironmentProperty("foo", "bar");
+ httpGet = new HttpGet(HOST_URL + "/engine/environment/foo");
+ response = client.execute(httpGet);
+ responseBody = getResponseBody(response);
+ logger.info("/engine/environment/foo response code: {}",response.getStatusLine().getStatusCode());
+ logger.info("/engine/environment/foo response body: {}",responseBody);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("bar", responseBody);
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/switches");
+ response = client.execute(httpGet);
+ logger.info("/engine/switches response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ Properties controllerProps = new Properties();
+ PolicyEngine.manager.createPolicyController(FOO_CONTROLLER, controllerProps);
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers");
+ response = client.execute(httpGet);
+ responseBody = getResponseBody(response);
+ logger.info("/engine/controllers response code: {}",response.getStatusLine().getStatusCode());
+ logger.info("/engine/controllers response body: {}",responseBody);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("[\"" + FOO_CONTROLLER +"\"]", responseBody);
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/inventory");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/inventory response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/features");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/features response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/features/inventory");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/features/inventory response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/features/dummy");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/features/dummy response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER);
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/ response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/nonexistantcontroller response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/properties");
+ response = client.execute(httpGet);
+ responseBody = getResponseBody(response);
+ logger.info("/engine/controllers/contoller/properties response code: {}", response.getStatusLine().getStatusCode());
+ logger.info("/engine/controllers/contoller/properties response code: {}", responseBody);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("{}", responseBody);
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/properties");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/nonexistantcontroller/properties response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/inputs");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/inputs response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/switches");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/switches response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/drools response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/drools");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/nonexistantcontroller/drools response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/drools/facts response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/drools/facts");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/nonexistantcontroller/drools/facts response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts/dummy");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/drools/facts/fact response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts/dummy/dummy");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/drools/facts/fact response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/drools/facts/session/query/queriedEntity");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/drools/facts/session/query/queriedEntity response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/decoders response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/decoders");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/nonexistantcontroller/decoders response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/filters");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controllers/decoders/filters response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/nonexistantcontroller/decoders/filters");
+ response = client.execute(httpGet);
+ logger.info("engine/controllers/nonexistantcontroller/decoders/filters response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controllers/decoders/topics response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controllers/decoders/topic/filters response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters/factType");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controller/decoders/topic/filters/factType response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters/factType/rules");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controllers/decoders/topic/filters/factType/rules response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+ httpGet = new HttpGet(HOST_URL + "/engine/controllers/" + FOO_CONTROLLER + "/decoders/topic/filters/factType/rules/ruleName");
+ response = client.execute(httpGet);
+ logger.info("/engine/controllers/controllers/decoders/topic/filters/factType/rules/ruleName response code: {}",response.getStatusLine().getStatusCode());
+ assertEquals(404, response.getStatusLine().getStatusCode());
+ httpGet.releaseConnection();
+
+
+ }
+
+
+ public String getResponseBody(CloseableHttpResponse response) {
+
+ HttpEntity entity;
+ try {
+ entity = response.getEntity();
+ return EntityUtils.toString(entity);
+
+ } catch (IOException e) {
+
+ }
+
+ return null;
+ }
+
+}
diff --git a/policy-management/src/test/resources/logback-test.xml b/policy-management/src/test/resources/logback-test.xml
index 4a3b561f..b2ddf807 100644
--- a/policy-management/src/test/resources/logback-test.xml
+++ b/policy-management/src/test/resources/logback-test.xml
@@ -10,7 +10,7 @@
<logger name="org.onap.policy.drools.system.test" level="INFO"/>
- <root level="WARN">
+ <root level="INFO">
<appender-ref ref="STDOUT"/>
</root>