1a75f125f6bb1071af4216de42df7769429a8254
[so.git] /
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 import org.apache.commons.lang.reflect.FieldUtils;
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 = "{" + "    \"service\":{" + "        \"name\":\"ONAP_223531\","
42             + "        \"description\":\"ONAP_1546\","
43             + "        \"serviceInvariantUuid\":\"4a09419a-c9fd-4a53-b1bd-b49603169ca1\","
44             + "        \"serviceUuid\":\"1bd0eae6-2dcc-4461-9ae6-56d641f369d6\","
45             + "        \"globalSubscriberId\":\"test_custormer\"," + "        \"serviceType\":\"example-service-type\","
46             + "        \"parameters\":{" + "            \"locationConstraints\":[" + "            ],"
47             + "            \"resources\":[" + "                {"
48             + "                    \"resourceName\":\"vEPC_ONAP01\","
49             + "                    \"resourceInvariantUuid\":\"36ebe421-283a-4ee8-92f1-d09e7c44b911\","
50             + "                    \"resourceUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed111\","
51             + "                    \"resourceCustomizationUuid\":\"47a0e235-b67a-4ea4-a0cf-25761afed231\","
52             + "                    \"parameters\":{" + "                        \"locationConstraints\":["
53             + "                            {"
54             + "                                \"vnfProfileId\":\"b244d433-8c9c-49ad-9c70-8e34b8dc8328\","
55             + "                                \"locationConstraints\":{"
56             + "                                    \"vimId\":\"vmware_vio\"" + "                                }"
57             + "                            }," + "                            {"
58             + "                                \"vnfProfileId\":\"8a9f7c48-21ce-41b7-95b8-a8ac61ccb1ff\","
59             + "                                \"locationConstraints\":{"
60             + "                                    \"vimId\":\"core-dc_RegionOne\""
61             + "                                }" + "                            }" + "                        ],"
62             + "                        \"resources\":[" + "                        ],"
63             + "                        \"requestInputs\":{" + "                            \"sdncontroller\":\"\""
64             + "                        }" + "                    }" + "                }," + "                {"
65             + "                    \"resourceName\":\"VL OVERLAYTUNNEL\","
66             + "                    \"resourceInvariantUuid\":\"184494cf-472f-436f-82e2-d83dddde21cb\","
67             + "                    \"resourceUuid\":\"95bc3e59-c9c5-458f-ad6e-78874ab4b3cc\","
68             + "                    \"resourceCustomizationUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed232\","
69             + "                    \"parameters\":{" + "                        \"locationConstraints\":["
70             + "                        ]," + "                        \"resources\":[" + "                        ],"
71             + "                        \"requestInputs\":{" + "                        }" + "                    }"
72             + "                }" + "            ]," + "            \"requestInputs\":{"
73             + "                \"vlunderlayvpn0_name\":\"l3connect\","
74             + "                \"vlunderlayvpn0_site1_id\":\"IP-WAN-Controller-1\","
75             + "                \"vlunderlayvpn0_site2_id\":\"SPTNController\","
76             + "                \"vlunderlayvpn0_site1_networkName\":\"network1,network2\","
77             + "                \"vlunderlayvpn0_site2_networkName\":\"network3,network4\","
78             + "                \"vlunderlayvpn0_site1_routerId\":\"a8098c1a-f86e-11da-bd1a-00112444be1a\","
79             + "                \"vlunderlayvpn0_site2_routerId\":\"a8098c1a-f86e-11da-bd1a-00112444be1e\","
80             + "                \"vlunderlayvpn0_site2_importRT1\":\"200:1,200:2\","
81             + "                \"vlunderlayvpn0_site1_exportRT1\":\"300:1,300:2\","
82             + "                \"vlunderlayvpn0_site2_exportRT1\":\"400:1,400:2\","
83             + "                \"vlunderlayvpn0_site1_vni\":\"2000\","
84             + "                \"vlunderlayvpn0_site2_vni\":\"3000\","
85             + "                \"vlunderlayvpn0_tunnelType\":\"L3-DCI\","
86             + "                \"CallSource\":\"NOT-ExternalAPI\"," + "                \"sotnconnectivity\":\"\""
87             + "            }" + "        }" + "    }" + "}";
88
89
90     @Test
91     public void doProcessSiteLocation_isNeedProcessSite() {
92         String result = servicePluginFactory.doProcessSiteLocation(serviceDecomposition, uuiRequest);
93         Assert.assertEquals(result, uuiRequest);
94     }
95
96     @Test
97     public void doProcessSiteLocation_uuiObjectNull() {
98         String faultyJsonInput = "site_address,sotncondition_clientsignal";
99         String result = servicePluginFactory.doProcessSiteLocation(serviceDecomposition, faultyJsonInput);
100         Assert.assertEquals(result, faultyJsonInput);
101     }
102
103     @Test
104     public void doProcessSiteLocation_isSiteLocationLocal() {
105         String jsonWithOnlyNeededValues = "{\"site_address\":\"\",\"sotncondition_clientsignal\":\"\"}";
106         String result = servicePluginFactory.doProcessSiteLocation(serviceDecomposition, jsonWithOnlyNeededValues);
107         Assert.assertEquals(result, jsonWithOnlyNeededValues);
108     }
109
110
111     @Test
112     public void doTPResourcesAllocation_Success() {
113         doReturn(null).when(servicePluginFactory).getTPsfromAAI();
114         String result = servicePluginFactory.doTPResourcesAllocation(null, uuiRequest);
115         Assert.assertNotEquals(result, uuiRequest);
116     }
117
118     @Test
119     public void doTPResourcesAllocation_uuiObjectNull() {
120         String faultyJsonInput = "site_address,sotncondition_clientsignal";
121         String result = servicePluginFactory.doTPResourcesAllocation(null, faultyJsonInput);
122         Assert.assertEquals(result, faultyJsonInput);
123     }
124
125     @Test
126     public void doTPResourcesAllocation_isNeedAllocateCrossTPResources() {
127         // doReturn(null).when(servicePluginFactory).getTPsfromAAI();
128         String jsonWithOnlyNeededValues = "{\"site_address\":\"\",\"sotncondition_clientsignal\":\"\"}";
129         String result = servicePluginFactory.doTPResourcesAllocation(null, jsonWithOnlyNeededValues);
130         Assert.assertEquals(result, jsonWithOnlyNeededValues);
131     }
132
133     @Test
134     public void preProcessService_isSOTN() {
135         String invalidJsonWithOnlyNeededValues = "\"clientSignal\":\"\",\"vpnType\":\"\"}";
136         String result = servicePluginFactory.preProcessService(null, invalidJsonWithOnlyNeededValues);
137         Assert.assertEquals(result, invalidJsonWithOnlyNeededValues);
138     }
139
140     @Test
141     public void preProcessService() {
142         String result = servicePluginFactory.preProcessService(null, uuiRequest);
143         Assert.assertEquals(result, uuiRequest);
144     }
145
146     @Test
147     public void doServiceHoming() {
148         String result = servicePluginFactory.doServiceHoming(null, uuiRequest);
149         Assert.assertEquals(result, uuiRequest);
150     }
151
152     @Test
153     public void doServiceHoming_isSOTN() {
154         String invalidJsonWithOnlyNeededValues = "\"clientSignal\":\"\",\"vpnType\":\"\"}";
155         String result = servicePluginFactory.doServiceHoming(null, invalidJsonWithOnlyNeededValues);
156         Assert.assertEquals(result, invalidJsonWithOnlyNeededValues);
157     }
158
159     @Test
160     public void verifyExternalConfigurationLoading() throws IllegalAccessException {
161
162         ServicePluginFactory servicePluginFactory = ServicePluginFactory.getInstance();
163
164         String oofDefaultEndpoint = (String) FieldUtils.readField(servicePluginFactory, "OOF_DEFAULT_ENDPOINT", true);
165         Assert.assertNotNull(oofDefaultEndpoint);
166
167         String thirdSpDefaultEndpoint =
168                 (String) FieldUtils.readField(servicePluginFactory, "THIRD_SP_DEFAULT_ENDPOINT", true);
169         Assert.assertNotNull(thirdSpDefaultEndpoint);
170
171         String inventoryOssDefaultEndpoint =
172                 (String) FieldUtils.readField(servicePluginFactory, "INVENTORY_OSS_DEFAULT_ENDPOINT", true);
173         Assert.assertNotNull(inventoryOssDefaultEndpoint);
174     }
175 }