/**
   * @param dynamicModels
   * @param modelName
   * @return model with given name
   */
  private DynamicModel findModel(Collection<DynamicModel> models, String modelName) {
    assertNotNull(models);
    for (DynamicModel model : models) {
      if (model.getName().equals(modelName)) return model;
    }

    Assert.fail("No dynamic model named " + modelName);
    return null;
  }
  @Test
  public void convertDynamicVdbToXmiVdb() throws Exception {
    DynamicVdb dynVdb = VdbTestUtils.mockPortfolioDynamicVdb(modelWorkspaceMock);
    assertNotNull(dynVdb);

    IFile dynVdbSrcFile = dynVdb.getSourceFile();
    IProject parent = dynVdbSrcFile.getProject();
    assertNotNull(parent);

    File destFile = File.createTempFile(dynVdb.getName(), ITeiidVdb.VDB_DOT_EXTENSION);
    MockFileBuilder destination = new MockFileBuilder(destFile);

    XmiVdb xmiVdb = dynVdb.convert(XmiVdb.class, destination.getResourceFile(), new Properties());

    assertEquals(dynVdb.getName(), xmiVdb.getName());
    assertEquals(dynVdb.getDescription(), xmiVdb.getDescription());

    for (Map.Entry<Object, Object> entry : dynVdb.getProperties().entrySet()) {
      System.out.println(
          "VDB Property:  "
              + entry.getValue()
              + " == "
              + xmiVdb.getProperties().getProperty(entry.getKey().toString()));
      assertEquals(entry.getValue(), xmiVdb.getProperties().getProperty(entry.getKey().toString()));
    }

    assertEquals(destination.getResourceFile(), xmiVdb.getSourceFile());
    assertEquals(dynVdb.getVersion(), xmiVdb.getVersion());

    assertEquals(dynVdb.getConnectionType(), xmiVdb.getConnectionType());
    assertEquals(dynVdb.isPreview(), xmiVdb.isPreview());
    assertEquals(dynVdb.getQueryTimeout(), xmiVdb.getQueryTimeout());

    assertEquals(dynVdb.getAllowedLanguages().size(), xmiVdb.getAllowedLanguages().size());
    List<String> dynLanguageValues =
        Arrays.asList(xmiVdb.getAllowedLanguages().getAllowedLanguageValues());
    for (String language : dynVdb.getAllowedLanguages().getAllowedLanguageValues()) {
      assertTrue(dynLanguageValues.contains(language));
    }

    assertEquals(dynVdb.getSecurityDomain(), xmiVdb.getSecurityDomain());
    assertEquals(dynVdb.getGssPattern(), xmiVdb.getGssPattern());
    assertEquals(dynVdb.getPasswordPattern(), xmiVdb.getPasswordPattern());
    assertEquals(dynVdb.getAuthenticationType(), xmiVdb.getAuthenticationType());
    assertEquals(dynVdb.getValidationDateTime(), xmiVdb.getValidationDateTime());
    assertEquals(dynVdb.isAutoGenerateRESTWar(), xmiVdb.isAutoGenerateRESTWar());

    assertEquals(dynVdb.getImports().size(), xmiVdb.getImports().size());
    for (VdbImportVdbEntry entry : dynVdb.getImports()) {
      assertTrue(xmiVdb.getImports().contains(entry));
    }

    assertEquals(dynVdb.getTranslators().size(), xmiVdb.getTranslators().size());
    for (TranslatorOverride translator : dynVdb.getTranslators()) {
      assertTrue(xmiVdb.getTranslators().contains(translator));
    }

    assertEquals(dynVdb.getDataRoles().size(), xmiVdb.getDataRoles().size());
    for (DataRole role : dynVdb.getDataRoles()) {
      assertTrue(xmiVdb.getDataRoles().contains(role));
    }

    assertEquals(dynVdb.getDynamicModels().size(), xmiVdb.getModelEntries().size());
    for (DynamicModel dynModel : dynVdb.getDynamicModels()) {

      VdbModelEntry modelEntry = null;
      Collection<VdbModelEntry> entries = xmiVdb.getModelEntries();
      for (VdbModelEntry entry : entries) {
        if (dynModel.getName().equals(entry.getName())) {
          modelEntry = entry;
          break;
        }
      }
      assertNotNull(modelEntry);

      assertEquals(dynModel.getDescription(), modelEntry.getDescription());

      for (Map.Entry<Object, Object> prop : dynModel.getProperties().entrySet()) {
        assertEquals(
            prop.getValue(), modelEntry.getProperties().getProperty(prop.getKey().toString()));
      }

      VdbSourceInfo sourceInfo = modelEntry.getSourceInfo();

      assertEquals(dynModel.getModelType().toString(), modelEntry.getType());
      assertEquals(dynModel.isMultiSource(), sourceInfo.isMultiSource());
      assertEquals(dynModel.doAddColumn(), sourceInfo.isAddColumn());
      assertEquals(dynModel.getColumnAlias(), sourceInfo.getColumnAlias());

      assertEquals(dynModel.getSources().length, sourceInfo.getSources().size());
      List<VdbSource> entrySources = new ArrayList<VdbSource>(sourceInfo.getSources());
      for (VdbSource source : dynModel.getSources()) {
        assertTrue(entrySources.contains(source));
      }
    }
  }