Merge "Bug 5543 - Bo: Update JUnit tests part_8"
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / NsiConvertorTest.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.nsi.grouping.NsiValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NsiCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.NsiCaseValueBuilder;
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.NxAugMatchNotifPacketIn;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxNsiKey;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nsi.grouping.NxmNxNsiBuilder;
33 import org.opendaylight.yangtools.yang.binding.Augmentation;
34
35 /**
36  * Test for {@link NsiConvertor}.
37  */
38 @RunWith(MockitoJUnitRunner.class)
39 public class NsiConvertorTest {
40     @Mock
41     private Extension extension;
42     @Mock
43     private MatchEntry matchEntry;
44
45     private NsiConvertor nsiConvertor;
46
47     @Before
48     public void setUp() throws Exception {
49         final NxmNxNsiBuilder nxmNxNsiBuilder = new NxmNxNsiBuilder()
50                 .setNsi((short)1);
51         final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
52         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNsi(nxmNxNsiBuilder.build());
53
54         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
55         when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
56
57         nsiConvertor = new NsiConvertor();
58     }
59
60     @Test
61     public void testConvert() throws Exception {
62         final MatchEntry matchEntry = nsiConvertor.convert(extension);
63         Assert.assertEquals(1, ((NsiCaseValue)matchEntry.getMatchEntryValue()).getNsiValues().getNsi().intValue());
64     }
65
66     @Test
67     public void testConvert1() throws Exception {
68         final NsiValuesBuilder nsiValuesBuilder = new NsiValuesBuilder()
69                 .setNsi(Short.valueOf((short)1));
70         final NsiCaseValueBuilder nsiCaseValueBuilder = new NsiCaseValueBuilder()
71                 .setNsiValues(nsiValuesBuilder.build());
72
73         final NsiCaseValue nsiCaseValue = nsiCaseValueBuilder.build();
74
75         when(matchEntry.getMatchEntryValue()).thenReturn(nsiCaseValue);
76
77         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nsiConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
78         Assert.assertEquals(1, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxNsi().getNsi().intValue());
79         Assert.assertEquals(extensionAugment.getKey(), NxmNxNsiKey.class);
80
81         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nsiConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
82         Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxNsi().getNsi().intValue());
83         Assert.assertEquals(extensionAugment.getKey(), NxmNxNsiKey.class);
84
85         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nsiConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
86         Assert.assertEquals(1, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxNsi().getNsi().intValue());
87         Assert.assertEquals(extensionAugment.getKey(), NxmNxNsiKey.class);
88     }
89
90 }