aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src
diff options
context:
space:
mode:
authorMagnusen, Drew (dm741q) <dm741q@att.com>2017-09-15 14:41:44 -0500
committerMagnusen, Drew (dm741q) <dm741q@att.com>2017-09-21 15:03:59 -0500
commitfa720dc93a52ed9cfaa957c9ff9ba3f140e3fd79 (patch)
tree42aafe7a96fc7d628f85120dec8fd1b0c8379c35 /policy-management/src
parent42ddcb6dde34fd19523a33b72607dec4ecca31fc (diff)
Added junit for policy-management
Junits were added to cover the FileSystemPersistence and RestManager classes Patch 2: Merged some test functionality from FileSystemPersistenceTest class into SystemPersistenceTest class. Deleted FileSystemPersistenceTest class. Issue-ID: POLICY-109 Change-Id: Ifd058b9988db30f6b5bc49ae54e5060c67f4ad5e Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
Diffstat (limited to 'policy-management/src')
-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/server/restful/test/RestManagerTest.java345
-rw-r--r--policy-management/src/test/resources/logback-test.xml2
3 files changed, 407 insertions, 2 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 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/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>