import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.config.api.ValidationException;
-import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace;
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;
import javax.management.JMX;
import javax.management.ObjectName;
import java.util.Collections;
-import java.util.Map;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
doReturn(mockedSysBundle).when(mockedContext).getBundle(0);
mockedContext.getBundle(0);
doNothing().when(mockedSysBundle).stop();
+ ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+ // initialize default instance
+ transaction.commit();
}
@Test
}
}
+ private static final ObjectName runtimeON = ObjectNameUtil.createRuntimeBeanName(NAME, NAME, Collections.<String, String>emptyMap());
+
@Test
public void testWithoutSecret() throws Exception {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- transaction.createModule(NAME, NAME);
- transaction.commit();
// test JMX rpc
- ObjectName runtimeON = ObjectNameUtil.createRuntimeBeanName(NAME, NAME, Collections.<String, String>emptyMap());
+
ShutdownRuntimeMXBean runtime = configRegistryClient.newMXBeanProxy(runtimeON, ShutdownRuntimeMXBean.class);
try {
- runtime.shutdown("foo", null);
+ runtime.shutdown("foo", 60000L, null);
fail();
} catch (IllegalArgumentException e) {
assertEquals("Invalid secret", e.getMessage());
}
- runtime.shutdown("", null);
+ runtime.shutdown("", 60000L, null);
assertStopped();
}
@Test
public void testWithSecret() throws Exception {
ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- ObjectName on = transaction.createModule(NAME, NAME);
+ ObjectName on = transaction.lookupConfigBean(NAME, NAME);
ShutdownModuleMXBean proxy = transaction.newMXBeanProxy(on, ShutdownModuleMXBean.class);
String secret = "secret";
proxy.setSecret(secret);
transaction.commit();
shutdownViaRuntimeJMX(secret);
-
- // test old secret
- transaction = configRegistryClient.createTransaction();
- on = transaction.lookupConfigBean(NAME, NAME);
- proxy = transaction.newMXBeanProxy(on, ShutdownModuleMXBean.class);
- try {
- rethrowCause(proxy).getOldSecret();
- fail();
- } catch (UnsupportedOperationException e) {
- }
try {
- rethrowCause(proxy).getSecret();
+ ShutdownRuntimeMXBean runtime = JMX.newMXBeanProxy(platformMBeanServer, runtimeON, ShutdownRuntimeMXBean.class);
+ runtime.shutdown("foo", 60000L, null);
fail();
- } catch (UnsupportedOperationException e) {
- }
- // set secret to nothing
- String newSecret = "newSecret";
- proxy.setSecret(newSecret);
- try {
- transaction.commit();
- fail("Old secret not provided - should fail validation");
- } catch (ValidationException e) {
- Map<String, Map<String, ExceptionMessageWithStackTrace>> failedValidations = e.getFailedValidations();
- assertTrue(failedValidations.containsKey(NAME));
- ExceptionMessageWithStackTrace exceptionMessageWithStackTrace = failedValidations.get(NAME).get(NAME);
- assertNotNull(exceptionMessageWithStackTrace);
- assertEquals("OldSecret Invalid old secret", exceptionMessageWithStackTrace.getMessage());
-
+ } catch (IllegalArgumentException e) {
+ assertEquals("Invalid secret", e.getMessage());
}
- proxy.setOldSecret(secret);
- transaction.commit();
- shutdownViaRuntimeJMX(newSecret);
}
private void shutdownViaRuntimeJMX(String secret) throws Exception {
// test JMX rpc
- ObjectName runtimeON = ObjectNameUtil.createRuntimeBeanName(NAME, NAME, Collections.<String, String>emptyMap());
ShutdownRuntimeMXBean runtime = JMX.newMXBeanProxy(platformMBeanServer, runtimeON, ShutdownRuntimeMXBean.class);
try {
- runtime.shutdown("", null);
+ runtime.shutdown("", 60000L, null);
fail();
} catch (IllegalArgumentException e) {
assertEquals("Invalid secret", e.getMessage());
}
- runtime.shutdown(secret, null);
+ runtime.shutdown(secret, 60000L, null);
assertStopped();
}