示例#1
0
 private void postEventInManualUpdateMode() {
   // Generate an event which will cause all cache entries to be marked dirty.
   fViewerListener.reset();
   fViewerListener.addUpdates(
       TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
   fVMListener.reset();
   fFormattedValuesListener.reset();
   fVMProvider.postEvent(new TestEvent(fModel.getRootElement(), IModelDelta.CONTENT));
   while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES))
     if (!fDisplay.readAndDispatch()) fDisplay.sleep();
   assertTrue(fFormattedValuesListener.getFormattedValuesCompleted().isEmpty());
 }
示例#2
0
 /**
  * helper to destory view model and viewer
  *
  * @param vmOnly true to destory view model only and do not destroy viewer
  */
 void destroyViewer(boolean vmOnly) {
   fVMProvider.getNode().setFormattedValuesListener(null);
   fVMProvider.getNode().getLabelProvider().removePropertiesUpdateListener(fViewerListener);
   fVMProvider.getNode().setVMUpdateListener(null);
   fVMListener.dispose();
   if (vmOnly == false) {
     fViewerListener.dispose();
     fViewer.getPresentationContext().dispose();
     // Close the shell
     fShell.close();
     while (!fShell.isDisposed()) if (!fDisplay.readAndDispatch()) fDisplay.sleep();
   }
 }
示例#3
0
 /** helper to set preference to an invalid format and verify. */
 void setInvalidPreferenceAndVerify() {
   fViewerListener.reset();
   fViewerListener.addUpdates(
       TreePath.EMPTY,
       ((TestElementVMContext) fViewer.getInput()).getElement(),
       -1,
       ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
   fVMListener.reset();
   fVMListener.addUpdates(
       TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
   fViewer
       .getPresentationContext()
       .setProperty(PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, "invalid format");
   while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES)
       || !fVMListener.isFinished(CONTENT_UPDATES | PROPERTY_UPDATES)) {
     if (!fDisplay.readAndDispatch()) {
       fDisplay.sleep();
     }
   }
   validateModel(
       IFormattedValues.HEX_FORMAT,
       " (" + FormattedValueVMUtil.getFormatLabel(IFormattedValues.HEX_FORMAT) + ")",
       DummyFormattedValueService.DUMMY_FORMAT,
       " (" + DummyFormattedValueService.DUMMY_FORMAT + ")");
 }
示例#4
0
 /** helper to set element to an invalid format */
 void setElementInvalidFormat() {
   fViewerListener.reset();
   fViewerListener.addUpdates(
       TreePath.EMPTY,
       ((TestElementVMContext) fViewer.getInput()).getElement(),
       -1,
       ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
   fVMListener.reset();
   fVMListener.addUpdates(
       TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
   HashMap<String, ElementFormatSetting> map = new HashMap<String, ElementFormatSetting>();
   String[] format = {"invalid element format"};
   makeElementFormatSetting(fViewer, TreePath.EMPTY, format, -1, 0, map);
   ArrayList<ElementFormatSetting> elementFormats =
       new ArrayList<ElementFormatSetting>(map.values());
   if (fVMProvider instanceof IElementFormatProvider) {
     IElementFormatProvider ep = ((IElementFormatProvider) fVMProvider);
     for (ElementFormatSetting es : elementFormats) {
       ep.setActiveFormat(
           fViewer.getPresentationContext(),
           es.nodes.toArray(new IVMNode[es.nodes.size()]),
           fViewer.getInput(),
           es.elementPaths.toArray(new TreePath[es.elementPaths.size()]),
           es.formatId);
     }
   }
   while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES)
       || !fVMListener.isFinished(CONTENT_UPDATES | PROPERTY_UPDATES)) {
     if (!fDisplay.readAndDispatch()) {
       fDisplay.sleep();
     }
   }
 }
示例#5
0
  /** @throws java.lang.Exception */
  @Override
  protected void tearDown() throws Exception {
    fVMProvider.getNode().setFormattedValuesListener(null);
    fModel.setTestModelListener(null);

    fVMProvider.getNode().getLabelProvider().removePropertiesUpdateListener(fViewerListener);
    fVMProvider.getNode().setVMUpdateListener(null);

    fVMAdapter.dispose();

    fVMListener.dispose();
    fViewerListener.dispose();

    shutdownService(fDummyValuesService);
    shutdownService(fModel);
    fViewer.getPresentationContext().dispose();
    // Close the shell and exit.
    fShell.close();
    while (!fShell.isDisposed()) if (!fDisplay.readAndDispatch()) fDisplay.sleep();
    DsfSession.endSession(fDsfSession);
    fDsfExecutor.shutdown();
  }
