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/03 08:53:24 UTC
[10/13] SQOOP-1498: Sqoop2: Repository Object refactoring (objects
prefixed with M)
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/json/TestDriverConfigBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestDriverConfigBean.java b/common/src/test/java/org/apache/sqoop/json/TestDriverConfigBean.java
deleted file mode 100644
index fcce7b5..0000000
--- a/common/src/test/java/org/apache/sqoop/json/TestDriverConfigBean.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.json;
-
-import org.apache.sqoop.model.MDriverConfig;
-import org.json.simple.JSONObject;
-import org.json.simple.JSONValue;
-import org.junit.Test;
-
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.json.TestUtil.*;
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class TestDriverConfigBean {
-
- /**
- * Test that by JSON serialization followed by deserialization we will get
- * equal framework object.
- */
- @Test
- public void testSerialization() {
- MDriverConfig driverConfig = getDriverConfig();
-
- // Serialize it to JSON object
- DriverConfigBean bean = new DriverConfigBean(driverConfig, getResourceBundle());
- 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);
- DriverConfigBean retrievedBean = new DriverConfigBean();
- retrievedBean.restore(retrievedJson);
-
- assertEquals(driverConfig, retrievedBean.getDriverConfig());
-
- ResourceBundle retrievedBundle = retrievedBean.getResourceBundle();
- assertEquals("a", retrievedBundle.getString("a"));
- assertEquals("b", retrievedBundle.getString("b"));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/json/TestJobBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestJobBean.java b/common/src/test/java/org/apache/sqoop/json/TestJobBean.java
index 78a3420..1fc8dbd 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestJobBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestJobBean.java
@@ -17,6 +17,11 @@
*/
package org.apache.sqoop.json;
+import static org.apache.sqoop.json.ConfigTestUtil.getJob;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Date;
+
import org.apache.sqoop.common.Direction;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MStringInput;
@@ -25,11 +30,6 @@ import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import org.junit.Test;
-import java.util.Date;
-
-import static org.apache.sqoop.json.TestUtil.getJob;
-import static org.junit.Assert.assertEquals;
-
/**
*
*/
@@ -46,25 +46,25 @@ public class TestJobBean {
job.setEnabled(false);
// Fill some data at the beginning
- MStringInput input = (MStringInput) job.getConnectorPart(Direction.FROM)
- .getForms().get(0).getInputs().get(0);
+ MStringInput input = (MStringInput) job.getJobConfig(Direction.FROM)
+ .getConfigs().get(0).getInputs().get(0);
input.setValue("Hi there!");
- input = (MStringInput) job.getConnectorPart(Direction.TO)
- .getForms().get(0).getInputs().get(0);
+ input = (MStringInput) job.getJobConfig(Direction.TO)
+ .getConfigs().get(0).getInputs().get(0);
input.setValue("Hi there again!");
// Serialize it to JSON object
- JobBean bean = new JobBean(job);
- JSONObject json = bean.extract(false);
+ JobBean jobBean = new JobBean(job);
+ JSONObject jobJson = jobBean.extract(false);
// "Move" it across network in text form
- String string = json.toJSONString();
+ String jobJsonString = jobJson.toJSONString();
// Retrieved transferred object
- JSONObject retrievedJson = (JSONObject)JSONValue.parseWithException(string);
- JobBean retrievedBean = new JobBean();
- retrievedBean.restore(retrievedJson);
- MJob target = retrievedBean.getJobs().get(0);
+ JSONObject parsedJobJson = (JSONObject)JSONValue.parseWithException(jobJsonString);
+ JobBean parsedJobBean = new JobBean();
+ parsedJobBean.restore(parsedJobJson);
+ MJob target = parsedJobBean.getJobs().get(0);
// Check id and name
assertEquals(666, target.getPersistenceId());
@@ -78,11 +78,11 @@ public class TestJobBean {
assertEquals(false, target.getEnabled());
// Test that value was correctly moved
- MStringInput targetInput = (MStringInput) target.getConnectorPart(Direction.FROM)
- .getForms().get(0).getInputs().get(0);
+ MStringInput targetInput = (MStringInput) target.getJobConfig(Direction.FROM)
+ .getConfigs().get(0).getInputs().get(0);
assertEquals("Hi there!", targetInput.getValue());
- targetInput = (MStringInput) target.getConnectorPart(Direction.TO)
- .getForms().get(0).getInputs().get(0);
+ targetInput = (MStringInput) target.getJobConfig(Direction.TO)
+ .getConfigs().get(0).getInputs().get(0);
assertEquals("Hi there again!", targetInput.getValue());
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java b/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java
index 9ca6b64..ac07137 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java
@@ -17,19 +17,21 @@
*/
package org.apache.sqoop.json;
+import static org.apache.sqoop.json.ConfigTestUtil.getLink;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+
+import org.apache.sqoop.json.util.ConfigSerialization;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MStringInput;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
-import org.json.simple.JSONArray;
import org.json.simple.JSONValue;
import org.junit.Test;
-import java.util.Date;
-
-import static org.junit.Assert.*;
-import static org.apache.sqoop.json.TestUtil.*;
-
/**
*
*/
@@ -48,31 +50,31 @@ public class TestLinkBean {
link.setEnabled(false);
// Fill some data at the beginning
- MStringInput input = (MStringInput) link.getConnectorPart().getForms()
+ MStringInput input = (MStringInput) link.getConnectorLinkConfig().getConfigs()
.get(0).getInputs().get(0);
input.setValue("Hi there!");
// Serialize it to JSON object
- LinkBean bean = new LinkBean(link);
- JSONObject json = bean.extract(false);
+ LinkBean linkBean = new LinkBean(link);
+ JSONObject json = linkBean.extract(false);
// Check for sensitivity
- JSONArray all = (JSONArray)json.get("all");
+ JSONArray all = (JSONArray)json.get(ConfigSerialization.ALL);
JSONObject allItem = (JSONObject)all.get(0);
- JSONArray connectors = (JSONArray)allItem.get("connector");
+ JSONArray connectors = (JSONArray)allItem.get(LinkBean.LINK_CONFIG);
JSONObject connector = (JSONObject)connectors.get(0);
- JSONArray inputs = (JSONArray)connector.get("inputs");
+ JSONArray inputs = (JSONArray)connector.get(ConfigSerialization.CONFIG_INPUTS);
for (Object input1 : inputs) {
- assertTrue(((JSONObject)input1).containsKey("sensitive"));
+ assertTrue(((JSONObject)input1).containsKey(ConfigSerialization.CONFIG_INPUT_SENSITIVE));
}
// "Move" it across network in text form
- String string = json.toJSONString();
+ String linkJsonString = json.toJSONString();
// Retrieved transferred object
- JSONObject retrievedJson = (JSONObject) JSONValue.parse(string);
+ JSONObject parsedLinkJson = (JSONObject) JSONValue.parse(linkJsonString);
LinkBean retrievedBean = new LinkBean();
- retrievedBean.restore(retrievedJson);
+ retrievedBean.restore(parsedLinkJson);
MLink target = retrievedBean.getLinks().get(0);
// Check id and name
@@ -85,8 +87,8 @@ public class TestLinkBean {
assertEquals(false, target.getEnabled());
// Test that value was correctly moved
- MStringInput targetInput = (MStringInput) target.getConnectorPart()
- .getForms().get(0).getInputs().get(0);
+ MStringInput targetInput = (MStringInput) target.getConnectorLinkConfig()
+ .getConfigs().get(0).getInputs().get(0);
assertEquals("Hi there!", targetInput.getValue());
}
@@ -104,7 +106,7 @@ public class TestLinkBean {
link.setEnabled(true);
// Fill some data at the beginning
- MStringInput input = (MStringInput) link.getConnectorPart().getForms()
+ MStringInput input = (MStringInput) link.getConnectorLinkConfig().getConfigs()
.get(0).getInputs().get(0);
input.setValue("Hi there!");
@@ -114,25 +116,25 @@ public class TestLinkBean {
JSONObject jsonFiltered = bean.extract(true);
// Sensitive values should exist
- JSONArray all = (JSONArray)json.get("all");
+ JSONArray all = (JSONArray)json.get(ConfigSerialization.ALL);
JSONObject allItem = (JSONObject)all.get(0);
- JSONArray connectors = (JSONArray)allItem.get("connector");
+ JSONArray connectors = (JSONArray)allItem.get(LinkBean.LINK_CONFIG);
JSONObject connector = (JSONObject)connectors.get(0);
- JSONArray inputs = (JSONArray)connector.get("inputs");
+ JSONArray inputs = (JSONArray)connector.get(ConfigSerialization.CONFIG_INPUTS);
assertEquals(3, inputs.size());
// Inputs are ordered when creating link
JSONObject password = (JSONObject)inputs.get(2);
- assertTrue(password.containsKey("value"));
+ assertTrue(password.containsKey(ConfigSerialization.CONFIG_INPUT_VALUE));
// Sensitive values should not exist
- all = (JSONArray)jsonFiltered.get("all");
+ all = (JSONArray)jsonFiltered.get(ConfigSerialization.ALL);
allItem = (JSONObject)all.get(0);
- connectors = (JSONArray)allItem.get("connector");
+ connectors = (JSONArray)allItem.get(LinkBean.LINK_CONFIG);
connector = (JSONObject)connectors.get(0);
- inputs = (JSONArray)connector.get("inputs");
+ inputs = (JSONArray)connector.get(ConfigSerialization.CONFIG_INPUTS);
assertEquals(3, inputs.size());
// Inputs are ordered when creating link
password = (JSONObject)inputs.get(2);
- assertFalse(password.containsKey("value"));
+ assertFalse(password.containsKey(ConfigSerialization.CONFIG_INPUT_VALUE));
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/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
deleted file mode 100644
index 9875219..0000000
--- a/common/src/test/java/org/apache/sqoop/json/TestUtil.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.json;
-
-import org.apache.sqoop.common.Direction;
-import org.apache.sqoop.model.MLink;
-import org.apache.sqoop.model.MConnectionForms;
-import org.apache.sqoop.model.MConnector;
-import org.apache.sqoop.model.MForm;
-import org.apache.sqoop.model.MDriverConfig;
-import org.apache.sqoop.model.MInput;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.model.MJobForms;
-import org.apache.sqoop.model.MStringInput;
-import org.apache.sqoop.utils.MapResourceBundle;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-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(), fromJobForms, toJobForms);
- }
-
- public static MDriverConfig getDriverConfig() {
- return new MDriverConfig(getConnectionForms(), getJobForms(), "1");
- }
-
- public static MLink getLink(String name) {
- return new MLink(1, getConnector(name).getConnectionForms(), getDriverConfig()
- .getConnectionForms());
- }
-
- public static MJob getJob(String name) {
- return new MJob(1, 2, 1, 2, getConnector(name).getJobForms(Direction.FROM), getConnector(name)
- .getJobForms(Direction.TO), getDriverConfig().getJobForms());
- }
-
- public static MConnectionForms getConnectionForms() {
- List<MInput<?>> inputs;
- MStringInput input;
- MForm form;
- List<MForm> connectionForms = new ArrayList<MForm>();
- inputs = new ArrayList<MInput<?>>();
-
- input = new MStringInput("url", false, (short) 10);
- input.setPersistenceId(1);
- inputs.add(input);
-
- input = new MStringInput("username", false, (short) 10);
- input.setPersistenceId(2);
- input.setValue("test");
- inputs.add(input);
-
- input = new MStringInput("password", true, (short) 10);
- input.setPersistenceId(3);
- input.setValue("test");
- inputs.add(input);
-
- form = new MForm("connection", inputs);
- form.setPersistenceId(10);
- connectionForms.add(form);
-
- return new MConnectionForms(connectionForms);
- }
-
- public static MJobForms getJobForms() {
- List<MInput<?>> inputs;
- MStringInput input;
- MForm form;
- List<MForm> jobForms = new ArrayList<MForm>();
-
- inputs = new ArrayList<MInput<?>>();
-
- input = new MStringInput("A", false, (short) 10);
- input.setPersistenceId(4);
- inputs.add(input);
-
- input = new MStringInput("B", false, (short) 10);
- input.setPersistenceId(5);
- inputs.add(input);
-
- input = new MStringInput("C", false, (short) 10);
- input.setPersistenceId(6);
- inputs.add(input);
-
- form = new MForm("Z", inputs);
- form.setPersistenceId(11);
- jobForms.add(form);
-
- inputs = new ArrayList<MInput<?>>();
-
- input = new MStringInput("D", false, (short) 10);
- input.setPersistenceId(7);
- inputs.add(input);
-
- input = new MStringInput("E", false, (short) 10);
- input.setPersistenceId(8);
- inputs.add(input);
-
- input = new MStringInput("F", false, (short) 10);
- input.setPersistenceId(9);
- inputs.add(input);
-
- form = new MForm("connection", inputs);
- form.setPersistenceId(12);
- jobForms.add(form);
-
- return new MJobForms(jobForms);
- }
-
- public static ResourceBundle getResourceBundle() {
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("a", "a");
- map.put("b", "b");
-
- return new MapResourceBundle(map);
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java b/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java
index f5f3389..fc5b21d 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestValidationBean.java
@@ -17,18 +17,20 @@
*/
package org.apache.sqoop.json;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.sqoop.common.Direction;
+import org.apache.sqoop.validation.ConfigValidator;
import org.apache.sqoop.validation.Status;
-import org.apache.sqoop.validation.Validation;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
/**
*
*/
@@ -44,7 +46,7 @@ public class TestValidationBean {
);
JSONObject json = bean.extract(false);
- // "Move" it across network in text form
+ // "Move" it across network in text config
String string = json.toJSONString();
// Retrieved transferred object
@@ -54,43 +56,43 @@ public class TestValidationBean {
assertNull(retrievedBean.getId());
- Validation.FormInput fa = new Validation.FormInput("f", "i");
- Validation.FormInput fb = new Validation.FormInput("f2", "i2");
+ ConfigValidator.ConfigInput fa = new ConfigValidator.ConfigInput("c", "i");
+ ConfigValidator.ConfigInput fb = new ConfigValidator.ConfigInput("c2", "i2");
- Validation fromConnector = retrievedBean.getConnectorValidation(Direction.FROM);
+ ConfigValidator fromConnector = retrievedBean.getConnectorValidation(Direction.FROM);
assertEquals(Status.FINE, fromConnector.getStatus());
assertEquals(2, fromConnector.getMessages().size());
assertTrue(fromConnector.getMessages().containsKey(fa));
- assertEquals(new Validation.Message(Status.FINE, "d"),
+ assertEquals(new ConfigValidator.Message(Status.FINE, "d"),
fromConnector.getMessages().get(fa));
- Validation toConnector = retrievedBean.getConnectorValidation(Direction.TO);
+ ConfigValidator toConnector = retrievedBean.getConnectorValidation(Direction.TO);
assertEquals(Status.FINE, toConnector.getStatus());
assertEquals(2, toConnector.getMessages().size());
assertTrue(toConnector.getMessages().containsKey(fa));
- assertEquals(new Validation.Message(Status.FINE, "d"),
+ assertEquals(new ConfigValidator.Message(Status.FINE, "d"),
toConnector.getMessages().get(fa));
- Validation framework = retrievedBean.getFrameworkValidation();
+ ConfigValidator framework = retrievedBean.getFrameworkValidation();
assertEquals(Status.UNACCEPTABLE, framework.getStatus());
assertEquals(2, framework.getMessages().size());
assertTrue(framework.getMessages().containsKey(fb));
- assertEquals(new Validation.Message(Status.UNACCEPTABLE, "c"),
+ assertEquals(new ConfigValidator.Message(Status.UNACCEPTABLE, "c"),
framework.getMessages().get(fb));
}
@Test
public void testJobValidationBeanId() {
// Serialize it to JSON object
- JobValidationBean bean = new JobValidationBean(
+ JobValidationBean jobValidatioBean = new JobValidationBean(
getValidation(Status.FINE),
getValidation(Status.FINE),
getValidation(Status.FINE)
);
- bean.setId((long) 10);
- JSONObject json = bean.extract(false);
+ jobValidatioBean.setId((long) 10);
+ JSONObject json = jobValidatioBean.extract(false);
- // "Move" it across network in text form
+ // "Move" it across network in text config
String string = json.toJSONString();
// Retrieved transferred object
@@ -105,12 +107,10 @@ public class TestValidationBean {
public void testLinkValidationBeanSerialization() {
// Serialize it to JSON object
LinkValidationBean bean = new LinkValidationBean(
- getValidation(Status.FINE),
- getValidation(Status.UNACCEPTABLE)
- );
+ getValidation(Status.FINE));
JSONObject json = bean.extract(false);
- // "Move" it across network in text form
+ // "Move" it across network in text config
String string = json.toJSONString();
// Retrieved transferred object
@@ -120,35 +120,25 @@ public class TestValidationBean {
assertNull(retrievedBean.getId());
- Validation.FormInput fa = new Validation.FormInput("f", "i");
- Validation.FormInput fb = new Validation.FormInput("f2", "i2");
-
- Validation connector = retrievedBean.getConnectorValidation();
+ ConfigValidator.ConfigInput ca = new ConfigValidator.ConfigInput("c", "i");
+ ConfigValidator connector = retrievedBean.getLinkConfigValidator();
assertEquals(Status.FINE, connector.getStatus());
assertEquals(2, connector.getMessages().size());
- assertTrue(connector.getMessages().containsKey(fa));
- assertEquals(new Validation.Message(Status.FINE, "d"),
- connector.getMessages().get(fa));
-
- Validation framework = retrievedBean.getFrameworkValidation();
- assertEquals(Status.UNACCEPTABLE, framework.getStatus());
- assertEquals(2, framework.getMessages().size());
- assertTrue(framework.getMessages().containsKey(fb));
- assertEquals(new Validation.Message(Status.UNACCEPTABLE, "c"),
- framework.getMessages().get(fb));
+ assertTrue(connector.getMessages().containsKey(ca));
+ assertEquals(new ConfigValidator.Message(Status.FINE, "d"),
+ connector.getMessages().get(ca));
}
@Test
public void testLinkValidationBeanId() {
// Serialize it to JSON object
LinkValidationBean bean = new LinkValidationBean(
- getValidation(Status.FINE),
getValidation(Status.FINE)
);
bean.setId((long) 10);
JSONObject json = bean.extract(false);
- // "Move" it across network in text form
+ // "Move" it across network in text config
String string = json.toJSONString();
// Retrieved transferred object
@@ -159,17 +149,12 @@ public class TestValidationBean {
assertEquals((Long)(long) 10, retrievedBean.getId());
}
- public Validation getValidation(Status status) {
- Map<Validation.FormInput, Validation.Message> messages =
- new HashMap<Validation.FormInput, Validation.Message>();
+ public ConfigValidator getValidation(Status status) {
+ Map<ConfigValidator.ConfigInput, ConfigValidator.Message> messages = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>();
- messages.put(
- new Validation.FormInput("f", "i"),
- new Validation.Message(status, "d"));
- messages.put(
- new Validation.FormInput("f2", "i2"),
- new Validation.Message(status, "c"));
+ messages.put(new ConfigValidator.ConfigInput("c", "i"), new ConfigValidator.Message(status, "d"));
+ messages.put(new ConfigValidator.ConfigInput("c2", "i2"), new ConfigValidator.Message(status, "c"));
- return new Validation(status, messages);
+ return new ConfigValidator(status, messages);
}
}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/json/TestValidationResultBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestValidationResultBean.java b/common/src/test/java/org/apache/sqoop/json/TestValidationResultBean.java
index 5c094fb..bdbad72 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestValidationResultBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestValidationResultBean.java
@@ -19,7 +19,7 @@ package org.apache.sqoop.json;
import org.apache.sqoop.validation.Message;
import org.apache.sqoop.validation.Status;
-import org.apache.sqoop.validation.ValidationResult;
+import org.apache.sqoop.validation.ConfigValidationResult;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.junit.Test;
@@ -39,31 +39,31 @@ public class TestValidationResultBean {
@Test
public void testEmptyTransfer() {
- ValidationResult []empty = new ValidationResult[0];
+ ConfigValidationResult []empty = new ConfigValidationResult[0];
- ValidationResult []retrieved = transfer(empty);
+ ConfigValidationResult []retrieved = transfer(empty);
assertEquals(0, retrieved.length);
}
@Test
public void testOneMessage() {
- ValidationResult []empty = new ValidationResult[] {
+ ConfigValidationResult []empty = new ConfigValidationResult[] {
getResultA()
};
- ValidationResult []retrieved = transfer(empty);
+ ConfigValidationResult []retrieved = transfer(empty);
assertEquals(1, retrieved.length);
verifyResultA(retrieved[0]);
}
@Test
public void testTwoMessages() {
- ValidationResult []empty = new ValidationResult[] {
+ ConfigValidationResult []empty = new ConfigValidationResult[] {
getResultA(),
getResultA()
};
- ValidationResult []retrieved = transfer(empty);
+ ConfigValidationResult []retrieved = transfer(empty);
assertEquals(2, retrieved.length);
verifyResultA(retrieved[0]);
@@ -79,7 +79,7 @@ public class TestValidationResultBean {
assertNull(idNull);
}
- public void verifyResultA(ValidationResult result) {
+ public void verifyResultA(ConfigValidationResult result) {
assertNotNull(result);
assertEquals(Status.UNACCEPTABLE, result.getStatus());
@@ -98,8 +98,8 @@ public class TestValidationResultBean {
assertEquals("B", messagesA.get(1).getMessage());
}
- public ValidationResult getResultA() {
- ValidationResult result = new ValidationResult();
+ public ConfigValidationResult getResultA() {
+ ConfigValidationResult result = new ConfigValidationResult();
List<Message> messages = new LinkedList<Message>();
messages.add(new Message(Status.ACCEPTABLE, "A"));
messages.add(new Message(Status.UNACCEPTABLE, "B"));
@@ -109,7 +109,7 @@ public class TestValidationResultBean {
private Long transfer(Long id) {
- ValidationResultBean bean = new ValidationResultBean(new ValidationResult[0]);
+ ValidationResultBean bean = new ValidationResultBean(new ConfigValidationResult[0]);
bean.setId(id);
JSONObject json = bean.extract(false);
@@ -122,7 +122,7 @@ public class TestValidationResultBean {
return retrievedBean.getId();
}
- private ValidationResult[] transfer(ValidationResult [] results) {
+ private ConfigValidationResult[] transfer(ConfigValidationResult [] results) {
ValidationResultBean bean = new ValidationResultBean(results);
JSONObject json = bean.extract(false);
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/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
new file mode 100644
index 0000000..4f0c84d
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/json/util/TestConfigSerialization.java
@@ -0,0 +1,157 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.json.util;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MBooleanInput;
+import org.apache.sqoop.model.MEnumInput;
+import org.apache.sqoop.model.MConfig;
+import org.apache.sqoop.model.MInput;
+import org.apache.sqoop.model.MIntegerInput;
+import org.apache.sqoop.model.MMapInput;
+import org.apache.sqoop.model.MStringInput;
+import org.json.simple.JSONObject;
+import org.json.simple.JSONValue;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ *
+ */
+public class TestConfigSerialization {
+
+ @Test
+ public void testAllDataTypes() {
+ // 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 = ConfigSerialization.extractConfig(config, false);
+ assertNotNull(jsonObject);
+
+ // Exchange the data on string level
+ String serializedJson = jsonObject.toJSONString();
+ JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson);
+
+ // And retrieve back from JSON representation
+ MConfig retrieved = ConfigSerialization.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());
+ assertEquals("YES", retrieved.getEnumInput("Enum").getValue());
+ }
+
+ @Test
+ public void testMapDataType() {
+ MConfig config = getMapConfig();
+
+ // Inserted values
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("A", "B");
+ config.getMapInput("Map").setValue(map);
+
+ // Serialize
+ JSONObject jsonObject = ConfigSerialization.extractConfig(config, false);
+ String serializedJson = jsonObject.toJSONString();
+
+ // Deserialize
+ JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson);
+ MConfig retrieved = ConfigSerialization.restoreConfig(retrievedJson);
+ assertEquals(map, retrieved.getMapInput("Map").getValue());
+ }
+
+ @Test(expected=SqoopException.class)
+ public void testMapDataTypeException() {
+ MConfig config = getMapConfig();
+
+ // Inserted values
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("A", "B");
+ config.getMapInput("Map").setValue(map);
+
+ // Serialize
+ JSONObject jsonObject = ConfigSerialization.extractConfig(config, false);
+ String serializedJson = jsonObject.toJSONString();
+
+ // Replace map value with a fake string to force exception
+ String badSerializedJson = serializedJson.replace("{\"A\":\"B\"}", "\"nonsensical string\"");
+ System.out.println(badSerializedJson);
+ JSONObject retrievedJson = (JSONObject) JSONValue.parse(badSerializedJson);
+ ConfigSerialization.restoreConfig(retrievedJson);
+ }
+
+ protected MConfig getMapConfig() {
+ List<MInput<?>> inputs;
+ MInput input;
+
+ inputs = new LinkedList<MInput<?>>();
+
+ input = new MMapInput("Map", false);
+ inputs.add(input);
+
+ return new MConfig("c", inputs);
+ }
+
+ /**
+ * Return config with all data types.
+ *
+ * @return
+ */
+ protected MConfig getConfig() {
+ List<MInput<?>> inputs;
+ MInput input;
+
+ inputs = new LinkedList<MInput<?>>();
+
+ input = new MStringInput("String", false, (short)30);
+ inputs.add(input);
+
+ input = new MMapInput("Map", false);
+ inputs.add(input);
+
+ input = new MIntegerInput("Integer", false);
+ inputs.add(input);
+
+ input = new MBooleanInput("Boolean", false);
+ inputs.add(input);
+
+ input = new MEnumInput("Enum", false, new String[] {"YES", "NO"});
+ inputs.add(input);
+
+ return new MConfig("c", inputs);
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/json/util/TestFormSerialization.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/util/TestFormSerialization.java b/common/src/test/java/org/apache/sqoop/json/util/TestFormSerialization.java
deleted file mode 100644
index c4223ec..0000000
--- a/common/src/test/java/org/apache/sqoop/json/util/TestFormSerialization.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.json.util;
-
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.model.MBooleanInput;
-import org.apache.sqoop.model.MEnumInput;
-import org.apache.sqoop.model.MForm;
-import org.apache.sqoop.model.MInput;
-import org.apache.sqoop.model.MIntegerInput;
-import org.apache.sqoop.model.MMapInput;
-import org.apache.sqoop.model.MStringInput;
-import org.json.simple.JSONObject;
-import org.json.simple.JSONValue;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-/**
- *
- */
-public class TestFormSerialization {
-
- @Test
- public void testAllDataTypes() {
- // Inserted values
- Map<String, String> map = new HashMap<String, String>();
- map.put("A", "B");
-
- // Fill form with all values
- MForm form = getForm();
- form.getStringInput("String").setValue("A");
- form.getMapInput("Map").setValue(map);
- form.getIntegerInput("Integer").setValue(1);
- form.getBooleanInput("Boolean").setValue(true);
- form.getEnumInput("Enum").setValue("YES");
-
- // Serialize that into JSON
- JSONObject jsonObject = FormSerialization.extractForm(form, false);
- assertNotNull(jsonObject);
-
- // Exchange the data on string level
- String serializedJson = jsonObject.toJSONString();
- JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson);
-
- // And retrieve back from JSON representation
- MForm retrieved = FormSerialization.restoreForm(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());
- assertEquals("YES", retrieved.getEnumInput("Enum").getValue());
- }
-
- @Test
- public void testMapDataType() {
- MForm form = getMapForm();
-
- // Inserted values
- Map<String, String> map = new HashMap<String, String>();
- map.put("A", "B");
- form.getMapInput("Map").setValue(map);
-
- // Serialize
- JSONObject jsonObject = FormSerialization.extractForm(form, false);
- String serializedJson = jsonObject.toJSONString();
-
- // Deserialize
- JSONObject retrievedJson = (JSONObject) JSONValue.parse(serializedJson);
- MForm retrieved = FormSerialization.restoreForm(retrievedJson);
- assertEquals(map, retrieved.getMapInput("Map").getValue());
- }
-
- @Test(expected=SqoopException.class)
- public void testMapDataTypeException() {
- MForm form = getMapForm();
-
- // Inserted values
- Map<String, String> map = new HashMap<String, String>();
- map.put("A", "B");
- form.getMapInput("Map").setValue(map);
-
- // Serialize
- JSONObject jsonObject = FormSerialization.extractForm(form, false);
- String serializedJson = jsonObject.toJSONString();
-
- // Replace map value with a fake string to force exception
- String badSerializedJson = serializedJson.replace("{\"A\":\"B\"}", "\"nonsensical string\"");
- System.out.println(badSerializedJson);
- JSONObject retrievedJson = (JSONObject) JSONValue.parse(badSerializedJson);
- FormSerialization.restoreForm(retrievedJson);
- }
-
- protected MForm getMapForm() {
- List<MInput<?>> inputs;
- MInput input;
-
- inputs = new LinkedList<MInput<?>>();
-
- input = new MMapInput("Map", false);
- inputs.add(input);
-
- return new MForm("f", inputs);
- }
-
- /**
- * Return form with all data types.
- *
- * @return
- */
- protected MForm getForm() {
- List<MInput<?>> inputs;
- MInput input;
-
- inputs = new LinkedList<MInput<?>>();
-
- input = new MStringInput("String", false, (short)30);
- inputs.add(input);
-
- input = new MMapInput("Map", false);
- inputs.add(input);
-
- input = new MIntegerInput("Integer", false);
- inputs.add(input);
-
- input = new MBooleanInput("Boolean", false);
- inputs.add(input);
-
- input = new MEnumInput("Enum", false, new String[] {"YES", "NO"});
- inputs.add(input);
-
- return new MForm("f", inputs);
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java b/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java
new file mode 100644
index 0000000..9d7cd4b
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/model/TestConfigUtils.java
@@ -0,0 +1,217 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.model;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.sqoop.common.SqoopException;
+
+/**
+ * Test config utils
+ */
+public class TestConfigUtils extends TestCase {
+
+ public void testConfigs() {
+ TestConfiguration config = new TestConfiguration();
+ config.aConfig.a1 = "value";
+
+ List<MConfig> configsByInstance = ConfigUtils.toConfigs(config);
+ assertEquals(getConfigs(), configsByInstance);
+ assertEquals("value", configsByInstance.get(0).getInputs().get(0).getValue());
+
+ List<MConfig> configsByClass = ConfigUtils.toConfigs(TestConfiguration.class);
+ assertEquals(getConfigs(), configsByClass);
+
+ List<MConfig> configsByBoth = ConfigUtils.toConfigs(TestConfiguration.class, config);
+ assertEquals(getConfigs(), configsByBoth);
+ assertEquals("value", configsByBoth.get(0).getInputs().get(0).getValue());
+ }
+
+ public void testConfigsMissingAnnotation() {
+ try {
+ ConfigUtils.toConfigs(ConfigWithout.class);
+ } catch(SqoopException ex) {
+ assertEquals(ModelError.MODEL_003, ex.getErrorCode());
+ return;
+ }
+
+ fail("Correct exception wasn't thrown");
+ }
+
+ public void testFailureOnPrimitiveType() {
+ PrimitiveConfig config = new PrimitiveConfig();
+
+ try {
+ ConfigUtils.toConfigs(config);
+ fail("We were expecting exception for unsupported type.");
+ } catch(SqoopException ex) {
+ assertEquals(ModelError.MODEL_007, ex.getErrorCode());
+ }
+ }
+
+ public void testFillValues() {
+ List<MConfig> configs = getConfigs();
+
+ ((MStringInput)configs.get(0).getInputs().get(0)).setValue("value");
+
+ TestConfiguration config = new TestConfiguration();
+
+ ConfigUtils.fromConfigs(configs, config);
+ assertEquals("value", config.aConfig.a1);
+ }
+
+ public void testFillValuesObjectReuse() {
+ List<MConfig> configs = getConfigs();
+
+ ((MStringInput)configs.get(0).getInputs().get(0)).setValue("value");
+
+ TestConfiguration config = new TestConfiguration();
+ config.aConfig.a2 = "x";
+ config.bConfig.b1 = "y";
+
+ ConfigUtils.fromConfigs(configs, config);
+ assertEquals("value", config.aConfig.a1);
+ assertNull(config.aConfig.a2);
+ assertNull(config.bConfig.b2);
+ assertNull(config.bConfig.b2);
+ }
+
+ public void testJson() {
+ TestConfiguration config = new TestConfiguration();
+ config.aConfig.a1 = "A";
+ config.bConfig.b2 = "B";
+ config.cConfig.intValue = 4;
+ config.cConfig.map.put("C", "D");
+ config.cConfig.enumeration = Enumeration.X;
+
+ String json = ConfigUtils.toJson(config);
+
+ TestConfiguration targetConfig = new TestConfiguration();
+
+ // Old values from should be always removed
+ targetConfig.aConfig.a2 = "X";
+ targetConfig.bConfig.b1 = "Y";
+ // Nulls in configs shouldn't be an issue either
+ targetConfig.cConfig = null;
+
+ ConfigUtils.fillValues(json, targetConfig);
+
+ assertEquals("A", targetConfig.aConfig.a1);
+ assertNull(targetConfig.aConfig.a2);
+
+ assertNull(targetConfig.bConfig.b1);
+ assertEquals("B", targetConfig.bConfig.b2);
+
+ assertEquals((Integer)4, targetConfig.cConfig.intValue);
+ assertEquals(1, targetConfig.cConfig.map.size());
+ assertTrue(targetConfig.cConfig.map.containsKey("C"));
+ assertEquals("D", targetConfig.cConfig.map.get("C"));
+ assertEquals(Enumeration.X, targetConfig.cConfig.enumeration);
+ }
+
+ /**
+ * Config structure that corresponds to Config class declared below
+ * @return Config structure
+ */
+ protected List<MConfig> getConfigs() {
+ List<MConfig> ret = new LinkedList<MConfig>();
+
+ List<MInput<?>> inputs;
+
+ // Config A
+ inputs = new LinkedList<MInput<?>>();
+ inputs.add(new MStringInput("aConfig.a1", false, (short)30));
+ inputs.add(new MStringInput("aConfig.a2", true, (short)-1));
+ ret.add(new MConfig("aConfig", inputs));
+
+ // Config B
+ inputs = new LinkedList<MInput<?>>();
+ inputs.add(new MStringInput("bConfig.b1", false, (short)2));
+ inputs.add(new MStringInput("bConfig.b2", false, (short)3));
+ ret.add(new MConfig("bConfig", inputs));
+
+ // Config C
+ inputs = new LinkedList<MInput<?>>();
+ inputs.add(new MIntegerInput("cConfig.intValue", false));
+ inputs.add(new MMapInput("cConfig.map", false));
+ inputs.add(new MEnumInput("cConfig.enumeration", false, new String[]{"X", "Y"}));
+ ret.add(new MConfig("cConfig", inputs));
+
+ return ret;
+ }
+
+ @ConfigurationClass
+ public static class TestConfiguration {
+
+ public TestConfiguration() {
+ aConfig = new AConfig();
+ bConfig = new BConfig();
+ cConfig = new CConfig();
+ }
+
+ @Config AConfig aConfig;
+ @Config BConfig bConfig;
+ @Config CConfig cConfig;
+ }
+
+ @ConfigurationClass
+ public static class PrimitiveConfig {
+ @Config DConfig dConfig;
+ }
+
+ @ConfigClass
+ public static class AConfig {
+ @Input(size = 30) String a1;
+ @Input(sensitive = true) String a2;
+ }
+
+ @ConfigClass
+ public static class BConfig {
+ @Input(size = 2) String b1;
+ @Input(size = 3) String b2;
+ }
+
+ @ConfigClass
+ public static class CConfig {
+ @Input Integer intValue;
+ @Input Map<String, String> map;
+ @Input Enumeration enumeration;
+
+ public CConfig() {
+ map = new HashMap<String, String>();
+ }
+ }
+
+ @ConfigClass
+ public static class DConfig {
+ @Input int value;
+ }
+
+ public static class ConfigWithout {
+ }
+
+ enum Enumeration {
+ X,
+ Y,
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java b/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java
deleted file mode 100644
index 18c9692..0000000
--- a/common/src/test/java/org/apache/sqoop/model/TestFormUtils.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.model;
-
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.validation.Status;
-import org.apache.sqoop.validation.Validation;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-/**
- * Test form utils
- */
-public class TestFormUtils {
-
- @Test
- public void testToForms() {
- Config config = new Config();
- config.aForm.a1 = "value";
-
- List<MForm> formsByInstance = FormUtils.toForms(config);
- assertEquals(getForms(), formsByInstance);
- assertEquals("value", formsByInstance.get(0).getInputs().get(0).getValue());
-
- List<MForm> formsByClass = FormUtils.toForms(Config.class);
- assertEquals(getForms(), formsByClass);
-
- List<MForm> formsByBoth = FormUtils.toForms(Config.class, config);
- assertEquals(getForms(), formsByBoth);
- assertEquals("value", formsByBoth.get(0).getInputs().get(0).getValue());
- }
-
- @Test
- public void testToFormsMissingAnnotation() {
- try {
- FormUtils.toForms(ConfigWithout.class);
- } catch(SqoopException ex) {
- assertEquals(ModelError.MODEL_003, ex.getErrorCode());
- return;
- }
-
- fail("Correct exception wasn't thrown");
- }
-
- @Test
- public void testFailureOnPrimitiveType() {
- PrimitiveConfig config = new PrimitiveConfig();
-
- try {
- FormUtils.toForms(config);
- fail("We were expecting exception for unsupported type.");
- } catch(SqoopException ex) {
- assertEquals(ModelError.MODEL_007, ex.getErrorCode());
- }
- }
-
- @Test
- public void testFillValues() {
- List<MForm> forms = getForms();
-
- ((MStringInput)forms.get(0).getInputs().get(0)).setValue("value");
-
- Config config = new Config();
-
- FormUtils.fromForms(forms, config);
- assertEquals("value", config.aForm.a1);
- }
-
- @Test
- public void testFillValuesObjectReuse() {
- List<MForm> forms = getForms();
-
- ((MStringInput)forms.get(0).getInputs().get(0)).setValue("value");
-
- Config config = new Config();
- config.aForm.a2 = "x";
- config.bForm.b1 = "y";
-
- FormUtils.fromForms(forms, config);
- assertEquals("value", config.aForm.a1);
- assertNull(config.aForm.a2);
- assertNull(config.bForm.b2);
- assertNull(config.bForm.b2);
- }
-
- @Test
- public void testJson() {
- Config config = new Config();
- config.aForm.a1 = "A";
- config.bForm.b2 = "B";
- config.cForm.intValue = 4;
- config.cForm.map.put("C", "D");
- config.cForm.enumeration = Enumeration.X;
-
- String json = FormUtils.toJson(config);
-
- Config targetConfig = new Config();
-
- // Old values from should be always removed
- targetConfig.aForm.a2 = "X";
- targetConfig.bForm.b1 = "Y";
- // Nulls in forms shouldn't be an issue either
- targetConfig.cForm = null;
-
- FormUtils.fillValues(json, targetConfig);
-
- assertEquals("A", targetConfig.aForm.a1);
- assertNull(targetConfig.aForm.a2);
-
- assertNull(targetConfig.bForm.b1);
- assertEquals("B", targetConfig.bForm.b2);
-
- assertEquals((Integer)4, targetConfig.cForm.intValue);
- assertEquals(1, targetConfig.cForm.map.size());
- assertTrue(targetConfig.cForm.map.containsKey("C"));
- assertEquals("D", targetConfig.cForm.map.get("C"));
- assertEquals(Enumeration.X, targetConfig.cForm.enumeration);
- }
-
- /**
- * Form structure that corresponds to Config class declared below
- * @return Form structure
- */
- protected List<MForm> getForms() {
- List<MForm> ret = new LinkedList<MForm>();
-
- List<MInput<?>> inputs;
-
- // Form A
- inputs = new LinkedList<MInput<?>>();
- inputs.add(new MStringInput("aForm.a1", false, (short)30));
- inputs.add(new MStringInput("aForm.a2", true, (short)-1));
- ret.add(new MForm("aForm", inputs));
-
- // Form B
- inputs = new LinkedList<MInput<?>>();
- inputs.add(new MStringInput("bForm.b1", false, (short)2));
- inputs.add(new MStringInput("bForm.b2", false, (short)3));
- ret.add(new MForm("bForm", inputs));
-
- // Form C
- inputs = new LinkedList<MInput<?>>();
- inputs.add(new MIntegerInput("cForm.intValue", false));
- inputs.add(new MMapInput("cForm.map", false));
- inputs.add(new MEnumInput("cForm.enumeration", false, new String[]{"X", "Y"}));
- ret.add(new MForm("cForm", inputs));
-
- return ret;
- }
-
- @ConfigurationClass
- public static class Config {
-
- public Config() {
- aForm = new AForm();
- bForm = new BForm();
- cForm = new CForm();
- }
-
- @Form AForm aForm;
- @Form BForm bForm;
- @Form CForm cForm;
- }
-
- @ConfigurationClass
- public static class PrimitiveConfig {
- @Form DForm dForm;
- }
-
- @FormClass
- public static class AForm {
- @Input(size = 30) String a1;
- @Input(sensitive = true) String a2;
- }
-
- @FormClass
- public static class BForm {
- @Input(size = 2) String b1;
- @Input(size = 3) String b2;
- }
-
- @FormClass
- public static class CForm {
- @Input Integer intValue;
- @Input Map<String, String> map;
- @Input Enumeration enumeration;
-
- public CForm() {
- map = new HashMap<String, String>();
- }
- }
-
- @FormClass
- public static class DForm {
- @Input int value;
- }
-
- public static class ConfigWithout {
- }
-
- enum Enumeration {
- X,
- Y,
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java b/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java
index af0f450..ba53739 100644
--- a/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java
+++ b/common/src/test/java/org/apache/sqoop/model/TestMAccountableEntity.java
@@ -35,14 +35,13 @@ public class TestMAccountableEntity {
*/
@Test
public void testInitialization() {
- List<MForm> forms = new ArrayList<MForm>();
+ List<MConfig> configs = new ArrayList<MConfig>();
MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false);
List<MInput<?>> list = new ArrayList<MInput<?>>();
list.add(input);
- MForm form = new MForm("FORMNAME", list);
- forms.add(form);
- MAccountableEntity link = new MLink(123l, new MConnectionForms(
- forms), new MConnectionForms(forms));
+ MConfig config = new MConfig("CONFIGNAME", list);
+ configs.add(config);
+ MAccountableEntity link = new MLink(123l, new MLinkConfig(configs));
// Initially creation date and last update date is same
assertEquals(link.getCreationDate(), link.getLastUpdateDate());
Date testCreationDate = new Date();
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMConfig.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMConfig.java b/common/src/test/java/org/apache/sqoop/model/TestMConfig.java
new file mode 100644
index 0000000..c5a07a0
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/model/TestMConfig.java
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TestMConfig {
+
+ /**
+ * Test for initialization
+ */
+ @Test
+ public void testInitialization() {
+ MInput<String> input1 = new MStringInput("sqoopsqoop1", true, (short) 5);
+ MInput<String> input2 = new MStringInput("sqoopsqoop2", true, (short) 5);
+
+ List<MInput<?>> list = new ArrayList<MInput<?>>();
+ list.add(input1);
+ list.add(input2);
+ MConfig mConfig = new MConfig("config", list);
+
+ assertEquals("config", mConfig.getName());
+ assertEquals(2, mConfig.getInputs().size());
+ }
+
+ /**
+ * Test for equals method
+ */
+ @Test
+ public void testEquals() {
+ MInput<Integer> input1 = new MIntegerInput("sqoopsqoop1", false);
+ MInput<Integer> input2 = new MIntegerInput("sqoopsqoop2", false);
+ List<MInput<?>> list1 = new ArrayList<MInput<?>>();
+ list1.add(input1);
+ list1.add(input2);
+ MConfig mform1 = new MConfig("config", list1);
+
+ MInput<Integer> input3 = new MIntegerInput("sqoopsqoop1", false);
+ MInput<Integer> input4 = new MIntegerInput("sqoopsqoop2", false);
+ List<MInput<?>> list2 = new ArrayList<MInput<?>>();
+ list2.add(input3);
+ list2.add(input4);
+ MConfig mform2 = new MConfig("config", list2);
+ assertEquals(mform2, mform1);
+ }
+
+ @Test
+ public void testGetInputs() {
+ MIntegerInput intInput = new MIntegerInput("Config.A", false);
+ MMapInput mapInput = new MMapInput("Config.B", false);
+ MStringInput stringInput = new MStringInput("Config.C", false, (short)3);
+ MEnumInput enumInput = new MEnumInput("Config.D", false, new String[] {"I", "V"});
+
+ List<MInput<?>> inputs = new ArrayList<MInput<?>>();
+ inputs.add(intInput);
+ inputs.add(mapInput);
+ inputs.add(stringInput);
+ inputs.add(enumInput);
+
+ MConfig config = new MConfig("Config", inputs);
+ assertEquals(intInput, config.getIntegerInput("Config.A"));
+ assertEquals(mapInput, config.getMapInput("Config.B"));
+ assertEquals(stringInput, config.getStringInput("Config.C"));
+ assertEquals(enumInput, config.getEnumInput("Config.D"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMConfigList.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMConfigList.java b/common/src/test/java/org/apache/sqoop/model/TestMConfigList.java
new file mode 100644
index 0000000..9b60055
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/model/TestMConfigList.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.model;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestMConfigList {
+ @Test
+ public void testGetInputs() {
+ List<MConfig> configs = new LinkedList<MConfig>();
+
+ MIntegerInput intInput = new MIntegerInput("Config1.A", false);
+ MMapInput mapInput = new MMapInput("Config1.B", false);
+
+ List<MInput<?>> inputs = new ArrayList<MInput<?>>();
+ inputs.add(intInput);
+ inputs.add(mapInput);
+ configs.add(new MConfig("Config1", inputs));
+
+ MStringInput stringInput = new MStringInput("Config2.C", false, (short)3);
+ MEnumInput enumInput = new MEnumInput("Config2.D", false, new String[] {"I", "V"});
+
+ inputs = new ArrayList<MInput<?>>();
+ inputs.add(stringInput);
+ inputs.add(enumInput);
+ configs.add(new MConfig("Config2", inputs));
+
+ MConfigList config = new MConfigList(configs);
+ assertEquals(intInput, config.getIntegerInput("Config1.A"));
+ assertEquals(mapInput, config.getMapInput("Config1.B"));
+ assertEquals(stringInput, config.getStringInput("Config2.C"));
+ assertEquals(enumInput, config.getEnumInput("Config2.D"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMConnectionForms.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMConnectionForms.java b/common/src/test/java/org/apache/sqoop/model/TestMConnectionForms.java
deleted file mode 100644
index 243fff9..0000000
--- a/common/src/test/java/org/apache/sqoop/model/TestMConnectionForms.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test class for org.apache.sqoop.model.MConnectionForms
- */
-public class TestMConnectionForms {
-
- /**
- * Test for class initialization and values
- */
- @Test
- public void testInitialization() {
- List<MForm> forms = new ArrayList<MForm>();
- MConnectionForms connectionForms1 = new MConnectionForms(forms);
- List<MForm> testForms = new ArrayList<MForm>();
- assertEquals(testForms, connectionForms1.getForms());
- MConnectionForms connectionForms2 = new MConnectionForms(testForms);
- assertEquals(connectionForms2, connectionForms1);
- // Add a form to list for checking not equals
- MForm m = new MForm("test", null);
- testForms.add(m);
- assertFalse(connectionForms1.equals(connectionForms2));
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMConnector.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMConnector.java b/common/src/test/java/org/apache/sqoop/model/TestMConnector.java
index d8bc94d..89ae440 100644
--- a/common/src/test/java/org/apache/sqoop/model/TestMConnector.java
+++ b/common/src/test/java/org/apache/sqoop/model/TestMConnector.java
@@ -17,6 +17,13 @@
*/
package org.apache.sqoop.model;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -24,39 +31,34 @@ import java.util.List;
import org.apache.sqoop.common.Direction;
import org.junit.Test;
-import static org.junit.Assert.*;
-
-/**
- * Test class for org.apache.sqoop.model.TestMConnector
- */
public class TestMConnector {
private MConnector createConnector(List<Direction> supportedDirections) {
- List<MForm> forms = new ArrayList<MForm>();
- MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false);
- input.setValue(100);
+ List<MConfig> configs = new ArrayList<MConfig>();
+ MIntegerInput inputs = new MIntegerInput("INTEGER-INPUT", false);
+ inputs.setValue(100);
MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20);
strInput.setValue("TEST-VALUE");
List<MInput<?>> list = new ArrayList<MInput<?>>();
- list.add(input);
+ list.add(inputs);
list.add(strInput);
- MForm form = new MForm("FORMNAME", list);
- forms.add(form);
+ MConfig config = new MConfig("CONFIGNAME", list);
+ configs.add(config);
- MConnectionForms connectionForms1 = new MConnectionForms(forms);
- MJobForms fromForm = null;
- MJobForms toForm = null;
+ MLinkConfig linkConfig = new MLinkConfig(configs);
+ MFromConfig fromConfig = null;
+ MToConfig toConfig = null;
if (supportedDirections.contains(Direction.FROM)) {
- fromForm = new MJobForms(forms);
+ fromConfig = new MFromConfig(configs);
}
if (supportedDirections.contains(Direction.TO)) {
- toForm = new MJobForms(forms);
+ toConfig = new MToConfig(configs);
}
return new MConnector("NAME", "CLASSNAME", "1.0",
- connectionForms1, fromForm, toForm);
+ linkConfig, fromConfig, toConfig);
}
/**
@@ -64,32 +66,32 @@ public class TestMConnector {
*/
@Test
public void testInitialization() {
- List<MForm> fromJobForms = new ArrayList<MForm>();
- List<MForm> toJobForms = new ArrayList<MForm>();
- MConnectionForms connectionForms1 = new MConnectionForms(fromJobForms);
- MJobForms fromJobForm1 = new MJobForms(fromJobForms);
- MJobForms toJobForm1 = new MJobForms(toJobForms);
+ List<MConfig> fromJobConfig = new ArrayList<MConfig>();
+ List<MConfig> toJobConfig = new ArrayList<MConfig>();
+ MLinkConfig linkConfig = new MLinkConfig(fromJobConfig);
+ MFromConfig fromConfig1 = new MFromConfig(fromJobConfig);
+ MToConfig toConfig1 = new MToConfig(toJobConfig);
MConnector connector1 = new MConnector("NAME", "CLASSNAME", "1.0",
- connectionForms1, fromJobForm1, toJobForm1);
+ linkConfig, fromConfig1, toConfig1);
assertEquals("NAME", connector1.getUniqueName());
assertEquals("CLASSNAME", connector1.getClassName());
assertEquals("1.0", connector1.getVersion());
MConnector connector2 = new MConnector("NAME", "CLASSNAME", "1.0",
- connectionForms1, fromJobForm1, toJobForm1);
+ linkConfig, fromConfig1, toConfig1);
assertEquals(connector2, connector1);
MConnector connector3 = new MConnector("NAME1", "CLASSNAME", "2.0",
- connectionForms1, fromJobForm1, toJobForm1);
+ linkConfig, fromConfig1, toConfig1);
assertFalse(connector1.equals(connector3));
try {
- connector1 = new MConnector(null, "CLASSNAME", "1.0", connectionForms1,
- fromJobForm1, toJobForm1); // Expecting null pointer exception
+ connector1 = new MConnector(null, "CLASSNAME", "1.0", linkConfig,
+ fromConfig1, toConfig1); // Expecting null pointer exception
} catch (NullPointerException e) {
assertTrue(true);
}
try {
- connector1 = new MConnector("NAME", null, "1.0", connectionForms1,
- fromJobForm1, toJobForm1); // Expecting null pointer exception
+ connector1 = new MConnector("NAME", null, "1.0", linkConfig,
+ fromConfig1, toConfig1); // Expecting null pointer exception
} catch (NullPointerException e) {
assertTrue(true);
}
@@ -97,48 +99,48 @@ public class TestMConnector {
@Test
public void testClone() {
- MConnector connector1 = createConnector(Arrays.asList(Direction.FROM, Direction.TO));
- assertEquals("NAME", connector1.getUniqueName());
- assertEquals("CLASSNAME", connector1.getClassName());
- assertEquals("1.0", connector1.getVersion());
- //Clone with values. Checking values copying after the cloning. But form values will be null
- MConnector clone1 = connector1.clone(true);
- assertEquals("NAME", clone1.getUniqueName());
- assertEquals("CLASSNAME", clone1.getClassName());
- assertEquals("1.0", clone1.getVersion());
- MForm clonedForm1 = clone1.getConnectionForms().getForms().get(0);
- assertNull(clonedForm1.getInputs().get(0).getValue());
- assertNull(clonedForm1.getInputs().get(1).getValue());
-
- MForm clonedForm2 = clone1.getJobForms(Direction.FROM).getForms().get(0);
- assertNull(clonedForm2.getInputs().get(0).getValue());
- assertNull(clonedForm2.getInputs().get(1).getValue());
-
- MForm clonedForm3 = clone1.getJobForms(Direction.TO).getForms().get(0);
- assertNull(clonedForm3.getInputs().get(0).getValue());
- assertNull(clonedForm3.getInputs().get(1).getValue());
+ MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO));
+ assertEquals("NAME", connector.getUniqueName());
+ assertEquals("CLASSNAME", connector.getClassName());
+ assertEquals("1.0", connector.getVersion());
+ //Clone with values. Checking values copying after the cloning. But config values will be null
+ MConnector cloneConnector1 = connector.clone(true);
+ assertEquals("NAME", cloneConnector1.getUniqueName());
+ assertEquals("CLASSNAME", cloneConnector1.getClassName());
+ assertEquals("1.0", cloneConnector1.getVersion());
+ MConfig clonedLinkConfig = cloneConnector1.getLinkConfig().getConfigs().get(0);
+ assertNull(clonedLinkConfig.getInputs().get(0).getValue());
+ assertNull(clonedLinkConfig.getInputs().get(1).getValue());
+
+ MConfig clonedFromConfig = cloneConnector1.getConfig(Direction.FROM).getConfigs().get(0);
+ assertNull(clonedFromConfig.getInputs().get(0).getValue());
+ assertNull(clonedFromConfig.getInputs().get(1).getValue());
+
+ MConfig clonedToConfig = cloneConnector1.getConfig(Direction.TO).getConfigs().get(0);
+ assertNull(clonedToConfig.getInputs().get(0).getValue());
+ assertNull(clonedToConfig.getInputs().get(1).getValue());
//Clone without values. Inputs value will be null after cloning.
- MConnector clone2 = connector1.clone(false);
- clonedForm1 = clone2.getConnectionForms().getForms().get(0);
- assertNull(clonedForm1.getInputs().get(0).getValue());
- assertNull(clonedForm1.getInputs().get(1).getValue());
- clonedForm2 = clone2.getJobForms(Direction.FROM).getForms().get(0);
- assertNull(clonedForm2.getInputs().get(0).getValue());
- assertNull(clonedForm2.getInputs().get(1).getValue());
- clonedForm3 = clone2.getJobForms(Direction.TO).getForms().get(0);
- assertNull(clonedForm3.getInputs().get(0).getValue());
- assertNull(clonedForm3.getInputs().get(1).getValue());
+ MConnector clonedConnector2 = connector.clone(false);
+ clonedLinkConfig = clonedConnector2.getLinkConfig().getConfigs().get(0);
+ assertNull(clonedLinkConfig.getInputs().get(0).getValue());
+ assertNull(clonedLinkConfig.getInputs().get(1).getValue());
+ clonedFromConfig = clonedConnector2.getConfig(Direction.FROM).getConfigs().get(0);
+ assertNull(clonedFromConfig.getInputs().get(0).getValue());
+ assertNull(clonedFromConfig.getInputs().get(1).getValue());
+ clonedToConfig = clonedConnector2.getConfig(Direction.TO).getConfigs().get(0);
+ assertNull(clonedToConfig.getInputs().get(0).getValue());
+ assertNull(clonedToConfig.getInputs().get(1).getValue());
}
@Test
public void testFromDirection() {
MConnector connector = createConnector(Arrays.asList(Direction.FROM));
- // Clone should clone only one job form.
+ // Clone should clone only one job config.
MConnector clone = connector.clone(true);
- assertNotNull(clone.getJobForms(Direction.FROM));
- assertNull(clone.getJobForms(Direction.TO));
+ assertNotNull(clone.getFromConfig());
+ assertNull(clone.getToConfig());
assertEquals(connector, clone);
assertEquals(connector.toString(), clone.toString());
assertNotEquals(connector.hashCode(), clone.hashCode());
@@ -148,10 +150,10 @@ public class TestMConnector {
public void testToDirection() {
MConnector connector = createConnector(Arrays.asList(Direction.TO));
- // Clone should clone only one job form.
+ // Clone should clone only one job config.
MConnector clone = connector.clone(true);
- assertNull(clone.getJobForms(Direction.FROM));
- assertNotNull(clone.getJobForms(Direction.TO));
+ assertNull(clone.getFromConfig());
+ assertNotNull(clone.getToConfig());
assertEquals(connector, clone);
assertEquals(connector.toString(), clone.toString());
assertNotEquals(connector.hashCode(), clone.hashCode());
@@ -161,10 +163,10 @@ public class TestMConnector {
public void testNoDirection() {
MConnector connector = createConnector(Arrays.asList(new Direction[0]));
- // Clone should clone only one job form.
+ // Clone should clone only one job config.
MConnector clone = connector.clone(true);
- assertNull(clone.getJobForms(Direction.FROM));
- assertNull(clone.getJobForms(Direction.TO));
+ assertNull(clone.getFromConfig());
+ assertNull(clone.getToConfig());
assertEquals(connector, clone);
assertEquals(connector.toString(), clone.toString());
assertNotEquals(connector.hashCode(), clone.hashCode());
@@ -174,10 +176,10 @@ public class TestMConnector {
public void testBothDirections() {
MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO));
- // Clone should clone only one job form.
+ // Clone should clone only one job config.
MConnector clone = connector.clone(true);
- assertNotNull(clone.getJobForms(Direction.FROM));
- assertNotNull(clone.getJobForms(Direction.TO));
+ assertNotNull(clone.getFromConfig());
+ assertNotNull(clone.getToConfig());
assertEquals(connector, clone);
assertEquals(connector.toString(), clone.toString());
assertNotEquals(connector.hashCode(), clone.hashCode());
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMDriver.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMDriver.java b/common/src/test/java/org/apache/sqoop/model/TestMDriver.java
new file mode 100644
index 0000000..aa1ee34
--- /dev/null
+++ b/common/src/test/java/org/apache/sqoop/model/TestMDriver.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.model;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sqoop.json.DriverBean;
+import org.junit.Test;
+
+public class TestMDriver {
+
+ @Test
+ public void testDriver() {
+ List<MConfig> driverConfig = new ArrayList<MConfig>();
+ driverConfig.add(new MConfig("driver-test", new ArrayList<MInput<?>>()));
+ MDriverConfig mDriverConfig = new MDriverConfig(driverConfig);
+
+ MDriver driver = new MDriver(mDriverConfig, DriverBean.CURRENT_DRIVER_VERSION);
+ assertEquals(1, driver.getDriverConfig().getConfigs().size());
+ assertEquals("driver-test", driver.getDriverConfig().getConfigs().get(0).getName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java b/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java
deleted file mode 100644
index 9c23cc3..0000000
--- a/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.model;
-
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class TestMDriverConfig {
-
- @Test
- public void testForms() {
- List<MForm> connectionFormList = new ArrayList<MForm>();
- List<MForm> jobFormList = new ArrayList<MForm>();
- connectionFormList.add(new MForm("connection-test", new ArrayList<MInput<?>>()));
- jobFormList.add(new MForm("job-test", new ArrayList<MInput<?>>()));
- MConnectionForms connectionForms = new MConnectionForms(connectionFormList);
- MJobForms jobForms = new MJobForms(jobFormList);
-
- MDriverConfig driver = new MDriverConfig(connectionForms, jobForms, "1");
- assertEquals(1, driver.getJobForms().getForms().size());
- assertEquals("job-test", driver.getJobForms().getForms().get(0).getName());
- assertEquals(1, driver.getConnectionForms().getForms().size());
- assertEquals("connection-test", driver.getConnectionForms().getForms().get(0).getName());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMForm.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMForm.java b/common/src/test/java/org/apache/sqoop/model/TestMForm.java
deleted file mode 100644
index 536b650..0000000
--- a/common/src/test/java/org/apache/sqoop/model/TestMForm.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Test class for org.apache.sqoop.model.MForm
- */
-public class TestMForm {
-
- /**
- * Test for initialization
- */
- @Test
- public void testInitialization() {
- MInput<String> input1 = new MStringInput("sqoopsqoop1", true, (short) 5);
- MInput<String> input2 = new MStringInput("sqoopsqoop2", true, (short) 5);
-
- List<MInput<?>> list = new ArrayList<MInput<?>>();
- list.add(input1);
- list.add(input2);
- MForm mform = new MForm("form", list);
-
- assertEquals("form", mform.getName());
- assertEquals(2, mform.getInputs().size());
- }
-
- /**
- * Test for equals method
- */
- @Test
- public void testEquals() {
- MInput<Integer> input1 = new MIntegerInput("sqoopsqoop1", false);
- MInput<Integer> input2 = new MIntegerInput("sqoopsqoop2", false);
- List<MInput<?>> list1 = new ArrayList<MInput<?>>();
- list1.add(input1);
- list1.add(input2);
- MForm mform1 = new MForm("form", list1);
-
- MInput<Integer> input3 = new MIntegerInput("sqoopsqoop1", false);
- MInput<Integer> input4 = new MIntegerInput("sqoopsqoop2", false);
- List<MInput<?>> list2 = new ArrayList<MInput<?>>();
- list2.add(input3);
- list2.add(input4);
- MForm mform2 = new MForm("form", list2);
- assertEquals(mform2, mform1);
- }
-
- @Test
- public void testGetInputs() {
- MIntegerInput intInput = new MIntegerInput("Form.A", false);
- MMapInput mapInput = new MMapInput("Form.B", false);
- MStringInput stringInput = new MStringInput("Form.C", false, (short)3);
- MEnumInput enumInput = new MEnumInput("Form.D", false, new String[] {"I", "V"});
-
- List<MInput<?>> inputs = new ArrayList<MInput<?>>();
- inputs.add(intInput);
- inputs.add(mapInput);
- inputs.add(stringInput);
- inputs.add(enumInput);
-
- MForm form = new MForm("Form", inputs);
- assertEquals(intInput, form.getIntegerInput("Form.A"));
- assertEquals(mapInput, form.getMapInput("Form.B"));
- assertEquals(stringInput, form.getStringInput("Form.C"));
- assertEquals(enumInput, form.getEnumInput("Form.D"));
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/f63c080d/common/src/test/java/org/apache/sqoop/model/TestMFormList.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/model/TestMFormList.java b/common/src/test/java/org/apache/sqoop/model/TestMFormList.java
deleted file mode 100644
index b8d3d37..0000000
--- a/common/src/test/java/org/apache/sqoop/model/TestMFormList.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.sqoop.model;
-
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- *
- */
-public class TestMFormList {
- @Test
- public void testGetInputs() {
- List<MForm> forms = new LinkedList<MForm>();
-
- MIntegerInput intInput = new MIntegerInput("Form1.A", false);
- MMapInput mapInput = new MMapInput("Form1.B", false);
-
- List<MInput<?>> inputs = new ArrayList<MInput<?>>();
- inputs.add(intInput);
- inputs.add(mapInput);
- forms.add(new MForm("Form1", inputs));
-
- MStringInput stringInput = new MStringInput("Form2.C", false, (short)3);
- MEnumInput enumInput = new MEnumInput("Form2.D", false, new String[] {"I", "V"});
-
- inputs = new ArrayList<MInput<?>>();
- inputs.add(stringInput);
- inputs.add(enumInput);
- forms.add(new MForm("Form2", inputs));
-
- MFormList form = new MFormList(forms);
- assertEquals(intInput, form.getIntegerInput("Form1.A"));
- assertEquals(mapInput, form.getMapInput("Form1.B"));
- assertEquals(stringInput, form.getStringInput("Form2.C"));
- assertEquals(enumInput, form.getEnumInput("Form2.D"));
- }
-}