InstructionInfo redesign
[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 java.util.Collections;
14 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.genius.mdsalutil.InstructionInfo;
17 import org.opendaylight.genius.mdsalutil.InstructionType;
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     @Test
29     public void backwardsCompatibleInstruction() {
30         verifyInstructionInfo(
31                 new InstructionInfo(InstructionType.write_actions, Collections.singletonList(new ActionGroup(1L))));
32     }
33
34     @Test
35     public void newInstruction() {
36         verifyInstructionInfo(new InstructionWriteActions(Collections.singletonList(new ActionGroup(1L))));
37     }
38
39     private void verifyInstructionInfo(InstructionInfo instructionInfo) {
40         Instruction instruction = instructionInfo.buildInstruction(2);
41         assertEquals(2, instruction.getKey().getOrder().intValue());
42         assertTrue(instruction.getInstruction() instanceof WriteActionsCase);
43         WriteActionsCase writeActionsCase = (WriteActionsCase) instruction.getInstruction();
44         List<Action> actions = writeActionsCase.getWriteActions().getAction();
45         assertEquals(1, actions.size());
46         Action action = actions.get(0);
47         assertTrue(action.getAction() instanceof GroupActionCase);
48     }
49 }