diff --git a/java/src/main/java/com/google/cloud/dataproc/templates/gcs/GCSToSpanner.java b/java/src/main/java/com/google/cloud/dataproc/templates/gcs/GCSToSpanner.java index b98f360de..785911957 100644 --- a/java/src/main/java/com/google/cloud/dataproc/templates/gcs/GCSToSpanner.java +++ b/java/src/main/java/com/google/cloud/dataproc/templates/gcs/GCSToSpanner.java @@ -40,7 +40,6 @@ public GCSToSpanner(GCSToSpannerConfig config) { public static GCSToSpanner of(String... args) { GCSToSpannerConfig config = GCSToSpannerConfig.fromProperties(PropertyUtil.getProperties()); - ValidationUtil.validateOrThrow(config); LOGGER.info("Config loaded\n{}", config); return new GCSToSpanner(config); } @@ -82,5 +81,8 @@ public void write(Dataset dataset) { .save(); } - public void validateInput() {} + @Override + public void validateInput() { + ValidationUtil.validateOrThrow(config); + } } diff --git a/java/src/test/java/com/google/cloud/dataproc/templates/gcs/GCSToSpannerTest.java b/java/src/test/java/com/google/cloud/dataproc/templates/gcs/GCSToSpannerTest.java index bceda2aba..91f680ce8 100644 --- a/java/src/test/java/com/google/cloud/dataproc/templates/gcs/GCSToSpannerTest.java +++ b/java/src/test/java/com/google/cloud/dataproc/templates/gcs/GCSToSpannerTest.java @@ -34,7 +34,6 @@ import org.apache.spark.sql.SaveMode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.ThrowingSupplier; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; @@ -59,7 +58,9 @@ void setUp() { @Test void runTemplateWithValidParameters() { LOGGER.info("Running test: runTemplateWithValidParameters"); - assertDoesNotThrow((ThrowingSupplier) GCSToSpanner::of); + GCSToSpannerConfig config = GCSToSpannerConfig.fromProperties(PropertyUtil.getProperties()); + GCSToSpanner template = new GCSToSpanner(config); + assertDoesNotThrow(template::validateInput); } @ParameterizedTest @@ -67,7 +68,10 @@ void runTemplateWithValidParameters() { void runTemplateWithMissingRequiredParameters(String propKey) { LOGGER.info("Running test: runTemplateWithInvalidParameters"); PropertyUtil.getProperties().setProperty(propKey, ""); - ValidationException exception = assertThrows(ValidationException.class, GCSToSpanner::of); + GCSToSpannerConfig config = GCSToSpannerConfig.fromProperties(PropertyUtil.getProperties()); + GCSToSpanner template = new GCSToSpanner(config); + ValidationException exception = + assertThrows(ValidationException.class, template::validateInput); assertEquals(1, exception.getViolations().size()); ConstraintViolation violation = exception.getViolations().get(0); assertEquals("must not be empty", violation.getMessage()); @@ -83,7 +87,10 @@ void runTemplateWithMissingPrimaryKey(String saveMode) { LOGGER.info("Running test: runTemplateWithInvalidParameters"); PropertyUtil.getProperties().setProperty(GCS_SPANNER_OUTPUT_SAVE_MODE, saveMode); PropertyUtil.getProperties().setProperty(GCS_SPANNER_OUTPUT_PRIMARY_KEY, ""); - ValidationException exception = assertThrows(ValidationException.class, GCSToSpanner::of); + GCSToSpannerConfig config = GCSToSpannerConfig.fromProperties(PropertyUtil.getProperties()); + GCSToSpanner template = new GCSToSpanner(config); + ValidationException exception = + assertThrows(ValidationException.class, template::validateInput); assertEquals(1, exception.getViolations().size()); ConstraintViolation violation = exception.getViolations().get(0); assertEquals("primaryKey", violation.getPropertyPath().toString());