use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.
the class DataPipelineServiceTest method testValidateMultiInputInvalidInputField.
@Test
public void testValidateMultiInputInvalidInputField() throws Exception {
// StringValueFilterTransform will be configured to filter records where field x has value 'y'
// it will be invalid because the type of field x will be an int instead of the required string
String stageName = "tx";
Map<String, String> properties = new HashMap<>();
properties.put("field", "x");
properties.put("value", "y");
ETLStage stage = new ETLStage(stageName, new ETLPlugin(StringValueFilterTransform.NAME, Transform.PLUGIN_TYPE, properties));
Schema inputSchema = Schema.recordOf("x", Schema.Field.of("x", Schema.of(Schema.Type.INT)));
StageValidationRequest requestBody = new StageValidationRequest(stage, ImmutableList.of(new StageSchema("input1", inputSchema), new StageSchema("input2", inputSchema)), false);
StageValidationResponse actual = sendRequest(requestBody);
List<String> expectedInputs = ImmutableList.of("input1", "input2");
Assert.assertNull(actual.getSpec());
Assert.assertEquals(1, actual.getFailures().size());
ValidationFailure failure = actual.getFailures().iterator().next();
// the stage will add 3 causes. Two are related to input field and one is related to config property.
Assert.assertEquals(3, failure.getCauses().size());
Assert.assertEquals("field", failure.getCauses().get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
Assert.assertEquals(stageName, failure.getCauses().get(0).getAttribute(STAGE));
Assert.assertEquals(stageName, failure.getCauses().get(1).getAttribute(STAGE));
Assert.assertEquals(stageName, failure.getCauses().get(2).getAttribute(STAGE));
Assert.assertTrue(expectedInputs.contains(failure.getCauses().get(1).getAttribute(CauseAttributes.INPUT_STAGE)));
Assert.assertTrue(expectedInputs.contains(failure.getCauses().get(2).getAttribute(CauseAttributes.INPUT_STAGE)));
}
use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.
the class ValidationUtilsTest method testValidateException.
@Test
public void testValidateException() {
Schema testSchema = Schema.recordOf("a", Schema.Field.of("a", Schema.of(Schema.Type.STRING)));
StageSchema testStageSchema = new StageSchema("source", testSchema);
ETLStage etlStage = new ETLStage("source", MockSource.getPlugin(null));
StageValidationRequest validationRequest = new StageValidationRequest(etlStage, Collections.singletonList(testStageSchema), false);
StageValidationResponse stageValidationResponse = ValidationUtils.validate(NamespaceId.DEFAULT.getNamespace(), validationRequest, getPluginConfigurer(MockSource.PLUGIN_CLASS), properties -> properties, MOCK_FEATURE_FLAGS_PROVIDER);
Assert.assertEquals(1, stageValidationResponse.getFailures().size());
}
use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.
the class ValidationUtilsTest method testMacroSubstitution.
@Test
public void testMacroSubstitution() {
Schema testSchema = Schema.recordOf("a", Schema.Field.of("a", Schema.of(Schema.Type.STRING)));
StageSchema testStageSchema = new StageSchema("source", testSchema);
ETLStage etlStage = new ETLStage("source", MockSource.getPlugin("@{tName}"));
StageValidationRequest validationRequest = new StageValidationRequest(etlStage, Collections.singletonList(testStageSchema), false);
String testtable = "testtable";
StageValidationResponse stageValidationResponse = ValidationUtils.validate(NamespaceId.DEFAULT.getNamespace(), validationRequest, getPluginConfigurer(MockSource.PLUGIN_CLASS), properties -> {
Map<String, String> propertiesCopy = new HashMap<>(properties);
if (propertiesCopy.getOrDefault("tableName", "").equals("@{tName}")) {
propertiesCopy.put("tableName", testtable);
}
return propertiesCopy;
}, MOCK_FEATURE_FLAGS_PROVIDER);
Assert.assertTrue(stageValidationResponse.getFailures().isEmpty());
Assert.assertEquals(testtable, stageValidationResponse.getSpec().getPlugin().getProperties().get("tableName"));
}
use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.
the class DataPipelineServiceTest method testSecureMacroSubstitution.
@Test
public void testSecureMacroSubstitution() throws Exception {
// StringValueFilterTransform checks that the field exists in the input schema
String stageName = "tx";
Map<String, String> properties = new HashMap<>();
properties.put("field", "${secure(field)}");
properties.put("value", "y");
ETLStage stage = new ETLStage(stageName, new ETLPlugin(StringValueFilterTransform.NAME, Transform.PLUGIN_TYPE, properties));
Schema inputSchema = Schema.recordOf("x", Schema.Field.of("x", Schema.of(Schema.Type.INT)));
// this call happens when no value for 'field' is in the secure store, which should not result in
// any failures because the macro could not be enabled so the check is skipped
StageValidationRequest requestBody = new StageValidationRequest(stage, Collections.singletonList(new StageSchema("input", inputSchema)), false);
StageValidationResponse actual = sendRequest(requestBody);
Assert.assertTrue(actual.getFailures().isEmpty());
// now set the value of 'field' to be 'z', which is not in the input schema
// this call should result in a failure
getSecureStoreManager().put("default", "field", "z", "desc", Collections.emptyMap());
actual = sendRequest(requestBody);
Assert.assertNull(actual.getSpec());
Assert.assertEquals(1, actual.getFailures().size());
ValidationFailure failure = actual.getFailures().iterator().next();
// the stage will add 2 causes for invalid input field failure. One is related to input field and the other is
// related to config property.
Assert.assertEquals(1, failure.getCauses().size());
Assert.assertEquals("field", failure.getCauses().get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
Assert.assertEquals(stageName, failure.getCauses().get(0).getAttribute(STAGE));
}
use of io.cdap.cdap.etl.proto.v2.validation.StageSchema in project cdap by caskdata.
the class ValidationUtilsTest method testValidateNoException.
@Test
public void testValidateNoException() {
Schema testSchema = Schema.recordOf("a", Schema.Field.of("a", Schema.of(Schema.Type.STRING)));
StageSchema testStageSchema = new StageSchema("source", testSchema);
ETLStage etlStage = new ETLStage("source", MockSource.getPlugin("testtable"));
StageValidationRequest validationRequest = new StageValidationRequest(etlStage, Collections.singletonList(testStageSchema), false);
StageValidationResponse stageValidationResponse = ValidationUtils.validate(NamespaceId.DEFAULT.getNamespace(), validationRequest, getPluginConfigurer(MockSource.PLUGIN_CLASS), properties -> properties, MOCK_FEATURE_FLAGS_PROVIDER);
Assert.assertTrue(stageValidationResponse.getFailures().isEmpty());
}
Aggregations