Add sonar for southbound 89/17789/1
authorSam Hague <shague@redhat.com>
Mon, 6 Apr 2015 13:48:03 +0000 (09:48 -0400)
committerSam Hague <shague@redhat.com>
Mon, 6 Apr 2015 13:48:03 +0000 (09:48 -0400)
Change-Id: I99c0e84f1b52e7d295f485b954160d1593d72c7d
Signed-off-by: Sam Hague <shague@redhat.com>
southbound/southbound-impl/pom.xml
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbClientKeyTest.java [new file with mode: 0644]
southbound/southbound-it/pom.xml

index bc2b55946bb0a071af6e105d3b23af9fab2bd792..f3dd04db6a463d746aa04feea49ee53d7a16c60a 100644 (file)
@@ -20,6 +20,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <artifactId>southbound-impl</artifactId>
   <version>1.1.0-SNAPSHOT</version>
   <packaging>bundle</packaging>
+
+  <properties>
+    <powermock.version>1.5.2</powermock.version>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>${project.groupId}</groupId>
@@ -44,6 +49,23 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-core-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-api-mockito</artifactId>
+      <version>${powermock.version}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.powermock</groupId>
+      <artifactId>powermock-module-junit4</artifactId>
+      <version>${powermock.version}</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <plugins>
@@ -69,6 +91,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
           <excludes>**/yang/</excludes>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.jacoco</groupId>
+        <artifactId>jacoco-maven-plugin</artifactId>
+      </plugin>
     </plugins>
   </build>
 
diff --git a/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbClientKeyTest.java b/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbClientKeyTest.java
new file mode 100644 (file)
index 0000000..2120490
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2015 Red Hat, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.southbound;
+
+import static org.mockito.Matchers.any;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+
+/**
+* Unit test for {@link OvsdbClientKey}
+*
+* @author Sam Hague (shague@redhat.com)
+*/
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(SouthboundMapper.class)
+public class OvsdbClientKeyTest {
+    private static final String ADDRESS_STR = "192.168.120.1";
+    private static final String PORT_STR = "6640";
+    private OvsdbClientKey ovsdbClientKeyTest;
+    private InstanceIdentifier<Node> nodePath;
+
+    @Before
+    public void setUp() {
+        Ipv4Address ipv4 = new Ipv4Address(ADDRESS_STR);
+        PortNumber port = new PortNumber(Integer.parseInt(PORT_STR));
+        ovsdbClientKeyTest = new OvsdbClientKey(new IpAddress(ipv4), port);
+
+        String uriString = SouthboundConstants.OVSDB_URI_PREFIX + "://" + ADDRESS_STR + ":" + PORT_STR;
+        Uri uri = new Uri(uriString);
+        NodeId nodeId = new NodeId(uri);
+        nodePath = InstanceIdentifier
+                .create(NetworkTopology.class)
+                .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
+                .child(Node.class, new NodeKey(nodeId));
+    }
+
+    @Test
+    public void testToInstanceIndentifier() {
+        Assert.assertNotNull("OvsdbClientKey should not be null", ovsdbClientKeyTest);
+
+        PowerMockito.mockStatic(SouthboundMapper.class);
+        PowerMockito.when(SouthboundMapper.createInstanceIdentifier(any(IpAddress.class), any(PortNumber.class)))
+                .thenReturn(nodePath);
+
+        Assert.assertEquals("Failed to return " + nodePath, nodePath, ovsdbClientKeyTest.toInstanceIndentifier());
+    }
+}
\ No newline at end of file
index ced480a8f332ad9eea80e2f38c50c9b574d72c7c..53004188284247b7f32d7522d639fa8f15007d98 100644 (file)
@@ -153,6 +153,10 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
           <excludes>**/yang/</excludes>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>org.jacoco</groupId>
+        <artifactId>jacoco-maven-plugin</artifactId>
+      </plugin>
     </plugins>
   </build>
 </project>