ecf8c2f852d4f08c6caf3d91efee8ccf68354854
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / Nshc3ConvertorTest.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._3.grouping.Nshc3ValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc3CaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc3CaseValueBuilder;
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.NxmNxNshc3Key;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._3.grouping.NxmNxNshc3Builder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
35
36 /**
37  * Test for {@link Nshc3Convertor}.
38  */
39 @RunWith(MockitoJUnitRunner.class)
40 public class Nshc3ConvertorTest {
41
42     @Mock
43     private Extension extension;
44     @Mock
45     private MatchEntry matchEntry;
46
47     private Nshc3Convertor nshc3Convertor;
48
49     @Before
50     public void setUp() throws Exception {
51         final NxmNxNshc3Builder nxmNxNshc3Builder = new NxmNxNshc3Builder()
52                 .setValue(1L);
53         final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
54                 new NxAugMatchNodesNodeTableFlowBuilder();
55         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNshc3(nxmNxNshc3Builder.build());
56
57         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
58         when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any()))
59             .thenReturn(extensionAugmentation);
60
61         nshc3Convertor = new Nshc3Convertor();
62     }
63
64     @Test
65     public void testConvert() throws Exception {
66         final MatchEntry converted = nshc3Convertor.convert(extension);
67         Assert.assertEquals(1, ((Nshc3CaseValue)converted.getMatchEntryValue()).getNshc3Values().getNshc().intValue());
68     }
69
70     @Test
71     public void testConvert1() throws Exception {
72         final Nshc3ValuesBuilder nshc3ValuesBuilder = new Nshc3ValuesBuilder()
73                 .setNshc(Long.valueOf(1));
74         final Nshc3CaseValueBuilder nshc3CaseValueBuilder = new Nshc3CaseValueBuilder()
75                 .setNshc3Values(nshc3ValuesBuilder.build());
76
77         final Nshc3CaseValue nshc3CaseValue = nshc3CaseValueBuilder.build();
78
79         when(matchEntry.getMatchEntryValue()).thenReturn(nshc3CaseValue);
80
81         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nshc3Convertor.convert(matchEntry,
82                 MatchPath.PACKET_RECEIVED_MATCH);
83         Assert.assertEquals(1, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxNshc3()
84                 .getValue().intValue());
85         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc3Key.class);
86
87         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nshc3Convertor.convert(matchEntry,
88                 MatchPath.SWITCH_FLOW_REMOVED_MATCH);
89         Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
90                 .getNxmNxNshc3().getValue().intValue());
91         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc3Key.class);
92
93         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nshc3Convertor.convert(matchEntry,
94                 MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
95         Assert.assertEquals(1, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
96                 .getNxmNxNshc3().getValue().intValue());
97         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc3Key.class);
98
99         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = nshc3Convertor.convert(matchEntry,
100                 MatchPath.FLOWS_STATISTICS_RPC_MATCH);
101         Assert.assertEquals(1, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxNshc3()
102                 .getValue().intValue());
103         Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc3Key.class);
104     }
105 }