6a4e7556d557eca86c5dab4be4df0efd68cc6db7
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / EthTypeConvertorTest.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.of.match.eth.type.grouping.EthTypeValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthTypeCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.EthTypeCaseValueBuilder;
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.NxmOfEthTypeKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.of.eth.type.grouping.NxmOfEthTypeBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
35
36 /**
37  * Test for {@link EthTypeConvertor}.
38  */
39 @RunWith(MockitoJUnitRunner.class)
40 public class EthTypeConvertorTest {
41
42     @Mock
43     private Extension extension;
44     @Mock
45     private MatchEntry matchEntry;
46
47     private EthTypeConvertor ethTypeConvertor;
48
49     @Before
50     public void setUp() throws Exception {
51
52         final NxmOfEthTypeBuilder nxmOfEthTypeBuilder = new NxmOfEthTypeBuilder()
53                 .setValue(1);
54         final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
55                 new NxAugMatchNodesNodeTableFlowBuilder();
56         nxAugMatchNotifUpdateFlowStatsBuilder.setNxmOfEthType(nxmOfEthTypeBuilder.build());
57
58         final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
59         when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any()))
60             .thenReturn(extensionAugmentation);
61
62         ethTypeConvertor = new EthTypeConvertor();
63
64     }
65
66     @Test
67     public void testConvert() throws Exception {
68         final MatchEntry converted = ethTypeConvertor.convert(extension);
69         Assert.assertEquals(1, ((EthTypeCaseValue)converted.getMatchEntryValue())
70                 .getEthTypeValues().getValue().intValue());
71     }
72
73     @Test
74     public void testConvert1() throws Exception {
75         final EthTypeValuesBuilder ethTypeValuesBuilder = new EthTypeValuesBuilder()
76                 .setValue(Integer.valueOf(1));
77         final EthTypeCaseValueBuilder ethTypeCaseValueBuilder = new EthTypeCaseValueBuilder()
78                 .setEthTypeValues(ethTypeValuesBuilder.build());
79
80         final EthTypeCaseValue ethTypeCaseValue = ethTypeCaseValueBuilder.build();
81
82         when(matchEntry.getMatchEntryValue()).thenReturn(ethTypeCaseValue);
83
84         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = ethTypeConvertor
85                 .convert(matchEntry, MatchPath.PACKET_RECEIVED_MATCH);
86         Assert.assertEquals(1, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmOfEthType()
87                 .getValue().intValue());
88         Assert.assertEquals(extensionAugment.getKey(), NxmOfEthTypeKey.class);
89
90         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = ethTypeConvertor
91                 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
92         Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
93                 .getNxmOfEthType().getValue().intValue());
94         Assert.assertEquals(extensionAugment.getKey(), NxmOfEthTypeKey.class);
95
96         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = ethTypeConvertor
97                 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
98         Assert.assertEquals(1, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
99                 .getNxmOfEthType().getValue().intValue());
100         Assert.assertEquals(extensionAugment.getKey(), NxmOfEthTypeKey.class);
101
102         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = ethTypeConvertor
103                 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
104         Assert.assertEquals(1, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmOfEthType()
105                 .getValue().intValue());
106         Assert.assertEquals(extensionAugment.getKey(), NxmOfEthTypeKey.class);
107     }
108 }