sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [28/50] [abbrv] git commit: SQOOP-1544: Sqoop2: From/To: ConnectorBean should work support different directions
Date Fri, 10 Oct 2014 03:07:20 GMT
SQOOP-1544: Sqoop2: From/To: ConnectorBean should work support different directions

(Abraham Elmahrek via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/35a060e0
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/35a060e0
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/35a060e0

Branch: refs/heads/sqoop2
Commit: 35a060e04852c65603223fbb4dc78a18e5c54793
Parents: 2c20d92
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Fri Sep 26 08:03:58 2014 -0700
Committer: Abraham Elmahrek <abraham@elmahrek.com>
Committed: Thu Oct 9 17:59:24 2014 -0700

----------------------------------------------------------------------
 .../org/apache/sqoop/json/ConnectorBean.java    | 31 +++++++----
 .../apache/sqoop/json/TestConnectorBean.java    | 58 ++++++++++++++++++++
 .../java/org/apache/sqoop/json/TestUtil.java    | 14 ++++-
 3 files changed, 92 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/35a060e0/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java b/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java
index 465dd69..d726a14 100644
--- a/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java
@@ -86,10 +86,15 @@ public class ConnectorBean implements JsonBean {
 
       object.put(CON_FORMS, extractForms(connector.getConnectionForms().getForms(), skipSensitive));
       object.put(JOB_FORMS, new JSONObject());
-      ((JSONObject)object.get(JOB_FORMS)).put(
-          Direction.FROM, extractForms(connector.getJobForms(Direction.FROM).getForms(),
skipSensitive));
-      ((JSONObject)object.get(JOB_FORMS)).put(
-          Direction.TO, extractForms(connector.getJobForms(Direction.TO).getForms(), skipSensitive));
+      if (connector.getJobForms(Direction.FROM) != null) {
+        ((JSONObject)object.get(JOB_FORMS)).put(
+            Direction.FROM, extractForms(connector.getJobForms(Direction.FROM).getForms(),
skipSensitive));
+      }
+
+      if (connector.getJobForms(Direction.TO) != null) {
+        ((JSONObject)object.get(JOB_FORMS)).put(
+            Direction.TO, extractForms(connector.getJobForms(Direction.TO).getForms(), skipSensitive));
+      }
       array.add(object);
     }
 
@@ -124,17 +129,23 @@ public class ConnectorBean implements JsonBean {
       String className = (String) object.get(CLASS);
       String version = (String) object.get(VERSION);
 
+      MJobForms fromJob = null;
+      MJobForms toJob = null;
       List<MForm> connForms = restoreForms((JSONArray) object.get(CON_FORMS));
       JSONObject jobJson = (JSONObject) object.get(JOB_FORMS);
       JSONArray fromJobJson = (JSONArray)jobJson.get(Direction.FROM.name());
       JSONArray toJobJson = (JSONArray)jobJson.get(Direction.TO.name());
-      List<MForm> fromJobForms = restoreForms(fromJobJson);
-      List<MForm> toJobForms = restoreForms(toJobJson);
-      MJobForms fromJob = new MJobForms(fromJobForms);
-      MJobForms toJob = new MJobForms(toJobForms);
+      if (fromJobJson != null) {
+        List<MForm> fromJobForms = restoreForms(fromJobJson);
+        fromJob = new MJobForms(fromJobForms);
+      }
+      if (toJobJson != null) {
+        List<MForm> toJobForms = restoreForms(toJobJson);
+        toJob = new MJobForms(toJobForms);
+      }
       MConnectionForms connection = new MConnectionForms(connForms);
-      MConnector connector = new MConnector(uniqueName, className, version, connection, fromJob,
-          toJob);
+      MConnector connector = new MConnector(uniqueName, className, version,
+          connection, fromJob, toJob);
       connector.setPersistenceId(connectorId);
       connectors.add(connector);
     }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/35a060e0/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java b/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java
index e078474..c3aa84f 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestConnectorBean.java
@@ -73,4 +73,62 @@ public class TestConnectorBean {
     assertEquals("a", retrievedBundle.getString("a"));
     assertEquals("b", retrievedBundle.getString("b"));
   }
+
+  @Test
+  public void testSingleDirection() {
+    // Create testing connector
+    List<MConnector> connectors = new LinkedList<MConnector>();
+    connectors.add(getConnector("jdbc", true, false));
+    connectors.add(getConnector("mysql", false, true));
+
+    // Create testing bundles
+    Map<Long, ResourceBundle> bundles = new HashMap<Long, ResourceBundle>();
+    bundles.put(1L, getResourceBundle());
+    bundles.put(2L, getResourceBundle());
+
+    // Serialize it to JSON object
+    ConnectorBean bean = new ConnectorBean(connectors, bundles);
+    JSONObject json = bean.extract(false);
+
+    // "Move" it across network in text form
+    String string = json.toJSONString();
+
+    // Retrieved transferred object
+    JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
+    ConnectorBean retrievedBean = new ConnectorBean();
+    retrievedBean.restore(retrievedJson);
+
+    assertEquals(connectors.size(), retrievedBean.getConnectors().size());
+    assertEquals(connectors.get(0), retrievedBean.getConnectors().get(0));
+    assertEquals(connectors.get(1), retrievedBean.getConnectors().get(1));
+  }
+
+  @Test
+  public void testNoDirection() {
+    // Create testing connector
+    List<MConnector> connectors = new LinkedList<MConnector>();
+    connectors.add(getConnector("jdbc", false, false));
+    connectors.add(getConnector("mysql", false, false));
+
+    // Create testing bundles
+    Map<Long, ResourceBundle> bundles = new HashMap<Long, ResourceBundle>();
+    bundles.put(1L, getResourceBundle());
+    bundles.put(2L, getResourceBundle());
+
+    // Serialize it to JSON object
+    ConnectorBean bean = new ConnectorBean(connectors, bundles);
+    JSONObject json = bean.extract(false);
+
+    // "Move" it across network in text form
+    String string = json.toJSONString();
+
+    // Retrieved transferred object
+    JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
+    ConnectorBean retrievedBean = new ConnectorBean();
+    retrievedBean.restore(retrievedJson);
+
+    assertEquals(connectors.size(), retrievedBean.getConnectors().size());
+    assertEquals(connectors.get(0), retrievedBean.getConnectors().get(0));
+    assertEquals(connectors.get(1), retrievedBean.getConnectors().get(1));
+  }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/35a060e0/common/src/test/java/org/apache/sqoop/json/TestUtil.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestUtil.java b/common/src/test/java/org/apache/sqoop/json/TestUtil.java
index eaf9122..9875219 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestUtil.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestUtil.java
@@ -40,8 +40,20 @@ import java.util.ResourceBundle;
  */
 public class TestUtil {
   public static MConnector getConnector(String name) {
+    return getConnector(name, true, true);
+  }
+
+  public static MConnector getConnector(String name, boolean from, boolean to) {
+    MJobForms fromJobForms = null;
+    MJobForms toJobForms = null;
+    if (from) {
+      fromJobForms = getJobForms();
+    }
+    if (to) {
+      toJobForms = getJobForms();
+    }
     return new MConnector(name, name + ".class", "1.0-test",
-      getConnectionForms(), getJobForms(), getJobForms());
+      getConnectionForms(), fromJobForms, toJobForms);
   }
 
   public static MDriverConfig getDriverConfig() {


Mime
View raw message