示例#6
0
  private void setUpdatePolicy(String policyId) {
    IVMUpdatePolicy[] policies = fVMProvider.getAvailableUpdatePolicies();
    IVMUpdatePolicy newPolicy = null;
    for (IVMUpdatePolicy policy : policies) {
      if (policyId.equals(policy.getID())) {
        newPolicy = policy;
        break;
      }
    }
    if (newPolicy != null) {
      fVMProvider.setActiveUpdatePolicy(newPolicy);
    } else {
      throw new RuntimeException("Update policy " + policyId + " not available");
    }
    fViewerListener.reset();
    fViewerListener.addUpdates(
        TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
    fVMListener.setFailOnRedundantUpdates(false);
    while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES))
      if (!fDisplay.readAndDispatch()) fDisplay.sleep();

    fVMListener.setFailOnRedundantUpdates(true);
  }
示例#7
0
 /**
  * Test that when the preference format is invalid, each element can still change to a format.
  * Also, each element can restore to the invalid preference format such that the element uses
  * first available format from service.
  */
 public void testChangeElementFormatWithInvalidPreference() {
   recreateViewModel();
   String preferenceFormat = IFormattedValues.NATURAL_FORMAT;
   setInput(preferenceFormat);
   // set preference format to an invalid format and verify
   setInvalidPreferenceAndVerify();
   // set each element to a format, and verify
   HashMap<String, ElementFormatSetting> map = new HashMap<String, ElementFormatSetting>();
   String[] format = {
     IFormattedValues.HEX_FORMAT,
     IFormattedValues.DECIMAL_FORMAT,
     IFormattedValues.OCTAL_FORMAT,
     IFormattedValues.BINARY_FORMAT,
     IFormattedValues.NATURAL_FORMAT
   };
   makeElementFormatSetting(fViewer, TreePath.EMPTY, format, -1, 0, map);
   ArrayList<ElementFormatSetting> elementFormats =
       new ArrayList<ElementFormatSetting>(map.values());
   setFormatAndValidate("invalid format", elementFormats, elementFormats, false, false, false);
   // Restore each element to preference format which is an invalid format
   for (ElementFormatSetting e : elementFormats) {
     e.formatId = null;
   }
   fViewerListener.reset();
   fViewerListener.addUpdates(
       TreePath.EMPTY,
       ((TestElementVMContext) fViewer.getInput()).getElement(),
       -1,
       ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
   fVMListener.reset();
   fVMListener.addUpdates(
       TreePath.EMPTY, fModel.getRootElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
   if (fVMProvider instanceof IElementFormatProvider) {
     IElementFormatProvider ep = ((IElementFormatProvider) fVMProvider);
     for (ElementFormatSetting es : elementFormats) {
       ep.setActiveFormat(
           fViewer.getPresentationContext(),
           es.nodes.toArray(new IVMNode[es.nodes.size()]),
           fViewer.getInput(),
           es.elementPaths.toArray(new TreePath[es.elementPaths.size()]),
           es.formatId);
     }
   }
   while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES)
       || !fVMListener.isFinished(CONTENT_UPDATES | PROPERTY_UPDATES)) {
     if (!fDisplay.readAndDispatch()) {
       fDisplay.sleep();
     }
   }
   // verify service's first available format is used
   validateModel(
       IFormattedValues.HEX_FORMAT,
       " (" + FormattedValueVMUtil.getFormatLabel(IFormattedValues.HEX_FORMAT) + ")",
       DummyFormattedValueService.DUMMY_FORMAT,
       " (" + DummyFormattedValueService.DUMMY_FORMAT + ")");
 }
示例#8
0
  /** Initial format is NATURAL. */
  private void setInput(String formatId) {
    // Set the new number format to the viewer.
    fViewer.getPresentationContext().setProperty(PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, formatId);

    fViewer.setAutoExpandLevel(-1);
    TestElementVMContext rootVMC =
        fVMProvider.getElementVMContext(fViewer.getPresentationContext(), fModel.getRootElement());

    // Create the listener
    fViewerListener.reset();
    fViewerListener.addUpdates(
        TreePath.EMPTY, rootVMC.getElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
    fVMListener.reset();
    fVMListener.addUpdates(
        TreePath.EMPTY, rootVMC.getElement(), -1, ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);
    fFormattedValuesListener.reset();

    fViewer.setInput(rootVMC);
    while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES)
        || !fVMListener.isFinished(CONTENT_COMPLETE | PROPERTY_UPDATES))
      if (!fDisplay.readAndDispatch()) fDisplay.sleep();

    assertTrue(fFormattedValuesListener.isFinished());
  }
