OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / action / RegMoveConvertorTest.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.action;
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.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.openflowjava.nx.codec.match.NiciraMatchCodecs;
21 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegMove;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.NxActionRegMove;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionRegMoveNotifFlowsStatisticsUpdateWriteActionsCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.get.flow.statistics.output.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegMoveNotifDirectStatisticsUpdateApplyActionsCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.get.flow.statistics.output.flow.and.statistics.map.list.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionRegMoveNotifDirectStatisticsUpdateWriteActionsCase;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.group.desc.stats.updated.group.desc.stats.buckets.bucket.action.action.NxActionRegMoveNotifGroupDescStatsUpdatedCase;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionRegMoveNodesNodeTableFlowWriteActionsCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMove;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Dst;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Src;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.src.choice.grouping.src.choice.SrcNxTunIdCaseBuilder;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 /**
40  * Test for {@link RegMoveConvertor}.
41  */
42 @RunWith(MockitoJUnitRunner.class)
43 public class RegMoveConvertorTest {
44
45     private static final Logger LOG = LoggerFactory.getLogger(RegMoveConvertorTest.class);
46
47     @Mock
48     private NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCase actionsCase;
49     @Mock
50     private Action action;
51     @Mock
52     private NxRegMove nxRegMove;
53
54     private RegMoveConvertor regMoveConvertor;
55
56
57     @Before
58     public void setUp() throws Exception {
59         final Src src = Mockito.mock(Src.class);
60         final Dst dst = Mockito.mock(Dst.class);
61
62         when(actionsCase.getNxRegMove()).thenReturn(nxRegMove);
63         when(nxRegMove.getSrc()).thenReturn(src);
64         when(nxRegMove.getDst()).thenReturn(dst);
65         when(nxRegMove.getSrc().getStart()).thenReturn(1);
66         when(nxRegMove.getDst().getStart()).thenReturn(3);
67         when(nxRegMove.getDst().getEnd()).thenReturn(4);
68         when(nxRegMove.getDst().getDstChoice()).thenReturn(new DstNxTunIdCaseBuilder().build());
69         when(nxRegMove.getSrc().getSrcChoice()).thenReturn(new SrcNxTunIdCaseBuilder().build());
70
71         final ActionRegMove actionRegMove = Mockito.mock(ActionRegMove.class);
72         final NxActionRegMove nxActionRegMove = Mockito.mock(NxActionRegMove.class);
73         when(nxActionRegMove.getSrc()).thenReturn(
74                 NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toBigInteger());
75         when(nxActionRegMove.getDst()).thenReturn(
76                 NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toBigInteger());
77
78         when(nxActionRegMove.getNBits()).thenReturn(7);
79
80         when(actionRegMove.getNxActionRegMove()).thenReturn(nxActionRegMove);
81         when(action.getActionChoice()).thenReturn(actionRegMove);
82
83         regMoveConvertor = new RegMoveConvertor();
84
85     }
86
87     @Test
88     public void testConvert() throws Exception {
89         final ActionRegMove actionRegMove = (ActionRegMove) regMoveConvertor.convert(actionsCase).getActionChoice();
90         Assert.assertEquals(Integer.valueOf(3) ,actionRegMove.getNxActionRegMove().getDstOfs());
91         Assert.assertEquals(Integer.valueOf(2) ,actionRegMove.getNxActionRegMove().getNBits());
92         Assert.assertEquals(Integer.valueOf(1) ,actionRegMove.getNxActionRegMove().getSrcOfs());
93     }
94
95     @Test
96     public void testConvert1() throws Exception {
97         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult
98                 = regMoveConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
99         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult1
100                 = regMoveConvertor.convert(action, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS);
101         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult2
102                 = regMoveConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS);
103         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult3
104                 = regMoveConvertor.convert(action, ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION);
105         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult4
106                 = regMoveConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_APPLY_ACTIONS);
107         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult5
108                 = regMoveConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_WRITE_ACTIONS);
109
110         Assert.assertEquals(Integer.valueOf(0),
111                 ((NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxRegMove().getDst()
112                         .getStart());
113         Assert.assertEquals(Integer.valueOf(6),
114                 ((NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxRegMove().getDst()
115                         .getEnd());
116         Assert.assertEquals(Integer.valueOf(0),
117                 ((NxActionRegMoveNodesNodeTableFlowWriteActionsCase) actionResult1).getNxRegMove().getDst().getStart());
118         Assert.assertEquals(Integer.valueOf(6),
119                 ((NxActionRegMoveNodesNodeTableFlowWriteActionsCase) actionResult1).getNxRegMove().getDst().getEnd());
120         Assert.assertEquals(Integer.valueOf(0),
121                 ((NxActionRegMoveNotifFlowsStatisticsUpdateWriteActionsCase) actionResult2).getNxRegMove().getDst()
122                         .getStart());
123         Assert.assertEquals(Integer.valueOf(6),
124                 ((NxActionRegMoveNotifFlowsStatisticsUpdateWriteActionsCase) actionResult2).getNxRegMove().getDst()
125                         .getEnd());
126         Assert.assertEquals(Integer.valueOf(0),
127                 ((NxActionRegMoveNotifGroupDescStatsUpdatedCase) actionResult3).getNxRegMove().getDst().getStart());
128         Assert.assertEquals(Integer.valueOf(6),
129                 ((NxActionRegMoveNotifGroupDescStatsUpdatedCase) actionResult3).getNxRegMove().getDst().getEnd());
130         Assert.assertEquals(Integer.valueOf(0),
131                 ((NxActionRegMoveNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxRegMove().getDst()
132                         .getStart());
133         Assert.assertEquals(Integer.valueOf(6),
134                 ((NxActionRegMoveNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxRegMove().getDst()
135                         .getEnd());
136         Assert.assertEquals(Integer.valueOf(0),
137                 ((NxActionRegMoveNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxRegMove().getDst()
138                         .getStart());
139         Assert.assertEquals(Integer.valueOf(6),
140                 ((NxActionRegMoveNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxRegMove().getDst()
141                         .getEnd());
142     }
143 }