Increase UT coverage for VTN-Neutron package. 10/12610/1
authorananthip <ananthip@hcl.com>
Fri, 7 Nov 2014 15:09:54 +0000 (20:39 +0530)
committerananthip <ananthip@hcl.com>
Fri, 7 Nov 2014 15:09:54 +0000 (20:39 +0530)
Change-Id: I9b1d8f86b1172e58984d8572d3e8c52406fb925d
Signed-off-by: ananthip <ananthip@hcl.com>
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/NeutronPortCRUDStub.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/OVSDBManagerStub.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/OVSDBPluginEventHandlerTest.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/PortHandlerTest.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/TestBase.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/VTNManagerStub.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/VTNNeutronUtilsTest.java

index cc55ab5fde2eb324bd9ae70201a647e01b766233..25bef57b9aab90f717ea5a8822efa38c86784617 100644 (file)
@@ -25,8 +25,20 @@ public class NeutronPortCRUDStub implements INeutronPortCRUD {
     @Override
     public NeutronPort getPort(String uuid) {
         if (uuid.equals("C387EB44-7832-49F4-B9F0-D30D27770883")) {
+            //Setting all IDs(TenantID, SwitchID, PortID) to NULL
             NeutronPort neutron = new NeutronPort();
             return neutron;
+        } else if (uuid.equals("D387EB44-7832-49F4-B9F0-D30D27770884")) {
+            //Setting SwitchID and PortID to NULL
+            NeutronPort neutron = new NeutronPort();
+            neutron.setTenantID("D387EB44-7832-49F4-B9F0-D30D27770885");
+            return neutron;
+        } else if (uuid.equals("4790F3C1-AB34-4ABC-B7A5-C1B5C7202389")) {
+            //Setting PortID to NULL
+            NeutronPort neutron = new NeutronPort();
+            neutron.setTenantID("E6E005D3A24542FCB03897730A5150E2");
+            neutron.setNetworkUUID("5e7e0900-f215-11e3-aa76-0002a5d5c51b");
+            return neutron;
         } else if (uuid.equals("4790F3C1-AB34-4ABC-B7A5-C1B5C7202389")) {
             NeutronPort neutron = new NeutronPort();
             neutron.setTenantID("E6E005D3A24542FCB03897730A5150E2");
index 3b177bd56301b95d21b64fa26cce7634c82f0142..aaec49c2f57a985052ffcc029bd532182b77e1fc 100644 (file)
@@ -257,14 +257,15 @@ public class OVSDBManagerStub extends TestBase implements OvsdbConfigurationServ
         bridge.setName("invalid Bridge name");
 
         boolean isValidPeNodeIdOf5 = false;
-        if ((String.valueOf(node.getID()).length() == UUID_LEN)
-                && (NODE_ID_2.equalsIgnoreCase(String.valueOf(Long.parseLong(String.valueOf(node.getID()).substring(UUID_POSITION_IN_NODE), HEX_RADIX))))) {
+        if (NODE_ID_2.equalsIgnoreCase(node.getID().toString())) {
             isValidPeNodeIdOf5 = true;
         }
-        if ((NODE_ID_1.equalsIgnoreCase(String.valueOf(node.getID())))
-                || (isValidPeNodeIdOf5)) {
-            bridge.setName("br-int");
-        }
+        try {
+            if ((isValidPeNodeIdOf5)
+                    || (NODE_ID_1.equalsIgnoreCase(Long.toHexString(Long.parseLong(node.getID().toString()))))) {
+                bridge.setName("br-int");
+            }
+        } catch (Exception e) { }
 
         return (T)bridge;
     }
index f3754db36d60511f47066cff735a91180fc372e0..136144b3a9bcf5e2cf55e43538fa3c7a533a68ab 100644 (file)
@@ -93,18 +93,16 @@ public class OVSDBPluginEventHandlerTest extends TestBase {
 
                 if (OPENFLOW.equalsIgnoreCase(createNetwork[NODE_ADD_NODE_TYPE])) {
                     //            String strObj = String.valueOf(Long.parseLong(CREATE_NETWORK[NODE_ADD_NODE_ID]));
-                    Node nodeObj = new Node(createNetwork[NODE_ADD_NODE_TYPE], Long.parseLong(createNetwork[NODE_ADD_NODE_ID]));
+                    Node nodeObj = new Node(createNetwork[NODE_ADD_NODE_TYPE], Long.parseLong(createNetwork[NODE_ADD_NODE_ID], HEX_RADIX));
                     //            ovsdb.prepareInternalNetwork(nodeObj);
                     ovsdb.nodeAdded(nodeObj, null, 0);
-
                 } else if ((ONEPK.equalsIgnoreCase(createNetwork[NODE_ADD_NODE_TYPE])) ||
                         (PRODUCTION.equalsIgnoreCase(createNetwork[NODE_ADD_NODE_TYPE]))) {
                     //            String strNode = String.valueOf(Long.parseLong(CREATE_NETWORK[NODE_ADD_NODE_ID], 16));
                     Node nodeObj = new Node(createNetwork[NODE_ADD_NODE_TYPE], createNetwork[NODE_ADD_NODE_ID]);
                     ovsdb.nodeAdded(nodeObj, null, 0);
                 } else if (PCEP.equalsIgnoreCase(createNetwork[NODE_ADD_NODE_TYPE])) {
-                    UUID idOne = new UUID(new Long(0), new Long(createNetwork[NODE_ADD_NODE_ID]));
-                    Node nodeObj = new Node(createNetwork[NODE_ADD_NODE_TYPE], idOne);
+                    Node nodeObj = new Node(createNetwork[NODE_ADD_NODE_TYPE], UUID.fromString(createNetwork[NODE_ADD_NODE_ID]));
                     ovsdb.nodeAdded(nodeObj, null, 0);
                 }
 
@@ -208,6 +206,10 @@ public class OVSDBPluginEventHandlerTest extends TestBase {
                     Interface interfaceBridge = new InterfaceStub();
                     interfaceBridge.setName(rowUpdate[ROW_UPDATE_NODE_OBJECT_NAME]);
 
+                    if (SET_NULL_TO_NODE.equalsIgnoreCase(rowUpdate[ROW_UPDATE_PARENT_UUID])) {
+                        nodeObj = null;
+                    }
+
                     if (rowUpdate[ROW_UPDATE_OLD_ROW].equalsIgnoreCase("null")
                             && rowUpdate[ROW_UPDATE_NEW_ROW].equalsIgnoreCase("null")) {
                         ovsdb.rowUpdated(nodeObj, rowUpdate[ROW_UPDATE_ACTUAL_TABLE_NAME], rowUpdate[ROW_UPDATE_PARENT_UUID], null, null);
@@ -297,6 +299,14 @@ public class OVSDBPluginEventHandlerTest extends TestBase {
                     OpenVSwitch oldOpenVSwitch = new OpenVSwitchStub();
 
                     ovsdb.rowUpdated(nodeObj, isUpdateOfInterest[ROW_UPDATE_ACTUAL_TABLE_NAME], isUpdateOfInterest[ROW_UPDATE_PARENT_UUID], oldOpenVSwitch.getRow(), newOpenVSwitch.getRow());
+                } else if (isUpdateOfInterest[ROW_UPDATE_ACTUAL_TABLE_NAME].equalsIgnoreCase("Bridge")) {
+                    Bridge newBridge = new BridgeStub();
+                    newBridge.setName(isUpdateOfInterest[ROW_UPDATE_NODE_OBJECT_NAME]);
+
+                    Bridge oldBridge = new BridgeStub();
+                    oldBridge.setName(isUpdateOfInterest[ROW_UPDATE_NODE_OBJECT_NAME]);
+
+                    ovsdb.rowUpdated(nodeObj, isUpdateOfInterest[ROW_UPDATE_ACTUAL_TABLE_NAME], isUpdateOfInterest[ROW_UPDATE_PARENT_UUID], oldBridge.getRow(), newBridge.getRow());
                 }
 
                 ovsdb.unsetOVSDBConfigService(ovsdbConfig);
index 65bf32a38b84fc34a1c666d8771f85f36381290d..5d15364af1ee604c991440531b82bdc4fd01df43 100644 (file)
@@ -29,13 +29,13 @@ public class PortHandlerTest extends TestBase {
         PortHandler ph = new PortHandler();
         ph.setVTNManager(new VTNManagerStub());
 
-        // In the cases that the method returns HTTP_BAD_REQUEST by setting NULL to NeutronPort object.
+        // Failure Case - Method returns HTTP_BAD_REQUEST by setting NULL to NeutronPort object.
         NeutronPort port = null;
 
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canCreatePort(port));
 
-        // In the cases that the method returns HTTP_NOT_FOUND by setting wrong TenantID.
+        // Failure Case - Method returns HTTP_NOT_FOUND by setting wrong TenantID.
         port = new NeutronPort();
         port.setTenantID(TENANT_ID_ARRAY[0]);
         port.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -46,7 +46,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
                 ph.canCreatePort(port));
 
-        // In the cases that the method returns HTTP_NOT_FOUND by setting wrong NetworkID.
+        // Failure Case - Method returns HTTP_NOT_FOUND by setting wrong NetworkID.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -57,7 +57,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
                 ph.canCreatePort(port));
 
-        // In the cases that the method returns HTTP_CONFLICT.
+        // Failure Case - Method returns HTTP_CONFLICT by setting existing UUID to Port UUID
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -68,18 +68,18 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_CONFLICT,
                 ph.canCreatePort(port));
 
-        // In the cases that the method returns HTTP_CREATED.
+        // Failure Case - Method returns HTTP_BAD_REQUEST by setting wrong UUID to Port UUID.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
-        port.setPortUUID(NEUTRON_UUID_ARRAY[1]);
+        port.setPortUUID(VTNManagerStub.VBR_IF_3_UUID);
         port.setMacAddress(MAC_ADDR_ARRAY[0]);
         port.setFixedIPs(new ArrayList<Neutron_IPs>(0));
 
-        assertEquals(HttpURLConnection.HTTP_CREATED,
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canCreatePort(port));
 
-        // In the cases that the method returns HTTP_CREATED.
+        // Success Case - Method returns HTTP_CREATED.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -91,7 +91,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_CREATED,
                 ph.canCreatePort(port));
 
-        // In the cases that the method returns HTTP_CREATED.
+        // Success Case - Method returns HTTP_CREATED.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -118,13 +118,13 @@ public class PortHandlerTest extends TestBase {
         ph.setVTNManager(new VTNManagerStub());
 
         NeutronPort port = null;
-        // Case - Failure case by setting NULL to NeutronPort object
+        // Failure Case - By setting NULL to NeutronPort object
         port = null;
 
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canCreatePort(port));
 
-        // Case - Failure case by setting NULL to TennantID
+        // Failure Case - By setting NULL to TennantID
         port = new NeutronPort();
         port.setTenantID(null);
         port.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -135,7 +135,28 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canCreatePort(port));
 
