Merge pull request #399 from TeruU/develop062001

The unit tests of SwitchStorageImpl
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
index d008220..79a4f76 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -23,18 +23,6 @@
 	/*
 	 * Get all ports associated on a switch
 	 */
-	public Collection<OFPhysicalPort> getPorts(long dpid);
-	/*
-	 * Get Port by Number
-	 */
-	public OFPhysicalPort getPort(String dpid, short portnum);
-	/*
-	 * Get port by name
-	 */
-	public OFPhysicalPort getPort(String dpid, String portName);
-	/*
-	 * Add a switch
-	 */
 	public void addSwitch(String dpid);
 	/*
 	 * Delete switch and associated ports
@@ -45,12 +33,6 @@
 	 */
 	public void deletePort(String dpid, short port);
 	/*
-	 * Delete port on a switch by name
-	 */
-	public void deletePort(String dpid, String portName);
-	
-	
-	/*
 	 * Initialize
 	 */
 	public void init(String conf);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
index 2e9ea60..b12ccfa 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
@@ -1,10 +1,9 @@
 package net.onrc.onos.ofcontroller.core.internal;
 
-import java.util.Collection;
-
 import net.onrc.onos.ofcontroller.core.ISwitchStorage;
 import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
 import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.util.GraphDBConnection;
 import net.onrc.onos.util.GraphDBOperation;
 
 import org.openflow.protocol.OFPhysicalPort;
@@ -13,16 +12,99 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * This is the class for storing the information of switches into CassandraDB
+ */
 public class SwitchStorageImpl implements ISwitchStorage {
 	protected GraphDBOperation op;
 	protected static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
-
+	
+	/***
+	 * Initialize function. Before you use this class, please call this method
+	 * @param conf configuration file for Cassandra DB
+	 */
 	@Override
-	public void update(String dpid, SwitchState state, DM_OPERATION op) {
-		// TODO Auto-generated method stub
-		log.info("SwitchStorage:update dpid:{} state: {} ", dpid, state);
-        switch(op) {
+	public void init(String conf) {
+		GraphDBConnection conn = GraphDBConnection.getInstance(conf);
+		op = new GraphDBOperation(conn);
+	}
 
+	/***
+	 * Finalize/close function. After you use this class, please call this method.
+	 * It will close the DB connection.
+	 */
+	public void finalize() {
+		close();
+	}
+	
+	/***
+	 * Finalize/close function. After you use this class, please call this method.
+	 * It will close the DB connection. This is for Java gabage collection.
+	 */
+	@Override
+	public void close() {
+		op.close();		
+	}
+	
+	private void setStatus(String dpid, SwitchState state) {
+		ISwitchObject sw = op.searchSwitch(dpid);
+		
+		try {
+			if (sw != null) {
+				sw.setState(state.toString());
+				op.commit();
+				log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
+			}
+		} catch(Exception e) {
+			e.printStackTrace();
+			op.rollback();
+			log.info("SwitchStorage:setStatus dpid:{} state: {} failed: switch not found", dpid, state);	
+		}
+	}
+
+	/***
+	 * This function is for adding the switch into the DB.
+	 * @param dpid The switch dpid you want to add into the DB.
+	 */
+	@Override
+	public void addSwitch(String dpid) {
+		
+		log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+		try {
+			ISwitchObject sw = op.searchSwitch(dpid);
+			if (sw != null) {
+				//If existing the switch. set The SW state ACTIVE. 
+				log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
+				sw.setState(SwitchState.ACTIVE.toString());
+				op.commit();
+			} else {
+				sw = op.newSwitch(dpid);
+
+				if (sw != null) {
+					sw.setState(SwitchState.ACTIVE.toString());
+					op.commit();
+					log.info("SwitchStorage:addSwitch dpid:{} added", dpid);
+				} else {
+					log.error("switchStorage:addSwitch dpid:{} failed -> newSwitch failed", dpid);
+				}
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			op.rollback();
+			log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+		}
+	}
+	
+	/***
+	 * This function is for updating the switch into the DB.
+	 * @param dpid The switch dpid you want to update from the DB
+	 * @param state The state of the switch like ACTIVE, INACTIVE
+	 * @param dmope	The DM_OPERATION of the switch
+	 */
+	@Override
+	public void update(String dpid, SwitchState state, DM_OPERATION dmope) {
+		log.info("SwitchStorage:update dpid:{} state: {} ", dpid, state);
+        switch(dmope) {
         	case UPDATE:
         	case INSERT:
         	case CREATE:
@@ -38,29 +120,41 @@
         }
 	}
 
-	private void setStatus(String dpid, SwitchState state) {
-		ISwitchObject sw = op.searchSwitch(dpid);
-		if (sw != null) {
-			sw.setState(state.toString());
-			op.commit();
-			log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
-		} 	else {
-			op.rollback();
-			log.info("SwitchStorage:setStatus dpid:{} state: {} failed: switch not found", dpid, state);
+	/***
+	 * This function is for deleting the switch into the DB.
+	 * @param dpid The switch dpid you want to delete from the DB.
+	 */
+	@Override
+	public void deleteSwitch(String dpid) {
+		try {
+			ISwitchObject sw = op.searchSwitch(dpid);
+            if (sw  != null) {
+            	op.removeSwitch(sw);
+            	op.commit();
+            	log.info("SwitchStorage:DeleteSwitch dpid:{} done", dpid);
+            }
+		} catch (Exception e) {
+			e.printStackTrace();
+			op.rollback();			
+			log.error("SwitchStorage:deleteSwitch {} failed", dpid);
 		}
+
 	}
 
+	/***
+	 * This function is for adding the switch port into the DB.
+	 * @param dpid The switch dpid that has the port.
+	 * @param port The port you want to add the switch.
+	 */
 	@Override
 	public void addPort(String dpid, OFPhysicalPort port) {
-		// TODO Auto-generated method stub
 		
-        boolean portDown = ((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
-        		((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0);
-       if (portDown) {
-             deletePort(dpid, port.getPortNumber());
-             return;
+       if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
+        					((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0)) {
+    	     deletePort(dpid, port.getPortNumber());
+             return;  
        }
-             
+
 		try {
 			ISwitchObject sw = op.searchSwitch(dpid);
 
@@ -81,95 +175,20 @@
         		log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, port.getPortNumber());
             }
 		} catch (Exception e) {
-             // TODO: handle exceptions
 			e.printStackTrace();
 			op.rollback();
 			log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, port.getPortNumber());
 		}	
 
 	}
-
-	@Override
-	public Collection<OFPhysicalPort> getPorts(long dpid) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public OFPhysicalPort getPort(String dpid, short portnum) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public OFPhysicalPort getPort(String dpid, String portName) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	@Override
-	public void addSwitch(String dpid) {
-		
-		log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
-		
-		try {
-			ISwitchObject sw = op.searchSwitch(dpid);
-			if (sw != null) {
-				/*
-				 *  Do nothing or throw exception?
-				 */
-
-				log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
-				sw.setState(SwitchState.ACTIVE.toString());
-				op.commit();
-			} else {
-				sw = op.newSwitch(dpid);
-
-				if (sw != null) {
-					sw.setState(SwitchState.ACTIVE.toString());
-					op.commit();
-					log.info("SwitchStorage:addSwitch dpid:{} added", dpid);
-				} else {
-					log.error("switchStorage:addSwitch dpid:{} failed -> newSwitch failed", dpid);
-				}
-			}
-		} catch (Exception e) {
-			/*
-			 * retry?
-			 */
-			e.printStackTrace();
-			op.rollback();
-			log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
-		}
-
-
-	}
-
-	@Override
-	public void deleteSwitch(String dpid) {
-		// TODO Setting inactive but we need to eventually remove data
-
-		try {
-
-			ISwitchObject sw = op.searchSwitch(dpid);
-            if (sw  != null) {
-            	op.removeSwitch(sw);
- 
-            	op.commit();
-            	log.info("SwitchStorage:DeleteSwitch dpid:{} done", dpid);
-            }
-		} catch (Exception e) {
-             // TODO: handle exceptions
-			e.printStackTrace();
-			op.rollback();			
-			log.error("SwitchStorage:deleteSwitch {} failed", dpid);
-		}
-
-	}
-
+	
+	/***
+	 * This function is for deleting the switch port from the DB.
+	 * @param dpid The switch dpid that has the port.
+	 * @param port The port you want to delete the switch.
+	 */
 	@Override
 	public void deletePort(String dpid, short port) {
-		// TODO Auto-generated method stub
 		try {
 			ISwitchObject sw = op.searchSwitch(dpid);
 
@@ -183,36 +202,9 @@
             	}
             }
 		} catch (Exception e) {
-             // TODO: handle exceptions
 			e.printStackTrace();
 			op.rollback();
 			log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
 		}	
 	}
-
-	@Override
-	public void deletePort(String dpid, String portName) {
-		// TODO Auto-generated method stub
-
-	}
-
-
-
-	@Override
-	public void init(String conf) {
-		op = new GraphDBOperation(conf);
-	}
-
-
-
-	public void finalize() {
-		close();
-	}
-	
-	@Override
-	public void close() {
-		op.close();		
-	}
-
-	
-}
+}
\ No newline at end of file
diff --git a/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java b/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
index 8a09139..f811c9d 100644
--- a/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
+++ b/src/test/java/net/floodlightcontroller/core/internal/TestDatabaseManager.java
@@ -58,8 +58,17 @@
         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") instanceof Short)
+        	{
+        		Short portNum = (Short) port.getProperty("number");
+        		port.setProperty("number", portNum.shortValue());
+        	}
+        	else{
+        		Integer portNum = (Integer) port.getProperty("number");	
+        		port.setProperty("number", portNum.shortValue());
+        	}
+
         }
         titanGraph.stopTransaction(Conclusion.SUCCESS);
 	}
@@ -73,4 +82,4 @@
 		}
 	}
 	
