Merge "Bug 5543 - Bo: Update JUnit tests part_3"
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / TunIdConvertorTest.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 java.math.BigInteger;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Matchers;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.openflowplugin.extension.api.ExtensionAugment;
22 import org.opendaylight.openflowplugin.extension.api.path.MatchPath;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.tun.id.grouping.TunIdValuesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.TunIdCaseValueBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifPacketIn;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifSwitchFlowRemoved;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStats;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNotifUpdateFlowStatsBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxTunIdKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.tun.id.grouping.NxmNxTunIdBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
35
36 /**
37  * Test for {@link TunIdConvertor}.
38  */
39 @RunWith(MockitoJUnitRunner.class)
40 public class TunIdConvertorTest {
41     @Mock
42     private Extension extension;
43     @Mock
44     private MatchEntry matchEntry;
45
46     private TunIdConvertor tunIdConvertor;
47
48     @Before
49     public void setUp() throws Exception {
50         final NxmNxTunIdBuilder nxmNxTunIdBuilder = new NxmNxTunIdBuilder()
51                 .setValue(BigInteger.ONE);
52         final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
53         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxTunId(nxmNxTunIdBuilder.build());
54
55         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
56         when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
57
58         tunIdConvertor = new TunIdConvertor();
59     }
60
61     @Test
62     public void testConvert() throws Exception {
63         final MatchEntry matchEntry = tunIdConvertor.convert(extension);
64         Assert.assertEquals(BigInteger.ONE, ((TunIdCaseValue)matchEntry.getMatchEntryValue()).getTunIdValues().getValue());
65     }
66
67     @Test
68     public void testConvert1() throws Exception {
69         final TunIdValuesBuilder tunIdValuesBuilder = new TunIdValuesBuilder()
70                 .setValue(BigInteger.TEN);
71         final TunIdCaseValueBuilder tunIdCaseValueBuilder = new TunIdCaseValueBuilder()
72                 .setTunIdValues(tunIdValuesBuilder.build());
73
74         final TunIdCaseValue tunIdCaseValue = tunIdCaseValueBuilder.build();
75
76         when(matchEntry.getMatchEntryValue()).thenReturn(tunIdCaseValue);
77
78         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = tunIdConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
79         Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxTunId().getValue());
80         Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
81
82         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = tunIdConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
83         Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxTunId().getValue());
84         Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
85
86         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = tunIdConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
87         Assert.assertEquals(BigInteger.TEN, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxTunId().getValue());
88         Assert.assertEquals(extensionAugment.getKey(), NxmNxTunIdKey.class);
89     }
90
91 }