@Test
  public void testDataSourceRepo() throws SQLException, RepositoryException {
    DataSourceWorkflowRepository repo = new DataSourceWorkflowRepository(ds);

    // test id 1
    WorkflowCondition wc = repo.getWorkflowConditionById("1");
    assertEquals(wc.getConditionName(), "CheckCond");
    WorkflowConditionInstance condInst =
        GenericWorkflowObjectFactory.getConditionObjectFromClassName(
            wc.getConditionInstanceClassName());
    Metadata m = new Metadata();
    m.addMetadata("Met1", "Val1");
    m.addMetadata("Met2", "Val2");
    m.addMetadata("Met3", "Val3");
    assertTrue(condInst.evaluate(m, wc.getTaskConfig()));

    // test id 2
    wc = repo.getWorkflowConditionById("2");
    assertEquals(wc.getConditionName(), "FalseCond");
    condInst =
        GenericWorkflowObjectFactory.getConditionObjectFromClassName(
            wc.getConditionInstanceClassName());
    assertFalse(condInst.evaluate(m, wc.getTaskConfig()));

    // test id 3
    wc = repo.getWorkflowConditionById("3");
    assertEquals(wc.getConditionName(), "TrueCond");
    condInst =
        GenericWorkflowObjectFactory.getConditionObjectFromClassName(
            wc.getConditionInstanceClassName());
    assertTrue(condInst.evaluate(m, wc.getTaskConfig()));
  }
  @Test
  public void testGetConditionById() throws Exception {

    WorkflowCondition cond = fmc.getConditionById("urn:oodt:TrueCondition");

    assertNotNull(cond);

    assertThat(cond.getConditionName(), equalTo("True Condition"));
  }
  @BeforeClass
  public static void setup() throws MalformedURLException {

    testWrkInst = new WorkflowInstance();
    testWrkFlw = new Workflow();
    testTask = new WorkflowTask();
    testCond = new WorkflowCondition();
    Metadata sharedContext = new Metadata();

    // to check if the path already exists and to delete if it does exist
    if (new File(catalogPath).exists()) {
      try {
        FileUtils.deleteDirectory(new File(catalogPath));
      } catch (IOException e) {
        fail(e.getMessage());
      }
    }
    repo = new LuceneWorkflowInstanceRepository(catalogPath, stdPgSz);

    testWrkFlw.setName("test.getMetadataWorkflow");
    testWrkFlw.setId("test.id");
    List tasks = new Vector();
    List conds = new Vector();

    testCond.setConditionId("test.cond.id");
    testCond.setConditionInstanceClassName("test.class");
    testCond.setConditionName("test.cond.name");
    testCond.setOrder(1);
    conds.add(testCond);

    testTask.setTaskConfig(new WorkflowTaskConfiguration());
    testTask.setTaskId("test.task.id");
    testTask.setConditions(conds);
    testTask.setOrder(1);
    testTask.setTaskInstanceClassName("test.class");
    testTask.setTaskName("test.task.name");
    tasks.add(testTask);
    testWrkFlw.setTasks(tasks);

    testWrkInst.setCurrentTaskId("test.task");
    testWrkInst.setStatus("STARTED");
    testWrkInst.setWorkflow(testWrkFlw);

    sharedContext.addMetadata("key1", "val1");
    sharedContext.addMetadata("key1", "val2");
    sharedContext.addMetadata("key1", "val3");
    sharedContext.addMetadata("key2", "val4");
    sharedContext.addMetadata("key2", "val5");
    testWrkInst.setSharedContext(sharedContext);
    startXmlRpcWorkflowManager();
    startWorkflow();
    fmc = new XmlRpcWorkflowManagerClient(new URL("http://localhost:" + WM_PORT));
  }
  /*
   * (non-Javadoc)
   *
   * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflowConditionById(java.lang.String)
   */
  public WorkflowCondition getWorkflowConditionById(String conditionId) throws RepositoryException {
    Connection conn = null;
    Statement statement = null;
    ResultSet rs = null;

    WorkflowCondition condition = null;

    try {
      conn = dataSource.getConnection();
      statement = conn.createStatement();

      String getConditionsSql =
          "SELECT * FROM workflow_conditions WHERE workflow_condition_id = " + conditionId;

      LOG.log(Level.FINE, "getWorkflowConditionById: Executing: " + getConditionsSql);
      rs = statement.executeQuery(getConditionsSql);

      while (rs.next()) {
        // get an instance of the class name
        condition = DbStructFactory.getWorkflowCondition(rs, false);
        condition.setCondConfig(getConfigurationByConditionId(conditionId));
      }

    } catch (Exception e) {
      e.printStackTrace();
      LOG.log(Level.WARNING, "Exception getting condition by id. Message: " + e.getMessage());
      try {
        conn.rollback();
      } catch (SQLException e2) {
        LOG.log(
            Level.SEVERE,
            "Unable to rollback getWorkflowConditionById transaction. Message: " + e2.getMessage());
      }
      throw new RepositoryException(e.getMessage());
    } finally {

      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException ignore) {
        }

        rs = null;
      }

      if (statement != null) {
        try {
          statement.close();
        } catch (SQLException ignore) {
        }

        statement = null;
      }

      if (conn != null) {
        try {
          conn.close();

        } catch (SQLException ignore) {
        }

        conn = null;
      }
    }

    return condition;
  }