blob: fd96de4173e746866d0d9b496018b27bc425a971 [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 =
24 MatchActionOperationsId.createNewOperationsId();
25 final MatchActionOperations operations1 =
26 MatchActionOperations.createMatchActionsOperations(id1);
27 assertThat(id1, is(notNullValue()));
28 assertThat(id1, is(equalTo(operations1.getOperationsId())));
29
30 final MatchActionOperationsId id2 =
31 MatchActionOperationsId.createNewOperationsId();
32 final MatchActionOperations operations2 =
33 MatchActionOperations.createMatchActionsOperations(id2);
34 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 =
48 MatchActionOperationsId.createNewOperationsId();
49 final MatchActionOperationsId id2 =
50 MatchActionOperationsId.createNewOperationsId();
51 final MatchActionOperationsId id1Copy =
52 MatchActionOperationsId.createNewOperationsId();
53
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 =
76 MatchActionOperationsId.createNewOperationsId();
77 assertThat(id1.hashCode(), is(equalTo(id1.getId().hashCode())));
78 }
79}