Move OperationLimiter.acquire() warnings to callers
[controller.git] / opendaylight / md-sal / sal-common-testutil / src / main / java / org / opendaylight / controller / md / sal / common / api / clustering / testutil / TestEntityOwnershipService.java
1 /*
2  * Copyright (c) 2016 Red Hat, 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.controller.md.sal.common.api.clustering.testutil;
9
10 import static org.opendaylight.yangtools.testutils.mockito.MoreAnswers.realOrException;
11
12 import com.google.common.base.Optional;
13 import org.mockito.Mockito;
14 import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
15 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
16 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
17 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
18 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
19 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState;
20
21 /**
22  * Fake EntityOwnershipService suitable for non-clustered component tests.
23  *
24  * @author Michael Vorburger
25  */
26 public abstract class TestEntityOwnershipService implements EntityOwnershipService {
27
28     private static final EntityOwnershipState STATE = new EntityOwnershipState(true, true);
29
30     public static EntityOwnershipService newInstance() {
31         return Mockito.mock(TestEntityOwnershipService.class, realOrException());
32     }
33
34     @Override
35     public EntityOwnershipCandidateRegistration registerCandidate(Entity entity) {
36         return Mockito.mock(EntityOwnershipCandidateRegistration.class, realOrException());
37     }
38
39     @Override
40     public EntityOwnershipListenerRegistration registerListener(String entityType, EntityOwnershipListener listener) {
41         return Mockito.mock(EntityOwnershipListenerRegistration.class, realOrException());
42     }
43
44     @Override
45     public Optional<EntityOwnershipState> getOwnershipState(Entity forEntity) {
46         return Optional.of(STATE);
47     }
48
49     @Override
50     public boolean isCandidateRegistered(Entity entity) {
51         return true;
52     }
53 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.