blob: 95368484a7a5f995ead9be8d6f2d0cc8e03c4948 [file] [log] [blame]
Brian O'Connordee2e6b2014-08-12 11:34:51 -07001package net.onrc.onos.core.matchaction;
2
3import org.junit.Test;
4
5import java.util.List;
6
7import static org.hamcrest.MatcherAssert.assertThat;
8import static org.hamcrest.Matchers.equalTo;
9import static org.hamcrest.Matchers.hasSize;
10import static org.hamcrest.Matchers.is;
11import static org.hamcrest.Matchers.notNullValue;
12
13
14/**
15 * Unit tests for creation of MatchActionOperations.
16 */
17public class TestOperationsCreation {
18
19 /**
20 * Checks creation of Match Action Operations.
21 */
22 @Test
23 public void testOperationsCreation() {
24 // Create the MatchActionOperations
25 final MatchActionOperations operations = new MatchActionOperations();
26
27 // Create one MatchActionEntry and add it to the Operations
28 final String id1 = "MA1";
29 final MatchAction action1 = new MatchAction(id1, null, null, null);
30
31 final MatchActionOperationEntry entry1 =
32 new MatchActionOperationEntry(MatchActionOperations.Operator.ADD, action1);
33
34 operations.addOperation(entry1);
35
36 // Query the Operations entry list and check that the returned list is correct
37 final List<MatchActionOperationEntry> opList = operations.getOperations();
38 assertThat(opList, is(notNullValue()));
39 assertThat(opList, hasSize(1));
40 assertThat(opList.size(), is(equalTo(operations.size())));
41
42 // Check that the MatchAction was persisted correctly
43 final MatchActionOperationEntry loadedEntry1 = opList.get(0);
44 assertThat(loadedEntry1, is(notNullValue()));
45
46 final MatchAction loadedAction1 = loadedEntry1.getTarget();
47 assertThat(loadedAction1.getId().toString(), is(equalTo(id1)));
48
49 final MatchActionOperations.Operator loadedOperator1 = loadedEntry1.getOperator();
50 assertThat(loadedOperator1, is(equalTo(MatchActionOperations.Operator.ADD)));
51 }
52}