From c2eaae773f3a76ecf585a24172692da0bf00445f Mon Sep 17 00:00:00 2001 From: Gaurav Agrawal Date: Thu, 21 Sep 2017 16:29:34 +0530 Subject: Improve code coverage for MdsalHelper Changes includes 1. Modified pom to take JUNIT version from parent pom. 2. Added basic testcases for MdsalHelper utilities with test YANG. 3. Made necessary pom additions. Change-Id: Ib46bd9c8a87db33c90aaaf36736d709a7c17cbdd Issue-Id: CCSDK-101 Signed-off-by: Gaurav Agrawal --- sli/provider/pom.xml | 240 ++++++++++++++------- .../core/sli/provider/TestMdsalHelperUtils.java | 79 +++++++ .../l3vpnyang/ietf-l3vpn-svc-part@2017-09-21.yang | 68 ++++++ 3 files changed, 309 insertions(+), 78 deletions(-) create mode 100644 sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/TestMdsalHelperUtils.java create mode 100755 sli/provider/src/test/resources/l3vpnyang/ietf-l3vpn-svc-part@2017-09-21.yang diff --git a/sli/provider/pom.xml b/sli/provider/pom.xml index 529f9769..51db628c 100755 --- a/sli/provider/pom.xml +++ b/sli/provider/pom.xml @@ -1,98 +1,182 @@ - - 4.0.0 - - org.onap.ccsdk.sli.core - sli - 0.1.2-SNAPSHOT - - sli-provider - bundle - SLI - Provider - - UTF-8 - - - - junit - junit - 3.8.1 - test - + + 4.0.0 + + org.onap.ccsdk.sli.core + sli + 0.1.2-SNAPSHOT + + sli-provider + bundle + SLI - Provider + + UTF-8 + + + + junit + junit + ${junit.version} + test + ch.vorburger.mariaDB4j mariaDB4j 2.2.3 test - - org.onap.ccsdk.sli.core - sli-common - ${project.version} - compile - - - equinoxSDK381 - org.eclipse.osgi - ${equinox.osgi.version} - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - jcl-over-slf4j - ${slf4j.version} - - - commons-lang - commons-lang - ${commons.lang.version} - compile - - + + org.onap.ccsdk.sli.core + sli-common + ${project.version} + compile + + + equinoxSDK381 + org.eclipse.osgi + ${equinox.osgi.version} + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + commons-lang + commons-lang + ${commons.lang.version} + compile + - + - + - - - - org.apache.felix - maven-bundle-plugin - ${bundle.plugin.version} - true - - - org.onap.ccsdk.sli.core.sli.provider.SvcLogicActivator - org.onap.ccsdk.sli.core.sli.provider;version=${project.version} + + + + org.apache.felix + maven-bundle-plugin + ${bundle.plugin.version} + true + + + org.onap.ccsdk.sli.core.sli.provider.SvcLogicActivator + org.onap.ccsdk.sli.core.sli.provider;version=${project.version} - * + * org.onap.ccsdk.sli.core.sli;version="${project.version}",* - *;scope=compile;artifactId=commons-lang|commons-lang3 + *;scope=compile;artifactId=commons-lang|commons-lang3 - true - + true + + + + + org.opendaylight.yangtools + yang-maven-plugin + ${odl.yangtools.yang.maven.plugin.version} + + + config + + generate-sources + + + src/test/resources + + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + + ${jmxGeneratorPath} + + + urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang + + + + + + org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl + + ${salGeneratorPath} + + + true + + + + + + org.opendaylight.mdsal + maven-sal-api-gen-plugin + ${odl.sal.api.gen.plugin.version} + jar + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${odl.yang.jmx.generator.version} + + + - + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + prepare-package + + run + + + + + + + + + + + + + + - - - - SLI Provider is the OSGi bundle that exposes the service logic interpreter as a service. + + + SLI Provider is the OSGi bundle that exposes the service logic interpreter as a service. diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/TestMdsalHelperUtils.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/TestMdsalHelperUtils.java new file mode 100644 index 00000000..dca6b54c --- /dev/null +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/TestMdsalHelperUtils.java @@ -0,0 +1,79 @@ +/*- + * ============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.ccsdk.sli.core.sli.provider; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.l3vpn.svc.part.rev170921.L3vpnSvcBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.l3vpn.svc.part.rev170921.SvcId; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.l3vpn.svc.part.rev170921.l3vpn.svc.VpnServicesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.l3vpn.svc.part.rev170921.l3vpn.svc.vpn.services.VpnSvc; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.l3vpn.svc.part.rev170921.l3vpn.svc.vpn.services.VpnSvcBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.l3vpn.svc.part.rev170921.l3vpn.svc.vpn.services.VpnSvcKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestMdsalHelperUtils { + + private static final Logger log = LoggerFactory.getLogger(TestMdsalHelperUtils.class); + + @Test + public void testL3vpnSvcToBuilder() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("l3vpn-svc.vpn-services.vpn-svc[0].vpn-id", "1"); + + L3vpnSvcBuilder svcBuilder = new L3vpnSvcBuilder(); + + MdsalHelper.toBuilder(ctx.toProperties(), "", svcBuilder); + + assertThat(svcBuilder.getVpnServices().getVpnSvc().get(0).getKey().getVpnId().getValue(), is("1")); + log.info(svcBuilder.toString()); + } + + @Test + public void testL3vpnSvcToProperties() throws SvcLogicException { + VpnSvcBuilder vpnSvcBuilder = new VpnSvcBuilder(); + vpnSvcBuilder.setKey(new VpnSvcKey(new SvcId("1"))); + List vpnSvcList = new ArrayList<>(); + vpnSvcList.add(vpnSvcBuilder.build()); + VpnServicesBuilder vpnServicesBuilder = new VpnServicesBuilder(); + vpnServicesBuilder.setVpnSvc(vpnSvcList); + L3vpnSvcBuilder l3vpnSvcBuilder = new L3vpnSvcBuilder(); + l3vpnSvcBuilder.setVpnServices(vpnServicesBuilder.build()); + + Properties properties = new Properties(); + + MdsalHelper.toProperties(properties, "", l3vpnSvcBuilder.build()); + + assertThat(properties.getProperty("l3vpn-svc.vpn-services.vpn-svc[0].vpn-id"), is("1")); + log.info(properties.toString()); + } + + // TODO add more detailed testcases. +} diff --git a/sli/provider/src/test/resources/l3vpnyang/ietf-l3vpn-svc-part@2017-09-21.yang b/sli/provider/src/test/resources/l3vpnyang/ietf-l3vpn-svc-part@2017-09-21.yang new file mode 100755 index 00000000..4af08060 --- /dev/null +++ b/sli/provider/src/test/resources/l3vpnyang/ietf-l3vpn-svc-part@2017-09-21.yang @@ -0,0 +1,68 @@ +module ietf-l3vpn-svc-part { + + namespace "urn:ietf:params:xml:ns:yang:ietf-l3vpn-svc-part"; + + prefix l3vpn-svc; + + organization + "IETF L3SM Working Group"; + + contact + "WG List: <mailto:l3sm@ietf.org> + + Editor: + + "; + + description + "The YANG module defines a generic service configuration + model for Layer 3 VPN common across all of the vendor + implementations."; + + revision 2017-09-21 { + description + "Part of draft-ietf-l3sm-l3vpn-service-yang-11"; + reference + "draft-ietf-l3sm-l3vpn-service-yang-11"; + } + + /* Typedefs */ + + typedef svc-id { + type string; + description + "Defining a type of service component + identificators."; + } + + /* Main blocks */ + + container l3vpn-svc { + container vpn-services { + list vpn-svc { + key vpn-id; + + uses vpn-svc-cfg; /*Not used*/ + + description " + List of VPN services."; + } + description + "top level container + for the VPN services."; + } + } + + grouping vpn-svc-cfg { + leaf vpn-id { + type svc-id; + description + "VPN identifier. Local administration meaning."; + } + leaf customer-name { + type string; + description + "Name of the customer."; + } + } +} -- cgit 1.2.3-korg