Increased unit test coverage for keys 07/12007/1
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Thu, 16 Oct 2014 11:13:07 +0000 (13:13 +0200)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Thu, 16 Oct 2014 12:47:03 +0000 (14:47 +0200)
 - removed check in DeserializationFactory as it is done in DeserializerRegistry
   - also updated DeserializerRegistryImplTest

Change-Id: I4baa4fea035104827b34ec7e1b99e1ca4056dd44
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
14 files changed:
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/extensibility/EnhancedMessageCodeKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/extensibility/EnhancedMessageTypeKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageCodeKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/extensibility/MessageTypeKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/ActionDeserializerKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/ActionSerializerKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/InstructionDeserializerKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/InstructionSerializerKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/MatchEntryDeserializerKeyTest.java
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/MatchEntrySerializerKeyTest.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializationFactory.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImplTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/MessageTypeCodeKeyTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassKeyTest.java

index a99b890174c1f4062717df48734b35d70346a639..7b350d55c42d59afe3ee897971792bad6f4e9e49 100644 (file)
@@ -53,12 +53,22 @@ public class EnhancedMessageCodeKeyTest {
      */\r
     @Test\r
     public void testEquals() {\r
-        \r
          EnhancedMessageCodeKey key1 =\r
                  new EnhancedMessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, 8, BarrierInput.class);\r
          \r
          Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
          Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
-         \r
+    }\r
+\r
+    /**\r
+     * Test EnhancedMessageCodeKey toString()\r
+     */\r
+    @Test\r
+    public void testToString() {\r
+        EnhancedMessageCodeKey key1 =\r
+                new EnhancedMessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, 8, BarrierInput.class);\r
+\r
+        Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
+                + ".openflow.protocol.rev130731.BarrierInput msgType: 4 msgType2: 8", key1.toString());\r
     }\r
 }
\ No newline at end of file
index ec48d7ea787e3a8df74613dcf6962328194be154..e6be8a8d19528d88c953b12838bb7a4d874a2a70 100644 (file)
@@ -57,12 +57,10 @@ public class EnhancedMessageTypeKeyTest {
     public void testEquals() {\r
         EnhancedMessageTypeKey<?,?> key1;\r
         EnhancedMessageTypeKey<?,?> key2;\r
-\r
         key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);\r
         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);\r
         \r
         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
-        \r
         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
         \r
         key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, null);\r
@@ -70,8 +68,18 @@ public class EnhancedMessageTypeKeyTest {
         key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);\r
         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, SetField.class);\r
         Assert.assertFalse("Wrong equal by msgType2 class name.", key1.equals(key2));\r
+    }\r
 \r
+    /**\r
+     * Test EnhancedMessageTypeKey toString()\r
+     */\r
+    @Test\r
+    public void testToString() {\r
+        EnhancedMessageTypeKey<?,?> key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID,\r
+                Action.class, Output.class);\r
+\r
+         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
+                 + ".openflow.common.action.rev130731.actions.grouping.Action msgType2: org.opendaylight.yang.gen.v1.urn"\r
+                 + ".opendaylight.openflow.common.action.rev130731.Output", key1.toString());\r
     }\r
-    \r
-    \r
 }
\ No newline at end of file
index 7b3f36a0bfea9ccaaf7a4a01b4f9aebe8b434e42..4087a55bd744af0c9c0725923d5bd5e65fcdcf77 100644 (file)
@@ -44,28 +44,34 @@ public class MessageCodeKeyTest {
         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
     }\r
-    \r
+\r
     /**\r
-     * Test EnhancedMessageTypeKey equals - additional test\r
+     * Test MessageCodeKey equals - additional test\r
      */\r
     @Test\r
     public void testEquals() {\r
-        \r
-        MessageCodeKey key1;\r
-        MessageCodeKey key2;\r
-        \r
-        key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
-        \r
-        \r
+        MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
+\r
         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
         Assert.assertFalse("Wrong equal to null.", key1.equals(null));\r
         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
-        \r
+\r
         key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);\r
-        key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
-        \r
+        MessageCodeKey key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
         Assert.assertFalse("Wrong equal by clazz.", key1.equals(key2));\r
-        \r
+\r
+        key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);\r
+        Assert.assertTrue("Wrong equal by clazz.", key1.equals(key2));\r
+    }\r
+\r
+    /**\r
+     * Test MessageCodeKey toString()\r
+     */\r
+    @Test\r
+    public void testToString() {\r
+        MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
+\r
+        Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn"\r
+                + ".opendaylight.openflow.protocol.rev130731.BarrierInput msgType: 4", key1.toString());\r
     }\r
