Add unit tests for EchoInputMessageFactory, EchoReplyInputMessageFactory 13/12013/7
authorMarian Adamjak <marian.adamjak@pantheon.sk>
Thu, 16 Oct 2014 13:10:21 +0000 (15:10 +0200)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Mon, 20 Oct 2014 14:58:20 +0000 (16:58 +0200)
Change-Id: I519e6cf4cb5657be3f506716c999da611079a1d6
Signed-off-by: Marian Adamjak <marian.adamjak@pantheon.sk>
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java

index 25bc0ff7b824a1d0fecf146e2e2b28f1e764e257..ebe8351b2395e52650407c1ddb86a6ff2a947a92 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 
+import org.junit.Assert;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;
 
@@ -52,10 +53,8 @@ public class EchoInputMessageFactoryTest {
         EchoInputBuilder eib = new EchoInputBuilder();
         BufferHelper.setupHeader(eib, EncodeConstants.OF13_VERSION_ID);
         EchoInput ei = eib.build();
-        
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
         echoFactory.serialize(ei, out);
-        
         BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);
     }
     
@@ -68,11 +67,28 @@ public class EchoInputMessageFactoryTest {
         EchoInputBuilder eib = new EchoInputBuilder();
         BufferHelper.setupHeader(eib, EncodeConstants.OF10_VERSION_ID);
         EchoInput ei = eib.build();
-        
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
         echoFactory.serialize(ei, out);
-        
         BufferHelper.checkHeaderV10(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);
     }
 
+    /**
+     * Testing of {@link EchoInputMessageFactory} for correct data serialization
+     * @throws Exception 
+     */
+    @Test
+    public void testData() throws Exception{
+        byte[] dataToTest = new byte[]{91,92,93,94,95,96,97,98};
+        EchoInputBuilder eib = new EchoInputBuilder();
+        BufferHelper.setupHeader(eib, EncodeConstants.OF13_VERSION_ID);
+        eib.setData(dataToTest);
+        EchoInput ei = eib.build();
+        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+        echoFactory.serialize(ei, out);
+        BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8+dataToTest.length);
+        byte[] outData = new byte[dataToTest.length];
+        out.readBytes(outData);
+        Assert.assertArrayEquals(dataToTest, outData);
+        out.release();
+    }
 }
index 40aa9a0d7c1938630297615423cf271194011c37..970bace064ff7ddce8ce318187ca8f3f4dfe437f 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 
+import org.junit.Assert;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.UnpooledByteBufAllocator;
 
@@ -52,10 +53,8 @@ public class EchoReplyInputMessageFactoryTest {
         EchoReplyInputBuilder erib = new EchoReplyInputBuilder();
         BufferHelper.setupHeader(erib, EncodeConstants.OF13_VERSION_ID);
         EchoReplyInput eri = erib.build();
-        
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
         echoFactory.serialize(eri, out);
-        
         BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8);
     }
     
@@ -68,11 +67,28 @@ public class EchoReplyInputMessageFactoryTest {
         EchoReplyInputBuilder erib = new EchoReplyInputBuilder();
         BufferHelper.setupHeader(erib, EncodeConstants.OF10_VERSION_ID);
         EchoReplyInput eri = erib.build();
-        
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
         echoFactory.serialize(eri, out);
-        
         BufferHelper.checkHeaderV10(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8);
     }
 
+    /**
+     * Testing of {@link EchoReplyInputMessageFactory} for correct message serialization
+     * @throws Exception
+     */
+    @Test
+    public void testDataSerialize()throws Exception {
+        byte[] dataToTest = new byte[]{91,92,93,94,95,96,97,98};
+        EchoReplyInputBuilder erib = new EchoReplyInputBuilder();
+        BufferHelper.setupHeader(erib, EncodeConstants.OF13_VERSION_ID);
+        erib.setData(dataToTest);
+        EchoReplyInput eri = erib.build();
+        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
+        echoFactory.serialize(eri, out);
+        BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8+dataToTest.length);
+        byte[] outData = new byte[dataToTest.length];
+        out.readBytes(outData);
+        Assert.assertArrayEquals("Wrong - different output data.",dataToTest, outData);
+        out.release();
+    }
 }