-        // Case - Failure case by setting invalid UUID to TennantID
+        // Failure Case - By setting NULL to NetworkID
+        port = new NeutronPort();
+        port.setTenantID(NEUTRON_UUID_ARRAY[0]);
+        port.setNetworkUUID(null);
+        port.setPortUUID(NEUTRON_UUID_ARRAY[1]);
+        port.setMacAddress(MAC_ADDR_ARRAY[0]);
+        port.setFixedIPs(new ArrayList<Neutron_IPs>(0));
+
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
+                ph.canCreatePort(port));
+
+        // Failure Case - By setting NULL to PortID
+        port = new NeutronPort();
+        port.setTenantID(NEUTRON_UUID_ARRAY[0]);
+        port.setNetworkUUID(NEUTRON_UUID_ARRAY[1]);
+        port.setPortUUID(null);
+        port.setMacAddress(MAC_ADDR_ARRAY[0]);
+        port.setFixedIPs(new ArrayList<Neutron_IPs>(0));
+
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
+                ph.canCreatePort(port));
+        // Failure Case - By setting invalid UUID to TennantID
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.INVALID_UUID);
         port.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -146,7 +167,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canCreatePort(port));
 
-        // Case - Failure case by setting invalid UUID to NetworkID
+        // Failure Case - By setting invalid UUID to NetworkID
         port = new NeutronPort();
         port.setTenantID(TENANT_ID_ARRAY[0]);
         port.setNetworkUUID(VTNManagerStub.INVALID_UUID);
