Skip to content

Commit

Permalink
Added test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Kondaka <[email protected]>
  • Loading branch information
Krishna Kondaka committed Oct 14, 2024
1 parent d20ca87 commit 4a6f69e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class S3SinkConfig {
private ObjectMetadataConfig objectMetadataConfig;

@AssertTrue(message = "Only one of object_metadata and predefined_object_metadata can be used.")
private boolean isValidMetadataConfig() {
boolean isValidMetadataConfig() {
// One of them or both should be null
return (objectMetadataConfig == null || predefinedObjectMetadata == null);
}
Expand Down Expand Up @@ -151,8 +151,8 @@ public ObjectKeyOptions getObjectKeyOptions() {
return objectKeyOptions;
}

public ObjectMetadataConfig getObjectMetadataConfig() {
return objectMetadataConfig;
public Object getObjectMetadataConfig() {
return objectMetadataConfig != null ? objectMetadataConfig : predefinedObjectMetadata;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,39 @@ void get_bucket_name_with_s3_prefix_test() throws NoSuchFieldException, IllegalA
assertThat(objectUnderTest.getBucketName(), equalTo(bucketName));
}

@Test
void test_default_metadata_config() throws NoSuchFieldException, IllegalAccessException {
final String bucketName = UUID.randomUUID().toString();
final String bucketNameWithPrefix = S3_PREFIX + bucketName;
final S3SinkConfig objectUnderTest = new S3SinkConfig();
assertThat(objectUnderTest.isValidMetadataConfig(), equalTo(true));
assertThat(objectUnderTest.getObjectMetadataConfig(), equalTo(null));
}

@Test
void test_object_metadata_config() throws NoSuchFieldException, IllegalAccessException {
final String bucketName = UUID.randomUUID().toString();
final String bucketNameWithPrefix = S3_PREFIX + bucketName;
final S3SinkConfig objectUnderTest = new S3SinkConfig();

ObjectMetadataConfig objectMetadataConfig = new ObjectMetadataConfig();
ReflectivelySetField.setField(S3SinkConfig.class, objectUnderTest, "objectMetadataConfig", objectMetadataConfig);
assertThat(objectUnderTest.isValidMetadataConfig(), equalTo(true));
assertThat(objectUnderTest.getObjectMetadataConfig(), equalTo(objectMetadataConfig));
}

@Test
void test_predefined_metadata_config() throws NoSuchFieldException, IllegalAccessException {
final String bucketName = UUID.randomUUID().toString();
final String bucketNameWithPrefix = S3_PREFIX + bucketName;
final S3SinkConfig objectUnderTest = new S3SinkConfig();

PredefinedObjectMetadata objectMetadataConfig = new PredefinedObjectMetadata();
ReflectivelySetField.setField(S3SinkConfig.class, objectUnderTest, "predefinedObjectMetadata", objectMetadataConfig);
assertThat(objectUnderTest.isValidMetadataConfig(), equalTo(true));
assertThat(objectUnderTest.getObjectMetadataConfig(), equalTo(objectMetadataConfig));
}

@Test
void get_object_key_test() {
assertThat("Object key is not an instance of ObjectKeyOptions",
Expand All @@ -81,4 +114,4 @@ void get_json_codec_test() {
void get_client_option_test() {
assertNull(new S3SinkConfig().getClientOptions());
}
}
}

0 comments on commit 4a6f69e

Please sign in to comment.