Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / Nshc2ConvertorTest.java
1 /**
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.nicira.convertor.match;
10
11 import static org.mockito.Mockito.when;
12
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Matchers;
18 import org.mockito.Mock;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
21 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nshc._2.grouping.Nshc2ValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc2CaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc2CaseValueBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNshc2Key;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._2.grouping.NxmNxNshc2Builder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
35
36 /**
37  * Test for {@link Nshc2Convertor}.
38  */
39 @RunWith(MockitoJUnitRunner.class)
40 public class Nshc2ConvertorTest {
41     @Mock
42     private Extension extension;
43     @Mock
44     private MatchEntry matchEntry;
45
46     private Nshc2Convertor nshc2Convertor;
47
48     @Before
49     public void setUp() throws Exception {
50         final NxmNxNshc2Builder nxmNxNshc2Builder = new NxmNxNshc2Builder()
51                 .setValue(1L);
52         final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
53                 new NxAugMatchNodesNodeTableFlowBuilder();
54         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNshc2(nxmNxNshc2Builder.build());
55
56         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
57         when(extension.augmentation(Matchers.<Class<Augmentation<Extension>>>any()))
58             .thenReturn(extensionAugmentation);
59
60         nshc2Convertor = new Nshc2Convertor();
61     }
62
63     @Test
64     public void testConvert() throws Exception {
65         final MatchEntry converted = nshc2Convertor.convert(extension);
66         Assert.assertEquals(1, ((Nshc2CaseValue)converted.getMatchEntryValue()).getNshc2Values().getNshc().intValue());
67     }
68
69     @Test
70     public void testConvert1() throws Exception {
71         final Nshc2ValuesBuilder nshc2ValuesBuilder = new Nshc2ValuesBuilder()
72                 .setNshc(Long.valueOf(1));
73         final Nshc2CaseValueBuilder nshc2CaseValueBuilder = new Nshc2CaseValueBuilder()
74                 .setNshc2Values(nshc2ValuesBuilder.build());
75
76         final Nshc2CaseValue nshc2CaseValue = nshc2CaseValueBuilder.build();
77
78         when(matchEntry.getMatchEntryValue()).thenReturn(nshc2CaseValue);
79
80         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nshc2Convertor.convert(matchEntry,
81                 MatchPath.PACKET_RECEIVED_MATCH);
82         Assert.assertEquals(1, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxNshc2()
83                 .getValue().intValue());
84         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
85
86         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nshc2Convertor.convert(matchEntry,
87                 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
88         Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
89                 .getNxmNxNshc2().getValue().intValue());
90         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
91
92         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nshc2Convertor.convert(matchEntry,
93                 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
94         Assert.assertEquals(1, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
95                 .getNxmNxNshc2().getValue().intValue());
96         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
97
98         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = nshc2Convertor.convert(matchEntry,
99                 MatchPath.FLOWS_STATISTICS_RPC_MATCH);
100         Assert.assertEquals(1, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxNshc2()
101                 .getValue().intValue());
102         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
103     }
104 }