Update MRI projects for Aluminium
[openflowplugin.git] / extension / openflowplugin-extension-eric / src / test / java / org / opendaylight / openflowplugin / extension / vendor / eric / convertor / match / Icmpv6NDOptionsTypeConvertorTest.java
1 /*
2  * Copyright (c) 2019 Ericsson India Global Services Pvt Ltd. 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.vendor.eric.convertor.match;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.when;
13
14 import java.util.Collections;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Matchers;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
23 import org.opendaylight.openflowplugin.extension.api.GroupingLooseResolver;
24 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetField;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.icmpv6.nd.options.type.grouping.Icmpv6NdOptionsTypeValuesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdOptionsTypeCaseValue;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdOptionsTypeCaseValueBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlow;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlowBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifPacketIn;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifSwitchFlowRemoved;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchRpcGetFlowStats;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.Icmpv6NdOptionsTypeKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.eric.of.icmpv6.nd.options.type.grouping.EricOfIcmpv6NdOptionsTypeBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetField;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionListGrouping;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
44 import org.opendaylight.yangtools.yang.binding.Augmentation;
45
46 /**
47  * Test for {@link Icmpv6NDOptionsTypeConvertor}.
48  */
49 @RunWith(MockitoJUnitRunner.class)
50 public class Icmpv6NDOptionsTypeConvertorTest {
51
52     @Mock
53     private Extension extension;
54     @Mock
55     private MatchEntry matchEntry;
56
57     private Icmpv6NDOptionsTypeConvertor icmpv6NDOptionsTypeConvertor;
58
59     @Before
60     public void setUp()  {
61         final EricOfIcmpv6NdOptionsTypeBuilder ericOfIcmpv6NdOptionsTypeBuilder = new EricOfIcmpv6NdOptionsTypeBuilder()
62                 .setIcmpv6NdOptionsType((short)1);
63         final EricAugMatchNodesNodeTableFlowBuilder ericAugMatchNotifUpdateFlowStatsBuilder =
64                 new EricAugMatchNodesNodeTableFlowBuilder();
65         ericAugMatchNotifUpdateFlowStatsBuilder.setEricOfIcmpv6NdOptionsType(ericOfIcmpv6NdOptionsTypeBuilder.build());
66
67         final Augmentation<Extension> extensionAugmentation = ericAugMatchNotifUpdateFlowStatsBuilder.build();
68         when(extension.augmentation(Matchers.any()))
69                 .thenReturn(extensionAugmentation);
70
71         icmpv6NDOptionsTypeConvertor = new Icmpv6NDOptionsTypeConvertor();
72     }
73
74     @Test
75     public void testConvert()  {
76         final MatchEntry converted = icmpv6NDOptionsTypeConvertor.convert(extension);
77         assertEquals(1, ((Icmpv6NdOptionsTypeCaseValue)converted.getMatchEntryValue())
78                 .getIcmpv6NdOptionsTypeValues().getIcmpv6NdOptionsType().intValue());
79     }
80
81     @Test
82     public void testConvert1()  {
83         final Icmpv6NdOptionsTypeValuesBuilder icmpv6NdOptionsTypeValuesBuilder = new Icmpv6NdOptionsTypeValuesBuilder()
84                 .setIcmpv6NdOptionsType((short)10);
85         final Icmpv6NdOptionsTypeCaseValueBuilder icmpv6NdOptionsTypeCaseValueBuilder
86                 = new Icmpv6NdOptionsTypeCaseValueBuilder()
87                 .setIcmpv6NdOptionsTypeValues(icmpv6NdOptionsTypeValuesBuilder.build());
88
89         final Icmpv6NdOptionsTypeCaseValue icmpv6NdOptionsTypeCaseValue = icmpv6NdOptionsTypeCaseValueBuilder.build();
90         when(matchEntry.getMatchEntryValue()).thenReturn(icmpv6NdOptionsTypeCaseValue);
91
92         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment
93                 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.PACKET_RECEIVED_MATCH);
94         assertEquals(10, ((EricAugMatchNotifPacketIn) extensionAugment.getAugmentationObject())
95                 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
96         assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
97
98         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1
99                 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
100         assertEquals(10, ((EricAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
101                 .getEricOfIcmpv6NdOptionsType() .getIcmpv6NdOptionsType().intValue());
102         assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
103
104         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2
105                 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
106         assertEquals(10, ((EricAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
107                 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
108         assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
109
110         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3
111                 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
112         assertEquals(10, ((EricAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
113                 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
114         assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
115     }
116
117     @Test
118     public void testSetFieldExtension()  {
119         GroupingLooseResolver<GeneralExtensionListGrouping> eqGroup =
120                 new GroupingLooseResolver<>(GeneralExtensionListGrouping.class);
121         eqGroup.add(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class);
122
123         ExtensionAugment<? extends Augmentation<Extension>> extensionMatch
124                 =  new ExtensionAugment<>(EricAugMatchNodesNodeTableFlow.class,
125                 new EricAugMatchNodesNodeTableFlowBuilder().setEricOfIcmpv6NdOptionsType(
126                         new EricOfIcmpv6NdOptionsTypeBuilder().setIcmpv6NdOptionsType((short)1).build()).build(),
127                 Icmpv6NdOptionsTypeKey.class);
128
129         ExtensionListBuilder extListBld = null;
130         ExtensionBuilder extBld = new ExtensionBuilder();
131         extBld.addAugmentation(extensionMatch.getAugmentationClass(), extensionMatch.getAugmentationObject());
132
133         extListBld = new ExtensionListBuilder();
134         extListBld.setExtension(extBld.build());
135         extListBld.setExtensionKey(extensionMatch.getKey());
136
137         GeneralAugMatchNodesNodeTableFlowWriteActionsSetField ndOptionsTypeSetField =
138                  new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
139                          .setExtensionList(Collections.singletonList(extListBld.build())).build();
140
141         SetFieldBuilder sb = new SetFieldBuilder();
142         SetField setField = sb.addAugmentation(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class,
143                  ndOptionsTypeSetField).build();
144
145         Assert.assertEquals(Icmpv6NdOptionsTypeKey.class, eqGroup.getExtension(setField).get().nonnullExtensionList()
146                  .values().iterator().next().getExtensionKey());
147     }
148
149 }