-    \r
 }
\ No newline at end of file
index 73dee30400133ec966a6e058188c75570141b317..4dbd5541622704c03f98b0f9d9c075639c8cd7de 100644 (file)
@@ -41,24 +41,36 @@ public class MessageTypeKeyTest {
         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
     }\r
-    \r
+\r
     /**\r
-     * Test EnhancedMessageTypeKey equals - additional test\r
+     * Test MessageTypeKey equals - additional test\r
      */\r
     @Test\r
     public void testEquals() {\r
          MessageTypeKey<?> key1;\r
          MessageTypeKey<?> key2; \r
-         \r
          key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);\r
-         \r
+\r
          Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
          Assert.assertFalse("Wrong equal to null.", key1.equals(null));\r
          Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
-         \r
+\r
          key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null);\r
          key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);\r
-         \r
          Assert.assertFalse("Wrong equal by msgType.", key1.equals(key2));\r
+\r
+         key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null);\r
+         Assert.assertTrue("Wrong equal by msgType.", key1.equals(key2));\r
+    }\r
+\r
+    /**\r
+     * Test MessageTypeKey toString()\r
+     */\r
+    @Test\r
+    public void testToString() {\r
+         MessageTypeKey<?> key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);\r
+\r
+         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn"\r
+                 + ".opendaylight.openflow.protocol.rev130731.BarrierInput", key1.toString());\r
     }\r
 }
\ No newline at end of file
index 3ffe358f9e210023c37d879c655cbf3d4fa14401..66a09fe9bef05361047549d17825f76c6bc285b9 100644 (file)
@@ -46,15 +46,25 @@ public class ActionDeserializerKeyTest {
      */\r
     @Test\r
     public void testEquals(){\r
-        \r
         ActionDeserializerKey key1 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
         ActionDeserializerKey key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 42L);\r
-        \r
+\r
         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
-        \r
         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
-        \r
         Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));\r
-        \r
+        key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
+        Assert.assertTrue("Wrong equal by experimenterId", key1.equals(key2));\r
+    }\r
+\r
+    /**\r
+     * Test InstructionDeserializerKey toString()\r
+     */\r
+    @Test\r
+    public void testToString(){\r
+        ActionDeserializerKey key1 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
+\r
+        Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn"\r
+                + ".opendaylight.openflow.common.action.rev130731.actions.grouping.Action msgType: 11"\r
+                + " experimenterID: null", key1.toString());\r
     }\r
 }
\ No newline at end of file
index e145e8a23e01ba0044f7bbfb12b0f87ee791a575..f9c5225d3568ab57d4f6b741dfad3a7ce7df98cd 100644 (file)
@@ -49,18 +49,33 @@ public class ActionSerializerKeyTest {
     }\r
     \r
     /**\r
-     * Test ActionDeserializerKey equals - additional test\r
+     * Test ActionSerializerKey equals - additional test\r
      */\r
     @Test\r
     public void testEquals(){\r
-         ActionSerializerKey<CopyTtlIn> key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);\r
+         ActionSerializerKey<?> key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);\r
          ActionSerializerKey<?> key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlIn.class, 42L);\r
          \r
          Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
-         \r
          Assert.assertFalse("Wrong equal by actionType", key1.equals(key2));\r
          \r
+         key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);\r
+         Assert.assertTrue("Wrong equal by action type", key1.equals(key2));\r
          key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID,  CopyTtlIn.class, null);\r
          Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));\r
+         key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlIn.class, null);\r
+         Assert.assertTrue("Wrong equal by experimenterId", key1.equals(key2));\r
+    }\r
+\r
+    /**\r
+     * Test ActionSerializerKey toString()\r
+     */\r
+    @Test\r
+    public void testToString(){\r
+        ActionSerializerKey<CopyTtlIn> key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlIn.class, 42L);\r
+\r
+        Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
+                + ".openflow.common.action.rev130731.actions.grouping.Action action type: org.opendaylight.yang.gen.v1.urn"\r
+                + ".opendaylight.openflow.common.action.rev130731.CopyTtlIn experimenterID: 42", key1.toString());\r
     }\r
 }
\ No newline at end of file
index ccd3311108769be8d8191793f2248da590f3253f..2497413a91939968adeb139e702eab02903e8d06 100644 (file)
@@ -46,15 +46,25 @@ public class InstructionDeserializerKeyTest {
      */\r
     @Test\r
     public void testEquals(){\r
-        \r
         InstructionDeserializerKey key1 = new InstructionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
         InstructionDeserializerKey key2 = new InstructionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 24L);\r
-        \r
+\r
         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
-        \r
         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
-        \r
         Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));\r
