2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.groupbasedpolicy.resolver;
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;
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;
23 public class EgKeyTest {
26 private TenantId tenantId;
27 private EndpointGroupId egId;
31 tenantId = mock(TenantId.class);
32 egId = mock(EndpointGroupId.class);
34 String value = "value";
35 when(tenantId.getValue()).thenReturn(value);
36 when(egId.getValue()).thenReturn(value);
38 egKey = new EgKey(tenantId, egId);
42 public void testConstructor() {
43 assertEquals(tenantId, egKey.getTenantId());
44 assertEquals(egId, egKey.getEgId());
48 public void testEquals() {
49 assertTrue(egKey.equals(egKey));
50 assertFalse(egKey.equals(null));
51 assertFalse(egKey.equals(new Object()));
54 other = new EgKey(null, egId);
55 assertFalse(egKey.equals(other));
56 assertFalse(other.equals(egKey));
58 other = new EgKey(tenantId, null);
59 assertFalse(egKey.equals(other));
60 assertFalse(other.equals(egKey));
62 other = new EgKey(tenantId, egId);
63 assertTrue(egKey.equals(other));
65 egKey = new EgKey(null, null);
66 other = new EgKey(null, null);
67 assertTrue(egKey.equals(other));
71 public void testCompareTo() {
72 EgKey other = new EgKey(tenantId, egId);
73 assertEquals(0, egKey.compareTo(other));
75 other = new EgKey(null, null);
76 assertEquals(-1, egKey.compareTo(other));
77 assertEquals(1, other.compareTo(egKey));
79 String valueOther = "valu";
80 TenantId tenantIdOther = mock(TenantId.class);
81 when(tenantIdOther.getValue()).thenReturn(valueOther);
83 other = new EgKey(tenantIdOther, egId);
84 assertEquals(1, egKey.compareTo(other));
85 assertEquals(-1, other.compareTo(egKey));
87 EndpointGroupId egIdOther = mock(EndpointGroupId.class);
88 when(egIdOther.getValue()).thenReturn(valueOther);
90 other = new EgKey(tenantId, egIdOther);
91 assertEquals(1, egKey.compareTo(other));
92 assertEquals(-1, other.compareTo(egKey));
94 egKey = new EgKey(tenantIdOther, egId);
95 assertEquals(-1, egKey.compareTo(other));
96 assertEquals(1, other.compareTo(egKey));
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()));