diff options
author | daniel <dc443y@att.com> | 2017-10-24 06:33:31 -0500 |
---|---|---|
committer | daniel <dc443y@att.com> | 2017-10-24 13:16:10 -0500 |
commit | 1480d327ff8559c1d912108f7d3353fed03fcd2c (patch) | |
tree | 8745bec65ea2ee8962f42048ed0362961d0dfc60 /controlloop/common/actors/actor.appclcm/src/test | |
parent | baea880ddf0564d81d61bf87ae7f124229bf08f0 (diff) |
Change vnf-id to vnf-name
These changes now allow a lookup of the source vnf-id
based on the onset's vnf-name.
Issue-Id: POLICY-366
Change-Id: I6f6bd500b892dddbbb9e12156b4486208309e21d
Signed-off-by: Daniel Cruz <dc443y@att.com>
Diffstat (limited to 'controlloop/common/actors/actor.appclcm/src/test')
-rw-r--r-- | controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java | 67 |
1 files changed, 61 insertions, 6 deletions
diff --git a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java index 63ecd2ec9..7c0f1882a 100644 --- a/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java +++ b/controlloop/common/actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmServiceProviderTest.java @@ -27,7 +27,11 @@ import java.util.AbstractMap; import java.util.HashMap; import java.util.UUID; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.aai.AAIGETVnfResponse; +import org.onap.policy.aai.util.AAIException; import org.onap.policy.appclcm.LCMCommonHeader; import org.onap.policy.appclcm.LCMRequest; import org.onap.policy.appclcm.LCMRequestWrapper; @@ -41,6 +45,9 @@ import org.onap.policy.controlloop.policy.Policy; import org.onap.policy.controlloop.policy.PolicyResult; import org.onap.policy.controlloop.policy.Target; import org.onap.policy.controlloop.policy.TargetType; +import org.onap.policy.drools.http.server.HttpServletServer; +import org.onap.policy.drools.system.PolicyEngine; +import org.onap.policy.simulators.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,6 +58,7 @@ public class AppcLcmServiceProviderTest { private static VirtualControlLoopEvent onsetEvent; private static ControlLoopOperation operation; private static Policy policy; + private static AAIGETVnfResponse aaiResponse; private static LCMRequestWrapper dmaapRequest; private static LCMResponseWrapper dmaapResponse; @@ -64,11 +72,11 @@ public class AppcLcmServiceProviderTest { onsetEvent.requestID = UUID.randomUUID(); onsetEvent.closedLoopEventClient = "tca.instance00001"; onsetEvent.target_type = ControlLoopTargetType.VM; - onsetEvent.target = "generic-vnf.vnf-id"; + onsetEvent.target = "generic-vnf.vnf-name"; onsetEvent.from = "DCAE"; onsetEvent.closedLoopAlarmStart = Instant.now(); onsetEvent.AAI = new HashMap<>(); - onsetEvent.AAI.put("generic-vnf.vnf-id", "fw0001vm001fw001"); + onsetEvent.AAI.put("generic-vnf.vnf-name", "fw0001vm001fw001"); onsetEvent.closedLoopEventStatus = ControlLoopEventStatus.ONSET; /* Construct an operation with an APPC actor and restart operation. */ @@ -84,11 +92,15 @@ public class AppcLcmServiceProviderTest { policy.setName("Restart the VM"); policy.setDescription("Upon getting the trigger event, restart the VM"); policy.setActor("APPC"); - policy.setTarget(new Target(TargetType.VM)); + policy.setTarget(new Target(TargetType.VNF)); policy.setRecipe("Restart"); policy.setPayload(null); policy.setRetry(2); policy.setTimeout(300); + + /* Construct a mock A&AI response */ + aaiResponse = new AAIGETVnfResponse(); + aaiResponse.vnfID = "vnf01"; /* A sample DMAAP request wrapper. */ dmaapRequest = new LCMRequestWrapper(); @@ -101,7 +113,12 @@ public class AppcLcmServiceProviderTest { dmaapResponse.setCorrelationId(onsetEvent.requestID.toString() + "-" + "1"); dmaapResponse.setRpcName(policy.getRecipe().toLowerCase()); dmaapResponse.setType("response"); - + + /* Set environment properties */ + PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666"); + PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI"); + PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI"); + /* A sample APPC LCM request. */ LCMRequest appcRequest = new LCMRequest(); @@ -132,13 +149,33 @@ public class AppcLcmServiceProviderTest { dmaapResponse.setBody(appcResponse); } + @BeforeClass + public static void setUpSimulator() { + try { + Util.buildAaiSim(); + } catch (Exception e) { + fail(e.getMessage()); + } + } + + @AfterClass + public static void tearDownSimulator() { + HttpServletServer.factory.destroy(); + } + /** * A test to construct an APPC LCM restart request. */ @Test public void constructRestartRequestTest() { - LCMRequestWrapper dmaapRequest = AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, policy); + LCMRequestWrapper dmaapRequest = null; + try { + dmaapRequest = AppcLcmActorServiceProvider.constructRequest(onsetEvent, operation, policy, aaiResponse); + } catch (AAIException e) { + logger.warn(e.toString()); + fail("no vnfid found"); + } /* The service provider must return a non null DMAAP request wrapper */ assertNotNull(dmaapRequest); @@ -162,6 +199,7 @@ public class AppcLcmServiceProviderTest { /* Action Identifiers are required and cannot be null */ assertNotNull(appcRequest.getActionIdentifiers()); assertNotNull(appcRequest.getActionIdentifiers().get("vnf-id")); + assertEquals(appcRequest.getActionIdentifiers().get("vnf-id"), "vnf01"); logger.debug("APPC Request: \n" + appcRequest.toString()); } @@ -267,5 +305,22 @@ public class AppcLcmServiceProviderTest { assertEquals(result.getKey(), PolicyResult.FAILURE_EXCEPTION); } - + /** + * This test ensures that that if the the source entity + * is also the target entity, the source will be used for + * the APPC request + */ + @Test + public void sourceIsTargetTest() { + String resourceId = "82194af1-3c2c-485a-8f44-420e22a9eaa4"; + String targetVnfId = null; + try { + targetVnfId = AppcLcmActorServiceProvider.vnfNamedQuery(resourceId, aaiResponse.vnfID); + } catch (AAIException e) { + logger.warn(e.toString()); + fail("no vnf-id found"); + } + assertNotNull(targetVnfId); + assertEquals(targetVnfId, aaiResponse.vnfID); + } } |