Migrate users of Optional.get()
[openflowplugin.git] / extension / openflowplugin-extension-eric / src / test / java / org / opendaylight / openflowplugin / extension / vendor / eric / convertor / match / Icmpv6NDOptionsTypeConvertorTest.java
index 05b3b3d20a49520dcefcc31981b68dcb3b3a20fd..d786ac2b5d43de3c5e2affab3807d2bffc8db06d 100644 (file)
@@ -5,20 +5,17 @@
  * 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.vendor.eric.convertor.match;
 
 import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
-import java.util.Collections;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.Matchers;
 import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
 import org.opendaylight.openflowplugin.extension.api.GroupingLooseResolver;
 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
@@ -26,8 +23,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.icmpv6.nd.options.type.grouping.Icmpv6NdOptionsTypeValuesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdOptionsTypeCaseValue;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.oxm.container.match.entry.value.Icmpv6NdOptionsTypeCaseValueBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.ofj.aug.eric.match.options.Icmpv6NdOptionsTypeCaseValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.eric.match.rev180730.ofj.aug.eric.match.options.Icmpv6NdOptionsTypeCaseValueBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNodesNodeTableFlowBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.eric.match.rev180730.EricAugMatchNotifPacketIn;
@@ -42,6 +39,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.ge
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 /**
  * Test for {@link Icmpv6NDOptionsTypeConvertor}.
@@ -59,13 +58,13 @@ public class Icmpv6NDOptionsTypeConvertorTest {
     @Before
     public void setUp()  {
         final EricOfIcmpv6NdOptionsTypeBuilder ericOfIcmpv6NdOptionsTypeBuilder = new EricOfIcmpv6NdOptionsTypeBuilder()
-                .setIcmpv6NdOptionsType((short)1);
+                .setIcmpv6NdOptionsType(Uint8.ONE);
         final EricAugMatchNodesNodeTableFlowBuilder ericAugMatchNotifUpdateFlowStatsBuilder =
                 new EricAugMatchNodesNodeTableFlowBuilder();
         ericAugMatchNotifUpdateFlowStatsBuilder.setEricOfIcmpv6NdOptionsType(ericOfIcmpv6NdOptionsTypeBuilder.build());
 
         final Augmentation<Extension> extensionAugmentation = ericAugMatchNotifUpdateFlowStatsBuilder.build();
-        when(extension.augmentation(Matchers.any()))
+        when(extension.augmentation(any()))
                 .thenReturn(extensionAugmentation);
 
         icmpv6NDOptionsTypeConvertor = new Icmpv6NDOptionsTypeConvertor();
@@ -81,7 +80,7 @@ public class Icmpv6NDOptionsTypeConvertorTest {
     @Test
     public void testConvert1()  {
         final Icmpv6NdOptionsTypeValuesBuilder icmpv6NdOptionsTypeValuesBuilder = new Icmpv6NdOptionsTypeValuesBuilder()
-                .setIcmpv6NdOptionsType((short)10);
+                .setIcmpv6NdOptionsType(Uint8.TEN);
         final Icmpv6NdOptionsTypeCaseValueBuilder icmpv6NdOptionsTypeCaseValueBuilder
                 = new Icmpv6NdOptionsTypeCaseValueBuilder()
                 .setIcmpv6NdOptionsTypeValues(icmpv6NdOptionsTypeValuesBuilder.build());
@@ -93,25 +92,25 @@ public class Icmpv6NDOptionsTypeConvertorTest {
                 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.PACKET_RECEIVED_MATCH);
         assertEquals(10, ((EricAugMatchNotifPacketIn) extensionAugment.getAugmentationObject())
                 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
-        assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
+        assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.VALUE);
 
         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1
                 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
         assertEquals(10, ((EricAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
                 .getEricOfIcmpv6NdOptionsType() .getIcmpv6NdOptionsType().intValue());
-        assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
+        assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.VALUE);
 
         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2
                 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
         assertEquals(10, ((EricAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
                 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
-        assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
+        assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.VALUE);
 
         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3
                 = icmpv6NDOptionsTypeConvertor.convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
         assertEquals(10, ((EricAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject())
                 .getEricOfIcmpv6NdOptionsType().getIcmpv6NdOptionsType().intValue());
-        assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.class);
+        assertEquals(extensionAugment.getKey(), Icmpv6NdOptionsTypeKey.VALUE);
     }
 
     @Test
@@ -120,30 +119,26 @@ public class Icmpv6NDOptionsTypeConvertorTest {
                 new GroupingLooseResolver<>(GeneralExtensionListGrouping.class);
         eqGroup.add(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class);
 
-        ExtensionAugment<? extends Augmentation<Extension>> extensionMatch
-                =  new ExtensionAugment<>(EricAugMatchNodesNodeTableFlow.class,
+        ExtensionAugment<? extends Augmentation<Extension>> extensionMatch =
+            new ExtensionAugment<>(EricAugMatchNodesNodeTableFlow.class,
                 new EricAugMatchNodesNodeTableFlowBuilder().setEricOfIcmpv6NdOptionsType(
-                        new EricOfIcmpv6NdOptionsTypeBuilder().setIcmpv6NdOptionsType((short)1).build()).build(),
-                Icmpv6NdOptionsTypeKey.class);
+                    new EricOfIcmpv6NdOptionsTypeBuilder().setIcmpv6NdOptionsType(Uint8.ONE).build()).build(),
+                Icmpv6NdOptionsTypeKey.VALUE);
 
         ExtensionListBuilder extListBld = null;
         ExtensionBuilder extBld = new ExtensionBuilder();
-        extBld.addAugmentation(extensionMatch.getAugmentationClass(), extensionMatch.getAugmentationObject());
+        extBld.addAugmentation(extensionMatch.getAugmentationObject());
 
         extListBld = new ExtensionListBuilder();
         extListBld.setExtension(extBld.build());
         extListBld.setExtensionKey(extensionMatch.getKey());
 
-        GeneralAugMatchNodesNodeTableFlowWriteActionsSetField ndOptionsTypeSetField =
-                 new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
-                         .setExtensionList(Collections.singletonList(extListBld.build())).build();
-
-        SetFieldBuilder sb = new SetFieldBuilder();
-        SetField setField = sb.addAugmentation(GeneralAugMatchNodesNodeTableFlowWriteActionsSetField.class,
-                 ndOptionsTypeSetField).build();
+        SetField setField = new SetFieldBuilder()
+                .addAugmentation(new GeneralAugMatchNodesNodeTableFlowWriteActionsSetFieldBuilder()
+                    .setExtensionList(BindingMap.of(extListBld.build())).build())
+                .build();
 
-        Assert.assertEquals(Icmpv6NdOptionsTypeKey.class, eqGroup.getExtension(setField).get().getExtensionList().get(0)
-                 .getExtensionKey());
+        assertEquals(Icmpv6NdOptionsTypeKey.VALUE, eqGroup.getExtension(setField).orElseThrow()
+            .nonnullExtensionList().values().iterator().next().getExtensionKey());
     }
-
-}
\ No newline at end of file
+}