-}
\ No newline at end of file
+}
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
index ebfb532..daac980 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
@@ -1,278 +1,768 @@
 package net.onrc.onos.ofcontroller.core.internal;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
+import static org.easymock.EasyMock.*;
 
 import net.onrc.onos.ofcontroller.core.ISwitchStorage;
 import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
-
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.util.GraphDBConnection;
+import net.onrc.onos.util.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+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.openflow.protocol.OFPhysicalPort;
+import org.openflow.protocol.OFPhysicalPort.OFPortState;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.LoggerFactory;
 
+import com.thinkaurelius.titan.core.TitanFactory;
 import com.thinkaurelius.titan.core.TitanGraph;
-import com.tinkerpop.blueprints.Vertex;
-import com.tinkerpop.gremlin.java.GremlinPipeline;
-import com.tinkerpop.pipes.PipeFunction;
-import com.tinkerpop.pipes.branch.LoopPipe.LoopBundle;
 
-import javax.script.ScriptContext;
-import javax.script.ScriptEngine;
-import javax.script.ScriptException;
-import com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine;
-
-
+//Add Powermock preparation
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({TitanFactory.class, GraphDBConnection.class, GraphDBOperation.class, SwitchStorageImpl.class})
 public class SwitchStorageImplTest {
 
-	private ISwitchStorage switchStorage;
-	private TitanGraph titanGraph;
-	
+	protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+	String conf;
+    private GraphDBConnection mockConn = null;
+    private GraphDBOperation mockOpe = null;
+    private GraphDBOperation realOpe = null;
+    private TitanGraph titanGraph = null;
+    ISwitchStorage swSt = null;
+    
 	@Before
 	public void setUp() throws Exception {
-		titanGraph = TestDatabaseManager.getTestDatabase();
-		TestDatabaseManager.populateTestData(titanGraph);
 		
-		switchStorage = new TestableSwitchStorageImpl();
+		swSt = new SwitchStorageImpl();
+		conf = "/dummy/path/to/db";
+		
+        // Make mock cassandra DB
+		// Replace TitanFactory.open() to return mock DB
+
+		PowerMock.mockStatic(GraphDBConnection.class);
+		mockConn = createMock(GraphDBConnection.class);
+		PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class));
+		EasyMock.expect(GraphDBConnection.getInstance((String)EasyMock.anyObject())).andReturn(mockConn);
+		PowerMock.replay(GraphDBConnection.class);
+		
+		PowerMock.mockStatic(GraphDBOperation.class);
+		mockOpe = PowerMock.createStrictMock(GraphDBOperation.class);
+		PowerMock.expectNew(GraphDBOperation.class, mockConn).andReturn(mockOpe);
+		PowerMock.replay(GraphDBOperation.class);
+        // Replace the conf to dummy conf
+		// String conf = "/tmp/cassandra.titan";
+		
+
 	}
 
 	@After
 	public void tearDown() throws Exception {
-		titanGraph.shutdown();
+		swSt.close();
+		swSt = null;
+		
 	}
-
-	@Ignore @Test
-	public void testUpdate() {
-		fail("Not yet implemented");
-	}
-
-	@Test
-	public void testAddPort() {
-		
-		String dpid = "00:00:00:00:00:00:0a:01";
-		short portNumber = 5;
-		
-		OFPhysicalPort portToAdd = new OFPhysicalPort();
-		portToAdd.setName("port 5 at SEA switch");
-		portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue());
-		portToAdd.setPortNumber(portNumber);
-		
-		switchStorage.addPort(dpid, portToAdd);
-		
-		Vertex sw = titanGraph.getVertices("dpid", dpid).iterator().next();
-		
-		GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
-		pipe.start(sw).out("on").has("number", portNumber);
-		
-		assertTrue(pipe.hasNext());
-		Vertex addedPort = pipe.next();
-		assertFalse(pipe.hasNext());
-		
-		assertEquals(addedPort.getProperty("number"), portNumber);
-	}
-
-	@Ignore @Test
-	public void testGetPorts() {
-		fail("Not yet implemented");
-	}
-
-	@Ignore @Test
-	public void testGetPortStringShort() {
-		fail("Not yet implemented");
-	}
-
-	@Ignore @Test
-	public void testGetPortStringString() {
-		fail("Not yet implemented");
-	}
-
+	
+	/**
+	 * Desc:
+	 *  Test method for addSwitch method.
+	 * Condition:
+	 *  Normal
+	 * Expect:
+	 * 	Call SwitchStorageImpl.addSwitch func with proper properties.
+	 */
+	@Ignore 
 	@Test
 	public void testAddSwitch() {
 		String dpid = "00:00:00:00:00:00:0a:07";
+		String state = "ACTIVE";
 		
-		switchStorage.addSwitch(dpid);
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		replay(mockISw);
 		
-		Iterator<Vertex> it = titanGraph.getVertices("dpid", dpid).iterator();
-		assertTrue(it.hasNext());
-		Vertex addedSwitch = it.next();
-		assertFalse(it.hasNext());
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
 		
-		assertEquals(addedSwitch.getProperty("type"), "switch");
-		assertEquals(addedSwitch.getProperty("dpid"), dpid);
-		assertEquals(addedSwitch.getProperty("state"), SwitchState.ACTIVE.toString());
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
 	}
-
 	
