/** Test of runScriptlet method, of class ScriptingContainer. */ @Test public void testRunScriptlet_PathType_String() { System.out.println("runScriptlet(type, filename)"); PathType type = null; String filename = ""; String basedir = System.getProperty("user.dir"); String[] paths = {basedir + "/lib/ruby/1.8"}; ScriptingContainer instance = new ScriptingContainer(); instance.getProvider().setLoadPaths(Arrays.asList(paths)); Object expResult = null; Object result; try { result = instance.parse(type, filename); } catch (RuntimeException e) { assertTrue(e.getCause() instanceof FileNotFoundException); } // absolute path filename = basedir + "/test/org/jruby/embed/ruby/next_year.rb"; result = instance.runScriptlet(PathType.ABSOLUTE, filename); // perhaps, a return type should be in a method argument // since implicit cast results in a Long type expResult = new Long(getNextYear()); assertEquals(expResult, result); instance.setAttribute(AttributeName.BASE_DIR, basedir + "/test/org/jruby/embed"); filename = "/ruby/next_year.rb"; result = instance.runScriptlet(PathType.RELATIVE, filename); assertEquals(expResult, result); instance.removeAttribute(AttributeName.BASE_DIR); StringWriter writer = new StringWriter(); instance.setWriter(writer); String[] radioactive_isotopes = { "Uranium", "Plutonium", "Carbon", "Radium", "Einstenium", "Nobelium" }; instance.put("@list", Arrays.asList(radioactive_isotopes)); filename = "/test/org/jruby/embed/ruby/list_printer.rb"; result = instance.runScriptlet(PathType.RELATIVE, filename); expResult = "Uranium >> Plutonium >> Carbon >> Radium >> Einstenium >> Nobelium: 6 in total"; assertEquals(expResult, writer.toString().trim()); writer = new StringWriter(); instance.setWriter(writer); radioactive_isotopes = new String[] {"ウラン", "プルトニウム", "炭素", "ラジウム", "アインスタイニウム", "ノーベリウム"}; instance.put("@list", Arrays.asList(radioactive_isotopes)); filename = "org/jruby/embed/ruby/list_printer.rb"; result = instance.runScriptlet(PathType.CLASSPATH, filename); expResult = "ウラン >> プルトニウム >> 炭素 >> ラジウム >> アインスタイニウム >> ノーベリウム: 6 in total"; assertEquals(expResult, writer.toString().trim()); instance.getVarMap().clear(); instance = null; }