ConfigObjectFactory conf = new ConfigObjectFactory(pm);
ConfigObjectFactory conf = new ConfigObjectFactory(pm, pm.extensionClassLoader);
ConfigObjectFactory conf = new ConfigObjectFactory(pm); Map<String, GraphDesc> grapMap = conf.setGraphDescMap(); ConfigObjectFactory confjar = new ConfigObjectFactory(pm);
@Test public void testFullConfigpath() throws Exception { PropertiesManager localpm = Tools.makePm(testFolder); ConfigObjectFactory conf = new ConfigObjectFactory(localpm, localpm.extensionClassLoader); conf.getNodeMap(ConfigType.MACRODEF).put("macrodef", Tools.parseString(goodMacroXml)); Assert.assertNotNull("Macro not build", conf.setMacroMap().get("macrodef")); }
@Test public void testFullConfigpath() throws Exception { PropertiesManager localpm = Tools.makePm(testFolder); ConfigObjectFactory conf = new ConfigObjectFactory(localpm); conf.getNodeMap(ConfigType.FILTER).put("filtername", Tools.parseString(goodFilterXml)); Assert.assertNotNull("Filter not build", conf.setFilterMap().get("filtername")); }
@Test public void testFullConfigpath() throws Exception { PropertiesManager localpm = Tools.makePm(testFolder); ConfigObjectFactory conf = new ConfigObjectFactory(localpm); conf.getNodeMap(ConfigType.GRAPHDESC).put("graphdesc", Tools.parseRessource("graphdesc.xml")); Assert.assertNotNull("Graphdesc not build", conf.setGraphDescMap().get("graphdesctest")); }
@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 testFullConfigpath() throws Exception { PropertiesManager localpm = Tools.makePm(testFolder); JrdsDocument host = new JrdsDocument(Tools.dbuilder.newDocument()); host.doRootElement("host", "name=name"); ConfigObjectFactory conf = new ConfigObjectFactory(localpm, localpm.extensionClassLoader); conf.getNodeMap(ConfigType.HOSTS).put("name", host); Assert.assertNotNull("Probedesc not build", conf.setHostMap(Tools.getSimpleTimerMap()).get("name")); }
@Test public void enumerateProbe() throws IOException { PropertiesManager pm = Tools.makePm(testFolder, "autocreate=false", "strictparsing=true"); pm.update(); pm.libspath.clear(); File descpath = new File("desc"); if(descpath.exists()) pm.libspath.add(descpath.toURI()); ConfigObjectFactory conf = new ConfigObjectFactory(pm); Set<String> failed = new HashSet<String>(); for(JrdsDocument n: conf.getNodeMap(ConfigType.PROBEDESC).values()) { JrdsElement root = n.getRootElement(); JrdsElement classElem = root.getElementbyName("probeClass"); ProbeDesc<String> pd = new ProbeDesc<>(); String name = ""; try { String className = classElem.getTextContent().trim(); name = root.getElementbyName("name").getTextContent(); @SuppressWarnings("unchecked") Class<? extends Probe<String, ?>> c = (Class<? extends Probe<String, ?>>) pm.extensionClassLoader.loadClass(className); pd.setProbeClass(c); } catch (Exception e) { logger.error("Failed probedesc " + name + ": " + e.getMessage()); failed.add(name); } } if(!failed.isEmpty()) { Assert.fail("Invalid class:" + failed); } }
@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); }
ConfigObjectFactory conf = new ConfigObjectFactory(pm); conf.setArchiveSetMap(); conf.setGraphDescMap();
@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")); }
ConfigObjectFactory conf = new ConfigObjectFactory(pm);
@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)); } }