+	/**
+	 * Desc:
+	 *  Test method for addSwitch method.
+	 * Condition:
+	 *  The switch is already existing.
+	 * Expect:
+	 * 	Call SwitchStorageImpl.addSwitch func with proper properties.
+	 */
+	//@Ignore 
+	@Test
+	public void testAddSwitchExisting() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		String state = "ACTIVE";
+		
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		mockISw.setState(state);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
+		
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.addSwitch(dpid);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for addSwitch method.
+	 * Condition:
+	 *  The switch construction is fail and return null
+	 * Expect:
+	 * 	Write the status as info log.
+	 */
+	//@Ignore 
+	@Test
+	public void testAddSwitchAbnormal() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(null);
+		mockOpe.close();
+		replay(mockOpe);
+		
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for addSwitch method.
+	 * Condition:
+	 *  Tthrow runtimeException. 
+	 * Expect:
+	 * 	The rollback method is called.
+	 */
+	//@Ignore 
+	@Test
+	public void testAddSwitchException() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		String state = "ACTIVE";
+		
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expectLastCall().andThrow(new RuntimeException());
+		mockOpe.rollback();
+		mockOpe.close();
+		replay(mockOpe);
+		
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for updateSwitch method.
+	 * Condition:
+	 *  SwitchState : INACTIVE
+	 *  DMOPERATION : UPDATE
+	 * Expect:
+	 * 	Should call addSwitch function and commit.
+	 */
+	//@Ignore 
+	@Test
+	public void testUpdateUPDATE() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		SwitchState stateINACTIVE = SwitchState.INACTIVE;
+		DM_OPERATION opUPDATE = DM_OPERATION.UPDATE;
+		
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState("ACTIVE");
+		mockISw.setState(stateINACTIVE.toString());
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);	
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
+		
+		swSt.init(conf);
+		swSt.update(dpid, stateINACTIVE, opUPDATE);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for updateSwitch method.
+	 * Condition:
+	 *  SwitchState : INACTIVE
+	 *  DMOPERATION : CREATE
+	 * Expect:
+	 * 	Should call addSwitch function and commit.
+	 */
+	//@Ignore 
+	@Test
+	public void testUpdateCREATE() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		SwitchState stateINACTIVE = SwitchState.INACTIVE;
+		DM_OPERATION opCREATE = DM_OPERATION.CREATE;
+		
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState("ACTIVE");
+		mockISw.setState(stateINACTIVE.toString());
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);	
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
+		
+		swSt.init(conf);
+		swSt.update(dpid, stateINACTIVE, opCREATE);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for updateSwitch method.
+	 * Condition:
+	 *  SwitchState : INACTIVE
+	 *  DMOPERATION : INSERT
+	 * Expect:
+	 * 	Should call addSwitch function and commit.
+	 */
+	//@Ignore 
+	@Test
+	public void testUpdateINSERT() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		SwitchState stateINACTIVE = SwitchState.INACTIVE;
+		DM_OPERATION opINSERT = DM_OPERATION.INSERT;
+		
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState("ACTIVE");
+		mockISw.setState(stateINACTIVE.toString());
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
+		
+		swSt.init(conf);
+		swSt.update(dpid, stateINACTIVE, opINSERT);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for updateSwitch method.
+	 * Condition:
+	 *  SwitchState : ACTIVE
+	 *  DMOPERATION : DELETE
+	 * Expect:
+	 * 	Should call removeSwitch function and commit.
+	 */
+	//@Ignore 
+	@Test
+	public void testUpdateDELETE() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		SwitchState stateACTIVE = SwitchState.ACTIVE;
+		DM_OPERATION opDELETE = DM_OPERATION.DELETE;
+		
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(stateACTIVE.toString());
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		mockOpe.removeSwitch(mockISw);
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
+		
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.update(dpid, stateACTIVE, opDELETE);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for deleteSwitch method.
+	 * Condition:
+	 *  The switch is existing.
+	 * Expect:
+	 * 	Should call removeSwitch function and commit.
+	 */
+	//@Ignore
 	@Test
 	public void testDeleteSwitch() {
-		String dpid = "00:00:00:00:00:00:0a:01";
+		String dpid = "00:00:00:00:00:00:0a:07";
+		String state = "ACTIVE";
+	
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		replay(mockISw);
 		
-		switchStorage.deleteSwitch(dpid);
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+    	mockOpe.removeSwitch(mockISw);
+    	mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
 		
-		Iterator<Vertex> it = titanGraph.getVertices("dpid", dpid).iterator();
-		assertFalse(it.hasNext());
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.deleteSwitch(dpid);
+		
+		//Iterator<Vertex> it = titanGraph.getVertices("dpid", dpid).iterator();
+		//assertFalse(it.hasNext());
 	}
-
+	
+	/**
+	 * Desc:
+	 *  Test method for deleteSwitch method.
+	 * Condition:
+	 *  The commit func throw exception.
+	 * Expect:
+	 * 	Should call rollback.
+	 */
+	//@Ignore
 	@Test
-	public void testDeletePortByPortNum() {
-		//FIXME fails because query for the port is wrong in SwitchStorageImpl
+	public void testDeleteSwitchException() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		String state = "ACTIVE";
+		String type = "";
 		
-		String dpid = "00:00:00:00:00:00:0a:01";
-		short portNum = 3;
+		//Mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		replay(mockISw);
 		
-		switchStorage.deletePort(dpid, portNum);
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+    	mockOpe.removeSwitch(mockISw);
+    	mockOpe.commit();
+		expectLastCall().andThrow(new RuntimeException());
+		mockOpe.rollback();
+		mockOpe.close();
+		replay(mockOpe);
 		
-		Vertex sw = titanGraph.getVertices("dpid", dpid).iterator().next();
-		
-		/*
-		Iterator<Vertex> it = sw.getVertices(Direction.OUT, "on").iterator();
-		
-		while (it.hasNext()){
-			System.out.println(it.next());
-		}
-		*/
-		
-		GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
-		pipe.start(sw).out("on").has("number", portNum);
-		assertFalse(pipe.hasNext());
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.deleteSwitch(dpid);
 	}
-
-	@Ignore @Test
-	public void testDeletePortStringString() {
-		fail("Not yet implemented");
-	}
-
-	@Ignore @Test
-	public void testGetActiveSwitches() {
-		fail("Not yet implemented");
-	}
-
-	static class MyLoopFunction implements PipeFunction<LoopBundle<Vertex>, Boolean> {
-	    String dpid;
-	    public MyLoopFunction(String dpid) {
-		super();
-		this.dpid = dpid;
-	    }
-	    public Boolean compute(LoopBundle<Vertex> bundle) {
-		Boolean output = false;
-		if (! bundle.getObject().getProperty("dpid").equals(dpid)) {
-		    output = true;
-		}
-		return output;
-	    }
-	}
-
+	
+	/**
+	 * Desc:
+	 *  Test method for addPort method.
+	 * Condition:
+	 *  port is existing.
+	 * Expect:
+	 * 	Should call addPort and commit.
+	 */
+	//@Ignore
 	@Test
-	public void testShortestPath() {
-	    String dpid_src = "00:00:00:00:00:00:0a:01";
-	    String dpid_dest = "00:00:00:00:00:00:0a:06";
+	public void testAddPort() {
+		String dpid = "00:00:00:00:00:00:0a:01";
+		short portNumber = 5;
+		String state = "ACTIVE";
+		String name = "port 5 at SEA switch";
+		
+		OFPhysicalPort portToAdd = new OFPhysicalPort();
+		portToAdd.setName(name);
+		portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue());
+		portToAdd.setPortNumber(portNumber);
+		portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		
+		//Expectation of  mock Port
+		IPortObject mockIPort = createMock(IPortObject.class);
+		mockIPort.setState(state);
+		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		mockIPort.setDesc(name);
+		replay(mockIPort);
+		
+		//Expectation of mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		mockISw.addPort(mockIPort);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+		expect(mockOpe.newPort(portNumber)).andReturn(mockIPort);	
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
 
-	    //
-	    // Implement the Shortest Path between two vertices by using
-	    // the following Gremlin CLI code:
-	    //   v_src.as("x").out("on").out("link").in("on").dedup().loop("x"){it.object.dpid != v_dest.dpid}.path(){it.dpid}{it.number}{it.number}
-	    // The equivalent code used here is:
-	    //   results = []; v_src.as("x").out("on").out("link").in("on").dedup().loop("x"){it.object.dpid != v_dest.dpid}.path().fill(results)
-	    //
-
-	    // Get the source vertex
-	    Iterator<Vertex> iter = titanGraph.getVertices("dpid", dpid_src).iterator();
-	    if (! iter.hasNext())
-		return;			// Source vertex not found
-	    Vertex v_src = iter.next();
-
-	    // Get the destination vertex
-	    iter = titanGraph.getVertices("dpid", dpid_dest).iterator();
-	    if (! iter.hasNext())
-		return;			// Destination vertex not found
-	    Vertex v_dest = iter.next();
-
-	    //
-	    // Implement the Gremlin script and run it
-	    //
-	    // NOTE: This mechanism is slower. The code is kept here
-	    // for future reference.
-	    //
-	    /*
-	    String gremlin = "v_src.as(\"x\").out(\"on\").out(\"link\").in(\"on\").dedup().loop(\"x\"){it.object.dpid != v_dest.dpid}.path().fill(results)";
-
-	    String gremlin_nopath = "v_src.as(\"x\").out(\"on\").out(\"link\").in(\"on\").dedup().loop(\"x\"){it.object.dpid != \"NO-SUCH-DPID\"}.path().fill(results)";
-
-	    ScriptEngine engine = new GremlinGroovyScriptEngine();
-	    ArrayList<ArrayList<Vertex>> results = new ArrayList<ArrayList<Vertex>>();
-	    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", titanGraph);
-	    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("v_src", v_src);
-	    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("v_dest", v_dest);
-	    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("results", results);
-
-	    try {
-		engine.eval(gremlin);
-	    } catch (ScriptException e) {
-		System.err.println("Caught ScriptException running Gremlin script: " + e.getMessage());
-		return;
-	    }
-
-	    for (ArrayList<Vertex> lv : results) {
-		...
-	    }
-	    */
-
-	    MyLoopFunction whileFunction = new MyLoopFunction(dpid_dest);
-	    GremlinPipeline<Vertex, Vertex> pipe = new GremlinPipeline<Vertex, Vertex>();
-	    Collection<List> results = new ArrayList<List>();
-	    GremlinPipeline<Vertex, List> path;
-	    path = pipe.start(v_src).as("x").out("on").out("link").in("on").dedup().loop("x", whileFunction).path();
-	    path.fill(results);
-
-	    //
-	    // Extract the result and compose it into a string
-	    //
-	    String results_str = "";
-	    // System.out.println("BEGIN " + results.size());
-	    for (List l : results) {
-		for (Object o: l) {
-		    Vertex v = (Vertex)(o);
-		    // System.out.println(v);
-		    String type = v.getProperty("type").toString();
-		    results_str += "[type: " + type;
-		    // System.out.println("type: " + type);
-		    if (type.equals("port")) {
-			String number = v.getProperty("number").toString();
-			// System.out.println("number: " + number);
-			results_str += " number: " + number + "]";
-		    }
-		    if (type.equals("switch")) {
-			String dpid = v.getProperty("dpid").toString();
-			// System.out.println("dpid: " + dpid);
-			results_str += " dpid: " + dpid + "]";
-		    }
-		}
-	    }
-	    // System.out.println("END\n");
-	    System.out.println(results_str);
-
-	    //
-	    // Check the result
-	    //
-	    String expected_result = "[type: switch dpid: 00:00:00:00:00:00:0a:01][type: port number: 2][type: port number: 1][type: switch dpid: 00:00:00:00:00:00:0a:03][type: port number: 2][type: port number: 2][type: switch dpid: 00:00:00:00:00:00:0a:04][type: port number: 3][type: port number: 1][type: switch dpid: 00:00:00:00:00:00:0a:06]";
-
-	    assertEquals(results_str, expected_result);
-
-	    //
-	    // Test Shortest-Path computation to non-existing destination
-	    //
-	    results.clear();
-	    MyLoopFunction noDestWhileFunction = new MyLoopFunction("NO-SUCH-DPID");
-	    path = pipe.start(v_src).as("x").out("on").out("link").in("on").dedup().loop("x", noDestWhileFunction).path();
-	    path.fill(results);
-	    assertTrue(results.size() == 0);
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.addPort(dpid, portToAdd);
 	}
