blob: b01f1c8c30bfcbe6f29051fa44a8b9ced727b798 [file] [log] [blame]
Ray Milkeyc127a5a2014-08-20 11:22:12 -07001package net.onrc.onos.core.matchaction;
2
3import static org.hamcrest.MatcherAssert.assertThat;
4import static org.hamcrest.Matchers.equalTo;
5import static org.hamcrest.Matchers.not;
6import static org.hamcrest.Matchers.is;
7import static org.hamcrest.Matchers.notNullValue;
8
9import net.onrc.onos.core.util.TestUtils;
10import org.junit.Test;
11
12/**
13 * Unit tests for Match Action Operations.
14 */
15public class MatchActionOperationsTest {
16
17 /**
18 * Test that creation of MatchActionOperations objects is correct and that
19 * the objects have unique identifiers.
20 */
21 @Test
22 public void testMatchActionoperationsCreate() {
23 final MatchActionOperationsId id1 =
Ray Milkey9ed4b962014-08-20 15:43:40 -070024 new MatchActionOperationsId(1L);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070025 final MatchActionOperations operations1 =
Ray Milkey9ed4b962014-08-20 15:43:40 -070026 new MatchActionOperations(id1);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070027 assertThat(id1, is(notNullValue()));
28 assertThat(id1, is(equalTo(operations1.getOperationsId())));
29
30 final MatchActionOperationsId id2 =
Ray Milkey9ed4b962014-08-20 15:43:40 -070031 new MatchActionOperationsId(2L);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070032 final MatchActionOperations operations2 =
Ray Milkey9ed4b962014-08-20 15:43:40 -070033 new MatchActionOperations(id2);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070034 assertThat(id2, is(notNullValue()));
35 assertThat(id2, is(equalTo(operations2.getOperationsId())));
36
37 assertThat(id1.getId(), is(not(equalTo(id2.getId()))));
38 }
39
40 /**
41 * Test the correctness of the equals() operation for
42 * MatchActionOperationsId objects.
43 * objects.
44 */
45 @Test
46 public void testMatchActionOperationsIdEquals() {
47 final MatchActionOperationsId id1 =
Ray Milkey9ed4b962014-08-20 15:43:40 -070048 new MatchActionOperationsId(1L);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070049 final MatchActionOperationsId id2 =
Ray Milkey9ed4b962014-08-20 15:43:40 -070050 new MatchActionOperationsId(2L);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070051 final MatchActionOperationsId id1Copy =
Ray Milkey9ed4b962014-08-20 15:43:40 -070052 new MatchActionOperationsId(1L);
Ray Milkeyc127a5a2014-08-20 11:22:12 -070053
54
55 // Check that null does not match
56 assertThat(id1, is(not(equalTo(null))));
57
58 // Check that different objects do not match
59 assertThat(id1, is(not(equalTo(id2))));
60
61 // Check that copies match
62 TestUtils.setField(id1Copy, "id", id1.getId());
63 assertThat(id1, is(equalTo(id1Copy)));
64
65 // Check that the same object matches
66 assertThat(id1, is(equalTo(id1Copy)));
67 }
68
69 /**
70 * Test the correctness of the hashCode() operation for
71 * MatchActionOperationsId objects.
72 */
73 @Test
74 public void testMatchActionOperationsIdHashCode() {
75 final MatchActionOperationsId id1 =
Ray Milkey9ed4b962014-08-20 15:43:40 -070076 new MatchActionOperationsId(22L);
77 assertThat(id1.hashCode(), is(equalTo(22)));
Ray Milkeyc127a5a2014-08-20 11:22:12 -070078 }
79}