Skip to content

Commit

Permalink
fix: updated unit test cases for GCSToSpanner
Browse files Browse the repository at this point in the history
  • Loading branch information
vanshaj-bhatia committed May 11, 2023
1 parent ae24e62 commit 19a052b
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,15 +58,20 @@ void setUp() {
@Test
void runTemplateWithValidParameters() {
LOGGER.info("Running test: runTemplateWithValidParameters");
assertDoesNotThrow((ThrowingSupplier<GCSToSpanner>) GCSToSpanner::of);
GCSToSpannerConfig config = GCSToSpannerConfig.fromProperties(PropertyUtil.getProperties());
GCSToSpanner template = new GCSToSpanner(config);
assertDoesNotThrow(template::validateInput);
}

@ParameterizedTest
@MethodSource("requiredPropertyKeys")
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());
Expand All @@ -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());
Expand Down

0 comments on commit 19a052b

Please sign in to comment.