X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fnetty-event-executor-config%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fnetty%2Feventexecutor%2FGlobalEventExecutorModuleTest.java;h=7d763699ffd4e7d3ba9bad4ec0f6eb6bbb2960e6;hp=6af508829be93eb6b64157562806753596b2ae64;hb=dceb9db7853dabfbd4abdfb3d886a79871097831;hpb=18a090d8e17e83debe6748b4db865435aeab88c8 diff --git a/opendaylight/config/netty-event-executor-config/src/test/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModuleTest.java b/opendaylight/config/netty-event-executor-config/src/test/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModuleTest.java index 6af508829b..7d763699ff 100644 --- a/opendaylight/config/netty-event-executor-config/src/test/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModuleTest.java +++ b/opendaylight/config/netty-event-executor-config/src/test/java/org/opendaylight/controller/config/yang/netty/eventexecutor/GlobalEventExecutorModuleTest.java @@ -1,8 +1,23 @@ +/* + * Copyright (c) 2013 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.yang.netty.eventexecutor; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import io.netty.util.concurrent.EventExecutor; import javax.management.InstanceAlreadyExistsException; import javax.management.ObjectName; - import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.config.api.ConflictingVersionException; @@ -11,16 +26,29 @@ import org.opendaylight.controller.config.api.jmx.CommitStatus; import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; +import org.osgi.framework.Filter; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; public class GlobalEventExecutorModuleTest extends AbstractConfigTest { private GlobalEventExecutorModuleFactory factory; - private final String instanceName = "netty1"; + private final String instanceName = GlobalEventExecutorModuleFactory.SINGLETON_NAME; + @SuppressWarnings({ "rawtypes", "unchecked" }) @Before - public void setUp() { + public void setUp() throws Exception { factory = new GlobalEventExecutorModuleFactory(); - super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory)); + super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,factory)); + + Filter mockFilter = mock(Filter.class); + doReturn("mock").when(mockFilter).toString(); + doReturn(mockFilter).when(mockedContext).createFilter(anyString()); + doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), anyString()); + ServiceReference mockServiceRef = mock(ServiceReference.class); + doReturn(new ServiceReference[]{mockServiceRef}).when(mockedContext). + getServiceReferences(anyString(), anyString()); + doReturn(mock(EventExecutor.class)).when(mockedContext).getService(mockServiceRef); } @Test @@ -29,12 +57,23 @@ public class GlobalEventExecutorModuleTest extends AbstractConfigTest { ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); createInstance(transaction, instanceName); - createInstance(transaction, instanceName + 2); + transaction.validateConfig(); CommitStatus status = transaction.commit(); - assertBeanCount(2, factory.getImplementationName()); - assertStatus(status, 2, 0, 0); + assertBeanCount(1, factory.getImplementationName()); + assertStatus(status, 1, 0, 0); + } + + @Test + public void testConflictingName() throws Exception { + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); + try { + createInstance(transaction, instanceName + "x"); + fail(); + }catch(IllegalArgumentException e){ + assertTrue(e.getMessage() + " failure", e.getMessage().contains("only allowed name is singleton")); + } } @Test @@ -57,7 +96,7 @@ public class GlobalEventExecutorModuleTest extends AbstractConfigTest { private ObjectName createInstance(ConfigTransactionJMXClient transaction, String instanceName) throws InstanceAlreadyExistsException { ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName); - transaction.newMBeanProxy(nameCreated, GlobalEventExecutorModuleMXBean.class); + transaction.newMXBeanProxy(nameCreated, GlobalEventExecutorModuleMXBean.class); return nameCreated; }