Map<String, ProbeDesc<? extends Object>> probesMap = conf.setProbeDescMap(); if(args.length == 0) { dumpAll(probesMap.values());
for(ProbeDesc<?> pd: confjar.setProbeDescMap().values()) { Class<?> pc = pd.getProbeClass(); while (pc != null && pc != StarterNode.class) {
@Test public void testFullConfigpath() throws Exception { PropertiesManager localpm = Tools.makePm(testFolder); ConfigObjectFactory conf = new ConfigObjectFactory(localpm, localpm.extensionClassLoader); conf.getNodeMap(ConfigType.PROBEDESC).put("name", Tools.parseRessource("httpxmlprobedesc.xml")); ProbeDesc<?> pd = conf.setProbeDescMap().get("name"); Assert.assertNotNull("Probedesc not build", pd); }
@Test public void testDefaultArgs() throws Exception { PropertiesManager localpm = Tools.makePm(testFolder); ConfigObjectFactory conf = new ConfigObjectFactory(localpm, localpm.extensionClassLoader); JrdsDocument pddoc = Tools.parseRessource("beans.xml"); pddoc.getRootElement().getElementbyName("probeClass").setTextContent("jrds.mockobjects.MokeProbeBean"); conf.getNodeMap(ConfigType.PROBEDESC).put("name", pddoc); ProbeDesc<?> pd = conf.setProbeDescMap().get("name"); Assert.assertEquals("bean default value not found", "defaultattr1", pd.getDefaultBeans().get("customattr1").value); Assert.assertEquals("default attribute not delayed", true, pd.getDefaultBeans().get("customattr2").delayed); }
conf.setArchiveSetMap(); conf.setGraphDescMap(); Map<String, ProbeDesc<?>> allProbeDesc = conf.setProbeDescMap(); for(ProbeDesc<?> pd: allProbeDesc.values()) { for(ProbeMeta meta: ArgFactory.enumerateAnnotation(pd.getProbeClass(), ProbeMeta.class, StarterNode.class)) {
@Test public void testOptional() throws Exception { PropertiesManager localpm = Tools.makePm(testFolder); ConfigObjectFactory conf = new ConfigObjectFactory(localpm, localpm.extensionClassLoader); JrdsDocument pddoc = Tools.parseRessource("httpxmlprobedesc.xml"); pddoc.getRootElement().getElementbyName("probeClass").setTextContent("jrds.mockobjects.MokeProbeBean"); conf.getNodeMap(ConfigType.PROBEDESC).put("name", pddoc); @SuppressWarnings("unchecked") ProbeDesc<String> pd = (ProbeDesc<String>) conf.setProbeDescMap().get("name"); Assert.assertNotNull("Probedesc not build", pd); @SuppressWarnings("unchecked") Probe<String, String> p = (Probe<String, String>) pd.getProbeClass().getConstructor().newInstance(); p.setPd(pd); p.setLabel("goodlabel"); Assert.assertTrue("optional resolution broken", p.isOptional("goodlabel")); }
Map<String, ProbeDesc<?>> probeDescMap = conf.setProbeDescMap();
@Test public void testAttributesParsing() throws Exception { PropertiesManager pm = Tools.makePm(testFolder); File descpath = new File("desc"); if(descpath.exists()) pm.libspath.add(descpath.toURI()); ConfigObjectFactory conf = new ConfigObjectFactory(pm); JrdsDocument pddoc = Tools.parseRessource("beans.xml"); conf.getNodeMap(ConfigType.PROBEDESC).put("name", pddoc); Map<String, GraphDesc> graphDescMap = conf.setGraphDescMap(); Map<String, ProbeDesc<? extends Object>> probeDescMap = conf.setProbeDescMap(); ProbeFactory pf = new ProbeFactory(probeDescMap, graphDescMap); HostBuilder hb = new HostBuilder(); hb.setPm(pm); hb.setClassLoader(this.getClass().getClassLoader()); hb.setMacros(new HashMap<String, Macro>(0)); hb.setProbeFactory(pf); Map<String, Timer> timerMap = Tools.getSimpleTimerMap(); timerMap.put("another", timerMap.get(Timer.DEFAULTNAME)); hb.setTimers(timerMap); JrdsDocument fullhost = Tools.parseRessource("attrhost.xml"); HostInfo hi = hb.build(fullhost); Probe<?, ?> p = hi.getProbes().iterator().next(); Assert.assertEquals("${attr.customattr1} failed", "defaultattr1", Util.parseTemplate("${attr.customattr1}", p)); Assert.assertEquals("${attr.customattr3} failed", "defaultattr2", Util.parseTemplate("${attr.customattr2}", p)); Assert.assertEquals("${attr.customattr3} failed", "defaultattr1", Util.parseTemplate("${attr.customattr3}", p)); Assert.assertEquals("${attr.customattr4} failed", "value4", Util.parseTemplate("${attr.customattr4}", p)); }
@Test public void testCustomBeans() throws Exception { PropertiesManager localpm = Tools.makePm(testFolder); ConfigObjectFactory conf = new ConfigObjectFactory(localpm, localpm.extensionClassLoader); JrdsDocument pddoc = Tools.parseRessource("beans.xml"); pddoc.getRootElement().getElementbyName("probeClass").setTextContent("jrds.mockobjects.MokeProbeBean"); conf.getNodeMap(ConfigType.PROBEDESC).put("name", pddoc); @SuppressWarnings("unchecked") ProbeDesc<String> pd = (ProbeDesc<String>) conf.setProbeDescMap().get("name"); Assert.assertNotNull("custom bean customattr1 not found", pd.getBean("customattr1")); Assert.assertNotNull("custom bean customattr2 not found", pd.getBean("customattr2")); @SuppressWarnings("unchecked") Probe<String, String> p = (Probe<String, String>) pd.getProbeClass().getConstructor().newInstance(); p.setPd(pd); pd.getBean("customattr1").set(p, "value1"); pd.getBean("customattr2").set(p, "value2"); Assert.assertEquals("value1", pd.getBean("customattr1").get(p)); Assert.assertEquals("value2", pd.getBean("customattr2").get(p)); Assert.assertEquals("value1", Util.parseTemplate("${attr.customattr1}", p)); Assert.assertEquals("value2", Util.parseTemplate("${attr.customattr2}", p)); } }