Fix models due to sonar changes in common
[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-2019 Huawei. All rights reserved.
6  * Modifications Copyright (C) 2018-2019 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
29 import java.util.Objects;
30 import java.util.UUID;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
35 import org.onap.policy.controlloop.ControlLoopOperation;
36 import org.onap.policy.controlloop.VirtualControlLoopEvent;
37 import org.onap.policy.controlloop.policy.Policy;
38 import org.onap.policy.sdnc.SdncRequest;
39 import org.onap.policy.simulators.Util;
40
41 public class SdncActorServiceProviderTest {
42
43     private static final String REROUTE = "Reroute";
44
45     /**
46      * Set up before test class.
47      * @throws Exception if the A&AI simulator cannot be started
48      */
49     @BeforeClass
50     public static void setUpSimulator() throws Exception {
51         Util.buildAaiSim();
52     }
53
54     @AfterClass
55     public static void tearDownSimulator() {
56         HttpServletServerFactoryInstance.getServerFactory().destroy();
57     }
58
59     @Test
60     public void testConstructRequest() {
61         VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
62         ControlLoopOperation operation = new ControlLoopOperation();
63
64         Policy policy = new Policy();
65         policy.setRecipe(REROUTE);
66
67         SdncActorServiceProvider provider = new SdncActorServiceProvider();
68         assertNull(provider.constructRequest(onset, operation, policy));
69
70         onset.getAai().put("network-information.network-id", "network-5555");
71         assertNull(provider.constructRequest(onset, operation, policy));
72
73         assertNull(provider.constructRequest(onset, operation, policy));
74
75         UUID requestId = UUID.randomUUID();
76         onset.setRequestId(requestId);
77         assertNull(provider.constructRequest(onset, operation, policy));
78
79         assertNull(provider.constructRequest(onset, operation, policy));
80
81         onset.getAai().put("service-instance.service-instance-id", "service-instance-01");
82         assertNotNull(provider.constructRequest(onset, operation, policy));
83
84         policy.setRecipe(REROUTE);
85         assertNotNull(provider.constructRequest(onset, operation, policy));
86
87         SdncRequest request =
88                 provider.constructRequest(onset, operation, policy);
89
90         assertEquals(requestId, Objects.requireNonNull(request).getRequestId());
91         assertEquals("reoptimize", request.getHealRequest().getRequestHeaderInfo().getSvcAction());
92         assertEquals("ReoptimizeSOTNInstance", request.getHealRequest().getRequestInfo().getRequestAction());
93         assertEquals("network-5555", request.getHealRequest().getNetworkInfo().getNetworkId());
94         assertEquals("service-instance-01", request.getHealRequest().getServiceInfo().getServiceInstanceId());
95     }
96
97     @Test
98     public void testMethods() {
99         SdncActorServiceProvider sp = new SdncActorServiceProvider();
100
101         assertEquals("SDNC", sp.actor());
102         assertEquals(1, sp.recipes().size());
103         assertEquals(REROUTE, sp.recipes().get(0));
104         assertEquals("VM", sp.recipeTargets(REROUTE).get(0));
105         assertEquals(0, sp.recipePayloads(REROUTE).size());
106     }
107 }