@Test public void testAttachedFragment() throws Exception { Bundle hostA = installBundle(getHostA()); assertBundleState(Bundle.INSTALLED, hostA.getState()); Bundle fragA = installBundle(getFragmentA()); assertBundleState(Bundle.INSTALLED, fragA.getState()); hostA.start(); assertBundleState(Bundle.ACTIVE, hostA.getState()); assertBundleState(Bundle.RESOLVED, fragA.getState()); URL entryURL = hostA.getEntry("resource.txt"); assertNull("Entry URL null", entryURL); URL resourceURL = hostA.getResource("resource.txt"); assertEquals("bundle", resourceURL.getProtocol()); assertEquals("/resource.txt", resourceURL.getPath()); BufferedReader br = new BufferedReader(new InputStreamReader(resourceURL.openStream())); assertEquals("fragA", br.readLine()); // Load class provided by the fragment assertLoadClass(hostA, FragBeanA.class.getName()); // Load a private class from host assertLoadClass(hostA, SubBeanA.class.getName()); // PackageAdmin.getBundleType PackageAdmin pa = getPackageAdmin(); assertEquals("Bundle type", 0, pa.getBundleType(hostA)); assertEquals("Bundle type", PackageAdmin.BUNDLE_TYPE_FRAGMENT, pa.getBundleType(fragA)); // PackageAdmin.getHosts Bundle[] hosts = pa.getHosts(hostA); assertNull("Not a fragment", hosts); hosts = pa.getHosts(fragA); assertNotNull("Hosts not null", hosts); assertEquals("Hosts length", 1, hosts.length); assertEquals("Hosts equals", hostA, hosts[0]); // PackageAdmin.getFragments Bundle[] fragments = pa.getFragments(fragA); assertNull("Not a host", fragments); fragments = pa.getFragments(hostA); assertNotNull("Fragments not null", fragments); assertEquals("Fragments length", 1, fragments.length); assertEquals("Fragments equals", fragA, fragments[0]); hostA.uninstall(); assertBundleState(Bundle.UNINSTALLED, hostA.getState()); assertBundleState(Bundle.RESOLVED, fragA.getState()); fragA.uninstall(); assertBundleState(Bundle.UNINSTALLED, fragA.getState()); }
public Bundle[] getHosts(Bundle bundle) { PackageAdmin packageAdmin = getPackageAdmin(); if (packageAdmin == null) return null; return packageAdmin.getHosts(bundle); }
/** @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); adaptorProvider = EasyMock.createNiceMock(IAdaptorProvider.class); context = EasyMock.createNiceMock(BundleContext.class); bundle = EasyMock.createMock(Bundle.class); otherBundle = EasyMock.createMock(Bundle.class); supplementerBundle1 = EasyMock.createMock(Bundle.class); supplementerBundle2 = EasyMock.createMock(Bundle.class); supplementerBundle3 = EasyMock.createMock(Bundle.class); supplementedBundle1 = EasyMock.createMock(Bundle.class); supplementedBundle2 = EasyMock.createMock(Bundle.class); supplementedBundle3 = EasyMock.createMock(Bundle.class); packageAdmin = EasyMock.createMock(PackageAdmin.class); EasyMock.expect(packageAdmin.getHosts(bundle)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementedBundle1)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementedBundle2)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementedBundle3)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementerBundle1)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementerBundle2)).andStubReturn(null); EasyMock.expect(packageAdmin.getHosts(supplementerBundle3)).andStubReturn(null); registry = new SupplementerRegistry(adaptorProvider); registry.setBundleContext(context); registry.setPackageAdmin(packageAdmin); EasyMock.expect(bundle.getBundleId()).andStubReturn(1l); EasyMock.expect(otherBundle.getBundleId()).andStubReturn(2l); EasyMock.expect(supplementerBundle1.getBundleId()).andStubReturn(3l); EasyMock.expect(supplementerBundle2.getBundleId()).andStubReturn(4l); EasyMock.expect(supplementerBundle3.getBundleId()).andStubReturn(5l); EasyMock.expect(supplementedBundle1.getBundleId()).andStubReturn(6l); EasyMock.expect(supplementedBundle2.getBundleId()).andStubReturn(7l); EasyMock.expect(supplementedBundle3.getBundleId()).andStubReturn(8l); EasyMock.expect(bundle.getSymbolicName()).andStubReturn("symbolic-name-bundle"); EasyMock.expect(otherBundle.getSymbolicName()).andStubReturn("symbolic-name-otherBundle"); EasyMock.expect(supplementerBundle1.getSymbolicName()) .andStubReturn("symbolic-name-supplementerBundle1"); EasyMock.expect(supplementerBundle2.getSymbolicName()) .andStubReturn("symbolic-name-supplementerBundle2"); EasyMock.expect(supplementerBundle3.getSymbolicName()) .andStubReturn("symbolic-name-supplementerBundle3"); EasyMock.expect(supplementedBundle1.getSymbolicName()) .andStubReturn("symbolic-name-supplementedBundle1"); EasyMock.expect(supplementedBundle2.getSymbolicName()) .andStubReturn("symbolic-name-supplementedBundle2"); EasyMock.expect(supplementedBundle3.getSymbolicName()).andStubReturn("different-symbolic-name"); mocks = new Object[] { adaptorProvider, packageAdmin, context, bundle, otherBundle, supplementedBundle1, supplementedBundle2, supplementedBundle3, supplementerBundle1, supplementerBundle2, supplementerBundle3 }; }