2 * Copyright (c) 2015 Brocade Communications 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.controller.md.sal.common.api.clustering;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
13 import org.apache.commons.lang3.SerializationUtils;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 * Unit tests for Entity.
21 * @author Thomas Pantelis
23 public class EntityTest {
24 static String ENTITY_TYPE1 = "type1";
25 static String ENTITY_TYPE2 = "type2";
26 static final QName QNAME1 = QName.create("test", "2015-08-14", "1");
27 static final QName QNAME2 = QName.create("test", "2015-08-14", "2");
28 static final YangInstanceIdentifier YANGID1 = YangInstanceIdentifier.of(QNAME1);
29 static final YangInstanceIdentifier YANGID2 = YangInstanceIdentifier.of(QNAME2);
32 public void testHashCode() {
33 Entity entity1 = new Entity(ENTITY_TYPE1, YANGID1);
35 assertEquals("hashCode", entity1.hashCode(), new Entity(ENTITY_TYPE1, YANGID1).hashCode());
36 assertNotEquals("hashCode", entity1.hashCode(), new Entity(ENTITY_TYPE2, YANGID2).hashCode());
40 public void testEquals() {
41 Entity entity1 = new Entity(ENTITY_TYPE1, YANGID1);
43 assertEquals("Same", true, entity1.equals(entity1));
44 assertEquals("Same", true, entity1.equals(new Entity(ENTITY_TYPE1, YANGID1)));
45 assertEquals("Different entity type", false, entity1.equals(new Entity(ENTITY_TYPE2, YANGID1)));
46 assertEquals("Different yang ID", false, entity1.equals(new Entity(ENTITY_TYPE1, YANGID2)));
47 assertEquals("Different Object", false, entity1.equals(new Object()));
48 assertEquals("Equals null", false, entity1.equals(null));
52 public void testSerialization() {
53 Entity entity = new Entity(ENTITY_TYPE1, YANGID1);
55 Entity clone = SerializationUtils.clone(entity);
57 assertEquals("getType", entity.getType(), clone.getType());
58 assertEquals("getId", entity.getId(), clone.getId());