public JSON getConfig() throws Exception { ClassLoader classLoader = getClassLoader(); URL cfg = classLoader.getResource("juzu/config.json"); String s = Tools.read(cfg); return (JSON)JSON.parse(s); }
public JSON getConfig() throws Exception { ClassLoader classLoader = getClassLoader(); URL cfg = classLoader.getResource("juzu/config.json"); String s = Tools.read(cfg); return (JSON)JSON.parse(s); }
private ApplicationDescriptor(ClassLoader loader, Class<?> applicationClass) throws Exception { // Load config JSON config; InputStream in = null; try { String configPath = applicationClass.getPackage().getName().replace('.', '/') + "/config.json"; in = loader.getResourceAsStream(configPath); String s = Tools.read(in); config = (JSON)JSON.parse(s); } catch (IOException e) { throw new AssertionError(e); } finally { Tools.safeClose(in); } // Init this first before initing plugin so they can use it this.applicationClass = applicationClass; this.name = applicationClass.getSimpleName(); this.packageName = applicationClass.getPackage().getName(); this.packageClass = Tools.getPackageClass(applicationClass.getClassLoader(), applicationClass.getPackage().getName()); this.loader = loader; this.config = config; }
public final ReadFileSystem<?> getSourcePath() { if (sourcePath == null) { String sourcePathParam = getInitParameter(SOURCE_PATH); if (sourcePathParam != null) { sourcePath = new DiskFileSystem(new File(sourcePathParam)); } else { try { URL configURL = getClassLoader().getResource("juzu/config.json"); if (configURL != null) { String configValue = Tools.read(configURL); JSON config = (JSON)JSON.parse(configValue); String sourcePathValue = config.getString("sourcepath"); if (sourcePathValue != null) { File sourcePathRoot = new File(sourcePathValue); if (sourcePathRoot.isDirectory() && sourcePathRoot.exists()) { sourcePath = new DiskFileSystem(sourcePathRoot); } } } } catch (IOException e) { e.printStackTrace(); } } } return sourcePath; }
@Test public void testReadArray() throws Exception { List<?> o = (List<?>)JSON.parse("[\"a\",\"b\"]"); assertEquals(2, o.size()); assertEquals("a", o.get(0)); assertEquals("b", o.get(1)); }
@Test public void testReadArray() throws Exception { List<?> o = (List<?>)JSON.parse("[\"a\",\"b\"]"); assertEquals(2, o.size()); assertEquals("a", o.get(0)); assertEquals("b", o.get(1)); }
@Test public void testReadMap() throws Exception { JSON o = (JSON)JSON.parse("{\"a\":\"b\"}"); assertEquals(Collections.singleton("a"), o.names()); assertEquals("b", o.get("a")); }
@Test public void testReadMap() throws Exception { JSON o = (JSON)JSON.parse("{\"a\":\"b\"}"); assertEquals(Collections.singleton("a"), o.names()); assertEquals("b", o.get("a")); }
@Test public void testParseArray() throws Exception { String s = "{\"a\":[{\"b\":\"c\"}]}"; JSON json = (JSON)JSON.parse(s); JSON expected = new JSON().set("a", Arrays.asList(new JSON().set("b", "c"))); assertEquals(expected, json); }
@Test public void testParseArray() throws Exception { String s = "{\"a\":[{\"b\":\"c\"}]}"; JSON json = (JSON)JSON.parse(s); JSON expected = new JSON().set("a", Arrays.asList(new JSON().set("b", "c"))); assertEquals(expected, json); }
@Test public void testEscapeXML() throws Exception { MockApplication<?> app = application("plugin.controller.url.escapexml"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertEquals(Boolean.TRUE, url.getJSON("properties").get(PropertyType.ESCAPE_XML.getClass().getName())); }
@Test public void testEscapeXML() throws Exception { MockApplication<?> app = application("plugin.controller.url.escapexml"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertEquals(Boolean.TRUE, url.getJSON("properties").get(PropertyType.ESCAPE_XML.getClass().getName())); }
@Test public void testSimple() throws Exception { MockApplication<?> app = application("plugin.controller.url.simple"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertFalse(url.getJSON("properties").contains(PropertyType.ESCAPE_XML.getClass().getName())); }
@Test public void testSimple() throws Exception { MockApplication<?> app = application("plugin.controller.url.simple"); app.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); JSON url = (JSON)JSON.parse(render.assertStringResponse()); assertFalse(url.getJSON("properties").contains(PropertyType.ESCAPE_XML.getClass().getName())); }
@Test public void testNull() throws Exception { JSON json = new JSON().set("foo", null); String s = json.toString(); assertEquals("{\"foo\":null}", s); JSON unmarshalled = (JSON)JSON.parse(s); assertEquals(json, unmarshalled); }
@Test public void testNull() throws Exception { JSON json = new JSON().set("foo", null); String s = json.toString(); assertEquals("{\"foo\":null}", s); JSON unmarshalled = (JSON)JSON.parse(s); assertEquals(json, unmarshalled); }
private void runMissing(String pkg) throws Exception { MockApplication<File> application = application(InjectorProvider.GUICE, pkg); MockApplication<?> app = application.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String url = render.assertStringResponse(); JSON json = (JSON)JSON.parse(url); json.set("parameters", new JSON()); MockViewBridge action = (MockViewBridge)client.invoke(json.toString()); String result = action.assertStringResponse(); assertEquals("pass", result); } }
private void runMissing(String pkg) throws Exception { MockApplication<File> application = application(InjectorProvider.GUICE, pkg); MockApplication<?> app = application.init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String url = render.assertStringResponse(); JSON json = (JSON)JSON.parse(url); json.set("parameters", new JSON()); MockViewBridge action = (MockViewBridge)client.invoke(json.toString()); String result = action.assertStringResponse(); assertEquals("pass", result); } }