Package gov.nasa.arc.mct.gui

Examples of gov.nasa.arc.mct.gui.ActionContext


        MockitoAnnotations.initMocks(this);
        executableButtonAction = new ExecutableButtonAction();
    }
   
    private final ActionContext mockActionContextObject() {
        ActionContext context = new ActionContext() {
           
             @Override
             public View getWindowManifestation() {
                 return View.NULL_VIEW_MANIFESTATION;
             }
View Full Code Here


    }
   
    @Test
    public void testCanHandle() {
        
         ActionContext context = mockActionContextObject();
         Assert.assertTrue(context.getSelectedManifestations().size() == 1);
         Assert.assertNotNull(context);
        
         Mockito.when(manifestation.getManifestedComponent()).thenReturn(abstractComp);
         Assert.assertNotNull(abstractComp);
    }
View Full Code Here

    public void testCanHandle() {
        // Mock context has a content area, so we should be able to handle this
        Assert.assertTrue(new RefreshAction().canHandle(mockContext));
       
        // With no housing, action can't be handled
        ActionContext noHousingContext = Mockito.mock(ActionContext.class);
        Mockito.when(noHousingContext.getWindowManifestation()).thenReturn(null);
        Assert.assertFalse(new RefreshAction().canHandle(noHousingContext));

        // With no content area, action can't be handled
        ActionContext noContentContext = Mockito.mock(ActionContext.class);
        MCTHousingViewManifestation noContentHousing = Mockito.mock(MCTHousingViewManifestation.class);
        Mockito.when(noContentContext.getWindowManifestation()).thenReturn(noContentHousing);
        Mockito.when(noContentHousing.getContentArea()).thenReturn(null);
        Assert.assertFalse(new RefreshAction().canHandle(noHousingContext));
    }
View Full Code Here

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

        MockitoAnnotations.initMocks(this);
        openMultiMonitorsObjectsAction = new OpenMultipleMonitorsObjectsAction();
    }
   
    private final ActionContext mockActionContextObject() {
        ActionContext context = new ActionContext() {
           
             @Override
             public View getWindowManifestation() {
                 return View.NULL_VIEW_MANIFESTATION;
             }
View Full Code Here

    }
   
    @Test
    public void testCanHandle() {
        
         ActionContext context = mockActionContextObject();
         Assert.assertTrue(context.getSelectedManifestations().size() == 1);
         Assert.assertNotNull(context);
        
         Mockito.when(manifestation.getManifestedComponent()).thenReturn(abstractComp);
         Assert.assertNotNull(abstractComp);
    }
View Full Code Here

        MockitoAnnotations.initMocks(this);
        openMultiMonitorsThissAction = new OpenMultipleMonitorsThisAction();
    }
   
    private final ActionContext mockActionContextObject() {
        ActionContext context = new ActionContext() {
           
             @Override
             public View getWindowManifestation() {
                 return View.NULL_VIEW_MANIFESTATION;
             }
View Full Code Here

    }
   
    @Test
    public void testCanHandle() {
        
         ActionContext context = mockActionContextObject();
         Assert.assertTrue(context.getSelectedManifestations().size() == 1);
         Assert.assertNotNull(context);
        
         Mockito.when(manifestation.getManifestedComponent()).thenReturn(abstractComp);
         Assert.assertNotNull(abstractComp);
    }
View Full Code Here

  }

  @Test
  public void testCanHandle() {
    // Setup mocks
    ActionContext mockContext = Mockito.mock(ActionContext.class);
    View mockView = Mockito.mock(View.class);
    AbstractComponent mockComponent = Mockito.mock(AbstractComponent.class);
    Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);
   
    // This-style import needs a window manifestation
    Mockito.when(mockContext.getWindowManifestation()).thenReturn(null);
    Assert.assertFalse(importThisAction.canHandle(mockContext));
    Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockView);
    Assert.assertTrue(importThisAction.canHandle(mockContext));
   
    // Objects-style import needs exactly one selection
    Mockito.when(mockContext.getSelectedManifestations())
      .thenReturn(Arrays.<View>asList());
    Assert.assertFalse(importAction.canHandle(mockContext));
    Mockito.when(mockContext.getSelectedManifestations())
      .thenReturn(Arrays.<View>asList(mockView, mockView));
    Assert.assertFalse(importAction.canHandle(mockContext));
    Mockito.when(mockContext.getSelectedManifestations())
      .thenReturn(Arrays.<View>asList(mockView));
    Assert.assertTrue(importAction.canHandle(mockContext));   
  }
View Full Code Here

  }
 
  @Test
  public void testIsEnabled() {
    // Setup mocks (need to invoke canHandle for Action lifecycle)
    ActionContext mockContext = Mockito.mock(ActionContext.class);
    View mockView = Mockito.mock(View.class);
    AbstractComponent mockComponent = Mockito.mock(AbstractComponent.class);
    Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);

    // Call canHandle (for lifecycle)
    Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockView);
    Assert.assertTrue(importThisAction.canHandle(mockContext));
    Mockito.when(mockContext.getSelectedManifestations())
      .thenReturn(Arrays.<View>asList(mockView));
    Assert.assertTrue(importAction.canHandle(mockContext));   

    // Check isEnabled - should depend on policy
    for (boolean truth : new boolean[] {true, false}) {
View Full Code Here

TOP

Related Classes of gov.nasa.arc.mct.gui.ActionContext

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.