@@ -157,7 +178,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canCreatePort(port));
 
-        // Case - Failure case by setting invalid UUID to PortID
+        // Failure Case - By setting invalid UUID to PortID
         port = new NeutronPort();
         port.setTenantID(TENANT_ID_ARRAY[0]);
         port.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -168,7 +189,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canCreatePort(port));
 
-        // Case - Success
+        // Success Case - Only for Method(getVTNIdentifiers)
         port = new NeutronPort();
         port.setTenantID(TENANT_ID_ARRAY[0]);
         port.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -189,7 +210,7 @@ public class PortHandlerTest extends TestBase {
         PortHandler ph = new PortHandler();
         ph.setVTNManager(new VTNManagerStub());
 
-        // In the cases that the method returns HTTP_CONFLICT and failed to create New NeutronPort.
+        // Failure Case - Method returns HTTP_CONFLICT and failed to create New NeutronPort.
         NeutronPort port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -199,7 +220,7 @@ public class PortHandlerTest extends TestBase {
 
         ph.neutronPortCreated(port);
 
-        // In the cases that the method returns HTTP_CONFLICT and failed to create New NeutronPort.
+        // Failure Case - Method returns HTTP_CONFLICT and failed to create New NeutronPort.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -209,7 +230,17 @@ public class PortHandlerTest extends TestBase {
 
         ph.neutronPortCreated(port);
 
-        // In the cases that the method successfully executes.
+        // Failure Case - Method returns HTTP_CONFLICT and failed to create Bridge Interface.
+        port = new NeutronPort();
+        port.setTenantID(VTNManagerStub.TENANT_1_UUID);
+        port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
+        port.setPortUUID(VTNManagerStub.VBR_IF_4_UUID);
+        port.setMacAddress(MAC_ADDR_ARRAY[0]);
+        port.setFixedIPs(new ArrayList<Neutron_IPs>(0));
+
+        ph.neutronPortCreated(port);
+
+        // Success Case - Method successfully executes.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -230,16 +261,20 @@ public class PortHandlerTest extends TestBase {
         PortHandler ph = new PortHandler();
         ph.setVTNManager(new VTNManagerStub());
 
-        // In the cases that the method returns HTTP_BAD_REQUEST by setting NULL to both NeutronPort object.
+        // Failure Case - Method returns HTTP_BAD_REQUEST by setting NULL to both NeutronPort object.
         NeutronPort portDelta = null;
         NeutronPort portOriginal = null;
 
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canUpdatePort(portDelta, portOriginal));
 
+        // Failure Case - Method returns HTTP_BAD_REQUEST by setting NULL to portOriginal object.
         portDelta = new NeutronPort();
 
-        // In the cases that the method returns HTTP_BAD_REQUEST by setting NULL to TenantID.
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
+                ph.canUpdatePort(portDelta, portOriginal));
+
+        // Failure Case - Method returns HTTP_BAD_REQUEST by setting NULL to TenantID.
         portOriginal = new NeutronPort();
         portOriginal.setTenantID(null);
         portOriginal.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -250,7 +285,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canUpdatePort(portDelta, portOriginal));
 
