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.eos.common.api;
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;
15 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipChangeState;
18 * Unit tests for EntityOwnershipChangeState.
20 * @author Thomas Pantelis
22 public class EntityOwnershipChangeStateTest {
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));
38 @Test(expected=IllegalArgumentException.class)
39 public void testFromWithInvalidFalseTrueFalse() {
40 EntityOwnershipChangeState.from(false, true, false);
43 @Test(expected=IllegalArgumentException.class)
44 public void testFromWithInvalidTrueTrueFalse() {
45 EntityOwnershipChangeState.from(true, true, false);
48 @Test(expected=IllegalArgumentException.class)
49 public void testFromWithInvalidTrueTrueTrue() {
50 EntityOwnershipChangeState.from(true, true, true);
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.*"));