X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fshutdown-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fshutdown%2Fimpl%2FShutdownTest.java;h=5dd856a605b82d0f6a80502f4e89158e7e14fcd8;hp=d1abe08d52b64453ee038a8a8b053e80ae08c586;hb=1417bcd892b1dc9a4d68c9562d91eee8320de38f;hpb=f04d241578740473fc8b9f17fe38db6f8ea17f02 diff --git a/opendaylight/config/shutdown-impl/src/test/java/org/opendaylight/controller/config/yang/shutdown/impl/ShutdownTest.java b/opendaylight/config/shutdown-impl/src/test/java/org/opendaylight/controller/config/yang/shutdown/impl/ShutdownTest.java index d1abe08d52..5dd856a605 100644 --- a/opendaylight/config/shutdown-impl/src/test/java/org/opendaylight/controller/config/yang/shutdown/impl/ShutdownTest.java +++ b/opendaylight/config/shutdown-impl/src/test/java/org/opendaylight/controller/config/yang/shutdown/impl/ShutdownTest.java @@ -7,10 +7,23 @@ */ package org.opendaylight.controller.config.yang.shutdown.impl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.opendaylight.controller.config.yang.shutdown.impl.ShutdownModuleFactory.NAME; + +import java.util.Collections; +import javax.management.InstanceNotFoundException; +import javax.management.JMX; +import javax.management.ObjectName; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.config.api.ConflictingVersionException; +import org.opendaylight.controller.config.api.ValidationException; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; @@ -18,22 +31,10 @@ import org.opendaylight.controller.config.manager.impl.factoriesresolver.ModuleF import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; import org.osgi.framework.Bundle; -import javax.management.InstanceNotFoundException; -import javax.management.JMX; -import javax.management.ObjectName; -import java.util.Collections; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; -import static org.opendaylight.controller.config.yang.shutdown.impl.ShutdownModuleFactory.NAME; - public class ShutdownTest extends AbstractConfigTest { private final ShutdownModuleFactory factory = new ShutdownModuleFactory(); @Mock - private Bundle mockedSysBundle, mockedConfigManager; + private Bundle mockedSysBundle; @Before @@ -44,11 +45,10 @@ public class ShutdownTest extends AbstractConfigTest { doReturn(mockedSysBundle).when(mockedContext).getBundle(0); mockedContext.getBundle(0); doNothing().when(mockedSysBundle).stop(); - doNothing().when(mockedConfigManager).stop(); doReturn(mockedContext).when(mockedSysBundle).getBundleContext(); - doReturn(new Bundle[]{mockedSysBundle, mockedConfigManager}).when(mockedContext).getBundles(); + doReturn(new Bundle[]{mockedSysBundle}).when(mockedContext).getBundles(); doReturn("system bundle").when(mockedSysBundle).getSymbolicName(); - doReturn(StopSystemBundleThread.CONFIG_MANAGER_SYMBOLIC_NAME).when(mockedConfigManager).getSymbolicName(); + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); @@ -62,7 +62,7 @@ public class ShutdownTest extends AbstractConfigTest { try { transaction.createModule(NAME, "foo"); fail(); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { assertEquals("Singleton enforcement failed. Expected instance name shutdown", e.getMessage()); } } @@ -77,7 +77,7 @@ public class ShutdownTest extends AbstractConfigTest { try { runtime.shutdown("foo", 60000L, null); fail(); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { assertEquals("Invalid secret", e.getMessage()); } runtime.shutdown("", 60000L, null); @@ -92,7 +92,7 @@ public class ShutdownTest extends AbstractConfigTest { shutdownViaRuntimeJMX(secret); } - private void setSecret(String secret) throws InstanceNotFoundException { + private void setSecret(final String secret) throws InstanceNotFoundException, ValidationException, ConflictingVersionException { ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); ObjectName on = transaction.lookupConfigBean(NAME, NAME); ShutdownModuleMXBean proxy = transaction.newMXBeanProxy(on, ShutdownModuleMXBean.class); @@ -107,18 +107,18 @@ public class ShutdownTest extends AbstractConfigTest { ShutdownRuntimeMXBean runtime = JMX.newMXBeanProxy(platformMBeanServer, runtimeON, ShutdownRuntimeMXBean.class); runtime.shutdown("foo", 60000L, null); fail(); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { assertEquals("Invalid secret", e.getMessage()); } } - private void shutdownViaRuntimeJMX(String secret) throws Exception { + private void shutdownViaRuntimeJMX(final String secret) throws Exception { // test JMX rpc ShutdownRuntimeMXBean runtime = JMX.newMXBeanProxy(platformMBeanServer, runtimeON, ShutdownRuntimeMXBean.class); try { runtime.shutdown("", 60000L, null); fail(); - } catch (IllegalArgumentException e) { + } catch (final IllegalArgumentException e) { assertEquals("Invalid secret", e.getMessage()); } runtime.shutdown(secret, 60000L, null); @@ -127,7 +127,6 @@ public class ShutdownTest extends AbstractConfigTest { private void assertStopped() throws Exception { Thread.sleep(3000); // happens on another thread - verify(mockedConfigManager).stop(); verify(mockedSysBundle).stop(); } }