-        \r
+        key2 = new InstructionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
+        Assert.assertTrue("Wrong equal by experimenterId", key1.equals(key2));\r
+    }\r
+\r
+    /**\r
+     * Test InstructionDeserializerKey toString()\r
+     */\r
+    @Test\r
+    public void testToString(){\r
+        InstructionDeserializerKey key1 = new InstructionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
+\r
+        Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
+                + ".openflow.common.instruction.rev130731.instructions.grouping.Instruction msgType: 11"\r
+                + " experimenterID: null", key1.toString());\r
     }\r
 }
\ No newline at end of file
index f6b65a90b6a6de84789325d4dbe4a865e833d0ab..8e7d1f5fd53676c836b488dfad182af981ae29ca 100644 (file)
@@ -53,20 +53,33 @@ public class InstructionSerializerKeyTest {
      */\r
     @Test\r
     public void testEquals(){\r
-        \r
         InstructionSerializerKey<?> key1 =\r
                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);\r
         InstructionSerializerKey<?> key2 =\r
                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);\r
-        \r
+\r
         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
-        \r
+\r
         key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, null);\r
         Assert.assertFalse("Wrong equal by experimenterId.", key1.equals(key2));\r
-        \r
-        key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID,  null, 42L);\r
-        Assert.assertFalse("Wrong equal by instructionType.", key1.equals(key2));\r
-        \r
+\r
+        key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);\r
+        key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);\r
+        Assert.assertTrue("Wrong equal by instructionType.", key1.equals(key2));\r
+    }\r
+\r
+    /**\r
+     * Test InstructionSerializerKey toString()\r
+     */\r
+    @Test\r
+    public void testToString(){\r
+        InstructionSerializerKey<?> key1 =\r
+                new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);\r
+\r
+        Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
+                + ".openflow.common.instruction.rev130731.instructions.grouping.Instruction"\r
+                + " instructionType type: org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"\r
+                + ".instruction.rev130731.ApplyActions vendorID: 42", key1.toString());\r
     }\r
 }
\ No newline at end of file
index 0f8e254e011baab7b7c45a3449cf60721f8d3747..be87d557792e6af09fff09891e993544b8c7b30f 100644 (file)
@@ -52,24 +52,32 @@ public class MatchEntryDeserializerKeyTest {
      */\r
     @Test\r
     public void testEquals() {\r
-        \r
          MatchEntryDeserializerKey key1 = new MatchEntryDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0x8000, 42);\r
          MatchEntryDeserializerKey key2 = new MatchEntryDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0x8000, 42);\r
          \r
          Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
-        \r
          Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
          \r
-         \r
          Long expId1=123456L;\r
          Long expId2=654321L;\r
-         \r
          key1.setExperimenterId(null);\r
          key2.setExperimenterId(expId2);\r
-         Assert.assertFalse("Wrong equal by  experimeterId.", key1.equals(key2));\r
+         Assert.assertFalse("Wrong equal by experimeterId.", key1.equals(key2));\r
          \r
          key1.setExperimenterId(expId1);\r
-         Assert.assertFalse("Wrong equal by  experimeterId.", key1.equals(key2));\r
+         Assert.assertFalse("Wrong equal by experimeterId.", key1.equals(key2));\r
+         Assert.assertFalse("Wrong equals with different object class", key1.equals(key2));\r
+    }\r
+\r
+    /**\r
+     * Test MatchEntryDeserializerKey toString()\r
+     */\r
+    @Test\r
+    public void testToString(){\r
+        MatchEntryDeserializerKey key1 = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID, 0x8000, 42);\r
 \r
+        Assert.assertEquals("Wrong toString()", "msgVersion: 4 objectClass: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
+                + ".openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries msgType: 32768 oxm_field: 42"\r
+                + " experimenterID: null", key1.toString());\r
     }\r
 }
\ No newline at end of file
index 5e79712df9515680487733b492d89b89cdb93792..576c446f0e9a3d661aed547e45a5f31b312f9467 100644 (file)
@@ -53,6 +53,8 @@ public class MatchEntrySerializerKeyTest {
                 null, InPhyPort.class);\r
         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
