7919af44660fabe2199347f828eec01dd64acd8f
[policy/drools-applications.git] /
1 /*-
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actor.vfc;
22
23 import static org.junit.Assert.*;
24
25 import java.util.UUID;
26
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;
38
39 public class TestVFCActorServiceProvider {
40         @BeforeClass
41         public static void setUpSimulator() {
42                 try {
43                         Util.buildAaiSim();
44                 } catch (Exception e) {
45                         fail(e.getMessage());
46                 }
47         }
48
49         @AfterClass
50         public static void tearDownSimulator() {
51                 HttpServletServer.factory.destroy();
52         }
53
54         @Test
55         public void testConstructRequest() {
56                 VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
57                 ControlLoopOperation operation = new ControlLoopOperation();
58
59                 Policy policy = new Policy();
60                 policy.setRecipe("GoToOz");
61                 
62                 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
63                 
64                 onset.getAAI().put("generic-vnf.vnf-id", "dorothy.gale.1939");
65                 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
66                 
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));
71                 
72                 UUID requestID = UUID.randomUUID();
73                 onset.setRequestID(requestID);
74                 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
75                 
76                 onset.getAAI().put("generic-vnf.vnf-name", "Dorothy");
77         PolicyEngine.manager.getEnvironment().remove("aai.password");
78                 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
79                 
80         PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
81                 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
82                 
83                 onset.getAAI().put("service-instance.service-instance-id", "");
84                 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, null));
85
86                 assertNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AAIGETVnfResponse()));
87                 
88                 policy.setRecipe("Restart");
89                 assertNotNull(VFCActorServiceProvider.constructRequest(onset, operation, policy, new AAIGETVnfResponse()));
90
91                 VFCRequest request = VFCActorServiceProvider.constructRequest(onset, operation, policy, new AAIGETVnfResponse());
92                 
93                 assertEquals(requestID, request.getRequestId());
94                 assertEquals("dorothy.gale.1939", request.getHealRequest().getVnfInstanceId());
95                 assertEquals("restartvm", request.getHealRequest().getAdditionalParams().getAction());
96     }
97
98         @Test
99         public void testMethods() {
100                 VFCActorServiceProvider sp = new VFCActorServiceProvider();
101
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());
107         }
108 }