Add method to register listener for unknown msg
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / core / OFDatagramPacketDecoderTest.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.openflowjava.protocol.impl.core;
9
10 import static org.mockito.Mockito.times;
11 import static org.mockito.Mockito.verify;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.channel.ChannelHandlerContext;
14
15 import java.net.InetSocketAddress;
16
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
23 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;
24
25 /**
26  * @author madamjak
27  *
28  */
29 public class OFDatagramPacketDecoderTest {
30     @Mock DeserializationFactory deserializationFactory;
31     @Mock ChannelHandlerContext ctx;
32     @Mock ByteBuf messageBufferMock;
33
34     private VersionMessageUdpWrapper msgWrapper;
35
36     @Before
37     public void startUp(){
38         MockitoAnnotations.initMocks(this);
39     }
40
41     @Test
42     public void test() {
43         OFDatagramPacketDecoder decoder = new OFDatagramPacketDecoder();
44         decoder.setDeserializationFactory(deserializationFactory);
45         msgWrapper = new VersionMessageUdpWrapper(EncodeConstants.OF13_VERSION_ID, messageBufferMock, new InetSocketAddress("10.0.0.1", 6653));
46         try {
47             decoder.channelRead0(ctx, msgWrapper);
48         } catch (Exception e) {
49             Assert.fail("Exception occured");
50         }
51         verify(messageBufferMock, times(1)).release();
52     }
53 }