Add nemo-renderers partical test files 72/30372/1
authorsaomenmen <zhangmroy@163.com>
Mon, 30 Nov 2015 10:02:38 +0000 (18:02 +0800)
committersaomenmen <zhangmroy@163.com>
Mon, 30 Nov 2015 10:03:48 +0000 (18:03 +0800)
Change-Id: Iddcc0104a5564c7402e6a93e3832ade294e551f4
Signed-off-by: saomenmen <zhangmroy@163.com>
nemo-renderers/cli-renderer/src/test/java/org/opendaylight/nemo/renderer/cli/CliRendererTest.java [new file with mode: 0644]
nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/phtysicalnetwork/DataBrokerAdapterTest.java [new file with mode: 0644]
nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/phtysicalnetwork/UtilsTest.java [new file with mode: 0644]

diff --git a/nemo-renderers/cli-renderer/src/test/java/org/opendaylight/nemo/renderer/cli/CliRendererTest.java b/nemo-renderers/cli-renderer/src/test/java/org/opendaylight/nemo/renderer/cli/CliRendererTest.java
new file mode 100644 (file)
index 0000000..f207bdd
--- /dev/null
@@ -0,0 +1,31 @@
+package org.opendaylight.nemo.renderer.cli;
+import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.nemo.renderer.cli.CliRenderer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.mockito.Mockito.*;
+/**
+ * Created by zhangmeng on 2015/11/30.
+ */
+public class CliRendererTest extends TestCase {
+    private DataBroker dataBroker;
+    private CliRenderer cliRenderer;
+    @Before
+    public void setUp() throws Exception {
+        dataBroker = mock(DataBroker.class);
+        cliRenderer = new CliRenderer(dataBroker);
+    }
+
+    @Test
+    public void testClose() throws Exception {
+        cliRenderer.close();
+        Assert.assertNotNull(cliRenderer);
+    }
+}
\ No newline at end of file
diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/phtysicalnetwork/DataBrokerAdapterTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/phtysicalnetwork/DataBrokerAdapterTest.java
new file mode 100644 (file)
index 0000000..9fdd146
--- /dev/null
@@ -0,0 +1,73 @@
+package org.opendaylight.nemo.renderer.openflow.physicalnetwork;
+import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+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.nemo.renderer.openflow.physicalnetwork.DataBrokerAdapter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalHosts;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalLinks;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalNodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHostKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLink;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.links.PhysicalLinkKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.nodes.PhysicalNodeKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Method;
+
+import static org.mockito.Mockito.*;
+/**
+ * Created by zhangmeng on 2015/11/30.
+ */
+public class DataBrokerAdapterTest extends TestCase {
+    private DataBrokerAdapter dataBrokerAdapter;
+    private DataBroker dataBroker;
+    @Before
+    public void setUp() throws Exception {
+        dataBroker = mock(DataBroker.class);
+        dataBrokerAdapter = new DataBrokerAdapter(dataBroker);
+    }
+
+    @Test
+    public void testAddPhysicalHost() throws Exception {
+        PhysicalHostKey physicalHostKey = mock(PhysicalHostKey.class);
+        Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class;
+        Method method  = class1.getDeclaredMethod("getPhysicalHostIdentifier", new Class[]{PhysicalHostKey.class});
+
+        method.setAccessible(true);
+        Object result = method.invoke(dataBrokerAdapter,new Object[]{physicalHostKey = mock(PhysicalHostKey.class)});
+    }
+
+    @Test
+    public void testAddPhysicalNode() throws Exception {
+
+    }
+
+    @Test
+    public void testRemovePhysicalNode() throws Exception {
+
+    }
+
+    @Test
+    public void testAddPhysicalLink() throws Exception {
+
+    }
+
+    @Test
+    public void testRemovePhysicalLink() throws Exception {
+
+    }
+}
\ No newline at end of file
diff --git a/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/phtysicalnetwork/UtilsTest.java b/nemo-renderers/openflow-renderer/src/test/java/org/opendaylight/nemo/renderer/openflow/phtysicalnetwork/UtilsTest.java
new file mode 100644 (file)
index 0000000..3914120
--- /dev/null
@@ -0,0 +1,51 @@
+package org.opendaylight.nemo.renderer.openflow.physicalnetwork;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.nemo.renderer.openflow.physicalnetwork.Utils;
+
+import static org.junit.Assert.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import static org.mockito.Mockito.*;
+/**
+ * Created by zhangmeng on 2015/11/30.
+ */
+public class UtilsTest extends Utils {
+
+    @Test
+    public void testGetNodeType() throws Exception {
+        String strType = "switch";
+        Assert.assertTrue(Utils.getNodeType(strType) == PhysicalNodeInstance.NodeType.Switch);
+        strType = "router";
+        Assert.assertTrue(Utils.getNodeType(strType) == PhysicalNodeInstance.NodeType.Router);
+        strType = "firewall";
+        Assert.assertTrue(Utils.getNodeType(strType) == PhysicalNodeInstance.NodeType.Firewall);
+        strType = "loadbalancer";
+        Assert.assertTrue(Utils.getNodeType(strType) == PhysicalNodeInstance.NodeType.Loadbalancer);
+        strType = "test";
+        Assert.assertTrue(Utils.getNodeType(strType) == null);
+    }
+
+    @Test
+    public void testGetPortType() throws Exception {
+        String strType = "external";
+        Assert.assertTrue(Utils.getPortType(strType) == PhysicalPortInstance.PortType.External);
+        strType = "test";
+        Assert.assertTrue(Utils.getPortType(strType) == PhysicalPortInstance.PortType.Internal);
+    }
+
+    @Test
+    public void testReadFile() throws Exception {
+        String Path = new String(".");
+        Assert.assertNotNull(Utils.readFile(Path));
+        Path = "./test";
+        Assert.assertNotNull(Utils.readFile(Path));
+        Assert.assertTrue(Utils.readFile(Path) == "");
+    }
+}
\ No newline at end of file