Package gov.nasa.arc.mct.policy

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


    }
  }
 
  @Override
  public ExecutionResult execute(String categoryKey, PolicyContext context) {
    ExecutionResult result; 
    List<Policy> list = map.get(categoryKey);
    if (list == null)
      return new ExecutionResult(context, true, "No policies registered for " + categoryKey);
    ElapsedTimer categoryTimer = new ElapsedTimer();
    categoryTimer.startInterval();
    for (Policy policy : list) {
      ElapsedTimer policyTimer = new ElapsedTimer();
      policyTimer.startInterval();
      result = policy.execute(context);
      policyTimer.stopInterval();
      PERF_LOGGER.debug("time to execute policy {0} {1}", policy.getClass().getName(), policyTimer.getIntervalInMillis());
      if (!result.getStatus()) {
        LOGGER.debug("Policy category {} failed on policy {}", categoryKey, policy.getClass().getName());
        return result;
      }
    }
    categoryTimer.stopInterval();
    PERF_LOGGER.debug("time to execute policy category {0} {1}", categoryKey, categoryTimer.getIntervalInMillis());
    return new ExecutionResult(context, true, categoryKey + " passed.");
  }
View Full Code Here


    public void testCanDeleteComponentPolicy() {
        PolicyContext context = new  PolicyContext();
       
        context = new  PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), mockPrivateComponent);
        ExecutionResult exResult = policy.execute(context);
       
        Assert.assertTrue(exResult.getStatus());
       
        context = new  PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), mockPrivateComponentWithDifferentOwner);
        exResult = policy.execute(context);
       
        Assert.assertFalse(exResult.getStatus());
       
        MineTaxonomyComponent mockMine = Mockito.mock(MineTaxonomyComponent.class);
        context = new  PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), mockMine);
        exResult = policy.execute(context);
       
        Assert.assertFalse(exResult.getStatus());
    }
View Full Code Here

    @BeforeMethod
    protected void postSetup() {
        MockitoAnnotations.initMocks(this);
        (new PlatformAccess()).setPlatform(mockPlatform);
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(new ExecutionResult(null,true,""));
        Mockito.when(mockComponent.getComponentId()).thenReturn("abc");
    }
View Full Code Here

        Mockito.when(mockPlatform.getCurrentUser()).thenReturn(mockUser);
        Mockito.when(mockGroup.getDiscipline()).thenReturn(compGroup);
        Mockito.when(mockUser.getUserId()).thenReturn(userID);
        Mockito.when(mockUser.getDisciplineId()).thenReturn(groupID);
       
        ExecutionResult result = ownershipPolicy.execute(context);
        Assert.assertEquals(result.getStatus(), expectedResult);
    }
View Full Code Here

    @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

import gov.nasa.arc.mct.policy.PolicyContext;

final class SamplePolicy implements Policy {
  @Override
  public ExecutionResult execute(PolicyContext context) {
    return new ExecutionResult(context, true, PolicyManagerTest.POLICY_ACTION_DESC);
  }
View Full Code Here

    }
   
    public static class TestPolicyClass implements Policy {
        @Override
        public ExecutionResult execute(PolicyContext context) {
           return new ExecutionResult(context,false,"");
        }
View Full Code Here

    private PersistenceProvider mockPersistence;
   
    public static class TestPolicy implements Policy {
        public ExecutionResult execute(PolicyContext context) {
            return new ExecutionResult(context,true,"");
         }
View Full Code Here

public class MockPolicy implements Policy {

    @Override
    public ExecutionResult execute(PolicyContext context) {
        return new ExecutionResult(context, true, "");
    }
View Full Code Here

        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

TOP

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

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.