-}
+	
+	/**
+	 * Desc:
+	 *  Test method for addPort method.
+	 * Condition:
+	 *  Port status is down.
+	 * Expect:
+	 * 	Should call removePort and commit.
+	 */
+	//@Ignore
+	@Test
+	public void testAddPortWithPortLinkDown() {
+		String dpid = "00:00:00:00:00:00:0a:01";
+		short portNumber = 5;
+		String state = "ACTIVE";
+		String name = "port 5 at SEA switch";
+		
+		OFPhysicalPort portToAdd = new OFPhysicalPort();
+		portToAdd.setName(name);
+		portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue());
+		portToAdd.setPortNumber(portNumber);
+		portToAdd.setState(OFPortState.OFPPS_LINK_DOWN.getValue());
+		
+		//Expectation of  mock Port
+		IPortObject mockIPort = createMock(IPortObject.class);
+		mockIPort.setState(state);
+		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		mockIPort.setDesc(name);
+		replay(mockIPort);
+		
+		//Expectation of mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		mockISw.removePort(mockIPort);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);	
+		mockOpe.commit();	
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+		mockOpe.removePort(mockIPort);
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
+
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.addPort(dpid, portToAdd);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for addPort method.
+	 * Condition:
+	 *  The switch is not existing.
+	 * Expect:
+	 * 	Nothing happens.
+	 */
+	//@Ignore
+	@Test
+	public void testAddPortAbnormalNoSwitch() {
+		String dpid = "00:00:00:00:00:00:0a:01";
+		short portNumber = 5;
+		String state = "ACTIVE";
+		String name = "port 5 at SEA switch";
+		
+		OFPhysicalPort portToAdd = new OFPhysicalPort();
+		portToAdd.setName(name);
+		portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue());
+		portToAdd.setPortNumber(portNumber);
+		portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		
+		//Expectation of  mock Port
+		IPortObject mockIPort = createStrictMock(IPortObject.class);
+		replay(mockIPort);
+		
+		//Expectation of mock Switch
+		ISwitchObject mockISw = createStrictMock(ISwitchObject.class);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		mockOpe.close();
+		replay(mockOpe);
+
+		swSt.init(conf);
+		swSt.addPort(dpid, portToAdd);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for addPort method.
+	 * Condition:
+	 *  port is not existing.
+	 * Expect:
+	 * 	Should call addPort and commit.
+	 */
+	//@Ignore
+	@Test
+	public void testAddPortAbnormalNoPort() {
+		String dpid = "00:00:00:00:00:00:0a:01";
+		short portNumber = 5;
+		String state = "ACTIVE";
+		String name = "port 5 at SEA switch";
+		
+		OFPhysicalPort portToAdd = new OFPhysicalPort();
+		portToAdd.setName(name);
+		portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue());
+		portToAdd.setPortNumber(portNumber);
+		portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		
+		//Expectation of  mock Port
+		IPortObject mockIPort = createMock(IPortObject.class);
+		mockIPort.setState(state);
+		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		mockIPort.setDesc(name);
+		replay(mockIPort);
+		
+		//Expectation of mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		mockISw.addPort(mockIPort);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+		expect(mockOpe.newPort(portNumber)).andReturn(null);	
+		mockOpe.rollback();
+		mockOpe.close();
+		replay(mockOpe);
+
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.addPort(dpid, portToAdd);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for addPort method.
+	 * Condition:
+	 *  commit throw the exception.
+	 * Expect:
+	 * 	Should call rollback.
+	 */
+	//@Ignore
+	@Test
+	public void testAddPortWithException() {
+		String dpid = "00:00:00:00:00:00:0a:01";
+		short portNumber = 5;
+		String state = "ACTIVE";
+		String name = "port 5 at SEA switch";
+		
+		OFPhysicalPort portToAdd = new OFPhysicalPort();
+		portToAdd.setName(name);
+		portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue());
+		portToAdd.setPortNumber(portNumber);
+		portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		
+		//Expectation of  mock Port
+		IPortObject mockIPort = createMock(IPortObject.class);
+		mockIPort.setState(state);
+		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		mockIPort.setDesc(name);
+		replay(mockIPort);
+		
+		//Expectation of mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		mockISw.addPort(mockIPort);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+		expect(mockOpe.newPort(portNumber)).andReturn(mockIPort);	
+		mockOpe.commit();
+		expectLastCall().andThrow(new RuntimeException());
+		mockOpe.rollback();
+		mockOpe.close();
+		replay(mockOpe);
+
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.addPort(dpid, portToAdd);
+	}
+
+	/**
+	 * Desc:
+	 *  Test method for deletePort method.
+	 * Condition:
+	 *  port is existing.
+	 * Expect:
+	 * 	Should call removePort and commit.
+	 */
+	//@Ignore
+	@Test
+	public void testDeletePort() {
+		String dpid = "00:00:00:00:00:00:0a:01";
+		short portNumber = 5;
+		String state = "ACTIVE";
+		String name = "port 5 at SEA switch";
+		
+		OFPhysicalPort portToAdd = new OFPhysicalPort();
+		portToAdd.setName(name);
+		portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue());
+		portToAdd.setPortNumber(portNumber);
+		portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		
+		//Expectation of  mock Port
+		IPortObject mockIPort = createMock(IPortObject.class);
+		mockIPort.setState(state);
+		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		mockIPort.setDesc(name);
+		replay(mockIPort);
+		
+		//Expectation of mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		mockISw.addPort(mockIPort);
+		mockISw.removePort(mockIPort);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+		expect(mockOpe.newPort(portNumber)).andReturn(mockIPort);	
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+		mockOpe.removePort(mockIPort);
+		mockOpe.commit();
+		mockOpe.close();
+		replay(mockOpe);
+
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.addPort(dpid, portToAdd);
+		swSt.deletePort(dpid, portNumber);
+	}
+
+	/**
+	 * Desc:
+	 *  Test method for addPort method.
+	 * Condition:
+	 *  commit throws the exception.
+	 * Expect:
+	 * 	Should call rollback.
+	 */
+	//@Ignore
+	@Test
+	public void testDeletePortException() {
+		String dpid = "00:00:00:00:00:00:0a:01";
+		short portNumber = 5;
+		String state = "ACTIVE";
+		String name = "port 5 at SEA switch";
+		
+		OFPhysicalPort portToAdd = new OFPhysicalPort();
+		portToAdd.setName(name);
+		portToAdd.setCurrentFeatures(OFPhysicalPort.OFPortFeatures.OFPPF_100MB_FD.getValue());
+		portToAdd.setPortNumber(portNumber);
+		portToAdd.setState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		
+		//Expectation of  mock Port
+		IPortObject mockIPort = createMock(IPortObject.class);
+		mockIPort.setState(state);
+		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+		mockIPort.setDesc(name);
+		replay(mockIPort);
+		
+		//Expectation of mock Switch
+		ISwitchObject mockISw = createMock(ISwitchObject.class);
+		mockISw.setState(state);
+		mockISw.addPort(mockIPort);
+		mockISw.removePort(mockIPort);
+		replay(mockISw);
+		
+		//Expectation of mock operation.
+		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
+		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+		expect(mockOpe.newPort(portNumber)).andReturn(mockIPort);	
+		mockOpe.commit();
+		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
+		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+		mockOpe.removePort(mockIPort);
+		expectLastCall().andThrow(new RuntimeException());
+		mockOpe.rollback();
+		mockOpe.close();
+		replay(mockOpe);
+	
+		swSt.init(conf);
+		swSt.addSwitch(dpid);
+		swSt.addPort(dpid, portToAdd);
+		swSt.deletePort(dpid, portNumber);
+	}
+}
\ No newline at end of file
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
new file mode 100644
index 0000000..f6f70ae
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
@@ -0,0 +1,334 @@
+package net.onrc.onos.ofcontroller.core.internal;
+
+import static org.junit.Assert.*;
+
+import net.floodlightcontroller.core.internal.TestDatabaseManager;
+import net.onrc.onos.ofcontroller.core.ISwitchStorage;
+import net.onrc.onos.ofcontroller.core.ISwitchStorage.SwitchState;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.util.GraphDBConnection;
+import net.onrc.onos.util.GraphDBOperation;
+import net.onrc.onos.ofcontroller.core.INetMapStorage;
+import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+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.openflow.protocol.OFPhysicalPort;
+import org.openflow.protocol.OFPhysicalPort.OFPortState;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.LoggerFactory;
+
+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 SwitchStorageImplTestBB {
+
+	protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+	String conf;
+    private GraphDBConnection conn = null;
+    private GraphDBOperation ope = null;
+    private TitanGraph titanGraph = null;
+    ISwitchStorage swSt = null;
+    
+	@Before
+	public void setUp() throws Exception {
+		
+		swSt = new SwitchStorageImpl();
+		conf = "/dummy/path/to/db";
+		
+		// Make mock cassandra DB
+		// Replace TitanFactory.open() to return mock DB
+		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);
+		
+		swSt.init(conf);
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		
+		titanGraph.shutdown();
+		TestDatabaseManager.deleteTestDatabase();
+
+		swSt.close();
+		swSt = null;
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for addSwitch method.
+	 * Condition:
+	 *  Normal
+	 * Expect:
+	 * 1. Switch should be generated.
+	 * 2. The status of switch should be ACTIVE
+	 */
+	//@Ignore 
+	@Test
+	public void testAddSwitch() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw == null);
+		swSt.addSwitch(dpid);
+		ISwitchObject sw2 = ope.searchSwitch(dpid);
+		assertTrue(sw2 != null);
+		assertEquals(sw2.getState(), "ACTIVE");
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for addSwitch method.
+	 * Condition:
+	 *  The existing switch status is INACTIVE.
+	 *  The switch is already existing.
+	 * Expect:
+	 * 1. After add the same switch, the status of switch should be ACTIVE
+	 */
+	//@Ignore 
+	@Test
+	public void testAddSwitchExisting() {
+		String dpid = "00:00:00:00:00:00:0a:06";
+		
+		swSt.update(dpid, SwitchState.INACTIVE, DM_OPERATION.UPDATE);
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw != null);
+		assertEquals(sw.getState(), SwitchState.INACTIVE.toString());
+		swSt.addSwitch(dpid);
+		ISwitchObject sw2 = ope.searchSwitch(dpid);
+		assertTrue(sw2 != null);
+		assertEquals(sw2.getState(), SwitchState.ACTIVE.toString());
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for testUpdate method.
+	 * Condition:
+	 *  The switch is not existing.
+	 *  The status of added switch is INACTIVE.
+	 *  DM_OPERATION is CREATE.
+	 * Expect:
+	 * 1. Switch should be created.
+	 * 2. The status of switch should be INACTIVE.
+	 */
+	//@Ignore 
+	@Test
+	public void testUpdate() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		SwitchState state = ISwitchStorage.SwitchState.INACTIVE;
+		DM_OPERATION dmope = INetMapStorage.DM_OPERATION.CREATE;
+		
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw == null);
+		swSt.update(dpid, state, dmope);
+		ISwitchObject sw2 = ope.searchSwitch(dpid);
+		assertTrue(sw2 != null);
+		assertEquals(sw2.getState(), state.toString());
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for testUpdate method.
+	 * Condition:
+	 *  The switch is existing.
+	 *  The status of added switch is ACTIVE.
+	 *  DM_OPERATION is DELETE.
+	 * Expect:
+	 * 1. Switch should be deleted.
+	 */
+	//@Ignore 
+	@Test
+	public void testUpdateWithDELETE() {
+		String dpid = "00:00:00:00:00:00:0a:06";
+		SwitchState state = ISwitchStorage.SwitchState.ACTIVE;
+		DM_OPERATION dmope = INetMapStorage.DM_OPERATION.DELETE;
+		
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw != null);
+		swSt.update(dpid, state, dmope);
+		ISwitchObject sw2 = ope.searchSwitch(dpid);
+		assertTrue(sw2 == null);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for delete switch method.
+	 * Condition:
+	 *  The switch is existing.
+	 * Expect:
+	 * 1. Switch should be deleted.
+	 */
+	//@Ignore 
+	@Test
+	public void testDeleteSwitch() {
+		String dpid = "00:00:00:00:00:00:0a:06";
+		
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw != null);
+		swSt.deleteSwitch(dpid);
+		ISwitchObject sw2 = ope.searchSwitch(dpid);
+		assertTrue(sw2 == null);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for delete switch method.
+	 * Condition:
+	 *  The switch is not existing.
+	 * Expect:
+	 * Nothing happens.
+	 */
+	//@Ignore 
+	@Test
+	public void testDeleteNonExistingSwitch() {
+		String dpid = "00:00:00:00:00:00:0a:07";
+		
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw == null);
+		swSt.deleteSwitch(dpid);
+		ISwitchObject sw2 = ope.searchSwitch(dpid);
+		assertTrue(sw2 == null);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for delete port method.
+	 * Condition:
+	 *  The port is existing.
+	 * Expect:
+	 *  Deleted the port.
+	 */
+	//@Ignore 
+	@Test
+	public void testDeletePort() {
+		String dpid = "00:00:00:00:00:00:0a:06";
+		short portNumber = 3;
+		
+		IPortObject portObj1 = ope.searchPort(dpid, portNumber);
+		assertTrue(portObj1 != null);
+		swSt.deletePort(dpid, portNumber);
+		IPortObject portObj2 = ope.searchPort(dpid, portNumber);
+		assertTrue(portObj2 == null);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for delete port method.
+	 * Condition:
+	 *  The port is not existing.
+	 * Expect:
+	 *  Nothing happens.
+	 */
+	//@Ignore 
+	@Test
+	public void testDeleteNonExistingPort() {
+		String dpid = "00:00:00:00:00:00:0a:06";
+		short portNumber = 4;
+		
+		IPortObject portObj1 = ope.searchPort(dpid, portNumber);
+		assertTrue(portObj1 == null);
+		swSt.deletePort(dpid, portNumber);
+		IPortObject portObj2 = ope.searchPort(dpid, portNumber);
+		assertTrue(portObj2 == null);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for add port method.
+	 * Condition:
+	 *  The port is not existing.
+	 * Expect:
+	 *  The port should be added.
+	 *  The desc of IPortObject is the same as the name of OFPhysicalPort.
+	 */
+	//@Ignore 
+	@Test
+	public void testAddPort() {
+		String dpid = "00:00:00:00:00:00:0a:06";
+		short portNumber = 4;
+		String name = "port 4 at ATL Switch";
+		int state = OFPortState.OFPPS_STP_FORWARD.getValue();
+		OFPhysicalPort port = new OFPhysicalPort(); 
+		port.setPortNumber(portNumber);
+		port.setName(name);
+		port.setState(state);
+		
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw != null);
+		swSt.addPort(dpid, port);
+		IPortObject portObj = ope.searchPort(dpid, portNumber);
+		assertTrue(portObj != null);
+		assertEquals(portObj.getDesc(), name);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for add method.
+	 * Condition:
+	 *  The port is existing.
+	 * Expect:
+	 *  Nothing happens.
+	 */
+	//@Ignore 
+	@Test
+	public void testAddExistingPort() {
+		String dpid = "00:00:00:00:00:00:0a:06";
+		short portNumber = 3;
+		String name = "xxx";
+		int state = OFPortState.OFPPS_STP_FORWARD.getValue();
+		OFPhysicalPort port = new OFPhysicalPort(); 
+		port.setPortNumber(portNumber);
+		port.setName(name);
+		port.setState(state);
+		
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw != null);
+		swSt.addPort(dpid, port);
+		IPortObject portObj = ope.searchPort(dpid, portNumber);
+		assertTrue(portObj != null);
+	}
+	
+	/**
+	 * Desc:
+	 *  Test method for add method.
+	 * Condition:
+	 *  The port status is down.
+	 * Expect:
+	 *  Delete the port.
+	 */
+	//@Ignore 
+	@Test
+	public void testAddDownPort() {
+		String dpid = "00:00:00:00:00:00:0a:06";
+		short portNumber = 3;
+		String name = "port 3 at ATL Switch";
+		int state = OFPortState.OFPPS_LINK_DOWN.getValue();
+		OFPhysicalPort port = new OFPhysicalPort(); 
+		port.setPortNumber(portNumber);
+		port.setName(name);
+		port.setState(state);
+		
+		ISwitchObject sw = ope.searchSwitch(dpid);
+		assertTrue(sw != null);
+		swSt.addPort(dpid, port);
+		IPortObject portObj = ope.searchPort(dpid, portNumber);
+		assertTrue(portObj == null);
+	}
+}
diff --git a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTest.java
similarity index 98%
rename from src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceStorageImplTest.java
rename to src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTest.java
index fc37016..5cdcbb5 100644
--- a/src/test/java/net/floodlightcontroller/devicemanager/internal/DeviceStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTest.java
@@ -1,4 +1,4 @@
-package net.floodlightcontroller.devicemanager.internal;
+package net.onrc.onos.ofcontroller.devicemanager.internal;
 
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.expect;
@@ -20,10 +20,11 @@
 import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
 import net.onrc.onos.util.GraphDBConnection;
 import net.onrc.onos.util.GraphDBOperation;
