ExternalComponentRegistryImpl implements CoreComponentRegistry { public void refreshComponents(List<ExtendedComponentProvider> providers) { LOGGER.debug("providers refreshed {0}", providers); assert providers != null : "providers list should not be null"; synchronized(availableComponents) { activeProviders.set(providers); availableComponents.clear(); for (ExtendedComponentProvider provider:providers) { try { if (provider.getComponentTypes() != null) { for (ComponentTypeInfo info:provider.getComponentTypes()) { ExtendedComponentTypeInfo eInfo = new ExtendedComponentTypeInfo(info, provider.getBundleSymbolicName()); ExtendedComponentTypeInfo existingInfo = availableComponents.put(info.getId(), eInfo); assert existingInfo == null : "Component type already registered by " + existingInfo.getBundleSymbolicName() + " for " + info.getDisplayName() + " trying to register again by " + eInfo.getBundleSymbolicName(); } } } catch (Exception e) { LOGGER.error("Error occurred while invoking provider: " + provider.getClass().getName() + " from bundle: " + provider.getBundleSymbolicName(), e); } } } refreshBootstrapComponents(providers); } ExternalComponentRegistryImpl(); static ExternalComponentRegistryImpl getInstance(); @Override Set<ViewInfo> getViewInfos(String componentTypeId, ViewType type); Collection<ExtendedComponentTypeInfo> getComponentInfos(); @Override T getAsset(TypeInfo<?> objectType, Class<T> assetClass); void setDefaultViewProvider(ComponentProvider provider); @Override AbstractComponent newInstance(ComponentTypeInfo componentTypeInfo); @Override AbstractComponent newCollection(Collection<AbstractComponent> components); @Override T newInstance(Class<T> componentClass, AbstractComponent parent); void refreshComponents(List<ExtendedComponentProvider> providers); @Override AbstractComponent getComponent(String id); @Override boolean isCreatable(Class<?> clazz); @Override AbstractComponent newInstance(String componentType); static final byte USER_DEFINED_GROUP_PERMISSION; }
@SuppressWarnings("unchecked") @Test public void testPluginBootstraps() { final Bootstrap mockGlobal = Mockito.mock(Bootstrap.class); final Bootstrap mockNonGlobal = Mockito.mock(Bootstrap.class); Mockito.when(mockGlobal.isGlobal()).thenReturn(true); Mockito.when(mockNonGlobal.isGlobal()).thenReturn(false); class BootstrapComponent extends AbstractComponent { private boolean global; public BootstrapComponent(boolean global) { this.global = global; } @Override protected <T> T handleGetCapability(Class<T> capability) { if (capability.isAssignableFrom(Bootstrap.class)) { return capability.cast(global ? mockGlobal : mockNonGlobal); } return super.handleGetCapability(capability); } } ExtendedComponentProvider mockProvider = Mockito.mock(ExtendedComponentProvider.class); Mockito.when(mockProvider.getBootstrapComponents()).thenReturn(Collections.<AbstractComponent>emptyList()); registry.refreshComponents(Arrays.asList(mockProvider)); Mockito.verify(mockProvider).getBootstrapComponents(); Mockito.verifyNoMoreInteractions(mockPersistence); AbstractComponent global = new BootstrapComponent(true); AbstractComponent local = new BootstrapComponent(false); Mockito.when(mockProvider.getBootstrapComponents()).thenReturn(Arrays.asList(global, local)); registry.refreshComponents(Arrays.asList(mockProvider)); @SuppressWarnings("rawtypes") ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class); Mockito.verify(mockPersistence).persist(captor.capture()); Assert.assertEquals(captor.getValue().size(), 2); Assert.assertTrue(captor.getValue().contains(global)); Assert.assertTrue(captor.getValue().contains(local)); Mockito.verify(mockPersistence).tagComponents(Mockito.eq("bootstrap:admin"), captor.capture()); Assert.assertEquals(captor.getValue().size(), 1); Assert.assertTrue(captor.getValue().contains(global)); Mockito.verify(mockPersistence).tagComponents(Mockito.eq("bootstrap:creator"), captor.capture()); Assert.assertEquals(captor.getValue().size(), 1); Assert.assertTrue(captor.getValue().contains(local)); }