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.ct.zone.grouping.CtZoneValuesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValue;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.CtZoneCaseValueBuilder;
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.NxmNxCtZoneKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZoneBuilder;
34 import org.opendaylight.yangtools.yang.binding.Augmentation;
37 * Test for {@link CtZoneConvertor}.
39 @RunWith(MockitoJUnitRunner.class)
40 public class CtZoneConvertorTest {
43 private Extension extension;
45 private MatchEntry matchEntry;
47 private CtZoneConvertor ctZoneConvertor;
50 public void setUp() throws Exception {
52 final NxmNxCtZoneBuilder nxmNxCtZoneBuilder = new NxmNxCtZoneBuilder()
54 final NxAugMatchNodesNodeTableFlowBuilder nxAugMatchNotifUpdateFlowStatsBuilder =
55 new NxAugMatchNodesNodeTableFlowBuilder();
56 nxAugMatchNotifUpdateFlowStatsBuilder.setNxmNxCtZone(nxmNxCtZoneBuilder.build());
58 final Augmentation<Extension> extensionAugmentation = nxAugMatchNotifUpdateFlowStatsBuilder.build();
59 when(extension.getAugmentation(Matchers.<Class<Augmentation<Extension>>>any()))
60 .thenReturn(extensionAugmentation);
62 ctZoneConvertor = new CtZoneConvertor();
67 public void testConvert() throws Exception {
68 final MatchEntry converted = ctZoneConvertor.convert(extension);
69 Assert.assertEquals(1L,
70 ((CtZoneCaseValue) converted.getMatchEntryValue()).getCtZoneValues().getCtZone().longValue());
74 public void testConvert1() throws Exception {
75 final CtZoneValuesBuilder ctZoneValuesBuilder = new CtZoneValuesBuilder()
77 final CtZoneCaseValueBuilder ctZoneCaseValueBuilder = new CtZoneCaseValueBuilder()
78 .setCtZoneValues(ctZoneValuesBuilder.build());
80 final CtZoneCaseValue ctZoneCaseValue = ctZoneCaseValueBuilder.build();
82 when(matchEntry.getMatchEntryValue()).thenReturn(ctZoneCaseValue);
84 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = ctZoneConvertor.convert(matchEntry,
85 MatchPath.PACKET_RECEIVED_MATCH);
86 Assert.assertEquals(2L, ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxCtZone()
87 .getCtZone().longValue());
88 Assert.assertEquals(extensionAugment.getKey(), NxmNxCtZoneKey.class);
90 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = ctZoneConvertor
91 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
92 Assert.assertEquals(2L, ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject())
93 .getNxmNxCtZone().getCtZone().longValue());
94 Assert.assertEquals(extensionAugment.getKey(), NxmNxCtZoneKey.class);
96 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = ctZoneConvertor
97 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
98 Assert.assertEquals(2L, ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject())
99 .getNxmNxCtZone().getCtZone().longValue());
100 Assert.assertEquals(extensionAugment.getKey(), NxmNxCtZoneKey.class);
102 final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = ctZoneConvertor
103 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
104 Assert.assertEquals(2L, ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxCtZone()
105 .getCtZone().longValue());
106 Assert.assertEquals(extensionAugment.getKey(), NxmNxCtZoneKey.class);