Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import java.util.List; |
| 6 | |
| 7 | import static org.hamcrest.MatcherAssert.assertThat; |
| 8 | import static org.hamcrest.Matchers.equalTo; |
| 9 | import static org.hamcrest.Matchers.hasSize; |
| 10 | import static org.hamcrest.Matchers.is; |
| 11 | import static org.hamcrest.Matchers.notNullValue; |
| 12 | |
| 13 | |
| 14 | /** |
| 15 | * Unit tests for creation of MatchActionOperations. |
| 16 | */ |
| 17 | public 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 | } |