2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.match;
11 import static org.mockito.Mockito.when;
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._4.grouping.Nshc4ValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc4CaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.Nshc4CaseValueBuilder;
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.NxmNxNshc4Key;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.nshc._4.grouping.NxmNxNshc4Builder;
33 import org.opendaylight.yangtools.yang.binding.Augmentation;
36 * Test for {@link Nshc4Convertor}.
38 @RunWith(MockitoJUnitRunner.class)
39 public class Nshc4ConvertorTest {
41 private Extension extension;
43 private MatchEntry matchEntry;
45 private Nshc4Convertor nshc4Convertor;
48 public void setUp() throws Exception {
49 final NxmNxNshc4Builder nxmNxNshc4Builder = new NxmNxNshc4Builder()
51 final NxAugMatchNotifUpdateFlowStatsBuilder nxAugMatchNotifUpdateFlowStatsBuilder = new NxAugMatchNotifUpdateFlowStatsBuilder();
52 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxNshc4(nxmNxNshc4Builder.build());
54 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
55 when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any())).thenReturn(extensionAugmentation);
57 nshc4Convertor = new Nshc4Convertor();
61 public void testConvert() throws Exception {
62 final MatchEntry matchEntry = nshc4Convertor.convert(extension);
63 Assert.assertEquals(1, ((Nshc4CaseValue)matchEntry.getMatchEntryValue()).getNshc4Values().getNshc().intValue());
67 public void testConvert1() throws Exception {
68 final Nshc4ValuesBuilder nshc4ValuesBuilder = new Nshc4ValuesBuilder()
69 .setNshc(Long.valueOf(1));
70 final Nshc4CaseValueBuilder nshc4CaseValueBuilder = new Nshc4CaseValueBuilder()
71 .setNshc4Values(nshc4ValuesBuilder.build());
73 final Nshc4CaseValue nshc4CaseValue = nshc4CaseValueBuilder.build();
75 when(matchEntry.getMatchEntryValue()).thenReturn(nshc4CaseValue);
77 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = nshc4Convertor.convert(matchEntry, MatchPath.PACKETRECEIVED_MATCH);
78 Assert.assertEquals(1, ((NxAugMatchNotifPacketIn)extensionAugment.getAugmentationObject()).getNxmNxNshc4().getValue().intValue());
79 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
81 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = nshc4Convertor.convert(matchEntry, MatchPath.SWITCHFLOWREMOVED_MATCH);
82 Assert.assertEquals(1, ((NxAugMatchNotifSwitchFlowRemoved)extensionAugment1.getAugmentationObject()).getNxmNxNshc4().getValue().intValue());
83 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);
85 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = nshc4Convertor.convert(matchEntry, MatchPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_MATCH);
86 Assert.assertEquals(1, ((NxAugMatchNotifUpdateFlowStats)extensionAugment2.getAugmentationObject()).getNxmNxNshc4().getValue().intValue());
87 Assert.assertEquals(extensionAugment.getKey(), NxmNxNshc4Key.class);