+        key2.setExperimenterId(42L);\r
+        Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
     }\r
     \r
     /**\r
@@ -78,8 +80,28 @@ public class MatchEntrySerializerKeyTest {
         key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, null, InPort.class);\r
         key1.setExperimenterId(expId2);\r
         Assert.assertFalse("Wrong equal by oxmClass", key1.equals(key2));\r
+        key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, null, InPort.class);\r
+        key2.setExperimenterId(expId2);\r
+        Assert.assertTrue("Wrong equal by oxmClass", key1.equals(key2));\r
         key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, null);\r
         key1.setExperimenterId(expId2);\r
         Assert.assertFalse("Wrong equal by oxmField", key1.equals(key2));\r
+        key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, null);\r
+        key2.setExperimenterId(expId2);\r
+        Assert.assertTrue("Wrong equal by oxmField", key1.equals(key2));\r
+    }\r
+\r
+    /**\r
+     * Test MatchEntrySerializerKey toString()\r
+     */\r
+    @Test\r
+    public void testToString(){\r
+        MatchEntrySerializerKey<?, ?> key1;\r
+        key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);\r
+\r
+        Assert.assertEquals("Wrong toString()", "msgVersion: 4 objectType: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
+                + ".openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries oxm_class: org.opendaylight.yang.gen.v1.urn"\r
+                + ".opendaylight.openflow.oxm.rev130731.OpenflowBasicClass oxm_field: org.opendaylight.yang.gen.v1.urn"\r
+                + ".opendaylight.openflow.oxm.rev130731.InPort experimenterID: null", key1.toString());\r
     }\r
 }
\ No newline at end of file
index f459c97f5079d8e41972021a04687899e9443558..274b97407cfa67b66cdd2ee9cbdabd2a62981bab 100644 (file)
@@ -49,9 +49,7 @@ public class DeserializationFactory {
         rawMessage.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
         OFDeserializer<DataObject> deserializer = registry.getDeserializer(
                 new MessageCodeKey(version, type, clazz));
-        if (deserializer != null) {
-            dataObject = deserializer.deserialize(rawMessage);
-        }
+        dataObject = deserializer.deserialize(rawMessage);
         return dataObject;
     }
 
index 655702b9bce7ab6ca4e295389115f061b32369cc..aec3df43b68cc839eae40f77395ed3faa5b9f546 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
 import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.Match;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.v10.grouping.MatchV10;
 /**
  * 
  * @author madamjak
@@ -22,7 +23,7 @@ public class DeserializerRegistryImplTest {
 
     private static final short OF13 = EncodeConstants.OF13_VERSION_ID;
     private static final short OF10 = EncodeConstants.OF10_VERSION_ID;
-    public static final int EMPTY_VALUE = EncodeConstants.EMPTY_VALUE;
+    private static final int EMPTY_VALUE = EncodeConstants.EMPTY_VALUE;
 
     /**
      * Test - register deserializer without arguments
@@ -34,26 +35,52 @@ public class DeserializerRegistryImplTest {
     }
 
     /**
-     * Test - unregister deserializer without MessageTypeKye
+     * Test - register deserializer with no key
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testRegisterDeserializerNoKey(){
+        DeserializerRegistryImpl serReg = new DeserializerRegistryImpl();
+        serReg.registerDeserializer(null, new MatchDeserializer());
+    }
+
+    /**
+     * Test - register deserializer with no deserializer
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testRegisterDeserializerNoDeserializer(){
+        DeserializerRegistryImpl serReg = new DeserializerRegistryImpl();
+        serReg.registerDeserializer(new MessageCodeKey(OF13, EMPTY_VALUE, Match.class), null);
+    }
+
+    /**
+     * Test - unregister deserializer without MessageTypeKey
      */
     @Test(expected = IllegalArgumentException.class)
     public void testUnRegisterDeserializerNoMessageTypeKey(){
         DeserializerRegistryImpl derserReg = new DeserializerRegistryImpl();
         derserReg.init();
-        derserReg.registerDeserializer(new MessageCodeKey(OF13,EMPTY_VALUE, Match.class), new MatchDeserializer());
         derserReg.unregisterDeserializer(null);
     }
 
     /**
-     * Test - unregister deserializer 
+     * Test - unregister deserializer
      */
     @Test
     public void testUnRegisterDeserializer(){
         DeserializerRegistryImpl derserReg = new DeserializerRegistryImpl();
         derserReg.init();
-        derserReg.registerDeserializer(new MessageCodeKey(OF13,EMPTY_VALUE, Match.class), new MatchDeserializer());
         Assert.assertTrue("Wrong - unregister serializer",derserReg.unregisterDeserializer(new MessageCodeKey(OF13,EMPTY_VALUE, Match.class)));
-        derserReg.registerDeserializer(new MessageCodeKey(OF13, EMPTY_VALUE, Match.class), new MatchDeserializer());
         Assert.assertFalse("Wrong - unregister serializer",derserReg.unregisterDeserializer(new MessageCodeKey(OF10,EMPTY_VALUE, Match.class)));
     }
