aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2017-09-19 07:34:04 -0400
committerPamela Dragosh <pdragosh@research.att.com>2017-09-19 07:35:25 -0400
commit38bd1bffbed6faa272bf435c9936e3a99287372e (patch)
tree911517d6606281d35ab94fa0d36c9f2c6c10ea16 /policy-management
parentde75812664012694f42d1decb9409955683dbbb9 (diff)
Adding JUnits for Configuration Classes
Also fixed some Sonar Major issues to help clean that up. Issue-ID: POLICY-109 Change-Id: Ic8a0b8d97f2be1cc1f8e8e4e8b319c6117b231a4 Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'policy-management')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java3
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java17
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java21
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.java250
4 files changed, 272 insertions, 19 deletions
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/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);
+
+ }
+
+}