summaryrefslogtreecommitdiffstats
path: root/generic-resource-api/provider/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'generic-resource-api/provider/src/test')
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiProviderTest.java73
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiSvcLogicServiceClientTest.java4
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/NetworkTopologyOperationRPCTest.java (renamed from generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/TestGenericResourceApi.java)84
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java192
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java124
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java158
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/PropBuilder.java62
7 files changed, 626 insertions, 71 deletions
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
new file mode 100644
index 00000000..a0116016
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiProviderTest.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdnc.northbound;
+
+import org.junit.Before;
+import org.mockito.Mock;
+import org.onap.sdnc.northbound.util.GenericResourceApiSvcLogicServiceClientMockUtil;
+import org.onap.sdnc.northbound.util.PropBuilder;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class GenericResourceApiProviderTest extends AbstractConcurrentDataBrokerTest {
+
+ 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 GenericResourceApiSvcLogicServiceClientMockUtil svcClient;
+
+
+ @Before
+ public void setUp() throws Exception {
+ svcClient = new GenericResourceApiSvcLogicServiceClientMockUtil(mockGenericResourceApiSvcLogicServiceClient);
+
+ dataBroker = getDataBroker();
+ try {
+ genericResourceApiProvider = new GenericResourceApiProvider(
+ dataBroker,
+ mockNotificationPublishService,
+ mockRpcProviderRegistry,
+ mockGenericResourceApiSvcLogicServiceClient
+ );
+ } catch (Exception e) {
+ LOG.error("Caught exception on setUp", e);
+ throw e;
+ }
+ }
+
+
+ public static PropBuilder prop(){
+ return (new PropBuilder());
+ }
+
+
+}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiSvcLogicServiceClientTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiSvcLogicServiceClientTest.java
index cb827094..30015720 100644
--- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiSvcLogicServiceClientTest.java
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiSvcLogicServiceClientTest.java
@@ -36,7 +36,9 @@ import org.slf4j.Logger;
import java.util.Properties;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
public class GenericResourceApiSvcLogicServiceClientTest {
private static final String MODE = "mode";
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/TestGenericResourceApi.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/NetworkTopologyOperationRPCTest.java
index 939ada80..29ef1b4f 100644
--- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/TestGenericResourceApi.java
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/NetworkTopologyOperationRPCTest.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,83 +21,24 @@
package org.onap.sdnc.northbound;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import org.junit.Before;
import org.junit.Test;
-import static org.mockito.Mockito.mock;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutput;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder;
-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.NetworkTopologyOperationOutput;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.information.NetworkInformationBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation.RequestAction;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformationBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader.SvcAction;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeaderBuilder;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformationBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class TestGenericResourceApi extends AbstractConcurrentDataBrokerTest {
-
- private GenericResourceApiProvider genericResourceApiProvider;
- private static final Logger LOG = LoggerFactory.getLogger(GenericResourceApiProvider.class);
-
- @Before
- public void setUp() throws Exception {
- if (null == genericResourceApiProvider) {
- DataBroker dataBroker = getDataBroker();
- NotificationPublishService mockNotification = mock(NotificationPublishService.class);
- RpcProviderRegistry mockRpcRegistry = mock(RpcProviderRegistry.class);
- GenericResourceApiSvcLogicServiceClient client = mock(GenericResourceApiSvcLogicServiceClient.class);
- try {
- genericResourceApiProvider = new GenericResourceApiProvider(dataBroker, mockNotification, mockRpcRegistry, client);
- } catch (Exception e) {
- LOG.error("Caught exception on setUp", e);
- throw e;
- }
- }
- }
-
- @Test
- public void testServiceTopologyOperation() {
-
- ServiceTopologyOperationInputBuilder inputBuilder = new ServiceTopologyOperationInputBuilder();
-
- SdncRequestHeaderBuilder sdncRequestHeaderBuilder = new SdncRequestHeaderBuilder();
- sdncRequestHeaderBuilder.setSvcRequestId("1111");
- sdncRequestHeaderBuilder.setSvcAction(SvcAction.Assign);
- inputBuilder.setSdncRequestHeader(sdncRequestHeaderBuilder.build());
-
- RequestInformationBuilder requestInformationBuilder = new RequestInformationBuilder();
- requestInformationBuilder.setRequestId("1111");
- requestInformationBuilder.setRequestAction(RequestAction.CreateServiceInstance);
- inputBuilder.setRequestInformation(requestInformationBuilder.build());
- ServiceInformationBuilder serviceInformationBuilder = new ServiceInformationBuilder();
- serviceInformationBuilder.setServiceInstanceId("1111");
- inputBuilder.setServiceInformation(serviceInformationBuilder.build());
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
- // TODO: currently initialize GenericResourceApiSvcLogicServiceClient is failing, need to fix
- java.util.concurrent.Future<RpcResult<ServiceTopologyOperationOutput>> future = genericResourceApiProvider
- .serviceTopologyOperation(inputBuilder.build());
- RpcResult<ServiceTopologyOperationOutput> rpcResult = null;
- try {
- rpcResult = future.get();
- } catch (Exception e) {
- fail("Error : " + e);
- }
- LOG.info("result: {}", rpcResult);
- assertEquals("1111", rpcResult.getResult().getSvcRequestId());
- }
+@RunWith(MockitoJUnitRunner.class)
+public class NetworkTopologyOperationRPCTest extends GenericResourceApiProviderTest {
@Test
public void testNetworkTopologyOperation() {
@@ -111,7 +52,7 @@ public class TestGenericResourceApi extends AbstractConcurrentDataBrokerTest {
RequestInformationBuilder requestInformationBuilder = new RequestInformationBuilder();
requestInformationBuilder.setRequestId("1111");
- requestInformationBuilder.setRequestAction(RequestAction.CreateNetworkInstance);
+ requestInformationBuilder.setRequestAction(RequestInformation.RequestAction.CreateNetworkInstance);
inputBuilder.setRequestInformation(requestInformationBuilder.build());
ServiceInformationBuilder serviceInformationBuilder = new ServiceInformationBuilder();
@@ -122,7 +63,7 @@ public class TestGenericResourceApi extends AbstractConcurrentDataBrokerTest {
inputBuilder.setNetworkInformation(networkInformationBuilder.build());
java.util.concurrent.Future<RpcResult<NetworkTopologyOperationOutput>> future = genericResourceApiProvider
- .networkTopologyOperation(inputBuilder.build());
+ .networkTopologyOperation(inputBuilder.build());
RpcResult<NetworkTopologyOperationOutput> rpcResult = null;
try {
rpcResult = future.get();
@@ -132,4 +73,7 @@ public class TestGenericResourceApi extends AbstractConcurrentDataBrokerTest {
LOG.info("result: {}", rpcResult);
assertEquals("1111", rpcResult.getResult().getSvcRequestId());
}
+
+
+
}
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
new file mode 100644
index 00000000..aa0d28a7
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java
@@ -0,0 +1,192 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdnc.northbound;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.common.api.data.LogicalDatastoreType;
+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;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation.RequestAction;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader.SvcAction;
+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.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.read;
+import static org.onap.sdnc.northbound.util.MDSALUtil.requestInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.rpc;
+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.
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderTest {
+
+
+ final String SVC_OPERATION = "service-topology-operation";
+
+
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ svcClient.setScvOperation(SVC_OPERATION);
+ }
+
+
+ /**
+ * 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();
+ svcClient.mockExecute(svcResultProp);
+
+ // create the ServiceTopologyOperationInput from the template
+ ServiceTopologyOperationInput serviceTopologyOperationInput = createSTOI(RequestAction.CreateServiceInstance);
+
+ //execute the mdsal rpc
+ ServiceTopologyOperationOutput actualServiceTopologyOperationOutput = rpc(
+ genericResourceApiProvider::serviceTopologyOperation
+ , RpcResult::getResult
+ , serviceTopologyOperationInput
+ );
+
+
+ //verify the returned ServiceTopologyOperationOutput
+ ServiceTopologyOperationOutput expectedServiceTopologyOperationOutput = createExpectedSTOO(svcResultProp,serviceTopologyOperationInput);
+ assertEquals(expectedServiceTopologyOperationOutput,actualServiceTopologyOperationOutput);
+
+
+ //verify the persisted Service
+ Service actualService = read(dataBroker,serviceTopologyOperationInput.getServiceInformation().getServiceInstanceId(), LogicalDatastoreType.CONFIGURATION);
+ Service expectedService = createExpectedService(
+ expectedServiceTopologyOperationOutput,
+ serviceTopologyOperationInput,
+ actualService);
+ assertEquals(expectedService,actualService);
+
+ LOG.debug("done");
+ }
+
+
+
+ private ServiceTopologyOperationInput createSTOI(RequestAction requestAction)
+ {
+
+ 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")
+ ))
+ );
+ }
+
+
+ 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))
+ ))
+ );
+ }
+
+ private Service createExpectedService(
+ 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();
+
+ SdncRequestHeader expectedSdncRequestHeader = expectedServiceTopologyOperationInput.getSdncRequestHeader();
+ ServiceInformation expectedServiceInformation = expectedServiceTopologyOperationInput.getServiceInformation();
+ RequestInformation expectedRequestInformation = expectedServiceTopologyOperationInput.getRequestInformation();
+
+ return build(
+ 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)
+ )
+ )
+ );
+
+ }
+
+ 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
new file mode 100644
index 00000000..cd6280b7
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java
@@ -0,0 +1,124 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+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;
+
+
+/**
+ * GenericResourceApiSvcLogicServiceClientMockUtil provides a set of util methods for quickly configuring method
+ * behaviour on the Mock GenericResourceApiSvcLogicServiceClient
+ */
+public class GenericResourceApiSvcLogicServiceClientMockUtil {
+
+
+ private final String MODULE = "generic-resource-api";
+ private final String MODE = "sync";
+ private final String VERSION = null;
+ private String scvOperation = null;
+
+
+ public final String errorCode = "error-code";
+ public final String errorMessage = "error-message";
+ public final String ackFinal = "ack-final";
+ public final String serviceObjectPath = "service-object-path";
+
+ private final GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient;
+
+
+
+ public GenericResourceApiSvcLogicServiceClientMockUtil(GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient) {
+ this.mockGenericResourceApiSvcLogicServiceClient = mockGenericResourceApiSvcLogicServiceClient;
+ }
+
+
+ /** @param scvOperation - The scvOperation parameter to use on the {@link GenericResourceApiSvcLogicServiceClient} methods */
+ public void setScvOperation(String scvOperation) {
+ this.scvOperation = scvOperation;
+ }
+
+ /**
+ * Configure {@link GenericResourceApiSvcLogicServiceClient#hasGraph(String, String, String, String)}
+ * to return the specified value when when invoked with the parameters
+ * {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link #scvOperation}
+ */
+ public void mockHasGraph(Boolean isHasGraph) throws Exception {
+ when(
+ mockGenericResourceApiSvcLogicServiceClient
+ .hasGraph(
+ eq(MODULE),
+ eq(scvOperation),
+ eq(VERSION),
+ eq(MODE)
+ )
+ )
+ .thenReturn(isHasGraph);
+ }
+
+
+ /**
+ * @return
+ * PropBuilder - A PropBuilder populated with the expected properties returned from
+ * {@link GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String, ServiceDataBuilder, Properties)}
+ */
+ public PropBuilder createExecuteOKResult(){
+ return propBuilder()
+ .set(errorCode,"200")
+ .set(errorMessage,"OK")
+ .set(ackFinal,"Y")
+ .set(serviceObjectPath,"XYZ");
+ }
+
+
+ /**
+ * Configure
+ * {@link GenericResourceApiSvcLogicServiceClient#execute(String, String, String, String, ServiceDataBuilder, Properties)}
+ * to return the specified svcResultProp when when invoked with the parameters
+ * {@link #MODULE}, {@link #MODE}, {@link #VERSION} and {@link #scvOperation}
+ */
+ 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
+ ));
+ }
+
+}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java
new file mode 100644
index 00000000..6586c8e3
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java
@@ -0,0 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdnc.northbound.util;
+
+import com.google.common.base.Optional;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.Services;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformationBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeaderBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformationBuilder;
+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.model.infrastructure.ServiceBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.ServiceKey;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.response.information.ServiceResponseInformationBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatusBuilder;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+import java.util.concurrent.Future;
+import java.util.function.Function;
+
+
+/**
+ * This uill class provides utility to build yang objects using a recursive syntax that resembles the tree structure
+ * when defining the same yang object in json format.
+ *
+ * For Example
+ * <pre>
+ * {@code
+ * import static org.onap.sdnc.northbound.util.MDSALUtil.*;
+ * 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)
+ * ))
+ * .setServiceInformation(build(serviceInformationBuilder()
+ * .setServiceInstanceId("service-instance-id: xyz")
+ * ))
+ * );
+ * }
+ * </pre>
+ */
+public class MDSALUtil {
+
+ public static ServiceTopologyOperationInputBuilder serviceTopologyOperationInput() {
+ return new ServiceTopologyOperationInputBuilder();
+ }
+
+
+ public static ServiceTopologyOperationOutputBuilder serviceTopologyOperationOutput(){
+ return new ServiceTopologyOperationOutputBuilder();
+ }
+
+
+ public static SdncRequestHeaderBuilder sdncRequestHeader() {
+ return new SdncRequestHeaderBuilder();
+ }
+
+
+ public static RequestInformationBuilder requestInformation() {
+ return new RequestInformationBuilder();
+ }
+
+ public static ServiceResponseInformationBuilder serviceResponseInformation(){
+ return new ServiceResponseInformationBuilder();
+ }
+
+ public static ServiceInformationBuilder serviceInformationBuilder() {
+ return new ServiceInformationBuilder();
+ }
+
+
+ public static ServiceBuilder service(){return new ServiceBuilder();}
+
+
+ public static ServiceDataBuilder serviceData(){return new ServiceDataBuilder();}
+
+
+ public static ServiceStatusBuilder serviceStatus(){return new ServiceStatusBuilder();}
+
+ public static <P> P build(Builder<P> b) {
+ return b == null? null :b.build();
+ }
+
+ public static <O> O result(Future<RpcResult<O>> future, Function<RpcResult<O>,O> function) throws Exception {
+ return function.apply(future.get());
+ }
+
+ public static <I,O> O rpc(Function<I,Future<RpcResult<O>>> rpc,Function<RpcResult<O>,O> function,I input) throws Exception {
+ Future<RpcResult<O>> future = rpc.apply(input);
+ return function.apply(future.get());
+ }
+
+
+
+ /** @return Service - the Service object read from the DataBroker or null if none was found */
+ public static Service read(DataBroker dataBroker,String serviceKey, LogicalDatastoreType logicalDatastoreType) throws Exception {
+ InstanceIdentifier serviceInstanceIdentifier = InstanceIdentifier.<Services>builder(Services.class)
+ .child(Service.class, new ServiceKey(serviceKey)).build();
+ ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
+ Optional<Service> data = (Optional<Service>) readTx.read(logicalDatastoreType, serviceInstanceIdentifier).get();
+ if(!data.isPresent()){
+ return null;
+ }
+
+
+ //The toString() value from a Service object returned form data.get() is different than the toString() value
+ //from a Service Object constructed from a Builder. This makes it difficult to compare deltas when doing a
+ // assertEquals. That why we rebuild it her to solve that problem.
+ Service service = data.get();
+ return build(
+ (new ServiceBuilder(service))
+ .setServiceStatus(build(
+ service.getServiceStatus() == null ? null : new ServiceStatusBuilder(service.getServiceStatus())
+ ))
+ .setServiceData(build(
+ service.getServiceData() == null ? null : new ServiceDataBuilder(service.getServiceData())
+ ))
+ );
+ }
+
+
+
+
+
+
+
+}
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/PropBuilder.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/PropBuilder.java
new file mode 100644
index 00000000..b1a07016
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/PropBuilder.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdnc.northbound.util;
+
+import org.opendaylight.yangtools.concepts.Builder;
+
+import java.util.Properties;
+
+/**
+ * A Util class that adds method chaining to the {@link #set(String, String)} to reducing the syntax needed to populate
+ * {@link Properties}
+ */
+public class PropBuilder implements Builder<Properties> {
+
+
+ final Properties prop;
+
+ public PropBuilder(Properties prop) {
+ this.prop = prop;
+ }
+
+ public PropBuilder() {
+ this.prop = new Properties();
+ }
+
+ public Properties build(){
+ return prop;
+ }
+
+ public PropBuilder set(String key, String value) {
+ prop.setProperty(key, value);
+ return this;
+ }
+
+ public String get(String key) {
+ return prop.getProperty(key);
+ }
+
+
+ public static PropBuilder propBuilder(){
+ return (new PropBuilder());
+ }
+} \ No newline at end of file