@Test public void testIsEnabled() { ActionContext mockContext = Mockito.mock(ActionContext.class); View mockView = Mockito.mock(View.class); AbstractComponent mockComponent = Mockito.mock(AbstractComponent.class); Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent); Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockView); Assert.assertTrue(importThisAction.canHandle(mockContext)); Mockito.when(mockContext.getSelectedManifestations()) .thenReturn(Arrays.<View>asList(mockView)); Assert.assertTrue(importAction.canHandle(mockContext)); for (boolean truth : new boolean[] {true, false}) { Mockito.when(mockPolicy.execute(Mockito.anyString(), Mockito.<PolicyContext>any())) .thenReturn(new ExecutionResult(null, truth, "")); Assert.assertEquals(importAction.isEnabled(), truth); Assert.assertEquals(importThisAction.isEnabled(), truth); } }
@Override public boolean isEnabled() { AbstractComponent targetComponent = currentContext.getSelectedManifestations() .iterator().next().getManifestedComponent(); PolicyContext policyContext = new PolicyContext(); policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), targetComponent); policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w'); String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY .getKey(); return PlatformAccess.getPlatform().getPolicyManager().execute(compositionKey, policyContext).getStatus(); }
ImportAction extends ContextAwareAction implements PropertyChangeListener { @Override public boolean isEnabled() { AbstractComponent targetComponent = currentContext.getSelectedManifestations() .iterator().next().getManifestedComponent(); PolicyContext policyContext = new PolicyContext(); policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), targetComponent); policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w'); String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY .getKey(); return PlatformAccess.getPlatform().getPolicyManager().execute(compositionKey, policyContext).getStatus(); } }
ImportAction extends ContextAwareAction implements PropertyChangeListener { @Override public boolean isEnabled() { AbstractComponent targetComponent = currentContext.getSelectedManifestations() .iterator().next().getManifestedComponent(); PolicyContext policyContext = new PolicyContext(); policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), targetComponent); policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w'); String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY .getKey(); return PlatformAccess.getPlatform().getPolicyManager().execute(compositionKey, policyContext).getStatus(); } ImportAction(); }
ImportAction extends ContextAwareAction implements PropertyChangeListener { @Override public boolean isEnabled() { AbstractComponent targetComponent = currentContext.getSelectedManifestations() .iterator().next().getManifestedComponent(); PolicyContext policyContext = new PolicyContext(); policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), targetComponent); policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w'); String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY .getKey(); return PlatformAccess.getPlatform().getPolicyManager().execute(compositionKey, policyContext).getStatus(); } ImportAction(); @Override void actionPerformed(ActionEvent e); @Override void propertyChange(PropertyChangeEvent evt); List<File> selectFiles(Component source); @Override boolean canHandle(ActionContext context); @Override boolean isEnabled(); }
ImportAction extends ContextAwareAction implements PropertyChangeListener { @Override public boolean isEnabled() { AbstractComponent targetComponent = currentContext.getSelectedManifestations() .iterator().next().getManifestedComponent(); PolicyContext policyContext = new PolicyContext(); policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), targetComponent); policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w'); String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY .getKey(); return PlatformAccess.getPlatform().getPolicyManager().execute(compositionKey, policyContext).getStatus(); } ImportAction(); @Override void actionPerformed(ActionEvent e); @Override void propertyChange(PropertyChangeEvent evt); List<File> selectFiles(Component source); @Override boolean canHandle(ActionContext context); @Override boolean isEnabled();  }