/** * test the supplementer registry with a supplemented bundle * * @throws Exception */ public void testSupplementerRegistryWithCombinedSupplementer() throws Exception { Hashtable headers = new Hashtable(); headers.put("Eclipse-SupplementImporter", "test.import1"); headers.put("Eclipse-SupplementExporter", "test.export1"); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplementedBundle1"); EasyMock.expect(bundle.getHeaders()).andStubReturn(headers); EasyMock.expect(bundle.getSymbolicName()).andStubReturn("supplementer"); EasyMock.expect(context.getBundles()).andReturn(new Bundle[] {bundle}); EasyMock.expect(supplementedBundle1.getHeaders()).andStubReturn(new Hashtable()); headers = new Hashtable(); headers.put("Export-Package", "test.export1"); EasyMock.expect(supplementedBundle2.getHeaders()).andStubReturn(headers); headers = new Hashtable(); headers.put("Import-Package", "test.import1"); EasyMock.expect(supplementedBundle3.getHeaders()).andStubReturn(headers); EasyMock.replay(mocks); registry.addBundle(bundle); registry.addBundle(supplementedBundle1); registry.addBundle(supplementedBundle2); registry.addBundle(supplementedBundle3); Supplementer[] supplementers = registry.getSupplementers(supplementedBundle1); assertSame(bundle, supplementers[0].getSupplementerBundle()); supplementers = registry.getSupplementers(supplementedBundle2); assertSame(bundle, supplementers[0].getSupplementerBundle()); supplementers = registry.getSupplementers(supplementedBundle3); assertSame(bundle, supplementers[0].getSupplementerBundle()); EasyMock.verify(mocks); }
public void testSupplementerRegistryWithWildcards() throws Exception { Hashtable headers = new Hashtable(); headers = new Hashtable(); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplementedBundle*"); EasyMock.expect(supplementerBundle1.getHeaders()).andStubReturn(headers); headers = new Hashtable(); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplemented*"); EasyMock.expect(supplementerBundle2.getHeaders()).andStubReturn(headers); EasyMock.expect(context.getBundles()) .andStubReturn(new Bundle[] {supplementerBundle1, supplementerBundle2}); headers = new Hashtable(); EasyMock.expect(supplementedBundle1.getHeaders()).andStubReturn(headers); headers = new Hashtable(); EasyMock.expect(supplementedBundle2.getHeaders()).andStubReturn(headers); headers = new Hashtable(); EasyMock.expect(supplementedBundle3.getHeaders()).andStubReturn(headers); EasyMock.replay(mocks); registry.addBundle(supplementerBundle1); registry.addBundle(supplementerBundle2); registry.addBundle(supplementedBundle1); registry.addBundle(supplementedBundle2); registry.addBundle(supplementedBundle3); Supplementer[] supplementers = registry.getSupplementers(supplementedBundle1); assertEquals(2, supplementers.length); assertTrue(containsSupplementer(supplementers, supplementerBundle1)); assertTrue(containsSupplementer(supplementers, supplementerBundle2)); supplementers = registry.getSupplementers(supplementedBundle2); assertEquals(2, supplementers.length); assertTrue(containsSupplementer(supplementers, supplementerBundle1)); assertTrue(containsSupplementer(supplementers, supplementerBundle2)); supplementers = registry.getSupplementers(supplementedBundle3); assertEquals(0, supplementers.length); assertFalse(containsSupplementer(supplementers, supplementerBundle1)); assertFalse(containsSupplementer(supplementers, supplementerBundle2)); EasyMock.verify(mocks); }
/** * test the supplementer registry with a supplemented bundle * * @throws Exception */ public void testSupplementerRegistryWithSupplementedBundle() throws Exception { final Hashtable headers = new Hashtable(); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplementedBundle1"); EasyMock.expect(bundle.getHeaders()).andStubReturn(headers); EasyMock.expect(context.getBundles()).andReturn(new Bundle[] {bundle}); EasyMock.expect(supplementedBundle1.getHeaders()).andStubReturn(new Hashtable()); EasyMock.replay(mocks); registry.addBundle(bundle); registry.addBundle(supplementedBundle1); final Supplementer[] supplementers = registry.getSupplementers(supplementedBundle1); assertSame(bundle, supplementers[0].getSupplementerBundle()); EasyMock.verify(mocks); }
/** test the supplementer registry by adding a simple bundle without any supplementing to it */ public void testSupplementerRegistryAddSimpleBundle() { EasyMock.expect(bundle.getHeaders()).andStubReturn(new Hashtable()); EasyMock.replay(mocks); registry.addBundle(bundle); Supplementer[] supplementers = registry.getSupplementers(bundle); assertNotNull(supplementers); assertEquals(0, supplementers.length); supplementers = registry.getSupplementers(otherBundle); assertNotNull(supplementers); assertEquals(0, supplementers.length); EasyMock.verify(mocks); }
/** * test the supplementer registry by adding a supplementing bundle to it * * @throws Exception */ public void testSupplementerRegistryWithSupplementer() throws Exception { final Hashtable headers = new Hashtable(); headers.put("Eclipse-SupplementBundle", "test.bundle1"); EasyMock.expect(bundle.getHeaders()).andStubReturn(headers); EasyMock.expect(context.getBundles()).andReturn(new Bundle[] {bundle}); EasyMock.replay(mocks); registry.addBundle(bundle); final ManifestElement[] imports = ManifestElement.parseHeader("Import-Package", "org.test1,\n org.test2"); final ManifestElement[] exports = ManifestElement.parseHeader("Export-Package", "org.test3,\n org.test4"); final List<Supplementer> supplementers = registry.getMatchingSupplementers("test.bundle1", imports, exports); assertNotNull(supplementers); assertEquals(1, supplementers.size()); assertEquals(bundle, supplementers.get(0).getSupplementerBundle()); EasyMock.verify(mocks); }
/** * test different supplementers and removed supplementers * * @throws Exception */ public void testSupplementerRegistryWithDifferentRemovedSupplementers() throws Exception { Hashtable headers = new Hashtable(); headers.put("Eclipse-SupplementImporter", "test.import1"); EasyMock.expect(supplementerBundle1.getHeaders()).andStubReturn(headers); headers = new Hashtable(); headers.put("Eclipse-SupplementExporter", "test.export1"); EasyMock.expect(supplementerBundle2.getHeaders()).andStubReturn(headers); headers = new Hashtable(); headers.put("Eclipse-SupplementBundle", "symbolic-name-supplementedBundle*"); EasyMock.expect(supplementerBundle3.getHeaders()).andStubReturn(headers); EasyMock.expect(context.getBundles()) .andStubReturn( new Bundle[] {supplementerBundle1, supplementerBundle2, supplementerBundle3}); headers = new Hashtable(); headers.put("Import-Package", "test.import1"); headers.put("Export-Package", "test.export1"); EasyMock.expect(supplementedBundle1.getHeaders()).andStubReturn(headers); headers = new Hashtable(); EasyMock.expect(supplementedBundle2.getHeaders()).andStubReturn(headers); EasyMock.expect(supplementedBundle1.getState()).andStubReturn(Bundle.RESOLVED); EasyMock.expect(supplementedBundle2.getState()).andStubReturn(Bundle.RESOLVED); packageAdmin.refreshPackages(EasyMock.aryEq(new Bundle[] {supplementedBundle1})); packageAdmin.refreshPackages( EasyMock.aryEq(new Bundle[] {supplementedBundle1, supplementedBundle2})); IWeavingAdaptor adaptor = EasyMock.createNiceMock(IWeavingAdaptor.class); EasyMock.expect(adaptorProvider.getAdaptor(6l)).andStubReturn(adaptor); EasyMock.expect(adaptorProvider.getAdaptor(7l)).andStubReturn(adaptor); EasyMock.replay(mocks); registry.addBundle(supplementerBundle1); registry.addBundle(supplementerBundle2); registry.addBundle(supplementerBundle3); registry.addBundle(supplementedBundle1); registry.addBundle(supplementedBundle2); registry.removeBundle(supplementerBundle1); registry.removeBundle(supplementerBundle3); Supplementer[] supplementers = registry.getSupplementers(supplementedBundle1); assertEquals(1, supplementers.length); assertFalse(containsSupplementer(supplementers, supplementerBundle1)); assertTrue(containsSupplementer(supplementers, supplementerBundle2)); assertFalse(containsSupplementer(supplementers, supplementerBundle3)); supplementers = registry.getSupplementers(supplementedBundle2); assertEquals(0, supplementers.length); assertFalse(containsSupplementer(supplementers, supplementerBundle1)); assertFalse(containsSupplementer(supplementers, supplementerBundle2)); assertFalse(containsSupplementer(supplementers, supplementerBundle3)); EasyMock.verify(mocks); }