Merge "BUG-5888: moving the reconciliation process into a different thread to prevent...
[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.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.NxmNxNshc2Key;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._2.grouping.NxmNxNshc2Builder;
33 import org.opendaylight.yangtools.yang.binding.Augmentation;
34
35 /**
36  * Test for {@link Nshc2Convertor}.
37  */
38 @RunWith(MockitoJUnitRunner.class)
39 public class Nshc2ConvertorTest {
40     @Mock
41     private Extension extension;
42     @Mock
43     private MatchEntry matchEntry;
44
45     private Nshc2Convertor nshc2Convertor;
46
47     @Before
48     public void setUp() throws Exception {
49         final NxmNxNshc2Builder nxmNxNshc2Builder = new NxmNxNshc2Builder()
50                 .setValue(1L);
51         final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
52         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNshc2(nxmNxNshc2Builder.build());
53
54         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
55         when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
56
57         nshc2Convertor = new Nshc2Convertor();
58     }
59
60     @Test
61     public void testConvert() throws Exception {
62         final MatchEntry matchEntry = nshc2Convertor.convert(extension);
63         Assert.assertEquals(1, ((Nshc2CaseValue)matchEntry.getMatchEntryValue()).getNshc2Values().getNshc().intValue());
64     }
65
66     @Test
67     public void testConvert1() throws Exception {
68         final Nshc2ValuesBuilder nshc2ValuesBuilder = new Nshc2ValuesBuilder()
69                 .setNshc(Long.valueOf(1));
70         final Nshc2CaseValueBuilder nshc2CaseValueBuilder = new Nshc2CaseValueBuilder()
71                 .setNshc2Values(nshc2ValuesBuilder.build());
72
73         final Nshc2CaseValue nshc2CaseValue = nshc2CaseValueBuilder.build();
74
75         when(matchEntry.getMatchEntryValue()).thenReturn(nshc2CaseValue);
76
77         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nshc2Convertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
78         Assert.assertEquals(1, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxNshc2().getValue().intValue());
79         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
80
81         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nshc2Convertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
82         Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxNshc2().getValue().intValue());
83         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
84
85         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nshc2Convertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
86         Assert.assertEquals(1, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxNshc2().getValue().intValue());
87         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc2Key.class);
88     }
89
90
91 }