-
+import net.floodlightcontroller.devicemanager.internal.Device;
 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.openflow.util.HexString;
@@ -32,7 +33,6 @@
 import org.powermock.modules.junit4.PowerMockRunner;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import com.thinkaurelius.titan.core.TitanFactory;
 
 //Add Powermock preparation
@@ -49,7 +49,9 @@
     
 	@Before
 	public void setUp() throws Exception {
-
+	    deviceImpl = new DeviceStorageImpl();	
+		conf = "/dummy/path/to/db";
+				
 		PowerMock.mockStatic(GraphDBConnection.class);
 		mockConn = createMock(GraphDBConnection.class);
 		PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class));
@@ -58,19 +60,22 @@
 			
 		//PowerMock.mockStatic(GraphDBOperation.class);
 		mockOpe = PowerMock.createMock(GraphDBOperation.class);
-		PowerMock.expectNew(GraphDBOperation.class, mockConn).andReturn(mockOpe);
+		PowerMock.expectNew(GraphDBOperation.class, new Class<?>[]{String.class}, conf).andReturn(mockOpe);
+		mockOpe.close();
 		PowerMock.replay(GraphDBOperation.class);
         // Replace the conf to dummy conf
 		// String conf = "/tmp/cassandra.titan";
-		conf = "/dummy/path/to/db";
+
 		
