You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ab...@apache.org on 2014/10/10 04:51:31 UTC

[02/52] [abbrv] SQOOP-1374: From/To: Metadata upgrade

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
index f603cc1..29da340 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
@@ -18,6 +18,7 @@
 package org.apache.sqoop.repository.derby;
 
 import junit.framework.TestCase;
+import org.apache.sqoop.common.Direction;
 import org.apache.sqoop.framework.FrameworkManager;
 import org.apache.sqoop.model.MConnection;
 import org.apache.sqoop.model.MConnectionForms;
@@ -47,443 +48,648 @@ import static org.apache.sqoop.repository.derby.DerbySchemaQuery.*;
  */
 abstract public class DerbyTestCase extends TestCase {
 
-//  public static final String DERBY_DRIVER =
-//    "org.apache.derby.jdbc.EmbeddedDriver";
-//
-//  public static final String JDBC_URL =
-//    "jdbc:derby:memory:myDB";
-//
-//  private Connection connection;
-//
-//  @Override
-//  public void setUp() throws Exception {
-//    super.setUp();
-//
-//    // Create connection to the database
-//    Class.forName(DERBY_DRIVER).newInstance();
-//    connection = DriverManager.getConnection(getStartJdbcUrl());
-//  }
-//
-//  @Override
-//  public void tearDown() throws Exception {
-//    // Close active connection
-//    if(connection != null) {
-//      connection.close();
-//    }
-//
-//    try {
-//      // Drop in memory database
-//      DriverManager.getConnection(getStopJdbcUrl());
-//    } catch (SQLException ex) {
-//      // Dropping Derby database leads always to exception
-//    }
-//
-//    // Call parent tear down
-//    super.tearDown();
-//  }
-//
-//  /**
-//   * Create derby schema.
-//   *
-//   * @throws Exception
-//   */
-//  protected void createSchema() throws Exception {
-//    runQuery(QUERY_CREATE_SCHEMA_SQOOP);
-//    runQuery(QUERY_CREATE_TABLE_SQ_CONNECTOR);
-//    runQuery(QUERY_CREATE_TABLE_SQ_FORM);
-//    runQuery(QUERY_CREATE_TABLE_SQ_INPUT);
-//    runQuery(QUERY_CREATE_TABLE_SQ_CONNECTION);
-//    runQuery(QUERY_CREATE_TABLE_SQ_JOB);
-//    runQuery(QUERY_CREATE_TABLE_SQ_CONNECTION_INPUT);
-//    runQuery(QUERY_CREATE_TABLE_SQ_JOB_INPUT);
-//    runQuery(QUERY_CREATE_TABLE_SQ_SUBMISSION);
-//    runQuery(QUERY_CREATE_TABLE_SQ_COUNTER_GROUP);
-//    runQuery(QUERY_CREATE_TABLE_SQ_COUNTER);
-//    runQuery(QUERY_CREATE_TABLE_SQ_COUNTER_SUBMISSION);
-//    runQuery(QUERY_CREATE_TABLE_SQ_SYSTEM);
-//    runQuery(QUERY_UPGRADE_TABLE_SQ_CONNECTION_ADD_COLUMN_ENABLED);
-//    runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_ENABLED);
-//    runQuery(QUERY_UPGRADE_TABLE_SQ_CONNECTION_ADD_COLUMN_CREATION_USER);
-//    runQuery(QUERY_UPGRADE_TABLE_SQ_CONNECTION_ADD_COLUMN_UPDATE_USER);
-//    runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_CREATION_USER);
-//    runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_UPDATE_USER);
-//    runQuery(QUERY_UPGRADE_TABLE_SQ_SUBMISSION_ADD_COLUMN_CREATION_USER);
-//    runQuery(QUERY_UPGRADE_TABLE_SQ_SUBMISSION_ADD_COLUMN_UPDATE_USER);
-//    runQuery("INSERT INTO SQOOP.SQ_SYSTEM(SQM_KEY, SQM_VALUE) VALUES('version', '3')");
-//    runQuery("INSERT INTO SQOOP.SQ_SYSTEM(SQM_KEY, SQM_VALUE) " +
-//      "VALUES('framework.version', '1')");
-//  }
-//
-//  /**
-//   * Run arbitrary query on derby memory repository.
-//   *
-//   * @param query Query to execute
-//   * @throws Exception
-//   */
-//  protected void runQuery(String query) throws Exception {
-//    Statement stmt = null;
-//    try {
-//      stmt = getDerbyConnection().createStatement();
-//
-//      stmt.execute(query);
-//    } finally {
-//      if (stmt != null) {
-//        stmt.close();
-//      }
-//    }
-//  }
-//
-//  protected Connection getDerbyConnection() {
-//    return connection;
-//  }
-//
-//  protected String getJdbcUrl() {
-//    return JDBC_URL;
-//  }
-//
-//  protected String getStartJdbcUrl() {
-//    return JDBC_URL + ";create=true";
-//  }
-//
-//  protected String getStopJdbcUrl() {
-//    return JDBC_URL + ";drop=true";
-//  }
-//
-//  /**
-//   * Load testing connector and framework metadata into repository.
-//   *
-//   * @throws Exception
-//   */
-//  protected void loadConnectorAndFramework() throws Exception {
-//    // Connector entry
-//    runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS, SQC_VERSION)"
-//      + "VALUES('A', 'org.apache.sqoop.test.A', '1.0-test')");
-//
-//    for(String connector : new String[] {"1", "NULL"}) {
-//      // Form entries
-//      for(String operation : new String[] {"null", "'IMPORT'", "'EXPORT'"}) {
-//
-//        String type;
-//        if(operation.equals("null")) {
-//          type = "CONNECTION";
-//        } else {
-//          type = "JOB";
-//        }
-//
-//        runQuery("INSERT INTO SQOOP.SQ_FORM"
-//          + "(SQF_CONNECTOR, SQF_OPERATION, SQF_NAME, SQF_TYPE, SQF_INDEX) "
-//          + "VALUES("
-//          + connector  + ", "
-//          + operation
-//          + ", 'F1', '"
-//          + type
-//          + "', 0)");
-//        runQuery("INSERT INTO SQOOP.SQ_FORM"
-//          + "(SQF_CONNECTOR, SQF_OPERATION, SQF_NAME, SQF_TYPE, SQF_INDEX) "
-//          + "VALUES("
-//          + connector + ", "
-//          + operation
-//          +  ", 'F2', '"
-//          + type
-//          + "', 1)");
-//      }
-//    }
-//
-//    // Input entries
-//    for(int x = 0; x < 2; x++ ) {
-//      for(int i = 0; i < 3; i++) {
-//        // First form
-//        runQuery("INSERT INTO SQOOP.SQ_INPUT"
-//        +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
-//        + " VALUES('I1', " + (x * 6 + i * 2 + 1) + ", 0, 'STRING', false, 30)");
-//        runQuery("INSERT INTO SQOOP.SQ_INPUT"
-//        +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
-//        + " VALUES('I2', " + (x * 6 + i * 2 + 1) + ", 1, 'MAP', false, 30)");
-//
-//        // Second form
-//        runQuery("INSERT INTO SQOOP.SQ_INPUT"
-//        +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
-//        + " VALUES('I3', " + (x * 6 + i * 2 + 2) + ", 0, 'STRING', false, 30)");
-//        runQuery("INSERT INTO SQOOP.SQ_INPUT"
-//        +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
-//        + " VALUES('I4', " + (x * 6 + i * 2 + 2) + ", 1, 'MAP', false, 30)");
-//      }
-//    }
-//  }
-//
-//  /**
-//   * Load testing connection objects into metadata repository.
-//   *
-//   * @throws Exception
-//   */
-//  public void loadConnections() throws Exception {
-//    // Insert two connections - CA and CB
-//    runQuery("INSERT INTO SQOOP.SQ_CONNECTION(SQN_NAME, SQN_CONNECTOR) "
-//      + "VALUES('CA', 1)");
-//    runQuery("INSERT INTO SQOOP.SQ_CONNECTION(SQN_NAME, SQN_CONNECTOR) "
-//      + "VALUES('CB', 1)");
-//
-//    for(String ci : new String[] {"1", "2"}) {
-//      for(String i : new String[] {"1", "3", "13", "15"}) {
-//        runQuery("INSERT INTO SQOOP.SQ_CONNECTION_INPUT"
-//          + "(SQNI_CONNECTION, SQNI_INPUT, SQNI_VALUE) "
-//          + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
-//      }
-//    }
-//  }
-//
-//  /**
-//   * Load testing job objects into metadata repository.
-//   *
-//   * @throws Exception
-//   */
-//  public void loadJobs() throws Exception {
-//    for(String type : new String[] {"IMPORT", "EXPORT"}) {
-//      for(String name : new String[] {"JA", "JB"} ) {
-//        runQuery("INSERT INTO SQOOP.SQ_JOB(SQB_NAME, SQB_CONNECTION, SQB_TYPE)"
-//          + " VALUES('" + name + "', 1, '" + type + "')");
-//      }
-//    }
-//
-//    // Import inputs
-//    for(String ci : new String[] {"1", "2"}) {
-//      for(String i : new String[] {"5", "7", "17", "19"}) {
-//        runQuery("INSERT INTO SQOOP.SQ_JOB_INPUT"
-//          + "(SQBI_JOB, SQBI_INPUT, SQBI_VALUE) "
-//          + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
-//      }
-//    }
-//
-//    // Export inputs
-//    for(String ci : new String[] {"3", "4"}) {
-//      for(String i : new String[] {"9", "11", "21", "23"}) {
-//        runQuery("INSERT INTO SQOOP.SQ_JOB_INPUT"
-//          + "(SQBI_JOB, SQBI_INPUT, SQBI_VALUE) "
-//          + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
-//      }
-//    }
-//  }
-//
-//  /**
-//   * Add a second connector for testing with multiple connectors
-//   */
-//  public void addConnector() throws Exception {
-//    // Connector entry
-//    runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS, SQC_VERSION)"
-//            + "VALUES('B', 'org.apache.sqoop.test.B', '1.0-test')");
-//  }
-//
-//  /**
-//   * Load testing submissions into the metadata repository.
-//   *
-//   * @throws Exception
-//   */
-//  public void loadSubmissions() throws  Exception {
-//    runQuery("INSERT INTO SQOOP.SQ_COUNTER_GROUP "
-//      + "(SQG_NAME) "
-//      + "VALUES"
-//      + "('gA'), ('gB')"
-//    );
-//
-//    runQuery("INSERT INTO SQOOP.SQ_COUNTER "
-//      + "(SQR_NAME) "
-//      + "VALUES"
-//      + "('cA'), ('cB')"
-//    );
-//
-//    runQuery("INSERT INTO SQOOP.SQ_SUBMISSION"
-//      + "(SQS_JOB, SQS_STATUS, SQS_CREATION_DATE, SQS_UPDATE_DATE,"
-//      + " SQS_EXTERNAL_ID, SQS_EXTERNAL_LINK, SQS_EXCEPTION,"
-//      + " SQS_EXCEPTION_TRACE)"
-//      + "VALUES "
-//      + "(1, 'RUNNING', '2012-01-01 01:01:01', '2012-01-01 01:01:01', 'job_1',"
-//      +   "NULL, NULL, NULL),"
-//      + "(2, 'SUCCEEDED', '2012-01-01 01:01:01', '2012-01-02 01:01:01', 'job_2',"
-//      + " NULL, NULL, NULL),"
-//      + "(3, 'FAILED', '2012-01-01 01:01:01', '2012-01-03 01:01:01', 'job_3',"
-//      + " NULL, NULL, NULL),"
-//      + "(4, 'UNKNOWN', '2012-01-01 01:01:01', '2012-01-04 01:01:01', 'job_4',"
-//      + " NULL, NULL, NULL),"
-//      + "(1, 'RUNNING', '2012-01-01 01:01:01', '2012-01-05 01:01:01', 'job_5',"
-//      + " NULL, NULL, NULL)"
-//    );
-//
-//    runQuery("INSERT INTO SQOOP.SQ_COUNTER_SUBMISSION "
-//      + "(SQRS_GROUP, SQRS_COUNTER, SQRS_SUBMISSION, SQRS_VALUE) "
-//      + "VALUES"
-//      + "(1, 1, 4, 300)"
-//    );
-//
-//  }
-//
-//  protected MConnector getConnector() {
-//    return new MConnector("A", "org.apache.sqoop.test.A", "1.0-test",
-//      getConnectionForms(), getJobForms());
-//  }
-//
-//  protected MFramework getFramework() {
-//    return new MFramework(getConnectionForms(), getJobForms(),
-//      FrameworkManager.CURRENT_FRAMEWORK_VERSION);
-//  }
-//
-//  protected void fillConnection(MConnection connection) {
-//    List<MForm> forms;
-//
-//    forms = connection.getConnectorPart().getForms();
-//    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value1");
-//    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value2");
-//
-//    forms = connection.getFrameworkPart().getForms();
-//    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value13");
-//    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value15");
-//  }
-//
-//  protected void fillJob(MJob job) {
-//    List<MForm> forms;
-//
-//    forms = job.getFromPart().getForms();
-//    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value1");
-//    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value2");
-//
-//    forms = job.getFrameworkPart().getForms();
-//    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value13");
-//    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value15");
-//  }
-//
-//  protected List<MJobForms> getJobForms() {
-//    List <MJobForms> jobForms = new LinkedList<MJobForms>();
-//    jobForms.add(new MJobForms(MJob.Type.IMPORT, getForms()));
-//    jobForms.add(new MJobForms(MJob.Type.EXPORT, getForms()));
-//    return jobForms;
-//  }
-//
-//  protected MConnectionForms getConnectionForms() {
-//    return new MConnectionForms(getForms());
-//  }
-//
-//  protected List<MForm> getForms() {
-//    List<MForm> forms = new LinkedList<MForm>();
-//
-//    List<MInput<?>> inputs;
-//    MInput input;
-//
-//    inputs = new LinkedList<MInput<?>>();
-//    input = new MStringInput("I1", false, (short)30);
-//    inputs.add(input);
-//    input = new MMapInput("I2", false);
-//    inputs.add(input);
-//    forms.add(new MForm("F1", inputs));
-//
-//    inputs = new LinkedList<MInput<?>>();
-//    input = new MStringInput("I3", false, (short)30);
-//    inputs.add(input);
-//    input = new MMapInput("I4", false);
-//    inputs.add(input);
-//    forms.add(new MForm("F2", inputs));
-//
-//    return forms;
-//  }
-//
-//  /**
-//   * Find out number of entries in given table.
-//   *
-//   * @param table Table name
-//   * @return Number of rows in the table
-//   * @throws Exception
-//   */
-//  protected long countForTable(String table) throws Exception {
-//    Statement stmt = null;
-//    ResultSet rs = null;
-//
-//    try {
-//      stmt = getDerbyConnection().createStatement();
-//
-//      rs = stmt.executeQuery("SELECT COUNT(*) FROM "+ table);
-//      rs.next();
-//
-//      return rs.getLong(1);
-//    } finally {
-//      if(stmt != null) {
-//        stmt.close();
-//      }
-//      if(rs != null) {
-//        rs.close();
-//      }
-//    }
-//  }
-//
-//  /**
-//   * Assert row count for given table.
-//   *
-//   * @param table Table name
-//   * @param expected Expected number of rows
-//   * @throws Exception
-//   */
-//  protected void assertCountForTable(String table, long expected)
-//    throws Exception {
-//    long count = countForTable(table);
-//    assertEquals(expected, count);
-//  }
-//
-//  /**
-//   * Printout repository content for advance debugging.
-//   *
-//   * This method is currently unused, but might be helpful in the future, so
-//   * I'm letting it here.
-//   *
-//   * @throws Exception
-//   */
-//  protected void generateDatabaseState() throws Exception {
-//    for(String tbl : new String[] {"SQ_CONNECTOR", "SQ_FORM", "SQ_INPUT",
-//      "SQ_CONNECTION", "SQ_CONNECTION_INPUT", "SQ_JOB", "SQ_JOB_INPUT"}) {
-//      generateTableState("SQOOP." + tbl);
-//    }
-//  }
-//
-//  /**
-//   * Printout one single table.
-//   *
-//   * @param table Table name
-//   * @throws Exception
-//   */
-//  protected void generateTableState(String table) throws Exception {
-//    PreparedStatement ps = null;
-//    ResultSet rs = null;
-//    ResultSetMetaData rsmt = null;
-//
-//    try {
-//      ps = getDerbyConnection().prepareStatement("SELECT * FROM " + table);
-//      rs = ps.executeQuery();
-//
-//      rsmt = rs.getMetaData();
-//
-//      StringBuilder sb = new StringBuilder();
-//      System.out.println("Table " + table + ":");
-//
-//      for(int i = 1; i <= rsmt.getColumnCount(); i++) {
-//        sb.append("| ").append(rsmt.getColumnName(i)).append(" ");
-//      }
-//      sb.append("|");
-//      System.out.println(sb.toString());
-//
-//      while(rs.next()) {
-//        sb = new StringBuilder();
-//        for(int i = 1; i <= rsmt.getColumnCount(); i++) {
-//          sb.append("| ").append(rs.getString(i)).append(" ");
-//        }
-//        sb.append("|");
-//        System.out.println(sb.toString());
-//      }
-//
-//      System.out.println("");
-//
-//    } finally {
-//      if(rs != null) {
-//        rs.close();
-//      }
-//      if(ps != null) {
-//        ps.close();
-//      }
-//    }
-//  }
+  private static int SYSTEM_VERSION = 4;
+
+  public static final String DERBY_DRIVER =
+    "org.apache.derby.jdbc.EmbeddedDriver";
+
+  public static final String JDBC_URL =
+    "jdbc:derby:memory:myDB";
+
+  private Connection connection;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+
+    // Create connection to the database
+    Class.forName(DERBY_DRIVER).newInstance();
+    connection = DriverManager.getConnection(getStartJdbcUrl());
+  }
+
+  @Override
+  public void tearDown() throws Exception {
+    // Close active connection
+    if(connection != null) {
+      connection.close();
+    }
+
+    try {
+      // Drop in memory database
+      DriverManager.getConnection(getStopJdbcUrl());
+    } catch (SQLException ex) {
+      // Dropping Derby database leads always to exception
+    }
+
+    // Call parent tear down
+    super.tearDown();
+  }
+
+  /**
+   * Create derby schema.
+   *
+   * @throws Exception
+   */
+  protected void createSchema(int version) throws Exception {
+    if (version > 0) {
+      runQuery(QUERY_CREATE_SCHEMA_SQOOP);
+      runQuery(QUERY_CREATE_TABLE_SQ_CONNECTOR);
+      runQuery(QUERY_CREATE_TABLE_SQ_FORM);
+      runQuery(QUERY_CREATE_TABLE_SQ_INPUT);
+      runQuery(QUERY_CREATE_TABLE_SQ_CONNECTION);
+      runQuery(QUERY_CREATE_TABLE_SQ_JOB);
+      runQuery(QUERY_CREATE_TABLE_SQ_CONNECTION_INPUT);
+      runQuery(QUERY_CREATE_TABLE_SQ_JOB_INPUT);
+      runQuery(QUERY_CREATE_TABLE_SQ_SUBMISSION);
+      runQuery(QUERY_CREATE_TABLE_SQ_COUNTER_GROUP);
+      runQuery(QUERY_CREATE_TABLE_SQ_COUNTER);
+      runQuery(QUERY_CREATE_TABLE_SQ_COUNTER_SUBMISSION);
+    }
+
+    if (version > 1) {
+      runQuery(QUERY_CREATE_TABLE_SQ_SYSTEM);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_CONNECTION_ADD_COLUMN_ENABLED);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_ENABLED);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_CONNECTION_ADD_COLUMN_CREATION_USER);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_CONNECTION_ADD_COLUMN_UPDATE_USER);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_CREATION_USER);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_UPDATE_USER);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_SUBMISSION_ADD_COLUMN_CREATION_USER);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_SUBMISSION_ADD_COLUMN_UPDATE_USER);
+    }
+
+    if (version > 3) {
+      runQuery(QUERY_UPGRADE_TABLE_SQ_FORM_RENAME_COLUMN_SQF_OPERATION_TO_SQF_DIRECTION);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_RENAME_COLUMN_SQB_CONNECTION_TO_SQB_FROM_CONNECTION);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_COLUMN_SQB_TO_CONNECTION);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_REMOVE_CONSTRAINT_SQB_SQN);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_CONSTRAINT_SQB_SQN_FROM);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ADD_CONSTRAINT_SQB_SQN_TO);
+      runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_REMOVE_COLUMN_SQB_TYPE);
+    }
+
+    runQuery("INSERT INTO SQOOP.SQ_SYSTEM(SQM_KEY, SQM_VALUE) VALUES('version', '"  + version + "')");
+    runQuery("INSERT INTO SQOOP.SQ_SYSTEM(SQM_KEY, SQM_VALUE) " +
+      "VALUES('framework.version', '1')");
+  }
+
+  protected void createSchema() throws Exception {
+    createSchema(SYSTEM_VERSION);
+  }
+
+  /**
+   * Run arbitrary query on derby memory repository.
+   *
+   * @param query Query to execute
+   * @throws Exception
+   */
+  protected void runQuery(String query, String... args) throws Exception {
+    PreparedStatement stmt = null;
+    try {
+      stmt = getDerbyConnection().prepareStatement(query);
+
+      for (int i = 0; i < args.length; ++i) {
+        stmt.setString(i + 1, args[i]);
+      }
+
+      stmt.execute();
+    } finally {
+      if (stmt != null) {
+        stmt.close();
+      }
+    }
+  }
+
+  protected Connection getDerbyConnection() {
+    return connection;
+  }
+
+  protected String getJdbcUrl() {
+    return JDBC_URL;
+  }
+
+  protected String getStartJdbcUrl() {
+    return JDBC_URL + ";create=true";
+  }
+
+  protected String getStopJdbcUrl() {
+    return JDBC_URL + ";drop=true";
+  }
+
+  protected void loadConnectorAndFrameworkVersion2() throws Exception {
+    // Connector entry
+    runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS, SQC_VERSION)"
+        + "VALUES('A', 'org.apache.sqoop.test.A', '1.0-test')");
+
+    String connector = "1";
+
+    // Connector form entries
+    for(String operation : new String[] {"null", "'IMPORT'", "'EXPORT'"}) {
+
+      String type;
+      if(operation.equals("null")) {
+        type = "CONNECTION";
+      } else {
+        type = "JOB";
+      }
+
+      runQuery("INSERT INTO SQOOP.SQ_FORM"
+          + "(SQF_CONNECTOR, SQF_OPERATION, SQF_NAME, SQF_TYPE, SQF_INDEX) "
+          + "VALUES("
+          + connector  + ", "
+          + operation
+          + ", 'F1', '"
+          + type
+          + "', 0)");
+      runQuery("INSERT INTO SQOOP.SQ_FORM"
+          + "(SQF_CONNECTOR, SQF_OPERATION, SQF_NAME, SQF_TYPE, SQF_INDEX) "
+          + "VALUES("
+          + connector + ", "
+          + operation
+          +  ", 'F2', '"
+          + type
+          + "', 1)");
+    }
+
+    // Framework form entries
+    runQuery("INSERT INTO SQOOP.SQ_FORM"
+        + "(SQF_CONNECTOR, SQF_OPERATION, SQF_NAME, SQF_TYPE, SQF_INDEX) VALUES"
+        + "(NULL, 'IMPORT', 'output', 'JOB', 0),"
+        + "(NULL, 'IMPORT', 'throttling', 'JOB', 1),"
+        + "(NULL, 'EXPORT', 'input', 'JOB', 0),"
+        + "(NULL, 'EXPORT', 'throttling', 'JOB', 1),"
+        + "(NULL, NULL, 'security', 'CONNECTION', 0)");
+
+    // Connector input entries
+    int x = 0;
+    for(int i = 0; i < 3; i++) {
+      // First form
+      runQuery("INSERT INTO SQOOP.SQ_INPUT"
+          +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+          + " VALUES('I1', " + (i * 2 + 1) + ", 0, 'STRING', false, 30)");
+      runQuery("INSERT INTO SQOOP.SQ_INPUT"
+          +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+          + " VALUES('I2', " + (i * 2 + 1) + ", 1, 'MAP', false, 30)");
+
+      // Second form
+      runQuery("INSERT INTO SQOOP.SQ_INPUT"
+          +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+          + " VALUES('I3', " + (i * 2 + 2) + ", 0, 'STRING', false, 30)");
+      runQuery("INSERT INTO SQOOP.SQ_INPUT"
+          +"(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+          + " VALUES('I4', " + (i * 2 + 2) + ", 1, 'MAP', false, 30)");
+    }
+
+    // Framework input entries.
+    runQuery("INSERT INTO SQOOP.SQ_INPUT (SQI_NAME, SQI_FORM, SQI_INDEX,"
+        + " SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH, SQI_ENUMVALS)"
+        +" VALUES ('security.maxConnections',11,0,'INTEGER','false',NULL,NULL),"
+        + "('input.inputDirectory',9,0,'STRING','false',255,NULL),"
+        + "('throttling.extractors',8,0,'INTEGER','false',NULL,NULL),"
+        + "('throttling.loaders',8,1,'INTEGER','false',NULL,NULL),"
+        + "('output.storageType',7,0,'ENUM','false',NULL,'HDFS'),"
+        + "('output.outputFormat',7,1,'ENUM','false',NULL,'TEXT_FILE,SEQUENCE_FILE'),"
+        + "('output.compression',7,2,'ENUM','false',NULL,'NONE,DEFAULT,DEFLATE,GZIP,BZIP2,LZO,LZ4,SNAPPY'),"
+        + "('output.outputDirectory',7,3,'STRING','false',255,NULL),"
+        + "('throttling.extractors',10,0,'INTEGER','false',NULL,NULL),"
+        + "('throttling.loaders',10,1,'INTEGER','false',NULL,NULL)");
+  }
+
+  protected void loadConnectorAndFrameworkVersion4() throws Exception {
+    // Connector entry
+    runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS, SQC_VERSION)"
+        + "VALUES('A', 'org.apache.sqoop.test.A', '1.0-test')");
+
+    // Connector part
+    for (String connector : new String[]{"1"}) {
+      // Form entries
+      for (String direction : new String[]{"null", "'FROM'", "'TO'"}) {
+
+        String type;
+        if (direction.equals("null")) {
+          type = "CONNECTION";
+        } else {
+          type = "JOB";
+        }
+
+        runQuery("INSERT INTO SQOOP.SQ_FORM"
+            + "(SQF_CONNECTOR, SQF_DIRECTION, SQF_NAME, SQF_TYPE, SQF_INDEX) "
+            + "VALUES("
+            + connector + ", "
+            + direction
+            + ", 'F1', '"
+            + type
+            + "', 0)");
+        runQuery("INSERT INTO SQOOP.SQ_FORM"
+            + "(SQF_CONNECTOR, SQF_DIRECTION, SQF_NAME, SQF_TYPE, SQF_INDEX) "
+            + "VALUES("
+            + connector + ", "
+            + direction
+            + ", 'F2', '"
+            + type
+            + "', 1)");
+      }
+    }
+
+    // Framework part
+    for (String type : new String[]{"CONNECTION", "JOB"}) {
+      runQuery("INSERT INTO SQOOP.SQ_FORM"
+          + "(SQF_CONNECTOR, SQF_DIRECTION, SQF_NAME, SQF_TYPE, SQF_INDEX) "
+          + "VALUES(NULL, NULL"
+          + ", 'F1', '"
+          + type
+          + "', 0)");
+      runQuery("INSERT INTO SQOOP.SQ_FORM"
+          + "(SQF_CONNECTOR, SQF_DIRECTION, SQF_NAME, SQF_TYPE, SQF_INDEX) "
+          + "VALUES(NULL, NULL"
+          + ", 'F2', '"
+          + type
+          + "', 1)");
+    }
+
+    // Input entries
+    // Connector connection parts: 0-3
+    // Connector job (FROM) parts: 4-7
+    // Connector job (TO) parts: 8-11
+    // Framework connection parts: 12-15
+    // Framework job parts: 16-19
+    for (int i = 0; i < 5; i++) {
+      // First form
+      runQuery("INSERT INTO SQOOP.SQ_INPUT"
+          + "(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+          + " VALUES('I1', " + (i * 2 + 1) + ", 0, 'STRING', false, 30)");
+      runQuery("INSERT INTO SQOOP.SQ_INPUT"
+          + "(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+          + " VALUES('I2', " + (i * 2 + 1) + ", 1, 'MAP', false, 30)");
+
+      // Second form
+      runQuery("INSERT INTO SQOOP.SQ_INPUT"
+          + "(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+          + " VALUES('I3', " + (i * 2 + 2) + ", 0, 'STRING', false, 30)");
+      runQuery("INSERT INTO SQOOP.SQ_INPUT"
+          + "(SQI_NAME, SQI_FORM, SQI_INDEX, SQI_TYPE, SQI_STRMASK, SQI_STRLENGTH)"
+          + " VALUES('I4', " + (i * 2 + 2) + ", 1, 'MAP', false, 30)");
+    }
+  }
+
+  /**
+   * Load testing connector and framework metadata into repository.
+   *
+   * @param version system version (2 or 4)
+   * @throws Exception
+   */
+  protected void loadConnectorAndFramework(int version) throws Exception {
+    switch(version) {
+      case 2:
+        loadConnectorAndFrameworkVersion2();
+        break;
+
+      case 4:
+        loadConnectorAndFrameworkVersion4();
+        break;
+
+      default:
+        throw new AssertionError("Invalid connector and framework version: " + version);
+    }
+  }
+
+  protected void loadConnectorAndFramework() throws Exception {
+    loadConnectorAndFramework(SYSTEM_VERSION);
+  }
+
+  /**
+   * Load testing connection objects into metadata repository.
+   *
+   * @param version system version (2 or 4)
+   * @throws Exception
+   */
+  public void loadConnections(int version) throws Exception {
+    switch (version) {
+      case 2:
+        // Insert two connections - CA and CB
+        runQuery("INSERT INTO SQOOP.SQ_CONNECTION(SQN_NAME, SQN_CONNECTOR) "
+            + "VALUES('CA', 1)");
+        runQuery("INSERT INTO SQOOP.SQ_CONNECTION(SQN_NAME, SQN_CONNECTOR) "
+            + "VALUES('CB', 1)");
+
+        for(String ci : new String[] {"1", "2"}) {
+          for(String i : new String[] {"1", "3", "13", "15"}) {
+            runQuery("INSERT INTO SQOOP.SQ_CONNECTION_INPUT"
+                + "(SQNI_CONNECTION, SQNI_INPUT, SQNI_VALUE) "
+                + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
+          }
+        }
+        break;
+
+      case 4:
+        // Insert two connections - CA and CB
+        runQuery("INSERT INTO SQOOP.SQ_CONNECTION(SQN_NAME, SQN_CONNECTOR) "
+            + "VALUES('CA', 1)");
+        runQuery("INSERT INTO SQOOP.SQ_CONNECTION(SQN_NAME, SQN_CONNECTOR) "
+            + "VALUES('CB', 1)");
+
+        for (String ci : new String[]{"1", "2"}) {
+          for (String i : new String[]{"1", "3", "13", "15"}) {
+            runQuery("INSERT INTO SQOOP.SQ_CONNECTION_INPUT"
+                + "(SQNI_CONNECTION, SQNI_INPUT, SQNI_VALUE) "
+                + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
+          }
+        }
+        break;
+
+      default:
+        throw new AssertionError("Invalid connector and framework version: " + version);
+    }
+  }
+
+  public void loadConnections() throws Exception {
+    loadConnections(SYSTEM_VERSION);
+  }
+
+  /**
+   * Load testing job objects into metadata repository.
+   *
+   * @param version system version (2 or 4)
+   * @throws Exception
+   */
+  public void loadJobs(int version) throws Exception {
+    switch (version) {
+      case 2:
+        for(String type : new String[] {"IMPORT", "EXPORT"}) {
+          for(String name : new String[] {"JA", "JB"} ) {
+            runQuery("INSERT INTO SQOOP.SQ_JOB(SQB_NAME, SQB_CONNECTION, SQB_TYPE)"
+                + " VALUES('" + name + "', 1, '" + type + "')");
+          }
+        }
+
+        // Import inputs
+        for(String ci : new String[] {"1", "2"}) {
+          for(String i : new String[] {"5", "7", "17", "19"}) {
+            runQuery("INSERT INTO SQOOP.SQ_JOB_INPUT"
+                + "(SQBI_JOB, SQBI_INPUT, SQBI_VALUE) "
+                + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
+          }
+        }
+
+        // Export inputs
+        for(String ci : new String[] {"3", "4"}) {
+          for(String i : new String[] {"9", "11"}) {
+            runQuery("INSERT INTO SQOOP.SQ_JOB_INPUT"
+                + "(SQBI_JOB, SQBI_INPUT, SQBI_VALUE) "
+                + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
+          }
+        }
+        break;
+
+
+      case 4:
+        for (String name : new String[]{"JA", "JB", "JC", "JD"}) {
+          runQuery("INSERT INTO SQOOP.SQ_JOB(SQB_NAME, SQB_FROM_CONNECTION, SQB_TO_CONNECTION)"
+              + " VALUES('" + name + "', 1, 1)");
+        }
+
+        // Odd IDs inputs have values
+        for (String ci : new String[]{"1", "2", "3", "4"}) {
+          for (String i : new String[]{"5", "9", "17"}) {
+            runQuery("INSERT INTO SQOOP.SQ_JOB_INPUT"
+                + "(SQBI_JOB, SQBI_INPUT, SQBI_VALUE) "
+                + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
+          }
+
+          for (String i : new String[]{"7", "11", "19"}) {
+            runQuery("INSERT INTO SQOOP.SQ_JOB_INPUT"
+                + "(SQBI_JOB, SQBI_INPUT, SQBI_VALUE) "
+                + "VALUES(" + ci + ", " + i + ", 'Value" + i + "')");
+          }
+        }
+        break;
+
+      default:
+        throw new AssertionError("Invalid connector and framework version: " + version);
+    }
+  }
+
+  public void loadJobs() throws Exception {
+    loadJobs(SYSTEM_VERSION);
+  }
+
+  /**
+   * Add a second connector for testing with multiple connectors
+   */
+  public void addConnector() throws Exception {
+    // Connector entry
+    runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS, SQC_VERSION)"
+            + "VALUES('B', 'org.apache.sqoop.test.B', '1.0-test')");
+  }
+
+  /**
+   * Load testing submissions into the metadata repository.
+   *
+   * @throws Exception
+   */
+  public void loadSubmissions() throws  Exception {
+    runQuery("INSERT INTO SQOOP.SQ_COUNTER_GROUP "
+      + "(SQG_NAME) "
+      + "VALUES"
+      + "('gA'), ('gB')"
+    );
+
+    runQuery("INSERT INTO SQOOP.SQ_COUNTER "
+      + "(SQR_NAME) "
+      + "VALUES"
+      + "('cA'), ('cB')"
+    );
+
+    runQuery("INSERT INTO SQOOP.SQ_SUBMISSION"
+      + "(SQS_JOB, SQS_STATUS, SQS_CREATION_DATE, SQS_UPDATE_DATE,"
+      + " SQS_EXTERNAL_ID, SQS_EXTERNAL_LINK, SQS_EXCEPTION,"
+      + " SQS_EXCEPTION_TRACE)"
+      + "VALUES "
+      + "(1, 'RUNNING', '2012-01-01 01:01:01', '2012-01-01 01:01:01', 'job_1',"
+      +   "NULL, NULL, NULL),"
+      + "(2, 'SUCCEEDED', '2012-01-01 01:01:01', '2012-01-02 01:01:01', 'job_2',"
+      + " NULL, NULL, NULL),"
+      + "(3, 'FAILED', '2012-01-01 01:01:01', '2012-01-03 01:01:01', 'job_3',"
+      + " NULL, NULL, NULL),"
+      + "(4, 'UNKNOWN', '2012-01-01 01:01:01', '2012-01-04 01:01:01', 'job_4',"
+      + " NULL, NULL, NULL),"
+      + "(1, 'RUNNING', '2012-01-01 01:01:01', '2012-01-05 01:01:01', 'job_5',"
+      + " NULL, NULL, NULL)"
+    );
+
+    runQuery("INSERT INTO SQOOP.SQ_COUNTER_SUBMISSION "
+      + "(SQRS_GROUP, SQRS_COUNTER, SQRS_SUBMISSION, SQRS_VALUE) "
+      + "VALUES"
+      + "(1, 1, 4, 300)"
+    );
+
+  }
+
+  protected MConnector getConnector() {
+    return new MConnector("A", "org.apache.sqoop.test.A", "1.0-test",
+      getConnectionForms(), new MJobForms(getForms()), new MJobForms(getForms()));
+  }
+
+  protected MFramework getFramework() {
+    return new MFramework(getConnectionForms(), new MJobForms(getForms()),
+      FrameworkManager.CURRENT_FRAMEWORK_VERSION);
+  }
+
+  protected void fillConnection(MConnection connection) {
+    List<MForm> forms;
+
+    forms = connection.getConnectorPart().getForms();
+    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value1");
+    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value2");
+
+    forms = connection.getFrameworkPart().getForms();
+    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value13");
+    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value15");
+  }
+
+  protected void fillJob(MJob job) {
+    List<MForm> forms;
+
+    forms = job.getConnectorPart(Direction.FROM).getForms();
+    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value1");
+    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value2");
+
+    forms = job.getConnectorPart(Direction.TO).getForms();
+    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value1");
+    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value2");
+
+    forms = job.getFrameworkPart().getForms();
+    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Value13");
+    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Value15");
+  }
+
+  protected MConnectionForms getConnectionForms() {
+    return new MConnectionForms(getForms());
+  }
+
+  protected List<MForm> getForms() {
+    List<MForm> forms = new LinkedList<MForm>();
+
+    List<MInput<?>> inputs;
+    MInput input;
+
+    inputs = new LinkedList<MInput<?>>();
+    input = new MStringInput("I1", false, (short)30);
+    inputs.add(input);
+    input = new MMapInput("I2", false);
+    inputs.add(input);
+    forms.add(new MForm("F1", inputs));
+
+    inputs = new LinkedList<MInput<?>>();
+    input = new MStringInput("I3", false, (short)30);
+    inputs.add(input);
+    input = new MMapInput("I4", false);
+    inputs.add(input);
+    forms.add(new MForm("F2", inputs));
+
+    return forms;
+  }
+
+  /**
+   * Find out number of entries in given table.
+   *
+   * @param table Table name
+   * @return Number of rows in the table
+   * @throws Exception
+   */
+  protected long countForTable(String table) throws Exception {
+    Statement stmt = null;
+    ResultSet rs = null;
+
+    try {
+      stmt = getDerbyConnection().createStatement();
+
+      rs = stmt.executeQuery("SELECT COUNT(*) FROM "+ table);
+      rs.next();
+
+      return rs.getLong(1);
+    } finally {
+      if(stmt != null) {
+        stmt.close();
+      }
+      if(rs != null) {
+        rs.close();
+      }
+    }
+  }
+
+  /**
+   * Assert row count for given table.
+   *
+   * @param table Table name
+   * @param expected Expected number of rows
+   * @throws Exception
+   */
+  protected void assertCountForTable(String table, long expected)
+    throws Exception {
+    long count = countForTable(table);
+    assertEquals(expected, count);
+  }
+
+  /**
+   * Printout repository content for advance debugging.
+   *
+   * This method is currently unused, but might be helpful in the future, so
+   * I'm letting it here.
+   *
+   * @throws Exception
+   */
+  protected void generateDatabaseState() throws Exception {
+    for(String tbl : new String[] {"SQ_CONNECTOR", "SQ_FORM", "SQ_INPUT",
+      "SQ_CONNECTION", "SQ_CONNECTION_INPUT", "SQ_JOB", "SQ_JOB_INPUT"}) {
+      generateTableState("SQOOP." + tbl);
+    }
+  }
+
+  /**
+   * Printout one single table.
+   *
+   * @param table Table name
+   * @throws Exception
+   */
+  protected void generateTableState(String table) throws Exception {
+    PreparedStatement ps = null;
+    ResultSet rs = null;
+    ResultSetMetaData rsmt = null;
+
+    try {
+      ps = getDerbyConnection().prepareStatement("SELECT * FROM " + table);
+      rs = ps.executeQuery();
+
+      rsmt = rs.getMetaData();
+
+      StringBuilder sb = new StringBuilder();
+      System.out.println("Table " + table + ":");
+
+      for(int i = 1; i <= rsmt.getColumnCount(); i++) {
+        sb.append("| ").append(rsmt.getColumnName(i)).append(" ");
+      }
+      sb.append("|");
+      System.out.println(sb.toString());
+
+      while(rs.next()) {
+        sb = new StringBuilder();
+        for(int i = 1; i <= rsmt.getColumnCount(); i++) {
+          sb.append("| ").append(rs.getString(i)).append(" ");
+        }
+        sb.append("|");
+        System.out.println(sb.toString());
+      }
+
+      System.out.println("");
+
+    } finally {
+      if(rs != null) {
+        rs.close();
+      }
+      if(ps != null) {
+        ps.close();
+      }
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
index bdd3c05..f9e9217 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectionHandling.java
@@ -33,213 +33,213 @@ import java.util.Map;
  */
 public class TestConnectionHandling extends DerbyTestCase {
 
-//  DerbyRepositoryHandler handler;
-//
-//  @Override
-//  public void setUp() throws Exception {
-//    super.setUp();
-//
-//    handler = new DerbyRepositoryHandler();
-//
-//    // We always needs schema for this test case
-//    createSchema();
-//
-//    // We always needs connector and framework structures in place
-//    loadConnectorAndFramework();
-//  }
-//
-//  public void testFindConnection() throws Exception {
-//    // Let's try to find non existing connection
-//    try {
-//      handler.findConnection(1, getDerbyConnection());
-//      fail();
-//    } catch(SqoopException ex) {
-//      assertEquals(DerbyRepoError.DERBYREPO_0024, ex.getErrorCode());
-//    }
-//
-//    // Load prepared connections into database
-//    loadConnections();
-//
-//    MConnection connA = handler.findConnection(1, getDerbyConnection());
-//    assertNotNull(connA);
-//    assertEquals(1, connA.getPersistenceId());
-//    assertEquals("CA", connA.getName());
-//
-//    List<MForm> forms;
-//
-//    // Check connector part
-//    forms = connA.getConnectorPart().getForms();
-//    assertEquals("Value1", forms.get(0).getInputs().get(0).getValue());
-//    assertNull(forms.get(0).getInputs().get(1).getValue());
-//    assertEquals("Value3", forms.get(1).getInputs().get(0).getValue());
-//    assertNull(forms.get(1).getInputs().get(1).getValue());
-//
-//    // Check framework part
-//    forms = connA.getFrameworkPart().getForms();
-//    assertEquals("Value13", forms.get(0).getInputs().get(0).getValue());
-//    assertNull(forms.get(0).getInputs().get(1).getValue());
-//    assertEquals("Value15", forms.get(1).getInputs().get(0).getValue());
-//    assertNull(forms.get(1).getInputs().get(1).getValue());
-//  }
-//
-//  public void testFindConnections() throws Exception {
-//    List<MConnection> list;
-//
-//    // Load empty list on empty repository
-//    list = handler.findConnections(getDerbyConnection());
-//    assertEquals(0, list.size());
-//
-//    loadConnections();
-//
-//    // Load all two connections on loaded repository
-//    list = handler.findConnections(getDerbyConnection());
-//    assertEquals(2, list.size());
-//
-//    assertEquals("CA", list.get(0).getName());
-//    assertEquals("CB", list.get(1).getName());
-//  }
-//
-//  public void testExistsConnection() throws Exception {
-//    // There shouldn't be anything on empty repository
-//    assertFalse(handler.existsConnection(1, getDerbyConnection()));
-//    assertFalse(handler.existsConnection(2, getDerbyConnection()));
-//    assertFalse(handler.existsConnection(3, getDerbyConnection()));
-//
-//    loadConnections();
-//
-//    assertTrue(handler.existsConnection(1, getDerbyConnection()));
-//    assertTrue(handler.existsConnection(2, getDerbyConnection()));
-//    assertFalse(handler.existsConnection(3, getDerbyConnection()));
-//  }
-//
-//  public void testCreateConnection() throws Exception {
-//    MConnection connection = getConnection();
-//
-//    // Load some data
-//    fillConnection(connection);
-//
-//    handler.createConnection(connection, getDerbyConnection());
-//
-//    assertEquals(1, connection.getPersistenceId());
-//    assertCountForTable("SQOOP.SQ_CONNECTION", 1);
-//    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 4);
-//
-//    MConnection retrieved = handler.findConnection(1, getDerbyConnection());
-//    assertEquals(1, retrieved.getPersistenceId());
-//
-//    List<MForm> forms;
-//    forms = connection.getConnectorPart().getForms();
-//    assertEquals("Value1", forms.get(0).getInputs().get(0).getValue());
-//    assertNull(forms.get(0).getInputs().get(1).getValue());
-//    assertEquals("Value2", forms.get(1).getInputs().get(0).getValue());
-//    assertNull(forms.get(1).getInputs().get(1).getValue());
-//
-//    forms = connection.getFrameworkPart().getForms();
-//    assertEquals("Value13", forms.get(0).getInputs().get(0).getValue());
-//    assertNull(forms.get(0).getInputs().get(1).getValue());
-//    assertEquals("Value15", forms.get(1).getInputs().get(0).getValue());
-//    assertNull(forms.get(1).getInputs().get(1).getValue());
-//
-//    // Let's create second connection
-//    connection = getConnection();
-//    fillConnection(connection);
-//
-//    handler.createConnection(connection, getDerbyConnection());
-//
-//    assertEquals(2, connection.getPersistenceId());
-//    assertCountForTable("SQOOP.SQ_CONNECTION", 2);
-//    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 8);
-//  }
-//
-//  public void testInUseConnection() throws Exception {
-//    loadConnections();
-//
-//    assertFalse(handler.inUseConnection(1, getDerbyConnection()));
-//
-//    loadJobs();
-//
-//    assertTrue(handler.inUseConnection(1, getDerbyConnection()));
-//  }
-//
-//  public void testUpdateConnection() throws Exception {
-//    loadConnections();
-//
-//    MConnection connection = handler.findConnection(1, getDerbyConnection());
-//
-//    List<MForm> forms;
-//
-//    forms = connection.getConnectorPart().getForms();
-//    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated");
-//    ((MMapInput)forms.get(0).getInputs().get(1)).setValue(null);
-//    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated");
-//    ((MMapInput)forms.get(1).getInputs().get(1)).setValue(null);
-//
-//    forms = connection.getFrameworkPart().getForms();
-//    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated");
-//    ((MMapInput)forms.get(0).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value
-//    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated");
-//    ((MMapInput)forms.get(1).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value
-//
-//    connection.setName("name");
-//
-//    handler.updateConnection(connection, getDerbyConnection());
-//
-//    assertEquals(1, connection.getPersistenceId());
-//    assertCountForTable("SQOOP.SQ_CONNECTION", 2);
-//    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 10);
-//
-//    MConnection retrieved = handler.findConnection(1, getDerbyConnection());
-//    assertEquals("name", connection.getName());
-//
-//    forms = retrieved.getConnectorPart().getForms();
-//    assertEquals("Updated", forms.get(0).getInputs().get(0).getValue());
-//    assertNull(forms.get(0).getInputs().get(1).getValue());
-//    assertEquals("Updated", forms.get(1).getInputs().get(0).getValue());
-//    assertNull(forms.get(1).getInputs().get(1).getValue());
-//
-//    forms = retrieved.getFrameworkPart().getForms();
-//    assertEquals("Updated", forms.get(0).getInputs().get(0).getValue());
-//    assertNotNull(forms.get(0).getInputs().get(1).getValue());
-//    assertEquals(((Map)forms.get(0).getInputs().get(1).getValue()).size(), 0);
-//    assertEquals("Updated", forms.get(1).getInputs().get(0).getValue());
-//    assertNotNull(forms.get(1).getInputs().get(1).getValue());
-//    assertEquals(((Map)forms.get(1).getInputs().get(1).getValue()).size(), 0);
-//  }
-//
-//  public void testEnableAndDisableConnection() throws Exception {
-//    loadConnections();
-//
-//    // disable connection 1
-//    handler.enableConnection(1, false, getDerbyConnection());
-//
-//    MConnection retrieved = handler.findConnection(1, getDerbyConnection());
-//    assertNotNull(retrieved);
-//    assertEquals(false, retrieved.getEnabled());
-//
-//    // enable connection 1
-//    handler.enableConnection(1, true, getDerbyConnection());
-//
-//    retrieved = handler.findConnection(1, getDerbyConnection());
-//    assertNotNull(retrieved);
-//    assertEquals(true, retrieved.getEnabled());
-//  }
-//
-//  public void testDeleteConnection() throws Exception {
-//    loadConnections();
-//
-//    handler.deleteConnection(1, getDerbyConnection());
-//    assertCountForTable("SQOOP.SQ_CONNECTION", 1);
-//    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 4);
-//
-//    handler.deleteConnection(2, getDerbyConnection());
-//    assertCountForTable("SQOOP.SQ_CONNECTION", 0);
-//    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 0);
-//  }
-//
-//  public MConnection getConnection() {
-//    return new MConnection(1,
-//      handler.findConnector("A", getDerbyConnection()).getConnectionForms(),
-//      handler.findFramework(getDerbyConnection()).getConnectionForms()
-//    );
-//  }
+  DerbyRepositoryHandler handler;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+
+    handler = new DerbyRepositoryHandler();
+
+    // We always needs schema for this test case
+    createSchema();
+
+    // We always needs connector and framework structures in place
+    loadConnectorAndFramework();
+  }
+
+  public void testFindConnection() throws Exception {
+    // Let's try to find non existing connection
+    try {
+      handler.findConnection(1, getDerbyConnection());
+      fail();
+    } catch(SqoopException ex) {
+      assertEquals(DerbyRepoError.DERBYREPO_0024, ex.getErrorCode());
+    }
+
+    // Load prepared connections into database
+    loadConnections();
+
+    MConnection connA = handler.findConnection(1, getDerbyConnection());
+    assertNotNull(connA);
+    assertEquals(1, connA.getPersistenceId());
+    assertEquals("CA", connA.getName());
+
+    List<MForm> forms;
+
+    // Check connector part
+    forms = connA.getConnectorPart().getForms();
+    assertEquals("Value1", forms.get(0).getInputs().get(0).getValue());
+    assertNull(forms.get(0).getInputs().get(1).getValue());
+    assertEquals("Value3", forms.get(1).getInputs().get(0).getValue());
+    assertNull(forms.get(1).getInputs().get(1).getValue());
+
+    // Check framework part
+    forms = connA.getFrameworkPart().getForms();
+    assertEquals("Value13", forms.get(0).getInputs().get(0).getValue());
+    assertNull(forms.get(0).getInputs().get(1).getValue());
+    assertEquals("Value15", forms.get(1).getInputs().get(0).getValue());
+    assertNull(forms.get(1).getInputs().get(1).getValue());
+  }
+
+  public void testFindConnections() throws Exception {
+    List<MConnection> list;
+
+    // Load empty list on empty repository
+    list = handler.findConnections(getDerbyConnection());
+    assertEquals(0, list.size());
+
+    loadConnections();
+
+    // Load all two connections on loaded repository
+    list = handler.findConnections(getDerbyConnection());
+    assertEquals(2, list.size());
+
+    assertEquals("CA", list.get(0).getName());
+    assertEquals("CB", list.get(1).getName());
+  }
+
+  public void testExistsConnection() throws Exception {
+    // There shouldn't be anything on empty repository
+    assertFalse(handler.existsConnection(1, getDerbyConnection()));
+    assertFalse(handler.existsConnection(2, getDerbyConnection()));
+    assertFalse(handler.existsConnection(3, getDerbyConnection()));
+
+    loadConnections();
+
+    assertTrue(handler.existsConnection(1, getDerbyConnection()));
+    assertTrue(handler.existsConnection(2, getDerbyConnection()));
+    assertFalse(handler.existsConnection(3, getDerbyConnection()));
+  }
+
+  public void testCreateConnection() throws Exception {
+    MConnection connection = getConnection();
+
+    // Load some data
+    fillConnection(connection);
+
+    handler.createConnection(connection, getDerbyConnection());
+
+    assertEquals(1, connection.getPersistenceId());
+    assertCountForTable("SQOOP.SQ_CONNECTION", 1);
+    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 4);
+
+    MConnection retrieved = handler.findConnection(1, getDerbyConnection());
+    assertEquals(1, retrieved.getPersistenceId());
+
+    List<MForm> forms;
+    forms = connection.getConnectorPart().getForms();
+    assertEquals("Value1", forms.get(0).getInputs().get(0).getValue());
+    assertNull(forms.get(0).getInputs().get(1).getValue());
+    assertEquals("Value2", forms.get(1).getInputs().get(0).getValue());
+    assertNull(forms.get(1).getInputs().get(1).getValue());
+
+    forms = connection.getFrameworkPart().getForms();
+    assertEquals("Value13", forms.get(0).getInputs().get(0).getValue());
+    assertNull(forms.get(0).getInputs().get(1).getValue());
+    assertEquals("Value15", forms.get(1).getInputs().get(0).getValue());
+    assertNull(forms.get(1).getInputs().get(1).getValue());
+
+    // Let's create second connection
+    connection = getConnection();
+    fillConnection(connection);
+
+    handler.createConnection(connection, getDerbyConnection());
+
+    assertEquals(2, connection.getPersistenceId());
+    assertCountForTable("SQOOP.SQ_CONNECTION", 2);
+    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 8);
+  }
+
+  public void testInUseConnection() throws Exception {
+    loadConnections();
+
+    assertFalse(handler.inUseConnection(1, getDerbyConnection()));
+
+    loadJobs();
+
+    assertTrue(handler.inUseConnection(1, getDerbyConnection()));
+  }
+
+  public void testUpdateConnection() throws Exception {
+    loadConnections();
+
+    MConnection connection = handler.findConnection(1, getDerbyConnection());
+
+    List<MForm> forms;
+
+    forms = connection.getConnectorPart().getForms();
+    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated");
+    ((MMapInput)forms.get(0).getInputs().get(1)).setValue(null);
+    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated");
+    ((MMapInput)forms.get(1).getInputs().get(1)).setValue(null);
+
+    forms = connection.getFrameworkPart().getForms();
+    ((MStringInput)forms.get(0).getInputs().get(0)).setValue("Updated");
+    ((MMapInput)forms.get(0).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value
+    ((MStringInput)forms.get(1).getInputs().get(0)).setValue("Updated");
+    ((MMapInput)forms.get(1).getInputs().get(1)).setValue(new HashMap<String, String>()); // inject new map value
+
+    connection.setName("name");
+
+    handler.updateConnection(connection, getDerbyConnection());
+
+    assertEquals(1, connection.getPersistenceId());
+    assertCountForTable("SQOOP.SQ_CONNECTION", 2);
+    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 10);
+
+    MConnection retrieved = handler.findConnection(1, getDerbyConnection());
+    assertEquals("name", connection.getName());
+
+    forms = retrieved.getConnectorPart().getForms();
+    assertEquals("Updated", forms.get(0).getInputs().get(0).getValue());
+    assertNull(forms.get(0).getInputs().get(1).getValue());
+    assertEquals("Updated", forms.get(1).getInputs().get(0).getValue());
+    assertNull(forms.get(1).getInputs().get(1).getValue());
+
+    forms = retrieved.getFrameworkPart().getForms();
+    assertEquals("Updated", forms.get(0).getInputs().get(0).getValue());
+    assertNotNull(forms.get(0).getInputs().get(1).getValue());
+    assertEquals(((Map)forms.get(0).getInputs().get(1).getValue()).size(), 0);
+    assertEquals("Updated", forms.get(1).getInputs().get(0).getValue());
+    assertNotNull(forms.get(1).getInputs().get(1).getValue());
+    assertEquals(((Map)forms.get(1).getInputs().get(1).getValue()).size(), 0);
+  }
+
+  public void testEnableAndDisableConnection() throws Exception {
+    loadConnections();
+
+    // disable connection 1
+    handler.enableConnection(1, false, getDerbyConnection());
+
+    MConnection retrieved = handler.findConnection(1, getDerbyConnection());
+    assertNotNull(retrieved);
+    assertEquals(false, retrieved.getEnabled());
+
+    // enable connection 1
+    handler.enableConnection(1, true, getDerbyConnection());
+
+    retrieved = handler.findConnection(1, getDerbyConnection());
+    assertNotNull(retrieved);
+    assertEquals(true, retrieved.getEnabled());
+  }
+
+  public void testDeleteConnection() throws Exception {
+    loadConnections();
+
+    handler.deleteConnection(1, getDerbyConnection());
+    assertCountForTable("SQOOP.SQ_CONNECTION", 1);
+    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 4);
+
+    handler.deleteConnection(2, getDerbyConnection());
+    assertCountForTable("SQOOP.SQ_CONNECTION", 0);
+    assertCountForTable("SQOOP.SQ_CONNECTION_INPUT", 0);
+  }
+
+  public MConnection getConnection() {
+    return new MConnection(1,
+      handler.findConnector("A", getDerbyConnection()).getConnectionForms(),
+      handler.findFramework(getDerbyConnection()).getConnectionForms()
+    );
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectorHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectorHandling.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectorHandling.java
index 54ae726..745e128 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectorHandling.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestConnectorHandling.java
@@ -26,70 +26,70 @@ import java.util.List;
  */
 public class TestConnectorHandling extends DerbyTestCase {
 
-//  DerbyRepositoryHandler handler;
-//
-//  @Override
-//  public void setUp() throws Exception {
-//    super.setUp();
-//
-//    handler = new DerbyRepositoryHandler();
-//
-//    // We always needs schema for this test case
-//    createSchema();
-//  }
-//
-//  public void testFindConnector() throws Exception {
-//    // On empty repository, no connectors should be there
-//    assertNull(handler.findConnector("A", getDerbyConnection()));
-//    assertNull(handler.findConnector("B", getDerbyConnection()));
-//
-//    // Load connector into repository
-//    loadConnectorAndFramework();
-//
-//    // Retrieve it
-//    MConnector connector = handler.findConnector("A", getDerbyConnection());
-//    assertNotNull(connector);
-//
-//    // Get original structure
-//    MConnector original = getConnector();
-//
-//    // And compare them
-//    assertEquals(original, connector);
-//  }
-//
-//  public void testFindAllConnectors() throws Exception {
-//    // No connectors in an empty repository, we expect an empty list
-//    assertEquals(handler.findConnectors(getDerbyConnection()).size(),0);
-//
-//    loadConnectorAndFramework();
-//    addConnector();
-//
-//    // Retrieve connectors
-//    List<MConnector> connectors = handler.findConnectors(getDerbyConnection());
-//    assertNotNull(connectors);
-//    assertEquals(connectors.size(),2);
-//    assertEquals(connectors.get(0).getUniqueName(),"A");
-//    assertEquals(connectors.get(1).getUniqueName(),"B");
-//
-//
-//  }
-//
-//  public void testRegisterConnector() throws Exception {
-//    MConnector connector = getConnector();
-//
-//    handler.registerConnector(connector, getDerbyConnection());
-//
-//    // Connector should get persistence ID
-//    assertEquals(1, connector.getPersistenceId());
-//
-//    // Now check content in corresponding tables
-//    assertCountForTable("SQOOP.SQ_CONNECTOR", 1);
-//    assertCountForTable("SQOOP.SQ_FORM", 6);
-//    assertCountForTable("SQOOP.SQ_INPUT", 12);
-//
-//    // Registered connector should be easily recovered back
-//    MConnector retrieved = handler.findConnector("A", getDerbyConnection());
-//    assertNotNull(retrieved);
-//    assertEquals(connector, retrieved);
-//  }
+  DerbyRepositoryHandler handler;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+
+    handler = new DerbyRepositoryHandler();
+
+    // We always needs schema for this test case
+    createSchema();
+  }
+
+  public void testFindConnector() throws Exception {
+    // On empty repository, no connectors should be there
+    assertNull(handler.findConnector("A", getDerbyConnection()));
+    assertNull(handler.findConnector("B", getDerbyConnection()));
+
+    // Load connector into repository
+    loadConnectorAndFramework();
+
+    // Retrieve it
+    MConnector connector = handler.findConnector("A", getDerbyConnection());
+    assertNotNull(connector);
+
+    // Get original structure
+    MConnector original = getConnector();
+
+    // And compare them
+    assertEquals(original, connector);
+  }
+
+  public void testFindAllConnectors() throws Exception {
+    // No connectors in an empty repository, we expect an empty list
+    assertEquals(handler.findConnectors(getDerbyConnection()).size(),0);
+
+    loadConnectorAndFramework();
+    addConnector();
+
+    // Retrieve connectors
+    List<MConnector> connectors = handler.findConnectors(getDerbyConnection());
+    assertNotNull(connectors);
+    assertEquals(connectors.size(),2);
+    assertEquals(connectors.get(0).getUniqueName(),"A");
+    assertEquals(connectors.get(1).getUniqueName(),"B");
+
+
+  }
+
+  public void testRegisterConnector() throws Exception {
+    MConnector connector = getConnector();
+
+    handler.registerConnector(connector, getDerbyConnection());
+
+    // Connector should get persistence ID
+    assertEquals(1, connector.getPersistenceId());
+
+    // Now check content in corresponding tables
+    assertCountForTable("SQOOP.SQ_CONNECTOR", 1);
+    assertCountForTable("SQOOP.SQ_FORM", 6);
+    assertCountForTable("SQOOP.SQ_INPUT", 12);
+
+    // Registered connector should be easily recovered back
+    MConnector retrieved = handler.findConnector("A", getDerbyConnection());
+    assertNotNull(retrieved);
+    assertEquals(connector, retrieved);
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
index 8b3326d..006ec9c 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestFrameworkHandling.java
@@ -29,102 +29,101 @@ import java.sql.SQLException;
  */
 public class TestFrameworkHandling extends DerbyTestCase {
 
-//  DerbyRepositoryHandler handler;
-//
-//  @Override
-//  public void setUp() throws Exception {
-//    super.setUp();
-//
-//    handler = new DerbyRepositoryHandler();
-//
-//    // We always needs schema for this test case
-//    createSchema();
-//  }
-//
-//  public void testFindFramework() throws Exception {
-//    // On empty repository, no framework should be there
-//    assertNull(handler.findFramework(getDerbyConnection()));
-//
-//    // Load framework into repository
-//    loadConnectorAndFramework();
-//
-//    // Retrieve it
-//    MFramework framework = handler.findFramework(getDerbyConnection());
-//    assertNotNull(framework);
-//
-//    // Get original structure
-//    MFramework original = getFramework();
-//
-//    // And compare them
-//    assertEquals(original, framework);
-//  }
-//
-//  public void testRegisterConnector() throws Exception {
-//    MFramework framework = getFramework();
-//
-//    handler.registerFramework(framework, getDerbyConnection());
-//
-//    // Connector should get persistence ID
-//    assertEquals(1, framework.getPersistenceId());
-//
-//    // Now check content in corresponding tables
-//    assertCountForTable("SQOOP.SQ_CONNECTOR", 0);
-//    assertCountForTable("SQOOP.SQ_FORM", 6);
-//    assertCountForTable("SQOOP.SQ_INPUT", 12);
-//
-//    // Registered framework should be easily recovered back
-//    MFramework retrieved = handler.findFramework(getDerbyConnection());
-//    assertNotNull(retrieved);
-//    assertEquals(framework, retrieved);
-//    assertEquals(framework.getVersion(), retrieved.getVersion());
-//  }
-//
-//  private String getFrameworkVersion() throws Exception {
-//    final String frameworkVersionQuery =
-//      "SELECT SQM_VALUE FROM SQOOP.SQ_SYSTEM WHERE SQM_KEY=?";
-//    String retVal = null;
-//    PreparedStatement preparedStmt = null;
-//    ResultSet resultSet = null;
-//    try {
-//      preparedStmt =
-//        getDerbyConnection().prepareStatement(frameworkVersionQuery);
-//      preparedStmt.setString(1, DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION);
-//      resultSet = preparedStmt.executeQuery();
-//      if(resultSet.next())
-//        retVal = resultSet.getString(1);
-//      return retVal;
-//    } finally {
-//      if(preparedStmt !=null) {
-//        try {
-//          preparedStmt.close();
-//        } catch(SQLException e) {
-//        }
-//      }
-//      if(resultSet != null) {
-//        try {
-//          resultSet.close();
-//        } catch(SQLException e) {
-//        }
-//      }
-//    }
-//  }
-//
-//  public void testFrameworkVersion() throws Exception {
-//    handler.registerFramework(getFramework(), getDerbyConnection());
-//
-//    final String lowerVersion = Integer.toString(
-//      Integer.parseInt(FrameworkManager.CURRENT_FRAMEWORK_VERSION) - 1);
-//    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, getFrameworkVersion());
-//    runQuery("UPDATE SQOOP.SQ_SYSTEM SET SQM_VALUE='" + lowerVersion +
-//      "' WHERE SQM_KEY = '" + DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION + "'");
-//    assertEquals(lowerVersion, getFrameworkVersion());
-//
-//    MFramework framework = getFramework();
-//    handler.updateFramework(framework, getDerbyConnection());
-//
-//    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, framework.getVersion());
-//
-//    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, getFrameworkVersion());
-//  }
+  DerbyRepositoryHandler handler;
 
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+
+    handler = new DerbyRepositoryHandler();
+
+    // We always needs schema for this test case
+    createSchema();
+  }
+
+  public void testFindFramework() throws Exception {
+    // On empty repository, no framework should be there
+    assertNull(handler.findFramework(getDerbyConnection()));
+
+    // Load framework into repository
+    loadConnectorAndFramework();
+
+    // Retrieve it
+    MFramework framework = handler.findFramework(getDerbyConnection());
+    assertNotNull(framework);
+
+    // Get original structure
+    MFramework original = getFramework();
+
+    // And compare them
+    assertEquals(original, framework);
+  }
+
+  public void testRegisterConnector() throws Exception {
+    MFramework framework = getFramework();
+
+    handler.registerFramework(framework, getDerbyConnection());
+
+    // Connector should get persistence ID
+    assertEquals(1, framework.getPersistenceId());
+
+    // Now check content in corresponding tables
+    assertCountForTable("SQOOP.SQ_CONNECTOR", 0);
+    assertCountForTable("SQOOP.SQ_FORM", 4);
+    assertCountForTable("SQOOP.SQ_INPUT", 8);
+
+    // Registered framework should be easily recovered back
+    MFramework retrieved = handler.findFramework(getDerbyConnection());
+    assertNotNull(retrieved);
+    assertEquals(framework, retrieved);
+    assertEquals(framework.getVersion(), retrieved.getVersion());
+  }
+
+  private String getFrameworkVersion() throws Exception {
+    final String frameworkVersionQuery =
+      "SELECT SQM_VALUE FROM SQOOP.SQ_SYSTEM WHERE SQM_KEY=?";
+    String retVal = null;
+    PreparedStatement preparedStmt = null;
+    ResultSet resultSet = null;
+    try {
+      preparedStmt =
+        getDerbyConnection().prepareStatement(frameworkVersionQuery);
+      preparedStmt.setString(1, DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION);
+      resultSet = preparedStmt.executeQuery();
+      if(resultSet.next())
+        retVal = resultSet.getString(1);
+      return retVal;
+    } finally {
+      if(preparedStmt !=null) {
+        try {
+          preparedStmt.close();
+        } catch(SQLException e) {
+        }
+      }
+      if(resultSet != null) {
+        try {
+          resultSet.close();
+        } catch(SQLException e) {
+        }
+      }
+    }
+  }
+
+  public void testFrameworkVersion() throws Exception {
+    handler.registerFramework(getFramework(), getDerbyConnection());
+
+    final String lowerVersion = Integer.toString(
+      Integer.parseInt(FrameworkManager.CURRENT_FRAMEWORK_VERSION) - 1);
+    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, getFrameworkVersion());
+    runQuery("UPDATE SQOOP.SQ_SYSTEM SET SQM_VALUE='" + lowerVersion +
+      "' WHERE SQM_KEY = '" + DerbyRepoConstants.SYSKEY_FRAMEWORK_VERSION + "'");
+    assertEquals(lowerVersion, getFrameworkVersion());
+
+    MFramework framework = getFramework();
+    handler.updateFramework(framework, getDerbyConnection());
+
+    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, framework.getVersion());
+
+    assertEquals(FrameworkManager.CURRENT_FRAMEWORK_VERSION, getFrameworkVersion());
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInputTypes.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInputTypes.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInputTypes.java
index 5d3807d..15f9539 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInputTypes.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInputTypes.java
@@ -40,107 +40,107 @@ import java.util.Map;
  */
 public class TestInputTypes extends DerbyTestCase {
 
-//  DerbyRepositoryHandler handler;
-//
-//  @Override
-//  public void setUp() throws Exception {
-//    super.setUp();
-//
-//    handler = new DerbyRepositoryHandler();
-//
-//    // We always needs schema for this test case
-//    createSchema();
-//  }
-//
-//  /**
-//   * Ensure that metadata with all various data types can be successfully
-//   * serialized into repository and retrieved back.
-//   */
-//  public void testMetadataSerialization() throws Exception {
-//    MConnector connector = getConnector();
-//
-//    // Serialize the connector with all data types into repository
-//    handler.registerConnector(connector, getDerbyConnection());
-//
-//    // Successful serialization should update the ID
-//    assertNotSame(connector.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
-//
-//    // Retrieve registered connector
-//    MConnector retrieved = handler.findConnector(connector.getUniqueName(), getDerbyConnection());
-//    assertNotNull(retrieved);
-//
-//    // Original and retrieved connectors should be the same
-//    assertEquals(connector, retrieved);
-//  }
-//
-//  /**
-//   * Test that serializing actual data is not an issue.
-//   */
-//  public void testDataSerialization() throws Exception {
-//    MConnector connector = getConnector();
-//    MFramework framework = getFramework();
-//
-//    // Register metadata for everything and our new connector
-//    handler.registerConnector(connector, getDerbyConnection());
-//    handler.registerFramework(framework, getDerbyConnection());
-//
-//    // Inserted values
-//    Map<String, String> map = new HashMap<String, String>();
-//    map.put("A", "B");
-//
-//    // Connection object with all various values
-//    MConnection connection = new MConnection(connector.getPersistenceId(), connector.getConnectionForms(), framework.getConnectionForms());
-//    MConnectionForms forms = connection.getConnectorPart();
-//    forms.getStringInput("f.String").setValue("A");
-//    forms.getMapInput("f.Map").setValue(map);
-//    forms.getIntegerInput("f.Integer").setValue(1);
-//    forms.getBooleanInput("f.Boolean").setValue(true);
-//    forms.getEnumInput("f.Enum").setValue("YES");
-//
-//    // Create the connection in repository
-//    handler.createConnection(connection, getDerbyConnection());
-//    assertNotSame(connection.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
-//
-//    // Retrieve created connection
-//    MConnection retrieved = handler.findConnection(connection.getPersistenceId(), getDerbyConnection());
-//    forms = retrieved.getConnectorPart();
-//    assertEquals("A", forms.getStringInput("f.String").getValue());
-//    assertEquals(map, forms.getMapInput("f.Map").getValue());
-//    assertEquals(1, (int)forms.getIntegerInput("f.Integer").getValue());
-//    assertEquals(true, (boolean)forms.getBooleanInput("f.Boolean").getValue());
-//    assertEquals("YES", forms.getEnumInput("f.Enum").getValue());
-//  }
-//
-//  /**
-//   * Overriding parent method to get forms with all supported data types.
-//   *
-//   * @return Forms with all data types
-//   */
-//  @Override
-//  protected List<MForm> getForms() {
-//    List<MForm> forms = new LinkedList<MForm>();
-//
-//    List<MInput<?>> inputs;
-//    MInput input;
-//
-//    inputs = new LinkedList<MInput<?>>();
-//
-//    input = new MStringInput("f.String", false, (short)30);
-//    inputs.add(input);
-//
-//    input = new MMapInput("f.Map", false);
-//    inputs.add(input);
-//
-//    input = new MIntegerInput("f.Integer", false);
-//    inputs.add(input);
-//
-//    input = new MBooleanInput("f.Boolean", false);
-//    inputs.add(input);
-//
-//    input = new MEnumInput("f.Enum", false, new String[] {"YES", "NO"});
-//    inputs.add(input);
-//
-//    forms.add(new MForm("f", inputs));
-//    return forms;
-//  }
+  DerbyRepositoryHandler handler;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+
+    handler = new DerbyRepositoryHandler();
+
+    // We always needs schema for this test case
+    createSchema();
+  }
+
+  /**
+   * Ensure that metadata with all various data types can be successfully
+   * serialized into repository and retrieved back.
+   */
+  public void testMetadataSerialization() throws Exception {
+    MConnector connector = getConnector();
+
+    // Serialize the connector with all data types into repository
+    handler.registerConnector(connector, getDerbyConnection());
+
+    // Successful serialization should update the ID
+    assertNotSame(connector.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
+
+    // Retrieve registered connector
+    MConnector retrieved = handler.findConnector(connector.getUniqueName(), getDerbyConnection());
+    assertNotNull(retrieved);
+
+    // Original and retrieved connectors should be the same
+    assertEquals(connector, retrieved);
+  }
+
+  /**
+   * Test that serializing actual data is not an issue.
+   */
+  public void testDataSerialization() throws Exception {
+    MConnector connector = getConnector();
+    MFramework framework = getFramework();
+
+    // Register metadata for everything and our new connector
+    handler.registerConnector(connector, getDerbyConnection());
+    handler.registerFramework(framework, getDerbyConnection());
+
+    // Inserted values
+    Map<String, String> map = new HashMap<String, String>();
+    map.put("A", "B");
+
+    // Connection object with all various values
+    MConnection connection = new MConnection(connector.getPersistenceId(), connector.getConnectionForms(), framework.getConnectionForms());
+    MConnectionForms forms = connection.getConnectorPart();
+    forms.getStringInput("f.String").setValue("A");
+    forms.getMapInput("f.Map").setValue(map);
+    forms.getIntegerInput("f.Integer").setValue(1);
+    forms.getBooleanInput("f.Boolean").setValue(true);
+    forms.getEnumInput("f.Enum").setValue("YES");
+
+    // Create the connection in repository
+    handler.createConnection(connection, getDerbyConnection());
+    assertNotSame(connection.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT);
+
+    // Retrieve created connection
+    MConnection retrieved = handler.findConnection(connection.getPersistenceId(), getDerbyConnection());
+    forms = retrieved.getConnectorPart();
+    assertEquals("A", forms.getStringInput("f.String").getValue());
+    assertEquals(map, forms.getMapInput("f.Map").getValue());
+    assertEquals(1, (int)forms.getIntegerInput("f.Integer").getValue());
+    assertEquals(true, (boolean)forms.getBooleanInput("f.Boolean").getValue());
+    assertEquals("YES", forms.getEnumInput("f.Enum").getValue());
+  }
+
+  /**
+   * Overriding parent method to get forms with all supported data types.
+   *
+   * @return Forms with all data types
+   */
+  @Override
+  protected List<MForm> getForms() {
+    List<MForm> forms = new LinkedList<MForm>();
+
+    List<MInput<?>> inputs;
+    MInput input;
+
+    inputs = new LinkedList<MInput<?>>();
+
+    input = new MStringInput("f.String", false, (short)30);
+    inputs.add(input);
+
+    input = new MMapInput("f.Map", false);
+    inputs.add(input);
+
+    input = new MIntegerInput("f.Integer", false);
+    inputs.add(input);
+
+    input = new MBooleanInput("f.Boolean", false);
+    inputs.add(input);
+
+    input = new MEnumInput("f.Enum", false, new String[] {"YES", "NO"});
+    inputs.add(input);
+
+    forms.add(new MForm("f", inputs));
+    return forms;
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/51a07bc3/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
index 0d93348..913439b 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/TestInternals.java
@@ -17,31 +17,53 @@
  */
 package org.apache.sqoop.repository.derby;
 
+import java.sql.Connection;
+
 /**
  *
  */
 public class TestInternals extends DerbyTestCase {
 
-//  DerbyRepositoryHandler handler;
-//
-//  @Override
-//  public void setUp() throws Exception {
-//    super.setUp();
-//
-//    handler = new DerbyRepositoryHandler();
-//  }
-//
-//  public void testSuitableInternals() throws Exception {
-//    assertFalse(handler.haveSuitableInternals(getDerbyConnection()));
-//    createSchema(); // Test code is building the structures
-//    assertTrue(handler.haveSuitableInternals(getDerbyConnection()));
-//  }
-//
-//  public void testCreateorUpdateInternals() throws Exception {
-//    assertFalse(handler.haveSuitableInternals(getDerbyConnection()));
-//    handler.createOrUpdateInternals(getDerbyConnection());
-//    assertTrue(handler.haveSuitableInternals(getDerbyConnection()));
-//  }
+  DerbyRepositoryHandler handler;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+
+    handler = new TestDerbyRepositoryHandler();
+  }
+
+  public void testSuitableInternals() throws Exception {
+    assertFalse(handler.haveSuitableInternals(getDerbyConnection()));
+    createSchema(); // Test code is building the structures
+    assertTrue(handler.haveSuitableInternals(getDerbyConnection()));
+  }
+
+  public void testCreateorUpdateInternals() throws Exception {
+    assertFalse(handler.haveSuitableInternals(getDerbyConnection()));
+    handler.createOrUpdateInternals(getDerbyConnection());
+    assertTrue(handler.haveSuitableInternals(getDerbyConnection()));
+  }
 
+  public void testUpgradeVersion2ToVersion4() throws Exception {
+    createSchema(2);
+    assertFalse(handler.haveSuitableInternals(getDerbyConnection()));
+    loadConnectorAndFramework(2);
+    loadConnections(2);
+    loadJobs(2);
+    handler.createOrUpdateInternals(getDerbyConnection());
+    assertTrue(handler.haveSuitableInternals(getDerbyConnection()));
+  }
 
+  private class TestDerbyRepositoryHandler extends DerbyRepositoryHandler {
+    protected long registerHdfsConnector(Connection conn) {
+      try {
+        runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS, SQC_VERSION)"
+            + "VALUES('hdfs-connector', 'org.apache.sqoop.test.B', '1.0-test')");
+        return 2L;
+      } catch(Exception e) {
+        return -1L;
+      }
+    }
+  }
 }