2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.extension.onf.converter;
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.openflowplugin.extension.api.ExtensionConvertorData;
17 import org.opendaylight.openflowplugin.extension.api.path.MessagePath;
18 import org.opendaylight.openflowplugin.extension.onf.BundleTestUtils;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSal;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSalBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.bundle.control.sal.SalControlDataBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleControlType;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleFlags;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleId;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.common.grouping.BundleProperty;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.BundlePropertyExperimenter;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.bundle.property.experimenter.BundlePropertyExperimenterData;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControlOnf;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControlOnfBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.bundle.control.onf.OnfControlGroupingDataBuilder;
32 import org.opendaylight.yangtools.yang.common.Uint32;
33 import org.opendaylight.yangtools.yang.common.Uint64;
36 * Test for {@link org.opendaylight.openflowplugin.extension.onf.converter.BundleControlConverter}.
38 public class BundleControlConverterTest {
40 private final BundleControlConverter converter = new BundleControlConverter();
43 public void testGetExperimenterId() {
44 Assert.assertEquals("Wrong ExperimenterId.", new ExperimenterId(Uint32.valueOf(0x4F4E4600)),
45 converter.getExperimenterId());
49 public void testGetType() {
50 Assert.assertEquals("Wrong type.", 2300, converter.getType());
54 public void testConvertDownWithProperty() {
55 testConvertDown(true);
59 public void testConvertDownWithoutProperty() {
60 testConvertDown(false);
64 public void testConvertUpWithProperty() {
69 public void testConvertUpWithoutProperty() {
73 private void testConvertDown(final boolean withProperty) {
74 final BundleControlSal original = createOFPMessage(withProperty);
75 final ExtensionConvertorData data = new ExtensionConvertorData((short)1);
76 data.setXid(Uint32.valueOf(0L));
77 data.setDatapathId(Uint64.valueOf(BigInteger.ONE));
78 final BundleControlOnf converted = converter.convert(original, data);
79 testConvert(original, converted, withProperty);
82 private void testConvertUp(final boolean withProperty) {
83 final BundleControlOnf original = createOFJMessage(withProperty);
84 final BundleControlSal converted = converter.convert(original, MessagePath.MESSAGE_NOTIFICATION);
85 testConvert(converted, original, withProperty);
88 private static void testConvert(final BundleControlSal ofpMessage,
89 final BundleControlOnf ofjMessage,
90 final boolean withProperty) {
91 Assert.assertEquals("Wrong BundleId",
93 ofpMessage.getSalControlData().getBundleId().getValue()),
94 ofjMessage.getOnfControlGroupingData().getBundleId()
96 Assert.assertEquals("Wrong type",
97 BundleControlType.forValue(
98 ofpMessage.getSalControlData().getType().getIntValue()),
99 ofjMessage.getOnfControlGroupingData().getType()
101 Assert.assertEquals("Wrong flags",
103 ofpMessage.getSalControlData().getFlags().isAtomic(),
104 ofpMessage.getSalControlData().getFlags().isOrdered()),
105 ofjMessage.getOnfControlGroupingData().getFlags()
108 final BundlePropertyExperimenter originalProperty = (BundlePropertyExperimenter) ofpMessage
112 .getBundlePropertyEntry();
113 final BundlePropertyExperimenter convertedProperty = (BundlePropertyExperimenter) ofjMessage
114 .getOnfControlGroupingData()
117 .getBundlePropertyEntry();
118 Assert.assertEquals("Wrong property ExperimenterId", new ExperimenterId(originalProperty.getExperimenter()),
119 convertedProperty.getExperimenter());
120 Assert.assertEquals("Wrong property experimenter type", originalProperty.getExpType(),
121 convertedProperty.getExpType());
122 Assert.assertEquals("Wrong property data", originalProperty.getBundlePropertyExperimenterData(),
123 convertedProperty.getBundlePropertyExperimenterData());
125 Assert.assertTrue("Properties not empty",
127 .getOnfControlGroupingData()
128 .nonnullBundleProperty()
133 private static BundleControlSal createOFPMessage(final boolean withProperty) {
134 final SalControlDataBuilder dataBuilder = new SalControlDataBuilder();
135 dataBuilder.setBundleId(new BundleId(Uint32.ONE));
136 dataBuilder.setType(BundleControlType.ONFBCTOPENREQUEST);
137 dataBuilder.setFlags(new BundleFlags(true, false));
138 List<BundleProperty> properties = new ArrayList<>();
140 properties.add(BundleTestUtils.createExperimenterProperty(
141 Mockito.mock(BundlePropertyExperimenterData.class)));
143 dataBuilder.setBundleProperty(properties);
144 return new BundleControlSalBuilder().setSalControlData(dataBuilder.build()).build();
147 private static BundleControlOnf createOFJMessage(final boolean withProperty) {
148 final BundleControlOnfBuilder builder = new BundleControlOnfBuilder();
149 final OnfControlGroupingDataBuilder dataBuilder = new OnfControlGroupingDataBuilder();
150 dataBuilder.setBundleId(new BundleId(Uint32.ONE));
151 dataBuilder.setType(BundleControlType.ONFBCTOPENREPLY);
152 dataBuilder.setFlags(new BundleFlags(false, false));
153 List<BundleProperty> properties = new ArrayList<>();
155 properties.add(BundleTestUtils.createExperimenterProperty(
156 Mockito.mock(BundlePropertyExperimenterData.class)));
158 dataBuilder.setBundleProperty(properties);
159 return new BundleControlOnfBuilder().setOnfControlGroupingData(dataBuilder.build()).build();