Mark potentially-static methods as static
[genius.git] / mdsalutil / mdsalutil-api / src / test / java / org / opendaylight / genius / mdsalutil / instructions / InstructionWriteActionsTest.java
1 /*
2  * Copyright © 2017 Red Hat, Inc. and others.
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.genius.mdsalutil.instructions;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import ch.vorburger.xtendbeans.XtendBeanGenerator;
14 import java.util.Collections;
15 import java.util.Map;
16 import org.junit.Test;
17 import org.opendaylight.genius.mdsalutil.InstructionInfo;
18 import org.opendaylight.genius.mdsalutil.actions.ActionGroup;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
24
25 /**
26  * Test for {@link InstructionWriteActions}.
27  */
28 public class InstructionWriteActionsTest {
29
30     private static final InstructionWriteActions INSTRUCTION_INFO
31         = new InstructionWriteActions(Collections.singletonList(new ActionGroup(1L)));
32
33     @Test
34     public void newInstruction() {
35         verifyInstructionInfo(INSTRUCTION_INFO);
36     }
37
38     private static void verifyInstructionInfo(InstructionInfo instructionInfo) {
39         Instruction instruction = instructionInfo.buildInstruction(2);
40         assertEquals(2, instruction.key().getOrder().intValue());
41         assertTrue(instruction.getInstruction() instanceof WriteActionsCase);
42         WriteActionsCase writeActionsCase = (WriteActionsCase) instruction.getInstruction();
43         Map<ActionKey, Action> actions = writeActionsCase.getWriteActions().getAction();
44         assertEquals(1, actions.size());
45         Action action = actions.values().iterator().next();
46         assertTrue(action.getAction() instanceof GroupActionCase);
47     }
48
49     @Test
50     public void xtendBeanGenerator() {
51         XtendBeanGenerator generator = new XtendBeanGenerator();
52         assertEquals("new InstructionWriteActions(#[\n"
53                 + "    (new ActionGroupBuilder => [\n"
54                 + "        groupId = 1L\n"
55                 + "    ]).build()\n"
56                 + "])", generator.getExpression(INSTRUCTION_INFO));
57     }
58
59 }