2 * Copyright © 2017 Red Hat, Inc. and others.
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
8 package org.opendaylight.genius.mdsalutil.instructions;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import ch.vorburger.xtendbeans.XtendBeanGenerator;
14 import java.util.Collections;
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;
26 * Test for {@link InstructionWriteActions}.
28 public class InstructionWriteActionsTest {
30 private static final InstructionWriteActions INSTRUCTION_INFO
31 = new InstructionWriteActions(Collections.singletonList(new ActionGroup(1L)));
34 public void newInstruction() {
35 verifyInstructionInfo(INSTRUCTION_INFO);
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);
50 public void xtendBeanGenerator() {
51 XtendBeanGenerator generator = new XtendBeanGenerator();
52 assertEquals("new InstructionWriteActions(#[\n"
53 + " (new ActionGroupBuilder => [\n"
56 + "])", generator.getExpression(INSTRUCTION_INFO));