use of com.sun.jmx.examples.scandir.config.ScanManagerConfig in project jdk8u_jdk by JetBrains.
the class ScanDirConfigTest method testSave.
/**
* Test of save method, of class com.sun.jmx.examples.scandir.ScanDirConfig.
*/
public void testSave() throws Exception {
System.out.println("save");
final File file = File.createTempFile("testconf", ".xml");
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
final ScanManagerMXBean manager = ScanManager.register(mbs);
try {
final ScanDirConfigMXBean instance = manager.createOtherConfigurationMBean("testSave", file.getAbsolutePath());
assertTrue(mbs.isRegistered(ScanManager.makeScanDirConfigName("testSave")));
final ScanManagerConfig bean = new ScanManagerConfig("testSave");
final DirectoryScannerConfig dir = new DirectoryScannerConfig("tmp");
dir.setRootDirectory(file.getParent());
bean.putScan(dir);
instance.setConfiguration(bean);
instance.save();
final ScanManagerConfig loaded = new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
assertEquals(instance.getConfiguration(), loaded);
assertEquals(bean, loaded);
instance.getConfiguration().removeScan("tmp");
instance.save();
assertNotSame(loaded, instance.getConfiguration());
final ScanManagerConfig loaded2 = new XmlConfigUtils(file.getAbsolutePath()).readFromFile();
assertEquals(instance.getConfiguration(), loaded2);
} finally {
manager.close();
mbs.unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
}
final ObjectName all = new ObjectName(ScanManager.SCAN_MANAGER_NAME.getDomain() + ":*");
assertEquals(0, mbs.queryNames(all, null).size());
}
Aggregations