-}
+
+    /**
+     * Test - get deserializer
+     */
+    @Test(expected=IllegalStateException.class)
+    public void testGetDeserializer(){
+        DeserializerRegistryImpl registry = new DeserializerRegistryImpl();
+        registry.init();
+        registry.getDeserializer(new MessageCodeKey((short) 5000, EncodeConstants.EMPTY_VALUE, MatchV10.class));
+        Assert.fail();
+    }
+}
\ No newline at end of file
index d63a792f37757593aede7c3bdf88a0af081a2482..337d3d36d839ced41eeb0cf0096e205e1c270075 100644 (file)
@@ -8,9 +8,9 @@
 
 package org.opendaylight.openflowjava.protocol.impl.deserialization;
 
+import org.junit.Assert;
 import org.junit.Test;
 
-import junit.framework.Assert;
 
 /**
  * 
@@ -19,37 +19,44 @@ import junit.framework.Assert;
  */
 public class MessageTypeCodeKeyTest {
 
+    /**
+     * Tests equals and hashCode
+     */
     @Test
-    public void testEquals(){
+    public void testEqualsAndHashcode(){
         short msgType1 = 12;
         short msgVersion1 = 34;
         short msgType2 = 21;
         short msgVersion2 = 43;
-        
         MessageTypeCodeKey key1 = new MessageTypeCodeKey(msgVersion1, msgType1);
-        
-        Assert.assertTrue("Wrong - equals to same obejct",key1.equals(key1));
-        Assert.assertFalse("Wrong - equals to null",key1.equals(null));
-        Assert.assertFalse("Wrong - equals to different class",key1.equals(new Object()));
-        
-        MessageTypeCodeKey key2 = new MessageTypeCodeKey(msgVersion2, msgType2);
-        Assert.assertFalse("Wrong - equals by msgType",key1.equals(key2));
-        
+
+        Assert.assertTrue("Wrong - equals to same object", key1.equals(key1));
+        Assert.assertFalse("Wrong - equals to null", key1.equals(null));
+        Assert.assertFalse("Wrong - equals to different class", key1.equals(new Object()));
+
+        MessageTypeCodeKey key2 = new MessageTypeCodeKey(msgVersion1, msgType1);
+        Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
+        Assert.assertTrue("Wrong - equals to mirror object", key1.equals(key2));
+
+        key2 = new MessageTypeCodeKey(msgVersion2, msgType2);
+        Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
+        Assert.assertFalse("Wrong - equals by msgType", key1.equals(key2));
+
         key2 = new MessageTypeCodeKey(msgVersion2, msgType1);
-        Assert.assertFalse("Wrong - equals by msgVersion",key1.equals(key2));
+        Assert.assertFalse("Wrong - equals by msgVersion", key1.equals(key2));
+        Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
     }
 
+    /**
+     * Tests getters
+     */
     @Test
     public void testGetter(){
-        
         short msgType = 12;
         short msgVersion = 34;
-
         MessageTypeCodeKey key1 = new MessageTypeCodeKey(msgVersion, msgType);
 
         Assert.assertEquals(msgType, key1.getMsgType());
         Assert.assertEquals(msgVersion, key1.getMsgVersion());
-
     }
-
-}
+}
\ No newline at end of file
index 6756ac3a98c5b06bb21ea097cc9234c17bfc43cd..bf9d060fae68ac1ff00f278e80cec465c54c445a 100644 (file)
@@ -26,11 +26,13 @@ public class TypeToClassKeyTest {
         final short ver10 = EncodeConstants.OF10_VERSION_ID;
         final short ver13 = EncodeConstants.OF13_VERSION_ID;
         final int type1 = 1;
+        final int type2 = 2;
         TypeToClassKey typeToClsKey10 = new TypeToClassKey(ver10,type1);
         Assert.assertTrue("Wrong - equals to same object", typeToClsKey10.equals(typeToClsKey10));
         Assert.assertFalse("Wrong - equals to null", typeToClsKey10.equals(null));
         Assert.assertFalse("Wrong - equals to different class", typeToClsKey10.equals(new Object()));
-        TypeToClassKey typeToClsKey13 = new TypeToClassKey(ver13,type1);
+        TypeToClassKey typeToClsKey13 = new TypeToClassKey(ver13,type2);
         Assert.assertFalse("Wrong - equals by different version", typeToClsKey13.equals(new Object()));
+        Assert.assertFalse("Wrong - equals by different type", typeToClsKey13.equals(typeToClsKey10));
     }
 }