812b2d23fd33800a1ff90b6b0180ff230bb79844
[groupbasedpolicy.git] / groupbasedpolicy / src / test / java / org / opendaylight / groupbasedpolicy / resolver / EgKeyTest.java
1 package org.opendaylight.groupbasedpolicy.resolver;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertTrue;
7 import static org.mockito.Mockito.mock;
8 import static org.mockito.Mockito.when;
9
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.opendaylight.groupbasedpolicy.dto.EgKey;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
15
16 public class EgKeyTest {
17
18     private EgKey egKey;
19     private TenantId tenantId;
20     private EndpointGroupId egId;
21
22     @Before
23     public void init() {
24         tenantId = mock(TenantId.class);
25         egId = mock(EndpointGroupId.class);
26
27         String value = "value";
28         when(tenantId.getValue()).thenReturn(value);
29         when(egId.getValue()).thenReturn(value);
30
31         egKey = new EgKey(tenantId, egId);
32     }
33
34     @Test
35     public void testConstructor() {
36         assertEquals(tenantId, egKey.getTenantId());
37         assertEquals(egId, egKey.getEgId());
38     }
39
40     @Test
41     public void testEquals() {
42         assertTrue(egKey.equals(egKey));
43         assertFalse(egKey.equals(null));
44         assertFalse(egKey.equals(new Object()));
45
46         EgKey other;
47         other = new EgKey(null, egId);
48         assertFalse(egKey.equals(other));
49         assertFalse(other.equals(egKey));
50
51         other = new EgKey(tenantId, null);
52         assertFalse(egKey.equals(other));
53         assertFalse(other.equals(egKey));
54
55         other = new EgKey(tenantId, egId);
56         assertTrue(egKey.equals(other));
57
58         egKey = new EgKey(null, null);
59         other = new EgKey(null, null);
60         assertTrue(egKey.equals(other));
61     }
62
63     @Test
64     public void testCompareTo() {
65         EgKey other = new EgKey(tenantId, egId);
66         assertEquals(0, egKey.compareTo(other));
67
68         other = new EgKey(null, null);
69         assertEquals(-1, egKey.compareTo(other));
70         assertEquals(1, other.compareTo(egKey));
71
72         String valueOther = "valu";
73         TenantId tenantIdOther = mock(TenantId.class);
74         when(tenantIdOther.getValue()).thenReturn(valueOther);
75
76         other = new EgKey(tenantIdOther, egId);
77         assertEquals(1, egKey.compareTo(other));
78         assertEquals(-1, other.compareTo(egKey));
79
80         EndpointGroupId egIdOther = mock(EndpointGroupId.class);
81         when(egIdOther.getValue()).thenReturn(valueOther);
82
83         other = new EgKey(tenantId, egIdOther);
84         assertEquals(1, egKey.compareTo(other));
85         assertEquals(-1, other.compareTo(egKey));
86
87         egKey = new EgKey(tenantIdOther, egId);
88         assertEquals(-1, egKey.compareTo(other));
89         assertEquals(1, other.compareTo(egKey));
90     }
91
92     @Test
93     public void testToString() {
94         String string = egKey.toString();
95         assertNotNull(string);
96         assertFalse(string.isEmpty());
97         assertTrue(string.contains(tenantId.toString()));
98         assertTrue(string.contains(egId.toString()));
99     }
100 }