aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/policy-yaml
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/policy-yaml')
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java4
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java4
-rw-r--r--controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java6
-rw-r--r--controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java7
-rw-r--r--controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java8
-rw-r--r--controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java210
6 files changed, 234 insertions, 5 deletions
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java
index a8edf7a81..19cca8c82 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoop.java
@@ -20,6 +20,7 @@
package org.onap.policy.controlloop.policy;
+import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
@@ -27,7 +28,8 @@ import org.onap.policy.aai.Pnf;
import org.onap.policy.sdc.Resource;
import org.onap.policy.sdc.Service;
-public class ControlLoop {
+public class ControlLoop implements Serializable {
+ private static final long serialVersionUID = 1L;
private static final String COMPILER_VERSION = "2.0.0";
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java
index 161fe1def..bbc7747e4 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/ControlLoopPolicy.java
@@ -20,9 +20,11 @@
package org.onap.policy.controlloop.policy;
+import java.io.Serializable;
import java.util.List;
-public class ControlLoopPolicy {
+public class ControlLoopPolicy implements Serializable {
+ private static final long serialVersionUID = 1L;
private ControlLoop controlLoop;
diff --git a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java
index 8585b674b..22c58c8ab 100644
--- a/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java
+++ b/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java
@@ -20,11 +20,13 @@
package org.onap.policy.controlloop.policy;
+import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
-public class Policy {
+public class Policy implements Serializable {
+ private static final long serialVersionUID = 1L;
private String id = UUID.randomUUID().toString();
private String name;
@@ -264,7 +266,7 @@ public class Policy {
}
public boolean isValid() {
- return id == null || name == null || actor == null || recipe == null || target == null;
+ return id != null && name != null && actor != null && recipe != null && target != null;
}
@Override
diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java
index fcfe1dcfe..a4d1baa75 100644
--- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java
+++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopPolicyTest.java
@@ -31,6 +31,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.junit.Test;
+import org.onap.policy.common.utils.io.Serializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
@@ -114,6 +115,12 @@ public class ControlLoopPolicyTest {
// Seems we cannot use assertEquals here. Need advice.
//
//assertEquals(newObject, obj);
+
+ // test serialization
+ ControlLoopPolicy policy = (ControlLoopPolicy) obj;
+ ControlLoopPolicy policy2 = Serializer.roundTrip(policy);
+ assertTrue(policy.equals(policy2));
+
} catch (FileNotFoundException e) {
fail(e.getLocalizedMessage());
} catch (IOException e) {
diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
index daab1a26b..0349552af 100644
--- a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
+++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/ControlLoopTest.java
@@ -23,12 +23,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.aai.Pnf;
+import org.onap.policy.common.utils.io.Serializer;
import org.onap.policy.sdc.Resource;
import org.onap.policy.sdc.ResourceType;
import org.onap.policy.sdc.Service;
@@ -82,7 +84,7 @@ public class ControlLoopTest {
}
@Test
- public void testEquals() {
+ public void testEquals() throws IOException {
final Pnf pnf = new Pnf();
pnf.setPnfName("pnf 1");
@@ -128,6 +130,10 @@ public class ControlLoopTest {
assertTrue(controlLoop1.equals(controlLoop2));
assertEquals(controlLoop1.hashCode(), controlLoop2.hashCode());
+
+ controlLoop2 = Serializer.roundTrip(controlLoop1);
+ assertTrue(controlLoop1.equals(controlLoop2));
+ assertEquals(controlLoop1.hashCode(), controlLoop2.hashCode());
}
@Test
diff --git a/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java
new file mode 100644
index 000000000..6e13b326b
--- /dev/null
+++ b/controlloop/common/policy-yaml/src/test/java/org/onap/policy/controlloop/policy/PolicyTest.java
@@ -0,0 +1,210 @@
+/*
+ * ============LICENSE_START=======================================================
+ * policy-yaml unit test
+ * ================================================================================
+ * 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.controlloop.policy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.utils.io.Serializer;
+
+public class PolicyTest {
+ private Policy policy;
+
+ @Before
+ public void setUp() {
+ policy = new Policy();
+ }
+
+ @Test
+ public void testHashCode() {
+ assertTrue(policy.hashCode() != 0);
+
+ policy.setActor("a");
+ int hc1 = policy.hashCode();
+
+ policy.setActor("b");
+ assertTrue(hc1 != policy.hashCode());
+ }
+
+ @Test
+ public void test() throws IOException {
+ OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
+ operationsAccumulateParams.setLimit(10);
+
+ Map<String, String> payload = new TreeMap<>();
+ payload.put("mykey", "myvalue");
+
+ Target target = new Target();
+ target.setResourceID("myresource");
+
+ policy.setActor("act");
+ policy.setDescription("desc");
+ policy.setFailure("fail");
+ policy.setFailure_exception("failex");
+ policy.setFailure_guard("failguard");
+ policy.setFailure_retries("failretry");
+ policy.setFailure_timeout("failtimeout");
+ policy.setId("myid");
+ policy.setName("myname");
+ policy.setOperationsAccumulateParams(operationsAccumulateParams);
+ policy.setPayload(payload);
+ policy.setRecipe("myrecipe");
+ policy.setRetry(20);
+ policy.setSuccess("succ");
+ policy.setTarget(target);
+ policy.setTimeout(30);
+
+ assertEquals("act", policy.getActor());
+ assertEquals("desc", policy.getDescription());
+ assertEquals("fail", policy.getFailure());
+ assertEquals("failex", policy.getFailure_exception());
+ assertEquals("failguard", policy.getFailure_guard());
+ assertEquals("failretry", policy.getFailure_retries());
+ assertEquals("failtimeout", policy.getFailure_timeout());
+ assertEquals("myid", policy.getId());
+ assertEquals("myname", policy.getName());
+ assertEquals(operationsAccumulateParams, policy.getOperationsAccumulateParams());
+ assertEquals(payload, policy.getPayload());
+ assertEquals("myrecipe", policy.getRecipe());
+ assertEquals(20, policy.getRetry().intValue());
+ assertEquals("succ", policy.getSuccess());
+ assertEquals(target, policy.getTarget());
+ assertEquals(30, policy.getTimeout().intValue());
+
+ assertTrue(policy.equals(policy));
+ assertTrue(policy.hashCode() != new Policy().hashCode());
+ assertFalse(policy.equals(new Policy()));
+
+ Policy policy2 = Serializer.roundTrip(policy);
+ assertTrue(policy.equals(policy2));
+ assertEquals(policy.hashCode(), policy2.hashCode());
+
+ policy2 = new Policy(policy);
+ assertTrue(policy.equals(policy2));
+ assertEquals(policy.hashCode(), policy2.hashCode());
+ }
+
+ @Test
+ public void testPolicyString() {
+ policy = new Policy("justId");
+ assertEquals("justId", policy.getId());
+ }
+
+ @Test
+ public void testPolicyStringStringStringMapOfStringStringTarget() {
+ Map<String, String> payload = new TreeMap<>();
+ payload.put("mykeyB", "myvalueB");
+
+ Target target = new Target();
+ target.setResourceID("myresourceB");
+
+ policy = new Policy("nameB", "actorB", "recipeB", payload, target);
+ assertEquals("nameB", policy.getName());
+ assertEquals("actorB", policy.getActor());
+ assertEquals("recipeB", policy.getRecipe());
+ assertEquals(payload, policy.getPayload());
+ assertEquals(target, policy.getTarget());
+
+ assertTrue(policy.hashCode() != new Policy().hashCode());
+ }
+
+ @Test
+ public void testPolicyStringStringStringMapOfStringStringTargetIntegerInteger() {
+ Map<String, String> payload = new TreeMap<>();
+ payload.put("mykeyC", "myvalueC");
+
+ Target target = new Target();
+ target.setResourceID("myresourceC");
+
+ policy = new Policy("nameC", "actorC", "recipeC", payload, target, 201, 202);
+ assertEquals("nameC", policy.getName());
+ assertEquals("actorC", policy.getActor());
+ assertEquals("recipeC", policy.getRecipe());
+ assertEquals(payload, policy.getPayload());
+ assertEquals(target, policy.getTarget());
+ assertEquals(201, policy.getRetry().intValue());
+ assertEquals(202, policy.getTimeout().intValue());
+
+ assertTrue(policy.hashCode() != new Policy().hashCode());
+ }
+
+ @Test
+ public void testPolicyStringStringStringStringMapOfStringStringTargetStringIntegerInteger() {
+ Map<String, String> payload = new TreeMap<>();
+ payload.put("mykeyD", "myvalueD");
+
+ Target target = new Target();
+ target.setResourceID("myresourceD");
+
+ policy = new Policy("idD", "nameD", "descD", "actorD", payload, target, "recipeD", 301, 302);
+ assertEquals("idD", policy.getId());
+ assertEquals("nameD", policy.getName());
+ assertEquals("descD", policy.getDescription());
+ assertEquals("actorD", policy.getActor());
+ assertEquals(payload, policy.getPayload());
+ assertEquals(target, policy.getTarget());
+ assertEquals("recipeD", policy.getRecipe());
+ assertEquals(301, policy.getRetry().intValue());
+ assertEquals(302, policy.getTimeout().intValue());
+
+ assertTrue(policy.hashCode() != new Policy().hashCode());
+ }
+
+ @Test
+ public void testIsValid() {
+ assertFalse(policy.isValid());
+
+ Target target = new Target();
+ target.setResourceID("myresourceV");
+
+ policy = new Policy("nameV", "actorV", "recipeV", null, target);
+ assertEquals(null, policy.getPayload());
+ assertTrue(policy.isValid());
+ }
+
+ @Test
+ public void testToString() {
+ assertNotNull(policy.toString());
+ }
+
+ @Test
+ public void testEqualsObject() {
+ assertTrue(policy.equals(policy));
+
+ policy.setId("idE");
+ assertFalse(policy.equals(new Policy()));
+
+ Policy policy2 = new Policy();
+ policy2.setId(policy.getId());
+ assertTrue(policy.equals(policy2));
+
+ policy2.setId("idX");
+ assertFalse(policy.equals(policy2));
+ }
+
+}