aboutsummaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/test/java/org
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2020-03-22 19:37:21 -0500
committerjhh <jorge.hernandez-herrero@att.com>2020-03-22 22:29:07 -0500
commit97e19c931535a5b474d4942a9982f0b7a1cf7414 (patch)
treeea2f83efb976bf7bda159097dbff50c0b99e451a /feature-lifecycle/src/test/java/org
parentcc69c5a3f56a3e90c17c4fdcf38dc93c37cf93f2 (diff)
Fix op policies distribution to controllers
Fix a bug when distributing a policy to the right controller plus additional junits to catch similar issues. Issue-ID: POLICY-2356 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I25fefa64ad54c55e6516ae18c6895b6de9407419 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src/test/java/org')
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java6
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java252
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java24
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java15
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java3
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactControllerTest.java2
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java6
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java79
8 files changed, 363 insertions, 24 deletions
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java
index c6cf15c6..9b673dd5 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java
@@ -44,7 +44,8 @@ public class ControllerSupport {
protected static final String JUNIT_KJAR_DRL_PATH =
"src/main/resources/kbLifecycle/org/onap/policy/drools/test/";
- protected static final String POLICY_TYPE = "onap.policies.controlloop.Operational";
+ protected static final String POLICY_TYPE_LEGACY_OP = "onap.policies.controlloop.Operational";
+ protected static final String POLICY_TYPE_COMPLIANT_OP = "onap.policies.controlloop.operational.common.Drools";
protected static final String POLICY_TYPE_VERSION = "1.0.0";
protected static final String SESSION_NAME = "junits";
@@ -103,7 +104,8 @@ public class ControllerSupport {
* Get Policy Type.
*/
public static String getPolicyType() {
- return POLICY_TYPE + ":" + POLICY_TYPE_VERSION;
+ return POLICY_TYPE_LEGACY_OP + ":" + POLICY_TYPE_VERSION + ","
+ + POLICY_TYPE_COMPLIANT_OP + ":" + POLICY_TYPE_VERSION;
}
/**
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
new file mode 100644
index 00000000..0e5937ff
--- /dev/null
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
@@ -0,0 +1,252 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * =============LICENSE_END========================================================
+ */
+
+package org.onap.policy.drools.lifecycle;
+
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.models.pdp.concepts.PdpStateChange;
+import org.onap.policy.models.pdp.concepts.PdpUpdate;
+import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+
+/**
+ * Lifecycle State Active Test.
+ */
+public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest {
+
+ private static final String EXAMPLE_NATIVE_DROOLS_CONTROLLER_POLICY_NAME = "example.controller";
+ private static final String EXAMPLE_NATIVE_DROOLS_ARTIFACT_POLICY_NAME = "example.artifact";
+ private static final String FOO_NATIVE_DROOLS_CONTROLLER_POLICY_NAME = "foo.controller";
+
+ private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON =
+ "src/test/resources/tosca-policy-native-controller-example.json";
+ private static final String EXAMPLE_NATIVE_ARTIFACT_POLICY_JSON =
+ "src/test/resources/tosca-policy-native-artifact-example.json";
+ private static final String FOO_NATIVE_DROOLS_POLICY_JSON =
+ "src/test/resources/tosca-policy-native-controller-foo.json";
+
+ /**
+ * Start tests in the Active state.
+ */
+ @Before
+ public void startActive() throws CoderException {
+ fsm = makeFsmWithPseudoTime();
+
+ fsm.setStatusTimerSeconds(15);
+ assertTrue(fsm.start());
+
+ PdpStateChange change = new PdpStateChange();
+ change.setPdpGroup("A");
+ change.setPdpSubgroup("a");
+ change.setState(PdpState.ACTIVE);
+ change.setName(fsm.getName());
+
+ fsm.setSubGroupAction("a");
+ fsm.source.offer(new StandardCoder().encode(change));
+ controllerSupport.getController().start();
+ }
+
+ @Test
+ public void testUpdatePolicies() throws IOException, CoderException {
+ assertEquals(2, fsm.policyTypesMap.size());
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.native.drools.Controller", "1.0.0")));
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.native.drools.Artifact", "1.0.0")));
+
+ //
+ // create controller using native policy
+ //
+
+ ToscaPolicy policyNativeController =
+ getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_CONTROLLER_POLICY_NAME);
+
+ PdpUpdate update = new PdpUpdate();
+ update.setName(NetworkUtil.getHostname());
+ update.setPdpGroup("W");
+ update.setPdpSubgroup("w");
+ update.setPolicies(List.of(policyNativeController));
+
+ assertFalse(fsm.update(update));
+ assertEquals(0, fsm.getPoliciesMap().size());
+
+ // add topics
+
+ Properties noopTopicProperties = new Properties();
+ noopTopicProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS, "DCAE_TOPIC");
+ noopTopicProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-CL");
+ TopicEndpointManager.getManager().addTopics(noopTopicProperties);
+
+ assertTrue(fsm.update(update));
+ assertEquals(1, fsm.getPoliciesMap().size());
+
+ //
+ // add an artifact policy
+ //
+
+ ToscaPolicy policyNativeArtifact =
+ getPolicyFromFile(EXAMPLE_NATIVE_ARTIFACT_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_ARTIFACT_POLICY_NAME);
+
+ Map<String, String> controllerMap =
+ (Map<String, String>) policyNativeArtifact.getProperties().get("controller");
+ controllerMap.put("name", "xyz987");
+ update.setPolicies(List.of(policyNativeController, policyNativeArtifact));
+ assertFalse(fsm.update(update));
+
+ // add a registered controller
+
+ controllerMap.put("name", "lifecycle");
+ update.setPolicies(List.of(policyNativeController, policyNativeArtifact));
+ assertTrue(fsm.update(update));
+
+ assertEquals(2, fsm.getPoliciesMap().size());
+ assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertEquals(policyNativeArtifact, fsm.getPoliciesMap().get(policyNativeArtifact.getIdentifier()));
+
+ //
+ // add a legacy operational policy
+ //
+
+ String restart = Files.readString(Paths.get("src/test/resources/tosca-policy-operational-restart.json"));
+ ToscaPolicy opPolicyRestart = new StandardCoder().decode(restart, ToscaPolicy.class);
+ update.setPolicies(List.of(policyNativeController, policyNativeArtifact, opPolicyRestart));
+ assertFalse(fsm.update(update));
+
+ assertEquals(2, fsm.getPoliciesMap().size());
+ assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertEquals(policyNativeArtifact, fsm.getPoliciesMap().get(policyNativeArtifact.getIdentifier()));
+
+ // register controller
+
+ fsm.start(controllerSupport.getController());
+
+ assertEquals(4, fsm.policyTypesMap.size());
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.native.drools.Controller", "1.0.0")));
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.native.drools.Artifact", "1.0.0")));
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.controlloop.Operational", "1.0.0")));
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.controlloop.operational.common.Drools",
+ "1.0.0")));
+
+ // invalid controller name
+
+ opPolicyRestart.getProperties().put("controllerName", "xyz987");
+ assertFalse(fsm.update(update));
+ assertEquals(2, fsm.getPoliciesMap().size());
+ assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertEquals(policyNativeArtifact, fsm.getPoliciesMap().get(policyNativeArtifact.getIdentifier()));
+
+ // no controller name
+
+ opPolicyRestart.getProperties().remove("controllerName");
+ assertTrue(fsm.update(update));
+ assertEquals(3, fsm.getPoliciesMap().size());
+ assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertEquals(policyNativeArtifact, fsm.getPoliciesMap().get(policyNativeArtifact.getIdentifier()));
+ assertEquals(opPolicyRestart, fsm.getPoliciesMap().get(opPolicyRestart.getIdentifier()));
+
+ List<ToscaPolicy> factPolicies = controllerSupport.getFacts(ToscaPolicy.class);
+ assertEquals(1, factPolicies.size());
+ assertEquals(opPolicyRestart, factPolicies.get(0));
+
+ // upgrade operational policy with valid controller name
+
+ String restartV2 = Files.readString(
+ Paths.get("src/test/resources/tosca-policy-operational-restart.v2.json"));
+ ToscaPolicy opPolicyRestartV2 = new StandardCoder().decode(restartV2, ToscaPolicy.class);
+ opPolicyRestartV2.getProperties().put("controllerName", "lifecycle");
+ update.setPolicies(List.of(policyNativeController, policyNativeArtifact, opPolicyRestartV2));
+ assertTrue(fsm.update(update));
+
+ assertEquals(3, fsm.getPoliciesMap().size());
+ assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertEquals(policyNativeArtifact, fsm.getPoliciesMap().get(policyNativeArtifact.getIdentifier()));
+ assertEquals(opPolicyRestartV2, fsm.getPoliciesMap().get(opPolicyRestartV2.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(opPolicyRestart.getIdentifier()));
+
+ factPolicies = controllerSupport.getFacts(ToscaPolicy.class);
+ assertEquals(1, factPolicies.size());
+ assertEquals(opPolicyRestartV2, factPolicies.get(0));
+
+ update.setPolicies(List.of(policyNativeController, policyNativeArtifact));
+ assertTrue(fsm.update(update));
+
+ assertEquals(2, fsm.getPoliciesMap().size());
+ assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertEquals(policyNativeArtifact, fsm.getPoliciesMap().get(policyNativeArtifact.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(opPolicyRestartV2.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(opPolicyRestart.getIdentifier()));
+
+ factPolicies = controllerSupport.getFacts(ToscaPolicy.class);
+ assertEquals(0, factPolicies.size());
+ assertTrue(controllerSupport.getController().getDrools().isBrained());
+
+ update.setPolicies(List.of(policyNativeController));
+ assertTrue(fsm.update(update));
+ assertFalse(controllerSupport.getController().getDrools().isBrained());
+ assertEquals(1, fsm.getPoliciesMap().size());
+ assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(policyNativeArtifact.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(opPolicyRestartV2.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(opPolicyRestart.getIdentifier()));
+
+ ToscaPolicy policyNativeFooController =
+ getPolicyFromFile(FOO_NATIVE_DROOLS_POLICY_JSON, FOO_NATIVE_DROOLS_CONTROLLER_POLICY_NAME);
+ update.setPolicies(List.of(policyNativeController, policyNativeFooController));
+ assertTrue(fsm.update(update));
+ assertEquals(2, fsm.getPoliciesMap().size());
+ assertEquals(policyNativeController, fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertEquals(policyNativeFooController, fsm.getPoliciesMap().get(policyNativeFooController.getIdentifier()));
+
+ update.setPolicies(Collections.EMPTY_LIST);
+ assertTrue(fsm.update(update));
+ assertThatIllegalArgumentException().isThrownBy(() -> controllerSupport.getController().getDrools());
+ assertNull(fsm.getPoliciesMap().get(policyNativeController.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(policyNativeArtifact.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(opPolicyRestartV2.getIdentifier()));
+ assertNull(fsm.getPoliciesMap().get(opPolicyRestart.getIdentifier()));
+
+ fsm.shutdown();
+ }
+}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
index c61227b9..f370d0db 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
@@ -45,6 +46,7 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
* Lifecycle State Active Test.
@@ -207,7 +209,16 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
assertTrue(fsm.update(update));
assertEquals(qlength + 1, fsm.client.getSink().getRecentEvents().length);
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.native.drools.Controller", "1.0.0")));
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.native.drools.Artifact", "1.0.0")));
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.controlloop.Operational", "1.0.0")));
+ assertNotNull(fsm.getPolicyTypesMap().get(
+ new ToscaPolicyTypeIdentifier("onap.policies.controlloop.operational.common.Drools",
+ "1.0.0")));
PdpStatus cachedStatus = new StandardCoder()
.decode(fsm.client.getSink().getRecentEvents()[qlength], PdpStatus.class);
assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies());
@@ -221,7 +232,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
assertTrue(fsm.update(update));
assertEquals(qlength + 2, fsm.client.getSink().getRecentEvents().length);
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
cachedStatus = new StandardCoder()
.decode(fsm.client.getSink().getRecentEvents()[qlength + 1], PdpStatus.class);
assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies());
@@ -237,7 +248,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
update.setPolicies(Collections.emptyList());
assertTrue(fsm.update(update));
assertEquals(qlength + 3, fsm.client.getSink().getRecentEvents().length);
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
cachedStatus = new StandardCoder()
.decode(fsm.client.getSink().getRecentEvents()[qlength + 2], PdpStatus.class);
assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies());
@@ -251,7 +262,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
update.setPolicies(Arrays.asList(toscaPolicyRestartV1));
assertTrue(fsm.update(update));
assertEquals(qlength + 4, fsm.client.getSink().getRecentEvents().length);
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
cachedStatus = new StandardCoder()
.decode(fsm.client.getSink().getRecentEvents()[qlength + 3], PdpStatus.class);
assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies());
@@ -269,7 +280,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
update.setPolicies(Arrays.asList(toscaPolicyRestartV2));
assertTrue(fsm.update(update));
assertEquals(qlength + 5, fsm.client.getSink().getRecentEvents().length);
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
cachedStatus = new StandardCoder()
.decode(fsm.client.getSink().getRecentEvents()[qlength + 4], PdpStatus.class);
assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies());
@@ -288,7 +299,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
update.setPolicies(Arrays.asList(toscaPolicyRestartV2, toscaPolicyFirewall));
assertTrue(fsm.update(update));
assertEquals(qlength + 6, fsm.client.getSink().getRecentEvents().length);
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
cachedStatus = new StandardCoder()
.decode(fsm.client.getSink().getRecentEvents()[qlength + 5], PdpStatus.class);
assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies());
@@ -313,4 +324,5 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
fsm.shutdown();
}
+
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
index 219aa0fb..7ccbd1f2 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
@@ -76,11 +76,11 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertSame(controllerSupport.getController(),
((PolicyTypeDroolsController) fsm.getController(
new ToscaPolicyTypeIdentifier(
- ControllerSupport.POLICY_TYPE, ControllerSupport.POLICY_TYPE_VERSION)))
+ ControllerSupport.POLICY_TYPE_LEGACY_OP, ControllerSupport.POLICY_TYPE_VERSION)))
.controllers().get(0));
fsm.stop(controllerSupport.getController());
- assertNull(fsm.getController(new ToscaPolicyTypeIdentifier(ControllerSupport.POLICY_TYPE,
+ assertNull(fsm.getController(new ToscaPolicyTypeIdentifier(ControllerSupport.POLICY_TYPE_LEGACY_OP,
ControllerSupport.POLICY_TYPE_VERSION)));
fsm.shutdown();
@@ -211,11 +211,11 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertTrue(fsm.policiesMap.isEmpty());
fsm.start(controllerSupport.getController());
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
assertTrue(fsm.policiesMap.isEmpty());
assertTrue(fsm.update(update));
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
assertEquals(1, fsm.policiesMap.size());
assertEquals(fsm.policiesMap.get(toscaPolicy.getIdentifier()), toscaPolicy);
assertEquals(PdpState.PASSIVE, fsm.state());
@@ -229,7 +229,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
update.setPdpSubgroup(null);
update.setPolicies(Collections.emptyList());
assertTrue(fsm.update(update));
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
assertEquals(0, fsm.policiesMap.size());
assertEquals(PdpState.PASSIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
@@ -241,6 +241,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
fsm.shutdown();
}
+
@Test
public void testStateChange() throws CoderException, IOException {
/* no name */
@@ -269,11 +270,11 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
controllerSupport.getController().start();
fsm.start(controllerSupport.getController());
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
assertTrue(fsm.policiesMap.isEmpty());
assertTrue(fsm.update(update));
- assertEquals(3, fsm.policyTypesMap.size());
+ assertEquals(4, fsm.policyTypesMap.size());
assertEquals(1, fsm.policiesMap.size());
assertEquals(fsm.policiesMap.get(toscaPolicy.getIdentifier()), toscaPolicy);
assertEquals(PdpState.PASSIVE, fsm.state());
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
index 1d03124a..16474785 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
@@ -28,6 +28,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
@@ -66,6 +67,8 @@ public abstract class LifecycleStateRunningTest {
@AfterClass
public static void tearDown() {
controllerSupport.destroyController();
+ NoopTopicFactories.getSourceFactory().destroy();
+ NoopTopicFactories.getSinkFactory().destroy();
try {
Files.deleteIfExists(Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
CONTROLLER_NAME + "-controller.properties.bak"));
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactControllerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactControllerTest.java
index cb55e637..cd17385d 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactControllerTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeArtifactControllerTest.java
@@ -43,7 +43,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi
*/
public class PolicyTypeNativeArtifactControllerTest extends LifecycleStateRunningTest {
// Native Drools Policy
- private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example";
+ private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example.artifact";
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON =
"src/test/resources/tosca-policy-native-artifact-example.json";
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java
index 1aa3a684..a230ced8 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java
@@ -41,7 +41,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
*/
public class PolicyTypeNativeDroolsControllerTest extends LifecycleStateRunningTest {
// Native Drools Policy
- private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example";
+ private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example.controller";
private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON =
"src/test/resources/tosca-policy-native-controller-example.json";
@@ -86,8 +86,6 @@ public class PolicyTypeNativeDroolsControllerTest extends LifecycleStateRunningT
noopTopicProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-CL");
TopicEndpointManager.getManager().addTopics(noopTopicProperties);
- controller.deploy(policy);
-
- return;
+ assertTrue(controller.deploy(policy));
}
} \ No newline at end of file
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
index ae62095e..511fcc9b 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
@@ -19,7 +19,12 @@
package org.onap.policy.drools.server.restful;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.junit.After;
@@ -80,16 +85,82 @@ public class RestLifecycleManagerTest {
@Test
public void testFsm() {
- Response response = HttpClientFactoryInstance.getClientFactory().get("lifecycle").get("fsm/group");
+
+ HttpClient client = HttpClientFactoryInstance.getClientFactory().get("lifecycle");
+ Response response;
+
+ /* group */
+
+ response = client.put("group/GG", Entity.json(""), Collections.emptyMap());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals("GG", HttpClient.getBody(response, String.class));
+
+ response = HttpClientFactoryInstance.getClientFactory().get("lifecycle").get("group");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertEquals(LifecycleFeature.fsm.getGroup(), HttpClient.getBody(response, String.class));
+
+ /* subgroup */
+
+ response = client.put("subgroup/YY", Entity.json(""), Collections.emptyMap());
assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals("YY", HttpClient.getBody(response, String.class));
- response = HttpClientFactoryInstance.getClientFactory().get("lifecycle").get("fsm/subgroup");
- assertEquals("", HttpClient.getBody(response, String.class));
+ response = client.get("subgroup");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(LifecycleFeature.fsm.getSubgroup(), HttpClient.getBody(response, String.class));
- response = HttpClientFactoryInstance.getClientFactory().get("lifecycle").get("fsm/state");
+ /* properties */
+
+ response = client.get("properties");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(LifecycleFeature.fsm.getProperties(), HttpClient.getBody(response, Properties.class));
+
+ /* state (disallowed state change as has not been started) */
+
+ response = client.put("state/PASSIVE", Entity.json(""), Collections.emptyMap());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Boolean.FALSE, HttpClient.getBody(response, Boolean.class));
+
+ response = client.get("state");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertEquals(PdpState.TERMINATED, HttpClient.getBody(response, PdpState.class));
+
+ /* topics */
+
+ assertEquals(Status.OK.getStatusCode(), client.get("topic/source").getStatus());
+ assertEquals(Status.OK.getStatusCode(), client.get("topic/sink").getStatus());
+
+ /* status interval */
+
+ response = client.put("status/interval/1000", Entity.json(""), Collections.emptyMap());
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Long.valueOf(1000L), HttpClient.getBody(response, Long.class));
+
+ response = client.get("status/interval");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(Long.valueOf(1000L), HttpClient.getBody(response, Long.class));
+
+ /* policy types */
+
+ response = client.get("policyTypes");
assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(2, HttpClient.getBody(response, List.class).size());
+
+ response = client.get("policyTypes/onap.policies.native.drools.Artifact/1.0.0");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertNotNull(HttpClient.getBody(response, String.class));
+
+ response = client.get("policyTypes/onap.policies.native.drools.Controller/1.0.0");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertNotNull(HttpClient.getBody(response, String.class));
+
+ /* policies */
+
+ response = client.get("policies");
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ assertEquals(0, HttpClient.getBody(response, List.class).size());
+
+ response = client.get("policies/onap.policies.controlloop.Operational");
+ assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
}