@Test
  public void testValid4Context() throws Exception {
    // for context
    ImportRepTypeHandler basicHandler = new ImportRepTypeHandler();

    Map<String, String> data = new HashMap<String, String>();
    data.put("type", ERepositoryObjectType.CONTEXT.getType());
    basicHandler.setInitializationData(null, null, data);

    ResourcesManager resManager = mock(ResourcesManager.class);
    Set<IPath> pathes = new HashSet<IPath>(initPathes);
    when(resManager.getPaths()).thenReturn(pathes);

    Assert.assertFalse(basicHandler.valid(resManager, processPropPath1));
    Assert.assertFalse(basicHandler.valid(resManager, processItemPath1));
    Assert.assertFalse(basicHandler.valid(resManager, processItemPath2));
    Assert.assertFalse(basicHandler.valid(resManager, processItemPath3));
    Assert.assertFalse(basicHandler.valid(resManager, connPropPath));
    Assert.assertFalse(basicHandler.valid(resManager, connItemPath));

    IPath contextPropPath = new Path("TEST/context/test_0.1.properties");
    IPath contextItemPath = new Path("TEST/context/test_0.1.item");
    pathes.add(contextPropPath);
    pathes.add(contextItemPath);
    Assert.assertTrue(basicHandler.valid(resManager, contextPropPath));
    Assert.assertFalse(basicHandler.valid(resManager, contextItemPath));
  }
  @Test
  public void testValid4Unknown() throws Exception {
    ImportRepTypeHandler basicHandler = new ImportRepTypeHandler();

    Map<String, String> data = new HashMap<String, String>();
    data.put("type", "XXX");
    basicHandler.setInitializationData(null, null, data);

    ResourcesManager resManager = mock(ResourcesManager.class);
    Set<IPath> pathes = new HashSet<IPath>(initPathes);
    when(resManager.getPaths()).thenReturn(pathes);

    Assert.assertFalse(basicHandler.valid(resManager, processPropPath1));
    Assert.assertFalse(basicHandler.valid(resManager, processItemPath1));
    Assert.assertFalse(basicHandler.valid(resManager, processItemPath2));
    Assert.assertFalse(basicHandler.valid(resManager, processItemPath3));
    Assert.assertFalse(basicHandler.valid(resManager, connPropPath));
    Assert.assertFalse(basicHandler.valid(resManager, connItemPath));
  }
  @Test
  public void testValid4Connection() throws Exception {
    // DB connections
    ImportRepTypeHandler basicHandler = new ImportRepTypeHandler();

    Map<String, String> data = new HashMap<String, String>();
    data.put(
        "type",
        ERepositoryObjectType.PROCESS.getType()
            + ","
            + ERepositoryObjectType.METADATA_CONNECTIONS.getType());
    basicHandler.setInitializationData(null, null, data);

    ResourcesManager resManager = mock(ResourcesManager.class);
    Set<IPath> pathes = new HashSet<IPath>(initPathes);
    when(resManager.getPaths()).thenReturn(pathes);

    Assert.assertTrue(basicHandler.valid(resManager, processPropPath1));
    Assert.assertFalse(basicHandler.valid(resManager, processItemPath1));
    Assert.assertTrue(basicHandler.valid(resManager, processItemPath2));
    Assert.assertFalse(basicHandler.valid(resManager, processItemPath3));
    Assert.assertTrue(basicHandler.valid(resManager, connPropPath));
    Assert.assertFalse(basicHandler.valid(resManager, connItemPath));
  }
Exemple #4
0
  public List<ImportItem> populateImportingItems(
      ResourcesManager resManager,
      boolean overwrite,
      IProgressMonitor progressMonitor,
      boolean enableProductChecking)
      throws Exception {
    IProgressMonitor monitor = progressMonitor;
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    TimeMeasure.display = CommonsPlugin.isDebugMode();
    TimeMeasure.displaySteps = CommonsPlugin.isDebugMode();
    TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
    TimeMeasure.begin("populateItems"); // $NON-NLS-1$

    try {
      // pre populate
      prePopulate(monitor, resManager);

      ImportCacheHelper.getInstance().beforePopulateItems();

      if (resManager == null) {
        return Collections.emptyList();
      }

      Set<IPath> resPaths = resManager.getPaths();

      monitor.beginTask(
          Messages.getString("ImportExportHandlersManager_populatingItemsMessage"),
          resPaths.size()); // $NON-NLS-1$

      List<ImportItem> items = new ArrayList<ImportItem>();

      ImportHandlerHelper importHandlerHelper = new ImportHandlerHelper();
      for (IPath path : resPaths) {
        if (monitor.isCanceled()) {
          return Collections.emptyList(); //
        }
        ImportItem importItem =
            importHandlerHelper.computeImportItem(monitor, resManager, path, overwrite);
        if (importItem != null) {
          IImportItemsHandler importHandler =
              findValidImportHandler(importItem, enableProductChecking);
          if (importHandler != null) {
            if (importHandler instanceof ImportBasicHandler) {
              // save as the createImportItem of ImportBasicHandler
              ImportBasicHandler importBasicHandler = (ImportBasicHandler) importHandler;
              if (importBasicHandler.checkItem(resManager, importItem, overwrite)) {
                importBasicHandler.checkAndSetProject(resManager, importItem);
              }
            }
          } else {
            // if don't find valid handler, will try to check by noraml path of items, so set null
            // here.
            importItem = null;
          }
        }

        // if can't load rightly via *.properties, try to check another way for normal files.
        if (importItem == null) {
          IImportItemsHandler importHandler =
              findValidImportHandler(resManager, path, enableProductChecking);
          if (importHandler != null) {
            importItem =
                importHandler.createImportItem(progressMonitor, resManager, path, overwrite, items);
          }
        }

        if (importItem != null) {
          items.add(importItem);
        }
        monitor.worked(1);
      }

      // post populate
      postPopulate(monitor, resManager, items.toArray(new ImportItem[0]));

      return items;
    } finally {

      ImportCacheHelper.getInstance().afterPopulateItems();
      //
      TimeMeasure.end("populateItems"); // $NON-NLS-1$
      TimeMeasure.display = false;
      TimeMeasure.displaySteps = false;
      TimeMeasure.measureActive = false;
    }
  }