43e6d37df2e9753878e21d1ff8f0a2c8b662cd8b
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / OF10ErrorMessageFactoryTest.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  */
21 public class OF10ErrorMessageFactoryTest {
22
23         /**
24      * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO
25      */
26         @Test
27         public void testWithoutData() {
28                 ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02");
29                 ErrorMessage builtByFactory = BufferHelper.decodeV10(
30                                 OF10ErrorMessageFactory.getInstance(), bb);
31
32                 BufferHelper.checkHeaderV10(builtByFactory);
33                 Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue());
34                 Assert.assertEquals("Wrong code", 2, builtByFactory.getCode().intValue());
35                 Assert.assertEquals("Wrong type string", "BADREQUEST", builtByFactory.getTypeString());
36                 Assert.assertEquals("Wrong code string", "BADSTAT", builtByFactory.getCodeString());
37                 Assert.assertNull("Data is not null", builtByFactory.getData());
38         }
39         
40         /**
41      * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO
42      */
43         @Test
44         public void testWithData() {
45                 ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03");
46                 ErrorMessage builtByFactory = BufferHelper.decodeV10(
47                                 OF10ErrorMessageFactory.getInstance(), bb);
48
49                 BufferHelper.checkHeaderV10(builtByFactory);
50                 Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue());
51                 Assert.assertEquals("Wrong code", 1, builtByFactory.getCode().intValue());
52                 Assert.assertEquals("Wrong type string", "HELLOFAILED", builtByFactory.getTypeString());
53                 Assert.assertEquals("Wrong code string", "EPERM", builtByFactory.getCodeString());
54                 Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
55         }
56         
57         /**
58      * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO
59      */
60         @Test
61         public void testWithIncorrectTypeEnum() {
62                 ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 05 00 01 02 03");
63                 ErrorMessage builtByFactory = BufferHelper.decodeV10(
64                                 OF10ErrorMessageFactory.getInstance(), bb);
65
66                 BufferHelper.checkHeaderV10(builtByFactory);
67                 Assert.assertEquals("Wrong type", 10, builtByFactory.getType().intValue());
68                 Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue());
69                 Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString());
70                 Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
71                 Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
72         }
73         
74         /**
75      * Test of {@link OF10ErrorMessageFactory} for correct translation into POJO
76      */
77         @Test
78         public void testWithIncorrectCodeEnum() {
79                 ByteBuf bb = BufferHelper.buildBuffer("00 03 00 06 00 01 02 03");
80                 ErrorMessage builtByFactory = BufferHelper.decodeV10(
81                                 OF10ErrorMessageFactory.getInstance(), bb);
82
83                 BufferHelper.checkHeaderV10(builtByFactory);
84                 Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue());
85                 Assert.assertEquals("Wrong code", 6, builtByFactory.getCode().intValue());
86                 Assert.assertEquals("Wrong type string", "FLOWMODFAILED", builtByFactory.getTypeString());
87                 Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
88                 Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
89         }
90
91 }