5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-19 02:10:54 +08:00

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

(Abraham Elmahrek via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2015-03-03 10:28:38 -08:00
parent 934a009762
commit 36663eb399
2 changed files with 55 additions and 1 deletions

View File

@ -149,7 +149,9 @@ static MConfig restoreConfig(JSONObject config) {
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;

View File

@ -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.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 void testMapDataTypeException() {
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;