@Test
  public void testVDBRestart() throws Exception {
    String vdbName = "test";
    String testVDB =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"test\" version=\"1\">\n"
            + "    <property name=\"UseConnectorMetadata\" value=\"cached\" />\n"
            + "    <model name=\"loopy\">\n"
            + "        <source name=\"loop\" translator-name=\"loopy\" />\n"
            + "    </model>\n"
            + "</vdb>";

    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    JavaArchive jar = getLoopyArchive();
    admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());

    // normal load
    admin.deploy("test-vdb.xml", new ByteArrayInputStream(testVDB.getBytes()));
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
    int count = assertMetadataLoadCount(false, 1);

    // 1st restart
    admin.restartVDB(vdbName, 1);
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
    count = assertMetadataLoadCount(true, count + 1);

    // 2nd restart
    admin.restartVDB(vdbName, 1);
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);
    count = assertMetadataLoadCount(true, count + 1);

    admin.undeploy("loopy.jar");
  }
  @Test
  public void testSystemPropertiesInVDBXML() throws Exception {
    String vdbName = "test";
    String testVDB =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"test\" version=\"1\">\n"
            + "    <property name=\"UseConnectorMetadata\" value=\"${teiid.vdb.UseConnectorMetadata:none}\" />\n"
            + "    <model name=\"loopy\">\n"
            + "        <source name=\"loop\" translator-name=\"loopy\" />\n"
            + "    </model>\n"
            + "</vdb>";

    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    JavaArchive jar = getLoopyArchive();
    admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());

    // normal load
    admin.deploy("test-vdb.xml", new ByteArrayInputStream(testVDB.getBytes()));
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);

    VDB vdb = admin.getVDB(vdbName, 1);
    String value = vdb.getPropertyValue("UseConnectorMetadata");

    // see the arquillian.zml file in resources in the JVM proeprties section for the expected value
    assertEquals("custom", value);

    admin.undeploy("loopy.jar");
    admin.undeploy("test-vdb.xml");
  }
  @Test
  public void testDDLExport() throws Exception {
    String vdbName = "test";
    String testVDB =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"test\" version=\"1\">\n"
            + "    <property name=\"UseConnectorMetadata\" value=\"cached\" />\n"
            + "    <model name=\"loopy\">\n"
            + "        <source name=\"loop\" translator-name=\"loopy\" />\n"
            + "    </model>\n"
            + "</vdb>";

    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    JavaArchive jar = getLoopyArchive();
    admin.deploy("loopy.jar", jar.as(ZipExporter.class).exportAsInputStream());

    // normal load
    admin.deploy("test-vdb.xml", new ByteArrayInputStream(testVDB.getBytes()));
    AdminUtil.waitForVDBLoad(admin, vdbName, 1, 3);

    String ddl = admin.getSchema(vdbName, 1, "loopy", null, null);

    String expected = "CREATE FOREIGN TABLE Matadata (\n" + "	execCount integer\n" + ");";
    assertEquals(expected, ddl);

    admin.undeploy("loopy.jar");
  }
  @Test
  public void testErrorDeployment() throws Exception {
    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    admin.deploy(
        "error-vdb.xml", new FileInputStream(UnitTestUtil.getTestDataFile("error-vdb.xml")));

    AdminUtil.waitForVDBLoad(admin, "error", 1, 3);
    VDB vdb = admin.getVDB("error", 1);
    assertEquals(Status.FAILED, vdb.getStatus());
  }
  private boolean deployVdb() throws AdminException, FileNotFoundException {
    boolean vdbOneDeployed;
    admin.deploy("bqt.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt.vdb")));
    AdminUtil.waitForVDBLoad(admin, "bqt", 1, 3);
    vdbOneDeployed = true;

    VDB vdb = admin.getVDB("bqt", 1);
    Model model = vdb.getModels().get(0);
    admin.assignToModel(
        "bqt", 1, model.getName(), "Source", "h2", "java:jboss/datasources/ExampleDS");
    return vdbOneDeployed;
  }
  @Test
  public void testChainedDelegates() throws Exception {
    Properties props = new Properties();
    props.setProperty("connection-url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    props.setProperty("user-name", "sa");
    props.setProperty("password", "sa");

    AdminUtil.createDataSource(admin, "Oracle11_PushDS", "h2", props);
    admin.deploy("fake.jar", new FileInputStream(UnitTestUtil.getTestDataFile("fake.jar")));
    try {
      admin.deploy(
          "chained-vdb.xml", new FileInputStream(UnitTestUtil.getTestDataFile("chained-vdb.xml")));
    } finally {
      admin.undeploy("fake.jar");
    }
  }
  @Test
  public void testVDBDeployment() throws Exception {
    Collection<?> vdbs = admin.getVDBs();
    assertTrue(vdbs.isEmpty());

    Collection<String> dsNames = admin.getDataSourceNames();
    if (dsNames.contains("Oracle11_PushDS")) {
      admin.deleteDataSource("Oracle11_PushDS");
    }

    admin.deploy("bqt.vdb", new FileInputStream(UnitTestUtil.getTestDataFile("bqt.vdb")));

    vdbs = admin.getVDBs();
    assertFalse(vdbs.isEmpty());

    VDB vdb = admin.getVDB("bqt", 1);
    assertFalse(vdb.isValid());
    assertTrue(AdminUtil.waitForVDBLoad(admin, "bqt", 1, 3));
    assertFalse(vdb.isValid());

    Properties props = new Properties();
    props.setProperty("connection-url", "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    props.setProperty("user-name", "sa");
    props.setProperty("password", "sa");
    props.setProperty("connection-properties", "foo=bar,blah=blah");

    admin.createDataSource("Oracle11_PushDS", "h2", props);

    vdb = admin.getVDB("bqt", 1);
    assertTrue(vdb.isValid());
    assertTrue(vdb.getStatus().equals(Status.ACTIVE));

    dsNames = admin.getDataSourceNames();
    assertTrue(dsNames.contains("Oracle11_PushDS"));

    admin.deleteDataSource("Oracle11_PushDS");
    vdb = admin.getVDB("bqt", 1);
    assertFalse(vdb.isValid());
  }
 @After
 public void teardown() throws AdminException {
   AdminUtil.cleanUp(admin);
   admin.close();
 }