Search in sources :

Example 6 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class FileBatchSourceTest method testDelimitedFormatsInValidSchema.

@Test
public void testDelimitedFormatsInValidSchema() throws Exception {
    FileSourceConfig config = new FileSourceConfig();
    FailureCollector collector = new MockFailureCollector();
    FieldSetter.setField(config, AbstractFileSourceConfig.class.getDeclaredField("referenceName"), "ref");
    FieldSetter.setField(config, AbstractFileSourceConfig.class.getDeclaredField("format"), "delimited");
    FieldSetter.setField(config, AbstractFileSourceConfig.class.getDeclaredField("schema"), RECORD_SCHEMA_INVALID_DATE.toString());
    FieldSetter.setField(config, FileSourceConfig.class.getDeclaredField("path"), "path");
    config.validate(collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    List<ValidationFailure.Cause> failureCauses = collector.getValidationFailures().get(0).getCauses();
    Assert.assertEquals(2, failureCauses.size());
    Assert.assertEquals("format", failureCauses.get(0).getAttribute("stageConfig"));
    Assert.assertEquals("date", failureCauses.get(1).getAttribute("outputField"));
    Assert.assertEquals("Type 'date' in schema is not supported for 'delimited' format.", collector.getValidationFailures().get(0).getMessage());
}
Also used : AbstractFileSourceConfig(io.cdap.plugin.format.plugin.AbstractFileSourceConfig) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) AbstractFileSourceConfig(io.cdap.plugin.format.plugin.AbstractFileSourceConfig) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 7 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class FTPBatchSourceTest method testFTPPathWithSpecialCharactersInAuth.

@Test
public void testFTPPathWithSpecialCharactersInAuth() {
    FailureCollector collector = new MockFailureCollector();
    FTPBatchSource.FTPBatchSourceConfig config = new FTPBatchSource.FTPBatchSourceConfig();
    config.configuration(String.format("%s://%s:%s@%s:%d%s", FTP_PREFIX, USER, PASSWORD_WITH_SPECIAL_CHARACTERS, HOST, FTP_DEFAULT_PORT, PATH), null);
    config.validate(collector);
    final HashMap<String, String> fileSystemProperties = new HashMap<>();
    fileSystemProperties.put("fs.ftp.host", HOST);
    fileSystemProperties.put(String.format("fs.ftp.user.%s", HOST), USER);
    fileSystemProperties.put(String.format("fs.ftp.password.%s", HOST), PASSWORD_WITH_SPECIAL_CHARACTERS);
    fileSystemProperties.put("fs.ftp.host.port", String.valueOf(FTP_DEFAULT_PORT));
    Assert.assertEquals(fileSystemProperties, config.getFileSystemProperties(collector));
}
Also used : HashMap(java.util.HashMap) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 8 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class FTPBatchSourceTest method testSFTPPathWithoutSpecialCharactersInAuth.

@Test
public void testSFTPPathWithoutSpecialCharactersInAuth() {
    FailureCollector collector = new MockFailureCollector();
    FTPBatchSource.FTPBatchSourceConfig config = new FTPBatchSource.FTPBatchSourceConfig();
    config.configuration(String.format("%s://%s:%s@%s:%d%s", SFTP_PREFIX, USER, PASSWORD_WITHOUT_SPECIAL_CHARACTERS, HOST, SFTP_DEFAULT_PORT, PATH), null);
    config.validate(collector);
    Assert.assertEquals(config.getPathFromConfig(), config.getPath());
    Assert.assertEquals(0, config.getFileSystemProperties(collector).size());
}
Also used : MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 9 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class XMLReaderConfigTest method testEmptyTargetFolder.

@Test
public void testEmptyTargetFolder() {
    XMLReaderBatchSource.XMLReaderConfig config = new XMLReaderBatchSource.XMLReaderConfig("emptyTargetFolderReference", "/opt/hdfs/catalog.xml", null, "/catalog/book/", "Move", "", "No", "XMLTrackingTable", 30, "/tmp");
    FailureCollector collector = new MockFailureCollector();
    config.validate(collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(1, collector.getValidationFailures().get(0).getCauses().size());
    Cause expectedCause = new Cause();
    expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, XMLReaderBatchSource.XMLReaderConfig.TARGET_FOLDER);
    Assert.assertEquals(expectedCause, collector.getValidationFailures().get(0).getCauses().get(0));
}
Also used : Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Example 10 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class XMLReaderConfigTest method testEmptyPath.

@Test
public void testEmptyPath() {
    XMLReaderBatchSource.XMLReaderConfig config = new XMLReaderBatchSource.XMLReaderConfig("emptyPathReference", "", null, "/catalog/book/", null, null, "Yes", "XMLTrackingTable", 30, "/tmp");
    FailureCollector collector = new MockFailureCollector();
    config.validate(collector);
    Assert.assertEquals(1, collector.getValidationFailures().size());
    Assert.assertEquals(1, collector.getValidationFailures().get(0).getCauses().size());
    Cause expectedCause = new Cause();
    expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, XMLReaderBatchSource.XMLReaderConfig.PATH);
    Assert.assertEquals(expectedCause, collector.getValidationFailures().get(0).getCauses().get(0));
}
Also used : Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Aggregations

MockFailureCollector (io.cdap.cdap.etl.mock.validation.MockFailureCollector)36 Test (org.junit.Test)36 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)31 Schema (io.cdap.cdap.api.data.schema.Schema)11 AutoJoinerContext (io.cdap.cdap.etl.api.join.AutoJoinerContext)11 HashMap (java.util.HashMap)10 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)9 Cause (io.cdap.cdap.etl.api.validation.ValidationFailure.Cause)9 JoinDefinition (io.cdap.cdap.etl.api.join.JoinDefinition)6 JoinStage (io.cdap.cdap.etl.api.join.JoinStage)5 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)5 JoinField (io.cdap.cdap.etl.api.join.JoinField)2 AbstractFileSourceConfig (io.cdap.plugin.format.plugin.AbstractFileSourceConfig)2 List (java.util.List)2 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)1 JoinCondition (io.cdap.cdap.etl.api.join.JoinCondition)1 MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)1