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.*;
25 import java.util.UUID;
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.policy.aai.AAIGETVnfResponse;
31 import org.onap.policy.controlloop.ControlLoopOperation;
32 import org.onap.policy.controlloop.VirtualControlLoopEvent;
33 import org.onap.policy.controlloop.policy.Policy;
34 import org.onap.policy.drools.http.server.HttpServletServer;
35 import org.onap.policy.drools.system.PolicyEngine;
36 import org.onap.policy.simulators.Util;
37 import org.onap.policy.vfc.VFCRequest;
39 public class TestVFCActorServiceProvider {
41 public static void setUpSimulator() {
44 } catch (Exception e) {
50 public static void tearDownSimulator() {
51 HttpServletServer.factory.destroy();
55 public void testConstructRequest() {
56 VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
57 ControlLoopOperation operation = new ControlLoopOperation();
59 Policy policy = new Policy();
60 policy.setRecipe("GoToOz");
62 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
64 onset.getAAI().put("generic-vnf.vnf-id", "dorothy.gale.1939");
65 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
67 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
68 PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
69 PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
70 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
72 UUID requestID = UUID.randomUUID();
73 onset.setRequestID(requestID);
74 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
76 onset.getAAI().put("generic-vnf.vnf-name", "Dorothy");
77 PolicyEngine.manager.getEnvironment().remove("aai.password");
78 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
80 PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
81 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
83 onset.getAAI().put("service-instance.service-instance-id", "");
84 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
86 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AAIGETVnfResponse()));
88 policy.setRecipe("Restart");
89 assertNotNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AAIGETVnfResponse()));
91 VFCRequest request = VFCActorServiceProvider.constructRequest(onset, operation, policy, new AAIGETVnfResponse());
93 assertEquals(requestID, request.getRequestId());
94 assertEquals("dorothy.gale.1939", request.getHealRequest().getVnfInstanceId());
95 assertEquals("restartvm", request.getHealRequest().getAdditionalParams().getAction());
99 public void testMethods() {
100 VFCActorServiceProvider sp = new VFCActorServiceProvider();
102 assertEquals("VFC", sp.actor());
103 assertEquals(1, sp.recipes().size());
104 assertEquals("Restart", sp.recipes().get(0));
105 assertEquals("VM", sp.recipeTargets("Restart").get(0));
106 assertEquals(0, sp.recipePayloads("Restart").size());