Merge " Added new feature *odl-ovsdb-openstack-clusteraware*."
[netvirt.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / AbstractEventTest.java
1 /*
2  * Copyright (c) 2015 Inocybe 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
9 package org.opendaylight.ovsdb.openstack.netvirt;
10
11 import static org.junit.Assert.*;
12
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent.HandlerType;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
17
18 /**
19  * Unit test for {@link AbstractEvent}
20  */
21 public class AbstractEventTest {
22
23     private AbstractEventChild1 abstractEvent1;
24     private AbstractEventChild2 abstractEvent2;
25     private AbstractEventChild2 abstractEvent3;
26
27     class AbstractEventChild1 extends AbstractEvent{
28         protected AbstractEventChild1(HandlerType handlerType, Action action) {
29             super(handlerType, action);
30         }
31
32     }
33
34     class AbstractEventChild2 extends AbstractEvent{
35         protected AbstractEventChild2(HandlerType handlerType, Action action) {
36             super(handlerType, action);
37         }
38     }
39
40
41     @Before
42     public void setUp(){
43          abstractEvent1 = new AbstractEventChild1(HandlerType.SOUTHBOUND, Action.DELETE);
44          abstractEvent2 = new AbstractEventChild2(HandlerType.NEUTRON_FLOATING_IP, Action.ADD);
45          abstractEvent3 = abstractEvent2;
46     }
47
48     @Test
49     public void testAbstractEvent(){
50         assertEquals("Error, getAction() did not return the correct value", Action.DELETE, abstractEvent1.getAction());
51
52         assertEquals("Error, getHandlerType() did not return the correct value", HandlerType.SOUTHBOUND, abstractEvent1.getHandlerType());
53
54         assertTrue("Error, equals() did not succeed", abstractEvent2.equals(abstractEvent3));
55
56         assertNotNull("Error, hashCode() did not return any value", abstractEvent1.hashCode());
57         assertEquals("Error, hashCode() is not consistent", abstractEvent2.hashCode(), abstractEvent3.hashCode());
58
59         int transactionId = abstractEvent1.getTransactionId();
60         assertEquals("Error, toString() did not return the correct value",
61                 "AbstractEvent [transactionId=" + transactionId + " handlerType=SOUTHBOUND action=DELETE]", abstractEvent1.toString());
62     }
63 }