aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguochuyicmri <guochuyi@chinamobile.com>2018-12-04 15:02:00 +0800
committerguochuyicmri <guochuyi@chinamobile.com>2018-12-04 15:02:14 +0800
commit9fc416a859984ccfd320ddd6b3d5453c8b1d6ac2 (patch)
treef64dbc8b030fc6b4e9feb422d5703db3ae1e0fef
parentc3304b81fbdb6970ec5c149f58d2937e37d2a9f2 (diff)
add junit function for insert
Change-Id: Iea6cb6d49e635c552849236648101e8834e1f697 Issue-ID: USECASEUI-161 Signed-off-by: guochuyicmri <guochuyi@chinamobile.com>
-rwxr-xr-xserver/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java30
-rwxr-xr-xserver/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java17
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/controller/sotn/SotnControllerTest.java208
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java812
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SOTNServiceImplTest.java433
5 files changed, 1495 insertions, 5 deletions
diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java
index 3bce961d..44332c30 100755
--- a/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/controller/AlarmControllerTest.java
@@ -28,9 +28,11 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.usecaseui.server.bean.AlarmsHeader;
import org.onap.usecaseui.server.bean.AlarmsInformation;
+import org.onap.usecaseui.server.bo.AlarmBo;
import org.onap.usecaseui.server.service.AlarmsHeaderService;
import org.onap.usecaseui.server.service.AlarmsInformationService;
import org.onap.usecaseui.server.util.Page;
+import org.onap.usecaseui.server.wrapper.AlarmWrapper;
public class AlarmControllerTest {
@@ -103,4 +105,32 @@ public class AlarmControllerTest {
}
}
+ @Test
+ public void testAlarmWrapper(){
+ AlarmWrapper alarmWrapper = new AlarmWrapper();
+ AlarmsHeader alarmsHeader =new AlarmsHeader();
+ AlarmsInformation alarmsInformation = new AlarmsInformation();
+ int currentPage = 1;
+ int pageSize = 100;
+ alarmWrapper.setAlarmsHeader(alarmsHeader);
+ alarmWrapper.setAlarmsInformation(alarmsInformation);
+ alarmWrapper.setCurrentPage(currentPage);
+ alarmWrapper.setPageSize(pageSize);
+ alarmWrapper.getAlarmsHeader();
+ alarmWrapper.getAlarmsInformation();
+ alarmWrapper.getCurrentPage();
+ alarmWrapper.getPageSize();
+ }
+
+ @Test
+ public void testAlarmBo (){
+ AlarmsHeader alarmsHeader =new AlarmsHeader();
+ List<AlarmsInformation> alarmsInformation = new ArrayList<>();
+ AlarmBo alarmBo2 = new AlarmBo(alarmsHeader,alarmsInformation);
+ AlarmBo alarmBo = new AlarmBo();
+ alarmBo.setAlarmsHeader(alarmsHeader);
+ alarmBo.setAlarmsInformation(alarmsInformation);
+ alarmBo.getAlarmsHeader();
+ alarmBo.getAlarmsInformation();
+ }
}
diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java
index 1e4ec915..bccf73b1 100755
--- a/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/controller/PerformanceControllerTest.java
@@ -67,8 +67,21 @@ public class PerformanceControllerTest {
controller.getPerformanceData(currentPage+"",pageSize+"",null,null,null);
verify(phs,times(1)).queryPerformanceHeader(header,currentPage,pageSize);
-}
-
+ }
+
+ @Test
+ public void testGetPerformanceSourceNames() throws JsonProcessingException{
+ String currentPage="1";
+ String pageSize="10";
+ String sourceName="";
+ controller.getPerformanceSourceNames(currentPage, pageSize, sourceName);
+ }
+
+ @Test
+ public void testGetSourceIds(){
+ controller.getSourceIds();
+ }
+
@Test
public void testGetPerformanceHeaderDetail() {
try {
diff --git a/server/src/test/java/org/onap/usecaseui/server/controller/sotn/SotnControllerTest.java b/server/src/test/java/org/onap/usecaseui/server/controller/sotn/SotnControllerTest.java
new file mode 100644
index 00000000..326fa1b6
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/controller/sotn/SotnControllerTest.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.usecaseui.server.controller.sotn;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.util.ArrayList;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.usecaseui.server.bean.sotn.NetWorkResource;
+import org.onap.usecaseui.server.service.sotn.SOTNService;
+
+public class SotnControllerTest {
+
+ public SOTNService sotnService;
+
+ private SotnController sotnController = new SotnController();
+
+ @Before
+ public void setUp() {
+ sotnService = mock(SOTNService.class);
+ sotnController.setSotnService(sotnService);
+ }
+
+ @Test
+ public void TestGetNetWorkResources(){
+ sotnController.getNetWorkResources();
+ verify(sotnService, times(1)).getNetWorkResources();
+ }
+
+ @Test
+ public void TestGetPinterfaceByPnfName(){
+ String pnfName="pnfName";
+ sotnController.getPinterfaceByPnfName(pnfName);
+ verify(sotnService, times(1)).getPinterfaceByPnfName(pnfName);
+ }
+
+ @Test
+ public void TestGetLogicalLinks(){
+ sotnController.getLogicalLinks();
+ verify(sotnService, times(1)).getLogicalLinks();
+ }
+
+ @Test
+ public void TestGetSpecificLogicalLink(){
+ String linkName="pnfName";
+ sotnController.getSpecificLogicalLink(linkName);
+ verify(sotnService, times(1)).getSpecificLogicalLink(linkName);
+ }
+
+ @Test
+ public void TestGetHostUrl(){
+ String linkName="pnfName";
+ sotnController.getHostUrl(linkName);
+ verify(sotnService, times(1)).getHostUrl(linkName);
+ }
+
+ @Test
+ public void TestGetExtAaiId(){
+ String linkName="pnfName";
+ sotnController.getExtAaiId(linkName);
+ verify(sotnService, times(1)).getExtAaiId(linkName);
+ }
+
+ @Test
+ public void TestCreateHostUrl(){
+ String linkName="pnfName";
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ sotnController.createHostUrl(request,linkName);
+ verify(sotnService, times(1)).createHostUrl(request,linkName);
+ }
+
+ @Test
+ public void TestCreateTopoNetwork(){
+ String linkName="pnfName";
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ sotnController.createTopoNetwork(request,linkName);
+ verify(sotnService, times(1)).createTopoNetwork(request,linkName);
+ }
+
+ @Test
+ public void TestCreateTerminationPoint(){
+ String linkName="pnfName";
+ String tpid="tpid";
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ sotnController.createTerminationPoint(request,linkName,tpid);
+ verify(sotnService, times(1)).createTerminationPoint(request,linkName,tpid);
+ }
+
+ @Test
+ public void TestCreateLink(){
+ String linkName="pnfName";
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ sotnController.createLink(request,linkName);
+ verify(sotnService, times(1)).createLink(request,linkName);
+ }
+
+ @Test
+ public void TestCreatePnf(){
+ String linkName="pnfName";
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ sotnController.createPnf(request,linkName);
+ verify(sotnService, times(1)).createPnf(request,linkName);
+ }
+
+ @Test
+ public void TestDeleteLink(){
+ String linkName="pnfName";
+ String resourceVersion="resourceVersion";
+ sotnController.deleteLink(linkName,resourceVersion);
+ verify(sotnService, times(1)).deleteLink(linkName,resourceVersion);
+ }
+
+ @Test
+ public void TestGetServiceInstanceInfo(){
+ String linkName="pnfName";
+ String resourceVersion="resourceVersion";
+ String serviceType="serviceType";
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ sotnController.getServiceInstanceInfo(request);
+ verify(sotnService, times(1)).serviceInstanceInfo(linkName,resourceVersion,serviceType);
+ }
+
+ @Test
+ public void TestGetPnfInfo(){
+ String linkName="pnfName";
+ sotnController.getPnfInfo(linkName);
+ verify(sotnService, times(1)).getPnfInfo(linkName);
+ }
+
+ @Test
+ public void TestGetAllottedResources(){
+ String linkName="pnfName";
+ String resourceVersion="resourceVersion";
+ String serviceType="serviceType";
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ sotnController.getAllottedResources(request);
+ verify(sotnService, times(1)).getAllottedResources(linkName,resourceVersion,serviceType);
+ }
+
+ @Test
+ public void TestGetConnectivityInfo(){
+ String linkName="pnfName";
+ sotnController.getConnectivityInfo(linkName);
+ verify(sotnService, times(1)).getConnectivityInfo(linkName);
+ }
+
+ @Test
+ public void TestGetPinterfaceByVpnId(){
+ String linkName="pnfName";
+ sotnController.getPinterfaceByVpnId(linkName);
+ verify(sotnService, times(1)).getPinterfaceByVpnId(linkName);
+ }
+
+ @Test
+ public void TestGetServiceInstanceList(){
+ String linkName="pnfName";
+ String resourceVersion="resourceVersion";
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ sotnController.getServiceInstanceList(request);
+ verify(sotnService, times(1)).getServiceInstances(linkName,resourceVersion);
+ }
+
+ @Test
+ public void TestGetData(){
+ sotnController.getData();
+ }
+
+ @Test
+ public void TestDeleteExtNetwork(){
+ String linkName="pnfName";
+ String resourceVersion="resourceVersion";
+ sotnController.deleteExtNetwork(linkName,resourceVersion);
+ verify(sotnService, times(1)).deleteExtNetwork(linkName,resourceVersion);
+ }
+
+ @Test
+ public void testNetWorkResource(){
+ NetWorkResource netWorkResource = new NetWorkResource ();
+ netWorkResource = new NetWorkResource("networkId",new ArrayList(),new ArrayList(),"aaiId");
+ netWorkResource.getAaiId();
+ netWorkResource.getNetworkId();
+ netWorkResource.getPnfs();
+ netWorkResource.getTps();
+ netWorkResource.setAaiId("testaaai");
+ netWorkResource.setNetworkId("testnet");
+ netWorkResource.setPnfs(new ArrayList());
+ netWorkResource.setTps(new ArrayList());
+ }
+}
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java
index f003157a..2e378e64 100644
--- a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java
@@ -22,6 +22,7 @@ import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfo;
import org.onap.usecaseui.server.service.lcm.domain.aai.bean.VimInfoRsp;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.nsServiceRsp;
import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService;
import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.SDCServiceTemplate;
import org.onap.usecaseui.server.service.lcm.domain.sdc.bean.Vnf;
@@ -32,11 +33,19 @@ import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.DistributionResult
import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Job;
import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.JobStatus;
import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
+
+import okhttp3.ResponseBody;
import retrofit2.Call;
+import java.io.IOException;
import java.util.Collections;
import java.util.List;
+import javax.servlet.ReadListener;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+
+import static org.mockito.Matchers.anyObject;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,6 +55,35 @@ import static org.onap.usecaseui.server.util.CallStub.failedCall;
import static org.onap.usecaseui.server.util.CallStub.successfulCall;
public class DefaultPackageDistributionServiceTest {
+
+
+ private HttpServletRequest mockRequest() throws IOException {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getContentLength()).thenReturn(0);
+ ServletInputStream inStream = new ServletInputStream() {
+ @Override
+ public boolean isFinished() {
+ return false;
+ }
+
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public void setReadListener(ReadListener readListener) {
+
+ }
+
+ @Override
+ public int read() throws IOException {
+ return 0;
+ }
+ };
+ when(request.getInputStream()).thenReturn(inStream);
+ return request;
+ }
@Test
public void itCanRetrievePackageFromSDCAndAAI() {
@@ -208,6 +246,38 @@ public class DefaultPackageDistributionServiceTest {
}
@Test
+ public void itCanGetNsLcmJobStatusFromVFC() {
+ VfcService vfcService = mock(VfcService.class);
+ String jobId = "1";
+ String responseId = "1";
+ JobStatus jobStatus = new JobStatus();
+ when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(successfulCall(jobStatus));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(jobStatus, service.getNsLcmJobStatus(jobId, responseId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void getNsLcmJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
+ VfcService vfcService = mock(VfcService.class);
+ String jobId = "1";
+ String responseId = "1";
+ when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getNsLcmJobStatus(jobId, responseId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void getNsLcmJobStatusWillThrowExceptionWhenVFCResponseError() {
+ VfcService vfcService = mock(VfcService.class);
+ String jobId = "1";
+ String responseId = "1";
+ when(vfcService.getNsLcmJobStatus(jobId, responseId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getNsLcmJobStatus(jobId, responseId);
+ }
+
+ @Test
public void itCanDeleteNsPackage() {
String csarId = "1";
DistributionResult result = new DistributionResult();
@@ -235,7 +305,34 @@ public class DefaultPackageDistributionServiceTest {
PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
service.deleteNsPackage(csarId);
}
+
+ @Test
+ public void itCanGetVnfPackages(){
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfPackages()).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ Assert.assertSame(result, service.getVnfPackages());
+ }
+
+ @Test
+ public void getVnfPackagesThrowExceptionWhenVFCResponseError(){
+
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfPackages ()).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getVnfPackages();
+ }
+
+ @Test
+ public void getVnfPackagesThrowException(){
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfPackages ()).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getVnfPackages();
+ }
+
@Test
public void itCanDeleteVFPackage() {
String csarId = "1";
@@ -257,11 +354,720 @@ public class DefaultPackageDistributionServiceTest {
}
@Test(expected = VfcException.class)
- public void deleteVfPackageWillThrowExceptionWhenVFCResponseError() {
+ public void deleteVnfPackageWillThrowExceptionWhenVFCResponseError() {
String csarId = "1";
VfcService vfcService = mock(VfcService.class);
when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
- service.deleteVfPackage(csarId);
+ service.deleteVnfPackage(csarId);
+ }
+
+ @Test
+ public void itCanGetNetworkServicePackages() {
+ ResponseBody responseBody = null;
+ VfcService vfcService = mock(VfcService.class);
+ JobStatus jobStatus = new JobStatus();
+ when(vfcService.getNetworkServicePackages()).thenReturn(successfulCall(responseBody));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(jobStatus, service.getNetworkServicePackages());
+ }
+
+ @Test(expected = VfcException.class)
+ public void getNetworkServicePackagesWillThrowExceptionWhenVFCIsNotAvailable() {
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getNetworkServicePackages()).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getNetworkServicePackages();
+ }
+
+ @Test(expected = VfcException.class)
+ public void getNetworkServicePackagesWillThrowExceptionWhenVFCResponseError() {
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getNetworkServicePackages()).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getNetworkServicePackages();
+ }
+
+ @Test
+ public void itCanGetPnfPackages(){
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getPnfPackages()).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.getPnfPackages());
+ }
+
+ @Test
+ public void getPnfPackagesThrowExceptionWhenVFCResponseError(){
+
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getPnfPackages ()).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getPnfPackages();
+ }
+
+ @Test
+ public void getPnfPackagesThrowException(){
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getPnfPackages ()).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getPnfPackages();
+ }
+
+ @Test
+ public void itDownLoadNsPackage(){
+ String nsdInfoId="1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadNsPackage(nsdInfoId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.downLoadNsPackage(nsdInfoId));
+ }
+
+ @Test
+ public void downLoadNsPackagehrowExceptionWhenVFCResponseError(){
+ String nsdInfoId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.downLoadNsPackage(nsdInfoId);
+ }
+
+ @Test
+ public void downLoadNsPackageThrowException(){
+ String nsdInfoId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadNsPackage (nsdInfoId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.downLoadNsPackage(nsdInfoId);
+ }
+
+ @Test
+ public void itDownLoadPnfPackage(){
+ String pnfInfoId="1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadPnfPackage(pnfInfoId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.downLoadPnfPackage(pnfInfoId));
+ }
+
+ @Test
+ public void downLoadPnfPackagehrowExceptionWhenVFCResponseError(){
+ String pnfInfoId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.downLoadPnfPackage(pnfInfoId);
+ }
+
+ @Test
+ public void downLoadPnfPackageThrowException(){
+ String pnfInfoId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadPnfPackage (pnfInfoId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.downLoadPnfPackage(pnfInfoId);
+ }
+
+ @Test
+ public void itDownLoadVnfPackage(){
+ String vnfInfoId="1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadVnfPackage(vnfInfoId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.downLoadVnfPackage(vnfInfoId));
+ }
+
+ @Test
+ public void downLoadVnfPackagehrowExceptionWhenVFCResponseError(){
+ String vnfInfoId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.downLoadVnfPackage(vnfInfoId);
+ }
+
+ @Test
+ public void downLoadVnfPackageThrowException(){
+ String vnfInfoId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.downLoadVnfPackage (vnfInfoId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.downLoadVnfPackage(vnfInfoId);
+ }
+
+ @Test
+ public void itCanDeleteNsdPackage() {
+ String csarId = "1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteNsdPackage(csarId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.deleteNsdPackage(csarId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void deleteNsdPackageWillThrowExceptionWhenVFCIsNotAvailable() {
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteNsdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.deleteNsdPackage(csarId);
}
-} \ No newline at end of file
+
+ @Test(expected = VfcException.class)
+ public void deleteNsdPackageWillThrowExceptionWhenVFCResponseError() {
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteNsdPackage(csarId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.deleteNsdPackage(csarId);
+ }
+
+ @Test
+ public void itCanDeleteVnfPackage() {
+ String csarId = "1";
+ ResponseBody result=null;
+ Job job = new Job();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteVnfPackage(csarId)).thenReturn(successfulCall(job));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(job, service.deleteVnfPackage(csarId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void deleteVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteVnfPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.deleteVnfPackage(csarId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void deleteVnfNsdPackageWillThrowExceptionWhenVFCResponseError() {
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteVnfPackage(csarId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.deleteVnfPackage(csarId);
+ }
+
+ @Test
+ public void itCanDeletePnfdPackage() {
+ String csarId = "1";
+ ResponseBody result=null;
+ Job job = new Job();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deletePnfdPackage(csarId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.deletePnfPackage(csarId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void deletePnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deletePnfdPackage(csarId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.deletePnfPackage(csarId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void deletePnfPackageWillThrowExceptionWhenVFCResponseError() {
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deletePnfdPackage(csarId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.deletePnfPackage(csarId);
+ }
+
+ @Test
+ public void itCanDeleteNetworkServiceInstance() {
+ String csarId = "1";
+ ResponseBody result=null;
+ Job job = new Job();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.deleteNetworkServiceInstance(csarId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() {
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.deleteNetworkServiceInstance(csarId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void deleteNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() {
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.deleteNetworkServiceInstance(csarId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.deleteNetworkServiceInstance(csarId);
+ }
+
+ @Test
+ public void itCanCreateNetworkServiceInstance() throws IOException {
+ HttpServletRequest request = mockRequest();
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.createNetworkServiceInstance(request));
+ }
+
+ @Test(expected = VfcException.class)
+ public void createNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.createNetworkServiceInstance(request);
+ }
+
+ @Test(expected = VfcException.class)
+ public void createNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createNetworkServiceInstance(anyObject())).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.createNetworkServiceInstance(request);
+ }
+
+ @Test
+ public void itCanGetNetworkServiceInfo() throws IOException {
+ ResponseBody result=null;
+ nsServiceRsp ns = new nsServiceRsp();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getNetworkServiceInfo()).thenReturn(successfulCall(ns));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.getNetworkServiceInfo());
+ }
+
+ @Test(expected = VfcException.class)
+ public void getNetworkServiceInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getNetworkServiceInfo()).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getNetworkServiceInfo();
+ }
+
+ @Test(expected = VfcException.class)
+ public void getNetworkServiceInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getNetworkServiceInfo()).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getNetworkServiceInfo();
+ }
+
+
+
+ @Test
+ public void itCanHealNetworkServiceInstance() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ //when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ //Assert.assertSame(result, service.healNetworkServiceInstance(request,csarId));
+ service.healNetworkServiceInstance(request,csarId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void healNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.healNetworkServiceInstance(request,csarId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void healNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.healNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.healNetworkServiceInstance(request,csarId);
+ }
+
+ @Test
+ public void itCanScaleNetworkServiceInstance() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ //when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.scaleNetworkServiceInstance(request,csarId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.scaleNetworkServiceInstance(request,csarId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void scaleNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.scaleNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.scaleNetworkServiceInstance(request,csarId);
+ }
+
+
+ @Test
+ public void itCaninstantiateNetworkServiceInstance() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String serviceInstanceId="1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ //when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ service.instantiateNetworkServiceInstance(request,serviceInstanceId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String serviceInstanceId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.instantiateNetworkServiceInstance(request,serviceInstanceId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void instantiateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String serviceInstanceId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.instantiateNetworkServiceInstance(anyObject(),serviceInstanceId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.instantiateNetworkServiceInstance(request,serviceInstanceId);
+ }
+
+
+ @Test
+ public void itCanTerminateNetworkServiceInstance() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ ResponseBody result=null;
+ Job job = new Job();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ service.terminateNetworkServiceInstance(request,csarId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ //when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.terminateNetworkServiceInstance(request,csarId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void terminateNetworkServiceInstanceWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ String csarId = "1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.terminateNetworkServiceInstance(csarId,anyObject())).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.terminateNetworkServiceInstance(request,csarId);
+ }
+
+ @Test
+ public void itCreateNetworkServiceData() throws IOException {
+ HttpServletRequest request = mockRequest();
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createNetworkServiceData(anyObject())).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.createNetworkServiceData(request));
+ }
+
+ @Test(expected = VfcException.class)
+ public void createNetworkServiceDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createNetworkServiceData(anyObject())).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.createNetworkServiceData(request);
+ }
+
+ @Test(expected = VfcException.class)
+ public void createNetworkServiceDataWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createNetworkServiceData(anyObject())).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.createNetworkServiceData(request);
+ }
+
+ @Test
+ public void itCreateVnfData() throws IOException {
+ HttpServletRequest request = mockRequest();
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createVnfData(anyObject())).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.createVnfData(request));
+ }
+
+ @Test(expected = VfcException.class)
+ public void createVnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createVnfData(anyObject())).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.createVnfData(request);
+ }
+
+ @Test(expected = VfcException.class)
+ public void createVnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createVnfData(anyObject())).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.createVnfData(request);
+ }
+
+ @Test
+ public void itCreatePnfData() throws IOException {
+ HttpServletRequest request = mockRequest();
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createPnfData(anyObject())).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.createPnfData(request));
+ }
+
+ @Test(expected = VfcException.class)
+ public void createPnfDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createPnfData(anyObject())).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.createPnfData(request);
+ }
+
+ @Test(expected = VfcException.class)
+ public void createPnfDataWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.createPnfData(anyObject())).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.createPnfData(request);
+ }
+
+ @Test
+ public void itGetNsdInfo() throws IOException {
+ String nsdId="1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getNsdInfo(nsdId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.getNsdInfo(nsdId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void getNsdInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ String nsdId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getNsdInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getNsdInfo(nsdId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void getNsdInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
+ String nsdId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getNsdInfo(nsdId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getNsdInfo(nsdId);
+ }
+
+ @Test
+ public void itGetVnfInfo() throws IOException {
+ String nsdId="1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfInfo(nsdId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.getVnfInfo(nsdId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void getVnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ String nsdId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getVnfInfo(nsdId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void getVnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
+ String nsdId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfInfo(nsdId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getVnfInfo(nsdId);
+ }
+
+ @Test
+ public void itGetPnfInfo() throws IOException {
+ String nsdId="1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getPnfInfo(nsdId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.getPnfInfo(nsdId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void getPnfInfoWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ String nsdId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getPnfInfo(nsdId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getPnfInfo(nsdId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void getPnfInfoWillThrowExceptionWhenVFCResponseError() throws IOException {
+ String nsdId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getPnfInfo(nsdId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getPnfInfo(nsdId);
+ }
+
+ @Test
+ public void itCanListNsTemplates() throws IOException {
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.listNsTemplates()).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.listNsTemplates());
+ }
+
+ @Test(expected = VfcException.class)
+ public void listNsTemplatesWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.listNsTemplates()).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.listNsTemplates();
+ }
+
+ @Test(expected = VfcException.class)
+ public void listNsTemplatesWillThrowExceptionWhenVFCResponseError() throws IOException {
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.listNsTemplates()).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.listNsTemplates();
+ }
+
+ @Test
+ public void itCanGetVnfInfoById() throws IOException {
+ String nsdId="1";
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfInfoById(nsdId)).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.getVnfInfoById(nsdId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void getVnfInfoByIdWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ String nsdId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfInfoById(nsdId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getVnfInfoById(nsdId);
+ }
+
+ @Test(expected = VfcException.class)
+ public void getVnfInfoByIdWillThrowExceptionWhenVFCResponseError() throws IOException {
+ String nsdId="1";
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.getVnfInfoById(nsdId)).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.getVnfInfoById(nsdId);
+ }
+
+ @Test
+ public void itCanFetchNsTemplateData() throws IOException {
+ HttpServletRequest request = mockRequest();
+ ResponseBody result=null;
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(successfulCall(result));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+
+ Assert.assertSame(result, service.fetchNsTemplateData(request));
+ }
+
+ @Test(expected = VfcException.class)
+ public void fetchNsTemplateDataWillThrowExceptionWhenVFCIsNotAvailable() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.fetchNsTemplateData(request);
+ }
+
+ @Test(expected = VfcException.class)
+ public void fetchNsTemplateDataWillThrowExceptionWhenVFCResponseError() throws IOException {
+ HttpServletRequest request = mockRequest();
+ VfcService vfcService = mock(VfcService.class);
+ when(vfcService.fetchNsTemplateData(anyObject())).thenReturn(emptyBodyCall());
+ PackageDistributionService service = new DefaultPackageDistributionService(null, vfcService);
+ service.fetchNsTemplateData(request);
+ }
+
+ } \ No newline at end of file
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SOTNServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SOTNServiceImplTest.java
new file mode 100644
index 00000000..f6d6defa
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/SOTNServiceImplTest.java
@@ -0,0 +1,433 @@
+/*
+ * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.usecaseui.server.service.lcm.impl;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.usecaseui.server.util.CallStub.emptyBodyCall;
+import static org.onap.usecaseui.server.util.CallStub.failedCall;
+import static org.onap.usecaseui.server.util.CallStub.successfulCall;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ReadListener;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.usecaseui.server.bean.sotn.Pinterface;
+import org.onap.usecaseui.server.bean.sotn.PinterfaceRsp;
+import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
+import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
+import org.onap.usecaseui.server.service.lcm.domain.vfc.exceptions.VfcException;
+import org.onap.usecaseui.server.service.sotn.impl.SOTNServiceImpl;
+
+import okhttp3.ResponseBody;
+
+public class SOTNServiceImplTest {
+
+ SOTNServiceImpl dsts = null;
+ @Before
+ public void before() throws Exception {
+ dsts = new SOTNServiceImpl();
+ }
+
+ private HttpServletRequest mockRequest() throws IOException {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getContentLength()).thenReturn(0);
+ ServletInputStream inStream = new ServletInputStream() {
+ @Override
+ public boolean isFinished() {
+ return false;
+ }
+
+ @Override
+ public boolean isReady() {
+ return false;
+ }
+
+ @Override
+ public void setReadListener(ReadListener readListener) {
+
+ }
+
+ @Override
+ public int read() throws IOException {
+ return 0;
+ }
+ };
+ when(request.getInputStream()).thenReturn(inStream);
+ return request;
+ }
+
+ @Test
+ public void itCanGetNetWorkResources(){
+ ResponseBody result=null;
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.listNetWorkResources()).thenReturn(successfulCall(result));
+ dsts.getNetWorkResources();
+ }
+
+ @Test
+ public void getNetWorkResourcesWithThrowsEexception(){
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.listNetWorkResources()).thenReturn(failedCall("aai is not exist!"));
+ dsts.getNetWorkResources();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void itCanGetPinterfaceByPnfName(){
+ String pnfName="test";
+ PinterfaceRsp rsp = new PinterfaceRsp();
+ List pinterfaces = new ArrayList();
+ Pinterface pinterface = new Pinterface("interfaceName");
+ pinterfaces.add(pinterface);
+ rsp.setPinterfaces(pinterfaces);
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getPinterfaceByPnfName(pnfName)).thenReturn(successfulCall(rsp));
+ dsts.getPinterfaceByPnfName(pnfName);
+ }
+
+ @Test
+ public void getPinterfaceByPnfNameWithThrowsEexception(){
+ AAIService aaiService = mock(AAIService.class);
+ String pnfName="test";
+ when(aaiService.getPinterfaceByPnfName(pnfName)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getPinterfaceByPnfName(pnfName);
+ }
+
+ @Test
+ public void itCanGetLogicalLinks(){
+ ResponseBody result=null;
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getLogicalLinks()).thenReturn(successfulCall(result));
+ dsts.getLogicalLinks();
+ }
+
+ @Test
+ public void getLogicalLinksWithThrowsEexception(){
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getLogicalLinks()).thenReturn(failedCall("aai is not exist!"));
+ dsts.getLogicalLinks();
+ }
+
+ @Test
+ public void itCanGetSpecificLogicalLink(){
+ ResponseBody result=null;
+ String linkName="linkName";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getSpecificLogicalLink(linkName)).thenReturn(successfulCall(result));
+ dsts.getSpecificLogicalLink(linkName);
+ }
+
+ @Test
+ public void getSpecificLogicalLinkWithThrowsEexception(){
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ when(aaiService.getSpecificLogicalLink(linkName)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getSpecificLogicalLink(linkName);
+ }
+
+ @Test
+ public void itCanGetHostUrl(){
+ ResponseBody result=null;
+ String linkName="linkName";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getHostUrl(linkName)).thenReturn(successfulCall(result));
+ dsts.getHostUrl(linkName);
+ }
+
+ @Test
+ public void getHostUrlWithThrowsEexception(){
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ when(aaiService.getHostUrl(linkName)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getHostUrl(linkName);
+ }
+
+ @Test
+ public void itCanGetExtAaiId(){
+ ResponseBody result=null;
+ String linkName="linkName";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getExtAaiId(linkName)).thenReturn(successfulCall(result));
+ dsts.getExtAaiId(linkName);
+ }
+
+ @Test
+ public void getExtAaiIdWithThrowsEexception(){
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ when(aaiService.getExtAaiId(linkName)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getExtAaiId(linkName);
+ }
+
+ @Test
+ public void itCanCreateHostUrl() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ HttpServletRequest request = mockRequest();
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.createHostUrl(anyObject(),eq(linkName))).thenReturn(successfulCall(result));
+ Assert.assertSame(result,dsts.createHostUrl(request,linkName));
+ }
+
+ @Test
+ public void createHostUrlWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ HttpServletRequest request = mockRequest();
+ when(aaiService.createHostUrl(anyObject(),eq(linkName))).thenReturn(failedCall("aai is not exist!"));
+ Assert.assertSame("",dsts.createHostUrl(request,linkName));
+ }
+
+ @Test
+ public void itCanCreateTopoNetwork() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ HttpServletRequest request = mockRequest();
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.createTopoNetwork(anyObject(),eq(linkName))).thenReturn(successfulCall(result));
+ Assert.assertSame(result,dsts.createTopoNetwork(request,linkName));
+ }
+
+ @Test
+ public void createTopoNetworkWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ HttpServletRequest request = mockRequest();
+ when(aaiService.createTopoNetwork(anyObject(),eq(linkName))).thenReturn(failedCall("aai is not exist!"));
+ Assert.assertSame("",dsts.createTopoNetwork(request,linkName));
+ }
+
+ @Test
+ public void itCanCreateTerminationPoint() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ String tpid="tpId";
+ HttpServletRequest request = mockRequest();
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.createTerminationPoint(anyObject(),eq(linkName),eq(linkName))).thenReturn(successfulCall(result));
+ Assert.assertSame(result,dsts.createTerminationPoint(request,linkName,tpid));
+ }
+
+ @Test
+ public void createTerminationPointWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ String tpid="tpId";
+ HttpServletRequest request = mockRequest();
+ when(aaiService.createTerminationPoint(anyObject(),eq(linkName),eq(linkName))).thenReturn(failedCall("aai is not exist!"));
+ Assert.assertSame("",dsts.createTerminationPoint(request,linkName,tpid));
+ }
+
+ @Test
+ public void itCanCreateLink() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ HttpServletRequest request = mockRequest();
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.createLink(anyObject(),eq(linkName))).thenReturn(successfulCall(result));
+ dsts.createLink(request,linkName);
+ }
+
+ @Test
+ public void createLinkWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ HttpServletRequest request = mockRequest();
+ when(aaiService.createLink(anyObject(),eq(linkName))).thenReturn(failedCall("aai is not exist!"));
+ dsts.createLink(request,linkName);
+ }
+
+ @Test
+ public void itCanCreatePnf() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ HttpServletRequest request = mockRequest();
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.createPnf(anyObject(),eq(linkName))).thenReturn(successfulCall(result));
+ dsts.createPnf(request,linkName);
+ }
+
+ @Test
+ public void createPnfWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ HttpServletRequest request = mockRequest();
+ when(aaiService.createPnf(anyObject(),eq(linkName))).thenReturn(failedCall("aai is not exist!"));
+ dsts.createPnf(request,linkName);
+ }
+
+ @Test
+ public void itCanDeleteLink() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.deleteLink(linkName,resourceVersion)).thenReturn(successfulCall(result));
+ dsts.deleteLink(linkName,resourceVersion);
+ }
+
+ @Test
+ public void deleteLinkWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ when(aaiService.deleteLink(linkName,resourceVersion)).thenReturn(failedCall("aai is not exist!"));
+ dsts.deleteLink(linkName,resourceVersion);
+ }
+
+ @Test
+ public void itCanGetServiceInstances() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getServiceInstances(linkName,resourceVersion)).thenReturn(successfulCall(result));
+ dsts.getServiceInstances(linkName,resourceVersion);
+ }
+
+ @Test
+ public void getServiceInstancesWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ when(aaiService.getServiceInstances(linkName,resourceVersion)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getServiceInstances(linkName,resourceVersion);
+ }
+
+ @Test
+ public void itCanGerviceInstanceInfo() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ String serviceId="serviceId";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.serviceInstaneInfo(linkName,resourceVersion,serviceId)).thenReturn(successfulCall(result));
+ dsts.serviceInstanceInfo(linkName,resourceVersion,serviceId);
+ }
+
+ @Test
+ public void serviceInstanceInfoWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ String serviceId="serviceId";
+ when(aaiService.serviceInstaneInfo(linkName,resourceVersion,serviceId)).thenReturn(failedCall("aai is not exist!"));
+ dsts.serviceInstanceInfo(linkName,resourceVersion,serviceId);
+ }
+
+ @Test
+ public void itCanGetPnfInfo() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getPnfInfo(linkName)).thenReturn(successfulCall(result));
+ dsts.getPnfInfo(linkName);
+ }
+
+ @Test
+ public void getPnfInfoWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ when(aaiService.getPnfInfo(linkName)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getPnfInfo(linkName);
+ }
+
+ @Test
+ public void itCangetAllottedResources() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ String serviceId="serviceId";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getAllottedResources(linkName,resourceVersion,serviceId)).thenReturn(successfulCall(result));
+ dsts.getAllottedResources(linkName,resourceVersion,serviceId);
+ }
+
+ @Test
+ public void getAllottedResourcesWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ String serviceId="serviceId";
+ when(aaiService.getAllottedResources(linkName,resourceVersion,serviceId)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getAllottedResources(linkName,resourceVersion,serviceId);
+ }
+
+ @Test
+ public void itCangetConnectivityInfo() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getConnectivityInfo(linkName)).thenReturn(successfulCall(result));
+ dsts.getConnectivityInfo(linkName);
+ }
+
+ @Test
+ public void getConnectivityInfoWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ when(aaiService.getConnectivityInfo(linkName)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getConnectivityInfo(linkName);
+ }
+
+ @Test
+ public void itCangetPinterfaceByVpnId() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.getPinterfaceByVpnId(linkName)).thenReturn(successfulCall(result));
+ dsts.getPinterfaceByVpnId(linkName);
+ }
+
+ @Test
+ public void getPinterfaceByVpnIdWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ when(aaiService.getPinterfaceByVpnId(linkName)).thenReturn(failedCall("aai is not exist!"));
+ dsts.getPinterfaceByVpnId(linkName);
+ }
+
+ @Test
+ public void itCandeleteExtNetwork() throws IOException{
+ ResponseBody result=null;
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ AAIService aaiService = mock(AAIService.class);
+ when(aaiService.deleteExtNetwork(linkName,resourceVersion)).thenReturn(successfulCall(result));
+ dsts.deleteExtNetwork(linkName,resourceVersion);
+ }
+
+ @Test
+ public void deleteExtNetworkWithThrowsEexception() throws IOException{
+ AAIService aaiService = mock(AAIService.class);
+ String linkName="linkName";
+ String resourceVersion="resourceVersion";
+ when(aaiService.deleteExtNetwork(linkName,resourceVersion)).thenReturn(failedCall("aai is not exist!"));
+ dsts.deleteExtNetwork(linkName,resourceVersion);
+ }
+}