aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DbAudit.java54
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/DroolsPDPIntegrityMonitor.java281
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/RepositoryAudit.java2
-rw-r--r--feature-state-management/src/main/java/org/onap/policy/drools/statemanagement/StateManagementFeature.java46
-rw-r--r--feature-state-management/src/test/java/org/onap/policy/drools/statemanagement/test/StateManagementTest.java1
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java4
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java3
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java1
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java6
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java33
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java37
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java31
-rw-r--r--policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java22
-rw-r--r--pom.xml8
14 files changed, 321 insertions, 208 deletions
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 67991c7b..33f672c5 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
@@ -84,29 +84,11 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase
@Override
public void invoke(Properties properties)
{
- if(logger.isDebugEnabled()){
- logger.debug("Running 'DbAudit.invoke'");
- }
- if(isJunit){
- createTableNeeded = false;
- }
- boolean isActive = true;
- String dbAuditIsActive = StateManagementProperties.getProperty("db.audit.is.active");
- if(logger.isDebugEnabled()){
- logger.debug("DbAudit.invoke: dbAuditIsActive = {}", dbAuditIsActive);
- }
-
- if (dbAuditIsActive != null) {
- try {
- isActive = Boolean.parseBoolean(dbAuditIsActive.trim());
- } catch (NumberFormatException e) {
- logger.warn("DbAudit.invoke: Ignoring invalid property: db.audit.is.active = {}", dbAuditIsActive);
- }
- }
+ logger.debug("Running 'DbAudit.invoke'");
+ boolean doCreate = createTableNeeded && !isJunit;
- if(!isActive){
-
- logger.info("DbAudit.invoke: exiting because isActive = {}", isActive);
+ if(!isActive()){
+ logger.info("DbAudit.invoke: exiting because isActive = false");
return;
}
@@ -123,14 +105,12 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase
// create connection to DB
phase = "creating connection";
- if(logger.isDebugEnabled()){
- logger.debug("DbAudit: Creating connection to {}", url);
- }
+ logger.debug("DbAudit: Creating connection to {}", url);
try (Connection connection = DriverManager.getConnection(url, user, password))
{
// create audit table, if needed
- if (createTableNeeded)
+ if (doCreate)
{
phase = "create table";
createTable(connection);
@@ -156,14 +136,32 @@ public class DbAudit extends DroolsPDPIntegrityMonitor.AuditBase
}
/**
+ * Determines if the DbAudit is active, based on properties. Defaults to
+ * {@code true}, if not found in the properties.
+ * @return {@code true} if DbAudit is active, {@code false} otherwise
+ */
+ private boolean isActive() {
+ String dbAuditIsActive = StateManagementProperties.getProperty("db.audit.is.active");
+ logger.debug("DbAudit.invoke: dbAuditIsActive = {}", dbAuditIsActive);
+
+ if (dbAuditIsActive != null) {
+ try {
+ return Boolean.parseBoolean(dbAuditIsActive.trim());
+ } catch (NumberFormatException e) {
+ logger.warn("DbAudit.invoke: Ignoring invalid property: db.audit.is.active = {}", dbAuditIsActive);
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Creates the table.
* @param connection
* @throws SQLException
*/
private void createTable(Connection connection) throws SQLException {
- if(logger.isDebugEnabled()){
logger.info("DbAudit: Creating 'Audit' table, if needed");
- }
try (PreparedStatement statement = connection.prepareStatement
("CREATE TABLE IF NOT EXISTS Audit (\n"
+ " name varchar(64) DEFAULT NULL,\n"
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 0a4eb513..382f01e2 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,6 +20,7 @@
package org.onap.policy.drools.statemanagement;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;
import org.onap.policy.common.im.IntegrityMonitor;
@@ -67,10 +68,10 @@ public class DroolsPDPIntegrityMonitor extends IntegrityMonitor
super(resourceName, consolidatedProperties);
}
- private static void missingProperty(String prop) throws StateManagementPropertiesException{
+ private static void missingProperty(String prop) throws IntegrityMonitorException{
String msg = "init: missing IntegrityMonitor property: ".concat(prop);
logger.error(msg);
- throw new StateManagementPropertiesException(msg);
+ throw new IntegrityMonitorException(msg);
}
private static void logPropertyValue(String prop, String val){
@@ -83,156 +84,182 @@ public class DroolsPDPIntegrityMonitor extends IntegrityMonitor
/**
* Static initialization -- create Drools Integrity Monitor, and
* an HTTP server to handle REST 'test' requests
+ * @throws StateManagementPropertiesException
+ * @throws IntegrityMonitorException
*/
- public static DroolsPDPIntegrityMonitor init(String configDir) throws Exception
+ public static DroolsPDPIntegrityMonitor init(String configDir) throws IntegrityMonitorException
{
logger.info("init: Entering and invoking PropertyUtil.getProperties() on '{}'", configDir);
// read in properties
- Properties stateManagementProperties =
- PropertyUtil.getProperties(configDir + "/" + PROPERTIES_NAME);
- // fetch and verify definitions of some properties
+ Properties stateManagementProperties = getProperties(configDir);
+
+ // fetch and verify definitions of some properties, adding defaults where
+ // appropriate
// (the 'IntegrityMonitor' constructor does some additional verification)
+
+ checkPropError(stateManagementProperties, StateManagementProperties.TEST_HOST);
+ checkPropError(stateManagementProperties, StateManagementProperties.TEST_PORT);
+
+ addDefaultPropError(stateManagementProperties,
+ StateManagementProperties.TEST_SERVICES,
+ StateManagementProperties.TEST_SERVICES_DEFAULT);
+
+ addDefaultPropError(stateManagementProperties,
+ StateManagementProperties.TEST_REST_CLASSES,
+ StateManagementProperties.TEST_REST_CLASSES_DEFAULT);
+
+ addDefaultPropWarn(stateManagementProperties,
+ StateManagementProperties.TEST_MANAGED,
+ StateManagementProperties.TEST_MANAGED_DEFAULT);
+
+ addDefaultPropWarn(stateManagementProperties,
+ StateManagementProperties.TEST_SWAGGER,
+ StateManagementProperties.TEST_SWAGGER_DEFAULT);
+
+ checkPropError(stateManagementProperties, StateManagementProperties.RESOURCE_NAME);
+ checkPropError(stateManagementProperties, StateManagementProperties.FP_MONITOR_INTERVAL);
+ checkPropError(stateManagementProperties, StateManagementProperties.FAILED_COUNTER_THRESHOLD);
+ checkPropError(stateManagementProperties, StateManagementProperties.TEST_TRANS_INTERVAL);
+ checkPropError(stateManagementProperties, StateManagementProperties.WRITE_FPC_INTERVAL);
+ checkPropError(stateManagementProperties, StateManagementProperties.SITE_NAME);
+ checkPropError(stateManagementProperties, StateManagementProperties.NODE_TYPE);
+ checkPropError(stateManagementProperties, StateManagementProperties.DEPENDENCY_GROUPS);
+ checkPropError(stateManagementProperties, StateManagementProperties.DB_DRIVER);
+ checkPropError(stateManagementProperties, StateManagementProperties.DB_URL);
+ checkPropError(stateManagementProperties, StateManagementProperties.DB_USER);
+ checkPropError(stateManagementProperties, StateManagementProperties.DB_PWD);
+
String testHost = stateManagementProperties.getProperty(StateManagementProperties.TEST_HOST);
String testPort = stateManagementProperties.getProperty(StateManagementProperties.TEST_PORT);
- String testServices = stateManagementProperties.getProperty(StateManagementProperties.TEST_SERVICES);
- String testRestClasses = stateManagementProperties.getProperty(StateManagementProperties.TEST_REST_CLASSES);
- String testManaged = stateManagementProperties.getProperty(StateManagementProperties.TEST_MANAGED);
- String testSwagger = stateManagementProperties.getProperty(StateManagementProperties.TEST_SWAGGER);
String resourceName = stateManagementProperties.getProperty(StateManagementProperties.RESOURCE_NAME);
- String fpMonitorInterval = stateManagementProperties.getProperty(StateManagementProperties.FP_MONITOR_INTERVAL);
- String failedCounterThreshold = stateManagementProperties.getProperty(StateManagementProperties.FAILED_COUNTER_THRESHOLD);
- String testTransInterval = stateManagementProperties.getProperty(StateManagementProperties.TEST_TRANS_INTERVAL);
- String writeFpcInterval = stateManagementProperties.getProperty(StateManagementProperties.WRITE_FPC_INTERVAL);
- String siteName = stateManagementProperties.getProperty(StateManagementProperties.SITE_NAME);
- String nodeType = stateManagementProperties.getProperty(StateManagementProperties.NODE_TYPE);
- String dependencyGroups = stateManagementProperties.getProperty(StateManagementProperties.DEPENDENCY_GROUPS);
- String javaxPersistenceJdbcDriver = stateManagementProperties.getProperty(StateManagementProperties.DB_DRIVER);
- String javaxPersistenceJdbcUrl = stateManagementProperties.getProperty(StateManagementProperties.DB_URL);
- String javaxPersistenceJdbcUser = stateManagementProperties.getProperty(StateManagementProperties.DB_USER);
- String javaxPersistenceJdbcPassword = stateManagementProperties.getProperty(StateManagementProperties.DB_PWD);
-
- if (testHost == null){
- missingProperty(StateManagementProperties.TEST_HOST);
- }
- if (testPort == null){
- missingProperty(StateManagementProperties.TEST_PORT);
- }
- if (testServices == null) {
- testServices = StateManagementProperties.TEST_SERVICES_DEFAULT;
- stateManagementProperties.put(StateManagementProperties.TEST_SERVICES, testServices);
- }
- if (testRestClasses == null) {
- testRestClasses = StateManagementProperties.TEST_REST_CLASSES_DEFAULT;
- stateManagementProperties.put(StateManagementProperties.TEST_REST_CLASSES, testRestClasses);
- }
- if (testManaged == null) {
- testManaged = StateManagementProperties.TEST_MANAGED_DEFAULT;
- stateManagementProperties.put(StateManagementProperties.TEST_MANAGED, testManaged);
- }
- if (testSwagger == null) {
- testSwagger = StateManagementProperties.TEST_SWAGGER_DEFAULT;
- stateManagementProperties.put(StateManagementProperties.TEST_SWAGGER, testSwagger);
- }
- if (!testServices.equals(StateManagementProperties.TEST_SERVICES_DEFAULT)){
- logger.error(INVALID_PROPERTY_VALUE,
- StateManagementProperties.TEST_SERVICES,
- StateManagementProperties.TEST_SERVICES_DEFAULT);
- }
- if (!testRestClasses.equals(StateManagementProperties.TEST_REST_CLASSES_DEFAULT)){
- logger.error(INVALID_PROPERTY_VALUE,
- StateManagementProperties.TEST_REST_CLASSES,
- StateManagementProperties.TEST_REST_CLASSES_DEFAULT);
- }
- if (!testManaged.equals(StateManagementProperties.TEST_MANAGED_DEFAULT)){
- logger.warn(INVALID_PROPERTY_VALUE,
- StateManagementProperties.TEST_MANAGED,
- StateManagementProperties.TEST_MANAGED_DEFAULT);
- }
- if (!testSwagger.equals(StateManagementProperties.TEST_SWAGGER_DEFAULT)){
- logger.warn(INVALID_PROPERTY_VALUE,
- StateManagementProperties.TEST_SWAGGER,
- StateManagementProperties.TEST_SWAGGER_DEFAULT);
- }
- if (resourceName == null){
- missingProperty(StateManagementProperties.RESOURCE_NAME);
- }
- if (fpMonitorInterval == null){
- missingProperty(StateManagementProperties.FP_MONITOR_INTERVAL);
- }
- if (failedCounterThreshold == null){
- missingProperty(StateManagementProperties.FAILED_COUNTER_THRESHOLD);
- }
- if (testTransInterval == null){
- missingProperty(StateManagementProperties.TEST_TRANS_INTERVAL);
- }
- if (writeFpcInterval == null){
- missingProperty(StateManagementProperties.WRITE_FPC_INTERVAL);
- }
- if (siteName == null){
- missingProperty(StateManagementProperties.SITE_NAME);
- }
- if (nodeType == null){
- missingProperty(StateManagementProperties.NODE_TYPE);
- }
- if (dependencyGroups == null){
- missingProperty(StateManagementProperties.DEPENDENCY_GROUPS);
- }
- if (javaxPersistenceJdbcDriver == null){
- missingProperty(StateManagementProperties.DB_DRIVER);
- }
- if (javaxPersistenceJdbcUrl == null){
- missingProperty(StateManagementProperties.DB_URL);
- }
- if (javaxPersistenceJdbcUser == null){
- missingProperty(StateManagementProperties.DB_USER);
- }
- if (javaxPersistenceJdbcPassword == null){
- missingProperty(StateManagementProperties.DB_PWD);
- }
-
- //Log the values so we can diagnose any issues
- logPropertyValue(StateManagementProperties.TEST_HOST,testHost);
- logPropertyValue(StateManagementProperties.TEST_PORT,testPort);
- logPropertyValue(StateManagementProperties.TEST_SERVICES,testServices);
- logPropertyValue(StateManagementProperties.TEST_REST_CLASSES,testRestClasses);
- logPropertyValue(StateManagementProperties.TEST_MANAGED,testManaged);
- logPropertyValue(StateManagementProperties.TEST_SWAGGER,testSwagger);
- logPropertyValue(StateManagementProperties.RESOURCE_NAME,resourceName);
- logPropertyValue(StateManagementProperties.FP_MONITOR_INTERVAL,fpMonitorInterval);
- logPropertyValue(StateManagementProperties.FAILED_COUNTER_THRESHOLD,failedCounterThreshold);
- logPropertyValue(StateManagementProperties.TEST_TRANS_INTERVAL,testTransInterval);
- logPropertyValue(StateManagementProperties.WRITE_FPC_INTERVAL,writeFpcInterval);
- logPropertyValue(StateManagementProperties.SITE_NAME,siteName);
- logPropertyValue(StateManagementProperties.NODE_TYPE,nodeType);
- logPropertyValue(StateManagementProperties.DEPENDENCY_GROUPS,dependencyGroups);
- logPropertyValue(StateManagementProperties.DB_DRIVER,javaxPersistenceJdbcDriver);
- logPropertyValue(StateManagementProperties.DB_URL,javaxPersistenceJdbcUrl);
- logPropertyValue(StateManagementProperties.DB_USER,javaxPersistenceJdbcUser);
- logPropertyValue(StateManagementProperties.DB_PWD,javaxPersistenceJdbcPassword);
-
+
subsystemTestProperties = stateManagementProperties;
// Now that we've validated the properties, create Drools Integrity Monitor
// with these properties.
- im = new DroolsPDPIntegrityMonitor(resourceName,
- stateManagementProperties);
+ im = makeMonitor(resourceName, stateManagementProperties);
logger.info("init: New DroolsPDPIntegrityMonitor instantiated, resourceName = ", resourceName);
// create http server
+ makeRestServer(testHost, testPort, stateManagementProperties);
+ logger.info("init: Exiting and returning DroolsPDPIntegrityMonitor");
+
+ return im;
+ }
+
+ /**
+ * Makes an Integrity Monitor.
+ * @param resourceName unique name of this Integrity Monitor
+ * @param properties properties used to configure the Integrity Monitor
+ * @return
+ * @throws IntegrityMonitorException
+ */
+ private static DroolsPDPIntegrityMonitor makeMonitor(String resourceName, Properties properties)
+ throws IntegrityMonitorException {
+
+ try {
+ return new DroolsPDPIntegrityMonitor(resourceName, properties);
+
+ } catch (Exception e) {
+ throw new IntegrityMonitorException(e);
+ }
+ }
+
+ /**
+ * Makes a rest server for the Integrity Monitor.
+ * @param testHost host name
+ * @param testPort port
+ * @param properties properties used to configure the rest server
+ * @throws IntegrityMonitorException
+ */
+ private static void makeRestServer(String testHost, String testPort, Properties properties)
+ throws IntegrityMonitorException {
+
try {
logger.info("init: Starting HTTP server, addr= {}", testHost+":"+testPort);
+
IntegrityMonitorRestServer server = new IntegrityMonitorRestServer();
+ server.init(properties);
- server.init(stateManagementProperties);
} catch (Exception e) {
logger.error("init: Caught Exception attempting to start server on testPort= {} message:",
testPort, e);
- throw e;
+ throw new IntegrityMonitorException(e);
}
- logger.info("init: Exiting and returning DroolsPDPIntegrityMonitor");
- return im;
+ }
+
+ /**
+ * Gets the properties from the property file.
+ * @param configDir directory containing the property file
+ * @return the properties
+ * @throws IntegrityMonitorException
+ */
+ private static Properties getProperties(String configDir) throws IntegrityMonitorException {
+ try {
+ return PropertyUtil.getProperties(configDir + "/" + PROPERTIES_NAME);
+
+ } catch (IOException e) {
+ throw new IntegrityMonitorException(e);
+ }
+ }
+
+ /**
+ * Checks that a property is defined.
+ * @param props set of properties
+ * @param name name of the property to check
+ * @throws IntegrityMonitorException
+ */
+ private static void checkPropError(Properties props, String name) throws IntegrityMonitorException {
+ String val = props.getProperty(name);
+ if(val == null) {
+ missingProperty(name);
+ }
+
+ logPropertyValue(name, val);
+ }
+
+ /**
+ * Checks a property's value to verify that it matches the expected value.
+ * If the property is not defined, then it is added to the property set,
+ * with the expected value. Logs an error if the property is defined,
+ * but does not have the expected value.
+ * @param props set of properties
+ * @param name name of the property to check
+ * @param expected expected/default value
+ */
+ private static void addDefaultPropError(Properties props, String name, String expected) {
+ String val = props.getProperty(name);
+ if(val == null) {
+ props.setProperty(name, expected);
+
+ } else if( ! val.equals(expected)) {
+ logger.error(INVALID_PROPERTY_VALUE, name, expected);
+ }
+
+ logPropertyValue(name, val);
+ }
+
+ /**
+ * Checks a property's value to verify that it matches the expected value.
+ * If the property is not defined, then it is added to the property set,
+ * with the expected value. Logs a warning if the property is defined,
+ * but does not have the expected value.
+ * @param props set of properties
+ * @param name name of the property to check
+ * @param expected expected/default value
+ */
+ private static void addDefaultPropWarn(Properties props, String name, String dflt) {
+ String val = props.getProperty(name);
+ if(val == null) {
+ props.setProperty(name, dflt);
+
+ } else if( ! val.equals(dflt)) {
+ logger.warn(INVALID_PROPERTY_VALUE, name, dflt);
+ }
+
+ logPropertyValue(name, val);
}
/**
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 1e2a3a05..11134443 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
@@ -483,7 +483,6 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
{
- // logger.info("RepositoryAudit: Delete " + file);
file.toFile().delete();
return FileVisitResult.CONTINUE;
}
@@ -494,7 +493,6 @@ public class RepositoryAudit extends DroolsPDPIntegrityMonitor.AuditBase
{
if (e == null)
{
- // logger.info("RepositoryAudit: Delete " + file);
file.toFile().delete();
return FileVisitResult.CONTINUE;
}
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 a34d4f98..3cc27907 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
@@ -58,18 +58,14 @@ public class StateManagementFeature implements StateManagementFeatureAPI,
/**************************/
public StateManagementFeature(){
- if(logger.isDebugEnabled()){
- logger.debug("StateManagementFeature() constructor");
- }
+ logger.debug("StateManagementFeature() constructor");
}
@Override
public void globalInit(String[] args, String configDir)
{
// Initialization code associated with 'PolicyContainer'
- if(logger.isDebugEnabled()){
- logger.debug("StateManagementFeature.globalInit({}) entry", configDir);
- }
+ logger.debug("StateManagementFeature.globalInit({}) entry", configDir);
try
{
@@ -77,9 +73,7 @@ public class StateManagementFeature implements StateManagementFeatureAPI,
}
catch (Exception e)
{
- if(logger.isDebugEnabled()){
- logger.debug("DroolsPDPIntegrityMonitor initialization exception: ", e);
- }
+ logger.debug("DroolsPDPIntegrityMonitor initialization exception: ", e);
logger.error("DroolsPDPIntegrityMonitor.init()", e);
}
@@ -89,20 +83,16 @@ public class StateManagementFeature implements StateManagementFeatureAPI,
try {
droolsPdpIntegrityMonitor = DroolsPDPIntegrityMonitor.getInstance();
stateManagement = droolsPdpIntegrityMonitor.getStateManager();
- if(logger.isDebugEnabled()){
- logger.debug("StateManagementFeature.globalInit(): "
- + "stateManagement.getAdminState(): {}", stateManagement.getAdminState());
- }
+
+ logger.debug("StateManagementFeature.globalInit(): "
+ + "stateManagement.getAdminState(): {}", stateManagement.getAdminState());
+
if(stateManagement == null){
- if(logger.isDebugEnabled()){
- logger.debug("StateManagementFeature.globalInit(): stateManagement is NULL!");
- }
+ logger.debug("StateManagementFeature.globalInit(): stateManagement is NULL!");
}
} catch (Exception e1) {
- if(logger.isDebugEnabled()){
- logger.debug("StateManagementFeature.globalInit(): DroolsPDPIntegrityMonitor"
- + " initialization failed with exception:", e1);
- }
+ logger.debug("StateManagementFeature.globalInit(): DroolsPDPIntegrityMonitor"
+ + " initialization failed with exception:", e1);
logger.error("DroolsPDPIntegrityMonitor.init(): StateManagementFeature startup failed "
+ "to get DroolsPDPIntegrityMonitor instance:", e1);
}
@@ -113,15 +103,13 @@ public class StateManagementFeature implements StateManagementFeatureAPI,
*/
@Override
public void addObserver(Observer stateChangeObserver) {
- if(logger.isDebugEnabled()){
- logger.debug("StateManagementFeature.addObserver() entry\n"
- + "StateManagementFeature.addObserver(): "
- + "stateManagement.getAdminState(): {}", stateManagement.getAdminState());
- }
+ logger.debug("StateManagementFeature.addObserver() entry\n"
+ + "StateManagementFeature.addObserver(): "
+ + "stateManagement.getAdminState(): {}", stateManagement.getAdminState());
+
stateManagement.addObserver(stateChangeObserver);
- if(logger.isDebugEnabled()){
- logger.debug("StateManagementFeature.addObserver() exit");
- }
+
+ logger.debug("StateManagementFeature.addObserver() exit");
}
/**
@@ -267,7 +255,7 @@ public class StateManagementFeature implements StateManagementFeatureAPI,
@Override
public void allSeemsWell(String key, Boolean asw, String msg)
- throws IllegalArgumentException, AllSeemsWellException {
+ throws AllSeemsWellException {
droolsPdpIntegrityMonitor.allSeemsWell(key, asw, msg);
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 85e0ed85..b364ef83 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
@@ -185,6 +185,7 @@ public class StateManagementTest {
/**************Repository Audit Test**************/
logger.debug("\n\ntestStateManagementOperation: Repository Audit\n\n");
try{
+ StateManagementProperties.initProperties(fsmProperties);
RepositoryAudit repositoryAudit = (RepositoryAudit) RepositoryAudit.getInstance();
repositoryAudit.invoke(fsmProperties);
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java
index 257d2dae..681a2b20 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/LoggerUtil.java
@@ -32,6 +32,10 @@ public class LoggerUtil {
* Root logger
*/
public static final String ROOT_LOGGER = "ROOT";
+
+ private LoggerUtil() {
+ // Empty constructor
+ }
/**
* set the log level of a logger
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java
index bd5b8aac..6734226d 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java
@@ -39,6 +39,9 @@ public class NetworkUtil {
*/
public static final String IPv4_WILDCARD_ADDRESS = "0.0.0.0";
+ private NetworkUtil() {
+ // Empty constructor
+ }
/**
* try to connect to $host:$port $retries times while we are getting connection failures.
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java
index 75a3cd7d..7a6ca0a0 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/OrderedService.java
@@ -25,6 +25,7 @@ package org.onap.policy.drools.utils;
* of services (features) discovered via 'ServiceLoader'. See
* 'OrderedServiceImpl' for more details.
*/
+@FunctionalInterface
public interface OrderedService
{
/**
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
index 50135e84..bf59ec96 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
@@ -45,8 +45,7 @@ public class ReflectionUtil {
* @throws IllegalArgumentException if an invalid parameter has been passed in
*/
public static Class<?> fetchClass(ClassLoader classLoader,
- String className)
- throws IllegalArgumentException {
+ String className) {
if (classLoader == null)
throw new IllegalArgumentException("A class loader must be provided");
@@ -70,8 +69,7 @@ public class ReflectionUtil {
* @return true if exists
* @throws IllegalArgumentException if an invalid parameter has been passed in
*/
- public static boolean isClass(ClassLoader classLoader, String classname)
- throws IllegalArgumentException {
+ public static boolean isClass(ClassLoader classLoader, String classname) {
return fetchClass(classLoader, classname) != null;
}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java
new file mode 100644
index 00000000..d942a427
--- /dev/null
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/LoggerUtilTest.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-utils
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.utils;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class LoggerUtilTest {
+
+ @Test
+ public void test() {
+ assertNotNull(LoggerUtil.setLevel("foo", "warn"));
+ }
+
+}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java
new file mode 100644
index 00000000..c8b7735b
--- /dev/null
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/NetworkUtilTest.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-utils
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class NetworkUtilTest {
+
+ @Test
+ public void test() throws InterruptedException, IOException {
+ assertNotNull(NetworkUtil.IPv4_WILDCARD_ADDRESS);
+ assertFalse(NetworkUtil.isTcpPortOpen("localhost", 8080, 1, 5));
+ }
+
+}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java
index 1af831ad..5063447c 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/PairTripleTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.drools.utils;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
@@ -30,18 +31,20 @@ public class PairTripleTest {
public void pairTest() {
Pair<String, String> p = new Pair<String, String>("foo", "bar");
- assertEquals(p.first(),"foo");
- assertEquals(p.second(),"bar");
- assertEquals(p.getFirst(),"foo");
- assertEquals(p.getSecond(),"bar");
+ assertEquals("foo", p.first());
+ assertEquals("bar", p.second());
+ assertEquals("foo", p.getFirst());
+ assertEquals("bar", p.getSecond());
p.first("one");
p.second("two");
- assertEquals(p.first(),"one");
- assertEquals(p.second(),"two");
- assertEquals(p.getFirst(),"one");
- assertEquals(p.getSecond(),"two");
+ assertEquals("one", p.first());
+ assertEquals("two", p.second());
+ assertEquals("one", p.getFirst());
+ assertEquals("two", p.getSecond());
+
+ assertNotNull(p.toString());
}
@@ -49,17 +52,17 @@ public class PairTripleTest {
public void tripleTest() {
Triple<String, String, String> t = new Triple<String, String,String>("foo", "bar", "fiz");
- assertEquals(t.first(),"foo");
- assertEquals(t.second(),"bar");
- assertEquals(t.third(),"fiz");
+ assertEquals("foo", t.first());
+ assertEquals("bar", t.second());
+ assertEquals("fiz", t.third());
t.first("one");
t.second("two");
t.third("three");
- assertEquals(t.first(),"one");
- assertEquals(t.second(),"two");
- assertEquals(t.third(),"three");
+ assertEquals("one", t.first());
+ assertEquals("two", t.second());
+ assertEquals("three", t.third());
}
}
diff --git a/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java b/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java
index ab4bace5..0cb51060 100644
--- a/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java
+++ b/policy-utils/src/test/java/org/onap/policy/drools/utils/ReflectionUtilTest.java
@@ -21,6 +21,7 @@ package org.onap.policy.drools.utils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -58,5 +59,26 @@ public class ReflectionUtilTest {
fail();
}
}
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testException1() {
+ ReflectionUtil.fetchClass(null, "org.onap.policy.drools.utils.ReflectionUtil");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testException2() {
+ Class<?> class1;
+ try {
+ class1 = Class.forName("org.onap.policy.drools.utils.ReflectionUtil");
+ ClassLoader classLoader = class1.getClassLoader();
+ ReflectionUtil.fetchClass(classLoader, null);
+ } catch (ClassNotFoundException e) {
+ fail();
+ }
+ }
+ @Test
+ public void testException3() throws ClassNotFoundException {
+ assertNull(ReflectionUtil.fetchClass(ClassLoader.getSystemClassLoader(), "foo.bar"));
+ }
}
diff --git a/pom.xml b/pom.xml
index 44ae9b8b..1ea1f7a9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,7 +2,7 @@
============LICENSE_START=======================================================
ONAP Policy Engine - Drools PDP
================================================================================
- Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -43,9 +43,9 @@
<dmaap.version>1.0.0</dmaap.version>
<cambria.version>0.0.1</cambria.version>
<jersey.version>2.25.1</jersey.version>
- <jersey.swagger.version>1.5.16</jersey.swagger.version>
- <jackson.version>2.9.1</jackson.version>
- <http.client.version>4.5.2</http.client.version>
+ <jersey.swagger.version>1.5.18</jersey.swagger.version>
+ <jackson.version>2.9.4</jackson.version>
+ <http.client.version>4.5.5</http.client.version>
<http.core.version>4.4.4</http.core.version>
<logback.version>1.2.3</logback.version>
<junit.version>4.12</junit.version>