Move Adapter for Binding EntityOwnershipService
[mdsal.git] / entityownership / mdsal-eos-common-api / src / test / java / org / opendaylight / mdsal / common / api / clustering / EntityOwnershipChangeStateTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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.mdsal.common.api.clustering;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13
14 import org.junit.Test;
15
16 /**
17  * Unit tests for EntityOwnershipChangeState.
18  *
19  * @author Thomas Pantelis
20  */
21 public class EntityOwnershipChangeStateTest {
22
23     @Test
24     public void testFromWithValid() throws Exception {
25         assertEquals("from(false, true, true)", EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED,
26                 EntityOwnershipChangeState.from(false, true, true));
27         assertEquals("from(true, false, true)", EntityOwnershipChangeState.LOCAL_OWNERSHIP_LOST_NEW_OWNER,
28                 EntityOwnershipChangeState.from(true, false, true));
29         assertEquals("from(true, false, false)", EntityOwnershipChangeState.LOCAL_OWNERSHIP_LOST_NO_OWNER,
30                 EntityOwnershipChangeState.from(true, false, false));
31         assertEquals("from(false, false, true)", EntityOwnershipChangeState.REMOTE_OWNERSHIP_CHANGED,
32                 EntityOwnershipChangeState.from(false, false, true));
33         assertEquals("from(false, false, false)", EntityOwnershipChangeState.REMOTE_OWNERSHIP_LOST_NO_OWNER,
34                 EntityOwnershipChangeState.from(false, false, false));
35     }
36
37     @Test(expected=IllegalArgumentException.class)
38     public void testFromWithInvalidFalseTrueFalse() {
39         EntityOwnershipChangeState.from(false, true, false);
40     }
41
42     @Test(expected=IllegalArgumentException.class)
43     public void testFromWithInvalidTrueTrueFalse() {
44         EntityOwnershipChangeState.from(true, true, false);
45     }
46
47     @Test(expected=IllegalArgumentException.class)
48     public void testFromWithInvalidTrueTrueTrue() {
49         EntityOwnershipChangeState.from(true, true, true);
50     }
51
52     @Test
53     public void basicTest() throws Exception {
54         EntityOwnershipChangeState entityOwnershipChangeState = EntityOwnershipChangeState.from(false, true, true);
55         assertTrue(entityOwnershipChangeState.hasOwner());
56         assertTrue(entityOwnershipChangeState.isOwner());
57         assertFalse(entityOwnershipChangeState.wasOwner());
58         assertTrue(entityOwnershipChangeState.toString().matches(".*false.*true.*true.*"));
59     }
60 }