Fix checkstyle
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / test / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / action / MultipathConvertorTest.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 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
9
10 import static org.mockito.Mockito.when;
11
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.openflowjava.nx.codec.match.NiciraMatchCodecs;
20 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxHashFields;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxMpAlgorithm;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionMultipath;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.multipath.grouping.NxActionMultipath;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.dst.choice.grouping.dst.choice.DstNxTunIdCaseBuilder;
28 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.NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase;
29 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.NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase;
30 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.NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase;
31 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.NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.group.desc.stats.updated.group.desc.stats.buckets.bucket.action.action.NxActionMultipathNotifGroupDescStatsUpdatedCase;
33 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.NxActionMultipathNodesNodeTableFlowWriteActionsCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.multipath.grouping.NxMultipath;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.multipath.grouping.nx.multipath.Dst;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 /**
40  * Test for {@link MultipathConvertor}.
41  */
42 @RunWith(MockitoJUnitRunner.class)
43 public class MultipathConvertorTest {
44
45     private static final Logger LOG = LoggerFactory.getLogger(MultipathConvertorTest.class);
46
47     @Mock
48     private NxActionMultipathNodesNodeTableFlowWriteActionsCase bucketActionsCase;
49
50     @Mock
51     private Action action;
52
53     private MultipathConvertor multipathConvertor;
54
55     @Before
56     public void setUp() {
57         final NxMultipath nxMultipath = Mockito.mock(NxMultipath.class);
58         when(bucketActionsCase.getNxMultipath()).thenReturn(nxMultipath);
59
60         final Dst dst = Mockito.mock(Dst.class);
61         when(dst.getStart()).thenReturn(1);
62         when(dst.getEnd()).thenReturn(2);
63
64         final DstNxTunIdCase dstNxTunIdCase = new DstNxTunIdCaseBuilder().build();
65         when(dst.getDstChoice()).thenReturn(dstNxTunIdCase);
66         when(nxMultipath.getFields()).thenReturn(OfjNxHashFields.NXHASHFIELDSETHSRC);
67         when(nxMultipath.getBasis()).thenReturn(2);
68         when(nxMultipath.getAlgorithm()).thenReturn(OfjNxMpAlgorithm.NXMPALGHASHTHRESHOLD);
69         when(nxMultipath.getMaxLink()).thenReturn(2);
70         when(nxMultipath.getArg()).thenReturn(2L);
71         when(nxMultipath.getDst()).thenReturn(dst);
72
73         final ActionMultipath actionMultipath = Mockito.mock(ActionMultipath.class);
74         final NxActionMultipath nxActionMultipath = Mockito.mock(NxActionMultipath.class);
75         when(nxActionMultipath.getDst()).thenReturn(NiciraMatchCodecs.TUN_ID_CODEC.getHeaderWithoutHasMask().toLong());
76         when(nxActionMultipath.getBasis()).thenReturn(1);
77         when(nxActionMultipath.getAlgorithm()).thenReturn(OfjNxMpAlgorithm.NXMPALGHRW);
78         when(nxActionMultipath.getMaxLink()).thenReturn(2);
79         when(nxActionMultipath.getArg()).thenReturn(2L);
80         when(actionMultipath.getNxActionMultipath()).thenReturn(nxActionMultipath);
81         when(action.getActionChoice()).thenReturn(actionMultipath);
82
83         multipathConvertor = new MultipathConvertor();
84     }
85
86     @Test
87     public void testConvert() {
88         final ActionMultipath actionMultipath =
89                 (ActionMultipath) multipathConvertor.convert(bucketActionsCase).getActionChoice();
90         Assert.assertEquals(OfjNxHashFields.NXHASHFIELDSETHSRC, actionMultipath.getNxActionMultipath().getFields());
91         Assert.assertEquals(Integer.valueOf(2), actionMultipath.getNxActionMultipath().getBasis());
92         Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHASHTHRESHOLD,
93                 actionMultipath.getNxActionMultipath().getAlgorithm());
94         Assert.assertEquals(Integer.valueOf(2), actionMultipath.getNxActionMultipath().getMaxLink());
95         Assert.assertEquals(Long.valueOf(2L), actionMultipath.getNxActionMultipath().getArg());
96     }
97
98     @Test
99     public void testConvert1() {
100         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult
101                 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS);
102         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult1
103                 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS);
104         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult2
105                 = multipathConvertor.convert(action, ActionPath.GROUP_DESC_STATS_UPDATED_BUCKET_ACTION);
106         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult3
107                 = multipathConvertor.convert(action, ActionPath.INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS);
108         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult4
109                 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_APPLY_ACTIONS);
110         final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action actionResult5
111                 = multipathConvertor.convert(action, ActionPath.FLOWS_STATISTICS_RPC_WRITE_ACTIONS);
112
113         Assert.assertEquals(Integer.valueOf(1),
114                 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
115                         .getBasis());
116         Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
117                 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
118                         .getAlgorithm());
119         Assert.assertEquals(Long.valueOf(2L),
120                 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath().getArg());
121         Assert.assertEquals(Integer.valueOf(2),
122                 ((NxActionMultipathNotifFlowsStatisticsUpdateApplyActionsCase) actionResult).getNxMultipath()
123                         .getMaxLink());
124
125         Assert.assertEquals(Integer.valueOf(1),
126                 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
127                         .getBasis());
128         Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
129                 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
130                         .getAlgorithm());
131         Assert.assertEquals(Long.valueOf(2L),
132                 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
133                         .getArg());
134         Assert.assertEquals(Integer.valueOf(2),
135                 ((NxActionMultipathNotifFlowsStatisticsUpdateWriteActionsCase) actionResult1).getNxMultipath()
136                         .getMaxLink());
137
138         Assert.assertEquals(Integer.valueOf(1),
139                 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getBasis());
140         Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
141                 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getAlgorithm());
142         Assert.assertEquals(Long.valueOf(2L),
143                 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getArg());
144         Assert.assertEquals(Integer.valueOf(2),
145                 ((NxActionMultipathNotifGroupDescStatsUpdatedCase) actionResult2).getNxMultipath().getMaxLink());
146
147         Assert.assertEquals(Integer.valueOf(1),
148                 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getBasis());
149         Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
150                 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getAlgorithm());
151         Assert.assertEquals(Long.valueOf(2L),
152                 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getArg());
153         Assert.assertEquals(Integer.valueOf(2),
154                 ((NxActionMultipathNodesNodeTableFlowWriteActionsCase) actionResult3).getNxMultipath().getMaxLink());
155
156         Assert.assertEquals(Integer.valueOf(1),
157                 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
158                         .getBasis());
159         Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
160                 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
161                         .getAlgorithm());
162         Assert.assertEquals(Long.valueOf(2L),
163                 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
164                         .getArg());
165         Assert.assertEquals(Integer.valueOf(2),
166                 ((NxActionMultipathNotifDirectStatisticsUpdateApplyActionsCase) actionResult4).getNxMultipath()
167                         .getMaxLink());
168
169         Assert.assertEquals(Integer.valueOf(1),
170                 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
171                         .getBasis());
172         Assert.assertEquals(OfjNxMpAlgorithm.NXMPALGHRW,
173                 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
174                         .getAlgorithm());
175         Assert.assertEquals(Long.valueOf(2L),
176                 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
177                         .getArg());
178         Assert.assertEquals(Integer.valueOf(2),
179                 ((NxActionMultipathNotifDirectStatisticsUpdateWriteActionsCase) actionResult5).getNxMultipath()
180                         .getMaxLink());
181     }
182 }