public static String read(InputStream in) throws IOException { return read(in, Tools.UTF_8); }
public static String read(URL url) throws IOException { return read(url.openStream()); }
@Override public InputStream minify(String name, String type, InputStream stream) throws IOException { if (type.equals("script")) { NormalizeJSReader reader = new NormalizeJSReader(new InputStreamReader(stream)); String s = Tools.read(reader); return new ByteArrayInputStream(s.getBytes()); } else { throw new IOException("Can only process scripts and not " + type + " asset"); } } }
@Override public InputStream minify(String name, String type, InputStream stream) throws IOException { if (type.equals("script")) { NormalizeJSReader reader = new NormalizeJSReader(new InputStreamReader(stream)); String s = Tools.read(reader); return new ByteArrayInputStream(s.getBytes()); } else { throw new IOException("Can only process scripts and not " + type + " asset"); } } }
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); }
@Test public void testInjection() throws Exception { URL url = applicationURL(); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestProperty("Accept-Language", "fr-FR"); conn.connect(); assertEquals(200, conn.getResponseCode()); String result = Tools.read(conn.getInputStream()); assertTrue("Was expecting <" + result + "> to contain def", result.contains("def")); } }
@Test public void testInjection() throws Exception { URL url = applicationURL(); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestProperty("Accept-Language", "fr-FR"); conn.connect(); assertEquals(200, conn.getResponseCode()); String result = Tools.read(conn.getInputStream()); assertTrue("Was expecting <" + result + "> to contain def", result.contains("def")); } }
@Test public void testWhat() throws Exception { HttpURLConnection conn = (HttpURLConnection)applicationURL().openConnection(); conn.connect(); assertEquals(500, conn.getResponseCode()); String ret = Tools.read(conn.getErrorStream()); assertTrue(ret.contains("Cannot resolve asset")); assertTrue(ret.contains("foo")); } }
@Test public void testWhat() throws Exception { HttpURLConnection conn = (HttpURLConnection)applicationURL().openConnection(); conn.connect(); assertEquals(500, conn.getResponseCode()); String ret = Tools.read(conn.getErrorStream()); assertTrue(ret.contains("Cannot resolve asset")); assertTrue(ret.contains("foo")); } }
@Test public void testPathParam() throws Exception { driver.get(applicationURL().toString()); WebElement trigger = driver.findElement(By.tagName("body")); URL url = new URL(trigger.getText()); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.connect(); assertEquals("text/event-stream", conn.getContentType().substring(0, "text/event-stream".length())); Map<String, String> headers = Tools.responseHeaders(conn); assertTrue(headers.containsKey("juu")); assertEquals("juu_value", headers.get("juu")); String ret = Tools.read(conn.getInputStream()); assertEquals("pass", ret); } }
@Test public void testRouteToMethod() throws Exception { HttpMethod[] methods = { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT }; URL url = applicationURL(); for (HttpMethod method : methods) { HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod(method.name()); assertEquals(200, conn.getResponseCode()); String ret = Tools.read(conn.getInputStream()); assertTrue("Was expecting " + ret + " to container ok[" + method + "]", ret.contains("ok[" + method + "]")); } }
@Test public void testRouteToMethod() throws Exception { HttpMethod[] methods = { HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT }; URL url = applicationURL(); for (HttpMethod method : methods) { HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod(method.name()); assertEquals(200, conn.getResponseCode()); String ret = Tools.read(conn.getInputStream()); assertTrue("Was expecting " + ret + " to container ok[" + method + "]", ret.contains("ok[" + method + "]")); } }
@Test public void testResource() throws IOException { Context ctx = new Context("common.live.resource"); ctx.init(); // assertEquals("bar", Tools.read(ctx.local.getResource("common/live/resource/foo.txt"))); // File dir = new File(ctx.compilerAssert2.getClassOutput().getRoot(), "common/live/resource"); assertTrue(dir.mkdirs()); File f = new File(dir, "foo.txt"); new FileWriter(f).append("bar_").close(); assertEquals("bar_", Tools.read(ctx.local.getResource("common/live/resource/foo.txt"))); } }
@Test public void testMinify() throws Exception { CompilerAssert<File, File> ca = compiler("plugin.less.minify"); ca.assertCompile(); File f = ca.getClassOutput().getPath("plugin", "less", "minify", "assets", "stylesheet.css"); assertNotNull(f); assertTrue(f.exists()); String s = Tools.read(f); assertFalse(s.contains(" ")); }
@Test public void testMinify() throws Exception { CompilerAssert<File, File> ca = compiler("plugin.less.minify"); ca.assertCompile(); File f = ca.getClassOutput().getPath("plugin", "less", "minify", "assets", "stylesheet.css"); assertNotNull(f); assertTrue(f.exists()); String s = Tools.read(f); assertFalse(s.contains(" ")); }
public static WebArchive createDeployment(String packageName) throws IOException { WebArchive war = createPortletDeployment(packageName); Node node = war.get("WEB-INF/portlet.xml"); ArchivePath path = node.getPath(); String s = Tools.read(node.getAsset().openStream(), Tools.UTF_8); s = s.replace("<portlet-info>", "<resource-bundle>bundle</resource-bundle>" + "<portlet-info>"); war.delete(path); war.add(new StringAsset(s), path); war.addAsResource(new StringAsset("abc=def"), "bundle_fr_FR.properties"); return war; }
public static WebArchive createDeployment(String packageName) throws IOException { WebArchive war = createPortletDeployment(packageName); Node node = war.get("WEB-INF/portlet.xml"); ArchivePath path = node.getPath(); String s = Tools.read(node.getAsset().openStream(), Tools.UTF_8); s = s.replace("<portlet-info>", "<resource-bundle>bundle</resource-bundle>" + "<portlet-info>"); war.delete(path); war.add(new StringAsset(s), path); war.addAsResource(new StringAsset("abc=def"), "bundle_fr_FR.properties"); return war; }
public static WebArchive createDeployment(String packageName) throws IOException { WebArchive war = createServletDeployment(true, packageName); Node node = war.get("/WEB-INF/web.xml"); ArchivePath path = node.getPath(); String s = Tools.read(node.getAsset().openStream(), Tools.UTF_8); s = s.replace("<async-supported>true</async-supported>", "<init-param><param-name>juzu.resource_bundle</param-name><param-value>bundle</param-value></init-param>" + "<async-supported>true</async-supported>"); war.delete(path); war.add(new StringAsset(s), path); war.addAsResource(new StringAsset("abc=def"), "bundle_fr_FR.properties"); return war; }
public static WebArchive createDeployment(String packageName) throws IOException { WebArchive war = createServletDeployment(true, packageName); Node node = war.get("/WEB-INF/web.xml"); ArchivePath path = node.getPath(); String s = Tools.read(node.getAsset().openStream(), Tools.UTF_8); s = s.replace("<async-supported>true</async-supported>", "<init-param><param-name>juzu.resource_bundle</param-name><param-value>bundle</param-value></init-param>" + "<async-supported>true</async-supported>"); war.delete(path); war.add(new StringAsset(s), path); war.addAsResource(new StringAsset("abc=def"), "bundle_fr_FR.properties"); return war; }