Package gov.nasa.arc.mct.policy

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


                        Collections.<AbstractComponent> emptyList());
       
        Mockito.when(mockPlatform.getPolicyManager())
            .thenReturn(mockPolicyManager);
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext> any()))
            .thenReturn(new ExecutionResult(null, false, null)); // Nothing is locked

       
        GuiActionRunner.execute(new GuiTask() {
            @SuppressWarnings("serial")
            @Override
View Full Code Here


     * https://github.com/nasa/mct/issues/220
     */
    @Test
    public void testWithoutEmbeddedView() throws Exception {
        Mockito.when(mockPersistence.getAllProperties(Mockito.anyString())).thenReturn(new HashMap<String, ExtendedProperties>());
        Mockito.when(mockPolicy.execute(Mockito.anyString(), Mockito.<PolicyContext>any())).thenReturn(new ExecutionResult(null, true, ""));
       
        ViewInfo mockCanvasViewInfo = Mockito.mock(ViewInfo.class);
        AbstractComponent mockCanvasComponent = new TestComponent();
        AbstractComponent mockDropComponent = new TestComponent();
        CanvasManifestation canvas = new CanvasManifestation(mockCanvasComponent, mockCanvasViewInfo);
View Full Code Here

        }
        MockitoAnnotations.initMocks(this);
       
        (new PlatformAccess()).setPlatform(mockPlatform);
        when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
        when(mockPolicyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(new ExecutionResult(null,true,""));
        when(canvasManifestation.getInfo()).thenReturn(new ViewInfo(TestView.class,"",ViewType.CENTER));
        when(canvasManifestation.getComponents()).thenReturn(new Component[] {});
        configureManifestation(canvasManifestation);
        when(canvasManifestation.getSelectionProvider()).thenReturn(mockProvider);
        when(mockProvider.getSelectedManifestations()).thenReturn(Collections.singleton(canvasManifestation2));
View Full Code Here

        (new PlatformAccess()).setPlatform(mockPlatform);
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
        Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistenceProvider);
        Mockito.when(mockPersistenceProvider.getReferencedComponents(Mockito.any(AbstractComponent.class))).thenReturn(Collections.<AbstractComponent>emptyList());
        ExecutionResult er = new ExecutionResult(null, true, null);
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(er);
       
        componentA = new MockComponent(IdGenerator.nextComponentId(), false);
        componentA.getCapability(ComponentInitializer.class).initialize();
View Full Code Here

       
        // 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

        }
        MockitoAnnotations.initMocks(this);
        (new PlatformAccess()).setPlatform(mockPlatform);
        Mockito.when(mockPlatform.getPolicyManager()).thenReturn(mockPolicyManager);
        Mockito.when(mockPlatform.getRootComponent()).thenReturn(rootComponent);
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(new ExecutionResult(null,true,""));
        TestSetupUtilities.setUpActiveHousing();

        // Create a model role, a dummy component, and a tree with a single root node.
        String id = NODE_NAME;
        MyComponent c = new MyComponent(id);
View Full Code Here

        Mockito.when(mockRegistry.isCreatable(Mockito.<Class<?>>any())).thenReturn(true);
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext>any())).thenAnswer(
                new Answer<ExecutionResult>() {
                    @Override
                    public ExecutionResult answer(InvocationOnMock invocation) throws Throwable {
                        return new ExecutionResult((PolicyContext) invocation.getArguments()[1], true, "");
                    }                   
                }
        );
       
        mockSelections.clear();
View Full Code Here

       
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext>any())).thenAnswer(
                new Answer<ExecutionResult>() {
                    @Override
                    public ExecutionResult answer(InvocationOnMock invocation) throws Throwable {
                        return new ExecutionResult((PolicyContext) invocation.getArguments()[1], false, expected);
                    }                   
                }
        );
       
        // Ensure that all three options are available under baseline/nominal preconditions
View Full Code Here

*/
public class FilterViewPolicy implements Policy {
 
  @Override
  public ExecutionResult execute(PolicyContext context) {
    ExecutionResult trueResult = new ExecutionResult(context, true, "");

    if (!checkArguments(context))
      return trueResult; // Return true to skip this policy and pass the context to the next one.
   
    ExampleComponent targetComponent = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), ExampleComponent.class);
    ViewInfo viewInfo = context.getProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), ViewInfo.class);
    if (viewInfo.getViewClass().equals(PublicInfoView.class))
      return new ExecutionResult(context, false, targetComponent.getDisplayName()
                + " is private, cannot show " + viewInfo.getClass().getName()); //NOI18N
   
    if (viewInfo.getViewClass().equals(PrivateInfoView.class))
      return new ExecutionResult(context, false, targetComponent.getDisplayName()
                + " is public, cannot show " + viewInfo.getClass().getName()); //NOI18N
   
    return trueResult;
  }
View Full Code Here

        Mockito.when(mockPlatform.getPolicyManager())
            .thenReturn(mockPolicyManager);
        Mockito.when(mockPlatform.getWindowManager())
            .thenReturn(mockWindowManager);
        Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext>any()))
            .thenReturn(new ExecutionResult(null, true, ""));
        Mockito.when(mockPersistence.getComponent(TEST_COMPONENT_ID))
            .thenReturn(mockComponent);
        Mockito.when(mockComponent.getComponentId())
            .thenReturn(TEST_COMPONENT_ID);
        Mockito.when(mockViewInfo.getType())
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.