/** * When two guava versions installed, want us to load from the *brooklyn* version rather than * a newer version that happens to be in Karaf. */ @Test(groups={"Integration"}) public void testLoadsFromRightGuavaVersion() throws Exception { mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); ClassLoaderUtils clu = new ClassLoaderUtils(getClass(), mgmt); String bundleUrl = MavenRetriever.localUrl(MavenArtifact.fromCoordinate("com.google.guava:guava:jar:18.0")); Bundle bundle = installBundle(mgmt, bundleUrl); String bundleName = bundle.getSymbolicName(); String classname = bundleName + ":" + ImmutableList.class.getName(); assertLoadSucceeds(clu, classname, ImmutableList.class); }
@Test public void testVariousLoadersLoadClassInOsgiWhiteList() throws Exception { String bundlePath = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH; String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY; TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath); mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); Bundle bundle = installBundle(mgmt, bundleUrl); Class<?> clazz = bundle.loadClass(classname); Entity entity = createSimpleEntity(bundleUrl, clazz); String whiteList = bundle.getSymbolicName()+":"+bundle.getVersion(); System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, whiteList); ClassLoaderUtils cluMgmt = new ClassLoaderUtils(getClass(), mgmt); ClassLoaderUtils cluClass = new ClassLoaderUtils(clazz); ClassLoaderUtils cluEntity = new ClassLoaderUtils(getClass(), entity); assertLoadSucceeds(classname, clazz, cluMgmt, cluClass, cluEntity); assertLoadSucceeds(bundle.getSymbolicName() + ":" + classname, clazz, cluMgmt, cluClass, cluEntity); }
@Test public void testLoadClassInOsgi() throws Exception { String bundlePath = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH; String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY; TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath); mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); Bundle bundle = installBundle(mgmt, bundleUrl); @SuppressWarnings("unchecked") Class<? extends Entity> clazz = (Class<? extends Entity>) bundle.loadClass(classname); Entity entity = createSimpleEntity(bundleUrl, clazz); System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, "do.not.match.whitelist:1.0.0"); ClassLoaderUtils cluMgmt = new ClassLoaderUtils(getClass(), mgmt); ClassLoaderUtils cluClass = new ClassLoaderUtils(clazz); ClassLoaderUtils cluEntity = new ClassLoaderUtils(getClass(), entity); assertLoadFails(classname, cluMgmt); assertLoadSucceeds(bundle.getSymbolicName() + ":" + classname, clazz, cluMgmt, cluClass, cluEntity); assertLoadSucceeds(bundle.getSymbolicName() + ":" + bundle.getVersion()+":" + classname, clazz, cluMgmt, cluClass, cluEntity); }
Bundle bundle = installBundle(mgmt, bundleUrl);
@Test public void testLoadJustOneClassInOsgiWhiteList() throws Exception { String bundlePath = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH; String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; String classname = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY; TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), bundlePath); mgmt = LocalManagementContextForTests.builder(true).enableOsgiReusable().build(); Bundle bundle = installBundle(mgmt, bundleUrl); Class<?> clazz = bundle.loadClass(classname); Entity entity = createSimpleEntity(bundleUrl, clazz); String whiteList = bundle.getSymbolicName()+":"+bundle.getVersion(); System.setProperty(ClassLoaderUtils.WHITE_LIST_KEY, whiteList); ClassLoaderUtils cluEntity = new ClassLoaderUtils(getClass(), entity); BundledName resource = new BundledName(classname).toResource(); BundledName bn = new BundledName(resource.bundle, resource.version, "/" + resource.name); Asserts.assertSize(cluEntity.getResources(bn.toString()), 1); }