aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsuzhenyu <zysuh@isoftstone.com>2021-01-27 10:14:18 +0800
committerzhenyu su <zysuh@isoftstone.com>2021-01-27 07:40:16 +0000
commitc230c97ae764ab6c3bc98bec1478be638f4a8731 (patch)
tree1caaab63a7ea25603c7370adf1bb5dd19937c245
parent918f8c34dc4f332abd240afedb89f4a2e62a5b48 (diff)
Add some test code to improve code coverage3.0.8
Issue-ID: USECASEUI-532 Change-Id: Id41bd3c6a89b4d007b57acdbd02e833969129dd3 Signed-off-by: suzhenyu <zysuh@isoftstone.com>
-rw-r--r--server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImpl.java8
-rw-r--r--server/src/main/resources/modelconfig.json1
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java1
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java13
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImplTest.java645
5 files changed, 604 insertions, 64 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImpl.java
index 780dc1ab..4d3573a6 100644
--- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImpl.java
+++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImpl.java
@@ -59,14 +59,17 @@ import java.util.stream.Collectors;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;
+import lombok.Setter;
+
@Service("SotnLcmService")
@org.springframework.context.annotation.Configuration
@EnableAspectJAutoProxy
+@Setter
public class SotnServiceTemplateServiceImpl implements SotnServiceTemplateService {
private static final Logger logger = LoggerFactory.getLogger(SotnServiceTemplateServiceImpl.class);
-
+
private SOService soService;
private AAIService aaiService;
@@ -143,7 +146,7 @@ public class SotnServiceTemplateServiceImpl implements SotnServiceTemplateServic
Operation result = new Operation();
try {
logger.info("SO instantiate SOTN service is starting");
- Response<ServiceOperation> sotnserviceresponse = soService.instantiateSOTNService(requestBody).execute();
+ Response<ServiceOperation> sotnserviceresponse = soService.instantiateSOTNService(requestBody).execute();
logger.info("SO instantiate SOTN service has finished");
if (sotnserviceresponse.isSuccessful()) {
logger.info("SO instantiate SOTN service is successful");
@@ -224,7 +227,6 @@ public class SotnServiceTemplateServiceImpl implements SotnServiceTemplateServic
public ServiceInstance getServiceInstancesInfo(String customerId, String serviceType, String serviceInstanceId) throws Exception {
logger.info("Fire getServiceInstances : Begin");
ObjectMapper mapper = new ObjectMapper();
-
Response<ResponseBody> response = this.aaiService.getServiceInstancesForEdge(customerId, serviceType, serviceInstanceId).execute();
if (response.isSuccessful()) {
logger.info("Fire getServiceInstances : End");
diff --git a/server/src/main/resources/modelconfig.json b/server/src/main/resources/modelconfig.json
index 9e305998..6325d00f 100644
--- a/server/src/main/resources/modelconfig.json
+++ b/server/src/main/resources/modelconfig.json
@@ -2,6 +2,7 @@
"subscriberId":"SOTN-CUST",
"subscriptionType":"SOTN",
"status":1,
+ "deleteSleepTime":"1000",
"modelInformation":[
{
"modelType":"sotnservice",
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java
index 8bdd2539..7c6b101d 100644
--- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java
@@ -107,7 +107,6 @@ public class DefaultCustomerServiceTest {
@Test
public void itWillRetrieveEmptyListWhenNoServiceSubscriptionsInAAI() {
- DefaultCustomerService dc = new DefaultCustomerService();
AAIService aaiService = mock(AAIService.class);
Call<ServiceSubscriptionRsp> call = emptyBodyCall();
when(aaiService.listServiceSubscriptions("1")).thenReturn(call);
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java
index 8d2d3593..be14665c 100644
--- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java
@@ -15,6 +15,8 @@
*/
package org.onap.usecaseui.server.service.lcm.impl;
+import mockit.Mock;
+import mockit.MockUp;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
@@ -22,9 +24,7 @@ import org.hibernate.Transaction;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.bean.ServiceBean;
-import org.onap.usecaseui.server.service.impl.AlarmsHeaderServiceImpl;
import org.onap.usecaseui.server.service.lcm.ServiceLcmService;
import org.onap.usecaseui.server.service.lcm.domain.so.SOService;
import org.onap.usecaseui.server.service.lcm.domain.so.bean.DeleteOperationRsp;
@@ -34,9 +34,6 @@ import org.onap.usecaseui.server.service.lcm.domain.so.bean.SaveOrUpdateOperatio
import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
import org.onap.usecaseui.server.service.lcm.domain.so.exceptions.SOException;
-import mockit.Mock;
-import mockit.MockUp;
-
import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
@@ -102,8 +99,8 @@ public class DefaultServiceLcmServiceTest {
return mockUpQuery.getMockInstance();
}
@Mock
- public List<AlarmsHeader> list() {
- AlarmsHeader ah = new AlarmsHeader();
+ public List<ServiceBean> list() {
+ ServiceBean ah = new ServiceBean();
return Arrays.asList(ah);
}
@Mock
@@ -141,7 +138,7 @@ public class DefaultServiceLcmServiceTest {
return mockedSession.getMockInstance();
}
};
- new MockUp<AlarmsHeaderServiceImpl>() {
+ new MockUp<DefaultServiceLcmService>() {
@Mock
private Session getSession() {
return mockedSession.getMockInstance();
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImplTest.java
index ffc63d70..9bbadd22 100644
--- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImplTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SotnServiceTemplateServiceImplTest.java
@@ -15,27 +15,40 @@
*/
package org.onap.usecaseui.server.service.lcm.impl;
+import okhttp3.MediaType;
+import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
+import okio.Buffer;
+import okio.BufferedSource;
+import okio.ByteString;
+import okio.Options;
+import okio.Sink;
+import okio.Timeout;
import org.junit.Before;
import org.junit.Test;
import org.onap.usecaseui.server.bean.lcm.sotne2eservice.E2EServiceInstanceRequest;
import org.onap.usecaseui.server.bean.lcm.sotne2eservice.ModelConfig;
-import org.onap.usecaseui.server.service.lcm.SotnServiceTemplateService;
import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
import org.onap.usecaseui.server.service.lcm.domain.so.SOService;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.DeleteOperationRsp;
import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
-import org.onap.usecaseui.server.service.sotn.impl.SOTNServiceImpl;
+import retrofit2.Call;
+import retrofit2.Callback;
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
import java.util.HashMap;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.usecaseui.server.util.CallStub.failedCall;
-import static org.onap.usecaseui.server.util.CallStub.successfulCall;
public class SotnServiceTemplateServiceImplTest {
@@ -43,123 +56,149 @@ public class SotnServiceTemplateServiceImplTest {
SOService soService;
ServiceOperation serviceOperation;
SotnServiceTemplateServiceImpl sotnServiceTemplateService;
+
@Before
public void before() throws Exception {
aaiService = mock(AAIService.class);
soService = mock(SOService.class);
sotnServiceTemplateService = new SotnServiceTemplateServiceImpl();
+ sotnServiceTemplateService.setSoService(soService);
+ sotnServiceTemplateService.setAaiService(aaiService);
}
@Test
public void instantiate_CCVPN_ServiceTest() {
- when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
- sotnServiceTemplateService.instantiate_CCVPN_Service(new HashMap<String, Object>());
+
+ HashMap<String, Object> map = new HashMap<>();
+ map.put("name","12");
+ map.put("description","23");
+ map.put("l2vpn","34");
+ map.put("sotnUni","45");
+ Call<ServiceOperation> call = getSosCall();
+ when(soService.instantiateSOTNService(any(E2EServiceInstanceRequest.class))).thenReturn(call);
+ sotnServiceTemplateService.instantiate_CCVPN_Service(map);
}
@Test
public void instantiate_CCVPN_ServiceWithThrowException() {
- when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(failedCall("failed to create Service"));
- sotnServiceTemplateService.instantiate_CCVPN_Service(new HashMap<String, Object>());
+ HashMap<String, Object> map = new HashMap<>();
+ map.put("name","12");
+ map.put("description","23");
+ map.put("l2vpn","34");
+ map.put("sotnUni","45");
+ Call<ServiceOperation> call = getSosCall();
+ when(soService.instantiateSOTNService(any(E2EServiceInstanceRequest.class))).thenReturn(call);
+ sotnServiceTemplateService.instantiate_CCVPN_Service(map);
}
@Test
public void createSotnServiceTest() {
- when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(successfulCall(serviceOperation));
+ Call<ServiceOperation> call = getSosCall();
+ when(soService.instantiateSOTNService(any(E2EServiceInstanceRequest.class))).thenReturn(call);
sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
}
@Test
public void createSotnServiceWithThrowException() {
- when(soService.instantiateSOTNService(new E2EServiceInstanceRequest())).thenReturn(failedCall("failed to create Service"));
+ Call<ServiceOperation> call = getSosCall();
+ when(soService.instantiateSOTNService(any(E2EServiceInstanceRequest.class))).thenReturn(call);
sotnServiceTemplateService.createSotnService(new E2EServiceInstanceRequest());
}
@Test
public void getServiceInstancesInfoTest() throws Exception {
- ResponseBody result=null;
- when(aaiService.getServiceInstancesForEdge("ISAAC","SOTN","ISAAC")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("ServiceInstance");
+ when(aaiService.getServiceInstancesForEdge("ISAAC","SOTN","ISAAC")).thenReturn(call);
sotnServiceTemplateService.getServiceInstancesInfo("ISAAC","SOTN","ISAAC");
}
@Test
public void getServiceInstancesInfoWithThrowException() throws Exception {
- when(aaiService.getServiceInstancesForEdge("ISAAC","SOTN","ISAAC")).thenReturn(failedCall("Failed to get Service Instance"));
+ Call<ResponseBody> call = getAaiCall("ServiceInstance");
+ when(aaiService.getServiceInstancesForEdge("ISAAC","SOTN","ISAAC")).thenReturn(call);
sotnServiceTemplateService.getServiceInstancesInfo("ISAAC","SOTN","ISAAC");
}
@Test
public void getTerminationPointTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("Pinterface");
+ when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(call);
sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
}
@Test
public void getTerminationPointWithThrowException() throws Exception {
- when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(failedCall("Failed to get connectivity information."));
+ Call<ResponseBody> call = getAaiCall("Pinterface");
+ when(aaiService.getTerminationPoint("SOTN","123")).thenReturn(call);
sotnServiceTemplateService.getTerminationPoint("SOTN", "123");
}
@Test
public void getSOTNPinterfaceByVpnIdTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getPinterfaceByVpnId("1")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("VpnBinding");
+
+ when(aaiService.getPinterfaceByVpnId("1")).thenReturn(call);
sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
}
@Test
public void getSOTNPinterfaceByVpnIdWithThrowException() throws Exception {
- when(aaiService.getPinterfaceByVpnId("1")).thenReturn(failedCall("failed to get VPN ID"));
+ Call<ResponseBody> call = getAaiCall("VpnBinding");
+ when(aaiService.getPinterfaceByVpnId("1")).thenReturn(call);
sotnServiceTemplateService.getSOTNPinterfaceByVpnId("1");
}
@Test
public void getSOTNPnfTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getPnfInfo("test")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("Pnf");
+ when(aaiService.getPnfInfo("test")).thenReturn(call);
sotnServiceTemplateService.getSOTNPnf("test");
}
@Test
public void getSOTNPnfWithThrowException() throws Exception {
- when(aaiService.getPnfInfo("test")).thenReturn(failedCall("Failed to get PNF info."));
+ Call<ResponseBody> call = getAaiCall("Pnf");
+ when(aaiService.getPnfInfo("test")).thenReturn(call);
sotnServiceTemplateService.getSOTNPnf("test");
}
@Test
public void getSOTNLinkbyNameTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getSpecificLogicalLink("link")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("LogicalLink");
+ when(aaiService.getSpecificLogicalLink("link")).thenReturn(call);
sotnServiceTemplateService.getSOTNLinkbyName("link");
}
@Test
public void getSOTNLinkbyNameWithThrowException() throws Exception {
- when(aaiService.getSpecificLogicalLink("link")).thenReturn(failedCall("Failed to get link info."));
+ Call<ResponseBody> call = getAaiCall("LogicalLink");
+ when(aaiService.getSpecificLogicalLink("link")).thenReturn(call);
sotnServiceTemplateService.getSOTNLinkbyName("link");
}
@Test
public void getUNIInfoTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getUNIInfo("uni-id")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("Uni");
+ when(aaiService.getUNIInfo("uni-id")).thenReturn(call);
sotnServiceTemplateService.getUNIInfo("uni-id");
}
@Test
public void getUNIInfoWithThrowException() throws Exception {
- when(aaiService.getUNIInfo("uni-id")).thenReturn(failedCall("Failed to get link info."));
+ Call<ResponseBody> call = getAaiCall("Uni");
+ when(aaiService.getUNIInfo("uni-id")).thenReturn(call);
sotnServiceTemplateService.getUNIInfo("uni-id");
}
@Test
public void getVnfsTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getVNFsDetail("vnf-id")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("Vnfs");
+ when(aaiService.getVNFsDetail("vnf-id")).thenReturn(call);
sotnServiceTemplateService.getVnfs("vnf-id");
}
@Test
public void getVnfsWithThrowException() throws Exception {
- when(aaiService.getVNFsDetail("vnf-id")).thenReturn(failedCall("Failed to get link info."));
+ Call<ResponseBody> call = getAaiCall("Vnfs");
+ when(aaiService.getVNFsDetail("vnf-id")).thenReturn(call);
sotnServiceTemplateService.getVnfs("vnf-id");
}
@Test
@@ -172,31 +211,59 @@ public class SotnServiceTemplateServiceImplTest {
ModelConfig mdl = new ModelConfig();
sotnServiceTemplateService.readFile();
}
+
+ // TODO: 2021/1/22
@Test
public void getSOTNSiteInformationTopologyTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("ServiceInstance");
+ Call<ResponseBody> call1 = getAaiCall("AllottedResource");
+ Call<ResponseBody> call2 = getAaiCall("SiteResource");
+ Call<ResponseBody> call3 = getAaiCall("Connectivity");
+ Call<ResponseBody> call4 = getAaiCall("ComplexObj");
+ Call<ResponseBody> call5 = getAaiCall("Pinterface");
+ when(aaiService.getServiceInstancesForEdge(anyString(),anyString(),anyString())).thenReturn(call);
+ when(aaiService.getSiteResourceInfo(anyString())).thenReturn(call2);
+ when(aaiService.getConnectivityInformation(anyString())).thenReturn(call3);
+ when(aaiService.getAllotedResourceFor5G(anyString(),anyString(),anyString(),anyString())).thenReturn(call1);
+ when(aaiService.getComplexObject(anyString())).thenReturn(call4);
+ when(aaiService.getTerminationPoint(anyString(),anyString())).thenReturn(call5);
sotnServiceTemplateService.getSOTNSiteInformationTopology("SOTN", "ISAAC");
}
@Test
public void getSOTNSiteInformationTopologyWithThrowException() throws Exception {
- when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(failedCall("Failed to get connectivity."));
+ Call<ResponseBody> call = getAaiCall("ServiceInstance");
+ Call<ResponseBody> call1 = getAaiCall("AllottedResource");
+ Call<ResponseBody> call2 = getAaiCall("SiteResource");
+ Call<ResponseBody> call3 = getAaiCall("Connectivity");
+ Call<ResponseBody> call4 = getAaiCall("ComplexObj");
+ Call<ResponseBody> call5 = getAaiCall("Pinterface");
+ when(aaiService.getServiceInstancesForEdge(anyString(),anyString(),anyString())).thenReturn(call);
+ when(aaiService.getSiteResourceInfo(anyString())).thenReturn(call2);
+ when(aaiService.getConnectivityInformation(anyString())).thenReturn(call3);
+ when(aaiService.getAllotedResourceFor5G(anyString(),anyString(),anyString(),anyString())).thenReturn(call1);
+ when(aaiService.getComplexObject(anyString())).thenReturn(call4);
+ when(aaiService.getTerminationPoint(anyString(),anyString())).thenReturn(call5);
sotnServiceTemplateService.getSOTNSiteInformationTopology("SOTN", "ISAAC");
}
@Test
public void getServiceTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(successfulCall(result));
- ResponseBody result1 = null;
- when(aaiService.getConnectivityInformation("1")).thenReturn(successfulCall(result1));
- ResponseBody result2 = null;
- when(aaiService.getAllotedResourceFor5G("1", "SONT", "ISAAC", "2")).thenReturn(successfulCall(result2));
+ Call<ResponseBody> call = getAaiCall("ServiceInstance");
+ Call<ResponseBody> call1 = getAaiCall("AllottedResource");
+ Call<ResponseBody> call2 = getAaiCall("SiteResource");
+ Call<ResponseBody> call3 = getAaiCall("Connectivity");
+ Call<ResponseBody> call4 = getAaiCall("ComplexObj");
+ when(aaiService.getServiceInstancesForEdge(anyString(),anyString(),anyString())).thenReturn(call);
+ when(aaiService.getSiteResourceInfo(anyString())).thenReturn(call2);
+ when(aaiService.getConnectivityInformation(anyString())).thenReturn(call3);
+ when(aaiService.getAllotedResourceFor5G(anyString(),anyString(),anyString(),anyString())).thenReturn(call1);
+ when(aaiService.getComplexObject(anyString())).thenReturn(call4);
sotnServiceTemplateService.getService("SOTN", "ISAAC");
}
@Test
public void getServiceWithThrowException() throws Exception {
+ Call<ResponseBody> call = getAaiCall("ServiceInstance");
ResponseBody result = null;
- when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(failedCall("failed to get instances"));
+ when(aaiService.getServiceInstancesForEdge(anyString(),anyString(),anyString())).thenReturn(call);
ResponseBody result1 = null;
when(aaiService.getConnectivityInformation("1")).thenReturn(failedCall("Failed to get connectivity"));
ResponseBody result2 = null;
@@ -205,38 +272,72 @@ public class SotnServiceTemplateServiceImplTest {
}
@Test
public void getSOTNServiceInformationTopologyTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("ServiceInstance");
+ Call<ResponseBody> call1 = getAaiCall("Uni");
+ Call<ResponseBody> call2 = getAaiCall("Vnfs");
+ Call<ResponseBody> call3 = getAaiCall("Connectivity");
+ Call<ResponseBody> call4 = getAaiCall("Pinterface");
+ Call<ResponseBody> call5 = getAaiCall("VpnBinding");
+ when(aaiService.getServiceInstancesForEdge(anyString(),anyString(),anyString())).thenReturn(call);
+ when(aaiService.getUNIInfo(anyString())).thenReturn(call1);
+ when(aaiService.getVNFsDetail(anyString())).thenReturn(call2);
+ when(aaiService.getConnectivityInformation(anyString())).thenReturn(call3);
+ when(aaiService.getTerminationPoint(anyString(),anyString())).thenReturn(call4);
+ when(aaiService.getPinterfaceByVpnId(anyString())).thenReturn(call5);
sotnServiceTemplateService.getServiceInformationTopology("example-service-type-val-52265", "NNI-001");
}
@Test
public void getSOTNServiceInformationTopologyWithThrowException() throws Exception {
- when(aaiService.getServiceInstancesForEdge("1","SOTN","ISAAC")).thenReturn(failedCall("Failed to get connectivity."));
+ Call<ResponseBody> call = getAaiCall("ServiceInstance");
+ Call<ResponseBody> call1 = getAaiCall("Uni");
+ Call<ResponseBody> call2 = getAaiCall("Vnfs");
+ Call<ResponseBody> call3 = getAaiCall("Connectivity");
+ Call<ResponseBody> call4 = getAaiCall("Pinterface");
+ Call<ResponseBody> call5 = getAaiCall("VpnBinding");
+ when(aaiService.getServiceInstancesForEdge(anyString(),anyString(),anyString())).thenReturn(call);
+ when(aaiService.getUNIInfo(anyString())).thenReturn(call1);
+ when(aaiService.getVNFsDetail(anyString())).thenReturn(call2);
+ when(aaiService.getConnectivityInformation(anyString())).thenReturn(call3);
+ when(aaiService.getTerminationPoint(anyString(),anyString())).thenReturn(call4);
+ when(aaiService.getPinterfaceByVpnId(anyString())).thenReturn(call5);
sotnServiceTemplateService.getServiceInformationTopology("SOTN", "ISAAC");
}
+
+
@Test
public void getVPNBindingInformationTopologyTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(successfulCall(result));
+ Call<ResponseBody> call = getAaiCall("VpnBinding");
+ when(aaiService.getPinterfaceByVpnId(anyString())).thenReturn(call);
+ Call<ResponseBody> call1 = getAaiCall("Pinterface");
+ when(aaiService.getTerminationPoint(anyString(),anyString())).thenReturn(call1);
sotnServiceTemplateService.getVPNBindingInformationTopology("example-service-type-val-52265", "NNI-001", "vpn-bind-1");
}
@Test
public void getVPNBindingInformationTopologyWithThrowException() throws Exception {
- ResponseBody result = null;
- when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(failedCall("failed to get vpn binding topology."));
+ Call<ResponseBody> call = getAaiCall("VpnBinding");
+ when(aaiService.getPinterfaceByVpnId(anyString())).thenReturn(call);
+ Call<ResponseBody> call1 = getAaiCall("Pinterface");
+ when(aaiService.getTerminationPoint(anyString(),anyString())).thenReturn(call1);
sotnServiceTemplateService.getVPNBindingInformationTopology("example-service-type-val-52265", "NNI-001", "vpn-bind-1");
}
+
@Test
public void deleteServiceTest() throws Exception {
+ Call<ResponseBody> aaiCall = getAaiCall("ServiceInstance");
+ Call<DeleteOperationRsp> sosCall = getDeleteSosCall();
Response result = null;
RequestBody requestBody = null;
- when(soService.terminateService("serviceId",requestBody)).thenReturn(successfulCall(null));
+ when(aaiService.getServiceInstancesForEdge(anyString(),anyString(),anyString())).thenReturn(aaiCall);
+ when(soService.terminateService(anyString(),any(RequestBody.class))).thenReturn(sosCall);
sotnServiceTemplateService.deleteService("NNI-001", "vpn-bind-1");
}
@Test
public void deleteServiceWithThrowException() throws Exception {
+ Call<ResponseBody> aaiCall = getAaiCall("ServiceInstance");
+ Call<ServiceOperation> sosCall = getSosCall();
Response result = null;
RequestBody requestBody = null;
+ when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(aaiCall);
when(soService.terminateService("serviceId",requestBody)).thenReturn(failedCall("failed to delete the server."));
sotnServiceTemplateService.deleteService("NNI-001", "vpn-bind-1");
}
@@ -248,10 +349,21 @@ public class SotnServiceTemplateServiceImplTest {
public void getEdgeTest() throws Exception {
sotnServiceTemplateService.getEdge("fromid", "toId");
}
+
@Test
public void getSOTNResourceInformationTopologyTest() throws Exception {
- ResponseBody result = null;
- when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(successfulCall(result));
+ Call<ResponseBody> aaiCall = getAaiCall("ServiceInstance");
+ Call<ResponseBody> aaiCall1 = getAaiCall("Connectivity");
+ Call<ResponseBody> aaiCall2 = getAaiCall("Pnf");
+ Call<ResponseBody> aaiCall3 = getAaiCall("Pinterface");
+ Call<ResponseBody> aaiCall4 = getAaiCall("VpnBinding");
+ Call<ResponseBody> aaiCall5 = getAaiCall("LogicalLink");
+ when(aaiService.getServiceInstancesForEdge(anyString(),anyString(),anyString())).thenReturn(aaiCall);
+ when(aaiService.getConnectivityInformation( anyString())).thenReturn(aaiCall1);
+ when(aaiService.getPnfInfo(anyString())).thenReturn(aaiCall2);
+ when(aaiService.getTerminationPoint(anyString(),anyString())).thenReturn(aaiCall3);
+ when(aaiService.getPinterfaceByVpnId(anyString())).thenReturn(aaiCall4);
+ when(aaiService.getSpecificLogicalLink(anyString())).thenReturn(aaiCall5);
sotnServiceTemplateService.getSOTNResourceInformationTopology("example-service-type-val-52265", "NNI-001");
}
@Test
@@ -260,5 +372,434 @@ public class SotnServiceTemplateServiceImplTest {
when(aaiService.getServiceInstancesForEdge("ISAAC", "example-service-type-val-52265", "NNI-001")).thenReturn(failedCall("failed to get sotn resource topology."));
sotnServiceTemplateService.getSOTNResourceInformationTopology("example-service-type-val-52265", "NNI-001");
}
+
+
+ private Call<ServiceOperation> getSosCall(){
+ Call<ServiceOperation> call = new Call<ServiceOperation>() {
+
+ @Override
+ public retrofit2.Response<ServiceOperation> execute() throws IOException {
+ ServiceOperation serviceOperation=new ServiceOperation();
+ return retrofit2.Response.success(serviceOperation);
+ }
+
+ @Override
+ public void enqueue(Callback<ServiceOperation> callback) {
+
+ }
+
+ @Override
+ public boolean isExecuted() {
+ return false;
+ }
+
+ @Override
+ public void cancel() {
+
+ }
+
+ @Override
+ public boolean isCanceled() {
+ return false;
+ }
+
+ @Override
+ public Call<ServiceOperation> clone() {
+ return null;
+ }
+
+ @Override
+ public Request request() {
+ return null;
+ }
+ };
+ return call;
+ }
+ private Call<DeleteOperationRsp> getDeleteSosCall(){
+ Call<DeleteOperationRsp> call = new Call<DeleteOperationRsp>() {
+ @Override
+ public retrofit2.Response<DeleteOperationRsp> execute() throws IOException {
+ DeleteOperationRsp deleteOperationRsp = new DeleteOperationRsp();
+ return retrofit2.Response.success(deleteOperationRsp);
+ }
+
+ @Override
+ public void enqueue(Callback<DeleteOperationRsp> callback) {
+
+ }
+
+ @Override
+ public boolean isExecuted() {
+ return false;
+ }
+
+ @Override
+ public void cancel() {
+
+ }
+
+ @Override
+ public boolean isCanceled() {
+ return false;
+ }
+
+ @Override
+ public Call<DeleteOperationRsp> clone() {
+ return null;
+ }
+
+ @Override
+ public Request request() {
+ return null;
+ }
+ };
+ return call;
+ }
+ private Call<ResponseBody> getAaiCall(String t){
+ Call<ResponseBody> call = new Call<ResponseBody>() {
+ @Override
+ public retrofit2.Response<ResponseBody> execute() throws IOException {
+ ResponseBody responseBody= new ResponseBody() {
+ @Nullable
+ @Override
+ public MediaType contentType() {
+ return null;
+ }
+
+ @Override
+ public long contentLength() {
+ long lenth = 0;
+ // TODO: 2021/1/21 长度
+ if(t.equals("ServiceInstance")){
+ lenth = 417;
+ }else if(t.equals("Connectivity")){
+ lenth = 163;
+ }else if(t.equals("Pinterface")){
+ lenth = 326;
+ }else if(t.equals("AllottedResource")){
+ lenth = 48;
+ }else if(t.equals("SiteResource")){
+ lenth = 154;
+ }else if(t.equals("ComplexObj")){
+ lenth = 111;
+ }else if(t.equals("VpnBinding")){
+ lenth = 254;
+ }else if(t.equals("Pnf")){
+ lenth = 46;
+ }else if(t.equals("LogicalLink")){
+ lenth = 281;
+ }else if(t.equals("Uni")){
+ lenth = 221;
+ }else if(t.equals("Vnfs")){
+ lenth = 190;
+ }
+ return lenth;
+ }
+
+ @Override
+ public BufferedSource source() {
+ BufferedSource bufferedSource = new BufferedSource() {
+ @Override
+ public long read(Buffer buffer, long l) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public Timeout timeout() {
+ return null;
+ }
+
+ @Override
+ public void close() throws IOException {
+
+ }
+
+ @Override
+ public boolean isOpen() {
+ return false;
+ }
+
+ @Override
+ public int read(ByteBuffer dst) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public Buffer buffer() {
+ return null;
+ }
+
+ @Override
+ public boolean exhausted() throws IOException {
+ return false;
+ }
+
+ @Override
+ public void require(long l) throws IOException {
+
+ }
+
+ @Override
+ public boolean request(long l) throws IOException {
+ return false;
+ }
+
+ @Override
+ public byte readByte() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public short readShort() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public short readShortLe() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public int readIntLe() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long readLongLe() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long readDecimalLong() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long readHexadecimalUnsignedLong() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public void skip(long l) throws IOException {
+
+ }
+
+ @Override
+ public ByteString readByteString() throws IOException {
+ return null;
+ }
+
+ @Override
+ public ByteString readByteString(long l) throws IOException {
+ return null;
+ }
+
+ @Override
+ public int select(Options options) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public byte[] readByteArray() throws IOException {
+ // TODO: 2021/1/21 字符串
+ String s = new String();
+ if(t.equals("ServiceInstance")){
+ s = "{\"service-instance-id\":\"234\",\"service-instance-name\":18,\"input-parameters\":\"as\",\"service-type\":1591851786568,\"relationship-list\":{\"relationship\":[{\"related-to\":\"service-instance\",\"related-link\":\"12/0\"},{\"related-to\":\"generic-vnf\",\"related-link\":\"12/0\"},{\"related-to\":\"allotted-resource\",\"related-link\":\"12/0\"},{\"related-to\":\"connectivity\",\"related-link\":\"12/0\"},{\"related-to\":\"site-resource\",\"related-link\":\"12/0\"}]}}";
+ }else if(t.equals("Connectivity")){
+ s = "{\"connectivity-id\":\"234\",\"bandwidth-profile-name\":18,\"cir\":1591851786568,\"relationship-list\":{\"relationship\":[{\"related-to\":\"vpn-binding\",\"related-link\":\"12/0\"}]}}";
+ }else if(t.equals("Pinterface")){
+ s = "{\"interface-name\":\"234\",\"speed-units\":18,\"port-description\":1591851786568," +
+ "\"speed-value\":\"234\",\"equipment-identifier\":18,\"resource-version\":1591851786568," +
+ "\"in-maint\":\"true\",\"network-ref\":\"23\",\"transparent\":\"34\",\"operational-status\":\"34\",\"relationship-list\":{\"relationship\":[{\"related-to\":\"logical-link\",\"related-link\":\"12/0\"}]}}";
+ }else if(t.equals("AllottedResource")){
+ s = "{\"id\":234,\"selflink\":18,\"model-invariant-id\":12}";
+ }else if(t.equals("SiteResource")){
+ s = "{\"site-resource-id\":\"234\",\"site-resource-name\":18,\"description\":12,\"relationship-list\":{\"relationship\":[{\"related-to\":\"complex\",\"related-link\":\"123/0\"}]}}";
+ }else if(t.equals("ComplexObj")){
+ s = "{\"physical-location-id\":\"234\",\"resource-version\":18,\"physical-location-type\":12,\"city\":\"sd\",\"postal-code\":\"ds\"}";
+ }else if(t.equals("VpnBinding")){
+ s = "{\"vpn-binding\":[{\"vpn-id\":23,\"src-access-node-id\":18,\"dst-access-node-id\":18,\"relationship-list\":{\"relationship\":[{\"related-to\":\"p-interface\",\"relationship-data\":[{\"relationship-key\":\"pnf.pnf-name\",\"relationship-value\":\"23\"}],\"related-link\":\"123/2\"}]}}]}";
+ }else if(t.equals("Pnf")){
+ s = "{\"pnf-name\":\"234\",\"pnf-id\":18,\"in-maint\":true}";
+ }else if(t.equals("LogicalLink")){
+ s = "{\"link-name\":\"234\",\"in-maint\":18,\"link-type\":true,\"relationship-list\":{\"relationship\":[{\"related-to\":\"p-interface\",\"relationship-data\":[{\"relationship-key\":\"pnf.pnf-name\",\"relationship-value\":\"26\"}],\"related-link\":\"123/0\"},{\"related-to\":\"ext-aai-network\",\"related-link\":\"123/0\"}]}}";;
+ }else if(t.equals("Uni")){
+ s = "{\"id\":\"234\",\"tpId\":18,\"resource-version\":true,\"relationship-list\":{\"relationship\":[{\"related-to\":\"p-interface\",\"relationship-data\":[{\"relationship-key\":\"pnf.pnf-name\",\"relationship-value\":\"26\"}],\"related-link\":\"123/0\"}]}}";
+ }else if(t.equals("Vnfs")){
+ s = "{\"vnf-id\":\"234\",\"in-maint\":18,\"resource-version\":true,\"relationship-list\":{\"relationship\":[{\"related-to\":\"connectivity\",\"related-link\":\"123/0\"},{\"related-to\":\"uni\",\"related-link\":\"123/0\"}]}}";
+ }
+ byte[] bytes = s.getBytes();
+ return bytes;
+ }
+
+ @Override
+ public byte[] readByteArray(long l) throws IOException {
+ return new byte[0];
+ }
+
+ @Override
+ public int read(byte[] bytes) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public void readFully(byte[] bytes) throws IOException {
+
+ }
+
+ @Override
+ public int read(byte[] bytes, int i, int i1) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public void readFully(Buffer buffer, long l) throws IOException {
+
+ }
+
+ @Override
+ public long readAll(Sink sink) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public String readUtf8() throws IOException {
+ return null;
+ }
+
+ @Override
+ public String readUtf8(long l) throws IOException {
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public String readUtf8Line() throws IOException {
+ return null;
+ }
+
+ @Override
+ public String readUtf8LineStrict() throws IOException {
+ return null;
+ }
+
+ @Override
+ public String readUtf8LineStrict(long l) throws IOException {
+ return null;
+ }
+
+ @Override
+ public int readUtf8CodePoint() throws IOException {
+ return 0;
+ }
+
+ @Override
+ public String readString(Charset charset) throws IOException {
+ return null;
+ }
+
+ @Override
+ public String readString(long l, Charset charset) throws IOException {
+ return null;
+ }
+
+ @Override
+ public long indexOf(byte b) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long indexOf(byte b, long l) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long indexOf(byte b, long l, long l1) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long indexOf(ByteString byteString) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long indexOf(ByteString byteString, long l) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long indexOfElement(ByteString byteString) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public long indexOfElement(ByteString byteString, long l) throws IOException {
+ return 0;
+ }
+
+ @Override
+ public boolean rangeEquals(long l, ByteString byteString) throws IOException {
+ return false;
+ }
+
+ @Override
+ public boolean rangeEquals(long l, ByteString byteString, int i, int i1) throws IOException {
+ return false;
+ }
+
+ @Override
+ public InputStream inputStream() {
+ return null;
+ }
+ };
+ return bufferedSource;
+ }
+ };
+ return retrofit2.Response.success(200,responseBody);
+ }
+
+ @Override
+ public void enqueue(Callback<ResponseBody> callback) {
+
+ }
+
+ @Override
+ public boolean isExecuted() {
+ return false;
+ }
+
+ @Override
+ public void cancel() {
+
+ }
+
+ @Override
+ public boolean isCanceled() {
+ return false;
+ }
+
+ @Override
+ public Call<ResponseBody> clone() {
+ return null;
+ }
+
+ @Override
+ public Request request() {
+ return null;
+ }
+ };
+ return call;
+ }
}