defec3e70ad6861a21c3f958b4af70c582dbd3db
[usecase-ui/server.git] /
1 /**
2  * Copyright (C) 2020 Huawei, Inc. and others. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.usecaseui.server.service.lcm.impl;
17
18 import okhttp3.ResponseBody;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.onap.usecaseui.server.bean.lcm.sotne2eservice.E2EServiceInstanceRequest;
22 import org.onap.usecaseui.server.bean.lcm.sotne2eservice.ModelConfig;
23 import org.onap.usecaseui.server.service.lcm.SotnServiceTemplateService;
24 import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
25 import org.onap.usecaseui.server.service.lcm.domain.so.SOService;
26 import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
27 import org.onap.usecaseui.server.service.sotn.impl.SOTNServiceImpl;
28
29 import java.util.HashMap;
30
31 import static org.mockito.Matchers.anyObject;
32 import static org.mockito.Matchers.eq;
33 import static org.mockito.Mockito.mock;
34 import static org.mockito.Mockito.when;
35 import static org.onap.usecaseui.server.util.CallStub.failedCall;
36 import static org.onap.usecaseui.server.util.CallStub.successfulCall;
37
38 public class SotnServiceTemplateServiceImplTest {
39
40     AAIService aaiService;
41     SOService soService;
42     ServiceOperation serviceOperation;
43     SotnServiceTemplateServiceImpl sotnServiceTemplateService;
44     @Before
45     public void before() throws Exception {
46         aaiService = mock(AAIService.class);
47         soService = mock(SOService.class);
48         sotnServiceTemplateService = new SotnServiceTemplateServiceImpl();
49     }
50
51     @Test
52     public void instantiate_CCVPN_ServiceTest() {
53         when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
54         sotnServiceTemplateService.instantiate_CCVPN_Service(new HashMap<String, Object>());
55     }
56
57     @Test
58     public void instantiate_CCVPN_ServiceWithThrowException() {
59         when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(failedCall("failed to create Service"));
60         sotnServiceTemplateService.instantiate_CCVPN_Service(new HashMap<String, Object>());
61     }
62
63     @Test
64     public void createSotnServiceTest() {
65         when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
66         sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
67     }
68
69     @Test
70     public void createSotnServiceWithThrowException() {
71         when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(failedCall("failed to create Service"));
72         sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
73     }
74
75     @Test
76     public void getServiceInstancesInfoTest() throws Exception {
77         ResponseBody result=null;
78         when(aaiService.getServiceInstancesForEdge("ISAAC","SOTN","ISAAC")).thenReturn(successfulCall(result));
79         sotnServiceTemplateService.getServiceInstancesInfo("ISAAC","SOTN","ISAAC");
80     }
81
82     @Test
83     public void getServiceInstancesInfoWithThrowException() throws Exception {
84         when(aaiService.getServiceInstancesForEdge("ISAAC","SOTN","ISAAC")).thenReturn(failedCall("Failed to get Service Instance"));
85         sotnServiceTemplateService.getServiceInstancesInfo("ISAAC","SOTN","ISAAC");
86     }
87
88     @Test
89     public void getTerminationPointTest() throws Exception {
90         ResponseBody result = null;
91         when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(successfulCall(result));
92         sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
93     }
94
95     @Test
96     public void getTerminationPointWithThrowException() throws Exception {
97         when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(failedCall("Failed to get connectivity information."));
98         sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
99     }
100
101     @Test
102     public void getSOTNPinterfaceByVpnIdTest() throws Exception {
103         ResponseBody result = null;
104         when(aaiService.getPinterfaceByVpnId("1")).thenReturn(successfulCall(result));
105         sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
106     }
107
108     @Test
109     public void getSOTNPinterfaceByVpnIdWithThrowException() throws Exception {
110         when(aaiService.getPinterfaceByVpnId("1")).thenReturn(failedCall("failed to get VPN ID"));
111         sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
112     }
113
114     @Test
115     public void getSOTNPnfTest() throws Exception {
116         ResponseBody result = null;
117         when(aaiService.getPnfInfo("test")).thenReturn(successfulCall(result));
118         sotnServiceTemplateService.getSOTNPnf("test");
119     }
120
121     @Test
122     public void getSOTNPnfWithThrowException() throws Exception {
123         when(aaiService.getPnfInfo("test")).thenReturn(failedCall("Failed to get PNF info."));
124         sotnServiceTemplateService.getSOTNPnf("test");
125     }
126
127     @Test
128     public void getSOTNLinkbyNameTest() throws Exception {
129         ResponseBody result = null;
130         when(aaiService.getSpecificLogicalLink("link")).thenReturn(successfulCall(result));
131         sotnServiceTemplateService.getSOTNLinkbyName("link");
132     }
133
134     @Test
135     public void getSOTNLinkbyNameWithThrowException() throws Exception {
136         when(aaiService.getSpecificLogicalLink("link")).thenReturn(failedCall("Failed to get link info."));
137         sotnServiceTemplateService.getSOTNLinkbyName("link");
138     }
139 }