summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-03-19 13:13:23 +0100
committerJakub Dudycz <jakub.dudycz@nokia.com>2018-03-19 13:13:23 +0100
commit19b7e2d7d4e8c0f3fb7a68fc9240bd560b297ca2 (patch)
tree76761e0d38433e59e01357c95a7a4660fefd3b8c
parent065899bdbe753caea62024c50bfecadabc743bea (diff)
GenericResourceApiProvider unit tests part 1.
Unit tests for serviceTopologyOperation method Change-Id: I9a6f43fb6892b9b1d8f92544f7a90e203b0c9229 Issue-ID: SDNC-275 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
-rw-r--r--generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java108
-rw-r--r--generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/ResponseObject.java (renamed from generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/ErrorObject.java)4
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiProviderTest.java6
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java247
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java61
5 files changed, 267 insertions, 159 deletions
diff --git a/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java b/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java
index 9673515c..ba3f1b5f 100644
--- a/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java
+++ b/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/GenericResourceApiProvider.java
@@ -134,14 +134,14 @@ import com.google.common.util.concurrent.Futures;
public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURCEAPIService {
- private static final String APP_NAME = "generic-resource-api";
+ protected static final String APP_NAME = "generic-resource-api";
private static final String CALLED_STR = "{} called.";
private static final String NULL_OR_EMPTY_ERROR_MESSAGE = "exiting {} because of null or empty service-instance-id";
- private static final String NULL_OR_EMPTY_ERROR_PARAM = "invalid input, null or empty service-instance-id";
+ protected static final String NULL_OR_EMPTY_ERROR_PARAM = "invalid input, null or empty service-instance-id";
private static final String ADDING_INPUT_DATA_LOG = "Adding INPUT data for {} [{}] input: {}";
private static final String ADDING_OPERATIONAL_DATA_LOG = "Adding OPERATIONAL data for {} [{}] operational-data: {}";
private static final String OPERATIONAL_DATA_PARAM = "operational-data";
- private static final String NO_SERVICE_LOGIC_ACTIVE = "No service logic active for ";
+ protected static final String NO_SERVICE_LOGIC_ACTIVE = "No service logic active for ";
private static final String SERVICE_LOGIC_SEARCH_ERROR_MESSAGE = "Caught exception looking for service logic";
private static final String ERROR_CODE_PARAM = "error-code";
private static final String ERROR_MESSAGE_PARAM = "error-message";
@@ -502,7 +502,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// create a new response object
ServiceTopologyOperationOutputBuilder responseBuilder = new ServiceTopologyOperationOutputBuilder();
- if (hasValidService(input)) {
+ if (hasInvalidService(input)) {
log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
responseBuilder.setResponseCode("404");
responseBuilder.setResponseMessage(NULL_OR_EMPTY_ERROR_PARAM);
@@ -548,25 +548,25 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject responseObject = new ResponseObject("200", "");
String ackFinal = "Y";
String serviceObjectPath = null;
- Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error);
+ Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, responseObject);
if (respProps != null) {
- error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
- error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
+ responseObject.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
+ responseObject.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
serviceObjectPath = respProps.getProperty(SERVICE_OBJECT_PATH_PARAM);
}
- setServiceStatus(serviceStatusBuilder, error.getStatusCode(), error.getMessage(), ackFinal);
+ setServiceStatus(serviceStatusBuilder, responseObject.getStatusCode(), responseObject.getMessage(), ackFinal);
serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
serviceStatusBuilder.setRpcName(svcOperation);
- if (isValidErrorObject(error)) {
- responseBuilder.setResponseCode(error.getStatusCode());
- responseBuilder.setResponseMessage(error.getMessage());
+ if (failed(responseObject)) {
+ responseBuilder.setResponseCode(responseObject.getStatusCode());
+ responseBuilder.setResponseMessage(responseObject.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
ServiceBuilder serviceBuilder = new ServiceBuilder();
@@ -609,7 +609,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
} catch (Exception e) {
log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
responseBuilder.setResponseCode("500");
- responseBuilder.setResponseMessage(e.toString());
+ responseBuilder.setResponseMessage(e.getMessage());
responseBuilder.setAckFinalIndicator("Y");
log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
@@ -622,9 +622,9 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
}
// Update succeeded
- responseBuilder.setResponseCode(error.getStatusCode());
+ responseBuilder.setResponseCode(responseObject.getStatusCode());
responseBuilder.setAckFinalIndicator(ackFinal);
- trySetResponseMessage(responseBuilder, error);
+ trySetResponseMessage(responseBuilder, responseObject);
log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
@@ -636,13 +636,13 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private void trySetResponseMessage(ServiceTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(ServiceTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
}
- private boolean hasValidService(ServiceTopologyOperationInput input) {
+ private boolean hasInvalidService(ServiceTopologyOperationInput input) {
return input == null || input.getServiceInformation() == null
|| input.getServiceInformation().getServiceInstanceId() == null
|| input.getServiceInformation().getServiceInstanceId().length() == 0;
@@ -665,30 +665,30 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
}
private Properties tryGetProperties(String svcOperation, Properties parms, ServiceDataBuilder serviceDataBuilder,
- ErrorObject error) {
+ ResponseObject responseObject) {
try {
if (svcLogicClient.hasGraph(APP_NAME, svcOperation, null, "sync")) {
try {
return svcLogicClient.execute(APP_NAME, svcOperation, null, "sync", serviceDataBuilder, parms);
} catch (Exception e) {
log.error(SERVICE_LOGIC_EXECUTION_ERROR_MESSAGE, svcOperation, e);
- error.setMessage(e.getMessage());
- error.setStatusCode("500");
+ responseObject.setMessage(e.getMessage());
+ responseObject.setStatusCode("500");
}
} else {
- error.setMessage(NO_SERVICE_LOGIC_ACTIVE + APP_NAME + ": '" + svcOperation + "'");
- error.setStatusCode("503");
+ responseObject.setMessage(NO_SERVICE_LOGIC_ACTIVE + APP_NAME + ": '" + svcOperation + "'");
+ responseObject.setStatusCode("503");
}
} catch (Exception e) {
- error.setMessage(e.getMessage());
- error.setStatusCode("500");
+ responseObject.setMessage(e.getMessage());
+ responseObject.setStatusCode("500");
log.error(SERVICE_LOGIC_SEARCH_ERROR_MESSAGE, e);
}
return null;
}
- private boolean isValidErrorObject(ErrorObject error) {
+ private boolean failed(ResponseObject error) {
return
!error.getStatusCode().isEmpty() && !("0".equals(error.getStatusCode()) || "200"
.equals(error.getStatusCode()));
@@ -779,7 +779,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
String ackFinal = "Y";
String serviceObjectPath = null;
Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error);
@@ -795,7 +795,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
serviceStatusBuilder.setRpcName(svcOperation);
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
@@ -875,7 +875,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private void trySetResponseMessage(VnfTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(VnfTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
@@ -1009,7 +1009,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
String ackFinal = "Y";
String serviceObjectPath = null;
Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error);
@@ -1025,7 +1025,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
serviceStatusBuilder.setRpcName(svcOperation);
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getStatusCode());
responseBuilder.setAckFinalIndicator(ackFinal);
@@ -1099,7 +1099,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private void trySetResponseMessage(VfModuleTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(VfModuleTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
@@ -1182,7 +1182,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
String ackFinal = "Y";
String networkId = ERROR_NETWORK_ID;
String serviceObjectPath = null;
@@ -1198,7 +1198,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
networkObjectPath = respProps.getProperty("network-object-path");
}
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
@@ -1268,7 +1268,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private void trySetResponseMessage(NetworkTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(NetworkTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
@@ -1355,7 +1355,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
String ackFinal = "Y";
String allottedResourceId = ERROR_NETWORK_ID;
String serviceObjectPath = null;
@@ -1371,7 +1371,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
contrailRouteObjectPath = respProps.getProperty("contrail-route-object-path");
}
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
@@ -1439,7 +1439,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private void trySetResponseMessage(ContrailRouteTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(ContrailRouteTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
@@ -1527,7 +1527,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
Properties respProps = null;
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
String ackFinal = "Y";
String allottedResourceId = ERROR_NETWORK_ID;
String serviceObjectPath = null;
@@ -1562,7 +1562,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
securityZoneObjectPath = respProps.getProperty("security-zone-object-path");
}
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
@@ -1631,7 +1631,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private void trySetResponseMessage(SecurityZoneTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(SecurityZoneTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
@@ -1713,7 +1713,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
String ackFinal = "Y";
String allottedResourceId = ERROR_NETWORK_ID;
String serviceObjectPath = null;
@@ -1729,7 +1729,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
tunnelxconnObjectPath = respProps.getProperty("tunnelxconn-object-path");
}
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
@@ -1786,7 +1786,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private void trySetResponseMessage(TunnelxconnTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(TunnelxconnTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
@@ -1798,7 +1798,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
|| input.getServiceInformation().getServiceInstanceId().length() == 0;
}
- private Properties tryGetProperties(String svcOperation, Properties parms, ErrorObject error) {
+ private Properties tryGetProperties(String svcOperation, Properties parms, ResponseObject error) {
try {
if (svcLogicClient.hasGraph(APP_NAME, svcOperation, null, "sync")) {
@@ -1853,7 +1853,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
String ackFinal = "Y";
String allottedResourceId = ERROR_NETWORK_ID;
String serviceObjectPath = null;
@@ -1869,7 +1869,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
brgObjectPath = respProps.getProperty("brg-object-path");
}
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getMessage());
responseBuilder.setAckFinalIndicator(ackFinal);
@@ -1926,7 +1926,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private void trySetResponseMessage(BrgTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(BrgTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
@@ -2014,11 +2014,11 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
Properties respProps = tryGetProperties(svcOperation, parms, error);
String ackFinal = resolveAckFinal(error, respProps);
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getMessage());
@@ -2083,7 +2083,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return Futures.immediateFuture(rpcResult);
}
- private String resolveAckFinal(ErrorObject error, Properties respProps) {
+ private String resolveAckFinal(ResponseObject error, Properties respProps) {
if (respProps != null) {
error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
@@ -2092,7 +2092,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
return "Y";
}
- private void trySetResponseMessage(PreloadVnfTopologyOperationOutputBuilder responseBuilder, ErrorObject error) {
+ private void trySetResponseMessage(PreloadVnfTopologyOperationOutputBuilder responseBuilder, ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
@@ -2206,12 +2206,12 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
// Call SLI sync method
// Get SvcLogicService reference
- ErrorObject error = new ErrorObject("200", "");
+ ResponseObject error = new ResponseObject("200", "");
Properties respProps = tryGetProperties(svcOperation, parms, error);
String ackFinal = resolveAckFinal(error, respProps);
- if (isValidErrorObject(error)) {
+ if (failed(error)) {
responseBuilder.setResponseCode(error.getStatusCode());
responseBuilder.setResponseMessage(error.getMessage());
@@ -2277,7 +2277,7 @@ public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURC
}
private void trySetResponseMessage(PreloadNetworkTopologyOperationOutputBuilder responseBuilder,
- ErrorObject error) {
+ ResponseObject error) {
if (!error.getMessage().isEmpty()) {
responseBuilder.setResponseMessage(error.getMessage());
}
diff --git a/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/ErrorObject.java b/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/ResponseObject.java
index 5fe72cb4..a3ff2e2f 100644
--- a/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/ErrorObject.java
+++ b/generic-resource-api/provider/src/main/java/org/onap/sdnc/northbound/ResponseObject.java
@@ -1,13 +1,13 @@
package org.onap.sdnc.northbound;
-public class ErrorObject {
+public class ResponseObject {
private static final String EMPTY_STRING = "";
private String statusCode;
private String message;
- public ErrorObject(String statusCode, String message) {
+ public ResponseObject(String statusCode, String message) {
this.statusCode = statusCode == null ? EMPTY_STRING : statusCode;
this.message = message == null ? EMPTY_STRING : message;
}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiProviderTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiProviderTest.java
index a6568005..6bf6959e 100644
--- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiProviderTest.java
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiProviderTest.java
@@ -22,6 +22,7 @@
package org.onap.sdnc.northbound;
import org.junit.Before;
+import org.junit.Test;
import org.mockito.Mock;
import org.onap.sdnc.northbound.util.DataBrokerUtil;
import org.onap.sdnc.northbound.util.GenericResourceApiSvcLogicServiceClientMockUtil;
@@ -36,12 +37,13 @@ import org.slf4j.LoggerFactory;
public class GenericResourceApiProviderTest extends AbstractConcurrentDataBrokerTest {
+ protected static final Logger LOG = LoggerFactory.getLogger(GenericResourceApiProvider.class);
protected GenericResourceApiProvider genericResourceApiProvider;
protected DataBroker dataBroker;
protected @Mock NotificationPublishService mockNotificationPublishService;
protected @Mock RpcProviderRegistry mockRpcProviderRegistry;
protected @Mock GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient;
- protected static final Logger LOG = LoggerFactory.getLogger(GenericResourceApiProvider.class);
+
protected DataBrokerUtil db;
@@ -70,6 +72,4 @@ public class GenericResourceApiProviderTest extends AbstractConcurrentDataBroker
public static PropBuilder prop(){
return (new PropBuilder());
}
-
-
}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java
index 9a34c253..b4ce214a 100644
--- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java
@@ -21,13 +21,37 @@
package org.onap.sdnc.northbound;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.sdnc.northbound.GenericResourceApiProvider.APP_NAME;
+import static org.onap.sdnc.northbound.GenericResourceApiProvider.NO_SERVICE_LOGIC_ACTIVE;
+import static org.onap.sdnc.northbound.GenericResourceApiProvider.NULL_OR_EMPTY_ERROR_PARAM;
+import static org.onap.sdnc.northbound.util.MDSALUtil.build;
+import static org.onap.sdnc.northbound.util.MDSALUtil.exec;
+import static org.onap.sdnc.northbound.util.MDSALUtil.requestInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.sdncRequestHeader;
+import static org.onap.sdnc.northbound.util.MDSALUtil.service;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceData;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceInformationBuilder;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceResponseInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceStatus;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceTopologyOperationInput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceTopologyOperationOutput;
+
+import javax.xml.crypto.Data;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.sdnc.northbound.util.PropBuilder;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInput;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutput;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
@@ -36,21 +60,10 @@ import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.re
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformation;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.Service;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatus;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import static org.junit.Assert.assertEquals;
-import static org.onap.sdnc.northbound.util.MDSALUtil.build;
-import static org.onap.sdnc.northbound.util.MDSALUtil.exec;
-import static org.onap.sdnc.northbound.util.MDSALUtil.requestInformation;
-import static org.onap.sdnc.northbound.util.MDSALUtil.sdncRequestHeader;
-import static org.onap.sdnc.northbound.util.MDSALUtil.service;
-import static org.onap.sdnc.northbound.util.MDSALUtil.serviceData;
-import static org.onap.sdnc.northbound.util.MDSALUtil.serviceInformationBuilder;
-import static org.onap.sdnc.northbound.util.MDSALUtil.serviceResponseInformation;
-import static org.onap.sdnc.northbound.util.MDSALUtil.serviceStatus;
-import static org.onap.sdnc.northbound.util.MDSALUtil.serviceTopologyOperationInput;
-import static org.onap.sdnc.northbound.util.MDSALUtil.serviceTopologyOperationOutput;
-
/**
* This class test the ServiceTopologyOperation mdsal RPC.
@@ -70,13 +83,12 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT
/**
- * Verify ServiceTopologyOperation RPC executes a DG then produces the expected
- * {@link ServiceTopologyOperationOutput} and persisted the expected {@link Service} in the {@link DataBroker}
+ * Verify ServiceTopologyOperation RPC executes a DG then produces the expected {@link
+ * ServiceTopologyOperationOutput} and persisted the expected {@link Service} in the {@link DataBroker}
*/
@Test
public void testServiceTopologyOperationRPC_ExecuteDG_Success() throws Exception {
-
//mock svcClient to perform a successful execution with the expected parameters
svcClient.mockHasGraph(true);
PropBuilder svcResultProp = svcClient.createExecuteOKResult();
@@ -87,103 +99,192 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT
//execute the mdsal exec
ServiceTopologyOperationOutput actualServiceTopologyOperationOutput = exec(
- genericResourceApiProvider::serviceTopologyOperation
- , serviceTopologyOperationInput
- , RpcResult::getResult
+ genericResourceApiProvider::serviceTopologyOperation
+ , serviceTopologyOperationInput
+ , RpcResult::getResult
);
-
//verify the returned ServiceTopologyOperationOutput
- ServiceTopologyOperationOutput expectedServiceTopologyOperationOutput = createExpectedSTOO(svcResultProp,serviceTopologyOperationInput);
- assertEquals(expectedServiceTopologyOperationOutput,actualServiceTopologyOperationOutput);
-
+ ServiceTopologyOperationOutput expectedServiceTopologyOperationOutput = createExpectedSTOO(svcResultProp,
+ serviceTopologyOperationInput);
+ assertEquals(expectedServiceTopologyOperationOutput, actualServiceTopologyOperationOutput);
//verify the persisted Service
- Service actualService = db.read(serviceTopologyOperationInput.getServiceInformation().getServiceInstanceId(), LogicalDatastoreType.CONFIGURATION);
+ Service actualService = db.read(serviceTopologyOperationInput.getServiceInformation().getServiceInstanceId(),
+ LogicalDatastoreType.CONFIGURATION);
Service expectedService = createExpectedService(
- expectedServiceTopologyOperationOutput,
- serviceTopologyOperationInput,
- actualService);
- assertEquals(expectedService,actualService);
+ expectedServiceTopologyOperationOutput,
+ serviceTopologyOperationInput,
+ actualService);
+ assertEquals(expectedService, actualService);
LOG.debug("done");
}
+ @Test
+ public void serviceTopologyOperation_should_fail_when_service_info_not_present() throws Exception {
+ // create the ServiceTopologyOperationInput from the template
+ ServiceTopologyOperationInput input = build(
+ serviceTopologyOperationInput()
+ .setSdncRequestHeader(build(sdncRequestHeader()
+ .setSvcRequestId("svc-request-id: xyz")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setRequestInformation(build(requestInformation()
+ .setRequestId("request-id: xyz")
+ .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
+ )));
+
+ //execute the mdsal exec
+ ServiceTopologyOperationOutput output = exec(
+ genericResourceApiProvider::serviceTopologyOperation
+ , input
+ , RpcResult::getResult
+ );
+
+ assertEquals("404", output.getResponseCode());
+ assertEquals(NULL_OR_EMPTY_ERROR_PARAM, output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+ }
+
+
+ @Test
+ public void serviceTopologyOperation_should_fail_when_client_execution_failed() throws Exception {
+ svcClient.mockHasGraph(true);
+ svcClient.mockExecute(new RuntimeException("test exception"));
+
+ ServiceTopologyOperationInput input = createSTOI();
+
+ //execute the mdsal exec
+ ServiceTopologyOperationOutput output = exec(
+ genericResourceApiProvider::serviceTopologyOperation
+ , input
+ , RpcResult::getResult
+ );
+
+ assertEquals("500", output.getResponseCode());
+ assertEquals("test exception", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+ }
+
+ @Test
+ public void serviceTopologyOperation_should_fail_when_client_has_no_graph() throws Exception {
+ svcClient.mockHasGraph(false);
+
+ ServiceTopologyOperationInput input = createSTOI();
+
+ //execute the mdsal exec
+ ServiceTopologyOperationOutput output = exec(
+ genericResourceApiProvider::serviceTopologyOperation
+ , input
+ , RpcResult::getResult
+ );
+
+ assertEquals("503", output.getResponseCode());
+ assertEquals(NO_SERVICE_LOGIC_ACTIVE + APP_NAME + ": '" + SVC_OPERATION + "'", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+ }
+
+ @Test
+ public void serviceTopologyOperation_should_fail_when_failed_to_update_mdsal() throws Exception {
- private ServiceTopologyOperationInput createSTOI()
- {
+ svcClient.mockHasGraph(true);
+ WriteTransaction mockWriteTransaction = mock(WriteTransaction.class);
+ when(mockWriteTransaction.submit()).thenThrow(new TransactionChainClosedException("test exception"));
+
+ DataBroker spyDataBroker = Mockito.spy(dataBroker);
+ when(spyDataBroker.newWriteOnlyTransaction()).thenReturn(mockWriteTransaction);
+ genericResourceApiProvider.setDataBroker(spyDataBroker);
+
+ ServiceTopologyOperationInput input = createSTOI();
+
+ //execute the mdsal exec
+ ServiceTopologyOperationOutput output = exec(
+ genericResourceApiProvider::serviceTopologyOperation
+ , input
+ , RpcResult::getResult
+ );
+
+ assertEquals("500", output.getResponseCode());
+ assertEquals("test exception", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+ }
+
+
+
+ private ServiceTopologyOperationInput createSTOI() {
return build(
- serviceTopologyOperationInput()
- .setSdncRequestHeader(build(sdncRequestHeader()
- .setSvcRequestId("svc-request-id: xyz")
- .setSvcAction(SvcAction.Assign)
- ))
- .setRequestInformation(build(requestInformation()
- .setRequestId("request-id: xyz")
- .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
- ))
- .setServiceInformation(build(serviceInformationBuilder()
- .setServiceInstanceId("service-instance-id: xyz")
- ))
+ serviceTopologyOperationInput()
+ .setSdncRequestHeader(build(sdncRequestHeader()
+ .setSvcRequestId("svc-request-id: xyz")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setRequestInformation(build(requestInformation()
+ .setRequestId("request-id: xyz")
+ .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
+ ))
+ .setServiceInformation(build(serviceInformationBuilder()
+ .setServiceInstanceId("service-instance-id: xyz")
+ ))
);
}
- private ServiceTopologyOperationOutput createExpectedSTOO(PropBuilder expectedSvcResultProp,ServiceTopologyOperationInput expectedServiceTopologyOperationInput){
+ private ServiceTopologyOperationOutput createExpectedSTOO(PropBuilder expectedSvcResultProp,
+ ServiceTopologyOperationInput expectedServiceTopologyOperationInput) {
return build(
- serviceTopologyOperationOutput()
- .setSvcRequestId(expectedServiceTopologyOperationInput.getSdncRequestHeader().getSvcRequestId())
- .setResponseCode(expectedSvcResultProp.get(svcClient.errorCode))
- .setAckFinalIndicator(expectedSvcResultProp.get(svcClient.ackFinal))
- .setResponseMessage(expectedSvcResultProp.get(svcClient.errorMessage))
- .setServiceResponseInformation(build(serviceResponseInformation()
- .setInstanceId(expectedServiceTopologyOperationInput.getServiceInformation().getServiceInstanceId())
- .setObjectPath(expectedSvcResultProp.get(svcClient.serviceObjectPath))
- ))
+ serviceTopologyOperationOutput()
+ .setSvcRequestId(expectedServiceTopologyOperationInput.getSdncRequestHeader().getSvcRequestId())
+ .setResponseCode(expectedSvcResultProp.get(svcClient.errorCode))
+ .setAckFinalIndicator(expectedSvcResultProp.get(svcClient.ackFinal))
+ .setResponseMessage(expectedSvcResultProp.get(svcClient.errorMessage))
+ .setServiceResponseInformation(build(serviceResponseInformation()
+ .setInstanceId(expectedServiceTopologyOperationInput.getServiceInformation().getServiceInstanceId())
+ .setObjectPath(expectedSvcResultProp.get(svcClient.serviceObjectPath))
+ ))
);
}
private Service createExpectedService(
- ServiceTopologyOperationOutput expectedServiceTopologyOperationOutput,
- ServiceTopologyOperationInput expectedServiceTopologyOperationInput,
- Service actualService
- ){
-
+ ServiceTopologyOperationOutput expectedServiceTopologyOperationOutput,
+ ServiceTopologyOperationInput expectedServiceTopologyOperationInput,
+ Service actualService
+ ) {
//We cannot predict the timeStamp value so just steal it from the actual
//we need this to prevent the equals method from returning false as a result of the timestamp
- String responseTimeStamp = actualService == null || actualService.getServiceStatus() == null?
- null : actualService.getServiceStatus().getResponseTimestamp();
+ String responseTimeStamp = actualService == null || actualService.getServiceStatus() == null ?
+ null : actualService.getServiceStatus().getResponseTimestamp();
SdncRequestHeader expectedSdncRequestHeader = expectedServiceTopologyOperationInput.getSdncRequestHeader();
ServiceInformation expectedServiceInformation = expectedServiceTopologyOperationInput.getServiceInformation();
RequestInformation expectedRequestInformation = expectedServiceTopologyOperationInput.getRequestInformation();
return build(
- service()
+ service()
.setServiceInstanceId(expectedServiceInformation.getServiceInstanceId())
.setServiceData(build(serviceData()))
.setServiceStatus(
- build(
- serviceStatus()
- .setAction(expectedRequestInformation.getRequestAction().name())
- .setFinalIndicator(expectedServiceTopologyOperationOutput.getAckFinalIndicator())
- .setResponseCode(expectedServiceTopologyOperationOutput.getResponseCode())
- .setResponseMessage(expectedServiceTopologyOperationOutput.getResponseMessage())
- .setRpcAction(toRpcAction(expectedSdncRequestHeader.getSvcAction()))
- .setRpcName(SVC_OPERATION)
- .setRequestStatus(ServiceStatus.RequestStatus.Synccomplete)
- .setResponseTimestamp(responseTimeStamp)
- )
+ build(
+ serviceStatus()
+ .setAction(expectedRequestInformation.getRequestAction().name())
+ .setFinalIndicator(expectedServiceTopologyOperationOutput.getAckFinalIndicator())
+ .setResponseCode(expectedServiceTopologyOperationOutput.getResponseCode())
+ .setResponseMessage(expectedServiceTopologyOperationOutput.getResponseMessage())
+ .setRpcAction(toRpcAction(expectedSdncRequestHeader.getSvcAction()))
+ .setRpcName(SVC_OPERATION)
+ .setRequestStatus(ServiceStatus.RequestStatus.Synccomplete)
+ .setResponseTimestamp(responseTimeStamp)
+ )
)
);
}
- public ServiceStatus.RpcAction toRpcAction(SvcAction fromEnum){
- return fromEnum == null? null : ServiceStatus.RpcAction.valueOf(fromEnum.name());
+ public ServiceStatus.RpcAction toRpcAction(SvcAction fromEnum) {
+ return fromEnum == null ? null : ServiceStatus.RpcAction.valueOf(fromEnum.name());
}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java
index 2e73cce7..650147fd 100644
--- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java
@@ -21,17 +21,16 @@
package org.onap.sdnc.northbound.util;
-import org.onap.sdnc.northbound.GenericResourceApiSvcLogicServiceClient;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
-
-import java.util.Properties;
-
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.isA;
import static org.mockito.Mockito.when;
import static org.onap.sdnc.northbound.util.MDSALUtil.build;
import static org.onap.sdnc.northbound.util.PropBuilder.propBuilder;
+import java.util.Properties;
+import org.onap.sdnc.northbound.GenericResourceApiSvcLogicServiceClient;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
+
/**
* GenericResourceApiSvcLogicServiceClientMockUtil provides a set of util methods for quickly configuring method
@@ -75,15 +74,13 @@ public class GenericResourceApiSvcLogicServiceClientMockUtil {
*/
public void mockHasGraph(Boolean isHasGraph) throws Exception {
when(
- mockGenericResourceApiSvcLogicServiceClient
- .hasGraph(
- eq(MODULE),
- eq(scvOperation),
- eq(VERSION),
- eq(MODE)
- )
- )
- .thenReturn(isHasGraph);
+ mockGenericResourceApiSvcLogicServiceClient
+ .hasGraph(
+ eq(MODULE),
+ eq(scvOperation),
+ eq(VERSION),
+ eq(MODE))
+ ).thenReturn(isHasGraph);
}
@@ -112,19 +109,29 @@ public class GenericResourceApiSvcLogicServiceClientMockUtil {
*/
public void mockExecute(PropBuilder svcResultProp) throws Exception{
when(
- mockGenericResourceApiSvcLogicServiceClient
- .execute(
- eq(MODULE),
- eq(scvOperation),
- eq(VERSION),
- eq(MODE),
- isA(ServiceDataBuilder.class),
- isA(Properties.class)
- )
- )
- .thenReturn(build(
- svcResultProp
- ));
+ mockGenericResourceApiSvcLogicServiceClient
+ .execute(
+ eq(MODULE),
+ eq(scvOperation),
+ eq(VERSION),
+ eq(MODE),
+ isA(ServiceDataBuilder.class),
+ isA(Properties.class))
+ ).thenReturn(build(svcResultProp));
+ }
+
+ public void mockExecute(RuntimeException exception) throws Exception{
+ when(
+ mockGenericResourceApiSvcLogicServiceClient
+ .execute(
+ eq(MODULE),
+ eq(scvOperation),
+ eq(VERSION),
+ eq(MODE),
+ isA(ServiceDataBuilder.class),
+ isA(Properties.class)
+ )
+ ).thenThrow(exception);
}
}