Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / openflowjava / openflowjava-util / src / test / java / org / opendaylight / openflowjava / util / ExperimenterSerializerKeyFactoryTest.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.util;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdMeterSubTypeSerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdSerializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterIdTypeSerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterMeterBandSubType;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties;
20 import org.opendaylight.yangtools.yang.common.Uint32;
21
22 /**
23  * Test ExperimenterSerializerKeyFactory key creation.
24  *
25  * @author michal.polkorab
26  */
27 public class ExperimenterSerializerKeyFactoryTest {
28
29     @Test
30     public void testCreateExperimenterMessageSerializerKey() {
31         ExperimenterIdSerializerKey<?> createdKey;
32         ExperimenterIdSerializerKey<?> comparationKey;
33
34         createdKey = ExperimenterSerializerKeyFactory
35                 .createExperimenterMessageSerializerKey(EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(42), 1L);
36         comparationKey = new ExperimenterIdTypeSerializerKey<>(EncodeConstants.OF_VERSION_1_0,
37                 Uint32.valueOf(42), 1L, ExperimenterDataOfChoice.class);
38         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
39     }
40
41     @Test
42     public void testCreateMultipartRequestSerializerKey() {
43         ExperimenterIdSerializerKey<?> createdKey;
44         ExperimenterIdSerializerKey<?> comparationKey;
45
46         createdKey = ExperimenterSerializerKeyFactory.createMultipartRequestSerializerKey(
47                 EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(44), 1L);
48         comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0,
49                 Uint32.valueOf(44), ExperimenterDataOfChoice.class);
50         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
51     }
52
53     @Test
54     public void testCreateMultipartRequestTFSerializerKey() {
55         ExperimenterIdSerializerKey<?> createdKey;
56         ExperimenterIdSerializerKey<?> comparationKey;
57
58         createdKey = ExperimenterSerializerKeyFactory.createMultipartRequestTFSerializerKey(
59                 EncodeConstants.OF_VERSION_1_0, Uint32.valueOf(45));
60         comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0,
61                 Uint32.valueOf(45), TableFeatureProperties.class);
62         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
63     }
64
65     @Test
66     public void testCreateMeterBandSerializerKey() {
67         ExperimenterIdSerializerKey<?> createdKey;
68         ExperimenterIdSerializerKey<?> comparationKey;
69
70         createdKey = ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(EncodeConstants.OF_VERSION_1_0,
71                 Uint32.valueOf(43));
72         comparationKey = new ExperimenterIdSerializerKey<>(EncodeConstants.OF_VERSION_1_0,
73                 Uint32.valueOf(43), MeterBandExperimenterCase.class);
74         Assert.assertEquals("Wrong key created", comparationKey, createdKey);
75     }
76
77     @Test
78     public void testCreateMeterBandSubTypeSerializerKey() {
79         final ExperimenterIdSerializerKey<?> createdKey;
80         final ExperimenterIdSerializerKey<?> comparationKey1;
81         final ExperimenterIdSerializerKey<?> comparationKey2;
82         final ExperimenterIdSerializerKey<?> comparationKey3;
83         final ExperimenterIdSerializerKey<?> comparationKey4;
84         final ExperimenterIdSerializerKey<?> comparationKey5;
85
86         createdKey = ExperimenterSerializerKeyFactory.createMeterBandSerializerKey(EncodeConstants.OF_VERSION_1_0,
87                 Uint32.valueOf(43), ExperimenterMeterBandSubType.VALUE);
88         comparationKey1 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF_VERSION_1_3,
89                 Uint32.valueOf(43), MeterBandExperimenterCase.class, ExperimenterMeterBandSubType.VALUE);
90         comparationKey2 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF_VERSION_1_0,
91                 Uint32.valueOf(42), MeterBandExperimenterCase.class, ExperimenterMeterBandSubType.VALUE);
92         comparationKey3 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF_VERSION_1_0,
93                 Uint32.valueOf(43), null, ExperimenterMeterBandSubType.VALUE);
94         comparationKey4 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF_VERSION_1_0,
95                 Uint32.valueOf(43), MeterBandExperimenterCase.class, null);
96         comparationKey5 = new ExperimenterIdMeterSubTypeSerializerKey<>(EncodeConstants.OF_VERSION_1_0,
97                 Uint32.valueOf(43), MeterBandExperimenterCase.class, ExperimenterMeterBandSubType.VALUE);
98         Assert.assertNotEquals("Wrong key created", comparationKey1, createdKey);
99         Assert.assertNotEquals("Wrong key created", comparationKey2, createdKey);
100         Assert.assertNotEquals("Wrong key created", comparationKey3, createdKey);
101         Assert.assertNotEquals("Wrong key created", comparationKey4, createdKey);
102         Assert.assertEquals("Wrong key created", comparationKey5, createdKey);
103     }
104 }