2 * ============LICENSE_START=======================================================
3 * TestVFCActorServiceProvider
4 * ================================================================================
5 * Copyright (C) 2018 Ericsson. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actor.vfc;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.fail;
28 import java.util.UUID;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.policy.aai.AaiGetVnfResponse;
34 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
35 import org.onap.policy.controlloop.ControlLoopOperation;
36 import org.onap.policy.controlloop.VirtualControlLoopEvent;
37 import org.onap.policy.controlloop.policy.Policy;
38 import org.onap.policy.drools.system.PolicyEngine;
39 import org.onap.policy.simulators.Util;
40 import org.onap.policy.vfc.VFCRequest;
42 public class TestVFCActorServiceProvider {
45 * Set up for test class.
48 public static void setUpSimulator() {
51 } catch (Exception e) {
57 public static void tearDownSimulator() {
58 HttpServletServer.factory.destroy();
62 public void testConstructRequest() {
63 VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
64 ControlLoopOperation operation = new ControlLoopOperation();
66 Policy policy = new Policy();
67 policy.setRecipe("GoToOz");
69 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
71 onset.getAai().put("generic-vnf.vnf-id", "dorothy.gale.1939");
72 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
74 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
75 PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
76 PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
77 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
79 UUID requestId = UUID.randomUUID();
80 onset.setRequestId(requestId);
81 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
83 onset.getAai().put("generic-vnf.vnf-name", "Dorothy");
84 PolicyEngine.manager.getEnvironment().remove("aai.password");
85 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
87 PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
88 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
90 onset.getAai().put("service-instance.service-instance-id", "");
91 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
93 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse()));
95 policy.setRecipe("Restart");
96 assertNotNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse()));
99 VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse());
101 assertEquals(requestId, request.getRequestId());
102 assertEquals("dorothy.gale.1939", request.getHealRequest().getVnfInstanceId());
103 assertEquals("restartvm", request.getHealRequest().getAdditionalParams().getAction());
107 public void testMethods() {
108 VFCActorServiceProvider sp = new VFCActorServiceProvider();
110 assertEquals("VFC", sp.actor());
111 assertEquals(1, sp.recipes().size());
112 assertEquals("Restart", sp.recipes().get(0));
113 assertEquals("VM", sp.recipeTargets("Restart").get(0));
114 assertEquals(0, sp.recipePayloads("Restart").size());