summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'feature-lifecycle/src/test')
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java4
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java1
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesControllerTest.java140
-rw-r--r--feature-lifecycle/src/test/resources/example.policy.native.drools.tosca.json6
-rw-r--r--feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.Operational-1.0.0.schema.json1
-rw-r--r--feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.operational.common.Drools-1.0.0.schema.json15
6 files changed, 161 insertions, 6 deletions
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java
index 945b00b1..17bb9d49 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java
@@ -140,8 +140,8 @@ public class DomainPolicyTypesTest {
assertTrue(domainMaker.isConformant(toscaPolicy));
NativeDroolsPolicy domainDroolsPolicy = domainMaker.convertTo(toscaPolicy, NativeDroolsPolicy.class);
- assertEquals("org.onap.policy.controlloop", domainDroolsPolicy.getProperties().getRulesArtifact().getGroupId());
- assertEquals("example", domainDroolsPolicy.getProperties().getRulesArtifact().getArtifactId());
+ assertEquals("org.onap.policy.drools.test", domainDroolsPolicy.getProperties().getRulesArtifact().getGroupId());
+ assertEquals("lifecycle", domainDroolsPolicy.getProperties().getRulesArtifact().getArtifactId());
assertEquals("1.0.0", domainDroolsPolicy.getProperties().getRulesArtifact().getVersion());
String policyId = toscaPolicy.getMetadata().remove("policy-id");
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 06fd08ca..b80a98c7 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
@@ -61,6 +61,7 @@ public abstract class LifecycleStateRunningTest {
*/
@AfterClass
public static void tearDown() {
+ controllerSupport.destroyController();
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/PolicyTypeRulesControllerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesControllerTest.java
new file mode 100644
index 00000000..17a4ebed
--- /dev/null
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesControllerTest.java
@@ -0,0 +1,140 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.
+ * ============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.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
+import org.onap.policy.drools.controller.internal.NullDroolsController;
+import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsPolicy;
+import org.onap.policy.drools.system.PolicyControllerConstants;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+/**
+ * Rules Controller Test.
+ */
+public class PolicyTypeRulesControllerTest extends LifecycleStateRunningTest {
+ private static final StandardCoder coder = new StandardCoder();
+
+ // Native Drools Policy
+ private static final String EXAMPLE_NATIVE_DROOLS_POLICY_NAME = "example";
+ private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON =
+ "src/test/resources/example.policy.native.drools.tosca.json";
+
+ /**
+ * Test Set initialization.
+ */
+ @Before
+ public void init() {
+ fsm = makeFsmWithPseudoTime();
+ }
+
+ @Test
+ public void testDeploy() {
+ // TODO
+ }
+
+ @Test
+ public void testUndeploy() throws IOException, CoderException {
+ assertTrue(controllerSupport.getController().getDrools().isBrained());
+ assertFalse(controllerSupport.getController().isAlive());
+ assertFalse(controllerSupport.getController().getDrools().isAlive());
+ assertSame(controllerSupport.getController(), PolicyControllerConstants.getFactory().get("lifecycle"));
+
+ ToscaPolicy policy = getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_POLICY_NAME);
+ NativeDroolsPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class);
+
+ assertSame(controllerSupport.getController(),
+ PolicyControllerConstants.getFactory().get(
+ nativePolicy.getProperties().getRulesArtifact().getGroupId(),
+ nativePolicy.getProperties().getRulesArtifact().getArtifactId()));
+ assertEquals(controllerSupport.getController().getDrools().getGroupId(),
+ nativePolicy.getProperties().getRulesArtifact().getGroupId());
+ assertEquals(controllerSupport.getController().getDrools().getArtifactId(),
+ nativePolicy.getProperties().getRulesArtifact().getArtifactId());
+ assertEquals(controllerSupport.getController().getDrools().getVersion(),
+ nativePolicy.getProperties().getRulesArtifact().getVersion());
+
+ assertTrue(controllerSupport.getController().start());
+
+ assertTrue(controllerSupport.getController().isAlive());
+ assertTrue(controllerSupport.getController().getDrools().isAlive());
+ assertTrue(controllerSupport.getController().getDrools().isBrained());
+ assertSame(controllerSupport.getController(), PolicyControllerConstants.getFactory().get("lifecycle"));
+ assertSame(controllerSupport.getController(),
+ PolicyControllerConstants.getFactory().get(
+ nativePolicy.getProperties().getRulesArtifact().getGroupId(),
+ nativePolicy.getProperties().getRulesArtifact().getArtifactId()));
+ assertEquals(controllerSupport.getController().getDrools().getGroupId(),
+ nativePolicy.getProperties().getRulesArtifact().getGroupId());
+ assertEquals(controllerSupport.getController().getDrools().getArtifactId(),
+ nativePolicy.getProperties().getRulesArtifact().getArtifactId());
+ assertEquals(controllerSupport.getController().getDrools().getVersion(),
+ nativePolicy.getProperties().getRulesArtifact().getVersion());
+
+ PolicyTypeRulesController controller =
+ new PolicyTypeRulesController(makeFsmWithPseudoTime(),
+ new ToscaPolicyTypeIdentifier("onap.policies.native.Drools", "1.0.0"));
+ assertTrue(controller.undeploy(policy));
+
+ assertFalse(controllerSupport.getController().getDrools().isBrained());
+ assertFalse(controllerSupport.getController().getDrools().isAlive());
+ assertTrue(controllerSupport.getController().isAlive());
+ assertSame(controllerSupport.getController(), PolicyControllerConstants.getFactory().get("lifecycle"));
+ assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get(
+ nativePolicy.getProperties().getRulesArtifact().getGroupId(),
+ nativePolicy.getProperties().getRulesArtifact().getArtifactId()));
+ assertTrue(controllerSupport.getController().getDrools() instanceof NullDroolsController);
+ assertEquals(DroolsControllerConstants.NO_GROUP_ID, controllerSupport.getController().getDrools().getGroupId());
+ assertEquals(DroolsControllerConstants.NO_ARTIFACT_ID,
+ controllerSupport.getController().getDrools().getArtifactId());
+ assertEquals(DroolsControllerConstants.NO_VERSION, controllerSupport.getController().getDrools().getVersion());
+
+ assertTrue(controller.undeploy(policy));
+ PolicyControllerConstants.getFactory().destroy("lifecycle");
+ assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle"));
+ }
+
+ @Test
+ public void testGetPolicyType() {
+ // TODO
+ }
+
+ private ToscaPolicy getPolicyFromFile(String filePath, String policyName) throws CoderException, IOException {
+ String policyJson = new String(Files.readAllBytes(Paths.get(filePath)));
+ ToscaServiceTemplate serviceTemplate = coder.decode(policyJson, ToscaServiceTemplate.class);
+ return serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
+ }
+
+} \ No newline at end of file
diff --git a/feature-lifecycle/src/test/resources/example.policy.native.drools.tosca.json b/feature-lifecycle/src/test/resources/example.policy.native.drools.tosca.json
index 0313b2ed..f3f34b6f 100644
--- a/feature-lifecycle/src/test/resources/example.policy.native.drools.tosca.json
+++ b/feature-lifecycle/src/test/resources/example.policy.native.drools.tosca.json
@@ -13,12 +13,12 @@
},
"properties": {
"rulesArtifact": {
- "groupId": "org.onap.policy.controlloop",
- "artifactId": "example",
+ "groupId": "org.onap.policy.drools.test",
+ "artifactId": "lifecycle",
"version": "1.0.0"
},
"controller": {
- "name": "example",
+ "name": "lifecycle",
"version": "1.0.0"
}
}
diff --git a/feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.Operational-1.0.0.schema.json b/feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.Operational-1.0.0.schema.json
index e89238d7..801859be 100644
--- a/feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.Operational-1.0.0.schema.json
+++ b/feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.Operational-1.0.0.schema.json
@@ -7,6 +7,7 @@
"required": [
"type",
"type_version",
+ "name",
"version",
"properties"
],
diff --git a/feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.operational.common.Drools-1.0.0.schema.json b/feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.operational.common.Drools-1.0.0.schema.json
index c98e25bf..5d032f06 100644
--- a/feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.operational.common.Drools-1.0.0.schema.json
+++ b/feature-lifecycle/src/test/resources/schemas/onap.policies.controlloop.operational.common.Drools-1.0.0.schema.json
@@ -201,6 +201,18 @@
"VNF"
],
"pattern": "^(.+)$"
+ },
+ "entityIds": {
+ "$id": "#/properties/properties/properties/operations/items/properties/operation/properties/target/properties/entityIds",
+ "type": "object",
+ "title": "Arbitrary Resource Identities",
+ "examples": [
+ "Eace933104d443b496b8.nodes.heat.vpg"
+ ],
+ "additionalProperties": {
+ "type": "string",
+ "pattern": "^(.+)$"
+ }
}
}
},
@@ -209,7 +221,8 @@
"type": "object",
"title": "Payload",
"additionalProperties": {
- "type": "string"
+ "type": "string",
+ "pattern": "^(.+)$"
}
}
}