Factory tests back to stable
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / PortStatusMessageFactoryTest.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 \r
3 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
4 \r
5 import io.netty.buffer.ByteBuf;\r
6 \r
7 import org.junit.Assert;\r
8 import org.junit.Test;\r
9 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;\r
15 \r
16 /**\r
17  * @author timotej.kubas\r
18  * @author michal.polkorab\r
19  */\r
20 public class PortStatusMessageFactoryTest {\r
21 \r
22     /**\r
23      * Testing {@link PortStatusMessageFactory} for correct translation into POJO\r
24      */\r
25     @Test\r
26     public void test(){\r
27         ByteBuf bb = BufferHelper.buildBuffer("01 " + //reason \r
28                                               "00 00 00 00 00 00 00 " + //padding\r
29                                               "00 01 02 03 " + //port no\r
30                                               "00 00 00 00 " + //padding in ofp_port1\r
31                                               "08 00 27 00 B0 EB " + //mac address\r
32                                               "00 00 " + //padding in ofp_port2\r
33                                               "00 00 00 41 " + //port config\r
34                                               "00 00 00 05 " + //port state\r
35                                               "00 00 00 81 " + //current features\r
36                                               "00 00 00 81 " + //advertised features\r
37                                               "00 00 00 81 " + //supported features\r
38                                               "00 00 00 81 " + //peer features\r
39                                               "00 00 00 81 " + //curr speed\r
40                                               "00 00 00 80" //max speed\r
41                                               );\r
42         \r
43         PortStatusMessage builtByFactory = BufferHelper.decodeV13(PortStatusMessageFactory.getInstance(), bb);\r
44         \r
45         BufferHelper.checkHeaderV13(builtByFactory);\r
46         Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue());\r
47         Assert.assertEquals("Wrong portNumber", 66051L, builtByFactory.getPortNo().longValue());\r
48         Assert.assertEquals("Wrong macAddress", new MacAddress("08002700B0EB"), builtByFactory.getHwAddr());\r
49         Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig());\r
50         Assert.assertEquals("Wrong portState", new PortState(false, true, true), builtByFactory.getState());\r
51         Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false,\r
52                                              false, false, false, true, false, false, false, false, \r
53                                              false, false, false, false), builtByFactory.getCurrentFeatures());\r
54         Assert.assertEquals("Wrong advertisedFeatures", new PortFeatures(true, false, false, false,\r
55                                              false, false, false, true, false, false, false, false, \r
56                                              false, false, false, false), builtByFactory.getAdvertisedFeatures());\r
57         Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, false, false, false,\r
58                                              false, false, false, true, false, false, false, false, \r
59                                              false, false, false, false), builtByFactory.getSupportedFeatures());\r
60         Assert.assertEquals("Wrong peerFeatures", new PortFeatures(true, false, false, false,\r
61                                              false, false, false, true, false, false, false, false, \r
62                                              false, false, false, false), builtByFactory.getSupportedFeatures());\r
63         Assert.assertEquals("Wrong currSpeed", 129L, builtByFactory.getCurrSpeed().longValue());\r
64         Assert.assertEquals("Wrong maxSpeed", 128L, builtByFactory.getMaxSpeed().longValue());\r
65     }\r
66 }\r