示例#9
0
  private void setFormatAndValidate(
      String formatId,
      ArrayList<ElementFormatSetting> setElementFormats,
      ArrayList<ElementFormatSetting> expectElementFormats,
      boolean expectContentCached,
      boolean expectFormattedValuesCached,
      boolean expectCacheMissError) {
    fViewerListener.reset();
    fViewerListener.addUpdates(
        TreePath.EMPTY,
        ((TestElementVMContext) fViewer.getInput()).getElement(),
        -1,
        ALL_UPDATES_COMPLETE | PROPERTY_UPDATES);

    fVMListener.reset();
    int vmUpdateFlags = PROPERTY_UPDATES;
    if (!expectContentCached) {
      vmUpdateFlags |= ALL_UPDATES_COMPLETE;
    }
    fVMListener.addUpdates(TreePath.EMPTY, fModel.getRootElement(), vmListenerLevel, vmUpdateFlags);

    fFormattedValuesListener.reset();
    if (expectFormattedValuesCached && !expectCacheMissError) {
      fFormattedValuesListener.setCachedFormats(new String[] {formatId});
    }

    if (fVMProvider instanceof IElementFormatProvider && setElementFormats != null) {
      IElementFormatProvider ep = ((IElementFormatProvider) fVMProvider);
      for (ElementFormatSetting es : setElementFormats) {
        ep.setActiveFormat(
            fViewer.getPresentationContext(),
            es.nodes.toArray(new IVMNode[es.nodes.size()]),
            fViewer.getInput(),
            es.elementPaths.toArray(new TreePath[es.elementPaths.size()]),
            es.formatId);
      }
    } else {
      // Set the new number format to the viewer.
      fViewer
          .getPresentationContext()
          .setProperty(PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, formatId);
    }

    while (!fViewerListener.isFinished(ALL_UPDATES_COMPLETE | PROPERTY_UPDATES)
        || !fVMListener.isFinished(CONTENT_UPDATES | PROPERTY_UPDATES))
      if (!fDisplay.readAndDispatch()) fDisplay.sleep();

    if (expectCacheMissError) {
      try {
        validateModel(expectElementFormats, formatId, "", formatId, "");
        throw new RuntimeException("Expected validateModel to fail");
      } catch (AssertionFailedError e) {
        // expected
      }
    } else {
      validateModel(expectElementFormats, formatId, "", formatId, "");
    }

    if (expectCacheMissError) {
      String formatProperty = FormattedValueVMUtil.getPropertyForFormatId(formatId);

      assertTrue(fFormattedValuesListener.getFormattedValuesCompleted().isEmpty());
      assertFalse(fFormattedValuesListener.getPropertiesUpdates().isEmpty());
      for (IPropertiesUpdate update : fFormattedValuesListener.getPropertiesUpdates()) {
        PropertiesUpdateStatus status = (PropertiesUpdateStatus) update.getStatus();
        assertEquals(IDsfStatusConstants.INVALID_STATE, status.getCode());
        ElementFormatSetting elementFormat = null;
        if (expectElementFormats != null) {
          TreePath viewerPath = update.getElementPath();
          for (ElementFormatSetting es : expectElementFormats) {
            if (es.elementPaths.indexOf(viewerPath) >= 0) {
              elementFormat = es;
              break;
            }
          }
        }
        if (elementFormat != null) {
          assertEquals(
              "Cache contains stale data. Refresh view.",
              status
                  .getStatus(FormattedValueVMUtil.getPropertyForFormatId(elementFormat.formatId))
                  .getMessage());
        } else {
          assertEquals(
              "Cache contains stale data. Refresh view.",
              status.getStatus(formatProperty).getMessage());
        }
        assertEquals(
            "Cache contains stale data. Refresh view.",
            status.getStatus(PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE).getMessage());
        assertEquals(1, status.getChildren().length);
      }

    } else {
      assertTrue(fFormattedValuesListener.isFinished());
    }
  }