Add missing license headers
[groupbasedpolicy.git] / groupbasedpolicy / src / test / java / org / opendaylight / groupbasedpolicy / resolver / EgKeyTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.groupbasedpolicy.resolver;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
16
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.groupbasedpolicy.dto.EgKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
22
23 public class EgKeyTest {
24
25     private EgKey egKey;
26     private TenantId tenantId;
27     private EndpointGroupId egId;
28
29     @Before
30     public void init() {
31         tenantId = mock(TenantId.class);
32         egId = mock(EndpointGroupId.class);
33
34         String value = "value";
35         when(tenantId.getValue()).thenReturn(value);
36         when(egId.getValue()).thenReturn(value);
37
38         egKey = new EgKey(tenantId, egId);
39     }
40
41     @Test
42     public void testConstructor() {
43         assertEquals(tenantId, egKey.getTenantId());
44         assertEquals(egId, egKey.getEgId());
45     }
46
47     @Test
48     public void testEquals() {
49         assertTrue(egKey.equals(egKey));
50         assertFalse(egKey.equals(null));
51         assertFalse(egKey.equals(new Object()));
52
53         EgKey other;
54         other = new EgKey(null, egId);
55         assertFalse(egKey.equals(other));
56         assertFalse(other.equals(egKey));
57
58         other = new EgKey(tenantId, null);
59         assertFalse(egKey.equals(other));
60         assertFalse(other.equals(egKey));
61
62         other = new EgKey(tenantId, egId);
63         assertTrue(egKey.equals(other));
64
65         egKey = new EgKey(null, null);
66         other = new EgKey(null, null);
67         assertTrue(egKey.equals(other));
68     }
69
70     @Test
71     public void testCompareTo() {
72         EgKey other = new EgKey(tenantId, egId);
73         assertEquals(0, egKey.compareTo(other));
74
75         other = new EgKey(null, null);
76         assertEquals(-1, egKey.compareTo(other));
77         assertEquals(1, other.compareTo(egKey));
78
79         String valueOther = "valu";
80         TenantId tenantIdOther = mock(TenantId.class);
81         when(tenantIdOther.getValue()).thenReturn(valueOther);
82
83         other = new EgKey(tenantIdOther, egId);
84         assertEquals(1, egKey.compareTo(other));
85         assertEquals(-1, other.compareTo(egKey));
86
87         EndpointGroupId egIdOther = mock(EndpointGroupId.class);
88         when(egIdOther.getValue()).thenReturn(valueOther);
89
90         other = new EgKey(tenantId, egIdOther);
91         assertEquals(1, egKey.compareTo(other));
92         assertEquals(-1, other.compareTo(egKey));
93
94         egKey = new EgKey(tenantIdOther, egId);
95         assertEquals(-1, egKey.compareTo(other));
96         assertEquals(1, other.compareTo(egKey));
97     }
98
99     @Test
100     public void testToString() {
101         String string = egKey.toString();
102         assertNotNull(string);
103         assertFalse(string.isEmpty());
104         assertTrue(string.contains(tenantId.toString()));
105         assertTrue(string.contains(egId.toString()));
106     }
107 }