@Test public void testCopyAdding() throws Exception { generatedJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of(new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()))); assertJarContents(generatedJar, ImmutableMap.of("myfile.txt", "mytext"), false); }
@Test public void testCopyAddingManifest() throws Exception { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.2.3"); // needs version, or nothing added to manifest! manifest.getMainAttributes().putValue("mykey", "myval"); generatedJar = bundleMaker.copyAddingManifest(emptyJar, manifest); String expectedManifest = "Manifest-Version: 1.2.3\r\n" + "mykey: myval\r\n" + "\r\n"; assertJarContents(generatedJar, ImmutableMap.of(JarFile.MANIFEST_NAME, expectedManifest), false); }
@Test public void testCreateJarFromClasspathDirNoManifest() throws Exception { generatedJar = bundleMaker.createJarFromClasspathDir("/org/apache/brooklyn/util/core/osgi/test/bundlemaker/nomanifest"); assertJarContents(generatedJar, ImmutableMap.of("myfile.txt", "mytext", "subdir/myfile2.txt", "mytext2"), false); }
@Test public void testCreateJarFromClasspathDirWithManifest() throws Exception { generatedJar = bundleMaker.createJarFromClasspathDir("/org/apache/brooklyn/util/core/osgi/test/bundlemaker/withmanifest"); String expectedManifest = "Manifest-Version: 1.2.3\r\n" + "mykey: myval\r\n" + "\r\n"; assertJarContents(generatedJar, ImmutableMap.of(JarFile.MANIFEST_NAME, expectedManifest, "myfile.txt", "mytext", "subdir/myfile2.txt", "mytext2"), false); }
@Test public void testCopyRemovingItemsUnmatched() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of(new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()))); generatedJar = bundleMaker.copyRemoving(tempJar, ImmutableSet.of("wrong.txt")); assertJarContents(generatedJar, ImmutableMap.of("myfile.txt", "mytext"), false); }
@Test public void testCopyAddingOverwritesEntry() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of(new ZipEntry("myfile.txt"), new ByteArrayInputStream("myPreExisting".getBytes()))); generatedJar = bundleMaker.copyAdding(tempJar, ImmutableMap.of(new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()))); assertJarContents(generatedJar, ImmutableMap.of("myfile.txt", "mytext"), false); }
@Test public void testCopyRemovingItems() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of( new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()), new ZipEntry("myfile2.txt"), new ByteArrayInputStream("mytext2".getBytes()))); generatedJar = bundleMaker.copyRemoving(tempJar, ImmutableSet.of("myfile.txt")); assertJarContents(generatedJar, ImmutableMap.of("myfile2.txt", "mytext2"), false); }
@Test public void testCopyAddingToNonEmpty() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of(new ZipEntry("preExisting.txt"), new ByteArrayInputStream("myPreExisting".getBytes()))); generatedJar = bundleMaker.copyAdding(tempJar, ImmutableMap.of(new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()))); assertJarContents(generatedJar, ImmutableMap.of("preExisting.txt", "myPreExisting", "myfile.txt", "mytext"), false); }
@Test public void testCopyRemovingPredicate() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of( new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()), new ZipEntry("myfile2.txt"), new ByteArrayInputStream("mytext2".getBytes()))); generatedJar = bundleMaker.copyRemoving(tempJar, Predicates.equalTo("myfile.txt")); assertJarContents(generatedJar, ImmutableMap.of("myfile.txt", "mytext"), false); }
@Test(enabled=false) public void testCopyRemovingItemDir() throws Exception { tempJar = bundleMaker.copyAdding(emptyJar, ImmutableMap.of( new ZipEntry("mydir/myfile.txt"), new ByteArrayInputStream("mytext".getBytes()), new ZipEntry("mydir2/myfile2.txt"), new ByteArrayInputStream("mytext2".getBytes()))); generatedJar = bundleMaker.copyRemoving(tempJar, ImmutableSet.of("mydir")); assertJarContents(generatedJar, ImmutableMap.of("mydir2/myfile2.txt", "mytext2"), false); }
@Test public void testCopyAddingManifestOverwritesExisting() throws Exception { Map<String, String> origManifest = ImmutableMap.of(Attributes.Name.MANIFEST_VERSION.toString(), "4.5.6", "preExistingKey", "preExistingVal"); tempJar = bundleMaker.copyAddingManifest(emptyJar, origManifest); Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.2.3"); manifest.getMainAttributes().putValue("mykey", "myval"); generatedJar = bundleMaker.copyAddingManifest(tempJar, manifest); String expectedManifest = "Manifest-Version: 1.2.3\r\n" + "mykey: myval\r\n" + "\r\n"; assertJarContents(generatedJar, ImmutableMap.of(JarFile.MANIFEST_NAME, expectedManifest), false); }
@Test public void testCopyAddingManifestByMap() throws Exception { Map<String, String> manifest = ImmutableMap.of(Attributes.Name.MANIFEST_VERSION.toString(), "1.2.3", "mykey", "myval"); generatedJar = bundleMaker.copyAddingManifest(emptyJar, manifest); String expectedManifest = "Manifest-Version: 1.2.3\r\n" + "mykey: myval\r\n" + "\r\n"; assertJarContents(generatedJar, ImmutableMap.of(JarFile.MANIFEST_NAME, expectedManifest), false); }
@Test public void testCreate() throws Exception { Map<String, String> manifest = ImmutableMap.of( Attributes.Name.MANIFEST_VERSION.toString(), "1.2.3", Constants.BUNDLE_VERSION, "4.5.6", Constants.BUNDLE_SYMBOLICNAME, "myname"); generatedJar = bundleMaker.createTempBundle("test", manifest, ImmutableMap.of(new ZipEntry("myfile.txt"), new ByteArrayInputStream("mytext".getBytes()))); assertJarContents(generatedJar, ImmutableMap.of("myfile.txt", "mytext"), true); @SuppressWarnings("deprecation") Bundle bundle = bundleMaker.installBundle(generatedJar, false); assertEquals(bundle.getSymbolicName(), "myname"); assertEquals(bundle.getVersion(), new Version("4.5.6")); }