Improve code coverage for MdsalHelper
authorGaurav Agrawal <gaurav.agrawal@huawei.com>
Thu, 21 Sep 2017 10:59:34 +0000 (16:29 +0530)
committerGaurav Agrawal <gaurav.agrawal@huawei.com>
Thu, 21 Sep 2017 11:01:38 +0000 (16:31 +0530)
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 <gaurav.agrawal@huawei.com>
sli/provider/pom.xml
sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/TestMdsalHelperUtils.java [new file with mode: 0644]
sli/provider/src/test/resources/l3vpnyang/ietf-l3vpn-svc-part@2017-09-21.yang [new file with mode: 0755]

index 529f976..51db628 100755 (executable)
 <?xml version="1.0"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-       <modelVersion>4.0.0</modelVersion>
-       <parent>
-               <groupId>org.onap.ccsdk.sli.core</groupId>
-               <artifactId>sli</artifactId>
-               <version>0.1.2-SNAPSHOT</version>
-       </parent>
-       <artifactId>sli-provider</artifactId>
-       <packaging>bundle</packaging>
-       <name>SLI - Provider</name>
-       <properties>
-               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-       </properties>
-       <dependencies>
-               <dependency>
-                       <groupId>junit</groupId>
-                       <artifactId>junit</artifactId>
-                       <version>3.8.1</version>
-                       <scope>test</scope>
-               </dependency>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.onap.ccsdk.sli.core</groupId>
+        <artifactId>sli</artifactId>
+        <version>0.1.2-SNAPSHOT</version>
+    </parent>
+    <artifactId>sli-provider</artifactId>
+    <packaging>bundle</packaging>
+    <name>SLI - Provider</name>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>ch.vorburger.mariaDB4j</groupId>
             <artifactId>mariaDB4j</artifactId>
             <version>2.2.3</version>
             <scope>test</scope>
         </dependency>
