Package gov.nasa.arc.mct.policy

Examples of gov.nasa.arc.mct.policy.PolicyContext


   }
   
    @Test
    public void testReservedWordsNamingPolicy() {

        PolicyContext context = new  PolicyContext();
        context.setProperty("NAME", TEST_STRING_SHOULD_FAIL);
        ExecutionResult exResult = policy.execute(context);
       
        Assert.assertFalse(exResult.getStatus());
       
        context.setProperty("NAME", TEST_STRING_SHOULD_PASS);
        exResult = policy.execute(context);
       
        Assert.assertTrue(exResult.getStatus());
    }
View Full Code Here


   @Test
   public void test() {
     assertNotNull(manager);    
     assertNotNull(policy);
    
     PolicyContext context = new PolicyContext();
     context.setProperty(POLICY_ACTION_KEY, POLICY_ACTION_DESC);
     assertTrue(manager.execute(MY_POLICY_CATEGORY_KEY, context).getStatus());
   }
View Full Code Here

     manager.refreshExtendedPolicies(
         Arrays.asList(new ExtendedComponentProvider(provider,"test"),
                  new ExtendedComponentProvider(badProvider, "test2"))
     );
    
     PolicyContext context = new PolicyContext();
     context.setProperty(POLICY_ACTION_KEY, POLICY_ACTION_DESC);
     assertTrue(manager.execute(MY_POLICY_CATEGORY_KEY, context).getStatus());
   }
View Full Code Here

     manager.refreshExtendedPolicies(
         Arrays.asList(new ExtendedComponentProvider(provider,"test"),
                  new ExtendedComponentProvider(badProvider, "test2"))
     );
    
     PolicyContext context = new PolicyContext();
     context.setProperty(POLICY_ACTION_KEY, POLICY_ACTION_DESC);
     assertTrue(manager.execute(MY_POLICY_CATEGORY_KEY, context).getStatus());
   }
View Full Code Here

    @Override
    public void updateMonitoredGUI(AddChildEvent event) {
        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();
View Full Code Here

        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

                    public ExecutionResult answer(InvocationOnMock invocation) throws Throwable {
                        Set<AbstractComponent> set =
                                invocation.getArguments()[0].equals(
                                        PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY.getKey()) ?
                                                canCompose : canDelete;
                        PolicyContext context = (PolicyContext) invocation.getArguments()[1];
                        return set.contains(
                                context.getProperty(
                                        PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
                                        AbstractComponent.class)) ?
                                                yes : no;
                    }                   
                });
View Full Code Here

      Mockito.when(parentComponent.getComponents()).thenReturn(
                 Collections.<AbstractComponent> emptyList());
   
    access = new PolicyManagerAccess();
    access.setPolicyManager(policyManager);
    PolicyContext context = new PolicyContext();
        result = new ExecutionResult(context, true, "");
        Mockito.when(policyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(result)
        mockComponent = new DummyComponent();
        new PlatformAccess().setPlatform(mockPlatform);
    Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockProvider);
View Full Code Here

           
            return result.getStatus();
        }
       
        protected PolicyContext makePolicyContext(List<AbstractComponent> sourceComponents, AbstractComponent targetComponent) {
            PolicyContext context = new PolicyContext();
            context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), targetComponent);
            context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(), sourceComponents);
            context.setProperty(PolicyContext.PropertyName.ACTION.getName(), Character.valueOf( 'w' ));
            context.setProperty(CUSTOM_POLICY_KEY, this.getName());
            return context;
        }
View Full Code Here

        @Override
        public boolean canPerform() {
            // Move involves a Remove Manifestation, so obey those rules
            for (String id : parents.keySet()) {
                PolicyContext context = makePolicyContext(toRemove.get(id), parents.get(id));
                if (!consultPolicy(PolicyInfo.CategoryType.CAN_REMOVE_MANIFESTATION_CATEGORY, context) ||
                    !consultPolicy(PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY, context)) {
                    return false;
                }
            }
View Full Code Here

TOP

Related Classes of gov.nasa.arc.mct.policy.PolicyContext

Copyright © 2018 www.massapicom. 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.