Package gov.nasa.arc.mct.policy

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


            return false;
       
        AbstractComponent parentComponent = ((View) parentNode.getUserObject()).getManifestedComponent();
        AbstractComponent selectedComponent = View.class.cast(lastPathComponent.getUserObject()).getManifestedComponent();

        PolicyContext context = new PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), parentComponent);
        context.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w');
        context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(), Collections.singleton(selectedComponent));
        context.setProperty(PolicyContext.PropertyName.VIEW_MANIFESTATION_PROVIDER.getName(), parentNode.getUserObject());
       
        String canRemoveManifestationKey = PolicyInfo.CategoryType.CAN_REMOVE_MANIFESTATION_CATEGORY.getKey();
        boolean canRemoveManifestation = PolicyManagerImpl.getInstance().execute(canRemoveManifestationKey, context).getStatus();
       
        if (canRemoveManifestation) {
View Full Code Here


  @Test
  public void testRejectCanvasView() throws Exception {
    (new PolicyManagerAccess()).setPolicyManager(mockPolicyManager);
    AbstractComponent comp = Mockito.mock(AbstractComponent.class);
    PlotViewPolicy policy = new PlotViewPolicy();
    PolicyContext context = new PolicyContext();
    context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), new ViewInfo(PlotViewManifestation.class,"",ViewType.CENTER));
    Method m = policy.getClass().getDeclaredMethod("rejectCanvasView", PolicyContext.class, AbstractComponent.class);
    m.setAccessible(true);
    Mockito.when(comp.isLeaf()).thenReturn(false);
    Assert.assertEquals(m.invoke(policy, context, comp), Boolean.FALSE, "direct access to plot view role should always be true");
    context.setProperty(PolicyContext.PropertyName.VIEW_TYPE.getName(), ViewType.CENTER);
    Assert.assertEquals(m.invoke(policy, context, comp), Boolean.TRUE, "collections must not support canvas view roles");
    Mockito.when(comp.isLeaf()).thenReturn(true);
    Assert.assertEquals(m.invoke(policy, context, comp), Boolean.FALSE, "leafs must support canvas view roles");

  }
View Full Code Here

  }
 
  @Test
  public void testExecute() {
    Policy policy = new PlotViewPolicy();
    PolicyContext context;
   
    ViewInfo plotViewInfo = new ViewInfo(PlotViewManifestation.class, "Plot", ViewType.OBJECT);
   
    // Plot views should be allowed for leaf component with a feed
    context = new PolicyContext();
    context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(),
        plotViewInfo);
    context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
        leafWithAFeedComponent);   
    Assert.assertTrue(policy.execute(context).getStatus());

    // ...but not without a feed
    context = new PolicyContext();
    context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(),
        plotViewInfo);
    context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
        leafWithOutAFeedComponent);   
    Assert.assertFalse(policy.execute(context).getStatus());
   
    // Plot view policy should not reject non-plot, ever
    for (AbstractComponent ac : new AbstractComponent[] { leafWithAFeedComponent, leafWithOutAFeedComponent, nonLeafComponent} ) {
      for (ViewType vt : ViewType.values()) {
        ViewInfo someViewInfo = new ViewInfo(NonPlotView.class, "NonPlot", vt);
        context = new PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(),
            someViewInfo);
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
            ac);   
        Assert.assertTrue(policy.execute(context).getStatus());
      }
    }
  }
View Full Code Here

  @BeforeMethod
  public void setup() {
    MockitoAnnotations.initMocks(this);
   
    policy = new PlotStringPolicy();
    context = new PolicyContext();
    viewInfo = new ViewInfo(PlotViewManifestation.class, "Plot", ViewType.OBJECT);
    context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(),
        viewInfo);
    context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
        mockProvider);
View Full Code Here

 
  @BeforeTest
  public void setup() {
    MockitoAnnotations.initMocks(this);
    testPolicy = new GraphicalViewPolicy();
    context = new PolicyContext();
  }
View Full Code Here

   
    @BeforeMethod
    public void init() {
        MockitoAnnotations.initMocks(this);
        embeddedPolicy = new EmbeddedCanvasViewsAreNotWriteable();
        context = new PolicyContext();
        context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), mockedComponent);
    }
View Full Code Here

        }

        protected ExecutionResult checkPolicyForDrops(AbstractComponent canvasComponent,
                        Collection<AbstractComponent> dropComponents,
                        View canvasManifestation) {
            PolicyContext context = new PolicyContext();
            context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(),
                            canvasComponent);
            context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(),
                            dropComponents);
            context
                            .setProperty(PolicyContext.PropertyName.ACTION.getName(), Character
                                            .valueOf('w'));
            context.setProperty(PolicyContext.PropertyName.VIEW_MANIFESTATION_PROVIDER.getName(),
                            canvasManifestation);
            String policyCategoryKey = PolicyInfo.CategoryType.COMPOSITION_POLICY_CATEGORY.getKey();
            ExecutionResult result = PolicyManagerAccess.getPolicyManager().execute(
                            policyCategoryKey, context);
            return result;
View Full Code Here

        MockitoAnnotations.initMocks(this);
        dir = new MCTDirectoryArea();
        handler = new StubbedHandler(dir, tree, model);
        (new PlatformAccess()).setPlatform(mockPlatform);
        when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
        ExecutionResult result = new ExecutionResult(new PolicyContext(), true, "mock");
        when(mockPolicyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(result);
     }
View Full Code Here

        access.setPlatform(mockPlatform);
        Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistenceProvider);
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
        Mockito.when(mockPlatform.getComponentRegistry()).thenReturn(mockComponentRegistry);
        Mockito.when(mockPlatform.getWindowManager()).thenReturn(mockWindowManager);
        ExecutionResult mockResult = new ExecutionResult(new PolicyContext(), true, "");
        Mockito.when(mockpoPolicyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(mockResult);
        Mockito.when(mockWindowManager.<Object>showInputDialog(
                Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.anyMap()))
                .thenAnswer(new Answer<Object>() {
                    @Override
View Full Code Here

        WindowManager mockWindowManager = Mockito.mock(WindowManager.class);
       
        access.setPlatform(mockPlatform);
        Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistenceProvider);
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);       
        ExecutionResult mockResult = new ExecutionResult(new PolicyContext(), true, "");
        Mockito.when(mockpoPolicyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(mockResult);
        Mockito.when(mockPlatform.getComponentRegistry()).thenReturn(mockComponentRegistry);
        Mockito.when(mockPlatform.getWindowManager()).thenReturn(mockWindowManager);
        Mockito.when(mockWindowManager.<Object>showInputDialog(
                Mockito.anyString(), Mockito.anyString(), Mockito.<Object[]>any(), Mockito.any(), Mockito.anyMap()))
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.