@SuppressWarnings({ "rawtypes", "deprecation" }) @Test(dataProvider="viewInfoData") public void testGetViewInfos(Set<ViewInfo> viewInfos, final Set<ViewInfo> filterOut, ViewType type, Set<ViewInfo> expected) { AbstractComponent ac = new BaseComponentSub2(); CoreComponentRegistry mockRegistry = Mockito.mock(CoreComponentRegistry.class); PolicyManager mockPolicyManager = Mockito.mock(PolicyManager.class); Mockito.when(mockPlatform.getComponentRegistry()).thenReturn(mockRegistry); Mockito.when(mockRegistry.getViewInfos(Mockito.anyString(), Mockito.same(type))).thenReturn(viewInfos); Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager); Mockito.when(mockPolicyManager.execute(Mockito.matches(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey()), Mockito.any(PolicyContext.class))).thenAnswer( new Answer() { public Object answer(InvocationOnMock invocation) { Object[] args = invocation.getArguments(); PolicyContext pc = (PolicyContext) args[1]; ViewInfo vi = pc.getProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), ViewInfo.class); return new ExecutionResult(pc, !filterOut.contains(vi), ""); } } ); Mockito.when(mockPolicyManager.execute(Mockito.matches(PolicyInfo.CategoryType.PREFERRED_VIEW.getKey()), Mockito.any(PolicyContext.class))).thenReturn(new ExecutionResult(new PolicyContext(),true, "")); Set<ViewInfo> infos = ac.getViewInfos(type); Assert.assertEquals(infos, expected); }
public Set<ViewInfo> getViewInfos(ViewType type) { Set<ViewInfo> possibleViewInfos = PlatformAccess.getPlatform().getComponentRegistry().getViewInfos(getComponentTypeID(), type); Set<ViewInfo> filteredViewInfos = new LinkedHashSet<ViewInfo>(); Platform platform = PlatformAccess.getPlatform(); PolicyManager policyManager = platform.getPolicyManager(); PolicyContext context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), this); context.setProperty(PolicyContext.PropertyName.VIEW_TYPE.getName(), type); for (ViewInfo viewInfo : possibleViewInfos) { context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), viewInfo); if (policyManager.execute(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), context) .getStatus()) { filteredViewInfos.add(viewInfo); } } for (ViewInfo viewRole : filteredViewInfos) { if (this.getClass().equals(viewRole.getPreferredComponentType())) { Set<ViewInfo> setWithPreferredViewFirst = new LinkedHashSet<ViewInfo>(); setWithPreferredViewFirst.add(viewRole); setWithPreferredViewFirst.addAll(filteredViewInfos); filteredViewInfos = setWithPreferredViewFirst; break; } } return filteredViewInfos; }
AbstractComponent implements Cloneable { public Set<ViewInfo> getViewInfos(ViewType type) { Set<ViewInfo> possibleViewInfos = PlatformAccess.getPlatform().getComponentRegistry().getViewInfos(getComponentTypeID(), type); Set<ViewInfo> filteredViewInfos = new LinkedHashSet<ViewInfo>(); Platform platform = PlatformAccess.getPlatform(); PolicyManager policyManager = platform.getPolicyManager(); PolicyContext context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), this); context.setProperty(PolicyContext.PropertyName.VIEW_TYPE.getName(), type); for (ViewInfo viewInfo : possibleViewInfos) { context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), viewInfo); if (policyManager.execute(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), context) .getStatus()) { filteredViewInfos.add(viewInfo); } } for (ViewInfo viewRole : filteredViewInfos) { if (this.getClass().equals(viewRole.getPreferredComponentType())) { Set<ViewInfo> setWithPreferredViewFirst = new LinkedHashSet<ViewInfo>(); setWithPreferredViewFirst.add(viewRole); setWithPreferredViewFirst.addAll(filteredViewInfos); filteredViewInfos = setWithPreferredViewFirst; break; } } return filteredViewInfos; } }
AbstractComponent implements Cloneable { public Set<ViewInfo> getViewInfos(ViewType type) { Set<ViewInfo> possibleViewInfos = PlatformAccess.getPlatform().getComponentRegistry().getViewInfos(getComponentTypeID(), type); Set<ViewInfo> filteredViewInfos = new LinkedHashSet<ViewInfo>(); Platform platform = PlatformAccess.getPlatform(); PolicyManager policyManager = platform.getPolicyManager(); PolicyContext context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), this); context.setProperty(PolicyContext.PropertyName.VIEW_TYPE.getName(), type); for (ViewInfo viewInfo : possibleViewInfos) { context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), viewInfo); if (policyManager.execute(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), context) .getStatus()) { filteredViewInfos.add(viewInfo); } } for (ViewInfo viewRole : filteredViewInfos) { if (this.getClass().equals(viewRole.getPreferredComponentType())) { Set<ViewInfo> setWithPreferredViewFirst = new LinkedHashSet<ViewInfo>(); setWithPreferredViewFirst.add(viewRole); setWithPreferredViewFirst.addAll(filteredViewInfos); filteredViewInfos = setWithPreferredViewFirst; break; } } return filteredViewInfos; }  }
AbstractComponent implements Cloneable { public Set<ViewInfo> getViewInfos(ViewType type) { Set<ViewInfo> possibleViewInfos = PlatformAccess.getPlatform().getComponentRegistry().getViewInfos(getComponentTypeID(), type); Set<ViewInfo> filteredViewInfos = new LinkedHashSet<ViewInfo>(); Platform platform = PlatformAccess.getPlatform(); PolicyManager policyManager = platform.getPolicyManager(); PolicyContext context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), this); context.setProperty(PolicyContext.PropertyName.VIEW_TYPE.getName(), type); for (ViewInfo viewInfo : possibleViewInfos) { context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), viewInfo); if (policyManager.execute(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), context) .getStatus()) { filteredViewInfos.add(viewInfo); } } for (ViewInfo viewRole : filteredViewInfos) { if (this.getClass().equals(viewRole.getPreferredComponentType())) { Set<ViewInfo> setWithPreferredViewFirst = new LinkedHashSet<ViewInfo>(); setWithPreferredViewFirst.add(viewRole); setWithPreferredViewFirst.addAll(filteredViewInfos); filteredViewInfos = setWithPreferredViewFirst; break; } } return filteredViewInfos; }  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(); }
AbstractComponent implements Cloneable { public Set<ViewInfo> getViewInfos(ViewType type) { Set<ViewInfo> possibleViewInfos = PlatformAccess.getPlatform().getComponentRegistry().getViewInfos(getComponentTypeID(), type); Set<ViewInfo> filteredViewInfos = new LinkedHashSet<ViewInfo>(); Platform platform = PlatformAccess.getPlatform(); PolicyManager policyManager = platform.getPolicyManager(); PolicyContext context = new PolicyContext(); context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), this); context.setProperty(PolicyContext.PropertyName.VIEW_TYPE.getName(), type); for (ViewInfo viewInfo : possibleViewInfos) { context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), viewInfo); if (policyManager.execute(PolicyInfo.CategoryType.FILTER_VIEW_ROLE.getKey(), context) .getStatus()) { filteredViewInfos.add(viewInfo); } } for (ViewInfo viewRole : filteredViewInfos) { if (this.getClass().equals(viewRole.getPreferredComponentType())) { Set<ViewInfo> setWithPreferredViewFirst = new LinkedHashSet<ViewInfo>(); setWithPreferredViewFirst.add(viewRole); setWithPreferredViewFirst.addAll(filteredViewInfos); filteredViewInfos = setWithPreferredViewFirst; break; } } return filteredViewInfos; }  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; }