X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fnetty-timer-config%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fnetty%2Ftimer%2FHashedWheelTimerModuleTest.java;h=87d621f181d96ff85bbe168f069559919b18ca06;hb=b25f55c6265708661db0a43fccc595f7fdd81767;hp=6ffeb0490d0539874d7cc59e0b07507f1f073a20;hpb=ea980e87f8ac521022dfd776c5186819a8a38fd2;p=controller.git diff --git a/opendaylight/config/netty-timer-config/src/test/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModuleTest.java b/opendaylight/config/netty-timer-config/src/test/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModuleTest.java index 6ffeb0490d..87d621f181 100644 --- a/opendaylight/config/netty-timer-config/src/test/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModuleTest.java +++ b/opendaylight/config/netty-timer-config/src/test/java/org/opendaylight/controller/config/yang/netty/timer/HashedWheelTimerModuleTest.java @@ -9,7 +9,12 @@ package org.opendaylight.controller.config.yang.netty.timer; 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.Timer; import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceNotFoundException; import javax.management.ObjectName; @@ -23,6 +28,9 @@ import org.opendaylight.controller.config.manager.impl.factoriesresolver.Hardcod import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleFactory; import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean; +import org.osgi.framework.Filter; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; public class HashedWheelTimerModuleTest extends AbstractConfigTest { @@ -30,11 +38,21 @@ public class HashedWheelTimerModuleTest extends AbstractConfigTest { private NamingThreadFactoryModuleFactory threadFactory; private final String instanceName = "hashed-wheel-timer1"; + @SuppressWarnings({ "rawtypes", "unchecked" }) @Before - public void setUp() { + public void setUp() throws Exception { factory = new HashedWheelTimerModuleFactory(); threadFactory = new NamingThreadFactoryModuleFactory(); super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, factory, threadFactory)); + + 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(Timer.class)).when(mockedContext).getService(mockServiceRef); } public void testValidationExceptionTickDuration() throws InstanceAlreadyExistsException { @@ -43,7 +61,7 @@ public class HashedWheelTimerModuleTest extends AbstractConfigTest { createInstance(transaction, instanceName, 0L, 10, true); transaction.validateConfig(); fail(); - } catch (ValidationException e) { + } catch (final ValidationException e) { assertTrue(e.getMessage().contains("TickDuration value must be greater than 0")); } } @@ -54,7 +72,7 @@ public class HashedWheelTimerModuleTest extends AbstractConfigTest { createInstance(transaction, instanceName, 500L, 0, true); transaction.validateConfig(); fail(); - } catch (ValidationException e) { + } catch (final ValidationException e) { assertTrue(e.getMessage().contains("TicksPerWheel value must be greater than 0")); } }