6e221239966acaa1010b8fe3fd66cb34b1f9d010
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / java / org / onap / so / bpmn / infrastructure / workflow / service / ServicePluginFactoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Samsung Intellectual Property. 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 package org.onap.so.bpmn.infrastructure.workflow.service;
21
22 import static org.mockito.Mockito.doReturn;
23
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mock;
28 import org.mockito.Spy;
29 import org.mockito.junit.MockitoJUnitRunner;
30 import org.onap.so.bpmn.core.domain.ServiceDecomposition;
31
32 @RunWith(MockitoJUnitRunner.class)
33 public class ServicePluginFactoryTest {
34
35     @Mock
36     ServiceDecomposition serviceDecomposition;
37
38     @Spy
39     ServicePluginFactory servicePluginFactory;
40
41     String uuiRequest = "{"
42         + "    \"service\":{"
43         + "        \"name\":\"ONAP_223531\","
44         + "        \"description\":\"ONAP_1546\","
45         + "        \"serviceInvariantUuid\":\"4a09419a-c9fd-4a53-b1bd-b49603169ca1\","
46         + "        \"serviceUuid\":\"1bd0eae6-2dcc-4461-9ae6-56d641f369d6\","
47         + "        \"globalSubscriberId\":\"test_custormer\","
48         + "        \"serviceType\":\"example-service-type\","
49         + "        \"parameters\":{"
50         + "            \"locationConstraints\":["
51         + "            ],"
52         + "            \"resources\":["
53         + "                {"
54         + "                    \"resourceName\":\"vEPC_ONAP01\","
55         + "                    \"resourceInvariantUuid\":\"36ebe421-283a-4ee8-92f1-d09e7c44b911\","
56         + "                    \"resourceUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed111\","
57         + "                    \"resourceCustomizationUuid\":\"47a0e235-b67a-4ea4-a0cf-25761afed231\","
58         + "                    \"parameters\":{"
59         + "                        \"locationConstraints\":["
60         + "                            {"
61         + "                                \"vnfProfileId\":\"b244d433-8c9c-49ad-9c70-8e34b8dc8328\","
62         + "                                \"locationConstraints\":{"
63         + "                                    \"vimId\":\"vmware_vio\""
64         + "                                }"
65         + "                            },"
66         + "                            {"
67         + "                                \"vnfProfileId\":\"8a9f7c48-21ce-41b7-95b8-a8ac61ccb1ff\","
68         + "                                \"locationConstraints\":{"
69         + "                                    \"vimId\":\"core-dc_RegionOne\""
70         + "                                }"
71         + "                            }"
72         + "                        ],"
73         + "                        \"resources\":["
74         + "                        ],"
75         + "                        \"requestInputs\":{"
76         + "                            \"sdncontroller\":\"\""
77         + "                        }"
78         + "                    }"
79         + "                },"
80         + "                {"
81         + "                    \"resourceName\":\"VL OVERLAYTUNNEL\","
82         + "                    \"resourceInvariantUuid\":\"184494cf-472f-436f-82e2-d83dddde21cb\","
83         + "                    \"resourceUuid\":\"95bc3e59-c9c5-458f-ad6e-78874ab4b3cc\","
84         + "                    \"resourceCustomizationUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed232\","
85         + "                    \"parameters\":{"
86         + "                        \"locationConstraints\":["
87         + "                        ],"
88         + "                        \"resources\":["
89         + "                        ],"
90         + "                        \"requestInputs\":{"
91         + "                        }"
92         + "                    }"
93         + "                }"
94         + "            ],"
95         + "            \"requestInputs\":{"
96         + "                \"vlunderlayvpn0_name\":\"l3connect\","
97         + "                \"vlunderlayvpn0_site1_id\":\"IP-WAN-Controller-1\","
98         + "                \"vlunderlayvpn0_site2_id\":\"SPTNController\","
99         + "                \"vlunderlayvpn0_site1_networkName\":\"network1,network2\","
100         + "                \"vlunderlayvpn0_site2_networkName\":\"network3,network4\","
101         + "                \"vlunderlayvpn0_site1_routerId\":\"a8098c1a-f86e-11da-bd1a-00112444be1a\","
102         + "                \"vlunderlayvpn0_site2_routerId\":\"a8098c1a-f86e-11da-bd1a-00112444be1e\","
103         + "                \"vlunderlayvpn0_site2_importRT1\":\"200:1,200:2\","
104         + "                \"vlunderlayvpn0_site1_exportRT1\":\"300:1,300:2\","
105         + "                \"vlunderlayvpn0_site2_exportRT1\":\"400:1,400:2\","
106         + "                \"vlunderlayvpn0_site1_vni\":\"2000\","
107         + "                \"vlunderlayvpn0_site2_vni\":\"3000\","
108         + "                \"vlunderlayvpn0_tunnelType\":\"L3-DCI\","
109         + "                \"CallSource\":\"NOT-ExternalAPI\","
110         + "                \"sotnconnectivity\":\"\""
111         + "            }"
112         + "        }"
113         + "    }"
114         + "}";
115
116
117     @Test
118     public void doProcessSiteLocation_isNeedProcessSite() {
119         String result = servicePluginFactory.doProcessSiteLocation(serviceDecomposition, uuiRequest);
120         Assert.assertEquals(result, uuiRequest);
121     }
122
123     @Test
124     public void doProcessSiteLocation_uuiObjectNull() {
125         String faultyJsonInput = "site_address,sotncondition_clientsignal";
126         String result = servicePluginFactory.doProcessSiteLocation(
127             serviceDecomposition, faultyJsonInput);
128         Assert.assertEquals(result, faultyJsonInput);
129     }
130
131     @Test
132     public void doProcessSiteLocation_isSiteLocationLocal() {
133         String jsonWithOnlyNeededValues = "{\"site_address\":\"\",\"sotncondition_clientsignal\":\"\"}";
134         String result = servicePluginFactory.doProcessSiteLocation(
135             serviceDecomposition, jsonWithOnlyNeededValues);
136         Assert.assertEquals(result, jsonWithOnlyNeededValues);
137     }
138
139
140     @Test
141     public void doTPResourcesAllocation_Success() {
142         doReturn(null).when(servicePluginFactory).getTPsfromAAI();
143         String result = servicePluginFactory.doTPResourcesAllocation(null, uuiRequest);
144         Assert.assertNotEquals(result, uuiRequest);
145     }
146
147     @Test
148     public void doTPResourcesAllocation_uuiObjectNull() {
149         String faultyJsonInput = "site_address,sotncondition_clientsignal";
150         String result = servicePluginFactory.doTPResourcesAllocation(null, faultyJsonInput);
151         Assert.assertEquals(result, faultyJsonInput);
152     }
153
154     @Test
155     public void doTPResourcesAllocation_isNeedAllocateCrossTPResources() {
156         //doReturn(null).when(servicePluginFactory).getTPsfromAAI();
157         String jsonWithOnlyNeededValues = "{\"site_address\":\"\",\"sotncondition_clientsignal\":\"\"}";
158         String result = servicePluginFactory.doTPResourcesAllocation(null, jsonWithOnlyNeededValues);
159         Assert.assertEquals(result, jsonWithOnlyNeededValues);
160     }
161
162     @Test
163     public void preProcessService_isSOTN() {
164         String invalidJsonWithOnlyNeededValues = "\"clientSignal\":\"\",\"vpnType\":\"\"}";
165         String result = servicePluginFactory.preProcessService(null, invalidJsonWithOnlyNeededValues);
166         Assert.assertEquals(result, invalidJsonWithOnlyNeededValues);
167     }
168
169     @Test
170     public void preProcessService() {
171         String result = servicePluginFactory.preProcessService(null, uuiRequest);
172         Assert.assertEquals(result, uuiRequest);
173     }
174
175     @Test
176     public void doServiceHoming() {
177         String result = servicePluginFactory.doServiceHoming(null, uuiRequest);
178         Assert.assertEquals(result, uuiRequest);
179     }
180
181     @Test
182     public void doServiceHoming_isSOTN() {
183         String invalidJsonWithOnlyNeededValues = "\"clientSignal\":\"\",\"vpnType\":\"\"}";
184         String result = servicePluginFactory.doServiceHoming(null, invalidJsonWithOnlyNeededValues);
185         Assert.assertEquals(result, invalidJsonWithOnlyNeededValues);
186     }
187 }