633234f4422d64d2dd54872a17fa401e7d3b41e6
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * TestSdncActorServiceProvider
4  * ================================================================================
5  * Copyright (C) 2018 Huawei. All rights reserved.
6  * Modifications Copyright (C) 2018 AT&T Corp. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.controlloop.actor.sdnc;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.fail;
28
29 import java.util.Objects;
30 import java.util.UUID;
31
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.onap.policy.aai.AaiGetVnfResponse;
36 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
37 import org.onap.policy.controlloop.ControlLoopOperation;
38 import org.onap.policy.controlloop.VirtualControlLoopEvent;
39 import org.onap.policy.controlloop.policy.Policy;
40 import org.onap.policy.drools.system.PolicyEngine;
41 import org.onap.policy.sdnc.SdncRequest;
42 import org.onap.policy.simulators.Util;
43
44 public class SdncActorServiceProviderTest {
45
46     /**
47      * Set up for test class.
48      */
49     @BeforeClass
50     public static void setUpSimulator() {
51         try {
52             Util.buildAaiSim();
53         } catch (Exception e) {
54             fail(e.getMessage());
55         }
56     }
57
58     @AfterClass
59     public static void tearDownSimulator() {
60         HttpServletServer.factory.destroy();
61     }
62
63     @Test
64     public void testConstructRequest() {
65         VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
66         ControlLoopOperation operation = new ControlLoopOperation();
67
68         Policy policy = new Policy();
69         policy.setRecipe("Reroute");
70
71         assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
72
73         onset.getAai().put("network-information.network-id", "network-5555");
74         assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
75
76         PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
77         PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
78         PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
79         assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
80
81         UUID requestId = UUID.randomUUID();
82         onset.setRequestId(requestId);
83         assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
84
85         PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
86         assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
87
88         onset.getAai().put("service-instance.service-instance-id", "service-instance-01");
89         assertNotNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
90
91         policy.setRecipe("Reroute");
92         assertNotNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
93
94         SdncRequest request =
95                 SdncActorServiceProvider.constructRequest(onset, operation, policy);
96
97         assertEquals(requestId, Objects.requireNonNull(request).getRequestId());
98         assertEquals("reoptimize", request.getHealRequest().getRequestHeaderInfo().getSvcAction());
99         assertEquals("ReoptimizeSOTNInstance", request.getHealRequest().getRequestInfo().getRequestAction());
100         assertEquals("network-5555", request.getHealRequest().getNetworkInfo().getNetworkId());
101         assertEquals("service-instance-01", request.getHealRequest().getServiceInfo().getServiceInstanceId());
102     }
103
104     @Test
105     public void testMethods() {
106         SdncActorServiceProvider sp = new SdncActorServiceProvider();
107
108         assertEquals("SDNC", sp.actor());
109         assertEquals(1, sp.recipes().size());
110         assertEquals("Reroute", sp.recipes().get(0));
111         assertEquals("VM", sp.recipeTargets("Reroute").get(0));
112         assertEquals(0, sp.recipePayloads("Reroute").size());
113     }
114 }