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