This is the unit tests for INetMapTopologyObjects.
I modified INetMapTopologyObjects file itself.
Some of the methods use @incident but I think the method wants to get Vertex, I changed it to @Adjacency.
modified: src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
new file: src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIDeviceObjectTest.java
new file: src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowEntryTest.java
new file: src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
new file: src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIPortObjectTest.java
new file: src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsISwitchObjectTest.java
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIDeviceObjectTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIDeviceObjectTest.java
new file mode 100644
index 0000000..3ea90ba
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIDeviceObjectTest.java
@@ -0,0 +1,206 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsIDeviceObjectTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set MacAddress method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the mac address.
+ * 2. Should get the mac address.
+ */
+ @Test
+ public void testSetGetMacAddress() {
+ String macaddr = "00:00:00:00:00:00:0a:07";
+ IDeviceObject devObj = ope.newDevice();
+ devObj.setMACAddress(macaddr);
+ assertEquals(devObj.getMACAddress(), macaddr);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set IPAddress method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the ip address.
+ * 2. Should get the ip address.
+ */
+ @Test
+ public void testSetGetIPAddress() {
+ String ipaddr = "192.168.0.1";
+ IDeviceObject devObj = ope.newDevice();
+ devObj.setIPAddress(ipaddr);
+ assertEquals(devObj.getIPAddress(), ipaddr);
+ }
+
+ /**
+ * Desc:
+ * Test method for get attached port.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the attached ports.
+ */
+ @Test
+ public void testGetAttachedPort() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short number = 1;
+ Short number2 = 2;
+ IPortObject portObj = ope.newPort(dpid, number);
+ IPortObject portObj2 = ope.newPort(dpid, number2);
+
+ String ipaddr = "192.168.0.1";
+ IDeviceObject devObj = ope.newDevice();
+
+ portObj.setDevice(devObj);
+ portObj2.setDevice(devObj);
+
+ HashMap<Short, IPortObject> portObjectList = new HashMap<Short, IPortObject>();
+ for(IPortObject port : devObj.getAttachedPorts())
+ {
+ portObjectList.put(port.getNumber(), port);
+ }
+
+ assertTrue(portObjectList.containsValue(portObj));
+ assertTrue(portObjectList.containsValue(portObj2));
+
+ }
+
+ /**
+ * Desc:
+ * Test method for set and remove host port method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set host port from the device.
+ * 2. Should remove host port from the device.
+ */
+ @Test
+ public void testSetRemoveHostPort() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short number = 1;
+ Short number2 = 2;
+ IPortObject portObj = ope.newPort(dpid, number);
+ IPortObject portObj2 = ope.newPort(dpid, number2);
+
+ String ipaddr = "192.168.0.1";
+ IDeviceObject devObj = ope.newDevice();
+
+ devObj.setHostPort(portObj);
+
+ HashMap<String, IDeviceObject> portObjectList = new HashMap<String, IDeviceObject>();
+ for(IDeviceObject dev : portObj.getDevices())
+ {
+ portObjectList.put(dev.getMACAddress(), dev);
+ }
+ assertTrue(portObjectList.containsValue(devObj));
+
+ devObj.removeHostPort(portObj);
+
+ HashMap<String, IDeviceObject> portObjectList2 = new HashMap<String, IDeviceObject>();
+ for(IDeviceObject dev : portObj.getDevices())
+ {
+ portObjectList2.put(dev.getMACAddress(), dev);
+ }
+ assertTrue(!portObjectList2.containsValue(devObj));
+ }
+
+ /**
+ * Desc:
+ * Test method for getSwitch method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the switch connected to the device.
+ */
+ @Test
+ public void testGetSwitches() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ String dpid2 = "00:00:00:00:00:00:0a:08";
+ Short number = 1;
+ Short number2 = 2;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ ISwitchObject swObj2 = ope.newSwitch(dpid2);
+ IPortObject portObj = ope.newPort(dpid, number);
+ IPortObject portObj2 = ope.newPort(dpid2, number2);
+ swObj.addPort(portObj);
+ swObj2.addPort(portObj2);
+ IDeviceObject devObj = ope.newDevice();
+ portObj.setDevice(devObj);
+ portObj2.setDevice(devObj);
+
+ HashMap<String, ISwitchObject> switchObjectList = new HashMap<String, ISwitchObject>();
+ for(ISwitchObject sw : devObj.getSwitch())
+ {
+ switchObjectList.put(sw.getDPID(), sw);
+ }
+ assertTrue(switchObjectList.containsValue(swObj));
+ assertTrue(switchObjectList.containsValue(swObj2));
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowEntryTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowEntryTest.java
new file mode 100644
index 0000000..eba7447
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowEntryTest.java
@@ -0,0 +1,348 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsIFlowEntryTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+ private IFlowEntry flowEntry = null;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+
+ flowEntry = ope.newFlowEntry();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get FlowEntryId.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set FlowEntryId.
+ * 2. Should get FlowEntryId.
+ */
+ @Test
+ public void testSetGetFlowEntryId() {
+ String flowEntryId = "xx";
+ flowEntry.setFlowEntryId(flowEntryId);
+ assertEquals(flowEntry.getFlowEntryId(), flowEntryId);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get SwitchDpid.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set SwitchDpid.
+ * 2. Should get SwitchDpid.
+ */
+ @Test
+ public void testSetGetSwitchDpid() {
+ String switchDpid = "00:00:00:00:00:11";
+ flowEntry.setSwitchDpid(switchDpid);
+ assertEquals(flowEntry.getSwitchDpid(), switchDpid);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get UserState.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set UserState.
+ * 2. Should get UserState.
+ */
+ @Test
+ public void testSetGetUserState() {
+ String userStete = "good";
+ flowEntry.setUserState(userStete);
+ assertEquals(flowEntry.getUserState(), userStete);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get SwitchState.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set SwitchState.
+ * 2. Should get SwitchState.
+ */
+ @Test
+ public void testSetGetSwitchState() {
+ String switchStete = "ACTIVE";
+ flowEntry.setSwitchState(switchStete);
+ assertEquals(flowEntry.getSwitchState(), switchStete);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get ErrorStateType.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set ErrorStateType.
+ * 2. Should get ErrorStateType.
+ */
+ @Test
+ public void testSetGetErrorStateType() {
+ String errorSteteType = "error";
+ flowEntry.setErrorStateType(errorSteteType);
+ assertEquals(flowEntry.getErrorStateType(), errorSteteType);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get ErrorStateCode.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set ErrorStateCode.
+ * 2. Should get ErrorStateCode.
+ */
+ @Test
+ public void testSetGetErrorStateCode() {
+ String errorSteteCode = "error";
+ flowEntry.setErrorStateCode(errorSteteCode);
+ assertEquals(flowEntry.getErrorStateCode(), errorSteteCode);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchInPort.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchInPort.
+ * 2. Should get MatchInPort.
+ */
+ @Test
+ public void testSetGetMatchInPort() {
+ Short inPort = 1;
+ flowEntry.setMatchInPort(inPort);
+ assertEquals(flowEntry.getMatchInPort(), inPort);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchEthernetFrameType.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchEthernetFrameType.
+ * 2. Should get MatchEthernetFrameType.
+ */
+ @Test
+ public void testSetGetMatchEthernetFrameType() {
+ Short matchEthernetFrameType = 1;
+ flowEntry.setMatchEthernetFrameType(matchEthernetFrameType);
+ assertEquals(flowEntry.getMatchEthernetFrameType(), matchEthernetFrameType);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchSrcMac.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchSrcMac.
+ * 2. Should get MatchSrcMac.
+ */
+ @Test
+ public void testSetGetMatchSrcMac() {
+ String matchSrcMac = "00:00:00:00:00:11";
+ flowEntry.setMatchSrcMac(matchSrcMac);
+ assertEquals(flowEntry.getMatchSrcMac(), matchSrcMac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchDstMac.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchDstMac.
+ * 2. Should get MatchDstMac.
+ */
+ @Test
+ public void testSetGetMatchDstMac() {
+ String matchDstMac = "00:00:00:00:00:11";
+ flowEntry.setMatchDstMac(matchDstMac);
+ assertEquals(flowEntry.getMatchDstMac(), matchDstMac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get SrcIPv4Net.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set SrcIPv4Net.
+ * 2. Should get SrcIPv4Net.
+ */
+ @Test
+ public void testSetGetMatchSrcIPv4Net() {
+ String srcIPv4Net = "192.168.0.1";
+ flowEntry.setMatchSrcIPv4Net(srcIPv4Net);
+ assertEquals(flowEntry.getMatchSrcIPv4Net(), srcIPv4Net);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchDstIPv4Net.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchDstIPv4Net.
+ * 2. Should get MatchDstIPv4Net.
+ */
+ @Test
+ public void testSetGetMatchDstIPv4Net() {
+ String dstIPv4Net = "192.168.0.1";
+ flowEntry.setMatchDstIPv4Net(dstIPv4Net);
+ assertEquals(flowEntry.getMatchDstIPv4Net(), dstIPv4Net);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get ActionOutput.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set ActionOutput.
+ * 2. Should get ActionOutput.
+ */
+ @Test
+ public void testSetGetActionOutput() {
+ Short actionOutput = 1;
+ flowEntry.setActionOutput(actionOutput);
+ assertEquals(flowEntry.getActionOutput(), actionOutput);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get FlowPath.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set FlowPath.
+ * 2. Should get FlowPath.
+ */
+ @Test
+ public void testSetGetFlowPath() {
+ IFlowPath fp = ope.newFlowPath();
+ String flowId = "xx";
+ fp.setFlowId(flowId);
+ flowEntry.setFlow(fp);
+ IFlowPath fp2 = flowEntry.getFlow();
+ assertEquals(fp2.getFlowId(), flowId);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get Switch.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set Switch.
+ * 2. Should get Switch.
+ */
+ @Test
+ public void testSetGetSwitch() {
+ String dpid = "00:00:00:00:00:22";
+ ISwitchObject sw1 = ope.newSwitch(dpid);
+ flowEntry.setSwitch(sw1);
+ ISwitchObject sw2 = flowEntry.getSwitch();
+ assertEquals(sw2, sw1);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get InPort.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set InPort.
+ * 2. Should get InPort.
+ */
+ @Test
+ public void testSetGetInPort() {
+ String dpid = "00:00:00:00:00:22";
+ Short portNum = 4;
+ IPortObject port1 = ope.newPort(dpid, portNum);
+ flowEntry.setInPort(port1);
+ IPortObject port2 = flowEntry.getInPort();
+ assertEquals(port2, port1);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get OutPort.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set OutPort.
+ * 2. Should get OutPort.
+ */
+ @Test
+ public void testSetGetOutPort() {
+ String dpid = "00:00:00:00:00:22";
+ Short portNum = 4;
+ IPortObject port1 = ope.newPort(dpid, portNum);
+ flowEntry.setOutPort(port1);
+ IPortObject port2 = flowEntry.getOutPort();
+ assertEquals(port2, port1);
+ }
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
new file mode 100644
index 0000000..9765af8
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIFlowPathTest.java
@@ -0,0 +1,383 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsIFlowPathTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+ private IFlowPath flowPath = null;
+ private IFlowEntry flowEntry = null;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+
+ flowPath = ope.newFlowPath();
+ flowEntry = ope.newFlowEntry();
+ flowEntry.setState("zz");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set FlowId method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the flow id.
+ * 2. Should get the flow id.
+ */
+ @Test
+ public void testSetGetFlowId() {
+ String flowId = "xx";
+ flowPath.setFlowId(flowId);
+ assertEquals(flowPath.getFlowId(), flowId);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set InstallerId method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the installer id.
+ * 2. Should get the installer id.
+ */
+ @Test
+ public void testSetGetInstallerId() {
+ String flowId = "xx";
+ String installerId = "yy";
+ flowPath.setFlowId(flowId);
+ flowPath.setInstallerId(installerId);
+ assertEquals(flowPath.getInstallerId(), installerId);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set SourceSwitch method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the source switch.
+ * 2. Should get the source switch.
+ */
+ @Test
+ public void testSetGetSourceSwitch() {
+ String flowId = "xx";
+ String sourceSwitch = "aa";
+ flowPath.setFlowId(flowId);
+ flowPath.setSrcSwitch(sourceSwitch);
+ assertEquals(flowPath.getSrcSwitch(), sourceSwitch);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set SourcePort method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the source port.
+ * 2. Should get the source port.
+ */
+ @Test
+ public void testSetGetSourcePort() {
+ String flowId = "xx";
+ Short sourcePort = 1;
+ flowPath.setFlowId(flowId);
+ flowPath.setSrcPort(sourcePort);
+ assertEquals(flowPath.getSrcPort(), sourcePort);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set DestSwitch method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the dest switch.
+ * 2. Should get the dest switch.
+ */
+ @Test
+ public void testSetGetDestSwitch() {
+ String flowId = "xx";
+ String destSwitch = "bb";
+ flowPath.setFlowId(flowId);
+ flowPath.setDstSwitch(destSwitch);
+ assertEquals(flowPath.getDstSwitch(), destSwitch);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set DestPort method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the source dest port.
+ * 2. Should get the source dest port.
+ */
+ @Test
+ public void testSetGetDstPort() {
+ String flowId = "xx";
+ Short dstPort = 2;
+ flowPath.setFlowId(flowId);
+ flowPath.setDstPort(dstPort);
+ assertEquals(flowPath.getDstPort(), dstPort);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set DataPathSummary method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the data path summary.
+ * 2. Should get the data path summary.
+ */
+ @Test
+ public void testSetGetDataPathSummary() {
+ String flowId = "xx";
+ String dataPathSummary = "yy";
+ flowPath.setFlowId(flowId);
+ flowPath.setInstallerId(dataPathSummary);
+ assertEquals(flowPath.getInstallerId(), dataPathSummary);
+ }
+
+ public boolean testIFlowEntry(IFlowPath fp, IFlowEntry fe)
+ {
+ ArrayList<IFlowEntry> flowEntryList = new ArrayList<IFlowEntry>();
+ for(IFlowEntry inFlowEntry : fp.getFlowEntries())
+ {
+ flowEntryList.add(inFlowEntry);
+ }
+ return flowEntryList.contains(fe);
+ }
+
+ /**
+ * Desc:
+ * Test method for addFlowEntry and getFlorEntries method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should add the FlowEntry.
+ * 2. Should get the FlowEntries. It is tested in the testIFlowEntry method.
+ */
+ @Test
+ public void testAddFlowEntryAndGetFlowEntries() {
+ String flowId = "xx";
+ flowPath.setFlowId(flowId);
+ flowPath.addFlowEntry(flowEntry);
+ IFlowEntry flowEntry2 = ope.newFlowEntry();
+ flowPath.addFlowEntry(flowEntry2);
+ assertTrue(testIFlowEntry(flowPath, flowEntry));
+ assertTrue(testIFlowEntry(flowPath, flowEntry2));
+ }
+
+ /**
+ * Desc:
+ * Test method for remove FlowEntry.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should remove FlowEntry.
+ */
+ @Test
+ public void testRemoveFlowEntry() {
+ String flowId = "xx";
+ flowPath.setFlowId(flowId);
+ flowPath.addFlowEntry(flowEntry);
+ flowPath.removeFlowEntry(flowEntry);
+ assertTrue(!testIFlowEntry(flowPath, flowEntry));
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchEthernetFrameType
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchEthernetFrameType.
+ * 2. Should get MatchEthernetFrameType.
+ */
+ @Test
+ public void testSetGetMatchEthernetFrameType() {
+ String flowId = "xx";
+ Short matchEthernetFrameTypeShort = 1;
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchEthernetFrameType(matchEthernetFrameTypeShort);
+ assertEquals(flowPath.getMatchEthernetFrameType(), matchEthernetFrameTypeShort);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchSrcMac
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchSrcMac.
+ * 2. Should get MatchSrcMac.
+ */
+ @Test
+ public void testSetGetMatchSrcMac() {
+ String flowId = "xx";
+ String matchSrcMac = "00:00:00:00:00:11";
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchSrcMac(matchSrcMac);
+ assertEquals(flowPath.getMatchSrcMac(), matchSrcMac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get MatchDstMac.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set MatchDstMac.
+ * 2. Should get MatchDstMac.
+ */
+ @Test
+ public void testSetGetMatchDstMac() {
+ String flowId = "xx";
+ String matchDstMac = "00:00:00:00:00:11";
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchDstMac(matchDstMac);
+ assertEquals(flowPath.getMatchDstMac(), matchDstMac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get SrcIPv4Net.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set SrcIPv4Net.
+ * 2. Should get SrcIPv4Net.
+ */
+ @Test
+ public void testSetGetMatchSrcIPv4Net() {
+ String flowId = "xx";
+ String ip = "192.168.0.1";
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchSrcIPv4Net(ip);
+ assertEquals(flowPath.getMatchSrcIPv4Net(), ip);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get DstIPv4Net.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set DstIPv4Net.
+ * 2. Should get DstIPv4Net.
+ */
+ @Test
+ public void testSetGetMatchDstIPv4Net() {
+ String flowId = "xx";
+ String ip = "192.168.0.1";
+ flowPath.setFlowId(flowId);
+ flowPath.setMatchDstIPv4Net(ip);
+ assertEquals(flowPath.getMatchDstIPv4Net(), ip);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get UserState.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set UserState.
+ * 2. Should get UserState.
+ */
+ @Test
+ public void testSetGetUserState() {
+ String flowId = "xx";
+ String userStatus = "Good";
+ flowPath.setFlowId(flowId);
+ flowPath.setUserState(userStatus);
+ assertEquals(flowPath.getUserState(), userStatus);
+ }
+
+ /**
+ * Desc:
+ * Test method for get Switches.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get switches.
+ */
+ @Test
+ public void testGetSwitches() {
+ String flowId = "xx";
+ String dpid = "1";
+ flowPath.setFlowId(flowId);
+ ISwitchObject sw = ope.newSwitch(dpid);
+ flowEntry.setSwitch(sw);
+ flowPath.addFlowEntry(flowEntry);
+
+ HashMap<String, ISwitchObject> swList = new HashMap<String, ISwitchObject>();
+ for(ISwitchObject insw : flowPath.getSwitches()){
+ swList.put(sw.getDPID(), insw);
+ }
+
+ assertTrue(swList.containsKey(dpid));
+ }
+
+ //TODO Dont know how to set the state property.
+ @Test
+ public void testGetState() {
+ String status = null;
+ assertEquals(flowPath.getState(), status);
+ }
+
+
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIPortObjectTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIPortObjectTest.java
new file mode 100644
index 0000000..2ddab3d
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsIPortObjectTest.java
@@ -0,0 +1,359 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import net.onrc.onos.ofcontroller.flowmanager.FlowManager;
+import net.onrc.onos.ofcontroller.util.FlowId;
+import net.onrc.onos.ofcontroller.util.FlowPath;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openflow.protocol.OFPhysicalPort.OFPortState;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsIPortObjectTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+
+ private ISwitchObject swObj;
+ private IPortObject portObj;
+ private IPortObject portObj2;
+ String dpid;
+ Short number;
+ Short number2;
+
+ private ISwitchObject swObjParty;
+ private IPortObject portObjParty1;
+ private IPortObject portObjParty2;
+ String dpidParty;
+ Short numberParty1;
+ Short numberParty2;
+
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+
+ dpid = "00:00:00:00:00:00:0a:07";
+ number = 1;
+ number2 = 2;
+ swObj = ope.newSwitch(dpid);
+ portObj = ope.newPort(dpid, number);
+ portObj2 = ope.newPort(dpid, number2);
+
+ swObj.addPort(portObj);
+ swObj.addPort(portObj2);
+
+ dpidParty = "00:00:00:00:00:00:0a:08";
+ numberParty1 = 1;
+ numberParty2 = 2;
+ swObjParty = ope.newSwitch(dpidParty);
+ portObjParty1 = ope.newPort(dpidParty, numberParty1);
+ portObjParty2 = ope.newPort(dpidParty, numberParty2);
+ swObjParty.addPort(portObjParty1);
+ swObjParty.addPort(portObjParty2);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get port number property.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the port number.
+ * 2. Should get the port number.
+ */
+ @Test
+ public void testSetGetNumber() {
+ assertEquals(portObj.getNumber(), number);
+ Short testedNumber = 4;
+ portObj.setNumber(testedNumber);
+ assertEquals(portObj.getNumber(), testedNumber);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get port id property.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the port id.
+ * 2. Should get the port id.
+ */
+ @Test
+ public void testSetGetPortId() {
+ String portId = "test1";
+ portObj.setPortId(portId);
+ assertEquals(portObj.getPortId(), portId);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and get port desc property.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the port desc.
+ * 2. Should get the port desc.
+ */
+ @Test
+ public void testSetGetDesc() {
+ String testedDesc = "port 4 at ATL Switch";
+ portObj.setDesc(testedDesc);
+ assertEquals(portObj.getDesc(), testedDesc);
+ }
+
+
+ /**
+ * Desc:
+ * Test method for set and get port status property.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the port status.
+ * 2. Should get the port status.
+ */
+ @Test
+ public void testSetGetPortState() {
+ Integer portState = OFPortState.OFPPS_STP_FORWARD.getValue();
+ portObj.setPortState(portState);
+ assertEquals(portObj.getPortState(), portState);
+ }
+
+ /**
+ * Desc:
+ * Test method for get switch object.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the switch status.
+ */
+ @Test
+ public void testGetSwitch() {
+ ISwitchObject sw = portObj.getSwitch();
+ assertEquals(sw.getDPID(), dpid);
+ }
+
+ private boolean checkIDeviceObject(IPortObject IportObj, String mac)
+ {
+ HashMap<String, IDeviceObject> devList = new HashMap<String, IDeviceObject>();
+ for(IDeviceObject IdevObj : IportObj.getDevices())
+ {
+ devList.put(IdevObj.getMACAddress(), IdevObj);
+ }
+ return devList.containsKey(mac);
+ }
+
+ /**
+ * Desc:
+ * Test method for set and remove device object.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the device object.
+ * 2. SHould remove the device object.
+ */
+ @Test
+ public void testSetAndRemoveDevice() {
+ IDeviceObject devObj = ope.newDevice();
+ String devMac = "00:00:00:00:00:11";
+ devObj.setMACAddress(devMac);
+
+ boolean b = checkIDeviceObject(portObj, devMac);
+ assertTrue(!b);
+ portObj.setDevice(devObj);
+ boolean b2 = checkIDeviceObject(portObj, devMac);
+ assertTrue(b2);
+
+ portObj.removeDevice(devObj);
+ boolean b3 = checkIDeviceObject(portObj, devMac);
+ assertTrue(!b3);
+
+ }
+
+ /**
+ * Desc:
+ * Test method for get devices object.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the device objects.
+ */
+ @Test
+ public void testGetDevices() {
+ IDeviceObject devObj = ope.newDevice();
+ String devMac = "58:55:ca:c4:1b:a0";
+ devObj.setMACAddress(devMac);
+
+ portObj.setDevice(devObj);
+ boolean b = checkIDeviceObject(portObj, devMac);
+ assertTrue(b);
+ }
+
+ /**
+ * Desc:
+ * Test method for set, get and remove linked port.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the linked objects.
+ * 2. Should get the linked objects.
+ * 3. SHould remove the liked objects.
+ */
+ @Test
+ public void testSetGetRemoveLinkedPorts() {
+ String dpidParty = "00:00:00:00:00:00:00:08";
+ ISwitchObject swParty = ope.newSwitch(dpidParty);
+ Short poShort = 1;
+ IPortObject poParty = ope.newPort(dpidParty, poShort);
+ swParty.addPort(poParty);
+
+ portObj.setLinkPort(poParty);
+
+ ArrayList<IPortObject> iPortList = new ArrayList<IPortObject>();
+ for(IPortObject port : portObj.getLinkedPorts()) {
+ iPortList.add(port);
+ }
+ assertTrue(iPortList.contains(poParty));
+
+ portObj.removeLink(poParty);
+
+ ArrayList<IPortObject> iPortList2 = new ArrayList<IPortObject>();
+ for(IPortObject port : portObj.getLinkedPorts()) {
+ iPortList2.add(port);
+ }
+
+ assertTrue(!iPortList2.contains(poParty));
+ }
+
+ /**
+ * Desc:
+ * Test method for get inbound flowEntry
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the inbound flowEntry.
+ */
+ @Test
+ public void testGetInFlowEntries() {
+
+ portObj.setLinkPort(portObj2);
+
+ IFlowPath flowPathObj = ope.newFlowPath();
+
+ String flowEId = "1";
+ IFlowEntry flowEntryObj = ope.newFlowEntry();
+ flowEntryObj.setFlowEntryId(flowEId);
+ flowEntryObj.setInPort(portObj);
+ flowEntryObj.setOutPort(portObj2);
+ flowEntryObj.setSwitch(swObj);
+ flowEntryObj.setFlow(flowPathObj);
+
+ String flowEId2 = "2";
+ IFlowEntry flowEntryObj2 = ope.newFlowEntry();
+ flowEntryObj2.setFlowEntryId(flowEId2);
+ flowEntryObj2.setInPort(portObjParty1);
+ flowEntryObj2.setOutPort(portObjParty2);
+ flowEntryObj.setSwitch(swObjParty);
+ flowEntryObj2.setFlow(flowPathObj);
+
+ HashMap<String, IFlowEntry> flowEntryList = new HashMap<String, IFlowEntry>();
+ for(IFlowEntry flowEnt : portObj.getInFlowEntries())
+ {
+ flowEntryList.put(flowEnt.getFlowEntryId(), flowEnt);
+ }
+
+ assertTrue(flowEntryList.containsValue(flowEntryObj));
+
+ }
+
+ /**
+ * Desc:
+ * Test method for get outbound flowEntry
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the outbound flowEntry.
+ */
+ @Test
+ public void testGetOutFlowEntries() {
+
+ portObj.setLinkPort(portObj2);
+
+ IFlowPath flowPathObj = ope.newFlowPath();
+
+ String flowEId = "1";
+ IFlowEntry flowEntryObj = ope.newFlowEntry();
+ flowEntryObj.setFlowEntryId(flowEId);
+ flowEntryObj.setInPort(portObj);
+ flowEntryObj.setOutPort(portObj2);
+ flowEntryObj.setSwitch(swObj);
+ flowEntryObj.setFlow(flowPathObj);
+
+ String flowEId2 = "2";
+ IFlowEntry flowEntryObj2 = ope.newFlowEntry();
+ flowEntryObj2.setFlowEntryId(flowEId2);
+ flowEntryObj2.setInPort(portObjParty1);
+ flowEntryObj2.setOutPort(portObjParty2);
+ flowEntryObj.setSwitch(swObjParty);
+ flowEntryObj2.setFlow(flowPathObj);
+
+ HashMap<String, IFlowEntry> flowEntryList = new HashMap<String, IFlowEntry>();
+ for(IFlowEntry flowEnt : portObj2.getOutFlowEntries())
+ {
+ flowEntryList.put(flowEnt.getFlowEntryId(), flowEnt);
+ }
+
+ assertTrue(flowEntryList.containsValue(flowEntryObj));
+
+ }
+
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsISwitchObjectTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsISwitchObjectTest.java
new file mode 100644
index 0000000..c4dca4b
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjectsISwitchObjectTest.java
@@ -0,0 +1,285 @@
+package net.onrc.onos.ofcontroller.core;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+
+import net.onrc.onos.graph.GraphDBConnection;
+import net.onrc.onos.graph.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowEntry;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IFlowPath;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.TestDatabaseManager;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.slf4j.LoggerFactory;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.thinkaurelius.titan.core.TitanFactory;
+import com.thinkaurelius.titan.core.TitanGraph;
+
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
+public class INetMapTopologyObjectsISwitchObjectTest {
+
+ //The test network is ./titan/schema/test-network.xml
+
+ protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+ String conf;
+ private GraphDBConnection conn = null;
+ private GraphDBOperation ope = null;
+ private TitanGraph titanGraph = null;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = "/dummy/path/to/db";
+
+ // Make mock cassandra DB
+ // Replace TitanFactory.open() to return mock DB
+ TestDatabaseManager.deleteTestDatabase();
+ titanGraph = TestDatabaseManager.getTestDatabase();
+ //TestDatabaseManager.populateTestData(titanGraph);
+ PowerMock.mockStatic(TitanFactory.class);
+ EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+ PowerMock.replay(TitanFactory.class);
+
+ conn = GraphDBConnection.getInstance(conf);
+ ope = new GraphDBOperation(conn);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ titanGraph.shutdown();
+ TestDatabaseManager.deleteTestDatabase();
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set state method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the status of the switch.
+ * 2. Should get the status of the switch.
+ */
+ @Test
+ public void testSetGetState() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ String state = "ACTIVE";
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ swObj.setState(state);
+ assertEquals(swObj.getState(), state);
+ }
+
+ /**
+ * Desc:
+ * Test method for get and set Type method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the Type of the switch.
+ * 2. Should get the Type of the switch.
+ */
+ @Test
+ public void testSetGetType() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ String type = "Switch";
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ swObj.setType("Switch");
+ assertEquals(swObj.getType(), type);
+ }
+
+ /**
+ * Desc:
+ * Test method for getDPID method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get the dpid of the switch.
+ */
+ @Test
+ public void testGetDPID() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ ISwitchObject swObj = ope.newSwitch(dpid);
+
+ assertEquals(swObj.getDPID(), dpid);
+ }
+
+ /**
+ * Desc:
+ * Test method for setDPID method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should set the dpid of the switch.
+ */
+ @Test
+ public void testSetDPID() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ String dpid2 = "00:00:00:00:00:00:0a:08";
+ ISwitchObject obj = ope.newSwitch(dpid);
+ assertEquals(obj.getDPID(), dpid);
+
+ obj.setDPID(dpid2);
+ assertEquals(obj.getDPID(), dpid2);
+ }
+
+ /**
+ * Desc:
+ * Test method for getPorts method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get all of ports taken by the switch.
+ */
+ @Test
+ public void testGetPorts() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short portNumber = 1;
+ int testSwitchPortNumber = 1;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, portNumber);
+
+ swObj.addPort(portObj);
+ int i = 0;
+ for(IPortObject port : swObj.getPorts()){
+ i++;
+ }
+ assertEquals(testSwitchPortNumber, 1);
+ }
+
+ /**
+ * Desc:
+ * Test method for add and getPort method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should add the port.
+ * 1. Should get the port.
+ */
+ @Test
+ public void testGetPort() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short portNumber = 1;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, portNumber);
+
+ swObj.addPort(portObj);
+ IPortObject portObj2 = swObj.getPort(portNumber);
+ assertEquals(portObj, portObj2);
+ }
+
+ /**
+ * Desc:
+ * Test method for add and removePort method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should add a port to the switch.
+ * 1. Should remove a port from the switch.
+ */
+ @Test
+ public void testAddRemovePorts() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short portNum = 1;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, portNum);
+ swObj.addPort(portObj);
+
+ IPortObject portObj2 = swObj.getPort(portNum);
+ assertEquals(portObj2, portObj);
+ swObj.removePort(portObj);
+ assertNull(swObj.getPort(portNum));
+ }
+
+ /**
+ * Desc:
+ * Test method for getDevices method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get all devices attached to the switch.
+ */
+ @Test
+ public void testGetDevices() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short portNum = 1;
+ String devMac = "00:00:00:00:00:11";
+ int numOfDev = 1;
+
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, portNum);
+ IDeviceObject devObj = ope.newDevice();
+ devObj.setMACAddress(devMac);
+ swObj.addPort(portObj);
+ portObj.setDevice(devObj);
+
+ int i = 0;
+ for(IDeviceObject dev : swObj.getDevices()){
+ i++;
+ }
+ assertEquals(i, numOfDev);
+ }
+
+ /**
+ * Desc:
+ * Test method for getFlowEntries method.
+ * Condition:
+ * N/A
+ * Expect:
+ * 1. Should get all flowEntries attached to the switch.
+ */
+ @Test
+ public void testGetFlowEntries() {
+ String dpid = "00:00:00:00:00:00:0a:07";
+ Short number = 1;
+ Short number2 = 2;
+ Short number3 = 3;
+ ISwitchObject swObj = ope.newSwitch(dpid);
+ IPortObject portObj = ope.newPort(dpid, number);
+ IPortObject portObj2 = ope.newPort(dpid, number2);
+ IPortObject portObj3 = ope.newPort(dpid, number3);
+
+ swObj.addPort(portObj);
+ swObj.addPort(portObj2);
+ swObj.addPort(portObj3);
+
+ IFlowPath flowPathObj = ope.newFlowPath();
+
+ String flowEId = "1";
+ IFlowEntry flowEntryObj = ope.newFlowEntry();
+ flowEntryObj.setFlowEntryId(flowEId);
+ flowEntryObj.setInPort(portObj);
+ flowEntryObj.setOutPort(portObj2);
+ flowEntryObj.setSwitch(swObj);
+ flowEntryObj.setFlow(flowPathObj);
+
+ String flowEId2 = "2";
+ IFlowEntry flowEntryObj2 = ope.newFlowEntry();
+ flowEntryObj2.setFlowEntryId(flowEId2);
+ flowEntryObj2.setInPort(portObj);
+ flowEntryObj2.setOutPort(portObj3);
+ flowEntryObj2.setSwitch(swObj);
+ flowEntryObj2.setFlow(flowPathObj);
+
+ HashMap<String, IFlowEntry> flowEntryList = new HashMap<String, IFlowEntry>();
+ for(IFlowEntry flowEnt : swObj.getFlowEntries())
+ {
+ flowEntryList.put(flowEnt.getFlowEntryId(), flowEnt);
+ }
+
+ assertTrue(flowEntryList.containsValue(flowEntryObj));
+ assertTrue(flowEntryList.containsValue(flowEntryObj2));
+ }
+
+}