* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.openflowplugin.extension.onf.converter;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
-import org.opendaylight.openflowplugin.extension.onf.ConverterTestUtils;
+import org.mockito.Mockito;
+import org.opendaylight.openflowplugin.extension.api.ExtensionConvertorData;
+import org.opendaylight.openflowplugin.extension.api.path.MessagePath;
+import org.opendaylight.openflowplugin.extension.onf.BundleTestUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSal;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSalBuilder;
+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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleControlType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleFlags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundlePropertyType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.common.grouping.BundleProperty;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.common.grouping.BundlePropertyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.BundlePropertyExperimenter;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.BundlePropertyExperimenterBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.bundle.property.experimenter.BundlePropertyExperimenterData;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControlOnf;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControlOnfBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.bundle.control.onf.OnfControlGroupingDataBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
/**
* Test for {@link org.opendaylight.openflowplugin.extension.onf.converter.BundleControlConverter}.
@Test
public void testGetExperimenterId() {
- Assert.assertEquals("Wrong ExperimenterId.", new ExperimenterId(0x4F4E4600L), converter.getExperimenterId());
+ Assert.assertEquals("Wrong ExperimenterId.", new ExperimenterId(Uint32.valueOf(0x4F4E4600)),
+ converter.getExperimenterId());
}
@Test
}
@Test
- public void testConvertWithProperty() {
- final boolean withProperty = true;
- final org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControl original
- = createMessage(withProperty);
- final BundleControl converted = converter.convert(original);
- testConvert(original, converted, withProperty);
+ public void testConvertDownWithProperty() {
+ testConvertDown(true);
+ }
+
+ @Test
+ public void testConvertDownWithoutProperty() {
+ testConvertDown(false);
}
@Test
- public void testConvertWithoutProperty() {
- final boolean withProperty = false;
- final org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControl original
- = createMessage(withProperty);
- final BundleControl converted = converter.convert(original);
+ public void testConvertUpWithProperty() {
+ testConvertUp(true);
+ }
+
+ @Test
+ public void testConvertUpWithoutProperty() {
+ testConvertUp(true);
+ }
+
+ private void testConvertDown(final boolean withProperty) {
+ final BundleControlSal original = createOFPMessage(withProperty);
+ final ExtensionConvertorData data = new ExtensionConvertorData((short)1);
+ data.setXid(Uint32.valueOf(0L));
+ data.setDatapathId(Uint64.valueOf(BigInteger.ONE));
+ final BundleControlOnf converted = converter.convert(original, data);
testConvert(original, converted, withProperty);
}
- private static void testConvert(final org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControl original,
- final BundleControl converted, final boolean withProperty) {
- Assert.assertEquals("Wrong BundleId", new BundleId(original.getBundleId().getValue()), converted.getBundleId());
- Assert.assertEquals("Wrong type", BundleControlType.forValue(original.getType().getIntValue()), converted.getType());
- Assert.assertEquals("Wrong flags", new BundleFlags(original.getFlags().isAtomic(), original.getFlags().isOrdered()), converted.getFlags());
+ private void testConvertUp(final boolean withProperty) {
+ final BundleControlOnf original = createOFJMessage(withProperty);
+ final BundleControlSal converted = converter.convert(original, MessagePath.MESSAGE_NOTIFICATION);
+ testConvert(converted, original, withProperty);
+ }
+
+ private static void testConvert(final BundleControlSal ofpMessage,
+ final BundleControlOnf ofjMessage,
+ final boolean withProperty) {
+ Assert.assertEquals("Wrong BundleId",
+ new BundleId(
+ ofpMessage.getSalControlData().getBundleId().getValue()),
+ ofjMessage.getOnfControlGroupingData().getBundleId()
+ );
+ Assert.assertEquals("Wrong type",
+ BundleControlType.forValue(
+ ofpMessage.getSalControlData().getType().getIntValue()),
+ ofjMessage.getOnfControlGroupingData().getType()
+ );
+ Assert.assertEquals("Wrong flags",
+ new BundleFlags(
+ ofpMessage.getSalControlData().getFlags().getAtomic(),
+ ofpMessage.getSalControlData().getFlags().getOrdered()),
+ ofjMessage.getOnfControlGroupingData().getFlags()
+ );
if (withProperty) {
- final BundlePropertyExperimenter originalProperty = (BundlePropertyExperimenter) original.getBundleProperty().get(0).getBundlePropertyEntry();
- final BundlePropertyExperimenter convertedProperty = ((BundlePropertyExperimenter) converted.getBundleProperty().get(0).getBundlePropertyEntry());
- Assert.assertEquals("Wrong property ExperimenterId", new ExperimenterId(originalProperty.getExperimenter()), convertedProperty.getExperimenter());
- Assert.assertEquals("Wrong property experimenter type", originalProperty.getExpType(), convertedProperty.getExpType());
- Assert.assertEquals("Wrong property data", originalProperty.getBundlePropertyExperimenterData(), convertedProperty.getBundlePropertyExperimenterData());
+ final BundlePropertyExperimenter originalProperty = (BundlePropertyExperimenter) ofpMessage
+ .getSalControlData()
+ .getBundleProperty()
+ .get(0)
+ .getBundlePropertyEntry();
+ final BundlePropertyExperimenter convertedProperty = (BundlePropertyExperimenter) ofjMessage
+ .getOnfControlGroupingData()
+ .getBundleProperty()
+ .get(0)
+ .getBundlePropertyEntry();
+ Assert.assertEquals("Wrong property ExperimenterId", new ExperimenterId(originalProperty.getExperimenter()),
+ convertedProperty.getExperimenter());
+ Assert.assertEquals("Wrong property experimenter type", originalProperty.getExpType(),
+ convertedProperty.getExpType());
+ Assert.assertEquals("Wrong property data", originalProperty.getBundlePropertyExperimenterData(),
+ convertedProperty.getBundlePropertyExperimenterData());
} else {
- Assert.assertTrue("Properties not empty", converted.getBundleProperty().isEmpty());
+ Assert.assertTrue("Properties not empty",
+ ofjMessage
+ .getOnfControlGroupingData()
+ .nonnullBundleProperty()
+ .isEmpty());
}
}
- private static org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControl
- createMessage(final boolean withProperty) {
- final org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlBuilder builder
- = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlBuilder();
- builder.setBundleId(new BundleId(1L));
- builder.setType(BundleControlType.ONFBCTOPENREQUEST);
- builder.setFlags(new BundleFlags(true, false));
+ private static BundleControlSal createOFPMessage(final boolean withProperty) {
+ final SalControlDataBuilder dataBuilder = new SalControlDataBuilder();
+ dataBuilder.setBundleId(new BundleId(Uint32.ONE));
+ dataBuilder.setType(BundleControlType.ONFBCTOPENREQUEST);
+ dataBuilder.setFlags(new BundleFlags(true, false));
List<BundleProperty> properties = new ArrayList<>();
if (withProperty) {
- properties.add(ConverterTestUtils.createExperimenterProperty());
+ properties.add(BundleTestUtils.createExperimenterProperty(
+ Mockito.mock(BundlePropertyExperimenterData.class)));
}
- builder.setBundleProperty(properties);
- return builder.build();
+ dataBuilder.setBundleProperty(properties);
+ return new BundleControlSalBuilder().setSalControlData(dataBuilder.build()).build();
}
-
-
+ private static BundleControlOnf createOFJMessage(final boolean withProperty) {
+ final BundleControlOnfBuilder builder = new BundleControlOnfBuilder();
+ final OnfControlGroupingDataBuilder dataBuilder = new OnfControlGroupingDataBuilder();
+ dataBuilder.setBundleId(new BundleId(Uint32.ONE));
+ dataBuilder.setType(BundleControlType.ONFBCTOPENREPLY);
+ dataBuilder.setFlags(new BundleFlags(false, false));
+ List<BundleProperty> properties = new ArrayList<>();
+ if (withProperty) {
+ properties.add(BundleTestUtils.createExperimenterProperty(
+ Mockito.mock(BundlePropertyExperimenterData.class)));
+ }
+ dataBuilder.setBundleProperty(properties);
+ return new BundleControlOnfBuilder().setOnfControlGroupingData(dataBuilder.build()).build();
+ }
}