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
9 package org.opendaylight.openflowplugin.extension.onf.converter;
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.path.MessagePath;
17 import org.opendaylight.openflowplugin.extension.onf.BundleTestUtils;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSal;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSalBuilder;
21 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;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleControlType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleFlags;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.common.grouping.BundleProperty;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.BundlePropertyExperimenter;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.bundle.property.experimenter.BundlePropertyExperimenterData;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControlOnf;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControlOnfBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.bundle.control.onf.OnfControlGroupingDataBuilder;
33 * Test for {@link org.opendaylight.openflowplugin.extension.onf.converter.BundleControlConverter}.
35 public class BundleControlConverterTest {
37 private final BundleControlConverter converter = new BundleControlConverter();
40 public void testGetExperimenterId() {
41 Assert.assertEquals("Wrong ExperimenterId.", new ExperimenterId(0x4F4E4600L), converter.getExperimenterId());
45 public void testGetType() {
46 Assert.assertEquals("Wrong type.", 2300, converter.getType());
50 public void testConvertDownWithProperty() {
51 testConvertDown(true);
55 public void testConvertDownWithoutProperty() {
56 testConvertDown(false);
60 public void testConvertUpWithProperty() {
65 public void testConvertUpWithoutProperty() {
69 private void testConvertDown(final boolean withProperty) {
70 final BundleControlSal original = createOFPMessage(withProperty);
71 final BundleControlOnf converted = converter.convert(original, null);
72 testConvert(original, converted, withProperty);
75 private void testConvertUp(final boolean withProperty) {
76 final BundleControlOnf original = createOFJMessage(withProperty);
77 final BundleControlSal converted = converter.convert(original, MessagePath.MESSAGE_NOTIFICATION);
78 testConvert(converted, original, withProperty);
81 private static void testConvert(final BundleControlSal ofpMessage,
82 final BundleControlOnf ofjMessage,
83 final boolean withProperty) {
84 Assert.assertEquals("Wrong BundleId",
86 ofpMessage.getSalControlData().getBundleId().getValue()),
87 ofjMessage.getOnfControlGroupingData().getBundleId()
89 Assert.assertEquals("Wrong type",
90 BundleControlType.forValue(
91 ofpMessage.getSalControlData().getType().getIntValue()),
92 ofjMessage.getOnfControlGroupingData().getType()
94 Assert.assertEquals("Wrong flags",
96 ofpMessage.getSalControlData().getFlags().isAtomic(),
97 ofpMessage.getSalControlData().getFlags().isOrdered()),
98 ofjMessage.getOnfControlGroupingData().getFlags()
101 final BundlePropertyExperimenter originalProperty = (BundlePropertyExperimenter) ofpMessage
105 .getBundlePropertyEntry();
106 final BundlePropertyExperimenter convertedProperty = (BundlePropertyExperimenter) ofjMessage
107 .getOnfControlGroupingData()
110 .getBundlePropertyEntry();
111 Assert.assertEquals("Wrong property ExperimenterId", new ExperimenterId(originalProperty.getExperimenter()),
112 convertedProperty.getExperimenter());
113 Assert.assertEquals("Wrong property experimenter type", originalProperty.getExpType(),
114 convertedProperty.getExpType());
115 Assert.assertEquals("Wrong property data", originalProperty.getBundlePropertyExperimenterData(),
116 convertedProperty.getBundlePropertyExperimenterData());
118 Assert.assertTrue("Properties not empty",
120 .getOnfControlGroupingData()
121 .nonnullBundleProperty()
126 private static BundleControlSal createOFPMessage(final boolean withProperty) {
127 final SalControlDataBuilder dataBuilder = new SalControlDataBuilder();
128 dataBuilder.setBundleId(new BundleId(1L));
129 dataBuilder.setType(BundleControlType.ONFBCTOPENREQUEST);
130 dataBuilder.setFlags(new BundleFlags(true, false));
131 List<BundleProperty> properties = new ArrayList<>();
133 properties.add(BundleTestUtils.createExperimenterProperty(
134 Mockito.mock(BundlePropertyExperimenterData.class)));
136 dataBuilder.setBundleProperty(properties);
137 return new BundleControlSalBuilder().setSalControlData(dataBuilder.build()).build();
140 private static BundleControlOnf createOFJMessage(final boolean withProperty) {
141 final BundleControlOnfBuilder builder = new BundleControlOnfBuilder();
142 final OnfControlGroupingDataBuilder dataBuilder = new OnfControlGroupingDataBuilder();
143 dataBuilder.setBundleId(new BundleId(1L));
144 dataBuilder.setType(BundleControlType.ONFBCTOPENREPLY);
145 dataBuilder.setFlags(new BundleFlags(false, false));
146 List<BundleProperty> properties = new ArrayList<>();
148 properties.add(BundleTestUtils.createExperimenterProperty(
149 Mockito.mock(BundlePropertyExperimenterData.class)));
151 dataBuilder.setBundleProperty(properties);
152 return new BundleControlOnfBuilder().setOnfControlGroupingData(dataBuilder.build()).build();