2 * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
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.tests;
10 import static org.junit.Assert.assertEquals;
12 import ch.vorburger.xtendbeans.XtendBeanGenerator;
13 import java.math.BigInteger;
14 import org.junit.Test;
15 import org.opendaylight.genius.mdsalutil.ActionInfo;
16 import org.opendaylight.genius.mdsalutil.ActionInfoBuilder;
17 import org.opendaylight.genius.mdsalutil.ActionType;
20 * Test to illustrate why {@link ActionInfoBuilder} is required for
21 * {@link ActionInfo} to be able to be used with the {@link XtendBeanGenerator}.
23 * <p>Delete the ActionInfoBuilder class, and see that this test fails, even though
24 * there is no compile time dependency. Add tests here for new ActionInfo
25 * (sub)types; ensure (manually) that coverage on ActionInfo and its subtypes
26 * constructors stays 100%.
28 * @author Michael Vorburger
30 public class ActionInfoBuilderTest {
32 XtendBeanGenerator generator = new XtendBeanGenerator();
35 public void noActionValues() {
36 ActionInfo actionInfo = new ActionInfo(ActionType.drop_action, (String[]) null);
37 actionInfo.buildAction();
38 assertEquals("(new ActionInfoBuilder => [\n"
39 + " actionType = ActionType.drop_action\n"
40 + "]).build()", generator.getExpression(actionInfo));
44 public void groupActionWithSingleIntegerInStringValue() {
45 ActionInfo actionInfo = new ActionInfo(ActionType.group, new String[] { "123" });
46 actionInfo.buildAction();
47 assertEquals("(new ActionInfoBuilder => [\n"
48 + " actionType = ActionType.group\n"
49 + " actionValues = #[\n"
52 + "]).build()", generator.getExpression(actionInfo));
56 public void groupActionWithSingleIntegerInStringValueWithActionKey() {
57 ActionInfo actionInfo = new ActionInfo(ActionType.group, new String[] { "123" }, 69);
58 actionInfo.buildAction();
59 assertEquals("(new ActionInfoBuilder => [\n"
61 + " actionType = ActionType.group\n"
62 + " actionValues = #[\n"
65 + "]).build()", generator.getExpression(actionInfo));
69 public void set_field_tunnel_idActionWithBigActionValues() {
70 ActionInfo actionInfo = new ActionInfo(ActionType.set_field_tunnel_id,
71 new BigInteger[] { BigInteger.valueOf(123) });
72 actionInfo.buildAction();
73 assertEquals("(new ActionInfoBuilder => [\n"
74 + " actionType = ActionType.set_field_tunnel_id\n"
75 + " bigActionValues = #[\n"
78 + "]).build()", generator.getExpression(actionInfo));
82 public void set_field_tunnel_idActionWithBigActionValuesWithActionKey() {
83 ActionInfo actionInfo = new ActionInfo(ActionType.set_field_tunnel_id,
84 new BigInteger[] { BigInteger.valueOf(123) }, 69);
85 actionInfo.buildAction();
86 assertEquals("(new ActionInfoBuilder => [\n"
88 + " actionType = ActionType.set_field_tunnel_id\n"
89 + " bigActionValues = #[\n"
92 + "]).build()", generator.getExpression(actionInfo));
96 public void learnActionValuesMatrix() {
97 ActionInfo actionInfo = new ActionInfo(ActionType.learn,
98 new String[] { "1", "2", "3", "4", "5", "6", "7", "8" },
99 new String[][] { { "2", "3" }, { "4", "5" } });
100 actionInfo.buildAction();
101 assertEquals("(new ActionInfoBuilder => [\n"
102 + " actionType = ActionType.learn\n"
103 + " actionValues = #[\n"
113 + " actionValuesMatrix = #[\n"
123 + "]).build()", generator.getExpression(actionInfo));