Add new tests, fix several mistakes, add and edit copyright comments 74/11974/2
authorMarian Adamjak <marian.adamjak@pantheon.sk>
Wed, 15 Oct 2014 11:58:53 +0000 (13:58 +0200)
committerMarian Adamjak <marian.adamjak@pantheon.sk>
Wed, 15 Oct 2014 14:12:08 +0000 (16:12 +0200)
Change-Id: Ied68bd5c0f1c713ee7a1d819756101ccf4026181
Signed-off-by: Marian Adamjak <marian.adamjak@pantheon.sk>
openflow-protocol-api/src/test/java/org/opendaylight/openflowjava/protocol/api/keys/MatchEntrySerializerKeyTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactoryImplTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImplTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassKeyTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/SerializerRegistryImplTest.java

index fa88fd7b6b2f864d8657365c8f07ba9028943b7c..5e79712df9515680487733b492d89b89cdb93792 100644 (file)
@@ -60,15 +60,11 @@ public class MatchEntrySerializerKeyTest {
      */\r
     @Test\r
     public void testEquals(){\r
-        \r
         MatchEntrySerializerKey<?, ?> key1;\r
         MatchEntrySerializerKey<?, ?> key2;\r
-        \r
         key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);\r
         key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.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
         Long expId1 = 987654331L;\r
@@ -76,16 +72,14 @@ public class MatchEntrySerializerKeyTest {
         \r
         key1.setExperimenterId(null);\r
         key2.setExperimenterId(expId2);\r
-        \r
         Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));\r
-        \r
         key1.setExperimenterId(expId1);\r
         Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));\r
-        \r
         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
-        \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
     }\r
 }
\ No newline at end of file
index ae6d0ac97d6b02379017d9264d25b0d04dc90bfa..010953b3e9d1f0595ae7623f796d6992f026bc70 100644 (file)
@@ -1,8 +1,14 @@
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.openflowjava.protocol.impl.connection;
 
 import static org.mockito.Mockito.when;
 import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelPipeline;
 
 import java.net.InetSocketAddress;
@@ -12,26 +18,28 @@ import org.mockito.MockitoAnnotations;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-
+/**
+ * 
+ * @author madamjak
+ *
+ */
 public class ConnectionAdapterFactoryImplTest {
 
     @Mock ChannelPipeline channnelPipe;
     @Mock Channel channel; 
-    @Mock ChannelFuture channelFuture;
     @Mock InetSocketAddress address;
-    
+
     @Before
     public void startUp(){
         MockitoAnnotations.initMocks(this);
         when(channel.pipeline()).thenReturn(channnelPipe);
-        when(channel.disconnect()).thenReturn(channelFuture);
     }
-    
+
     @Test
     public void test(){
-        ConnectionAdapterFactoryImpl caf = new ConnectionAdapterFactoryImpl();
-        ConnectionFacade conn = caf.createConnectionFacade(channel, address);
-        
-        // otestovat isAlive
+        ConnectionAdapterFactoryImpl connAdapterFactory = new ConnectionAdapterFactoryImpl();
+        ConnectionFacade connFacade = connAdapterFactory.createConnectionFacade(channel, address);
+        Assert.assertNotNull("Wrong - ConnectionFacade has not created.", connFacade);
+        Assert.assertEquals("Wrong - diffrence between channel.isOpen() and ConnectionFacade.isAlive()", channel.isOpen(), connFacade.isAlive());
     }
 }
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImplTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/DeserializerRegistryImplTest.java
new file mode 100644 (file)
index 0000000..655702b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowjava.protocol.impl.deserialization;
+
+import org.junit.Assert;
+import org.junit.Test;
+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;
+/**
+ * 
+ * @author madamjak
+ *
+ */
+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;
+
+    /**
+     * Test - register deserializer without arguments
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testRegisterDeserializerNoArgs(){
+        DeserializerRegistryImpl serReg = new DeserializerRegistryImpl();
+        serReg.registerDeserializer(null, null);
+    }
+
+    /**
+     * Test - unregister deserializer without MessageTypeKye
+     */
+    @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
+    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)));
+    }
+}
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassKeyTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/TypeToClassKeyTest.java
new file mode 100644 (file)
index 0000000..6756ac3
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.deserialization;
+
+import junit.framework.Assert;
+import org.junit.Test;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+/**
+ * 
+ * @author madamjak
+ *
+ */
+public class TypeToClassKeyTest {
+
+    /**
+     * Test equals
+     */
+    @Test
+    public void test(){
+        final short ver10 = EncodeConstants.OF10_VERSION_ID;
+        final short ver13 = EncodeConstants.OF13_VERSION_ID;
+        final int type1 = 1;
+        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);
+        Assert.assertFalse("Wrong - equals by different version", typeToClsKey13.equals(new Object()));
+    }
+}
index c52300182849441e264fbabb350a5512c0efc7f2..c398e47d6640ff6cb0545b9b32deb8beba56b7e7 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
  *
@@ -50,7 +49,7 @@ public class SerializerRegistryImplTest {
      * Test - unregister serializer 
      */
     @Test
-    public void testUnRegisterSerialize(){
+    public void testUnRegisterSerializer(){
         SerializerRegistryImpl serReg = new SerializerRegistryImpl();
         serReg.init();
         serReg.registerSerializer(new MessageTypeKey<>(OF13, Match.class), new OF13MatchSerializer());