Copyright update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / ErrorMessageFactoryTest.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.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
17
18 /**
19  * @author michal.polkorab
20  * @author timotej.kubas
21  */
22 public class ErrorMessageFactoryTest {
23
24     /**
25      * Test of {@link ErrorMessageFactory} for correct translation into POJO
26      */
27     @Test
28     public void testWithoutData() {
29         ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02");
30         ErrorMessage builtByFactory = BufferHelper.decodeV13(
31                 ErrorMessageFactory.getInstance(), bb);
32
33         BufferHelper.checkHeaderV13(builtByFactory);
34         Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue());
35         Assert.assertEquals("Wrong code", 2, builtByFactory.getCode().intValue());
36         Assert.assertEquals("Wrong type string", "BADREQUEST", builtByFactory.getTypeString());
37         Assert.assertEquals("Wrong code string", "BADMULTIPART", builtByFactory.getCodeString());
38         Assert.assertNull("Data is not null", builtByFactory.getData());
39     }
40     
41     /**
42      * Test of {@link ErrorMessageFactory} for correct translation into POJO
43      */
44     @Test
45     public void testWithData() {
46         ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03");
47         ErrorMessage builtByFactory = BufferHelper.decodeV13(
48                 ErrorMessageFactory.getInstance(), bb);
49
50         BufferHelper.checkHeaderV13(builtByFactory);
51         Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue());
52         Assert.assertEquals("Wrong code", 1, builtByFactory.getCode().intValue());
53         Assert.assertEquals("Wrong type string", "HELLOFAILED", builtByFactory.getTypeString());
54         Assert.assertEquals("Wrong code string", "EPERM", builtByFactory.getCodeString());
55         Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
56     }
57     
58     /**
59      * Test of {@link ErrorMessageFactory} for correct translation into POJO
60      */
61     @Test
62     public void testWithIncorrectTypeEnum() {
63         ByteBuf bb = BufferHelper.buildBuffer("00 20 00 05 00 01 02 03");
64         ErrorMessage builtByFactory = BufferHelper.decodeV13(
65                 ErrorMessageFactory.getInstance(), bb);
66
67         BufferHelper.checkHeaderV13(builtByFactory);
68         Assert.assertEquals("Wrong type", 32, builtByFactory.getType().intValue());
69         Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue());
70         Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString());
71         Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
72         Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
73     }
74     
75     /**
76      * Test of {@link ErrorMessageFactory} for correct translation into POJO
77      */
78     @Test
79     public void testWithIncorrectCodeEnum() {
80         ByteBuf bb = BufferHelper.buildBuffer("00 03 00 10 00 01 02 03");
81         ErrorMessage builtByFactory = BufferHelper.decodeV13(
82                 ErrorMessageFactory.getInstance(), bb);
83
84         BufferHelper.checkHeaderV13(builtByFactory);
85         Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue());
86         Assert.assertEquals("Wrong code", 16, builtByFactory.getCode().intValue());
87         Assert.assertEquals("Wrong type string", "BADINSTRUCTION", builtByFactory.getTypeString());
88         Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
89         Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
90     }
91 }