@Test public void testToURLs3a() throws Exception { final File[] files = new File[0]; // empty array final URL[] urls = FileUtils.toURLs(files); assertEquals(0, urls.length); }
@Test public void emptyManifest() throws Exception { Manifest mf = new Manifest(); File jar = createJar(mf, "emptyManifest.jar"); URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar})); assertThat(ManifestUtils.getPropertyValues(classloader, "foo")).isEmpty(); }
@Test public void singleManifest() throws Exception { Manifest mf = new Manifest(); mf.getMainAttributes().putValue("foo", "bar"); mf.getMainAttributes().putValue("other", "value"); File jar = createJar(mf, "singleManifest.jar"); URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar})); List<String> values = ManifestUtils.getPropertyValues(classloader, "foo"); assertThat(values).containsOnly("bar"); }
@Test public void manyManifests() throws Exception { Manifest mf1 = new Manifest(); mf1.getMainAttributes().putValue("foo", "bar"); File jar1 = createJar(mf1, "manyManifests-one.jar"); Manifest mf2 = new Manifest(); mf2.getMainAttributes().putValue("foo", "otherbar"); File jar2 = createJar(mf2, "manyManifests-two.jar"); URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar1, jar2})); List<String> values = ManifestUtils.getPropertyValues(classloader, "foo"); assertThat(values).containsOnly("bar", "otherbar"); }
@Test public void testToURLs1() throws Exception { final File[] files = new File[]{ new File(getTestDirectory(), "file1.txt"), new File(getTestDirectory(), "file2.txt"), new File(getTestDirectory(), "test file.txt"), }; final URL[] urls = FileUtils.toURLs(files); assertEquals(files.length, urls.length); assertTrue(urls[0].toExternalForm().startsWith("file:")); assertTrue(urls[0].toExternalForm().contains("file1.txt")); assertTrue(urls[1].toExternalForm().startsWith("file:")); assertTrue(urls[1].toExternalForm().contains("file2.txt")); // Test escaped char assertTrue(urls[2].toExternalForm().startsWith("file:")); assertTrue(urls[2].toExternalForm().contains("test%20file.txt")); }
@Override public URL translateForm(FormRepresentation form) throws TranslatorException { FormRepresentationEncoder encoder = FormEncodingServerFactory.getEncoder(); try { String json = encoder.encode(form); File file = File.createTempFile("form-gwt-", ".json"); FileUtils.writeStringToFile(file, json); return FileUtils.toURLs(new File[] { file })[0]; } catch (IOException e) { throw new TranslatorException("Problem writing temporal file", e); } catch (FormEncodingException e) { throw new TranslatorException("Problem encoding form", e); } }