From: Michael Vorburger Date: Thu, 1 Jun 2017 00:53:05 +0000 (+0200) Subject: sal-common-testutil TestEntityOwnershipService X-Git-Tag: release/nitrogen~143 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=refs%2Fchanges%2F89%2F58089%2F5 sal-common-testutil TestEntityOwnershipService moved from existing (and already used there) org.opendaylight.genius.interfacemanager.test.infra, because I now need to also use this in a new component test for netvirt fibmanager, so instead of copy/pasting it, let's have it here. Change-Id: I4a524594f9d4bf0da6015738ef3b454eba13159d Signed-off-by: Michael Vorburger --- diff --git a/opendaylight/md-sal/pom.xml b/opendaylight/md-sal/pom.xml index 1c4ad1c5f2..39367d2838 100644 --- a/opendaylight/md-sal/pom.xml +++ b/opendaylight/md-sal/pom.xml @@ -21,6 +21,7 @@ sal-common-api sal-common-impl sal-common-util + sal-common-testutil sal-dom-api diff --git a/opendaylight/md-sal/sal-common-testutil/pom.xml b/opendaylight/md-sal/sal-common-testutil/pom.xml new file mode 100644 index 0000000000..a320a9a1ca --- /dev/null +++ b/opendaylight/md-sal/sal-common-testutil/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + + + org.opendaylight.odlparent + odlparent + 1.9.0-SNAPSHOT + + + + org.opendaylight.controller + sal-common-testutil + 1.6.0-SNAPSHOT + + + + ${project.groupId} + sal-common-api + ${project.version} + + + org.mockito + mockito-core + compile + + + org.opendaylight.yangtools + testutils + 1.2.0-SNAPSHOT + + + diff --git a/opendaylight/md-sal/sal-common-testutil/src/main/java/org/opendaylight/controller/md/sal/common/api/clustering/testutil/TestEntityOwnershipService.java b/opendaylight/md-sal/sal-common-testutil/src/main/java/org/opendaylight/controller/md/sal/common/api/clustering/testutil/TestEntityOwnershipService.java new file mode 100644 index 0000000000..230f59c5ff --- /dev/null +++ b/opendaylight/md-sal/sal-common-testutil/src/main/java/org/opendaylight/controller/md/sal/common/api/clustering/testutil/TestEntityOwnershipService.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.common.api.clustering.testutil; + +import static org.opendaylight.yangtools.testutils.mockito.MoreAnswers.realOrException; + +import com.google.common.base.Optional; +import org.mockito.Mockito; +import org.opendaylight.controller.md.sal.common.api.clustering.Entity; +import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration; +import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener; +import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration; +import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService; +import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState; + +/** + * Fake EntityOwnershipService suitable for non-clustered component tests. + * + * @author Michael Vorburger + */ +public abstract class TestEntityOwnershipService implements EntityOwnershipService { + + private static final EntityOwnershipState STATE = new EntityOwnershipState(true, true); + + public static EntityOwnershipService newInstance() { + return Mockito.mock(TestEntityOwnershipService.class, realOrException()); + } + + @Override + public EntityOwnershipCandidateRegistration registerCandidate(Entity entity) { + return Mockito.mock(EntityOwnershipCandidateRegistration.class, realOrException()); + } + + @Override + public EntityOwnershipListenerRegistration registerListener(String entityType, EntityOwnershipListener listener) { + return Mockito.mock(EntityOwnershipListenerRegistration.class, realOrException()); + } + + @Override + public Optional getOwnershipState(Entity forEntity) { + return Optional.of(STATE); + } + + @Override + public boolean isCandidateRegistered(Entity entity) { + return true; + } +}