Skip to content

Commit

Permalink
Merge pull request #647 from GoogleCloudPlatform/603-java-template-re…
Browse files Browse the repository at this point in the history
…dshifttogcs-empty-validateinput-method

fix: java-template-redshifttogcs-empty-validateinput-method
  • Loading branch information
vanshaj-bhatia authored May 11, 2023
2 parents 40a9835 + f1fd17b commit 4a4e32a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ public RedshiftToGCS(RedshiftToGCSConfig config) {

public static com.google.cloud.dataproc.templates.databases.RedshiftToGCS of(String... args) {
RedshiftToGCSConfig config = RedshiftToGCSConfig.fromProperties(PropertyUtil.getProperties());
ValidationUtil.validateOrThrow(config);
LOGGER.info("Config loaded\n{}", config);
return new com.google.cloud.dataproc.templates.databases.RedshiftToGCS(config);
return new RedshiftToGCS(config);
}

@Override
Expand Down Expand Up @@ -82,5 +81,8 @@ public void runTemplate() {
spark.stop();
}

public void validateInput() {}
@Override
public void validateInput() {
ValidationUtil.validateOrThrow(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.google.cloud.dataproc.templates.databases.RedshiftToGCS;
import com.google.cloud.dataproc.templates.databases.RedshiftToGCSConfig;
import com.google.cloud.dataproc.templates.util.PropertyUtil;
import com.google.cloud.dataproc.templates.util.ValidationUtil.ValidationException;
import java.util.stream.Stream;
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 Down Expand Up @@ -54,15 +54,20 @@ void setUp() {
@Test
void runTemplateWithValidParameters() {
LOGGER.info("Running test: runTemplateWithValidParameters");
assertDoesNotThrow((ThrowingSupplier<RedshiftToGCS>) RedshiftToGCS::of);
RedshiftToGCSConfig config = RedshiftToGCSConfig.fromProperties(PropertyUtil.getProperties());
RedshiftToGCS template = new RedshiftToGCS(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, RedshiftToGCS::of);
RedshiftToGCSConfig config = RedshiftToGCSConfig.fromProperties(PropertyUtil.getProperties());
RedshiftToGCS template = new RedshiftToGCS(config);
ValidationException exception =
assertThrows(ValidationException.class, template::validateInput);
}

static Stream<String> requiredPropertyKeys() {
Expand Down

0 comments on commit 4a4e32a

Please sign in to comment.