X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdependencyresolver%2FDependencyResolverManagerTest.java;fp=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdependencyresolver%2FDependencyResolverManagerTest.java;h=0000000000000000000000000000000000000000;hp=0f099e77b0eb32b29f1d8c79414ab3c17b8cfa2c;hb=ac6f2699cd0c1e340cc32e8f0d0ca94c8e9c0cc0;hpb=f43b01b81319959b1907e3e04537f5169e7f33d8 diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManagerTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManagerTest.java deleted file mode 100644 index 0f099e77b0..0000000000 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DependencyResolverManagerTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2013, 2017 Cisco Systems, 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.config.manager.impl.dependencyresolver; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; - -import java.util.Arrays; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.config.api.JmxAttribute; -import org.opendaylight.controller.config.api.ModuleIdentifier; -import org.opendaylight.controller.config.api.ServiceReferenceReadableRegistry; -import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.manager.impl.AbstractLockedPlatformMBeanServerTest; -import org.opendaylight.controller.config.manager.impl.ModuleInternalInfo; -import org.opendaylight.controller.config.manager.impl.TransactionIdentifier; -import org.opendaylight.controller.config.manager.impl.TransactionStatus; -import org.opendaylight.controller.config.manager.impl.jmx.TransactionModuleJMXRegistrator.TransactionModuleJMXRegistration; -import org.opendaylight.controller.config.spi.Module; -import org.opendaylight.controller.config.spi.ModuleFactory; -import org.osgi.framework.BundleContext; - -public class DependencyResolverManagerTest extends AbstractLockedPlatformMBeanServerTest { - - final ModuleIdentifier apspName = new ModuleIdentifier("apsp", "apsp"); // depends - // on: - final ModuleIdentifier threadPoolName = new ModuleIdentifier("threadpool", "threadpool"); // depends on: - final ModuleIdentifier threadFactoryName = new ModuleIdentifier("threadfactory", "threadfactory"); - - private DependencyResolverManager tested; - TransactionStatus transactionStatus; - - @Before - public void setUp() { - transactionStatus = mock(TransactionStatus.class); - ServiceReferenceReadableRegistry mockedRegistry = mock(ServiceReferenceReadableRegistry.class); - tested = new DependencyResolverManager(new TransactionIdentifier("txName"), transactionStatus, mockedRegistry, - null, platformMBeanServer); - doNothing().when(transactionStatus).checkCommitStarted(); - doNothing().when(transactionStatus).checkNotCommitted(); - } - - @Test - public void testOrdering() { - final DependencyResolverImpl apspDRI = tested.getOrCreate(apspName); - mockGetInstance(tested, apspName); - final DependencyResolverImpl threadPoolDRI = tested.getOrCreate(threadPoolName); - mockGetInstance(tested, threadPoolName); - tested.getOrCreate(threadFactoryName); - mockGetInstance(tested, threadFactoryName); - - // set threadfactory as dependency of threadpool - declareDependency(threadPoolDRI, threadFactoryName); - // set threadpool as dependency of apsp - declareDependency(apspDRI, threadPoolName); - - // switch to second phase committed - reset(transactionStatus); - doNothing().when(transactionStatus).checkCommitStarted(); - doNothing().when(transactionStatus).checkCommitted(); - doNothing().when(transactionStatus).checkNotCommitted(); - - List sortedModuleIdentifiers = tested.getSortedModuleIdentifiers(); - assertEquals(Arrays.asList(threadFactoryName, threadPoolName, apspName), sortedModuleIdentifiers); - } - - /** - * Simulate dependentResolver resolving its dependency identified by - * dependentName. - */ - private static void declareDependency(final DependencyResolverImpl dependerResolver, - final ModuleIdentifier dependentName) { - JmxAttribute dummyAttribute = new JmxAttribute("dummy"); - dependerResolver.resolveInstance(Object.class, ObjectNameUtil.createReadOnlyModuleON(dependentName), - dummyAttribute); - } - - private static void mockGetInstance(final DependencyResolverManager tested, - final ModuleIdentifier moduleIdentifier) { - - ModuleFactory moduleFactory = mock(ModuleFactory.class); - ModuleInternalInfo maybeOldInternalInfo = null; - TransactionModuleJMXRegistration transactionModuleJMXRegistration = null; - boolean isDefaultBean = false; - - tested.put(moduleIdentifier, mockedModule(), moduleFactory, maybeOldInternalInfo, - transactionModuleJMXRegistration, isDefaultBean, mock(BundleContext.class)); - } - - private static Module mockedModule() { - Module mockedModule = mock(Module.class); - doReturn(mock(AutoCloseable.class)).when(mockedModule).getInstance(); - doReturn(new ModuleIdentifier("fact", "instance")).when(mockedModule).getIdentifier(); - return mockedModule; - } -}