-        deviceImpl = new DeviceStorageImpl();
+
 	}
 
 	@After
 	public void tearDown() throws Exception {	
 		deviceImpl.close();
 		deviceImpl = null;
+		
+		verify(mockOpe);
 	}
 	
 	private String makeIPStringFromArray(Integer[] ipaddresses){
@@ -148,7 +153,6 @@
 			expect(mockOpe.newDevice()).andReturn(mockIDev);
 			expect(mockOpe.searchPort(switchMacAddr, portNum)).andReturn(mockIPort);
 			mockOpe.commit();
-
 			replay(mockOpe);				
 			
 			deviceImpl.init(conf);
@@ -158,7 +162,6 @@
 			assertNotNull(obj);
 			
 			verify(mockIDev);
-			verify(mockOpe);
 			
 		} catch(Exception e) {
 			fail(e.getMessage());
@@ -239,10 +242,7 @@
 			//Add the same device
 	        IDeviceObject obj2 = deviceImpl.addDevice(mockDev);
 			assertNotNull(obj2);
-			
-			verify(mockIDev);
-			verify(mockOpe);
-			
+
 		} catch(Exception e) {
 			fail(e.getMessage());
 		}
@@ -335,7 +335,6 @@
 			assertNotNull(obj2);
 			
 			verify(mockIDev);
-			verify(mockOpe);
 			
 		} catch(Exception e) {
 			fail(e.getMessage());
@@ -429,7 +428,7 @@
 		    assertNull(dev2);
 		    
 			verify(mockIDev);
-			verify(mockOpe);
+
 		} catch(Exception e) {
 			fail(e.getMessage());
 		}
@@ -511,7 +510,7 @@
 		    assertNotNull(dev);
 		    
 			verify(mockIDev);
-			verify(mockOpe);   
+
 		} catch(Exception e) {
 			fail(e.getMessage());
 		}
@@ -600,7 +599,7 @@
 		    assertNotNull(dev);
 		    
 			verify(mockIDev);
-			verify(mockOpe);
+
 			
 		} catch(Exception e) {
 			fail(e.getMessage());
@@ -735,18 +734,17 @@
 		    deviceImpl.changeDeviceAttachments(mockDev3);
 		    
 			verify(mockIDev);
-			verify(mockOpe);
+
 			
 		} catch(Exception e) {
 			fail(e.getMessage());
 		}
 	}
 
