X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fshutdown-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fshutdown%2Fimpl%2FShutdownTest.java;h=d1abe08d52b64453ee038a8a8b053e80ae08c586;hb=df2aabb0c61b9be04623c2a660c5a1592ff051f7;hp=5887e98f30daa4816da2bfb1e1215a6385ebc783;hpb=61b7635939c25009bbd12449d9b6aaddd100b982;p=controller.git 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 5887e98f30..d1abe08d52 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 @@ -18,6 +18,7 @@ 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; @@ -26,15 +27,14 @@ 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.reset; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; 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; + private Bundle mockedSysBundle, mockedConfigManager; + @Before public void setUp() throws Exception { @@ -44,6 +44,13 @@ 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("system bundle").when(mockedSysBundle).getSymbolicName(); + doReturn(StopSystemBundleThread.CONFIG_MANAGER_SYMBOLIC_NAME).when(mockedConfigManager).getSymbolicName(); + + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); // initialize default instance transaction.commit(); @@ -80,13 +87,22 @@ public class ShutdownTest extends AbstractConfigTest { @Test public void testWithSecret() throws Exception { + String secret = "secret"; + setSecret(secret); + shutdownViaRuntimeJMX(secret); + } + + private void setSecret(String secret) throws InstanceNotFoundException { ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); ObjectName on = transaction.lookupConfigBean(NAME, NAME); ShutdownModuleMXBean proxy = transaction.newMXBeanProxy(on, ShutdownModuleMXBean.class); - String secret = "secret"; proxy.setSecret(secret); transaction.commit(); - shutdownViaRuntimeJMX(secret); + } + + @Test + public void testWrongSecret() throws Exception { + setSecret("secret"); try { ShutdownRuntimeMXBean runtime = JMX.newMXBeanProxy(platformMBeanServer, runtimeON, ShutdownRuntimeMXBean.class); runtime.shutdown("foo", 60000L, null); @@ -109,12 +125,9 @@ public class ShutdownTest extends AbstractConfigTest { assertStopped(); } - private void assertStopped() throws Exception { - Thread.sleep(2000); // happens on another thread + Thread.sleep(3000); // happens on another thread + verify(mockedConfigManager).stop(); verify(mockedSysBundle).stop(); - verifyNoMoreInteractions(mockedSysBundle); - reset(mockedSysBundle); - doNothing().when(mockedSysBundle).stop(); } }