summaryrefslogtreecommitdiffstats
path: root/generic-resource-api/provider
diff options
context:
space:
mode:
Diffstat (limited to 'generic-resource-api/provider')
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/GenericResourceApiProviderTest.java4
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/NetworkTopologyOperationRPCTest.java240
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java16
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/DataBrokerUtil.java110
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/GenericResourceApiSvcLogicServiceClientMockUtil.java8
-rw-r--r--generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/MDSALUtil.java75
6 files changed, 361 insertions, 92 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
index a0116016..a6568005 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
@@ -23,6 +23,7 @@ package org.onap.sdnc.northbound;
import org.junit.Before;
import org.mockito.Mock;
+import org.onap.sdnc.northbound.util.DataBrokerUtil;
import org.onap.sdnc.northbound.util.GenericResourceApiSvcLogicServiceClientMockUtil;
import org.onap.sdnc.northbound.util.PropBuilder;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -43,14 +44,15 @@ public class GenericResourceApiProviderTest extends AbstractConcurrentDataBroker
protected static final Logger LOG = LoggerFactory.getLogger(GenericResourceApiProvider.class);
+ protected DataBrokerUtil db;
protected GenericResourceApiSvcLogicServiceClientMockUtil svcClient;
@Before
public void setUp() throws Exception {
svcClient = new GenericResourceApiSvcLogicServiceClientMockUtil(mockGenericResourceApiSvcLogicServiceClient);
-
dataBroker = getDataBroker();
+ db = new DataBrokerUtil(dataBroker);
try {
genericResourceApiProvider = new GenericResourceApiProvider(
dataBroker,
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/NetworkTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/NetworkTopologyOperationRPCTest.java
index 29ef1b4f..31ec9cd3 100644
--- a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/NetworkTopologyOperationRPCTest.java
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/NetworkTopologyOperationRPCTest.java
@@ -21,59 +21,225 @@
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.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder;
+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.NetworkTopologyOperationInput;
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;
-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;
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.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceData;
+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 java.time.Instant;
+
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+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.networkInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.networkResponseInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.networkTopologyOperationInput;
+import static org.onap.sdnc.northbound.util.MDSALUtil.networkTopologyOperationOutput;
+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.serviceLevelOperStatus;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceResponseInformation;
+import static org.onap.sdnc.northbound.util.MDSALUtil.serviceStatus;
+import static org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.OperStatusData.LastAction;
+import static org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.OperStatusData.LastOrderStatus;
+import static org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.OperStatusData.LastRpcAction;
+import static org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.OperStatusData.OrderStatus;
+
+/**
+ * This class test the NetworkTopologyOperation mdsal RPC.
+ */
@RunWith(MockitoJUnitRunner.class)
public class NetworkTopologyOperationRPCTest extends GenericResourceApiProviderTest {
+
+ final String SVC_OPERATION = "network-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 NetworkTopologyOperationOutput} and persisted the expected {@link Service} in the {@link DataBroker}
+ */
@Test
- public void testNetworkTopologyOperation() {
-
- NetworkTopologyOperationInputBuilder inputBuilder = new NetworkTopologyOperationInputBuilder();
-
- SdncRequestHeaderBuilder sdncRequestHeaderBuilder = new SdncRequestHeaderBuilder();
- sdncRequestHeaderBuilder.setSvcRequestId("1111");
- sdncRequestHeaderBuilder.setSvcAction(SvcAction.Create);
- inputBuilder.setSdncRequestHeader(sdncRequestHeaderBuilder.build());
-
- RequestInformationBuilder requestInformationBuilder = new RequestInformationBuilder();
- requestInformationBuilder.setRequestId("1111");
- requestInformationBuilder.setRequestAction(RequestInformation.RequestAction.CreateNetworkInstance);
- inputBuilder.setRequestInformation(requestInformationBuilder.build());
-
- ServiceInformationBuilder serviceInformationBuilder = new ServiceInformationBuilder();
- serviceInformationBuilder.setServiceInstanceId("1111");
- inputBuilder.setServiceInformation(serviceInformationBuilder.build());
-
- NetworkInformationBuilder networkInformationBuilder = new NetworkInformationBuilder();
- inputBuilder.setNetworkInformation(networkInformationBuilder.build());
-
- java.util.concurrent.Future<RpcResult<NetworkTopologyOperationOutput>> future = genericResourceApiProvider
- .networkTopologyOperation(inputBuilder.build());
- RpcResult<NetworkTopologyOperationOutput> rpcResult = null;
- try {
- rpcResult = future.get();
- } catch (Exception e) {
- fail("Error : " + e);
- }
- LOG.info("result: {}", rpcResult);
- assertEquals("1111", rpcResult.getResult().getSvcRequestId());
+ public void testNetworkTopologyOperation() throws Exception {
+
+ //mock svcClient to perform a successful execution with the expected parameters
+ svcClient.mockHasGraph(true);
+ PropBuilder svcResultProp = svcClient.createExecuteOKResult();
+ svcClient.mockExecute(svcResultProp);
+
+
+ //construct the input parameter for the NetworkTopologyOperation
+ NetworkTopologyOperationInput networkTopologyOperationInput = createNTOI();
+
+
+ //pre-populate the DataBroke with the required ServiceData.
+ Service service = persistServiceInDataBroker(networkTopologyOperationInput);
+
+
+
+ //execute the mdsal exec
+ NetworkTopologyOperationOutput actualNetworkTopologyOperationOutput = exec(
+ genericResourceApiProvider::networkTopologyOperation
+ , networkTopologyOperationInput
+ , RpcResult::getResult
+ );
+
+ //verify the returned NetworkTopologyOperationOutput
+ NetworkTopologyOperationOutput expectedNetworkTopologyOperationOutput
+ = createExpectedNTOO(svcResultProp,networkTopologyOperationInput);
+ assertEquals(expectedNetworkTopologyOperationOutput,actualNetworkTopologyOperationOutput);
+
+
+ //verify the persisted Service
+ Service actualService = db.read(
+ networkTopologyOperationInput.getServiceInformation().getServiceInstanceId(),
+ LogicalDatastoreType.CONFIGURATION
+ );
+ Service expectedService = createExpectedService(
+ expectedNetworkTopologyOperationOutput,
+ networkTopologyOperationInput,
+ service.getServiceData(),
+ actualService);
+ assertEquals(expectedService,actualService);
+
}
+ private NetworkTopologyOperationInput createNTOI()
+ {
+
+ return build(
+ networkTopologyOperationInput()
+ .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")
+ ))
+ .setNetworkInformation(build(
+ networkInformation()
+ ))
+ );
+ }
+
+ private Service persistServiceInDataBroker(
+ NetworkTopologyOperationInput networkTopologyOperationInput
+ ) throws Exception{
+ Service service = build(
+ service()
+ .setServiceInstanceId(
+ networkTopologyOperationInput.getServiceInformation().getServiceInstanceId()
+ )
+ .setServiceData(build(
+ serviceData()
+ .setServiceLevelOperStatus(build(
+ serviceLevelOperStatus()
+ .setOrderStatus(OrderStatus.Created)
+ .setModifyTimestamp(Instant.now().toString())
+ .setLastSvcRequestId("svc-request-id: abc")
+ .setLastRpcAction(LastRpcAction.Activate)
+ .setLastOrderStatus(LastOrderStatus.PendingAssignment)
+ .setLastAction(LastAction.ActivateNetworkInstance)
+ .setCreateTimestamp(Instant.now().toString())
+ ))
+ ))
+
+ );
+ db.write(true,service, LogicalDatastoreType.CONFIGURATION);
+ return service;
+ }
+
+
+
+
+
+
+ private NetworkTopologyOperationOutput createExpectedNTOO(
+ PropBuilder expectedSvcResultProp,
+ NetworkTopologyOperationInput expectedNetworkTopologyOperationInput){
+ return build(
+ networkTopologyOperationOutput()
+ .setSvcRequestId(expectedNetworkTopologyOperationInput.getSdncRequestHeader().getSvcRequestId())
+ .setResponseCode(expectedSvcResultProp.get(svcClient.errorCode))
+ .setAckFinalIndicator(expectedSvcResultProp.get(svcClient.ackFinal))
+ .setResponseMessage(expectedSvcResultProp.get(svcClient.errorMessage))
+ .setServiceResponseInformation(build(serviceResponseInformation()
+ .setInstanceId(expectedNetworkTopologyOperationInput.getServiceInformation().getServiceInstanceId())
+ .setObjectPath(expectedSvcResultProp.get(svcClient.serviceObjectPath))
+ ))
+ .setNetworkResponseInformation(build(
+ networkResponseInformation()
+ .setInstanceId(expectedSvcResultProp.get(svcClient.networkId))
+ .setObjectPath(expectedSvcResultProp.get(svcClient.networkObjectPath))
+ ))
+ );
+ }
+
+ private Service createExpectedService(
+ NetworkTopologyOperationOutput expectedNetworkTopologyOperationOutput,
+ NetworkTopologyOperationInput expectedNetworkTopologyOperationInput,
+ ServiceData expectedServiceData,
+ 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 = expectedNetworkTopologyOperationInput.getSdncRequestHeader();
+ ServiceInformation expectedServiceInformation = expectedNetworkTopologyOperationInput.getServiceInformation();
+ RequestInformation expectedRequestInformation = expectedNetworkTopologyOperationInput.getRequestInformation();
+
+ return build(
+ service()
+ .setServiceInstanceId(expectedServiceInformation.getServiceInstanceId())
+ .setServiceData(build(serviceData()))
+ .setServiceData(expectedServiceData)
+ .setServiceStatus(
+ build(
+ serviceStatus()
+ )
+ )
+ );
+
+ }
+
+ 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/ServiceTopologyOperationRPCTest.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/ServiceTopologyOperationRPCTest.java
index aa0d28a7..9a34c253 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
@@ -31,7 +31,6 @@ 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;
@@ -41,9 +40,8 @@ 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.exec;
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;
@@ -85,13 +83,13 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT
svcClient.mockExecute(svcResultProp);
// create the ServiceTopologyOperationInput from the template
- ServiceTopologyOperationInput serviceTopologyOperationInput = createSTOI(RequestAction.CreateServiceInstance);
+ ServiceTopologyOperationInput serviceTopologyOperationInput = createSTOI();
- //execute the mdsal rpc
- ServiceTopologyOperationOutput actualServiceTopologyOperationOutput = rpc(
+ //execute the mdsal exec
+ ServiceTopologyOperationOutput actualServiceTopologyOperationOutput = exec(
genericResourceApiProvider::serviceTopologyOperation
- , RpcResult::getResult
, serviceTopologyOperationInput
+ , RpcResult::getResult
);
@@ -101,7 +99,7 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT
//verify the persisted Service
- Service actualService = read(dataBroker,serviceTopologyOperationInput.getServiceInformation().getServiceInstanceId(), LogicalDatastoreType.CONFIGURATION);
+ Service actualService = db.read(serviceTopologyOperationInput.getServiceInformation().getServiceInstanceId(), LogicalDatastoreType.CONFIGURATION);
Service expectedService = createExpectedService(
expectedServiceTopologyOperationOutput,
serviceTopologyOperationInput,
@@ -113,7 +111,7 @@ public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderT
- private ServiceTopologyOperationInput createSTOI(RequestAction requestAction)
+ private ServiceTopologyOperationInput createSTOI()
{
return build(
diff --git a/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/DataBrokerUtil.java b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/DataBrokerUtil.java
new file mode 100644
index 00000000..9bbb3998
--- /dev/null
+++ b/generic-resource-api/provider/src/test/java/org/onap/sdnc/northbound/util/DataBrokerUtil.java
@@ -0,0 +1,110 @@
+/*-
+ * ============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 com.google.common.util.concurrent.CheckedFuture;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+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.TransactionCommitFailedException;
+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.service.data.ServiceDataBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.level.oper.status.ServiceLevelOperStatusBuilder;
+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.status.ServiceStatusBuilder;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+import static org.onap.sdnc.northbound.util.MDSALUtil.build;
+
+
+/**
+ * This util class provides utility to read and write {@link Service} data objects from the {@link DataBroker}
+ *
+ */
+public class DataBrokerUtil {
+
+
+ private final DataBroker dataBroker;
+
+ public DataBrokerUtil(DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ /** @return Service - the Service object read from the DataBroker or null if none was found */
+ public Service read(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.
+ return build(ServiceBuilder::new,data.get(),(service) -> service
+ .setServiceStatus(build(ServiceStatusBuilder::new,service.getServiceStatus()))
+ .setServiceData(build(ServiceDataBuilder::new,service.getServiceData(),(serviceStatus)->serviceStatus
+ .setServiceLevelOperStatus(build(ServiceLevelOperStatusBuilder::new,serviceStatus.getServiceLevelOperStatus()))
+ ))
+ );
+ }
+
+
+ /**
+ * Write the {@link Service} object to the {@link DataBroker}
+ * @param isReplace - false specifies the new data is to be merged into existing data, where as true cause the
+ * existing data to be replaced.
+ * @param service - the {@link Service} data object to be presisted in the db.
+ * @param logicalDatastoreType - The logicalDatastoreType
+ */
+ public void write(boolean isReplace,Service service, LogicalDatastoreType logicalDatastoreType) throws Exception {
+ // Each entry will be identifiable by a unique key, we have to create that
+ // identifier
+ InstanceIdentifier.InstanceIdentifierBuilder<Service> serviceBuilder = InstanceIdentifier
+ .<Services>builder(Services.class).child(Service.class, service.getKey());
+ InstanceIdentifier<Service> path = serviceBuilder.build();
+
+ WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
+ if (!isReplace) {
+ tx.merge(logicalDatastoreType, path, service);
+ } else {
+ tx.put(logicalDatastoreType, path, service);
+ }
+ CheckedFuture<Void,TransactionCommitFailedException> cf = tx.submit();
+ cf.checkedGet();
+
+ }
+
+
+
+
+
+
+
+}
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 cd6280b7..2e73cce7 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
@@ -50,6 +50,9 @@ public class GenericResourceApiSvcLogicServiceClientMockUtil {
public final String errorMessage = "error-message";
public final String ackFinal = "ack-final";
public final String serviceObjectPath = "service-object-path";
+ public final String networkObjectPath = "network-object-path";
+ public final String networkId = "networkId";
+
private final GenericResourceApiSvcLogicServiceClient mockGenericResourceApiSvcLogicServiceClient;
@@ -94,7 +97,10 @@ public class GenericResourceApiSvcLogicServiceClientMockUtil {
.set(errorCode,"200")
.set(errorMessage,"OK")
.set(ackFinal,"Y")
- .set(serviceObjectPath,"XYZ");
+ .set(serviceObjectPath,"serviceObjectPath: XYZ")
+ .set(networkObjectPath,"networkObjectPath: XYZ")
+ .set(networkId,"networkId: XYZ");
+
}
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
index 6586c8e3..11610659 100644
--- 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
@@ -21,27 +21,25 @@
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.NetworkTopologyOperationInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutputBuilder;
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.network.information.NetworkInformationBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.response.information.NetworkResponseInformationBuilder;
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.level.oper.status.ServiceLevelOperStatusBuilder;
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.Consumer;
import java.util.function.Function;
@@ -108,51 +106,40 @@ public class MDSALUtil {
public static ServiceStatusBuilder serviceStatus(){return new ServiceStatusBuilder();}
- public static <P> P build(Builder<P> b) {
- return b == null? null :b.build();
- }
+ public static NetworkInformationBuilder networkInformation(){return new NetworkInformationBuilder();}
- public static <O> O result(Future<RpcResult<O>> future, Function<RpcResult<O>,O> function) throws Exception {
- return function.apply(future.get());
- }
+ public static NetworkTopologyOperationInputBuilder networkTopologyOperationInput() {return new NetworkTopologyOperationInputBuilder();}
- 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());
- }
+ public static NetworkTopologyOperationOutputBuilder networkTopologyOperationOutput() {return new NetworkTopologyOperationOutputBuilder();}
+ public static NetworkResponseInformationBuilder networkResponseInformation(){return new NetworkResponseInformationBuilder();}
+ public static ServiceLevelOperStatusBuilder serviceLevelOperStatus() {return new ServiceLevelOperStatusBuilder();}
- /** @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()){
+ public static <P> P build(Builder<P> b) {
+ return b == null? null :b.build();
+ }
+
+ public static <P,B extends Builder<P>> P build(Function<P,B> builderConstructor,P sourceDataObject){
+ if(sourceDataObject == null){
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())
- ))
- );
+ B bp = builderConstructor.apply(sourceDataObject);
+ return bp.build();
}
+ public static <P,B extends Builder<P>> P build(Function<P,B> builderConstructor,P sourceDataObject,Consumer<B> builder){
+ if(sourceDataObject == null){
+ return null;
+ }
+ B bp = builderConstructor.apply(sourceDataObject);
+ builder.accept(bp);
+ return bp.build();
+ }
-
-
-
-
+ public static <I,O> O exec(Function<I,Future<RpcResult<O>>> rpc,I rpcParameter,Function<RpcResult<O>,O> rpcResult) throws Exception {
+ Future<RpcResult<O>> future = rpc.apply(rpcParameter);
+ return rpcResult.apply(future.get());
+ }
}