Merge "New match Reg4 type and temporary SMAC table definitions"
[genius.git] / mdsalutil / mdsalutil-api / src / test / java / org / opendaylight / genius / mdsalutil / tests / ActionInfoBuilderTest.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
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.tests;
9
10 import static org.junit.Assert.assertEquals;
11
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;
18
19 /**
20  * Test to illustrate why {@link ActionInfoBuilder} is required for
21  * {@link ActionInfo} to be able to be used with the {@link XtendBeanGenerator}.
22  *
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%.
27  *
28  * @author Michael Vorburger
29  */
30 public class ActionInfoBuilderTest {
31
32     XtendBeanGenerator generator = new XtendBeanGenerator();
33
34     @Test
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));
41     }
42
43     @Test
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"
50                 + "        \"123\"\n"
51                 + "    ]\n"
52                 + "]).build()", generator.getExpression(actionInfo));
53     }
54
55     @Test
56     public void groupActionWithSingleIntegerInStringValueWithActionKey() {
57         ActionInfo actionInfo = new ActionInfo(ActionType.group, new String[] { "123" }, 69);
58         actionInfo.buildAction();
59         assertEquals("(new ActionInfoBuilder => [\n"
60                 + "    actionKey = 69\n"
61                 + "    actionType = ActionType.group\n"
62                 + "    actionValues = #[\n"
63                 + "        \"123\"\n"
64                 + "    ]\n"
65                 + "]).build()", generator.getExpression(actionInfo));
66     }
67
68     @Test
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"
76                 + "        123bi\n"
77                 + "    ]\n"
78                 + "]).build()", generator.getExpression(actionInfo));
79     }
80
81     @Test
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"
87                 + "    actionKey = 69\n"
88                 + "    actionType = ActionType.set_field_tunnel_id\n"
89                 + "    bigActionValues = #[\n"
90                 + "        123bi\n"
91                 + "    ]\n"
92                 + "]).build()", generator.getExpression(actionInfo));
93     }
94
95     @Test
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"
104                 + "        \"1\",\n"
105                 + "        \"2\",\n"
106                 + "        \"3\",\n"
107                 + "        \"4\",\n"
108                 + "        \"5\",\n"
109                 + "        \"6\",\n"
110                 + "        \"7\",\n"
111                 + "        \"8\"\n"
112                 + "    ]\n"
113                 + "    actionValuesMatrix = #[\n"
114                 + "        #[\n"
115                 + "            \"2\",\n"
116                 + "            \"3\"\n"
117                 + "        ],\n"
118                 + "        #[\n"
119                 + "            \"4\",\n"
120                 + "            \"5\"\n"
121                 + "        ]\n"
122                 + "    ]\n"
123                 + "]).build()", generator.getExpression(actionInfo));
124     }
125
126 }