Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / NspConvertorTest.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.nsp.grouping.NspValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NspCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NspCaseValueBuilder;
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.NxmNxNspKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsp.grouping.NxmNxNspBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
35
36 /**
37  * Test for {@link NspConvertor}.
38  */
39 @RunWith(MockitoJUnitRunner.class)
40 public class NspConvertorTest {
41     @Mock
42     private Extension extension;
43     @Mock
44     private MatchEntry matchEntry;
45
46     private NspConvertor nspConvertor;
47
48     @Before
49     public void setUp() throws Exception {
50         final NxmNxNspBuilder nxmNxNspBuilder = new NxmNxNspBuilder()
51                 .setValue(Long.valueOf(1L));
52         final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
53                 new NxAugMatchNodesNodeTableFlowBuilder();
54         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNsp(nxmNxNspBuilder.build());
55
56         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
57         when(extension.augmentation(Matchers.<Class<Augmentation<Extension>>>any()))
58             .thenReturn(extensionAugmentation);
59
60         nspConvertor = new NspConvertor();
61     }
62
63     @Test
64     public void testConvert() throws Exception {
65         final MatchEntry converted = nspConvertor.convert(extension);
66         Assert.assertEquals(1, ((NspCaseValue)converted.getMatchEntryValue()).getNspValues().getNsp().intValue());
67     }
68
69     @Test
70     public void testConvert1() throws Exception {
71         final NspValuesBuilder nspValuesBuilder = new NspValuesBuilder()
72                 .setNsp(Long.valueOf(2L));
73         final NspCaseValueBuilder nspCaseValueBuilder = new NspCaseValueBuilder()
74                 .setNspValues(nspValuesBuilder.build());
75
76         final NspCaseValue nspCaseValue = nspCaseValueBuilder.build();
77
78         when(matchEntry.getMatchEntryValue()).thenReturn(nspCaseValue);
79
80         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nspConvertor.convert(matchEntry,
81                 MatchPath.PACKET_RECEIVED_MATCH);
82         Assert.assertEquals(2, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxNsp()
83                 .getValue().longValue());
84         Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
85
86         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nspConvertor.convert(matchEntry,
87                 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
88         Assert.assertEquals(2, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
89                 .getNxmNxNsp().getValue().longValue());
90         Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
91
92         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nspConvertor.convert(matchEntry,
93                 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
94         Assert.assertEquals(2, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxNsp()
95                 .getValue().longValue());
96         Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
97
98         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = nspConvertor.convert(matchEntry,
99                 MatchPath.FLOWS_STATISTICS_RPC_MATCH);
100         Assert.assertEquals(2, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxNsp()
101                 .getValue().longValue());
102         Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
103     }
104 }