diff options
30 files changed, 1472 insertions, 138 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..30e60521 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +.DS_Store +.project +.settings +.classpath +.jupiter +.pydevproject +*.swp +*.log +*.out +.metadata/ +target/ +*/logs/ +*/sql/ +*/testingLogs/ +*/config/ diff --git a/feature-healthcheck/.gitignore b/feature-healthcheck/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/feature-healthcheck/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckFeatureTest.java b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckFeatureTest.java index a618f033..1c0b45fb 100644 --- a/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckFeatureTest.java +++ b/feature-healthcheck/src/test/java/org/onap/policy/drools/healthcheck/HealthCheckFeatureTest.java @@ -22,28 +22,20 @@ package org.onap.policy.drools.healthcheck; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.FileOutputStream; import java.io.FileWriter; -import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; import java.util.Properties; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import org.onap.policy.drools.healthcheck.HealthCheck.Report; import org.onap.policy.drools.healthcheck.HealthCheck.Reports; -import org.onap.policy.drools.http.client.HttpClient; -import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.drools.persistence.SystemPersistence; import org.onap.policy.drools.properties.PolicyProperties; import org.onap.policy.drools.system.PolicyEngine; diff --git a/feature-state-management/.gitignore b/feature-state-management/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/feature-state-management/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/feature-state-management/pom.xml b/feature-state-management/pom.xml index 5265cdbb..033d36d6 100644 --- a/feature-state-management/pom.xml +++ b/feature-state-management/pom.xml @@ -133,5 +133,10 @@ <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java index a86ac8ef..efecf887 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java @@ -44,6 +44,9 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase // invoked -- doing this avoids the need to create the table in advance. static private boolean createTableNeeded = true; + synchronized private static void setCreateTableNeeded(boolean b) { + DbAudit.createTableNeeded = b; + } /** * @return the single 'DbAudit' instance */ @@ -98,26 +101,17 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase String user = properties.getProperty(StateManagementProperties.DB_USER); String password = properties.getProperty(StateManagementProperties.DB_PWD); - // connection to DB - Connection connection = null; - - // supports SQL operations - PreparedStatement statement = null; - ResultSet rs = null; - // operation phase currently running -- used to construct an error // message, if needed String phase = null; - try + // create connection to DB + phase = "creating connection"; + if(logger.isDebugEnabled()){ + logger.debug("DbAudit: Creating connection to {}", url); + } + try (Connection connection = DriverManager.getConnection(url, user, password)) { - // create connection to DB - phase = "creating connection"; - if(logger.isDebugEnabled()){ - logger.debug("DbAudit: Creating connection to {}", url); - } - - connection = DriverManager.getConnection(url, user, password); // create audit table, if needed if (createTableNeeded) @@ -126,93 +120,68 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase if(logger.isDebugEnabled()){ logger.info("DbAudit: Creating 'Audit' table, if needed"); } - statement = connection.prepareStatement + try (PreparedStatement statement = connection.prepareStatement ("CREATE TABLE IF NOT EXISTS Audit (\n" + " name varchar(64) DEFAULT NULL,\n" + " UNIQUE KEY name (name)\n" - + ") DEFAULT CHARSET=latin1;"); - statement.execute(); - statement.close(); - createTableNeeded = false; + + ") DEFAULT CHARSET=latin1;")) { + statement.execute(); + DbAudit.setCreateTableNeeded(false); + } catch (Exception e) { + throw e; + } } // insert an entry into the table phase = "insert entry"; String key = UUID.randomUUID().toString(); - statement = connection.prepareStatement - ("INSERT INTO Audit (name) VALUES (?)"); - statement.setString(1, key); - statement.executeUpdate(); - statement.close(); - + try (PreparedStatement statement = connection.prepareStatement + ("INSERT INTO Audit (name) VALUES (?)")) { + statement.setString(1, key); + statement.executeUpdate(); + } catch (Exception e) { + throw e; + } + // fetch the entry from the table phase = "fetch entry"; - statement = connection.prepareStatement - ("SELECT name FROM Audit WHERE name = ?"); - statement.setString(1, key); - rs = statement.executeQuery(); - if (rs.first()) - { - // found entry - if(logger.isDebugEnabled()){ - logger.debug("DbAudit: Found key {}", rs.getString(1)); + try (PreparedStatement statement = connection.prepareStatement + ("SELECT name FROM Audit WHERE name = ?")) { + statement.setString(1, key); + try (ResultSet rs = statement.executeQuery()) { + if (rs.first()) + { + // found entry + if(logger.isDebugEnabled()){ + logger.debug("DbAudit: Found key {}", rs.getString(1)); + } + } + else + { + logger.error + ("DbAudit: can't find newly-created entry with key {}", key); + setResponse("Can't find newly-created entry"); + } + } catch (Exception e) { + throw e; } - } - else - { - logger.error - ("DbAudit: can't find newly-created entry with key {}", key); - setResponse("Can't find newly-created entry"); - } - statement.close(); - + } // delete entries from table phase = "delete entry"; - statement = connection.prepareStatement - ("DELETE FROM Audit WHERE name = ?"); - statement.setString(1, key); - statement.executeUpdate(); - statement.close(); - statement = null; - } + try (PreparedStatement statement = connection.prepareStatement + ("DELETE FROM Audit WHERE name = ?")) { + statement.setString(1, key); + statement.executeUpdate(); + } catch (Exception e) { + throw e; + } + } catch (Exception e) { String message = "DbAudit: Exception during audit, phase = " + phase; logger.error(message, e); setResponse(message); } - finally - { - if (rs != null) - { - try - { - rs.close(); - } - catch (Exception e) - { - } - } - if (statement != null) - { - try - { - statement.close(); - } - catch (Exception e) - { - } - } - if (connection != null) - { - try - { - connection.close(); - } - catch (Exception e) - { - } - } - } } + } diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java index 73f6f738..2dc2e262 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java @@ -20,20 +20,17 @@ package org.onap.policy.drools.statemanagement; -import java.io.File; -import java.io.FileInputStream; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Properties; import org.onap.policy.common.im.IntegrityMonitor; import org.onap.policy.common.im.IntegrityMonitorException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.onap.policy.drools.core.PolicyContainer; import org.onap.policy.drools.http.server.HttpServletServer; import org.onap.policy.drools.properties.Startable; import org.onap.policy.drools.utils.PropertyUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This class extends 'IntegrityMonitor' for use in the 'Drools PDP' @@ -351,10 +348,11 @@ public class DroolsPDPIntegrityMonitor extends IntegrityMonitor try { server.waitedStart(5); } catch (Exception e) { - e.printStackTrace(); + logger.error("Exception waiting for servers to start: ", e); } } } catch (Exception e) { + logger.error("Exception building servers", e); return false; } @@ -366,7 +364,7 @@ public class DroolsPDPIntegrityMonitor extends IntegrityMonitor try { server.stop(); } catch (Exception e) { - e.printStackTrace(); + logger.error("Exception during stop", e); } return true; diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java index f5024299..ed522fce 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/IntegrityMonitorRestManager.java @@ -77,8 +77,6 @@ public class IntegrityMonitorRestManager { im = DroolsPDPIntegrityMonitor.getInstance(); } catch (Exception e) { logger.error("IntegrityMonitorRestManager: test() interface caught an exception", e); - e.printStackTrace(); - body.append("\nException: " + e + "\n"); responseValue = 500; } diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java index 6171572a..84cb7e32 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java @@ -335,11 +335,17 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase // place output in 'fileContents' (replacing the Return characters // with Newline) byte[] outputData = new byte[(int)output.length()]; - FileInputStream fis = new FileInputStream(output); - fis.read(outputData); - String fileContents = new String(outputData).replace('\r','\n'); - fis.close(); - + String fileContents; + try (FileInputStream fis = new FileInputStream(output)) { + // + // Ideally this should be in a loop or even better use + // Java 8 nio functionality. + // + int bytesRead = fis.read(outputData); + logger.info("fileContents read {} bytes", bytesRead); + fileContents = new String(outputData).replace('\r','\n'); + } + // generate log messages from 'Downloading' and 'Downloaded' // messages within the 'mvn' output int index = 0; diff --git a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java index 6d47039e..0143c58b 100644 --- a/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java +++ b/feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java @@ -24,14 +24,13 @@ import java.io.IOException; import java.util.Observer; import java.util.Properties; -import org.onap.policy.drools.statemanagement.StateManagementFeatureAPI; import org.onap.policy.common.im.StandbyStatusException; import org.onap.policy.common.im.StateManagement; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.onap.policy.drools.core.PolicySessionFeatureAPI; import org.onap.policy.drools.features.PolicyEngineFeatureAPI; import org.onap.policy.drools.utils.PropertyUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * If this feature is supported, there is a single instance of it. @@ -100,14 +99,12 @@ public class StateManagementFeature implements StateManagementFeatureAPI, } } } catch (Exception e1) { - String msg = " \n"; if(logger.isDebugEnabled()){ logger.debug("StateManagementFeature.globalInit(): DroolsPDPIntegrityMonitor" + " initialization failed with exception:", e1); } logger.error("DroolsPDPIntegrityMonitor.init(): StateManagementFeature startup failed " + "to get DroolsPDPIntegrityMonitor instance:", e1); - e1.printStackTrace(); } } diff --git a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java index e458dcea..1cd61788 100644 --- a/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java +++ b/feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java @@ -35,14 +35,13 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.onap.policy.common.im.StateManagement; import org.onap.policy.drools.core.PolicySessionFeatureAPI; import org.onap.policy.drools.statemanagement.StateManagementFeatureAPI; import org.onap.policy.drools.statemanagement.StateManagementProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class StateManagementTest { diff --git a/policy-core/drools-artifact-1.1/pom.xml b/policy-core/drools-artifact-1.1/pom.xml new file mode 100644 index 00000000..24a6d37d --- /dev/null +++ b/policy-core/drools-artifact-1.1/pom.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + ONAP Policy Engine - Drools PDP + ================================================================================ + 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========================================================= + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <artifactId>drools-artifact1</artifactId> + <version>17.1.0-SNAPSHOT</version> + <description>supports Junit tests in policy-core</description> + + <parent> + <groupId>org.onap.policy.drools-pdp</groupId> + <artifactId>drools-pdp</artifactId> + <version>1.1.0-SNAPSHOT</version> + </parent> +</project> diff --git a/policy-core/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml b/policy-core/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 00000000..22319689 --- /dev/null +++ b/policy-core/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"> + <kbase name="rules"> + <ksession name="session1"/> + </kbase> +</kmodule> diff --git a/policy-core/drools-artifact-1.1/src/main/resources/rules.drl b/policy-core/drools-artifact-1.1/src/main/resources/rules.drl new file mode 100644 index 00000000..9dac208b --- /dev/null +++ b/policy-core/drools-artifact-1.1/src/main/resources/rules.drl @@ -0,0 +1,30 @@ +package org.onap.policy.drools.core.test; + +rule "Initialization" + when + then + { + System.out.println("Initialization rule running"); + } +end + +rule "Add elements of an int array" + when + $object : Object() + then + { + if ($object instanceof int[]) + { + int[] array = (int[])($object); + + System.out.println("Received array of length " + array.length); + int sum = 0; + for (int i = 1 ; i < array.length ; i += 1) + { + sum += array[i]; + } + array[0] = sum; + retract($object); + } + } +end diff --git a/policy-core/drools-artifact-1.2/pom.xml b/policy-core/drools-artifact-1.2/pom.xml new file mode 100644 index 00000000..6b39d7c4 --- /dev/null +++ b/policy-core/drools-artifact-1.2/pom.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START======================================================= + ONAP Policy Engine - Drools PDP + ================================================================================ + 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========================================================= + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <artifactId>drools-artifact1</artifactId> + <version>17.2.0-SNAPSHOT</version> + <description>supports Junit tests in policy-core</description> + + <parent> + <groupId>org.onap.policy.drools-pdp</groupId> + <artifactId>drools-pdp</artifactId> + <version>1.1.0-SNAPSHOT</version> + </parent> +</project> diff --git a/policy-core/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml b/policy-core/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 00000000..22319689 --- /dev/null +++ b/policy-core/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"> + <kbase name="rules"> + <ksession name="session1"/> + </kbase> +</kmodule> diff --git a/policy-core/drools-artifact-1.2/src/main/resources/rules.drl b/policy-core/drools-artifact-1.2/src/main/resources/rules.drl new file mode 100644 index 00000000..e69b6597 --- /dev/null +++ b/policy-core/drools-artifact-1.2/src/main/resources/rules.drl @@ -0,0 +1,29 @@ +package org.onap.policy.drools.core.test; + +rule "Initialization" + when + then + { + System.out.println("Initialization rule running"); + } +end + +rule "Multiply elements of an int array" + when + $object : Object() + then + { + if ($object instanceof int[]) + { + int[] array = (int[])($object); + + System.out.println("Received array of length " + array.length); + int product = 1; + for (int i = 1 ; i < array.length ; i += 1) + { + product *= array[i]; + } + array[0] = product; + } + } +end diff --git a/policy-core/pom.xml b/policy-core/pom.xml index 076a4bf2..53e6f4aa 100644 --- a/policy-core/pom.xml +++ b/policy-core/pom.xml @@ -30,6 +30,57 @@ <version>1.1.0-SNAPSHOT</version> </parent> + <build> + <plugins> + + <!-- + 'maven-invoker-plugin' is used to build and install two versions of a + Drools artifact, both of which are used in Junit tests. These Maven + projects are invisible to Sonar and SonarQube, so there are no + complaints about multiple projects with the same artifact, and they + don't show up in the list of files or code line counts. + --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <version>3.0.1</version> + <executions> + + <execution> + <id>drools-artifact-1.1</id> + <goals> + <goal>run</goal> + </goals> + <phase>test-compile</phase> + <configuration> + <pom>drools-artifact-1.1/pom.xml</pom> + <goals> + <goal>install</goal> + </goals> + <streamLogs>true</streamLogs> + </configuration> + </execution> + + <execution> + <id>drools-artifact-1.2</id> + <goals> + <goal>run</goal> + </goals> + <phase>test-compile</phase> + <configuration> + <pom>drools-artifact-1.2/pom.xml</pom> + <goals> + <goal>install</goal> + </goals> + <streamLogs>true</streamLogs> + </configuration> + </execution> + + </executions> + </plugin> + </plugins> + </build> + <dependencies> <dependency> <groupId>org.kie</groupId> @@ -61,5 +112,5 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> - </dependencies> + </dependencies> </project> diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java new file mode 100644 index 00000000..e83f026c --- /dev/null +++ b/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java @@ -0,0 +1,334 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * 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.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * These tests focus on the following classes: + * PolicyContainer + * PolicySession + * PolicySessionFeatureAPI + */ +public class DroolsContainerTest +{ + /** + * This test is centered around the creation of a 'PolicyContainer' + * and 'PolicySession', and the updating of that container to a new + * version. + */ + @Test + public void createAndUpdate() throws Exception + { + // make sure feature log starts out clean + TestPolicySessionFeatureAPI.getLog(); + + // run 'globalInit', and verify expected feature hook fired + PolicyContainer.globalInit(new String[0]); + assertEquals(buildArrayList("globalInit"), + TestPolicySessionFeatureAPI.getLog()); + + // initial conditions -- there should be no containers + assertEquals(0, PolicyContainer.getPolicyContainers().size()); + + // create the container, and start it + PolicyContainer container = + new PolicyContainer("org.onap.policy.drools-pdp", + "drools-artifact1", "17.1.0-SNAPSHOT"); + container.start(); + assertTrue(container.isAlive()); + + // verify expected feature hooks fired + assertEquals(buildArrayList("activatePolicySession", + "newPolicySession", + "selectThreadModel"), + TestPolicySessionFeatureAPI.getLog()); + + // this container should be on the list + { + Collection<PolicyContainer> containers = + PolicyContainer.getPolicyContainers(); + assertEquals(1, containers.size()); + assertTrue(containers.contains(container)); + } + + // verify initial container attributes + assertEquals("org.onap.policy.drools-pdp:drools-artifact1:17.1.0-SNAPSHOT", + container.getName()); + assertEquals("org.onap.policy.drools-pdp", container.getGroupId()); + assertEquals("drools-artifact1", container.getArtifactId()); + assertEquals("17.1.0-SNAPSHOT", container.getVersion()); + + try + { + // fetch the session, and verify that it exists + PolicySession session = container.getPolicySession("session1"); + assertTrue(session != null); + + // get all sessions, and verify that this one is the only one + { + Collection<PolicySession> sessions = container.getPolicySessions(); + assertEquals(1, sessions.size()); + assertTrue(sessions.contains(session)); + } + + // verify session attributes + assertEquals(container, session.getPolicyContainer()); + assertEquals("session1", session.getName()); + assertEquals("org.onap.policy.drools-pdp:drools-artifact1:17.1.0-SNAPSHOT:session1", + session.getFullName()); + + // insert a new fact + int[] a = new int[]{0, 3, 8, 2}; + session.getKieSession().insert(a); + + // the Drools rules should add 3 + 8 + 2, and store 13 in a[0] + assertTrue(waitForChange(a) == 13); + + // update the container to a new version -- + // the rules will then multiply values rather than add them + assertEquals("[]", + container.updateToVersion("17.2.0-SNAPSHOT").toString()); + + // verify expected feature hooks fired + assertEquals(buildArrayList("selectThreadModel"), + TestPolicySessionFeatureAPI.getLog()); + + // verify new container attributes + assertEquals + ("org.onap.policy.drools-pdp:drools-artifact1:17.2.0-SNAPSHOT", + container.getName()); + assertEquals("org.onap.policy.drools-pdp", container.getGroupId()); + assertEquals("drools-artifact1", container.getArtifactId()); + assertEquals("17.2.0-SNAPSHOT", container.getVersion()); + + // verify new session attributes + assertEquals(container, session.getPolicyContainer()); + assertEquals("session1", session.getName()); + assertEquals("org.onap.policy.drools-pdp:drools-artifact1:17.2.0-SNAPSHOT:session1", + session.getFullName()); + + // the updated rules should now multiply 3 * 8 * 2, and return 48 + + a[0] = 0; + container.insert("session1", a); + assertTrue(waitForChange(a) == 48); + } + finally + { + container.shutdown(); + assertFalse(container.isAlive()); + + // verify expected feature hooks fired + assertEquals(buildArrayList("disposeKieSession"), + TestPolicySessionFeatureAPI.getLog()); + } + + // final conditions -- there should be no containers + assertEquals(0, PolicyContainer.getPolicyContainers().size()); + } + + /** + * This test create a 'PolicyContainer' and 'PolicySession', and verifies + * their behavior, but uses alternate interfaces to increase code coverage. + * In addition, feature hook invocations will trigger exceptions in this + * test, also to increase code coverage. + */ + @Test + public void versionList() throws Exception + { + // make sure feature log starts out clean + TestPolicySessionFeatureAPI.getLog(); + + // trigger exceptions in all feature hooks + TestPolicySessionFeatureAPI.setExceptionTrigger(true); + + // run 'globalInit', and verify expected feature hook fired + PolicyContainer.globalInit(new String[0]); + assertEquals(buildArrayList("globalInit-exception"), + TestPolicySessionFeatureAPI.getLog()); + + // initial conditions -- there should be no containers + assertEquals(0, PolicyContainer.getPolicyContainers().size()); + + String versionList = + "17.3.0-SNAPSHOT,17.1.0-SNAPSHOT,17.2.0-SNAPSHOT"; + + // versions should be tried in order -- the 17.1.0-SNAPSHOT should "win", + // given the fact that '17.3.0-SNAPSHOT' doesn't exist + PolicyContainer container = + new PolicyContainer("org.onap.policy.drools-pdp", + "drools-artifact1", versionList); + // the following should be equivalent to 'container.start()' + PolicyContainer.activate(); + assertTrue(container.isAlive()); + + // verify expected feature hooks fired + assertEquals(buildArrayList("activatePolicySession-exception", + "newPolicySession-exception", + "selectThreadModel-exception"), + TestPolicySessionFeatureAPI.getLog()); + + // this container should be on the list + { + Collection<PolicyContainer> containers = + PolicyContainer.getPolicyContainers(); + assertEquals(1, containers.size()); + assertTrue(containers.contains(container)); + } + + // verify initial container attributes + assertEquals("org.onap.policy.drools-pdp:drools-artifact1:17.1.0-SNAPSHOT", + container.getName()); + assertEquals("org.onap.policy.drools-pdp", container.getGroupId()); + assertEquals("drools-artifact1", container.getArtifactId()); + assertEquals("17.1.0-SNAPSHOT", container.getVersion()); + + // some container adjunct tests + { + Object bogusAdjunct = new Object(); + + // initially, no adjunct + assertSame(null, container.getAdjunct(this)); + + // set and verify adjunct + container.setAdjunct(this, bogusAdjunct); + assertSame(bogusAdjunct, container.getAdjunct(this)); + + // clear and verify adjunct + container.setAdjunct(this, null); + assertSame(null, container.getAdjunct(this)); + } + + try + { + // fetch the session, and verify that it exists + PolicySession session = container.getPolicySession("session1"); + assertTrue(session != null); + + // get all sessions, and verify that this one is the only one + { + Collection<PolicySession> sessions = container.getPolicySessions(); + assertEquals(1, sessions.size()); + assertTrue(sessions.contains(session)); + } + + // verify session attributes + assertEquals(container, session.getPolicyContainer()); + assertEquals("session1", session.getName()); + assertEquals("org.onap.policy.drools-pdp:drools-artifact1:17.1.0-SNAPSHOT:session1", + session.getFullName()); + + // some session adjunct tests + { + Object bogusAdjunct = new Object(); + + // initially, no adjunct + assertSame(null, session.getAdjunct(this)); + + // set and verify adjunct + session.setAdjunct(this, bogusAdjunct); + assertSame(bogusAdjunct, session.getAdjunct(this)); + + // clear and verify adjunct + session.setAdjunct(this, null); + assertSame(null, session.getAdjunct(this)); + } + + // insert a new fact (using 'insertAll') + int[] a = new int[]{0, 7, 3, 4}; + container.insertAll(a); + + // the Drools rules should add 7 + 3 + 4, and store 14 in a[0] + assertTrue(waitForChange(a) == 14); + + // exercise some more API methods + assertEquals(container.getClassLoader(), + container.getKieContainer().getClassLoader()); + } + finally + { + // should be equivalent to 'shutdown' without persistence + container.destroy(); + assertFalse(container.isAlive()); + + // verify expected feature hooks fired + assertEquals(buildArrayList("destroyKieSession-exception"), + TestPolicySessionFeatureAPI.getLog()); + + // clear exception trigger + TestPolicySessionFeatureAPI.setExceptionTrigger(false); + } + + // final conditions -- there should be no containers + assertEquals(0, PolicyContainer.getPolicyContainers().size()); + } + + /** + * This method is tied to the expected behavior of the drools sessions. + * Initially, the value of 'array[0]' should be 0. The Drools rules + * will either add or multiply 'array[1]' through 'array[n-1]', depending + * upon the version. It waits up to 30 seconds for a non-zero value + * to appear. + */ + private int waitForChange(int[] array) throws InterruptedException + { + int rval = -1; + + // the value is tested every 1/100 of a second, and it waits up to + // 3000 iterations (= 30 seconds) for a non-zero value + for (int i = 0 ; i < 3000 ; i += 1) + { + // wait for 10 milliseconds = 1/100 of a second + Thread.sleep(10); + if ((rval = array[0]) != 0) + { + // a non-zero value has been stored + break; + } + } + return(rval); + } + + /** + * @param args an array of string arguments + * @return an ArrayList constructed from the provided arguments + */ + private ArrayList<String> buildArrayList(String... args) + { + ArrayList<String> rval = new ArrayList<>(); + for (String arg : args) + { + rval.add(arg); + } + return(rval); + } +} diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/TestPolicySessionFeatureAPI.java b/policy-core/src/test/java/org/onap/policy/drools/core/TestPolicySessionFeatureAPI.java new file mode 100644 index 00000000..f456d814 --- /dev/null +++ b/policy-core/src/test/java/org/onap/policy/drools/core/TestPolicySessionFeatureAPI.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * policy-core + * ================================================================================ + * 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.core; + +import java.util.ArrayList; +import org.kie.api.runtime.KieSession; + +/** + * This class supports 'DroolsContainerTest' by implementing + * 'PolicySessionFeatureAPI', and providing a means to indicate + * which hooks have been invoked. + */ +public class TestPolicySessionFeatureAPI implements PolicySessionFeatureAPI +{ + // contains the log entries since the most recent 'getLog()' call + static private ArrayList<String> log = new ArrayList<>(); + + // if 'true', trigger an exception right after doing the log, + // to verify that exceptions are handled + static private boolean exceptionTrigger = false; + + /** + * @return the current contents of the log, and clear the log + */ + static public ArrayList<String> getLog() + { + synchronized(log) + { + ArrayList<String> rval = new ArrayList<>(log); + log.clear(); + return(rval); + } + } + + /** + * This method controls whether these hooks trigger an exception after + * being invoked. + * + * @param indicator if 'true', subsequent hook method calls will trigger + * an exception; if 'false', no exception is triggered + */ + static public void setExceptionTrigger(boolean indicator) + { + exceptionTrigger = indicator; + } + + /** + * This method adds an entry to the log, and possibly triggers an exception + * + * @param arg value to add to the log + */ + static private void addLog(String arg) + { + if (exceptionTrigger) + { + // the log entry will include a '-exception' appended to the end + synchronized(log) + { + log.add(arg + "-exception"); + } + System.out.println("*** " + arg + "-exception invoked ***"); + + // throw an exception -- it is up to the invoking code to catch it + throw(new IllegalStateException("Triggered from " + arg)); + } + else + { + // create a log entry, and display to standard output + synchronized(log) + { + log.add(arg); + } + System.out.println("*** " + arg + " invoked ***"); + } + } + + /***************************************/ + /* 'PolicySessionFeatureAPI' interface */ + /***************************************/ + + /** + * {@inheritDoc} + */ + public int getSequenceNumber() + { + return(1); + } + + /** + * {@inheritDoc} + */ + public void globalInit(String args[], String configDir) + { + addLog("globalInit"); + } + + /** + * {@inheritDoc} + */ + public KieSession activatePolicySession + (PolicyContainer policyContainer, String name, String kieBaseName) + { + addLog("activatePolicySession"); + return(null); + } + + /** + * {@inheritDoc} + */ + public void newPolicySession(PolicySession policySession) + { + addLog("newPolicySession"); + } + + /** + * {@inheritDoc} + */ + public PolicySession.ThreadModel selectThreadModel(PolicySession session) + { + addLog("selectThreadModel"); + return(null); + } + + /** + * {@inheritDoc} + */ + public void disposeKieSession(PolicySession policySession) + { + addLog("disposeKieSession"); + } + + /** + * {@inheritDoc} + */ + public void destroyKieSession(PolicySession policySession) + { + addLog("destroyKieSession"); + } +} diff --git a/policy-core/src/test/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureAPI b/policy-core/src/test/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureAPI new file mode 100644 index 00000000..d6b088c3 --- /dev/null +++ b/policy-core/src/test/resources/META-INF/services/org.onap.policy.drools.core.PolicySessionFeatureAPI @@ -0,0 +1 @@ +org.onap.policy.drools.core.TestPolicySessionFeatureAPI 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/configuration/ControllerConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java index ded7a52c..b0b8b504 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java @@ -67,7 +67,7 @@ public class ControllerConfiguration { @JsonProperty("drools") private DroolsConfiguration drools; @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + private Map<String, Object> additionalProperties = new HashMap<>(); protected final static Object NOT_FOUND_VALUE = new Object(); /** @@ -75,6 +75,7 @@ public class ControllerConfiguration { * */ public ControllerConfiguration() { + // Empty } /** diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java index 5f32d7a4..4c672e7b 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java @@ -63,7 +63,7 @@ public class DroolsConfiguration { @JsonProperty("version") private String version; @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + private Map<String, Object> additionalProperties = new HashMap<>(); protected final static Object NOT_FOUND_VALUE = new Object(); /** @@ -71,6 +71,7 @@ public class DroolsConfiguration { * */ public DroolsConfiguration() { + // Empty } /** @@ -196,21 +197,21 @@ public class DroolsConfiguration { switch (name) { case "artifactId": if (value instanceof String) { - setArtifactId(((String) value)); + setArtifactId((String) value); } else { throw new IllegalArgumentException(("property \"artifactId\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); } return true; case "groupId": if (value instanceof String) { - setGroupId(((String) value)); + setGroupId((String) value); } else { throw new IllegalArgumentException(("property \"groupId\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); } return true; case "version": if (value instanceof String) { - setVersion(((String) value)); + setVersion((String) value); } else { throw new IllegalArgumentException(("property \"version\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); } @@ -239,21 +240,21 @@ public class DroolsConfiguration { public<T >T get(String name) { Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE); if (DroolsConfiguration.NOT_FOUND_VALUE!= value) { - return ((T) value); + return (T) value; } else { - return ((T) getAdditionalProperties().get(name)); + return (T) getAdditionalProperties().get(name); } } public void set(String name, Object value) { if (!declaredProperty(name, value)) { - getAdditionalProperties().put(name, ((Object) value)); + getAdditionalProperties().put(name, value); } } public DroolsConfiguration with(String name, Object value) { if (!declaredProperty(name, value)) { - getAdditionalProperties().put(name, ((Object) value)); + getAdditionalProperties().put(name, value); } return this; } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java index d7295fd4..8d6f9bfd 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java @@ -67,9 +67,9 @@ public class PdpdConfiguration { * */ @JsonProperty("controllers") - private List<ControllerConfiguration> controllers = new ArrayList<ControllerConfiguration>(); + private List<ControllerConfiguration> controllers = new ArrayList<>(); @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + private Map<String, Object> additionalProperties = new HashMap<>(); protected final static Object NOT_FOUND_VALUE = new Object(); /** @@ -77,6 +77,7 @@ public class PdpdConfiguration { * */ public PdpdConfiguration() { + // Empty } /** @@ -201,21 +202,21 @@ public class PdpdConfiguration { switch (name) { case "requestID": if (value instanceof String) { - setRequestID(((String) value)); + setRequestID((String) value); } else { throw new IllegalArgumentException(("property \"requestID\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); } return true; case "entity": if (value instanceof String) { - setEntity(((String) value)); + setEntity((String) value); } else { throw new IllegalArgumentException(("property \"entity\" is of type \"java.lang.String\", but got "+ value.getClass().toString())); } return true; case "controllers": if (value instanceof List) { - setControllers(((List<ControllerConfiguration> ) value)); + setControllers((List<ControllerConfiguration> ) value); } else { throw new IllegalArgumentException(("property \"controllers\" is of type \"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", but got "+ value.getClass().toString())); } @@ -244,21 +245,21 @@ public class PdpdConfiguration { public<T >T get(String name) { Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE); if (PdpdConfiguration.NOT_FOUND_VALUE!= value) { - return ((T) value); + return (T) value; } else { - return ((T) getAdditionalProperties().get(name)); + return (T) getAdditionalProperties().get(name); } } public void set(String name, Object value) { if (!declaredProperty(name, value)) { - getAdditionalProperties().put(name, ((Object) value)); + getAdditionalProperties().put(name, value); } } public PdpdConfiguration with(String name, Object value) { if (!declaredProperty(name, value)) { - getAdditionalProperties().put(name, ((Object) value)); + getAdditionalProperties().put(name, value); } return this; } @@ -276,7 +277,7 @@ public class PdpdConfiguration { if ((other instanceof PdpdConfiguration) == false) { return false; } - PdpdConfiguration rhs = ((PdpdConfiguration) other); + PdpdConfiguration rhs = (PdpdConfiguration) other; return new EqualsBuilder().append(requestID, rhs.requestID).append(entity, rhs.entity).append(controllers, rhs.controllers).append(additionalProperties, rhs.additionalProperties).isEquals(); } 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/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/PdpdConfigurationTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.java new file mode 100644 index 00000000..84c85b8a --- /dev/null +++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.java @@ -0,0 +1,250 @@ +/*- + * ============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.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PdpdConfigurationTest { + + private static final Logger logger = LoggerFactory.getLogger(PdpdConfigurationTest.class); + + private static final String REQUEST_ID = UUID.randomUUID().toString(); + private static final String REQUEST_ID2 = UUID.randomUUID().toString(); + + private static final String ENTITY = "entity1"; + private static final String ENTITY2 = "entity2"; + + private static final String PROPERTY1 = "property1"; + private static final String PROPERTY2 = "property2"; + + private static final String VALUE1 = "value1"; + private static final String VALUE2 = "value2"; + + 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 NAME = "name"; + private static final String OPERATION = "operation"; + + private static final String NAME2 = "name2"; + private static final String OPERATION2 = "operation2"; + + @Test + public void test() { + // + // Empty constructor test + // + DroolsConfiguration drools = new DroolsConfiguration(); + drools.set("artifactId", ARTIFACT); + drools.set("groupId", GROUPID); + drools.set("version", VERSION); + drools.set(PROPERTY1, VALUE1); + + assertTrue(drools.equals(drools)); + assertFalse(drools.equals(new Object())); + + logger.info("Drools HashCode {}", drools.hashCode()); + + // + // Constructor with values test get calls + // + DroolsConfiguration drools2 = new DroolsConfiguration( + drools.get("artifactId"), + drools.get("groupId"), + drools.get("version")); + + // + // get Property + // + + drools2.set(PROPERTY1, drools.get(PROPERTY1)); + + assertTrue(drools.equals(drools2)); + + // + // with methods + // + drools2.withArtifactId(ARTIFACT2).withGroupId(GROUPID2).withVersion(VERSION2).withAdditionalProperty(PROPERTY2, VALUE2); + + assertFalse(drools.equals(drools2)); + + // + // Test get additional properties + // + assertEquals(drools.getAdditionalProperties().size(), 1); + + // + // Test Not found + // + assertEquals(drools.declaredPropertyOrNotFound(PROPERTY2, DroolsConfiguration.NOT_FOUND_VALUE), DroolsConfiguration.NOT_FOUND_VALUE); + + logger.info("drools {}", drools); + logger.info("drools2 {}", drools2); + + // + // Test Controller Default Constructor + // + ControllerConfiguration controller = new ControllerConfiguration(); + + // + // Test set + // + + controller.set("name", NAME); + controller.set("operation", OPERATION); + controller.set("drools", drools); + controller.set(PROPERTY1, VALUE1); + + assertTrue(controller.equals(controller)); + assertFalse(controller.equals(new Object())); + + logger.info("Controller HashCode {}", controller.hashCode()); + + // + // Controller Constructor gets + // + ControllerConfiguration controller2 = new ControllerConfiguration( + controller.get("name"), + controller.get("operation"), + controller.get("drools")); + + // + // Test get property + // + + controller2.set(PROPERTY1, controller.get(PROPERTY1)); + + assertTrue(controller.equals(controller2)); + + // + // test with methods + // + + controller2.withDrools(drools2).withName(NAME2).withOperation(OPERATION2).withAdditionalProperty(PROPERTY2, VALUE2); + + assertFalse(controller.equals(controller2)); + + // + // Test additional properties + // + assertEquals(controller.getAdditionalProperties().size(), 1); + + // + // Not found + // + assertEquals(controller.declaredPropertyOrNotFound(PROPERTY2, ControllerConfiguration.NOT_FOUND_VALUE), ControllerConfiguration.NOT_FOUND_VALUE); + + // + // toString + // + logger.info("Controller {}", controller); + logger.info("Controller2 {}", controller2); + + // + // PDP Configuration empty constructor + // + PdpdConfiguration config = new PdpdConfiguration(); + + // + // Test set + // + + config.set("requestID", REQUEST_ID); + config.set("entity", ENTITY); + List<ControllerConfiguration> controllers = new ArrayList<>(); + controllers.add(controller); + config.set("controllers", controllers); + config.set(PROPERTY1, VALUE1); + + assertTrue(config.equals(config)); + assertFalse(config.equals(new Object())); + + logger.info("Config HashCode {}", config.hashCode()); + + // + // Test constructor with values + // + + PdpdConfiguration config2 = new PdpdConfiguration( + config.get("requestID"), + config.get("entity"), + config.get("controllers")); + + // + // Test set + // + + config2.set(PROPERTY1, config.get(PROPERTY1)); + + assertTrue(config.equals(config2)); + + // + // Test with methods + // + List<ControllerConfiguration> controllers2 = new ArrayList<>(); + controllers2.add(controller2); + config2.withRequestID(REQUEST_ID2).withEntity(ENTITY2).withController(controllers2); + + assertFalse(config.equals(config2)); + + // + // Test additional properties + // + + assertEquals(config.getAdditionalProperties().size(), 1); + + // + // Test NOT FOUND + // + assertEquals(config.declaredPropertyOrNotFound(PROPERTY2, ControllerConfiguration.NOT_FOUND_VALUE), ControllerConfiguration.NOT_FOUND_VALUE); + + // + // toString + // + logger.info("Config {}", config); + logger.info("Config2 {}", config2); + + } + + @Test + public void testConstructor() { + + PdpdConfiguration config = new PdpdConfiguration(REQUEST_ID, ENTITY, null); + assertEquals(config.getRequestID(), REQUEST_ID); + assertEquals(config.getEntity(), ENTITY); + + } + +} 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> |