@Test public void testNewCollection() { Platform mockPlatform = Mockito.mock(Platform.class); AbstractComponent mockSandbox = Mockito.mock(AbstractComponent.class); Mockito.when(mockPlatform.getMySandbox()).thenReturn(mockSandbox); MockComponentRegistry registry = new MockComponentRegistry(); PlatformAccess platformAccess = new PlatformAccess(); platformAccess.setPlatform(mockPlatform); TestBaseComponent collection = Mockito.mock(TestBaseComponent.class); registry.setDefaultCollection(collection); List<AbstractComponent> selectedComponents = Collections.singletonList(Mockito.mock(AbstractComponent.class)); registry.setExpectedResultForAddComponents(true); AbstractComponent newCollection = registry.newCollection(selectedComponents); Assert.assertSame(newCollection, collection); registry.clearRegistry(); registry.setDefaultCollection(collection); registry.setExpectedResultForAddComponents(true); newCollection = registry.newCollection(selectedComponents); Assert.assertNotNull(newCollection); platformAccess.setPlatform(null); }
@Override public AbstractComponent newCollection(Collection<AbstractComponent> components) { AbstractComponent collectionComponent = null; AbstractComponent mySandbox = PlatformAccess.getPlatform().getMySandbox(); collectionComponent = newInstance(CollectionComponent.class, mySandbox); collectionComponent.save(); if (!addComponents(components, collectionComponent)) { mySandbox.removeDelegateComponent(collectionComponent); collectionComponent = null; } mySandbox.save(); return collectionComponent; }
ExternalComponentRegistryImpl implements CoreComponentRegistry { @Override public AbstractComponent newCollection(Collection<AbstractComponent> components) { AbstractComponent collectionComponent = null; AbstractComponent mySandbox = PlatformAccess.getPlatform().getMySandbox(); collectionComponent = newInstance(CollectionComponent.class, mySandbox); collectionComponent.save(); if (!addComponents(components, collectionComponent)) { mySandbox.removeDelegateComponent(collectionComponent); collectionComponent = null; } mySandbox.save(); return collectionComponent; } }
ExternalComponentRegistryImpl implements CoreComponentRegistry { @Override public AbstractComponent newCollection(Collection<AbstractComponent> components) { AbstractComponent collectionComponent = null; AbstractComponent mySandbox = PlatformAccess.getPlatform().getMySandbox(); collectionComponent = newInstance(CollectionComponent.class, mySandbox); collectionComponent.save(); if (!addComponents(components, collectionComponent)) { mySandbox.removeDelegateComponent(collectionComponent); collectionComponent = null; } mySandbox.save(); return collectionComponent; } ExternalComponentRegistryImpl(); }
ExternalComponentRegistryImpl implements CoreComponentRegistry { @Override public AbstractComponent newCollection(Collection<AbstractComponent> components) { AbstractComponent collectionComponent = null; AbstractComponent mySandbox = PlatformAccess.getPlatform().getMySandbox(); collectionComponent = newInstance(CollectionComponent.class, mySandbox); collectionComponent.save(); if (!addComponents(components, collectionComponent)) { mySandbox.removeDelegateComponent(collectionComponent); collectionComponent = null; } mySandbox.save(); return collectionComponent; } 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); }
ExternalComponentRegistryImpl implements CoreComponentRegistry { @Override public AbstractComponent newCollection(Collection<AbstractComponent> components) { AbstractComponent collectionComponent = null; AbstractComponent mySandbox = PlatformAccess.getPlatform().getMySandbox(); collectionComponent = newInstance(CollectionComponent.class, mySandbox); collectionComponent.save(); if (!addComponents(components, collectionComponent)) { mySandbox.removeDelegateComponent(collectionComponent); collectionComponent = null; } mySandbox.save(); return collectionComponent; } 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; }