Merge "OPNFLWPLUG-929 : Remove deprecated guava library"
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / FeaturesReplyMessageFactoryTest.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 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
23
24 /**
25  * Unit tests for FeaturesReplyMessageFactory.
26  *
27  * @author michal.polkorab
28  * @author timotej.kubas
29  */
30 public class FeaturesReplyMessageFactoryTest {
31
32     private OFDeserializer<GetFeaturesOutput> featuresFactory;
33
34     /**
35      * Initializes deserializer registry and lookups correct deserializer.
36      */
37     @Before
38     public void startUp() {
39         DeserializerRegistry registry = new DeserializerRegistryImpl();
40         registry.init();
41         featuresFactory = registry.getDeserializer(
42                 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 6, GetFeaturesOutput.class));
43     }
44
45     /**
46      * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO.
47      */
48     @Test
49     public void test() {
50         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"
51                 + " 00 00 00 00 01 02 03");
52         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
53
54         BufferHelper.checkHeaderV13(builtByFactory);
55         Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());
56         Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue());
57         Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue());
58         Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue());
59         Assert.assertEquals("Wrong capabilities", new Capabilities(false, false, false, false, false, false, false),
60                 builtByFactory.getCapabilities());
61         Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue());
62     }
63
64     /**
65      * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO
66      * (capabilities set).
67      */
68     @Test
69     public void testCapabilities() {
70         ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"
71                 + " 00 01 6F 00 01 02 03");
72         GetFeaturesOutput builtByFactory = BufferHelper.deserialize(featuresFactory, bb);
73
74         BufferHelper.checkHeaderV13(builtByFactory);
75         Assert.assertEquals("Wrong capabilities", new Capabilities(true, true, true, true, true, true, true),
76                 builtByFactory.getCapabilities());
77     }
78 }