-        // Cases - returns HTTP_NOT_FOUND(Interface does not exist) by setting wrong PortUUID.
+        // Failure Case - Method returns HTTP_NOT_FOUND(Interface does not exist) by setting wrong PortUUID.
         portOriginal = new NeutronPort();
         portOriginal.setTenantID(VTNManagerStub.TENANT_1_UUID);
         portOriginal.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -261,7 +296,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
                 ph.canUpdatePort(portDelta, portOriginal));
 
-        // In the cases that the method returns HTTP_OK.
+        // Success Case - Method returns HTTP_OK.
         portOriginal = new NeutronPort();
         portOriginal.setTenantID(VTNManagerStub.TENANT_1_UUID);
         portOriginal.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -282,7 +317,7 @@ public class PortHandlerTest extends TestBase {
         PortHandler ph = new PortHandler();
         ph.setVTNManager(new VTNManagerStub());
 
-        // Case - returns HTTP_BAD_REQUEST by setting NULL to TenantID.
+        // Failure Case - Method returns HTTP_BAD_REQUEST by setting NULL to TenantID.
         NeutronPort port = new NeutronPort();
         port.setTenantID(null);
         port.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -292,7 +327,7 @@ public class PortHandlerTest extends TestBase {
 
         ph.neutronPortUpdated(port);
 
-        // Case - returns HTTP_NOT_FOUND(Interface does not exist for tenant-id) by setting wrong PortUUID.
+        // Failure Case - Method returns HTTP_NOT_FOUND(Interface does not exist for tenant-id) by setting wrong PortUUID.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -302,7 +337,22 @@ public class PortHandlerTest extends TestBase {
 
         ph.neutronPortUpdated(port);
 
-        // Case - returns HTTP_CONFLICT(Modifying bridge interface failed) by setting Port-AdminStateUp to null
+        // Failure Case - Method(getBridgeInterface) returns NULL(throws VTNException) by setting Wrong Port UUID
+        port = new NeutronPort();
+        port.setTenantID(VTNManagerStub.TENANT_1_UUID);
+        port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
+        port.setPortUUID(VTNManagerStub.VBR_IF_3_UUID);
+        port.setMacAddress(MAC_ADDR_ARRAY[0]);
+        port.setFixedIPs(new ArrayList<Neutron_IPs>(0));
+
+        VTNManagerStub.isReturnValidVInterface = true;
+        try {
+            ph.neutronPortUpdated(port);
+        } catch (NullPointerException exception) {
+            assertEquals(exception.getMessage(), exception.toString(), new NullPointerException().toString());
+        }
+
+        // Failure Case - Method(canModifyInterface returns false) by setting Port-AdminStateUp to null
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -312,7 +362,7 @@ public class PortHandlerTest extends TestBase {
 
         ph.neutronPortUpdated(port);
 
-        // Case - Modifying bridge interface failed
+        // Failure Case - Modifying bridge interface failed
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -323,7 +373,7 @@ public class PortHandlerTest extends TestBase {
 
         ph.neutronPortUpdated(port);
 
-        // Case - Success
+        // Success Case
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -366,6 +416,18 @@ public class PortHandlerTest extends TestBase {
 
         ph.neutronPortUpdated(port);
 
+        // Case - returns True by setting Port-AdminStateUp to False and valid name to NeutronPort
+        port = new NeutronPort();
+        port.setTenantID(VTNManagerStub.TENANT_1_UUID);
+        port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
+        port.setPortUUID(VTNManagerStub.VBR_IF_1_UUID);
+        port.setMacAddress(MAC_ADDR_ARRAY[0]);
+        port.setFixedIPs(new ArrayList<Neutron_IPs>(0));
+        port.setAdminStateUp(Boolean.FALSE);
+        port.setName("Neutron-port");
+
+        ph.neutronPortUpdated(port);
+
         // Case - returns True by setting Port-AdminStateUp to True and valid Description to VBridgeIfConfig
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
@@ -388,6 +450,18 @@ public class PortHandlerTest extends TestBase {
         port.setName("Neutron-port");
 
         ph.neutronPortUpdated(port);
+
+        // Case - returns True by setting Port-AdminStateUp to True, valid Description to VBridgeIfConfig and same name of port object to VInterfaceConfig
+        port = new NeutronPort();
+        port.setTenantID(VTNManagerStub.TENANT_1_UUID);
+        port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
+        port.setPortUUID(VTNManagerStub.VBR_IF_2_UUID);
+        port.setMacAddress(MAC_ADDR_ARRAY[0]);
+        port.setFixedIPs(new ArrayList<Neutron_IPs>(0));
+        port.setAdminStateUp(Boolean.TRUE);
+        port.setName("br-int config");
+
+        ph.neutronPortUpdated(port);
     }
 
     /**
@@ -399,7 +473,7 @@ public class PortHandlerTest extends TestBase {
         PortHandler ph = new PortHandler();
         ph.setVTNManager(new VTNManagerStub());
 
-        // In the cases that the method returns HTTP_BAD_REQUEST by setting NULL to TenantID.
+        // Case - Method returns HTTP_BAD_REQUEST by setting NULL to TenantID.
         NeutronPort port = new NeutronPort();
         port.setTenantID(null);
         port.setNetworkUUID(NEUTRON_UUID_ARRAY[0]);
@@ -410,7 +484,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                 ph.canDeletePort(port));
 
-        // Cases - returns HTTP_NOT_FOUND(Interface does not exist) by setting wrong PortUUID.
+        // Case - returns HTTP_NOT_FOUND(Interface does not exist) by setting wrong PortUUID.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -421,7 +495,7 @@ public class PortHandlerTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
                 ph.canDeletePort(port));
 
-        // In the cases that the method returns HTTP_OK.
+        // Case - Method returns HTTP_OK.
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
@@ -437,12 +511,13 @@ public class PortHandlerTest extends TestBase {
      * Test method for
      * {@link PortHandler#neutronPortDeleted(NeutronPort)}.
      */
-    public void testNeutronPortDeleted(NeutronPort port) {
+    @Test
+    public void testNeutronPortDeleted() {
         PortHandler ph = new PortHandler();
         ph.setVTNManager(new VTNManagerStub());
 
         // Case - returns HTTP_NOT_FOUND(Interface does not exist) by setting wrong PortUUID.
-        port = new NeutronPort();
+        NeutronPort port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
         port.setPortUUID(NEUTRON_UUID_ARRAY[1]);
@@ -461,7 +536,7 @@ public class PortHandlerTest extends TestBase {
 
         ph.neutronPortDeleted(port);
 
-        // Case - Success.
+        // Success Case
         port = new NeutronPort();
         port.setTenantID(VTNManagerStub.TENANT_1_UUID);
         port.setNetworkUUID(VTNManagerStub.BRIDGE_1_UUID);
index 96043704241c3975ab023d14279e5c98b0c24ff6..51cd88e6b944ff733fb9ec68f6b4403c06733ea5 100644 (file)
@@ -12,6 +12,7 @@ package org.opendaylight.vtn.manager.neutron;
 import java.io.File;
 
 import org.junit.Assert;
+import java.util.UUID;
 
 /**
  * Abstract base class for JUnit tests.
@@ -104,7 +105,7 @@ public abstract class TestBase extends Assert {
     /**
      * String Declaration for identifying the Bridge with below NodeID.
      */
-    protected static final String NODE_ID_2 = "D30D27770885";
+    protected static final String NODE_ID_2 = UUID.randomUUID().toString();
 
     /**
      * String Declaration for identifying the Interface with below Parent_UUID.
@@ -121,6 +122,11 @@ public abstract class TestBase extends Assert {
      */
     public static final String CONFLICTED_NETWORK_UUID = "5e7e0900f2151e3aa760002a5d5c51c";
 
+    /*
+     * String declaration for setting Node to NULL for the below UUID
+     */
+    public static final String SET_NULL_TO_NODE = "5e7e0900f2151e3aa760002a5d5c51d";
+
     /**
      * String Declaration for setting the OFPortArray to NULL.
      */
@@ -288,7 +294,13 @@ public abstract class TestBase extends Assert {
          "9b2b6560-f21e-11e3-a6a2-0002a5d5c51b", "not_null", "not_null",
          "", "null_msg", "iface-id", "C387EB44-7832-49F4-B9F0-D30D27770881"},
 
-        // Fail case for No switch is associated with interface, Node or interface Uuid is Null by setting UUID to null
+        // Fail case for No switch is associated with interface, Node or interface Uuid is Null by setting Node to null
+        // At present case, the below case failes
+        {"PE", "bridge-int", "br-int", "Interface", "",
+         SET_NULL_TO_NODE, "null", "null",
+         "", "null_msg", "iface-id", "C387EB44-7832-49F4-B9F0-D30D27770883"},
+
+         // Fail case for No switch is associated with interface, Node or interface Uuid is Null by setting UUID to null
         {"PE", "bridge-int", "br-int", "Interface", "",
          null, "null", "null",
          "", "null_msg", "iface-id", "C387EB44-7832-49F4-B9F0-D30D27770883"},
@@ -371,7 +383,12 @@ public abstract class TestBase extends Assert {
         // OpenVSwitch
         {"PE", "intf-neutron", "interface1", "OpenVSwitch", "",
          "9b2b6560-f21e-11e3-a6a2-0002a5d5c51f", "not_null", "not_null",
-         "", "no_ex_msg", "iface-id", "0D2206F8-B700-4F78-913D-9CE7A2D78473"}};
+         "", "no_ex_msg", "iface-id", "0D2206F8-B700-4F78-913D-9CE7A2D78473"},
+
+        // Bridge
+        {"PE", "intf-neutron", "interface1", "Bridge", "",
+         "", "not_null", "not_null",
+         "", "no_ex_msg", "", ""}};
 
     /**
      * Exception message to be checked.
@@ -379,79 +396,6 @@ public abstract class TestBase extends Assert {
     protected static final String EXCEPTION_MSG =
             "org.opendaylight.ovsdb.lib.table.Bridge cannot be cast to org.opendaylight.ovsdb.lib.table.Interface";
 
-    /**
-     * An array of elements to update row with type OF.
-     */
-    protected static final String[][] RW_UPDT_INP_OF_ARY = {
-        {"Set_OF_neutron", "0", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "9b2b6560-f21e-11e3-a6a2-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_neutron", "12344321", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "9b2b6560-f21e-11e3-a6a2-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_neutron", "12344321", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", null,
-         "9b2b6560-f21e-11e3-a6a2-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_neutron", "12344321", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Bridge",
-         "9b2b6560-f21e-11e3-a6a2-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_neutron", "12345678", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "9b2b6560-f21e-11e3-a6a2-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_neutron", "12345678", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "", "0", "0", "no_ex_msg", "1", "0" }  ,
-
-        {"Set_OF_neutron", "23456789", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "85c27f20-f218-11e3-a7b6-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_neutron", "23456789", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "c09b7fc0-f218-11e3-bf2f-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_neutron", "23456789", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         null,
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_neutron", "98765432", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "85c27f20-f218-11e3-a7b6-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" },
-
-        {"Set_OF_Null", "12345678", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "0d0ff2a0-f219-11e3-a482-0002a5d5c51b",
-         "1", "0", "null_msg", "0", "0" },
-
-        {"Set_OF_Bridge", "98765432", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "85c27f20-f218-11e3-a7b6-0002a5d5c51b",
-         "1", "0", "ex_msg", "0", "0" },
-
-        {"Set_OF_Bridge_intf", "98765432", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "85c27f20-f218-11e3-a7b6-0002a5d5c51b",
-         "1", "0", "ex_msg", "0", "0" },
-
-        {"Set_OF_neutron", "12345678", "interface1", "iface-id",
-         "C387EB44-7832-49F4-B9F0-D30D27770883", "Interface",
-         "85c27f20-f218-11e3-a7b6-0002a5d5c51b",
-         "0", "0", "no_ex_msg", "1", "0" } };
-
     /**
      * An array of elements to create network.
      */
@@ -470,7 +414,7 @@ public abstract class TestBase extends Assert {
         // Update case in Node added method
         {"PE", NODE_ID_2, "0", "" },
         // New NODE added case - Successful
-        {"PE", "D30D27770883", "0", "" }
+        {"PE", UUID.randomUUID().toString(), "0", "" }
     };
 
     /**
@@ -491,7 +435,11 @@ public abstract class TestBase extends Assert {
         {"22222224", "Interface",        "0D2206F8-B700-4F78-913D-9CE7A2D78483", "0"},
         // Fail case(processRowUpdated getVTNIdentifiers failed) - by setting NodeID and return HTTP_BAD_REQUEST in Method-deletePortMapForInterface()
         {"22222225", "Interface",        "C387EB44-7832-49F4-B9F0-D30D27770883", "0"},
-        // Fail case(neutron identifiers not specified) - by setting invalid NodeID and return HTTP_BAD_REQUEST in Method-getVTNIdentifiers()
+        // Fail case(neutron identifiers not specified) - by setting invalid TennantID, SwitchID, PortID and return HTTP_BAD_REQUEST in Method-getVTNIdentifiers()
+        {"22222226", "Interface",        "D387EB44-7832-49F4-B9F0-D30D27770884", "0"},
+        // Fail case(neutron identifiers not specified) - by setting invalid SwitchID, PortID and return HTTP_BAD_REQUEST in Method-getVTNIdentifiers()
+        {"22222226", "Interface",        "D387EB44-7832-49F4-B9F0-D30D27770885", "0"},
+        // Fail case(neutron identifiers not specified) - by setting invalid PortID and return HTTP_BAD_REQUEST in Method-getVTNIdentifiers()
         {"22222226", "Interface",        "C387EB44-7832-49F4-B9F0-D30D27770883", "0"},
         // Fail case(Invalid tenant identifier) - by setting invalid TennantID and return HTTP_BAD_REQUEST in Method-getVTNIdentifiers()
         {"22222227", "Interface",        "0D2206F8-B700-4F78-913D-9CE7A2D78475", "0"},
@@ -505,20 +453,6 @@ public abstract class TestBase extends Assert {
         {"22222231", "Interface",        "0D2206F8-B700-4F78-913D-9CE7A2D78473", "0"},
     };
 
-    /**
-     * An array of elements to update row.
-     */
-    protected static final String[][] ROW_UPDATE_PORT_ARRAY = {
-        {"OF", "56456644", "interface1", "C387EB44-7832-49F4-B9F0-D30D27770883", "set_port", "", "0" },
-        {"OF", "56456644", "interface1", "C387EB44-7832-49F4-B9F0-D30D27770883", "set_null_port", "", "0" },
-        {"OF", "56456644", "interface1", "C387EB44-7832-49F4-B9F0-D30D27770883", "set_empty_port", "", "0" },
-        {"OF", "12345678", "interface1", "C387EB44-7832-49F4-B9F0-D30D27770883", "without_port", "65534", "0" },
-        {"OF", "56456644", "interface1", "4790F3C1-AB34-4ABC-B7A5-C1B5C7202389", "", "65534", "0" },
-        {"OF", "56456644", "interface1", "52B1482F-A41E-409F-AC68-B04ACFD07779", "", "65534", "0" },
-        {"OF", "56456644", "interface1", "8c781fc0-f215-11e3-aac3-0002a5d5c51b", "", "65534", "0" },
-        {"OF", "56456644", "interface1", "0D2206F8-B700-4F78-913D-9CE7A2D78473", "", "65534", "0" },
-    };
-
     /**
      * Delete the specified directory recursively.
      *
index de38f7baaf59cb1f6e6240ea9bd5d87c07ee63ea..75e2a7acc57212d016e0fd9d4d2df730a4f749ff 100644 (file)
@@ -62,6 +62,9 @@ import org.opendaylight.vtn.manager.flow.filter.FlowFilterId;
  * org.opendaylight.vtn.manager package.
  */
 public class VTNManagerStub implements IVTNManager {
+    // Boolean identifier for returning valid VInterface on setting this boolean variable
+    static boolean isReturnValidVInterface = false;
+
     // An invalid UUID
     static final String INVALID_UUID = "F6197D54-97A1-44D2-ABFB-6DFED030C30F-";
 
@@ -78,6 +81,10 @@ public class VTNManagerStub implements IVTNManager {
     static final String VBR_IF_1_NAME = "F6197D5497A14D2ABFB6DFED030C30F";
     static final String VBR_IF_2_UUID = "F6197D54-97A1-44D2-ABFB-6DFED030C300";
     static final String VBR_IF_2_NAME = "F6197D5497A14D2ABFB6DFED030C300";
+    static final String VBR_IF_3_UUID = "F6197D54-97A1-44D2-ABFB-6DFED030C301";
+    static final String VBR_IF_3_NAME = "F6197D5497A14D2ABFB6DFED030C301";
+    static final String VBR_IF_4_UUID = "F6197D54-97A1-44D2-ABFB-6DFED030C302";
+    static final String VBR_IF_4_NAME = "F6197D5497A14D2ABFB6DFED030C302";
 
     // Following methods are used in UnitTest.
     @Override
@@ -93,10 +100,14 @@ public class VTNManagerStub implements IVTNManager {
         }
 
         VTenantPath tenant1 = new VTenantPath(TENANT_1_NAME);
+        VTenantPath tenant2 = new VTenantPath(TENANT_1_UUID);
         if (path.equals(tenant1)) {
             VTenantConfig conf = new VTenantConfig(null);
             VTenant tenant = new VTenant(TENANT_1_NAME, conf);
             return tenant;
+        } else if (path.equals(tenant2)) {
+            Status status = new Status(StatusCode.BADREQUEST);
+            throw new VTNException(status);
         }
 
         return null;
@@ -125,6 +136,10 @@ public class VTNManagerStub implements IVTNManager {
 
         VBridgePath bridge1 = new VBridgePath(TENANT_1_NAME,
                                               BRIDGE_1_NAME);
+
+        VBridgePath bridge2 = new VBridgePath(TENANT_1_UUID,
+                                              BRIDGE_1_NAME);
+
         if (path.equals(bridge1)) {
             VBridgeConfig bconf = new VBridgeConfig(null);
             VBridge bridge = new VBridge(BRIDGE_1_NAME,
@@ -132,6 +147,9 @@ public class VTNManagerStub implements IVTNManager {
                                          0,
                                          bconf);
             return bridge;
+        } else if (path.equals(bridge2)) {
+            Status status = new Status(StatusCode.BADREQUEST);
+            throw new VTNException(status);
         }
 
         return null;
@@ -171,6 +189,10 @@ public class VTNManagerStub implements IVTNManager {
         VBridgeIfPath if2 = new VBridgeIfPath(TENANT_1_NAME,
                                               BRIDGE_1_NAME,
                                               VBR_IF_2_NAME);
+
+        VBridgeIfPath if3 = new VBridgeIfPath(TENANT_1_NAME,
+                                              BRIDGE_1_NAME,
+                                              VBR_IF_3_NAME);
         if (path.equals(if1)) {
             VInterfaceConfig iconf = new VInterfaceConfig(null, true);
             VInterface vif = new VInterface(VBR_IF_1_NAME,
@@ -185,6 +207,19 @@ public class VTNManagerStub implements IVTNManager {
                                             VNodeState.UNKNOWN,
                                             iconf);
             return vif;
+        } else if (path.equals(if3)) {
+            if (isReturnValidVInterface) {
+                isReturnValidVInterface = false;
+
+                VInterfaceConfig iconf = new VInterfaceConfig(null, true);
+                VInterface vif = new VInterface(VBR_IF_3_NAME,
+                                                VNodeState.UNKNOWN,
+                                                VNodeState.UNKNOWN,
+                                                iconf);
+                return vif;
+            }
+            Status status = new Status(StatusCode.BADREQUEST);
+            throw new VTNException(status);
         }
 
         return null;
@@ -199,7 +234,12 @@ public class VTNManagerStub implements IVTNManager {
         VBridgeIfPath bif1 = new VBridgeIfPath(TENANT_1_NAME,
                                                BRIDGE_1_NAME,
                                                VBR_IF_2_NAME);
-        if (path.equals(bif1)) {
+
+        VBridgeIfPath bif2 = new VBridgeIfPath(TENANT_1_NAME,
+                                              BRIDGE_1_NAME,
+                                              VBR_IF_4_NAME);
+
+        if ((path.equals(bif1)) || (path.equals(bif2))) {
             return new Status(StatusCode.CONFLICT);
         }
 
index e11ed60d40310f53e49bfbcf7a3082b4d17960de..8cf157a88d54128395ccff788434b51735d40cd5 100644 (file)
@@ -32,7 +32,10 @@ public class VTNNeutronUtilsTest extends TestBase {
         IVTNManager mgr = new VTNManagerStub();
 
         utils.setVTNManager(mgr);
-        assertSame(mgr, utils.getVTNManager());
+        assertEquals(mgr, utils.getVTNManager());
+
+        utils.unsetVTNManager(null);
+        assertEquals(mgr, utils.getVTNManager());
 
         utils.unsetVTNManager(mgr);
         assertNull(utils.getVTNManager());
@@ -88,6 +91,10 @@ public class VTNNeutronUtilsTest extends TestBase {
         invalidId = "550e8400-e29b41d4a716446655440000";
         assertFalse(VTNNeutronUtils.isValidNeutronID(invalidId));
 
+        // The length is 36 but invalid UUID format for IllegalArgumentException.
+        invalidId = "550e8400-e29b-41d4--716-446655440000";
+        assertFalse(VTNNeutronUtils.isValidNeutronID(invalidId));
+
         for (String neutronId: NEUTRON_UUID_ARRAY) {
             assertTrue(VTNNeutronUtils.isValidNeutronID(neutronId));
         }
@@ -120,6 +127,10 @@ public class VTNNeutronUtilsTest extends TestBase {
         invalidId = "550e8400-e29b41d4a716446655440000";
         assertNull(VTNNeutronUtils.convertNeutronIDToVTNKey(invalidId));
 
+        // The length is 32 but invalid UUID format for IllegalArgumentException.
+        invalidId = "550e8400e29b-1d4a716446655440000";
+        assertNull(VTNNeutronUtils.convertNeutronIDToVTNKey(invalidId));
+
         String validId = "550e8400-e29b-41d4-a716-446655440000";
         assertEquals("550e8400e29b1d4a716446655440000",
                      VTNNeutronUtils.convertNeutronIDToVTNKey(validId));
@@ -146,7 +157,7 @@ public class VTNNeutronUtilsTest extends TestBase {
                      utils.isTenantExist(tenantID));
 
         tenantID = VTNManagerStub.TENANT_1_UUID;
-        assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
                      utils.isTenantExist(tenantID));
 
         tenantID = VTNManagerStub.TENANT_1_NAME;
@@ -168,6 +179,10 @@ public class VTNNeutronUtilsTest extends TestBase {
 
         String tenantID = "a";
         String bridgeID = "a";
+
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
+                     utils.isBridgeExist(tenantID, null));
+
         assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
                      utils.isBridgeExist(tenantID, bridgeID));
 
@@ -181,6 +196,11 @@ public class VTNNeutronUtilsTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
                      utils.isBridgeExist(tenantID, bridgeID));
 
+        tenantID = VTNManagerStub.TENANT_1_UUID;
+        bridgeID = VTNManagerStub.BRIDGE_1_NAME;
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
+                     utils.isBridgeExist(tenantID, bridgeID));
+
         tenantID = VTNManagerStub.TENANT_1_NAME;
         bridgeID = VTNManagerStub.BRIDGE_1_NAME;
         assertEquals(HttpURLConnection.HTTP_OK,
@@ -202,6 +222,13 @@ public class VTNNeutronUtilsTest extends TestBase {
         String tenantID = "a";
         String bridgeID = "a";
         String portID = "a";
+
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
+                     utils.isBridgeInterfaceExist(tenantID, null, null));
+
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
+                     utils.isBridgeInterfaceExist(tenantID, bridgeID, null));
+
         assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
                      utils.isBridgeInterfaceExist(tenantID, bridgeID, portID));
 
@@ -211,6 +238,12 @@ public class VTNNeutronUtilsTest extends TestBase {
         assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
                      utils.isBridgeInterfaceExist(tenantID, bridgeID, portID));
 
+        tenantID = VTNManagerStub.TENANT_1_NAME;
+        bridgeID = VTNManagerStub.BRIDGE_1_NAME;
+        portID = VTNManagerStub.VBR_IF_3_NAME;
+        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
+                     utils.isBridgeInterfaceExist(tenantID, bridgeID, portID));
+
         tenantID = VTNManagerStub.TENANT_1_NAME;
         bridgeID = VTNManagerStub.BRIDGE_1_NAME;
         portID = VTNManagerStub.VBR_IF_1_NAME;