-	//@Ignore
+	@Ignore
 	@Test
 	public void testChangeDeviceAttachmentsIDeviceIDeviceObject() {
 		//It is tested by the testChangeDeviceAttachmentsIDevice
-		deviceImpl.init(conf);
 	}
 
 	/**
@@ -828,7 +826,7 @@
 	        deviceImpl.changeDeviceIPv4Address(mockDev2);	
 	        
 			verify(mockIDev);
-			verify(mockOpe);
+
 					
 		} 
 		catch(Exception e) {
diff --git a/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTestBB.java b/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTestBB.java
new file mode 100644
index 0000000..cea70f0
--- /dev/null
+++ b/src/test/java/net/onrc/onos/ofcontroller/devicemanager/internal/DeviceStorageImplTestBB.java
@@ -0,0 +1,626 @@
+package net.onrc.onos.ofcontroller.devicemanager.internal;
+
+import static org.junit.Assert.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+import net.floodlightcontroller.core.internal.TestDatabaseManager;
+import net.floodlightcontroller.devicemanager.IDevice;
+import net.floodlightcontroller.devicemanager.SwitchPort;
+import net.floodlightcontroller.devicemanager.internal.Device;
+import net.floodlightcontroller.packet.IPv4;
+import net.onrc.onos.ofcontroller.core.IDeviceStorage;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IDeviceObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject;
+import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject;
+import net.onrc.onos.ofcontroller.core.internal.DeviceStorageImpl;
+import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
+import net.onrc.onos.util.GraphDBConnection;
+import net.onrc.onos.util.GraphDBOperation;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openflow.util.HexString;
+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 DeviceStorageImplTestBB {
+	protected static org.slf4j.Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
+
+	String conf;
+    private GraphDBConnection conn = null;
+    private GraphDBOperation ope = null;
+    private TitanGraph titanGraph = null;
+    IDeviceStorage deviceImpl = null;
+    
+	@Before
+	public void setUp() throws Exception {
+		
+		deviceImpl = new DeviceStorageImpl();
+		conf = "/dummy/path/to/db";
+		
+		// Make mock cassandra DB
+		// Replace TitanFactory.open() to return mock DB
+		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);
+		
+		deviceImpl.init(conf);
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		titanGraph.shutdown();
+		TestDatabaseManager.deleteTestDatabase();
+
+		deviceImpl.close();
+		deviceImpl = null;
+	}
+
+	/**
+	 * Desc:
+	 *  Test method for addDevice method.
+	 * Codition:
+	 *  N/A
+	 * Expect:
+	 * 	Get proper IDeviceObject
+	 *  Check the IDeviceObject properties set
+	 */
+	@Test
+	public void testAddDevice() {
+		try 
+		{	   
+			//Make mockDevice
+			IDevice mockDev = EasyMock.createMock(Device.class);
+			// Mac addr for test device.
+			String macAddr = "99:99:99:99:99:99";
+			// IP addr for test device
+			String ip = "192.168.100.1";
+			Integer ipInt = IPv4.toIPv4Address(ip);
+			Integer[] ipaddrs = {ipInt};
+			// Mac addr for attached switch
+			String switchMacAddr = "00:00:00:00:00:00:0a:01";		
+			long switchMacAddrL = HexString.toLong(switchMacAddr);
+			// Port number for attached switch
+			short portNum = 2; 
+			SwitchPort sp1 = new SwitchPort(switchMacAddrL, portNum);
+			SwitchPort[] sps = {sp1};
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+
+			EasyMock.replay(mockDev);
+
+			//Add the device
+	        IDeviceObject obj = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj);
+
+			//Test to take a Device from DB correctly
+			IDeviceObject devObj1 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, devObj1.getMACAddress());
+
+			//Test to take a attached sw  from DB correctly
+			for(ISwitchObject sw1: devObj1.getSwitch())
+			{
+				String swMacFromDB = sw1.getDPID();
+				assertEquals(switchMacAddr, swMacFromDB);
+			}
+
+			//Test to take a IP addr from DB
+			//TodoForGettingIPaddr. There may be bug in the test class.
+			String ipFromDB = devObj1.getIPAddress();
+			String[] ipsFromDB = ipFromDB.replace("[", "").replace("]", "").split(",");
+			List<String> ipsList = Arrays.asList(ipsFromDB);
+			assertTrue(ipsList.contains(ip));
+
+			//Test to take a attached port from DB
+			for(IPortObject port : devObj1.getAttachedPorts())
+			{
+
+				//In this implementing, the object was not set the port. So it must be null.
+				if(port.getNumber() != null)
+				{
+					String portNumFromDB = port.getNumber().toString();
+					assertEquals(String.valueOf(portNum), portNumFromDB);				
+				}
+			}	
+		} catch(Exception e) {
+			fail(e.getMessage());
+		}
+	}
+	
+	/**
+	 * Desc:
+	 * 	Test method for addDevice method.
+	 * Condition:
+	 * 	Already added device is existed.
+	 * Expect:
+	 * 	Get proper IDeviceObject still.
+	 *  Check the IDeviceObject properties set.
+	 */
+	@Test
+	public void testAddDeviceExisting() {
+		try 
+		{	   
+			IDevice mockDev = EasyMock.createMock(Device.class);
+			String macAddr = "99:99:99:99:99:99";
+			String ip = "192.168.100.1";
+			Integer ipInt = IPv4.toIPv4Address(ip);
+			Integer[] ipaddrs = {ipInt};
+			String switchMacAddr = "00:00:00:00:00:00:0a:01";		
+			long switchMacAddrL = HexString.toLong(switchMacAddr);
+			short portNum = 2; 
+			SwitchPort sp1 = new SwitchPort(switchMacAddrL, portNum);
+			SwitchPort[] sps = {sp1};
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.replay(mockDev);
+
+			//Add the device
+	        IDeviceObject obj = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj);
+
+			//Test to take a Device from DB correctly
+			IDeviceObject devObj1 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, devObj1.getMACAddress());
+
+			//Add the same device
+	        IDeviceObject obj2 = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj2);
+
+			IDeviceObject devObj2 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, devObj2.getMACAddress());	
+
+			//Test to take a attached port from DB
+			for(IPortObject port : devObj2.getAttachedPorts())
+			{
+				//In this implementing, the object was not set the port. So it must be null.
+				if(port.getNumber() != null)
+				{
+
+					String portNumFromDB = port.getNumber().toString();
+					assertEquals(String.valueOf(portNum), portNumFromDB);						
+
+					ISwitchObject sw = port.getSwitch();
+					String str = sw.getDPID();
+					log.debug("");
+				}
+			}	
+
+			String ipFromDB = devObj2.getIPAddress();
+			String[] ipsFromDB = ipFromDB.replace("[", "").replace("]", "").split(",");
+			List<String> ipsList = Arrays.asList(ipsFromDB);
+			assertTrue(ipsList.contains(ip));
+
+			//Test to take a attached port from DB
+			for(IPortObject port : devObj2.getAttachedPorts())
+			{
+
+				//In this implementing, the object was not set the port. So it must be null.
+				if(port.getNumber() != null)
+				{
+					String portNumFromDB = port.getNumber().toString();
+					assertEquals(String.valueOf(portNum), portNumFromDB);				
+				}
+			}	
+		} catch(Exception e) {
+			fail(e.getMessage());
+		}
+	}
+	/**
+	 * Desc:
+	 * 	Test method for updateDevice method.
+	 * Condition:
+	 * 	The mac address and attachment point are the same. 
+	 *  All of the other parameter are different.
+	 * Expect:
+	 * 	Changed parameters are set properly.
+	 */
+	//@Ignore
+	@Test
+	public void testUpdateDevice() {
+		try
+		{
+			IDevice mockDev = EasyMock.createMock(Device.class);
+			String macAddr = "99:99:99:99:99:99";
+			String ip = "192.168.100.1";
+			Integer ipInt = IPv4.toIPv4Address(ip);
+			Integer[] ipaddrs = {ipInt};
+			String switchMacAddr = "00:00:00:00:00:00:0a:01";		
+			long switchMacAddrL = HexString.toLong(switchMacAddr);
+			short portNum = 2; 
+			SwitchPort sp1 = new SwitchPort(switchMacAddrL, portNum);
+			SwitchPort[] sps = {sp1};
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.replay(mockDev);
+
+			//Dev2 (attached port is the same)
+			IDevice mockDev2 = EasyMock.createMock(Device.class);
+			String macAddr2 = "99:aa:aa:aa:aa:aa";
+			Integer ip2 = IPv4.toIPv4Address("192.168.100.2");
+			Integer[] ipaddrs2 = {ip2};
+
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr2);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr2);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr2);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr2);
+			EasyMock.expect(mockDev2.getIPv4Addresses()).andReturn(ipaddrs2);
+			EasyMock.expect(mockDev2.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr2);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr2);
+			EasyMock.replay(mockDev2);
+
+	        IDeviceObject obj = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj);
+
+			IDeviceObject dev1 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, dev1.getMACAddress());
+
+			//update theDevice
+			deviceImpl.updateDevice(mockDev2);
+			IDeviceObject dev2 = ope.searchDevice(macAddr2);
+			assertEquals(macAddr2, dev2.getMACAddress());
+			IPortObject iport = ope.searchPort(switchMacAddr, portNum);
+
+			//Test to take a attached port from DB
+			for(IDeviceObject dev : iport.getDevices())
+			{
+				String macAddrFromDB = dev.getMACAddress();	
+				if(macAddr2.equals(macAddrFromDB)){
+					//Nothing to do
+				}
+				else{
+					fail("notFoundTheDeviceOnThePort");			
+				}
+			}
+
+		} catch(Exception e) {
+			fail(e.getMessage());
+		}
+	}
+
+	/**
+	 * Desc:
+	 * 	Test method for testRemoveDevice method.
+	 * Condition:
+	 * 	1. Unregistered IDeviceObject argument is put. 
+	 * Expect:
+	 *  1. Nothing happen when unregistered IDeviceObject is put
+	 * 	2. IDeviceObject will be removed.
+	 */
+	//@Ignore
+	@Test
+	public void testRemoveDevice() {
+		try
+		{
+			IDevice mockDev = EasyMock.createMock(Device.class);
+			String macAddr = "99:99:99:99:99:99";
+			String ip = "192.168.100.1";
+			Integer ipInt = IPv4.toIPv4Address(ip);
+			Integer[] ipaddrs = {ipInt};
+			String switchMacAddr = "00:00:00:00:00:00:0a:01";		
+			long switchMacAddrL = HexString.toLong(switchMacAddr);
+			short portNum = 2; 
+			SwitchPort sp1 = new SwitchPort(switchMacAddrL, portNum);
+			SwitchPort[] sps = {sp1};
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.replay(mockDev);
+
+	        IDeviceObject obj = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj);
+
+			IDeviceObject dev1 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, dev1.getMACAddress());
+
+			deviceImpl.removeDevice(mockDev);		
+		    IDeviceObject dev = deviceImpl.getDeviceByMac(macAddr);
+		    assertNull(dev);
+
+		} catch(Exception e) {
+			fail(e.getMessage());
+		}
+	}
+
+	/**
+	 * Desc:
+	 * 	Test method for getDeviceByMac
+	 * Condition:
+	 * 	1. Unregistered mac address argument is set
+	 * Expect:
+	 * 	1.Nothing happen when you put unregistered mac address
+	 *  2.Get the proper IDeviceObject.
+	 *  3.Check the IDeviceObject properties set.
+	 */
+	//@Ignore
+	@Test
+	public void testGetDeviceByMac() {
+		try
+		{
+			IDevice mockDev = EasyMock.createMock(Device.class);
+			String macAddr = "99:99:99:99:99:99";
+			String ip = "192.168.100.1";
+			Integer ipInt = IPv4.toIPv4Address(ip);
+			Integer[] ipaddrs = {ipInt};
+			String switchMacAddr = "00:00:00:00:00:00:0a:01";		
+			long switchMacAddrL = HexString.toLong(switchMacAddr);
+			short portNum = 2; 
+			SwitchPort sp1 = new SwitchPort(switchMacAddrL, portNum);
+			SwitchPort[] sps = {sp1};
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.replay(mockDev);
+
+	        IDeviceObject obj = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj);
+
+			IDeviceObject dev1 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, dev1.getMACAddress());
+
+		    IDeviceObject dev = deviceImpl.getDeviceByMac(macAddr);
+		    assertNotNull(dev);
+			assertEquals(macAddr, dev.getMACAddress());
+
+		} catch(Exception e) {
+			fail(e.getMessage());
+		}
+	}
+
+	/**
+	 * Desc:
+	 * 	Test method for getDeviceByIP method.
+	 * Condition:
+	 * 	1. Unregistered ip address argument is set
+	 * Expect:
+	 * 	1. Nothing happen when you put unregistered mac address
+	 * 	2. Get the proper IDeviceObject.
+	 *  3. Check the IDeviceObject properties set.
+	 */
+	//@Ignore
+	@Test
+	public void testGetDeviceByIP() {
+		try
+		{
+			IDevice mockDev = EasyMock.createMock(Device.class);
+			String macAddr = "99:99:99:99:99:99";
+			String ip = "192.168.100.1";
+			Integer ipInt = IPv4.toIPv4Address(ip);
+			Integer[] ipaddrs = {ipInt};
+			String switchMacAddr = "00:00:00:00:00:00:0a:01";		
+			long switchMacAddrL = HexString.toLong(switchMacAddr);
+			short portNum = 2; 
+			SwitchPort sp1 = new SwitchPort(switchMacAddrL, portNum);
+			SwitchPort[] sps = {sp1};
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.replay(mockDev);
+
+	        IDeviceObject obj = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj);
+
+			IDeviceObject dev1 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, dev1.getMACAddress());
+
+		    IDeviceObject dev = deviceImpl.getDeviceByIP(ip);
+		    assertNotNull(dev);
+			String ipFromDB = dev.getIPAddress();
+			String[] ipsFromDB = ipFromDB.replace("[", "").replace("]", "").split(",");
+			List<String> ipsList = Arrays.asList(ipsFromDB);
+			assertTrue(ipsList.contains(ip));
+
+		} catch(Exception e) {
+			fail(e.getMessage());
+		}
+	}
+
+	/**
+	 * Desc:
+	 * 	Test method for testChangeDeviceAttachmentsIDevice
+	 * Condition:
+	 * 	1. Unexisting attachment point argument is set
+	 * Expect:
+	 * 	1. Unexisting attachment point is ignored, so nothing happen.
+	 * 	2. Change the attachment point.
+	 */
+	//@Ignore
+	@Test
+	public void testChangeDeviceAttachmentsIDevice() {
+		try
+		{
+			IDevice mockDev = EasyMock.createMock(Device.class);
+			String macAddr = "99:99:99:99:99:99";
+			String ip = "192.168.100.1";
+			Integer ipInt = IPv4.toIPv4Address(ip);
+			Integer[] ipaddrs = {ipInt};
+			String switchMacAddr = "00:00:00:00:00:00:0a:01";		
+			long switchMacAddrL = HexString.toLong(switchMacAddr);
+			short portNum = 2; 
+			SwitchPort sp1 = new SwitchPort(switchMacAddrL, portNum);
+			SwitchPort[] sps = {sp1};
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.replay(mockDev);
+
+			//Dev2
+			IDevice mockDev2 = EasyMock.createMock(Device.class);
+			String switchMacAddr2 = "00:00:00:00:00:00:0a:02";
+			long lSwitchMacAddr2 = HexString.toLong(switchMacAddr2);
+			short portNum2 = 2; 
+			SwitchPort sp2 = new SwitchPort(lSwitchMacAddr2, portNum2);
+			SwitchPort sps2[] = {sp2};
+
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev2.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev2.getAttachmentPoints()).andReturn(sps2);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr);
+			EasyMock.replay(mockDev2);
+
+	        IDeviceObject obj = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj);
+
+		    deviceImpl.changeDeviceAttachments(mockDev2);
+
+		    IDeviceObject dev = deviceImpl.getDeviceByMac(macAddr);
+		    assertNotNull(dev);
+
+			for(ISwitchObject sw1: dev.getSwitch())
+			{
+				String swMacFromDB = sw1.getDPID();
+				assertEquals(switchMacAddr2, swMacFromDB);
+			}
+		} catch(Exception e) {
+			fail(e.getMessage());
+		}
+	}
+
+	//@Ignore
+	@Test
+	public void testChangeDeviceAttachmentsIDeviceIDeviceObject() {
+		//It is tested by the testChangeDeviceAttachmentsIDevice
+	}
+
+	/**
+	 * Desc:
+	 * 	Test method for testChangeDeviceIPv4Address
+	 * Condition:
+	 * 	N/A
+	 * Expect:
+	 *  1. Check correctly changed the ipadress
+	 */
+	//@Ignore
+	@Test
+	public void testChangeDeviceIPv4Address() {
+		try
+		{
+			//Dev1
+			IDevice mockDev = EasyMock.createMock(Device.class);
+			String macAddr = "99:99:99:99:99:99";
+			String ip = "192.168.100.1";
+			Integer ipInt = IPv4.toIPv4Address(ip);
+			Integer[] ipaddrs = {ipInt};
+			String switchMacAddr = "00:00:00:00:00:00:0a:01";		
+			long switchMacAddrL = HexString.toLong(switchMacAddr);
+			short portNum = 2; 
+			SwitchPort sp1 = new SwitchPort(switchMacAddrL, portNum);
+			SwitchPort[] sps = {sp1};
+
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getIPv4Addresses()).andReturn(ipaddrs);
+			EasyMock.expect(mockDev.getAttachmentPoints()).andReturn(sps);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev.getMACAddressString()).andReturn(macAddr);
+			EasyMock.replay(mockDev);
+
+	        IDeviceObject obj = deviceImpl.addDevice(mockDev);	
+			assertNotNull(obj);
+
+			IDevice mockDev2 = EasyMock.createMock(Device.class);
+			String ip2 = "192.168.100.2";
+			Integer ipInt2 = IPv4.toIPv4Address(ip2);
+			Integer[] ipaddrs2 = {ipInt2};
+			EasyMock.expect(mockDev2.getMACAddressString()).andReturn(macAddr);
+			EasyMock.expect(mockDev2.getIPv4Addresses()).andReturn(ipaddrs2);
+			EasyMock.replay(mockDev2);
+
+			IDeviceObject dev1 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, dev1.getMACAddress());
+			String ipFromDB = dev1.getIPAddress();
+			String[] ipsFromDB = ipFromDB.replace("[", "").replace("]", "").split(",");
+			List<String> ipsList = Arrays.asList(ipsFromDB);
+			assertTrue(ipsList.contains(ip));
+
+	        deviceImpl.changeDeviceIPv4Address(mockDev2);	
+
+			IDeviceObject dev2 = ope.searchDevice(macAddr);
+			assertEquals(macAddr, dev2.getMACAddress());
+			String ipFromDB2 = dev2.getIPAddress();
+			String[] ipsFromDB2 = ipFromDB2.replace("[", "").replace("]", "").split(",");
+			List<String> ipsList2 = Arrays.asList(ipsFromDB2);
+			assertTrue(ipsList2.contains(ip2));
+		} 
+		catch(Exception e) {
+			fail(e.getMessage());
+		}
+	}
+
+}