Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / match / ArpShaConvertorTest.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.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.arp.sha.grouping.ArpShaValuesBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpShaCaseValue;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.ArpShaCaseValueBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
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.NxAugMatchRpcAddFlowBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchRpcGetFlowStats;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxArpShaKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.arp.sha.grouping.NxmNxArpShaBuilder;
35 import org.opendaylight.yangtools.yang.binding.Augmentation;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 /**
40  * Test for {@link ArpShaConvertor}.
41  */
42 @RunWith(MockitoJUnitRunner.class)
43 public class ArpShaConvertorTest {
44
45     @Mock
46     private Extension extension;
47     @Mock
48     private MatchEntry matchEntry;
49
50     private ArpShaConvertor arpShaConvertor;
51
52     private static final MacAddress MAC_ADDRESS =  MacAddress.getDefaultInstance("01:23:45:67:89:AB");
53
54     private static final Logger LOG = LoggerFactory.getLogger(ArpShaConvertorTest.class);
55
56     @Before
57     public void setUp() throws Exception {
58         final NxmNxArpShaBuilder nxmNxArpShaBuilder = new NxmNxArpShaBuilder()
59                 .setMacAddress(MAC_ADDRESS);
60         final NxAugMatchRpcAddFlowBuilder nxAugMatchRpcAddFlowBuilder = new NxAugMatchRpcAddFlowBuilder()
61                 .setNxmNxArpSha(nxmNxArpShaBuilder.build());
62         final Augmentation<Extension> extensionAugmentation = nxAugMatchRpcAddFlowBuilder.build();
63
64         when(extension.augmentation(Matchers.<Class<Augmentation<Extension>>>any()))
65             .thenReturn(extensionAugmentation);
66
67         arpShaConvertor = new ArpShaConvertor();
68     }
69
70     @Test
71     public void testConvertToOFJava() throws Exception {
72         final MatchEntry converted = arpShaConvertor.convert(extension);
73         Assert.assertEquals(MAC_ADDRESS.getValue(),
74                 ((ArpShaCaseValue) converted.getMatchEntryValue()).getArpShaValues().getMacAddress().getValue());
75     }
76
77     @Test
78     public void testConvertFromOFJava() throws Exception {
79         final ArpShaValuesBuilder arpShaValuesBuilder = new ArpShaValuesBuilder()
80                 .setMacAddress(MAC_ADDRESS);
81         final ArpShaCaseValueBuilder arpShaCaseValueBuilder = new ArpShaCaseValueBuilder()
82                 .setArpShaValues(arpShaValuesBuilder.build());
83         final ArpShaCaseValue arpShaCaseValue = arpShaCaseValueBuilder.build();
84
85         when(matchEntry.getMatchEntryValue()).thenReturn(arpShaCaseValue);
86
87         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment = arpShaConvertor.convert(matchEntry,
88                 MatchPath.PACKET_RECEIVED_MATCH);
89         Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(),
90                 ((NxAugMatchNotifPacketIn) extensionAugment.getAugmentationObject()).getNxmNxArpSha().getMacAddress());
91         Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
92
93         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment1 = arpShaConvertor
94                 .convert(matchEntry, MatchPath.SWITCH_FLOW_REMOVED_MATCH);
95         Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(),
96                 ((NxAugMatchNotifSwitchFlowRemoved) extensionAugment1.getAugmentationObject()).getNxmNxArpSha()
97                         .getMacAddress());
98         Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
99
100         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment2 = arpShaConvertor
101                 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_UPDATE_MATCH);
102         Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(),
103                 ((NxAugMatchNodesNodeTableFlow) extensionAugment2.getAugmentationObject()).getNxmNxArpSha()
104                         .getMacAddress());
105         Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
106
107         final ExtensionAugment<? extends Augmentation<Extension>> extensionAugment3 = arpShaConvertor
108                 .convert(matchEntry, MatchPath.FLOWS_STATISTICS_RPC_MATCH);
109         Assert.assertEquals(arpShaCaseValue.getArpShaValues().getMacAddress(),
110                 ((NxAugMatchRpcGetFlowStats) extensionAugment3.getAugmentationObject()).getNxmNxArpSha()
111                         .getMacAddress());
112         Assert.assertEquals(extensionAugment.getKey(), NxmNxArpShaKey.class);
113     }
114
115 }