Added an unit test for method IPortObject.getReverseLinkedPorts()
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
index abb8809..4aea22a 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
@@ -256,6 +256,21 @@
Link linkToVerifyNot = createFeasibleLink();
assertFalse(links.contains(linkToVerifyNot));
}
+
+ /**
+ * Test if {@link LinkStorageImpl#getReverseLinks(String)} can correctly return Links connected to specific MAC address.
+ */
+ @Test
+ public void testGetReverseLinks_ByString() {
+ Link linkToVeryfy = createExistingLink();
+ String dpid = HexString.toHexString(linkToVeryfy.getDst());
+
+ List<Link> links = linkStorage.getReverseLinks(dpid);
+ assertTrue(links.contains(linkToVeryfy));
+
+ Link linkToVerifyNot = createFeasibleLink();
+ assertFalse(links.contains(linkToVerifyNot));
+ }
/**
* Test if {@link LinkStorageImpl#deleteLink(Link)} can correctly delete a Link.
@@ -447,6 +462,35 @@
}
/**
+ * Class defines a function called back when {@link IPortObject#getReverseLinkedPorts()} is called.
+ * @author Naoki Shiota
+ *
+ */
+ private class GetReverseLinkedPortsCallback implements IAnswer< Iterable<IPortObject> > {
+ private long dpid;
+ private short port;
+
+ public GetReverseLinkedPortsCallback(long dpid, short port) {
+ this.dpid = dpid;
+ this.port = port;
+ }
+
+ @Override
+ public Iterable<IPortObject> answer() throws Throwable {
+ List<IPortObject> ports = new ArrayList<IPortObject>();
+
+ for(Link lk : links) {
+ if(lk.getDst() == dpid && lk.getDstPort() == port) {
+ ports.add(createMockPort(lk.getSrc(), lk.getSrcPort()));
+ }
+ }
+
+ return ports;
+ }
+
+ }
+
+ /**
* Class defines a function called back when {@link LinkStorageImplTest} is called.
* @author Naoki Shiota
*
@@ -567,6 +611,9 @@
// Mock getLinkPorts() method
EasyMock.expect(mockPort.getLinkedPorts()).andAnswer(new GetLinkedPortsCallback(dpid, number)).anyTimes();
+
+ // Mock getReverseLinkPorts() method
+ EasyMock.expect(mockPort.getReverseLinkedPorts()).andAnswer(new GetReverseLinkedPortsCallback(dpid, number)).anyTimes();
// Mock getSwitch() method
EasyMock.expect(mockPort.getSwitch()).andAnswer(new GetSwitchCallback(dpid)).anyTimes();
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
index dfe6ccf..e4b200f 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/TestableGraphDBOperation.java
@@ -162,6 +162,7 @@
private ISwitchObject sw;
private List<IPortObject> linkedPorts;
+ private List<IPortObject> reverseLinkedPorts;
private List<IDeviceObject> devices;
private List<IFlowEntry> inflows,outflows;
@@ -179,6 +180,7 @@
type = "port";
linkedPorts = new ArrayList<IPortObject>();
+ reverseLinkedPorts = new ArrayList<IPortObject>();
linkedPortsToAdd = new ArrayList<IPortObject>();
linkedPortsToRemove = new ArrayList<IPortObject>();
devices = new ArrayList<IDeviceObject>();
@@ -289,6 +291,9 @@
public Iterable<IPortObject> getLinkedPorts() { return linkedPorts; }
@Override
+ public Iterable<IPortObject> getReverseLinkedPorts() { return reverseLinkedPorts; }
+
+ @Override
public void removeLink(IPortObject dest_port) { linkedPortsToRemove.add(dest_port); }
@Override