-               <dependency>
-                       <groupId>org.onap.ccsdk.sli.core</groupId>
-                       <artifactId>sli-common</artifactId>
-                       <version>${project.version}</version>
-                       <scope>compile</scope>
-               </dependency>
-               <dependency>
-                       <groupId>equinoxSDK381</groupId>
-                       <artifactId>org.eclipse.osgi</artifactId>
-                       <version>${equinox.osgi.version}</version>
-               </dependency>
-               <dependency>
-                       <groupId>org.slf4j</groupId>
-                       <artifactId>slf4j-api</artifactId>
-                       <version>${slf4j.version}</version>
-               </dependency>
-               <dependency>
-                       <groupId>org.slf4j</groupId>
-                       <artifactId>jcl-over-slf4j</artifactId>
-                       <version>${slf4j.version}</version>
-               </dependency>
-               <dependency>
-                       <groupId>commons-lang</groupId>
-                       <artifactId>commons-lang</artifactId>
-                       <version>${commons.lang.version}</version>
-                       <scope>compile</scope>
-               </dependency>
-
+        <dependency>
+            <groupId>org.onap.ccsdk.sli.core</groupId>
+            <artifactId>sli-common</artifactId>
+            <version>${project.version}</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>equinoxSDK381</groupId>
+            <artifactId>org.eclipse.osgi</artifactId>
+            <version>${equinox.osgi.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+            <version>${slf4j.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>${commons.lang.version}</version>
+            <scope>compile</scope>
+        </dependency>
 
-               <!--
-               <dependency>
-                       <groupId>org.antlr</groupId>
-                       <artifactId>antlr4</artifactId>
-                       <version>${antlr.version}</version>
-                       <type>jar</type>
-                       <scope>compile</scope>
-               </dependency>
-               -->
+        <!--
+        <dependency>
+          <groupId>org.antlr</groupId>
+          <artifactId>antlr4</artifactId>
+          <version>${antlr.version}</version>
+          <type>jar</type>
+          <scope>compile</scope>
+        </dependency>
+        -->
 
-       </dependencies>
+    </dependencies>
 
-       <build>
-               <plugins>
-                       <plugin>
-                               <groupId>org.apache.felix</groupId>
-                               <artifactId>maven-bundle-plugin</artifactId>
-                               <version>${bundle.plugin.version}</version>
-                               <extensions>true</extensions>
-                               <configuration>
-                                       <instructions>
-                                               <Bundle-Activator>org.onap.ccsdk.sli.core.sli.provider.SvcLogicActivator</Bundle-Activator>
-                                               <Export-Package>org.onap.ccsdk.sli.core.sli.provider;version=${project.version}</Export-Package>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>${bundle.plugin.version}</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Activator>org.onap.ccsdk.sli.core.sli.provider.SvcLogicActivator</Bundle-Activator>
+                        <Export-Package>org.onap.ccsdk.sli.core.sli.provider;version=${project.version}</Export-Package>
 
-                                               <DynamicImport-Package>*</DynamicImport-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
 
 
                         <Import-Package>org.onap.ccsdk.sli.core.sli;version="${project.version}",*</Import-Package>
 
-                                               <Embed-Dependency>*;scope=compile;artifactId=commons-lang|commons-lang3</Embed-Dependency>
+                        <Embed-Dependency>*;scope=compile;artifactId=commons-lang|commons-lang3</Embed-Dependency>
 
-                                               <Embed-Transitive>true</Embed-Transitive>
-                                       </instructions>
+                        <Embed-Transitive>true</Embed-Transitive>
+                    </instructions>
+                </configuration>
 
+            </plugin>
+            <plugin>
+                <groupId>org.opendaylight.yangtools</groupId>
+                <artifactId>yang-maven-plugin</artifactId>
+                <version>${odl.yangtools.yang.maven.plugin.version}</version>
+                <executions>
+                    <execution>
+                        <id>config</id>
+                        <goals>
+                            <goal>generate-sources</goal>
+                        </goals>
+                        <configuration>
+                            <yangFilesRootDir>src/test/resources</yangFilesRootDir>
+                            <codeGenerators>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>${jmxGeneratorPath}</outputBaseDir>
+                                    <additionalConfiguration>
+                                        <namespaceToPackage1>
+                                            urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang
+                                        </namespaceToPackage1>
+                                    </additionalConfiguration>
+                                </generator>
+                                <generator>
+                                    <codeGeneratorClass>
+                                        org.opendaylight.mdsal.binding.maven.api.gen.plugin.CodeGeneratorImpl
+                                    </codeGeneratorClass>
+                                    <outputBaseDir>${salGeneratorPath}</outputBaseDir>
+                                </generator>
+                            </codeGenerators>
+                            <inspectDependencies>true</inspectDependencies>
+                        </configuration>
+                    </execution>
+                </executions>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.opendaylight.mdsal</groupId>
+                        <artifactId>maven-sal-api-gen-plugin</artifactId>
+                        <version>${odl.sal.api.gen.plugin.version}</version>
+                        <type>jar</type>
+                    </dependency>
+                    <dependency>
+                        <groupId>org.opendaylight.controller</groupId>
+                        <artifactId>yang-jmx-generator-plugin</artifactId>
+                        <version>${odl.yang.jmx.generator.version}</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
 
-                               </configuration>
+            <!--
+            Cleans up generated test artifacts which get included as a source
+            directory, but which we don't want as part of the bundle.
+             -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <version>1.8</version>
+                <executions>
+                    <execution>
+                        <phase>prepare-package</phase>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                        <configuration>
+                            <target>
+                                <delete includeemptydirs="true">
+                                    <fileset
+                                        dir="${salGeneratorPath}"
+                                        includes="**/*"/>
+                                    <fileset
+                                        dir="${basedir}"
+                                        includes="${salGeneratorPath}"/>
+                                    <fileset
+                                        dir="${jmxGeneratorPath}"
+                                        includes="**/*"/>
+                                    <fileset
+                                        dir="${basedir}"
+                                        includes="${jmxGeneratorPath}"/>
+                                </delete>
+                            </target>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
 
-                       </plugin>
-               </plugins>
-       </build>
-       <description>SLI Provider is the OSGi bundle that exposes the service logic interpreter as a service.</description>
+        </plugins>
+    </build>
+    <description>SLI Provider is the OSGi bundle that exposes the service logic interpreter as a service.</description>
 </project>
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 (file)
index 0000000..dca6b54
--- /dev/null
@@ -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<VpnSvc> 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 (executable)
index 0000000..4af0806
--- /dev/null
@@ -0,0 +1,68 @@
+module ietf-l3vpn-svc-part {\r
+\r
+    namespace "urn:ietf:params:xml:ns:yang:ietf-l3vpn-svc-part";\r
+\r
+    prefix l3vpn-svc;\r
+\r
+    organization\r
+     "IETF L3SM Working Group";\r
+\r
+    contact\r
+        "WG List:   &lt;mailto:l3sm@ietf.org&gt;\r
+\r
+        Editor:\r
+\r
+        ";\r
+\r
+    description\r
+        "The YANG module defines a generic service configuration\r
+        model for Layer 3 VPN common across all of the vendor\r
+        implementations.";\r
+\r
+    revision 2017-09-21 {\r
+        description\r
+        "Part of draft-ietf-l3sm-l3vpn-service-yang-11";\r
+        reference\r
+            "draft-ietf-l3sm-l3vpn-service-yang-11";\r
+    }\r
+\r
+    /* Typedefs */\r
+\r
+    typedef svc-id {\r
+        type string;\r
+        description\r
+         "Defining a type of service component\r
+         identificators.";\r
+    }\r
+\r
+    /* Main blocks */\r
+\r
+    container l3vpn-svc {\r
+        container vpn-services {\r
+            list vpn-svc {\r
+                key vpn-id;\r
+\r
+                uses vpn-svc-cfg; /*Not used*/\r
+\r
+                description "\r
+                    List of VPN services.";\r
+            }\r
+            description\r
+             "top level container\r
+             for the VPN services.";\r
+        }\r
+    }\r
+\r
+    grouping vpn-svc-cfg {\r
+        leaf vpn-id {\r
+                type svc-id;\r
+                description\r
+                "VPN identifier. Local administration meaning.";\r
+            }\r
+        leaf customer-name {\r
+            type string;\r
+            description\r
+             "Name of the customer.";\r
+        }\r
+    }\r
+}\r