Update bundle extension tests
[openflowplugin.git] / extension / openflowplugin-extension-onf / src / test / java / org / opendaylight / openflowplugin / extension / onf / converter / BundleControlConverterTest.java
1 /*
2  * Copyright (c) 2017 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.openflowplugin.extension.onf.converter;
10
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.onf.BundleTestUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleControlType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleFlags;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.BundleId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.common.grouping.BundleProperty;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.BundlePropertyExperimenter;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.bundle.property.grouping.bundle.property.entry.bundle.property.experimenter.BundlePropertyExperimenterData;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.rev170124.experimenter.input.experimenter.data.of.choice.BundleControl;
25
26 /**
27  * Test for {@link org.opendaylight.openflowplugin.extension.onf.converter.BundleControlConverter}.
28  */
29 public class BundleControlConverterTest {
30
31     private final BundleControlConverter converter = new BundleControlConverter();
32
33     @Test
34     public void testGetExperimenterId() {
35         Assert.assertEquals("Wrong ExperimenterId.", new ExperimenterId(0x4F4E4600L), converter.getExperimenterId());
36     }
37
38     @Test
39     public void testGetType() {
40         Assert.assertEquals("Wrong type.", 2300, converter.getType());
41     }
42
43     @Test
44     public void testConvertWithProperty() {
45         testConvert(true);
46     }
47
48     @Test
49     public void testConvertWithoutProperty() {
50         testConvert(false);
51     }
52
53     private void testConvert(final boolean withProperty) {
54         final org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControl original
55                 = createMessage(withProperty);
56         final BundleControl converted = converter.convert(original);
57         testConvert(original, converted, withProperty);
58     }
59
60     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,
61                                     final BundleControl converted, final boolean withProperty) {
62         Assert.assertEquals("Wrong BundleId", new BundleId(original.getBundleId().getValue()), converted.getBundleId());
63         Assert.assertEquals("Wrong type", BundleControlType.forValue(original.getType().getIntValue()), converted.getType());
64         Assert.assertEquals("Wrong flags", new BundleFlags(original.getFlags().isAtomic(), original.getFlags().isOrdered()), converted.getFlags());
65         if (withProperty) {
66             final BundlePropertyExperimenter originalProperty = (BundlePropertyExperimenter) original.getBundleProperty().get(0).getBundlePropertyEntry();
67             final BundlePropertyExperimenter convertedProperty = ((BundlePropertyExperimenter) converted.getBundleProperty().get(0).getBundlePropertyEntry());
68             Assert.assertEquals("Wrong property ExperimenterId", new ExperimenterId(originalProperty.getExperimenter()), convertedProperty.getExperimenter());
69             Assert.assertEquals("Wrong property experimenter type", originalProperty.getExpType(), convertedProperty.getExpType());
70             Assert.assertEquals("Wrong property data", originalProperty.getBundlePropertyExperimenterData(), convertedProperty.getBundlePropertyExperimenterData());
71         } else {
72             Assert.assertTrue("Properties not empty", converted.getBundleProperty().isEmpty());
73         }
74     }
75
76     private static org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControl
77                     createMessage(final boolean withProperty) {
78         final org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlBuilder builder
79                 = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlBuilder();
80         builder.setBundleId(new BundleId(1L));
81         builder.setType(BundleControlType.ONFBCTOPENREQUEST);
82         builder.setFlags(new BundleFlags(true, false));
83         List<BundleProperty> properties = new ArrayList<>();
84         if (withProperty) {
85             properties.add(BundleTestUtils.createExperimenterProperty(Mockito.mock(BundlePropertyExperimenterData.class)));
86         }
87         builder.setBundleProperty(properties);
88         return builder.build();
89     }
90
91 }