X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=generic-resource-api%2Fprovider%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fsdnc%2Fnorthbound%2Futil%2FMDSALUtil.java;h=11610659788beabbebd943137a84a133bd2272d8;hb=e3446fcf2129c07af960e6b327c06f585c48ea68;hp=6586c8e340bccc746d0ac5853765c03b72563250;hpb=107951a4b13c1a4c725b9df201a1af7595ef4dec;p=sdnc%2Fnorthbound.git 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 build(Builder

b) { - return b == null? null :b.build(); - } + public static NetworkInformationBuilder networkInformation(){return new NetworkInformationBuilder();} - public static O result(Future> future, Function,O> function) throws Exception { - return function.apply(future.get()); - } + public static NetworkTopologyOperationInputBuilder networkTopologyOperationInput() {return new NetworkTopologyOperationInputBuilder();} - public static O rpc(Function>> rpc,Function,O> function,I input) throws Exception { - Future> 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.builder(Services.class) - .child(Service.class, new ServiceKey(serviceKey)).build(); - ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction(); - Optional data = (Optional) readTx.read(logicalDatastoreType, serviceInstanceIdentifier).get(); - if(!data.isPresent()){ + public static

P build(Builder

b) { + return b == null? null :b.build(); + } + + public static > P build(Function 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 build(Function builderConstructor,P sourceDataObject,Consumer builder){ + if(sourceDataObject == null){ + return null; + } + B bp = builderConstructor.apply(sourceDataObject); + builder.accept(bp); + return bp.build(); + } - - - - + public static O exec(Function>> rpc,I rpcParameter,Function,O> rpcResult) throws Exception { + Future> future = rpc.apply(rpcParameter); + return rpcResult.apply(future.get()); + } }