2 * Copyright (C) 2020 Huawei, Inc. and others. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.usecaseui.server.service.lcm.impl;
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;
29 import java.util.HashMap;
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;
38 public class SotnServiceTemplateServiceImplTest {
40 AAIService aaiService;
42 ServiceOperation serviceOperation;
43 SotnServiceTemplateServiceImpl sotnServiceTemplateService;
45 public void before() throws Exception {
46 aaiService = mock(AAIService.class);
47 soService = mock(SOService.class);
48 sotnServiceTemplateService = new SotnServiceTemplateServiceImpl();
52 public void instantiate_CCVPN_ServiceTest() {
53 when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
54 sotnServiceTemplateService.instantiate_CCVPN_Service(new HashMap<String, Object>());
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>());
64 public void createSotnServiceTest() {
65 when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
66 sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
70 public void createSotnServiceWithThrowException() {
71 when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(failedCall("failed to create Service"));
72 sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
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");
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");
89 public void getTerminationPointTest() throws Exception {
90 ResponseBody result = null;
91 when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(successfulCall(result));
92 sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
96 public void getTerminationPointWithThrowException() throws Exception {
97 when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(failedCall("Failed to get connectivity information."));
98 sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
102 public void getSOTNPinterfaceByVpnIdTest() throws Exception {
103 ResponseBody result = null;
104 when(aaiService.getPinterfaceByVpnId("1")).thenReturn(successfulCall(result));
105 sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
109 public void getSOTNPinterfaceByVpnIdWithThrowException() throws Exception {
110 when(aaiService.getPinterfaceByVpnId("1")).thenReturn(failedCall("failed to get VPN ID"));
111 sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
115 public void getSOTNPnfTest() throws Exception {
116 ResponseBody result = null;
117 when(aaiService.getPnfInfo("test")).thenReturn(successfulCall(result));
118 sotnServiceTemplateService.getSOTNPnf("test");
122 public void getSOTNPnfWithThrowException() throws Exception {
123 when(aaiService.getPnfInfo("test")).thenReturn(failedCall("Failed to get PNF info."));
124 sotnServiceTemplateService.getSOTNPnf("test");
128 public void getSOTNLinkbyNameTest() throws Exception {
129 ResponseBody result = null;
130 when(aaiService.getSpecificLogicalLink("link")).thenReturn(successfulCall(result));
131 sotnServiceTemplateService.getSOTNLinkbyName("link");
135 public void getSOTNLinkbyNameWithThrowException() throws Exception {
136 when(aaiService.getSpecificLogicalLink("link")).thenReturn(failedCall("Failed to get link info."));
137 sotnServiceTemplateService.getSOTNLinkbyName("link");