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.mdsal.common.api.clustering;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
14 import org.junit.Test;
17 * Unit tests for EntityOwnershipChangeState.
19 * @author Thomas Pantelis
21 public class EntityOwnershipChangeStateTest {
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));
37 @Test(expected=IllegalArgumentException.class)
38 public void testFromWithInvalidFalseTrueFalse() {
39 EntityOwnershipChangeState.from(false, true, false);
42 @Test(expected=IllegalArgumentException.class)
43 public void testFromWithInvalidTrueTrueFalse() {
44 EntityOwnershipChangeState.from(true, true, false);
47 @Test(expected=IllegalArgumentException.class)
48 public void testFromWithInvalidTrueTrueTrue() {
49 EntityOwnershipChangeState.from(true, true, true);
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.*"));