c80a38d77c88d4cc4a70af28f6a657a05512a2ed
[policy/models.git] /
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 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.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.sdnc.SdncRequest;
41 import org.onap.policy.simulators.Util;
42
43 public class SdncActorServiceProviderTest {
44
45     /**
46      * Set up for test class.
47      */
48     @BeforeClass
49     public static void setUpSimulator() {
50         try {
51             Util.buildAaiSim();
52         } catch (Exception e) {
53             fail(e.getMessage());
54         }
55     }
56
57     @AfterClass
58     public static void tearDownSimulator() {
59         HttpServletServer.factory.destroy();
60     }
61
62     @Test
63     public void testConstructRequest() {
64         VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
65         ControlLoopOperation operation = new ControlLoopOperation();
66
67         Policy policy = new Policy();
68         policy.setRecipe("Reroute");
69
70         SdncActorServiceProvider provider = new SdncActorServiceProvider();
71         assertNull(provider.constructRequest(onset, operation, policy));
72
73         onset.getAai().put("network-information.network-id", "network-5555");
74         assertNull(provider.constructRequest(onset, operation, policy));
75
76         assertNull(provider.constructRequest(onset, operation, policy));
77
78         UUID requestId = UUID.randomUUID();
79         onset.setRequestId(requestId);
80         assertNull(provider.constructRequest(onset, operation, policy));
81
82         assertNull(provider.constructRequest(onset, operation, policy));
83
84         onset.getAai().put("service-instance.service-instance-id", "service-instance-01");
85         assertNotNull(provider.constructRequest(onset, operation, policy));
86
87         policy.setRecipe("Reroute");
88         assertNotNull(provider.constructRequest(onset, operation, policy));
89
90         SdncRequest request =
91                 provider.constructRequest(onset, operation, policy);
92
93         assertEquals(requestId, Objects.requireNonNull(request).getRequestId());
94         assertEquals("reoptimize", request.getHealRequest().getRequestHeaderInfo().getSvcAction());
95         assertEquals("ReoptimizeSOTNInstance", request.getHealRequest().getRequestInfo().getRequestAction());
96         assertEquals("network-5555", request.getHealRequest().getNetworkInfo().getNetworkId());
97         assertEquals("service-instance-01", request.getHealRequest().getServiceInfo().getServiceInstanceId());
98     }
99
100     @Test
101     public void testMethods() {
102         SdncActorServiceProvider sp = new SdncActorServiceProvider();
103
104         assertEquals("SDNC", sp.actor());
105         assertEquals(1, sp.recipes().size());
106         assertEquals("Reroute", sp.recipes().get(0));
107         assertEquals("VM", sp.recipeTargets("Reroute").get(0));
108         assertEquals(0, sp.recipePayloads("Reroute").size());
109     }
110 }