summaryrefslogtreecommitdiffstats
path: root/vnfapi/provider
diff options
context:
space:
mode:
authorpawel.kadlubanski <pawel.kadlubanski@nokia.com>2018-02-20 08:19:57 +0100
committerpawel.kadlubanski <pawel.kadlubanski@nokia.com>2018-02-20 11:40:12 +0100
commitc4254fe8d4865c8e767fb6e614d8d72d7e41db53 (patch)
tree8d96913ee7d9fbbdb5fc6904101ef677ad6a98f9 /vnfapi/provider
parent9bf3b59219e9140024ccbec9157da22c9be184d6 (diff)
Add tests to VnfApiProvider part 2
Write test for function vnfInstanceTopologyOperation in vnfapiProvider class. Case when svcLogicClient hasGraph return false. Case when svcLogicClient execute throw SvcLogicException. Case when svcLogicClient execute throw SvcLogicException. Change-Id: I6f65049e7567ae1d0fd9eccf7f8c1f35deb3c482 Issue-ID: SDNC-267 Signed-off-by: pawel.kadlubanski <pawel.kadlubanski@nokia.com>
Diffstat (limited to 'vnfapi/provider')
-rw-r--r--vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java120
1 files changed, 90 insertions, 30 deletions
diff --git a/vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java b/vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java
index 72c244d5..5cc34e0c 100644
--- a/vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java
+++ b/vnfapi/provider/src/test/java/org/onap/sdnc/vnfapi/VnfApiProviderTest.java
@@ -26,6 +26,8 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.sdnc.vnfapi.util.DataBrokerUtil;
import org.onap.sdnc.vnfapi.util.PropBuilder;
import org.onap.sdnc.vnfapi.util.VNFSDNSvcLogicServiceClientMockUtil;
@@ -41,10 +43,18 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTop
import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.request.information.VnfInstanceRequestInformation;
import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.request.information.VnfInstanceRequestInformationBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.service.data.VnfInstanceServiceDataBuilder;
+
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest {
+ private static final String INVALID_INPUT = "invalid input, null or empty vnf-instance-id";
+ private static final String NO_SERVICE_LOGIC = "No service logic active for VNF-API: \'vnf-instance-topology-operation\'";
+ private static final String VIID = "viid";
+ private static final String PRELOAD_NAME = "preloadName";
+ private static final String PRELOAD_TYPE = "preloadType";
protected VnfApiProvider vnfapiProvider;
protected DataBroker dataBroker;
@@ -59,6 +69,7 @@ public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest {
@Before
public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
svcClient = new VNFSDNSvcLogicServiceClientMockUtil(mockVNFSDNSvcLogicServiceClient);
dataBroker = getDataBroker();
db = new DataBrokerUtil(dataBroker);
@@ -83,12 +94,7 @@ public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest {
@Test
public void vnfInstanceTopologyOperationInputIsNull() throws Exception {
VnfInstanceTopologyOperationInput input = null;
- VnfInstanceTopologyOperationOutput result = vnfapiProvider
- .vnfInstanceTopologyOperation(input)
- .get()
- .getResult();
-
- checkVnfInstanceTopologyOperationOutput(result);
+ checkVnfInstanceTopologyOperation(input, "403", INVALID_INPUT);
}
@@ -96,51 +102,105 @@ public class VnfApiProviderTest extends AbstractConcurrentDataBrokerTest {
public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationIsNull() throws Exception {
VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
builder.setVnfInstanceRequestInformation(null);
-
VnfInstanceTopologyOperationInput input = builder.build();
- VnfInstanceTopologyOperationOutput result = vnfapiProvider
- .vnfInstanceTopologyOperation(input)
- .get()
- .getResult();
- checkVnfInstanceTopologyOperationOutput(result);
+ checkVnfInstanceTopologyOperation(input, "403", INVALID_INPUT);
}
@Test
public void vnfInstanceTopologyOperationInput_getVnfInstanceRequestInformationVnfInstanceIdIsNull() throws Exception {
VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
- builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder()
- .setVnfInstanceId(null)
- .build());
-
+ builder.setVnfInstanceRequestInformation(createVnfInstanceRequestInformation(null));
VnfInstanceTopologyOperationInput input = builder.build();
- VnfInstanceTopologyOperationOutput result = vnfapiProvider
- .vnfInstanceTopologyOperation(input)
- .get()
- .getResult();
- checkVnfInstanceTopologyOperationOutput(result);
+ checkVnfInstanceTopologyOperation(input, "403", INVALID_INPUT);
}
@Test
public void vnfInstanceTopologyOperationInput_VnfInstanceRequestInformationVnfInstanceIdIsZero() throws Exception {
VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
- builder.setVnfInstanceRequestInformation(new VnfInstanceRequestInformationBuilder()
- .setVnfInstanceId("")
- .build());
+ builder.setVnfInstanceRequestInformation(createVnfInstanceRequestInformation(""));
+ VnfInstanceTopologyOperationInput input = builder.build();
+ checkVnfInstanceTopologyOperation(input, "403", INVALID_INPUT);
+ }
+
+ @Test
+ public void vnfInstanceTopologyOperationInput_svcLogicClientHasGrapheReturnFalse() throws Exception {
+ VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
+ builder.setVnfInstanceRequestInformation(createVnfInstanceRequestInformation(VIID));
VnfInstanceTopologyOperationInput input = builder.build();
- VnfInstanceTopologyOperationOutput result = vnfapiProvider
+
+ Mockito.when(mockVNFSDNSvcLogicServiceClient
+ .hasGraph(Mockito.any(),Mockito.any(), Mockito.any(),Mockito.any()))
+ .thenReturn(false);
+
+ checkVnfInstanceTopologyOperation(input, "503", NO_SERVICE_LOGIC);
+ }
+
+
+ @Test
+ public void vnfInstanceTopologyOperationInput_svcLogicClientExecuteThrowsSvcLogicException() throws Exception {
+ VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
+ builder.setVnfInstanceRequestInformation(createVnfInstanceRequestInformation(VIID));
+ VnfInstanceTopologyOperationInput input = builder.build();
+
+ Mockito.when(mockVNFSDNSvcLogicServiceClient
+ .hasGraph(Mockito.any(),Mockito.any(), Mockito.any(),Mockito.any()))
+ .thenReturn(true);
+ setMockVNFSDNSvcLogicServiceClientToThrowException(SvcLogicException.class);
+ checkVnfInstanceTopologyOperation(input, "500", null);
+ }
+
+ @Test
+ public void vnfInstanceTopologyOperationInput_svcLogicClientExecuteThrowsException() throws Exception {
+ VnfInstanceTopologyOperationInputBuilder builder = new VnfInstanceTopologyOperationInputBuilder();
+ builder.setVnfInstanceRequestInformation(createVnfInstanceRequestInformation(VIID));
+ VnfInstanceTopologyOperationInput input = builder.build();
+
+ Mockito.when(mockVNFSDNSvcLogicServiceClient
+ .hasGraph(Mockito.any(),Mockito.any(), Mockito.any(),Mockito.any()))
+ .thenReturn(true);
+ setMockVNFSDNSvcLogicServiceClientToThrowException(Exception.class);
+ checkVnfInstanceTopologyOperation(input, "500", null);
+ }
+
+ private void setMockVNFSDNSvcLogicServiceClientToThrowException(Class exceptionClass) throws Exception {
+ Mockito.when(mockVNFSDNSvcLogicServiceClient
+ .execute(Mockito.any(),
+ Mockito.any(),
+ Mockito.any(),
+ Mockito.any(),
+ Mockito.any(VnfInstanceServiceDataBuilder.class),
+ Mockito.any()))
+ .thenThrow(exceptionClass.asSubclass(Throwable.class));
+ }
+ private VnfInstanceRequestInformation createVnfInstanceRequestInformation(String vnfInstanceId) {
+ return new VnfInstanceRequestInformationBuilder()
+ .setVnfInstanceId(vnfInstanceId)
+ .setVnfInstanceName(PRELOAD_NAME)
+ .setVnfModelId(PRELOAD_TYPE)
+ .build();
+ }
+
+ private void checkVnfInstanceTopologyOperation(VnfInstanceTopologyOperationInput input,
+ String expectedResponseCode, String expectedResponseMessage) throws ExecutionException, InterruptedException {
+
+ VnfInstanceTopologyOperationOutput output = executeVnfInstanceTopologyOperation(input);
+ checkVnfInstanceTopologyOperationOutput(output, expectedResponseCode, expectedResponseMessage);
+ }
+
+ private VnfInstanceTopologyOperationOutput executeVnfInstanceTopologyOperation(
+ VnfInstanceTopologyOperationInput input) throws ExecutionException, InterruptedException {
+ return vnfapiProvider
.vnfInstanceTopologyOperation(input)
.get()
.getResult();
-
- checkVnfInstanceTopologyOperationOutput(result);
}
- private void checkVnfInstanceTopologyOperationOutput(VnfInstanceTopologyOperationOutput result) {
- String expectedResponseCode = "403";
- String expectedResponseMessage = "invalid input, null or empty vnf-instance-id";
+ private void checkVnfInstanceTopologyOperationOutput(VnfInstanceTopologyOperationOutput result,
+ String expectedResponseCode, String expectedResponseMessage) {
+
String expectedAckFinalIndicator = "Y";
Assert.assertEquals(result.getResponseCode(), expectedResponseCode );