Merge "add basic lib - plugin communication"
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / openflow / lib / TLSDetectorTest.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.openflow.lib;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 import io.netty.channel.embedded.EmbeddedChannel;\r
6 \r
7 import org.junit.Assert;\r
8 import org.junit.Before;\r
9 import org.junit.Test;\r
10 import org.openflow.lib.TcpHandler;\r
11 import org.openflow.lib.TlsDetector;\r
12 import org.openflow.lib.TcpHandler.COMPONENT_NAMES;\r
13 \r
14 /**\r
15  *\r
16  * @author michal.polkorab\r
17  */\r
18 public class TLSDetectorTest {\r
19     \r
20     private EmbeddedChannel embch;\r
21 \r
22     /**\r
23      * Sets up test environment\r
24      */\r
25     @Before\r
26     public void setUp() {\r
27         TlsDetector tlsDetector = new TlsDetector();\r
28         embch = new EmbeddedChannel(new DummyDecoder());\r
29         embch.pipeline().addFirst(TcpHandler.COMPONENT_NAMES.TLS_DETECTOR.name(), tlsDetector);\r
30     }\r
31 \r
32     /**\r
33      * Test of decode {@link TlsDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) }\r
34      * @throws Exception \r
35      */\r
36     @Test\r
37     public void testDecodeNotEncryptedMessage() throws Exception {\r
38         byte[] msgs = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01};\r
39         ByteBuf writeObj = embch.alloc().buffer(64);\r
40         writeObj.writeBytes(msgs);\r
41         embch.writeInbound(writeObj);\r
42 \r
43         Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.TLS_DETECTOR.name()));\r
44         Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.SSL_HANDLER.name()));\r
45     }\r
46 }