87a8abf2e9e85a9ec5d5bde2f59072cf2f025714
[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 = new NxAugMatchNodesNodeTableFlowBuilder();
53         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNsp(nxmNxNspBuilder.build());
54
55         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
56         when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
57
58         nspConvertor = new NspConvertor();
59     }
60
61     @Test
62     public void testConvert() throws Exception {
63         final MatchEntry matchEntry = nspConvertor.convert(extension);
64         Assert.assertEquals(1, ((NspCaseValue)matchEntry.getMatchEntryValue()).getNspValues().getNsp().intValue());
65     }
66
67     @Test
68     public void testConvert1() throws Exception {
69         final NspValuesBuilder nspValuesBuilder = new NspValuesBuilder()
70                 .setNsp(Long.valueOf(2L));
71         final NspCaseValueBuilder nspCaseValueBuilder = new NspCaseValueBuilder()
72                 .setNspValues(nspValuesBuilder.build());
73
74         final NspCaseValue nspCaseValue = nspCaseValueBuilder.build();
75
76         when(matchEntry.getMatchEntryValue()).thenReturn(nspCaseValue);
77
78         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nspConvertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
79         Assert.assertEquals(2, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxNsp().getValue().longValue());
80         Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
81
82         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nspConvertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
83         Assert.assertEquals(2, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxNsp().getValue().longValue());
84         Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
85
86         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nspConvertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
87         Assert.assertEquals(2, ((NxAugMatchNodesNodeTableFlow)extensionAugment2.getAugmentationObject()).getNxmNxNsp().getValue().longValue());
88         Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
89
90         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = nspConvertor.convert(matchEntry, MatchPath.RPCFLOWSSTATISTICS_FLOWANDSTATISTICSMAPLIST_MATCH);
91         Assert.assertEquals(2, ((NxAugMatchRpcGetFlowStats)extensionAugment3.getAugmentationObject()).getNxmNxNsp().getValue().longValue());
92         Assert.assertEquals(extensionAugment.getKey(), NxmNxNspKey.class);
93     }
94 }