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