Package gov.nasa.arc.mct.policy

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


   *       is or is not a leaf.
   */
  @SuppressWarnings("rawtypes")
  @Test
  public void testExecute() {
    ExecutionResult result = null;
    AbstractComponent mockComp = Mockito.mock(AbstractComponent.class);
    ViewInfo mockViewInfo = Mockito.mock(ViewInfo.class);
   
    /*
     * From (the below two lines), calling getProperty with the key 'PolicyContext.PropertyName.TARGET_COMPONENT.getName()'
     * returns our mocked component. Similarly calling getProperty with the key
     * 'PolicyContext.PropertyName.TARGET_VIEW_INFO.getName()' returns our mocked viewInfo.
     */
    context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), mockComp);
    context.setProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), mockViewInfo);

    //Now we test:

    /*Two tests (for leaf and non-leaf components) when the ViewInfo is from the MultiColView class*/
    Mockito.when((Class)mockViewInfo.getViewClass()).thenReturn(MultiColView.class);
      //(1) Test for leaf-components:
        Mockito.when(mockComp.isLeaf()).thenReturn(true)//mocked component is a leaf
      result = policy.execute(context)//context is: the component is a leaf, and the viewInfo is from MultiColView
      Assert.assertEquals(result.getStatus(), false);    //components which are leaves may not be viewed wrt MultiColView
      //---end test on leaf-components
     
      //(2) Test for non-leaf components:
        Mockito.when(mockComp.isLeaf()).thenReturn(false)//mocked component is not a leaf
      result = policy.execute(context);          //context is: the component is a leaf, and the viewInfo is from MultiColView
      Assert.assertEquals(result.getStatus(), true);    //components which are leaves are viewable wrt MultiColView
      //---end test on non-leaf components
     
    /*Two tests (for leaf and non-leaf components) when the ViewInfo is not from the MultiColView class*/
    Mockito.when((Class)mockViewInfo.getViewClass()).thenReturn(OnStiltsView.class);
      //(1) Test for leaf-components:
        Mockito.when(mockComp.isLeaf()).thenReturn(true)//mocked component is a leaf
      result = policy.execute(context)//context is: the component is a leaf, and the viewInfo is not from MultiColView
      Assert.assertEquals(result.getStatus(), true);    //policy should return true for views that are not MultiCol views
      //---end test on leaf-components
     
      //(2) Test for non-leaf components:
        Mockito.when(mockComp.isLeaf()).thenReturn(false)//mocked component is not a leaf
      result = policy.execute(context);          //context is: the component is a leaf, and the viewInfo is not from MultiColView
      Assert.assertEquals(result.getStatus(), true);    //policy should return true for views that are not MultiCol views
      //---end test on non-leaf components
  }
View Full Code Here


    /* View's isLocked() method is final - it can't be mocked & needs to reference the platform */
    /* So, provide a mock platform */
    Mockito.when(mockPlatform.getPolicyManager())
      .thenReturn(mockPolicyManager);
    Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext> any()))
      .thenReturn(new ExecutionResult(null, false, null));
   
    Mockito.when(mockLegendEntry.getComputedBaseDisplayName()).thenReturn("test");
    Mockito.when(mockLegendEntry.getFullBaseDisplayName()).thenReturn("test");
    Mockito.when(mockLegendEntry.getLineSettings()).thenReturn(new LineSettings());
    Mockito.when(mockLegendEntry.getNumberRegressionPoints()).thenReturn(15);
View Full Code Here

    Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistenceProvider);
        Mockito.when(mockPersistenceProvider.getReferencedComponents(Mockito.any(AbstractComponent.class))).thenReturn(Collections.<AbstractComponent>emptyList());

    Mockito.when(mockComponentRegistry.getViewInfos(Mockito.anyString(), Mockito.any(ViewType.class)))
      .thenReturn(Collections.singleton(new ViewInfo(TableViewManifestation.class,"","",ViewType.EMBEDDED)));
    Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.any(PolicyContext.class))).thenReturn(new ExecutionResult(null, true, ""));
    (new PlatformAccess()).setPlatform(mockPlatform);
   
    new ServiceAccess().bind(policyManager);
    success = new ExecutionResult(new PolicyContext(), true, "success");
    failure = new ExecutionResult(new PolicyContext(), false, "failure");

    when(leaf.isLeaf()).thenReturn(true);
    when(leafWithFeed.isLeaf()).thenReturn(true);
    when(leafWithFeed.getCapability(FeedProvider.class)).thenReturn(mockFeedProvider);
  }
