blob: 22789495de88d18ffe1f7cb44b1179d336c9ef3b [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
Ray Milkeyc127a5a2014-08-20 11:22:12 -070025 final MatchActionOperationsId operationsId =
Ray Milkey9ed4b962014-08-20 15:43:40 -070026 new MatchActionOperationsId(1L);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070027 final MatchActionOperations operations =
Ray Milkey9ed4b962014-08-20 15:43:40 -070028 new MatchActionOperations(operationsId);
Brian O'Connordee2e6b2014-08-12 11:34:51 -070029
30 // Create one MatchActionEntry and add it to the Operations
Ray Milkey9ed4b962014-08-20 15:43:40 -070031
32 final MatchActionId matchActionId1 = new MatchActionId(1L);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070033 final MatchAction action1 = new MatchAction(matchActionId1, null, null, null);
Brian O'Connordee2e6b2014-08-12 11:34:51 -070034
35 final MatchActionOperationEntry entry1 =
36 new MatchActionOperationEntry(MatchActionOperations.Operator.ADD, action1);
37
38 operations.addOperation(entry1);
39
40 // Query the Operations entry list and check that the returned list is correct
41 final List<MatchActionOperationEntry> opList = operations.getOperations();
42 assertThat(opList, is(notNullValue()));
43 assertThat(opList, hasSize(1));
44 assertThat(opList.size(), is(equalTo(operations.size())));
45
46 // Check that the MatchAction was persisted correctly
47 final MatchActionOperationEntry loadedEntry1 = opList.get(0);
48 assertThat(loadedEntry1, is(notNullValue()));
49
50 final MatchAction loadedAction1 = loadedEntry1.getTarget();
Ray Milkey9ed4b962014-08-20 15:43:40 -070051 assertThat(loadedAction1.getId().toString(),
52 is(equalTo(matchActionId1.toString())));
Brian O'Connordee2e6b2014-08-12 11:34:51 -070053
54 final MatchActionOperations.Operator loadedOperator1 = loadedEntry1.getOperator();
55 assertThat(loadedOperator1, is(equalTo(MatchActionOperations.Operator.ADD)));
56 }
57}