Fix test for LinkDicoveryManager
diff --git a/src/main/java/net/onrc/onos/util/GraphDBConnection.java b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
index 7ea0ab8..dcf8aba 100644
--- a/src/main/java/net/onrc/onos/util/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/util/GraphDBConnection.java
@@ -80,7 +80,7 @@
 	      return singleton;
 	   }
 	   
-	   public IDBUtils utils() {
+	public IDBUtils utils() {
 		   return utils;
 	   }
 	   
@@ -110,17 +110,17 @@
 		   log.debug("Registered listener {}",listener.getClass());
 	   }
 	   
-	   public Boolean isValid() {
+	public Boolean isValid() {
 		   
 		   return (graph != null||graph.isOpen());
 	   }
 	   
-	   public void startTx() {
+	public void startTx() {
 		   
 		   
 	   }
 	   
-	   public void endTx(Transaction tx) {
+	public void endTx(Transaction tx) {
 		   try {
 			   switch (tx) {
 			   case COMMIT:
@@ -170,7 +170,7 @@
 		}
 	   }
 	   
-	   public void close() {
+	public void close() {
 		   endTx(Transaction.COMMIT);
 	   }	   
 }
diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
index a6948c0..5aea937 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java
@@ -545,6 +545,11 @@
                 nPortChanged++;
                 notifyAll();
             }
+
+            @Override
+            public void switchPortAdded(Long switchId, OFPhysicalPort port) {};
+            @Override
+            public void switchPortRemoved(Long switchId, OFPhysicalPort port) {};
         }
         DummySwitchListener switchListener = new DummySwitchListener();
         IOFSwitch sw = createMock(IOFSwitch.class);
diff --git a/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java b/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
index 3d5e03b..3cd7bd1 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
@@ -58,8 +58,10 @@
         Iterator<Vertex> it = titanGraph.getVertices("type", "port").iterator();
         while (it.hasNext()){
         	Vertex port = it.next();
-        	Integer portNum = (Integer) port.getProperty("number");
-        	port.setProperty("number", portNum.shortValue());
+        	if(port.getProperty("number").getClass() == Integer.class) {
+        		Integer portNum = port.getProperty("number");
+            	port.setProperty("number", portNum.shortValue());
+        	}
         }
         titanGraph.stopTransaction(Conclusion.SUCCESS);
 	}
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
index 6e99acd..0bf9ba0 100644
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
+++ b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManagerTest.java
@@ -50,6 +50,8 @@
 import net.floodlightcontroller.topology.ITopologyService;
 import net.floodlightcontroller.topology.NodePortTuple;
 import net.floodlightcontroller.topology.TopologyManager;
+import net.onrc.onos.registry.controller.IControllerRegistryService;
+import net.onrc.onos.registry.controller.StandaloneRegistry;
 
 /**
  *
@@ -58,6 +60,7 @@
 public class LinkDiscoveryManagerTest extends FloodlightTestCase {
 
     private TestLinkDiscoveryManager ldm;
+    private StandaloneRegistry srs;
     protected static Logger log = LoggerFactory.getLogger(LinkDiscoveryManagerTest.class);
     
     public class TestLinkDiscoveryManager extends LinkDiscoveryManager {
@@ -99,6 +102,7 @@
         ldm = new TestLinkDiscoveryManager();
         TopologyManager routingEngine = new TopologyManager();
         ldm.linkDiscoveryAware = new ArrayList<ILinkDiscoveryListener>();
+        srs = new StandaloneRegistry();
         MockThreadPoolService tp = new MockThreadPoolService();
         RestApiServer restApi = new RestApiServer();
         cntx.addService(IRestApiService.class, restApi);
@@ -108,13 +112,17 @@
         cntx.addService(ITopologyService.class, ldm);
         cntx.addService(IStorageSourceService.class, new MemoryStorageSource());
         cntx.addService(IFloodlightProviderService.class, getMockFloodlightProvider());
+        cntx.addService(IControllerRegistryService.class, srs);
+
         restApi.init(cntx);
         tp.init(cntx);
         routingEngine.init(cntx);
+        srs.init(cntx);
         ldm.init(cntx);
         restApi.startUp(cntx);
         tp.startUp(cntx);
         routingEngine.startUp(cntx);
+        srs.startUp(cntx);
         ldm.startUp(cntx);
 
         IOFSwitch sw1 = createMockSwitch(1L);
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
index 1e71138..307447c 100644
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
+++ b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/LinkStorageImplTest.java
@@ -11,20 +11,32 @@
 import net.floodlightcontroller.core.internal.TestDatabaseManager;
 import net.floodlightcontroller.linkdiscovery.ILinkStorage;
 import net.floodlightcontroller.routing.Link;
+import net.onrc.onos.util.GraphDBConnection;
+import net.onrc.onos.util.IDBUtils;
 
+import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
+import com.thinkaurelius.titan.core.TitanFactory;
 import com.thinkaurelius.titan.core.TitanGraph;
 import com.tinkerpop.blueprints.Vertex;
 import com.tinkerpop.gremlin.java.GremlinPipeline;
 
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class})
 public class LinkStorageImplTest {
 	private static ILinkStorage linkStorage;
 	private static TitanGraph titanGraph;
 	
+	//private static IController
+
 	//TODO Future ideas:
 	//Test add links with CREATE and UPDATE
 	//Test adding existing link again
@@ -33,13 +45,22 @@
 	public void setUp() throws Exception{
 		titanGraph = TestDatabaseManager.getTestDatabase();
 		TestDatabaseManager.populateTestData(titanGraph);
+
+		linkStorage = new LinkStorageImpl();
+
+		// replace TitanFactory.open() to mock method
+		PowerMock.mockStatic(TitanFactory.class);
+		EasyMock.expect(TitanFactory.open((String)EasyMock.anyObject())).andReturn(titanGraph);
+		PowerMock.replay(TitanFactory.class);
 		
-		linkStorage = new TestableLinkStorageImpl(titanGraph);
+		linkStorage.init("/dummy/path/to/db");
 	}
 	
 	@After
 	public void tearDown() throws Exception {		
+//		dbConnection.close();
 		titanGraph.shutdown();
+		TestDatabaseManager.deleteTestDatabase();
 	}
 	
 	/*
diff --git a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/TestableLinkStorageImpl.java b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/TestableLinkStorageImpl.java
index 223b8a1..d9a6fea 100644
--- a/src/test/java/net/floodlightcontroller/linkdiscovery/internal/TestableLinkStorageImpl.java
+++ b/src/test/java/net/floodlightcontroller/linkdiscovery/internal/TestableLinkStorageImpl.java
@@ -17,6 +17,7 @@
  */
 
 public class TestableLinkStorageImpl extends LinkStorageImpl {
+	protected TitanGraph graph;
 
 	public TestableLinkStorageImpl(TitanGraph graph){
 		this.graph = graph;
@@ -24,6 +25,7 @@
 	
 	@Override
 	public void init(String conf){
+		super.init(conf);
         Set<String> s = graph.getIndexedKeys(Vertex.class);
         if (!s.contains("dpid")) {
            graph.createKeyIndex("dpid", Vertex.class);