sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject sqoop git commit: SQOOP-2162: Sqoop2: InputEditable should be optional in JSON API
Date Tue, 03 Mar 2015 18:29:16 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 934a00976 -> 36663eb39


SQOOP-2162: Sqoop2: InputEditable should be optional in JSON API

(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/36663eb3
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/36663eb3
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/36663eb3

Branch: refs/heads/sqoop2
Commit: 36663eb399e54dd978987fb8fc0bd422269f3c12
Parents: 934a009
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Tue Mar 3 10:28:38 2015 -0800
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Tue Mar 3 10:28:38 2015 -0800

----------------------------------------------------------------------
 .../json/util/ConfigInputSerialization.java     |  4 +-
 .../json/util/TestConfigSerialization.java      | 52 ++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/36663eb3/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
b/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
index ffaf041..1b1ec28 100644
--- a/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
+++ b/common/src/main/java/org/apache/sqoop/json/util/ConfigInputSerialization.java
@@ -149,7 +149,9 @@ public final class ConfigInputSerialization {
           MInputType.valueOf((String) input.get(ConfigInputConstants.CONFIG_INPUT_TYPE));
       String name = (String) input.get(ConfigInputConstants.CONFIG_INPUT_NAME);
       Boolean sensitive = (Boolean) input.get(ConfigInputConstants.CONFIG_INPUT_SENSITIVE);
-      InputEditable editable =  InputEditable.valueOf((String)input.get(ConfigInputConstants.CONFIG_INPUT_EDITABLE));
+      InputEditable editable =  (input.containsKey(ConfigInputConstants.CONFIG_INPUT_EDITABLE))
?
+          InputEditable.valueOf((String)input.get(ConfigInputConstants.CONFIG_INPUT_EDITABLE))
+              : InputEditable.USER_ONLY;
       String overrides = (String) input.get(ConfigInputConstants.CONFIG_INPUT_OVERRIDES);
 
       MInput mInput = null;

http://git-wip-us.apache.org/repos/asf/sqoop/blob/36663eb3/common/src/test/java/org/apache/sqoop/json/util/TestConfigSerialization.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/util/TestConfigSerialization.java
b/common/src/test/java/org/apache/sqoop/json/util/TestConfigSerialization.java
index f7f45f9..368502f 100644
--- a/common/src/test/java/org/apache/sqoop/json/util/TestConfigSerialization.java
+++ b/common/src/test/java/org/apache/sqoop/json/util/TestConfigSerialization.java
@@ -17,6 +17,7 @@
  */
 package org.apache.sqoop.json.util;
 
+import static org.testng.Assert.assertFalse;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.Assert.assertNotNull;
 
@@ -38,6 +39,7 @@ import org.apache.sqoop.model.MIntegerInput;
 import org.apache.sqoop.model.MLongInput;
 import org.apache.sqoop.model.MMapInput;
 import org.apache.sqoop.model.MStringInput;
+import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.testng.annotations.Test;
 
@@ -118,6 +120,56 @@ public class TestConfigSerialization {
     ConfigInputSerialization.restoreConfig(retrievedJson);
   }
 
+  @Test
+  public void testInputEditableOptional() {
+    // Inserted values
+    Map<String, String> map = new HashMap<String, String>();
+    map.put("A", "B");
+
+    // Fill config with all values
+    MConfig config = getConfig();
+    config.getStringInput("String").setValue("A");
+    config.getMapInput("Map").setValue(map);
+    config.getIntegerInput("Integer").setValue(1);
+    config.getBooleanInput("Boolean").setValue(true);
+    config.getEnumInput("Enum").setValue("YES");
+
+    // Serialize that into JSON
+    JSONObject jsonObject = ConfigInputSerialization.extractConfig(config, MConfigType.JOB,
 false);
+    assertNotNull(jsonObject);
+
+    // Make sure editable is optional
+    // Remove the editable
+    JSONArray inputs = (JSONArray) jsonObject.get(ConfigInputConstants.CONFIG_INPUTS);
+    for (int i = 0; i < inputs.size(); i++) {
+      JSONObject input = (JSONObject) inputs.get(i);
+      if ((input.containsKey(ConfigInputConstants.CONFIG_INPUT_EDITABLE))) {
+        input.remove(ConfigInputConstants.CONFIG_INPUT_EDITABLE);
+      }
+    }
+
+    // Exchange the data on string level
+    String serializedJson = jsonObject.toJSONString();
+    JSONObject retrievedJson = JSONUtils.parse(serializedJson);
+
+    // Make sure editable isn't part of the JSON
+    inputs = (JSONArray) retrievedJson.get(ConfigInputConstants.CONFIG_INPUTS);
+    for (int i = 0; i < inputs.size(); i++) {
+      JSONObject input = (JSONObject) inputs.get(i);
+      assertFalse(input.containsKey(ConfigInputConstants.CONFIG_INPUT_EDITABLE));
+    }
+
+    // And retrieve back from JSON representation
+    MConfig retrieved = ConfigInputSerialization.restoreConfig(retrievedJson);
+
+    // Verify all expected values
+    assertEquals("A", retrieved.getStringInput("String").getValue());
+    assertEquals(map, retrieved.getMapInput("Map").getValue());
+    assertEquals(1, (int)retrieved.getIntegerInput("Integer").getValue());
+    assertEquals(true, retrieved.getBooleanInput("Boolean").getValue().booleanValue());
+    assertEquals("YES", retrieved.getEnumInput("Enum").getValue());
+  }
+
   protected MConfig getMapConfig() {
     List<MInput<?>> inputs;
     MInput input;


Mime
View raw message