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.Objects;
29 import java.util.UUID;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.policy.aai.AaiGetVnfResponse;
35 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
36 import org.onap.policy.controlloop.ControlLoopOperation;
37 import org.onap.policy.controlloop.VirtualControlLoopEvent;
38 import org.onap.policy.controlloop.policy.Policy;
39 import org.onap.policy.drools.system.PolicyEngine;
40 import org.onap.policy.simulators.Util;
41 import org.onap.policy.vfc.VFCRequest;
43 public class TestVFCActorServiceProvider {
46 * Set up for test class.
49 public static void setUpSimulator() {
52 } catch (Exception e) {
58 public static void tearDownSimulator() {
59 HttpServletServer.factory.destroy();
63 public void testConstructRequest() {
64 VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
65 ControlLoopOperation operation = new ControlLoopOperation();
67 Policy policy = new Policy();
68 policy.setRecipe("GoToOz");
70 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
72 onset.getAai().put("generic-vnf.vnf-id", "dorothy.gale.1939");
73 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
75 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
76 PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
77 PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
78 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
80 UUID requestId = UUID.randomUUID();
81 onset.setRequestId(requestId);
82 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
84 onset.getAai().put("generic-vnf.vnf-name", "Dorothy");
85 PolicyEngine.manager.getEnvironment().remove("aai.password");
86 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
88 PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
89 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
91 onset.getAai().put("service-instance.service-instance-id", "");
92 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
94 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse()));
96 policy.setRecipe("Restart");
97 assertNotNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse()));
100 VFCActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse());
102 assertEquals(requestId, Objects.requireNonNull(request).getRequestId());
103 assertEquals("dorothy.gale.1939", request.getHealRequest().getVnfInstanceId());
104 assertEquals("restartvm", request.getHealRequest().getAdditionalParams().getAction());
108 public void testMethods() {
109 VFCActorServiceProvider sp = new VFCActorServiceProvider();
111 assertEquals("VFC", sp.actor());
112 assertEquals(1, sp.recipes().size());
113 assertEquals("Restart", sp.recipes().get(0));
114 assertEquals("VM", sp.recipeTargets("Restart").get(0));
115 assertEquals(0, sp.recipePayloads("Restart").size());