AbstractComponent implements Cloneable { @Override public AbstractComponent clone() { try { Class<? extends AbstractComponent> componentClassType = this.getClass(); String newID = IdGenerator.nextComponentId(); AbstractComponent clonedComponent = componentClassType.newInstance(); clonedComponent.setId(newID); ModelStatePersistence persistence = getCapability(ModelStatePersistence.class); if (persistence != null) { String modelState = persistence.getModelState(); ModelStatePersistence clonedPersistence = clonedComponent.getCapability(ModelStatePersistence.class); assert clonedPersistence != null; clonedPersistence.setModelState(modelState); } for (AbstractComponent child : getComponents()) { clonedComponent.addComponent(child); } ensureViewPropertiesLoaded(); clonedComponent.ensureViewPropertiesLoaded(); for (Entry<String, ExtendedProperties> e : viewRoleProperties.entrySet()) { clonedComponent.viewRoleProperties.put(e.getKey(), e.getValue().clone()); } clonedComponent.owner = owner; clonedComponent.creator = creator; clonedComponent.displayName = displayName; clonedComponent.externalKey = externalKey; clonedComponent.version = version; ComponentInitializer clonedCapability = clonedComponent.getCapability(ComponentInitializer.class); clonedCapability.initialize(); return clonedComponent; } catch (SecurityException e) { throw new MCTRuntimeException(e); } catch (IllegalArgumentException e) { throw new MCTRuntimeException(e); } catch (InstantiationException e) { throw new MCTRuntimeException(e); } catch (IllegalAccessException e) { throw new MCTRuntimeException(e); } }  static void checkBaseComponentRequirements(Class<? extends AbstractComponent> componentClass); AbstractComponent getWorkUnitDelegate(); String getComponentTypeID(); Set<ViewInfo> getViewInfos(ViewType type); String getId(); String getComponentId(); void setId(String id); boolean isLeaf(); synchronized void setOwner(String owner); final synchronized String getOriginalOwner(); synchronized String getOwner(); synchronized String getCreator(); synchronized Date getCreationDate(); final void addDelegateComponent(AbstractComponent childComponent); final void componentSaved(); Collection<AbstractComponent> getReferencingComponents(); final boolean canBeDeleted(); final boolean addDelegateComponents(Collection<AbstractComponent> childComponents); final boolean addDelegateComponents(int childIndex,
                    Collection<AbstractComponent> childComponents); final void removeDelegateComponent(AbstractComponent childComponent); synchronized void removeDelegateComponents(Collection<AbstractComponent> childComponents); synchronized String getDisplayName(); String getExtendedDisplayName(); synchronized String getExternalKey(); synchronized void setExternalKey(String key); synchronized void setDisplayName(String name); void setAndUpdateDisplayName(String name); void setAndUpdateOwner(String name); final void open(); final void open(GraphicsConfiguration graphicsConfig); final T getCapability(Class<T> capability); final List<T> getCapabilities(Class<T> capability); boolean isDirty(); synchronized boolean isStale(); void save(); @Override AbstractComponent clone(); int getVersion(); T getAsset(Class<T> assetClass); @Deprecated final javax.swing.ImageIcon getIcon(); @Deprecated static javax.swing.ImageIcon getIconForComponentType(String className); synchronized void resetComponentProperties(ResetPropertiesTransaction txn); void addViewManifestation(View viewManifestation); Set<View> getAllViewManifestations(); synchronized List<AbstractComponent> getComponents(); static AbstractComponent getComponentById(String id); List<PropertyDescriptor> getFieldDescriptors(); final static AbstractComponent NULL_COMPONENT; }
@Test public void testClone() { BaseComponentSub2 comp = new BaseComponentSub2(); ExtendedProperties props = new ExtendedProperties(); props.addProperty("value", "value"); Mockito.when(mockPersistenceService.getAllProperties(comp.getComponentId())).thenReturn(Collections.singletonMap("view1", props)); BaseComponentSub2 compClone = BaseComponentSub2.class.cast(comp.clone()); Map<String,ExtendedProperties> clonedProps = compClone.getCapability(ComponentInitializer.class).getAllViewRoleProperties(); Assert.assertTrue(clonedProps.size() == 1); ExtendedProperties clonedEp = clonedProps.get("view1"); Assert.assertTrue(clonedEp.getAllProperties().size() == 1); Assert.assertEquals(clonedEp.getProperty("value",String.class),"value"); }