View Full Code Here

 
  /* Tests for LegendEntryPopupMenuManager behavior */
  @Test
  public void testLegendEntryPopupMenuSize() {
    Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext> any()))
      .thenReturn(new ExecutionResult(null, false, null))
   
    LegendEntryPopupMenuFactory manager = new LegendEntryPopupMenuFactory(mockPlotViewManifestation);
    JPopupMenu menu = getSubMenu(manager.getPopup(mockLegendEntry), COLOR_SUBMENU);
   
    Assert.assertEquals(menu.getComponentCount(), PlotConstants.MAX_NUMBER_OF_DATA_ITEMS_ON_A_PLOT);   
View Full Code Here

  }
 
  @Test
  public void testLegendEntryRegressionMenu() {
    Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext> any()))
      .thenReturn(new ExecutionResult(null, false, null))
   
    LegendEntryPopupMenuFactory manager = new LegendEntryPopupMenuFactory(mockPlotViewManifestation);
    JMenuItem regressionLineCheckbox = ((JMenuItem) manager.getPopup(mockLegendEntry).getComponent(PREDICTION_CHECKBOX));
    Assert.assertEquals(regressionLineCheckbox.getText(), BUNDLE.getString("RegressionLineLabel"));
    Assert.assertFalse(regressionLineCheckbox.isSelected());
View Full Code Here

  }

  @Test
  public void testLegendEntryPopupMenuColors() {
    Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext> any()))
    .thenReturn(new ExecutionResult(null, false, null))
 
    LegendEntryPopupMenuFactory manager = new LegendEntryPopupMenuFactory(mockPlotViewManifestation);
    JPopupMenu menu = getSubMenu(manager.getPopup(mockLegendEntry), COLOR_SUBMENU);
   
    /* Draw icons to this to test for color correctness */
 
View Full Code Here

  }
 
  @Test
  public void testLegendEntryPopupMenuSelection() {
    Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext> any()))
    .thenReturn(new ExecutionResult(null, false, null))
 
    LegendEntryPopupMenuFactory manager = new LegendEntryPopupMenuFactory(mockPlotViewManifestation);
    for (int i = 0; i < PlotConstants.MAX_NUMBER_OF_DATA_ITEMS_ON_A_PLOT; i++) {
      Mockito.when(mockLegendEntry.getForeground()).thenReturn(PlotLineColorPalette.getColor(i));
 
View Full Code Here

  }

  @Test
  public void testLegendEntryPopupMenuThicknesses() {
    Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext> any()))
    .thenReturn(new ExecutionResult(null, false, null))
 
    LegendEntryPopupMenuFactory manager = new LegendEntryPopupMenuFactory(mockPlotViewManifestation);
    JPopupMenu menu = getSubMenu(manager.getPopup(mockLegendEntry), THICKNESS_SUBMENU );
   
    Assert.assertEquals(menu.getComponentCount(), PlotConstants.MAX_LINE_THICKNESS);
View Full Code Here

  }

  @Test
  public void testLegendEntryPopupMenuThicknessSelection() {
    Mockito.when(mockPolicyManager.execute(Mockito.anyString(), Mockito.<PolicyContext> any()))
    .thenReturn(new ExecutionResult(null, false, null))
 
    LegendEntryPopupMenuFactory manager = new LegendEntryPopupMenuFactory(mockPlotViewManifestation);
    for (int i = 0; i < PlotConstants.MAX_LINE_THICKNESS; i++) {
      LineSettings settings = new LineSettings();
      settings.setThickness(i + 1);
View Full Code Here

    ViewInfo viewInfo = context.getProperty(PolicyContext.PropertyName.TARGET_VIEW_INFO.getName(), ViewInfo.class);
    if (viewInfo.getViewClass().equals(TableViewManifestation.class)) {
      AbstractComponent targetComponent = context.getProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), AbstractComponent.class);
      result = !targetComponent.isLeaf() || hasFeed(targetComponent) || (targetComponent instanceof Placeholder);
    }
    return new ExecutionResult(context, result, "Requested Table View did not have children with data feeds.");
  }
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.