@Test public void testCatalogBomFromBundleWithManifest() throws Exception { bm.setDefaultClassForLoading(getClass()); File jf = bm.createJarFromClasspathDir("osgi/catalog-bundle-1"); Assert.assertTrue(bm.hasOsgiManifest(jf)); installBundle(jf); assertHasBasic1(); assertBasic1DeploysAndHasSensor(); }
private String copyResourcePathToTempPath(String resourcePath) { BundleMaker bm = new BundleMaker(ResourceUtils.create(this)); bm.setDefaultClassForLoading(CleanOrphanedLocationsIntegrationTest.class); File jar = bm.createJarFromClasspathDir(resourcePath); File output = Os.newTempDir("brooklyn-test-resouce-from-"+resourcePath); try { ArchiveUtils.extractZip(new ZipFile(jar), output.getAbsolutePath()); return output.getAbsolutePath(); } catch (Exception e) { throw Exceptions.propagate(e); } }
@Test public void testCatalogBomLoadsFileInBundle() throws Exception { bm.setDefaultClassForLoading(getClass()); File jf = bm.createJarFromClasspathDir("osgi/catalog-bundle-1"); // add a file in the bundle String customText = "Sample data "+Identifiers.makeRandomId(4); jf = bm.copyAdding(jf, MutableMap.of( new ZipEntry("sample.txt"), (InputStream) new ByteArrayInputStream(customText.getBytes()))); installBundle(jf); String yaml = Strings.lines("name: simple-app-yaml", "services:", "- type: " + "basic1", " brooklyn.initializers:", " - type: "+GetFileContentsEffector.class.getName()); Entity app = createAndStartApplication(yaml); Entity basic1 = Iterables.getOnlyElement( app.getChildren() ); // check the file put in the bundle gets loaded without needing to do anything special String contents = basic1.invoke(GetFileContentsEffector.GET_FILE_CONTENTS, MutableMap.of(GetFileContentsEffector.FILENAME.getName(), "classpath://sample.txt")).get(); Asserts.assertEquals(contents, customText); }
@Test public void testCatalogBomFromBundleWithManualManifest() throws Exception { bm.setDefaultClassForLoading(getClass()); File jf = bm.createJarFromClasspathDir("osgi/catalog-bundle-1"); jf = bm.copyRemoving(jf, MutableSet.of(JarFile.MANIFEST_NAME)); String customName = "catalog-bundle-1-manual-"+Identifiers.makeRandomId(4); jf = bm.copyAddingManifest(jf, MutableMap.of( "Manifest-Version", "2.0", "Bundle-SymbolicName", customName, "Bundle-Version", "0.0.0.SNAPSHOT")); Assert.assertTrue(bm.hasOsgiManifest(jf)); installBundle(jf); assertHasBasic1(); Entity basic1 = assertBasic1DeploysAndHasSensor(); RegisteredType item = mgmt().getTypeRegistry().get( basic1.getCatalogItemId() ); Collection<OsgiBundleWithUrl> libs = item.getLibraries(); Asserts.assertSize(libs, 1); Assert.assertEquals(Iterables.getOnlyElement(libs).getSymbolicName(), customName); }