Search in sources :

Example 6 with ScanManagerConfig

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());
}
Also used : ScanManagerConfig(com.sun.jmx.examples.scandir.config.ScanManagerConfig) DirectoryScannerConfig(com.sun.jmx.examples.scandir.config.DirectoryScannerConfig) XmlConfigUtils(com.sun.jmx.examples.scandir.config.XmlConfigUtils) File(java.io.File)

Aggregations

ScanManagerConfig (com.sun.jmx.examples.scandir.config.ScanManagerConfig)6 DirectoryScannerConfig (com.sun.jmx.examples.scandir.config.DirectoryScannerConfig)5 File (java.io.File)5 XmlConfigUtils (com.sun.jmx.examples.scandir.config.XmlConfigUtils)3 FileMatch (com.sun.jmx.examples.scandir.config.FileMatch)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1