mirror of
https://github.com/apache/sqoop.git
synced 2025-05-12 23:11:43 +08:00
SQOOP-2234: Sqoop2: Move DatasetURIValidator to Kite package as it's not generally usable validator
(Jarek Jarcec Cecho via Abraham Elmahrek)
This commit is contained in:
parent
9e8636981f
commit
251471ffb8
@ -20,7 +20,7 @@
|
|||||||
import org.apache.sqoop.model.ConfigClass;
|
import org.apache.sqoop.model.ConfigClass;
|
||||||
import org.apache.sqoop.model.Input;
|
import org.apache.sqoop.model.Input;
|
||||||
import org.apache.sqoop.model.Validator;
|
import org.apache.sqoop.model.Validator;
|
||||||
import org.apache.sqoop.validation.validators.DatasetURIValidator;
|
import org.apache.sqoop.connector.kite.validators.DatasetURIValidator;
|
||||||
|
|
||||||
@ConfigClass
|
@ConfigClass
|
||||||
public class FromJobConfig {
|
public class FromJobConfig {
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
import org.apache.sqoop.model.ConfigClass;
|
import org.apache.sqoop.model.ConfigClass;
|
||||||
import org.apache.sqoop.model.Input;
|
import org.apache.sqoop.model.Input;
|
||||||
import org.apache.sqoop.model.Validator;
|
import org.apache.sqoop.model.Validator;
|
||||||
import org.apache.sqoop.validation.validators.DatasetURIValidator;
|
import org.apache.sqoop.connector.kite.validators.DatasetURIValidator;
|
||||||
import org.apache.sqoop.validation.validators.NotNull;
|
import org.apache.sqoop.validation.validators.NotNull;
|
||||||
|
|
||||||
@ConfigClass
|
@ConfigClass
|
||||||
|
@ -15,12 +15,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.apache.sqoop.validation.validators;
|
package org.apache.sqoop.connector.kite.validators;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import org.apache.sqoop.classification.InterfaceAudience;
|
import org.apache.sqoop.classification.InterfaceAudience;
|
||||||
import org.apache.sqoop.classification.InterfaceStability;
|
import org.apache.sqoop.classification.InterfaceStability;
|
||||||
import org.apache.sqoop.validation.Status;
|
import org.apache.sqoop.validation.Status;
|
||||||
|
import org.apache.sqoop.validation.validators.AbstractValidator;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -31,8 +32,7 @@
|
|||||||
@InterfaceStability.Unstable
|
@InterfaceStability.Unstable
|
||||||
public class DatasetURIValidator extends AbstractValidator<String> {
|
public class DatasetURIValidator extends AbstractValidator<String> {
|
||||||
|
|
||||||
private static final Pattern DATASET_URI_PATTERN = Pattern
|
private static final Pattern DATASET_URI_PATTERN = Pattern.compile("^dataset:(hive|hdfs|file):.*$");
|
||||||
.compile("^dataset:(hive|hdfs|file):.*$");
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(String uri) {
|
public void validate(String uri) {
|
@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* 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.connector.kite.validators;
|
||||||
|
|
||||||
|
import org.apache.sqoop.validation.Status;
|
||||||
|
import org.apache.sqoop.validation.validators.AbstractValidator;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public class TestDatasetURIValidator {
|
||||||
|
|
||||||
|
AbstractValidator validator = new DatasetURIValidator();
|
||||||
|
|
||||||
|
@BeforeMethod(alwaysRun = true)
|
||||||
|
public void resetValidator() {
|
||||||
|
validator.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNull() {
|
||||||
|
validator.validate(null);
|
||||||
|
assertEquals(validator.getStatus(), Status.ERROR);
|
||||||
|
assertEquals(validator.getMessages().size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEmpty() {
|
||||||
|
validator.validate("");
|
||||||
|
assertEquals(validator.getStatus(), Status.ERROR);
|
||||||
|
assertEquals(validator.getMessages().size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRandomString() {
|
||||||
|
validator.validate("!@#$%");
|
||||||
|
assertEquals(validator.getStatus(), Status.ERROR);
|
||||||
|
assertEquals(validator.getMessages().size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHdfsDataset() {
|
||||||
|
validator.validate("dataset:hive:");
|
||||||
|
assertEquals(validator.getStatus(), Status.OK);
|
||||||
|
assertEquals(validator.getMessages().size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHiveDataset() {
|
||||||
|
validator.validate("dataset:hive:");
|
||||||
|
assertEquals(validator.getStatus(), Status.OK);
|
||||||
|
assertEquals(validator.getMessages().size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFileDataset() {
|
||||||
|
validator.validate("dataset:file:");
|
||||||
|
assertEquals(validator.getStatus(), Status.OK);
|
||||||
|
assertEquals(validator.getMessages().size(), 0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user