summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultCustomerServiceTest.java18
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultPackageDistributionServiceTest.java78
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java58
-rw-r--r--server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java118
4 files changed, 247 insertions, 25 deletions
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 af579afa..ebe70c72 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
@@ -17,17 +17,19 @@ package org.onap.usecaseui.server.service.lcm.impl;
import org.junit.Assert;
import org.junit.Test;
-import org.mockito.Mockito;
import org.onap.usecaseui.server.service.lcm.CustomerService;
import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer;
import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
-import org.onap.usecaseui.server.util.CallStub;
import retrofit2.Call;
import java.util.List;
import static java.util.Collections.singletonList;
+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 DefaultCustomerServiceTest {
@@ -35,9 +37,9 @@ public class DefaultCustomerServiceTest {
public void itCanRetrieveCustomersFromAAI() {
List<AAICustomer> customers = singletonList(new AAICustomer("1", "name", "type"));
- AAIService aaiService = Mockito.mock(AAIService.class);
- Call<List<AAICustomer>> call = CallStub.successfulCall(customers);
- Mockito.when(aaiService.listCustomer()).thenReturn(call);
+ AAIService aaiService = mock(AAIService.class);
+ Call<List<AAICustomer>> call = successfulCall(customers);
+ when(aaiService.listCustomer()).thenReturn(call);
CustomerService customerService = new DefaultCustomerService(aaiService);
Assert.assertSame(customers, customerService.listCustomer());
@@ -45,9 +47,9 @@ public class DefaultCustomerServiceTest {
@Test(expected = AAIException.class)
public void itWillThrowExceptionWhenAAIIsNotAvailable() {
- AAIService aaiService = Mockito.mock(AAIService.class);
- Call<List<AAICustomer>> call = CallStub.failedCall("AAI is not available!");
- Mockito.when(aaiService.listCustomer()).thenReturn(call);
+ AAIService aaiService = mock(AAIService.class);
+ Call<List<AAICustomer>> call = failedCall("AAI is not available!");
+ when(aaiService.listCustomer()).thenReturn(call);
CustomerService customerService = new DefaultCustomerService(aaiService);
customerService.listCustomer();
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 19430820..fed2bfce 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
@@ -17,7 +17,6 @@ package org.onap.usecaseui.server.service.lcm.impl;
import org.junit.Assert;
import org.junit.Test;
-import org.mockito.Mockito;
import org.onap.usecaseui.server.bean.lcm.VfNsPackageInfo;
import org.onap.usecaseui.server.service.lcm.PackageDistributionService;
import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
@@ -29,15 +28,20 @@ import org.onap.usecaseui.server.service.lcm.domain.sdc.exceptions.SDCCatalogExc
import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService;
import org.onap.usecaseui.server.service.lcm.domain.vfc.beans.Csar;
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 org.onap.usecaseui.server.util.CallStub;
import retrofit2.Call;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import static org.onap.usecaseui.server.service.lcm.domain.sdc.consts.SDCConsts.*;
+import static org.onap.usecaseui.server.util.CallStub.failedCall;
+import static org.onap.usecaseui.server.util.CallStub.successfulCall;
public class DefaultPackageDistributionServiceTest {
@@ -56,29 +60,29 @@ public class DefaultPackageDistributionServiceTest {
}
private AAIService newAAIService(List<VimInfo> vim) {
- AAIService aaiService = Mockito.mock(AAIService.class);
+ AAIService aaiService = mock(AAIService.class);
- Call<List<VimInfo>> vimCall = CallStub.successfulCall(vim);
- Mockito.when(aaiService.listVimInfo()).thenReturn(vimCall);
+ Call<List<VimInfo>> vimCall = successfulCall(vim);
+ when(aaiService.listVimInfo()).thenReturn(vimCall);
return aaiService;
}
private SDCCatalogService newSDCService(List<SDCServiceTemplate> serviceTemplate, List<Vnf> vnf) {
- SDCCatalogService sdcService = Mockito.mock(SDCCatalogService.class);
+ SDCCatalogService sdcService = mock(SDCCatalogService.class);
- Call<List<SDCServiceTemplate>> serviceCall = CallStub.successfulCall(serviceTemplate);
- Mockito.when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
+ Call<List<SDCServiceTemplate>> serviceCall = successfulCall(serviceTemplate);
+ when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
- Call<List<Vnf>> vnfCall = CallStub.successfulCall(vnf);
- Mockito.when(sdcService.listResources(RESOURCETYPE_VF, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(vnfCall);
+ Call<List<Vnf>> vnfCall = successfulCall(vnf);
+ when(sdcService.listResources(RESOURCETYPE_VF, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(vnfCall);
return sdcService;
}
@Test(expected = SDCCatalogException.class)
public void retrievePackageWillThrowExceptionWhenSDCIsNotAvailable() {
- SDCCatalogService sdcService = Mockito.mock(SDCCatalogService.class);
- Call<List<SDCServiceTemplate>> serviceCall = CallStub.failedCall("SDC is not available!");
- Mockito.when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
+ SDCCatalogService sdcService = mock(SDCCatalogService.class);
+ Call<List<SDCServiceTemplate>> serviceCall = failedCall("SDC is not available!");
+ when(sdcService.listServices(CATEGORY_NS, DISTRIBUTION_STATUS_DISTRIBUTED)).thenReturn(serviceCall);
List<VimInfo> vim = Collections.singletonList(new VimInfo("owner", "regionId"));
AAIService aaiService = newAAIService(vim);
@@ -89,10 +93,10 @@ public class DefaultPackageDistributionServiceTest {
@Test
public void itCanPostNsPackageToVFC() {
- VfcService vfcService = Mockito.mock(VfcService.class);
+ VfcService vfcService = mock(VfcService.class);
Csar csar = new Csar();
DistributionResult result = new DistributionResult("status", "description", "errorcode");
- Mockito.when(vfcService.distributeNsPackage(csar)).thenReturn(CallStub.successfulCall(result));
+ when(vfcService.distributeNsPackage(csar)).thenReturn(successfulCall(result));
PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
Assert.assertSame(result, service.postNsPackage(csar));
@@ -100,10 +104,50 @@ public class DefaultPackageDistributionServiceTest {
@Test(expected = VfcException.class)
public void postNsPackageWillThrowExceptionWhenVFCIsNotAvailable() {
- VfcService vfcService = Mockito.mock(VfcService.class);
+ VfcService vfcService = mock(VfcService.class);
Csar csar = new Csar();
- Mockito.when(vfcService.distributeNsPackage(csar)).thenReturn(CallStub.failedCall("VFC is not available!"));
+ when(vfcService.distributeNsPackage(csar)).thenReturn(failedCall("VFC is not available!"));
PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
service.postNsPackage(csar);
}
+
+ @Test
+ public void itCanPostVnfPackageToVFC() {
+ VfcService vfcService = mock(VfcService.class);
+ Csar csar = new Csar();
+ Job job = new Job();
+ when(vfcService.distributeVnfPackage(csar)).thenReturn(successfulCall(job));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
+
+ Assert.assertSame(job, service.postVfPackage(csar));
+ }
+
+ @Test(expected = VfcException.class)
+ public void postVnfPackageWillThrowExceptionWhenVFCIsNotAvailable() {
+ VfcService vfcService = mock(VfcService.class);
+ Csar csar = new Csar();
+ when(vfcService.distributeVnfPackage(csar)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
+ service.postVfPackage(csar);
+ }
+
+ @Test
+ public void itCanGetJobStatusFromVFC() {
+ VfcService vfcService = mock(VfcService.class);
+ String jobId = "1";
+ JobStatus jobStatus = new JobStatus();
+ when(vfcService.getJobStatus(jobId)).thenReturn(successfulCall(jobStatus));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
+
+ Assert.assertSame(jobStatus, service.getJobStatus(jobId));
+ }
+
+ @Test(expected = VfcException.class)
+ public void getJobStatusWillThrowExceptionWhenVFCIsNotAvailable() {
+ VfcService vfcService = mock(VfcService.class);
+ String jobId = "1";
+ when(vfcService.getJobStatus(jobId)).thenReturn(failedCall("VFC is not available!"));
+ PackageDistributionService service = new DefaultPackageDistributionService(null, null, vfcService);
+ service.getJobStatus(jobId);
+ }
} \ No newline at end of file
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java
new file mode 100644
index 00000000..6f193fb3
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceInstanceServiceTest.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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 org.junit.Assert;
+import org.junit.Test;
+import org.onap.usecaseui.server.service.lcm.ServiceInstanceService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.AAIService;
+import org.onap.usecaseui.server.service.lcm.domain.aai.bean.ServiceInstance;
+import org.onap.usecaseui.server.service.lcm.domain.aai.exceptions.AAIException;
+
+import java.util.Collections;
+import java.util.List;
+
+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 DefaultServiceInstanceServiceTest {
+
+ @Test
+ public void itCanRetrieveServiceInstanceFromAAI() {
+ AAIService aaiService = mock(AAIService.class);
+ String customerId = "1";
+ String serviceType = "service";
+ List<ServiceInstance> instances = Collections.singletonList(new ServiceInstance("1","service","1","VoLTE","e2eservice","abc","vim1"));
+ when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(successfulCall(instances));
+
+ ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
+
+ Assert.assertSame(instances, service.listServiceInstances(customerId, serviceType));
+ }
+
+ @Test(expected = AAIException.class)
+ public void retrieveServiceInstancesWillThrowExceptionWhenAAIIsNotAvailable() {
+ AAIService aaiService = mock(AAIService.class);
+ String customerId = "1";
+ String serviceType = "service";
+ when(aaiService.listServiceInstances(customerId, serviceType)).thenReturn(failedCall("AAI is not available!"));
+
+ ServiceInstanceService service = new DefaultServiceInstanceService(aaiService);
+ service.listServiceInstances(customerId, serviceType);
+ }
+} \ No newline at end of file
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
new file mode 100644
index 00000000..607a9148
--- /dev/null
+++ b/server/src/test/java/org/onap/usecaseui/server/service/lcm/impl/DefaultServiceLcmServiceTest.java
@@ -0,0 +1,118 @@
+/**
+ * Copyright 2016-2017 ZTE Corporation.
+ *
+ * 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 org.junit.Assert;
+import org.junit.Test;
+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.OperationProgressInformation;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceInstantiationRequest;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.ServiceOperation;
+import org.onap.usecaseui.server.service.lcm.domain.so.exceptions.SOException;
+
+import java.util.HashMap;
+
+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 DefaultServiceLcmServiceTest {
+
+ @Test
+ public void itCanInstantiateService() {
+ SOService soService = mock(SOService.class);
+ ServiceInstantiationRequest request = new ServiceInstantiationRequest(
+ "name",
+ "description",
+ "123",
+ "123",
+ new HashMap<>()
+ );
+ ServiceOperation operation = new ServiceOperation("1", "1");
+ when(soService.instantiateService(request)).thenReturn(successfulCall(operation));
+
+ ServiceLcmService service = new DefaultServiceLcmService(soService);
+
+ Assert.assertSame(operation, service.instantiateService(request));
+ }
+
+ @Test(expected = SOException.class)
+ public void instantiateServiceWillThrowExceptionWhenSOIsNotAvailable() {
+ SOService soService = mock(SOService.class);
+ ServiceInstantiationRequest request = new ServiceInstantiationRequest(
+ "name",
+ "description",
+ "123",
+ "123",
+ new HashMap<>()
+ );
+ when(soService.instantiateService(request)).thenReturn(failedCall("SO is not available!"));
+
+ ServiceLcmService service = new DefaultServiceLcmService(soService);
+
+ service.instantiateService(request);
+ }
+
+ @Test
+ public void itCanTerminateService() {
+ SOService soService = mock(SOService.class);
+ String serviceId = "1";
+ ServiceOperation operation = new ServiceOperation("1", "1");
+ when(soService.terminateService(serviceId)).thenReturn(successfulCall(operation));
+
+ ServiceLcmService service = new DefaultServiceLcmService(soService);
+
+ Assert.assertSame(operation, service.terminateService(serviceId));
+ }
+
+ @Test(expected = SOException.class)
+ public void terminateServiceWillThrowExceptionWhenSOIsNotAvailable() {
+ SOService soService = mock(SOService.class);
+ String serviceId = "1";
+ when(soService.terminateService(serviceId)).thenReturn(failedCall("SO is not available!"));
+
+ ServiceLcmService service = new DefaultServiceLcmService(soService);
+
+ service.terminateService(serviceId);
+ }
+
+ @Test
+ public void itCanQueryOperationProgress() {
+ SOService soService = mock(SOService.class);
+ String serviceId = "1";
+ String operationId = "1";
+ OperationProgressInformation progress = new OperationProgressInformation();
+ when(soService.queryOperationProgress(serviceId, operationId)).thenReturn(successfulCall(progress));
+
+ ServiceLcmService service = new DefaultServiceLcmService(soService);
+
+ Assert.assertSame(progress, service.queryOperationProgress(serviceId, operationId));
+ }
+
+ @Test(expected = SOException.class)
+ public void queryOperationProgressWillThrowExceptionWhenSOIsNotAvailable() {
+ SOService soService = mock(SOService.class);
+ String serviceId = "1";
+ String operationId = "1";
+ when(soService.queryOperationProgress(serviceId, operationId)).thenReturn(failedCall("SO is not available!"));
+
+ ServiceLcmService service = new DefaultServiceLcmService(soService);
+
+ service.queryOperationProgress(serviceId, operationId);
+ }
+} \ No newline at end of file