Copyright update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / TlsDetectorTest.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.core;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.channel.embedded.EmbeddedChannel;
13
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES;
18
19 /**
20  *
21  * @author michal.polkorab
22  */
23 public class TlsDetectorTest {
24     
25     private EmbeddedChannel embch;
26
27     /**
28      * Sets up test environment
29      */
30     @Before
31     public void setUp() {
32         TlsDetector tlsDetector = new TlsDetector();
33         embch = new EmbeddedChannel(new DummyDecoder());
34         embch.pipeline().addFirst(TcpHandler.COMPONENT_NAMES.TLS_DETECTOR.name(), tlsDetector);
35     }
36
37     /**
38      * Test of decode {@link TlsDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) }
39      * @throws Exception 
40      */
41     @Test
42     public void testDecodeNotEncryptedMessage() throws Exception {
43         byte[] msgs = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01};
44         ByteBuf writeObj = embch.alloc().buffer(64);
45         writeObj.writeBytes(msgs);
46         embch.writeInbound(writeObj);
47
48         Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.TLS_DETECTOR.name()));
49         Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.SSL_HANDLER.name()));
50     }
51 }