mirror of
https://github.com/apache/sqoop.git
synced 2025-05-21 11:21:39 +08:00
SQOOP-1544: Sqoop2: From/To: ConnectorBean should work support different directions
(Abraham Elmahrek via Jarek Jarcec Cecho)
This commit is contained in:
parent
2c20d920f4
commit
35a060e048
@ -86,10 +86,15 @@ public JSONObject extract(boolean skipSensitive) {
|
||||
|
||||
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 void restore(JSONObject jsonObject) {
|
||||
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);
|
||||
}
|
||||
|
@ -73,4 +73,62 @@ public void testSerialization() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,20 @@
|
||||
*/
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user