Examples of PolicyManager


Examples of gov.nasa.arc.mct.services.component.PolicyManager

       
        PolicyContext context = new PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), parentComponent);
        context.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w');
        String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY.getKey();
        PolicyManager policyManager = PlatformAccess.getPlatform().getPolicyManager();
        return policyManager.execute(compositionKey, context).getStatus();
    }
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

    public void setupPlatform() {
       
        oldPlatform = PlatformAccess.getPlatform();
       
        ExecutionResult trueResult = new ExecutionResult(null, true, null);
        PolicyManager mockPolicyManager = Mockito.mock(PolicyManager.class);
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext>any())).thenReturn(trueResult);
        Platform mockPlatform = Mockito.mock(Platform.class);
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
        Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistenceProvider);
        Mockito.when(mockPersistenceProvider.getReferencedComponents(Mockito.any(AbstractComponent.class))).thenReturn(Collections.<AbstractComponent>emptyList());
       
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

        if (node != null) {
            AbstractComponent parentComponent = ((View) node.getUserObject()).getManifestedComponent();
            PolicyContext context = new PolicyContext();
            context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), parentComponent);
            context.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w');
            PolicyManager policyManager = PlatformAccess.getPlatform().getPolicyManager();
            if (!policyManager.execute(PolicyInfo.CategoryType.OBJECT_INSPECTION_POLICY_CATEGORY.getKey(), context).getStatus())
                return;

            AbstractComponent childComponent = event.getChildComponent();
            Set<ViewInfo> viewInfos = childComponent.getViewInfos(ViewType.NODE);
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

       
        mockPlatform = Mockito.mock(Platform.class);
        new PlatformAccess().setPlatform(mockPlatform);
       
        PolicyManager mockPolicyManager = Mockito.mock(PolicyManager.class);
       
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
       
        Answer<ExecutionResult> answer = new Answer<ExecutionResult> () {
            @Override
            public ExecutionResult answer(InvocationOnMock invocation) throws Throwable {
                PolicyContext context = (PolicyContext) invocation.getArguments()[1];
                AbstractComponent comp = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), AbstractComponent.class);
                return new ExecutionResult(context, goodComponents.contains(comp), "" );
            }           
        };
       
        Mockito.when(mockPolicyManager.execute(Mockito.eq(PolicyInfo.CategoryType.OBJECT_INSPECTION_POLICY_CATEGORY.getKey()), Mockito.<PolicyContext>any())).thenAnswer(answer);
       
       
    }
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

    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);
            }
        }
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

     *
     * @return true if this component can be deleted, false otherwise.
     */
    public final boolean canBeDeleted() {
        Platform platform = PlatformAccess.getPlatform();
        PolicyManager policyManager = platform.getPolicyManager();

        PolicyContext context = new PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), this);
        context.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w');
        String compositionKey = PolicyInfo.CategoryType.CAN_DELETE_COMPONENT_POLICY_CATEGORY
                        .getKey();
        return policyManager.execute(compositionKey, context).getStatus();
    }
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

        if (isLeaf()) {
            throw new UnsupportedOperationException("components declared as leaf cannot be mutated");
        }
        Platform platform = PlatformAccess.getPlatform();
        PolicyManager policyManager = platform.getPolicyManager();
        PolicyContext context = new PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), this);
        context.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w');
        context
                        .setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(),
                                        childComponents);
        if (policyManager.execute(PolicyInfo.CategoryType.ACCEPT_DELEGATE_MODEL_CATEGORY.getKey(),
                        context).getStatus()) {
         
            if (!childComponents.isEmpty()) {
                for (AbstractComponent childComponent : childComponents) {
                    processAddDelegateComponent(childIndex, childComponent);
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

    @Mock
    private PersistenceProvider mockPersistenceService;
   
    @BeforeMethod
    public void setup() {
        PolicyManager mockManager = new PolicyManager() {
           
            @Override
            public ExecutionResult execute(String categoryKey, PolicyContext context) {
                return new ExecutionResult(null, true, null);
            }
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

    @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);
    }
View Full Code Here

Examples of gov.nasa.arc.mct.services.component.PolicyManager

       
        // Should only handle single, writable targets...
       
        // Set up mocks
        ActionContext mockContext = Mockito.mock(ActionContext.class);
        PolicyManager mockPolicy = Mockito.mock(PolicyManager.class);
        AbstractComponent mockComponent = Mockito.mock(AbstractComponent.class);
        View mockView = Mockito.mock(View.class);
        String compositionKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY.getKey();
       
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicy);
       
        // First, This's Import menu
        // No window active - should disallow
        Mockito.when(mockContext.getWindowManifestation()).thenReturn(null);
        Assert.assertFalse(thisMenu.canHandle(mockContext));
       
        // Active window but component is null - should disallow
        Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockView);
        Mockito.when(mockView.getManifestedComponent()).thenReturn(null);
        Assert.assertFalse(thisMenu.canHandle(mockContext));
       
        // Has a window, but policy says no - should disallow
        Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockView);
        Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, false, ""));
        Assert.assertFalse(thisMenu.canHandle(mockContext));
       
        // If policy allows, then canHandle should be true
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, true, ""));
        Assert.assertTrue(thisMenu.canHandle(mockContext));
       
       
        // Second, Objects's Import menu
        // Null selections - should disallow
        Mockito.when(mockContext.getSelectedManifestations()).thenReturn(null);
        Assert.assertFalse(objsMenu.canHandle(mockContext));

        // Empty selections - should disallow
        Mockito.when(mockContext.getSelectedManifestations())
            .thenReturn(Collections.<View>emptyList());
        Assert.assertFalse(objsMenu.canHandle(mockContext));
       
        // One selection but policy says no - should disallow
        Mockito.when(mockContext.getSelectedManifestations())
            .thenReturn(Arrays.asList(mockView));
        Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);       
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, false, ""));              
        Assert.assertFalse(objsMenu.canHandle(mockContext));
       
        // One selection but policy says yes - should allow!
        Mockito.when(mockContext.getSelectedManifestations())
            .thenReturn(Arrays.asList(mockView));
        Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);       
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, true, ""));              
        Assert.assertTrue(objsMenu.canHandle(mockContext));
       
        // Multiple selections, even though policy says yes - should disallow
        Mockito.when(mockContext.getSelectedManifestations())
            .thenReturn(Arrays.asList(mockView, mockView));
        Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);       
        Mockito.when(mockPolicy.execute(Mockito.eq(compositionKey), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, true, ""));              
        Assert.assertFalse(objsMenu.canHandle(mockContext));

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.