e79e6f47a736a14d2bd9b556044f42da05c9f435
[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.List;
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.flow.types.rev131026.instruction.instruction.WriteActionsCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
23
24 /**
25  * Test for {@link InstructionWriteActions}.
26  */
27 public class InstructionWriteActionsTest {
28
29     private static final InstructionWriteActions INSTRUCTION_INFO
30         = new InstructionWriteActions(Collections.singletonList(new ActionGroup(1L)));
31
32     @Test
33     public void newInstruction() {
34         verifyInstructionInfo(INSTRUCTION_INFO);
35     }
36
37     private void verifyInstructionInfo(InstructionInfo instructionInfo) {
38         Instruction instruction = instructionInfo.buildInstruction(2);
39         assertEquals(2, instruction.key().getOrder().intValue());
40         assertTrue(instruction.getInstruction() instanceof WriteActionsCase);
41         WriteActionsCase writeActionsCase = (WriteActionsCase) instruction.getInstruction();
42         List<Action> actions = writeActionsCase.getWriteActions().getAction();
43         assertEquals(1, actions.size());
44         Action action = actions.get(0);
45         assertTrue(action.getAction() instanceof GroupActionCase);
46     }
47
48     @Test
49     public void xtendBeanGenerator() {
50         XtendBeanGenerator generator = new XtendBeanGenerator();
51         assertEquals("new InstructionWriteActions(#[\n"
52                 + "    (new ActionGroupBuilder => [\n"
53                 + "        groupId = 1L\n"
54                 + "    ]).build()\n"
55                 + "])", generator.getExpression(INSTRUCTION_INFO));
56     }
57
58 }