diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2020-02-27 19:20:39 -0600 |
---|---|---|
committer | jhh <jorge.hernandez-herrero@att.com> | 2020-02-27 19:20:39 -0600 |
commit | 7f1a0e6e142513087aa9385786212455a1ea0f22 (patch) | |
tree | a8977301b868108220d62c8cba2733158f8d7509 /feature-lifecycle/src/test | |
parent | f22a6d5c2ae04a82919f7b9e7c9da5f5d459dd05 (diff) |
Undeploy support for native rules PDP-D policies.
Issue-ID: POLICY-2388
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: Ic829bda9dbbb54d8883df6c642c1895cd7936823
Diffstat (limited to 'feature-lifecycle/src/test')
-rw-r--r-- | feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesControllerTest.java | 94 |
1 files changed, 58 insertions, 36 deletions
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 index 17a4ebed..5754f06e 100644 --- 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 @@ -34,6 +34,7 @@ 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.MavenDroolsController; 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; @@ -52,40 +53,28 @@ public class PolicyTypeRulesControllerTest extends LifecycleStateRunningTest { private static final String EXAMPLE_NATIVE_DROOLS_POLICY_JSON = "src/test/resources/example.policy.native.drools.tosca.json"; + private ToscaPolicy policy; + private NativeDroolsPolicy nativePolicy; + private PolicyTypeRulesController controller; + /** * Test Set initialization. */ @Before - public void init() { + public void init() throws IOException, CoderException { fsm = makeFsmWithPseudoTime(); - } - - @Test - public void testDeploy() { - // TODO - } + policy = getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_POLICY_NAME); + nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class); + controller = + new PolicyTypeRulesController(fsm, + new ToscaPolicyTypeIdentifier("onap.policies.native.Drools", "1.0.0")); - @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()); - + /* start controller */ assertTrue(controllerSupport.getController().start()); assertTrue(controllerSupport.getController().isAlive()); @@ -102,33 +91,66 @@ public class PolicyTypeRulesControllerTest extends LifecycleStateRunningTest { 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")); + @Test + public void testUndeployDeploy() { + undeploy(); + deploy(); + + PolicyControllerConstants.getFactory().destroy("lifecycle"); + assertThatIllegalArgumentException().isThrownBy(() -> PolicyControllerConstants.getFactory().get("lifecycle")); + } + + private void undeploy() { + assertTrue(controller.undeploy(policy)); + assertUndeployed(); + + /* idempotence */ assertTrue(controller.undeploy(policy)); + assertUndeployed(); + } + + + private void deploy() { + assertTrue(controller.deploy(policy)); + assertDeployed(); + /* idempotence */ + assertTrue(controller.deploy(policy)); + assertDeployed(); + + // TODO: test a point version upgrade + } + + private void assertUndeployed() { 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())); + 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 void assertDeployed() { + assertTrue(controllerSupport.getController().getDrools().isBrained()); + assertTrue(controllerSupport.getController().getDrools().isAlive()); + assertTrue(controllerSupport.getController().isAlive()); + assertSame(controllerSupport.getController(), PolicyControllerConstants.getFactory().get("lifecycle")); + assertSame(controllerSupport.getController(), + PolicyControllerConstants.getFactory().get( + nativePolicy.getProperties().getRulesArtifact().getGroupId(), + nativePolicy.getProperties().getRulesArtifact().getArtifactId())); + assertTrue(controllerSupport.getController().getDrools() instanceof MavenDroolsController); } private ToscaPolicy getPolicyFromFile(String filePath, String policyName) throws CoderException, IOException { |