ServerHandle { protected JSONObject getDetectorOptions(Configuration pConfig, LogHandler pLogHandler) { String options = pConfig.get(ConfigKey.DETECTOR_OPTIONS); try { if (options != null) { JSONObject opts = (JSONObject) new JSONParser().parse(options); return (JSONObject) opts.get(getProduct()); } return null; } catch (ParseException e) { pLogHandler.error("Could not parse detector options '" + options + "' as JSON object: " + e,e); } return null; } ServerHandle(String vendor, String product, String version, Map<String, String> extraInfo); String getVendor(); String getProduct(); String getVersion(); Map<String,String> getExtraInfo(MBeanServerExecutor pServerManager); void preDispatch(MBeanServerExecutor pMBeanServerExecutor, JmxRequest pJmxReq); void postDetect(MBeanServerExecutor pServerManager, Configuration pConfig, LogHandler pLoghandler); ObjectName registerMBeanAtServer(MBeanServer pServer, Object pMBean, String pName); JSONObject toJSONObject(MBeanServerExecutor pServerManager);  }
@Test public void detectorOptions() { Configuration opts = new Configuration(ConfigKey.DETECTOR_OPTIONS, "{\"dukeNukem\" : {\"doIt\" : true }}"); JSONObject config = serverHandle.getDetectorOptions(opts,null); assertTrue((Boolean) config.get("doIt")); }
@Test public void detectorOptionsEmpty() { JSONObject config = serverHandle.getDetectorOptions(new Configuration(),null); assertNull(config); }
@Test public void detectOptionsFail() { LogHandler handler = EasyMock.createMock(LogHandler.class); handler.error(matches("^.*parse detector options.*"),isA(Exception.class)); replay(handler); Configuration opts = new Configuration(ConfigKey.DETECTOR_OPTIONS,"blub: bla"); JSONObject config = serverHandle.getDetectorOptions(opts,handler); assertNull(config); verify(handler); }