diff --git a/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/ElasticSearchLiteQueryCreatorTest.java b/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/ElasticSearchLiteQueryCreatorTest.java index 37c15a74..e70a9f5e 100644 --- a/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/ElasticSearchLiteQueryCreatorTest.java +++ b/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/ElasticSearchLiteQueryCreatorTest.java @@ -18,6 +18,25 @@ public class ElasticSearchLiteQueryCreatorTest { + + @Test + public void testWithEmptyLookup() { + + // GIVEN + LookupRow lookupRow = new LookupRow(); + lookupRow.setLookupPhysicalRowDataType(DataTypes.STRING()); + + GenericRowData lookupDataRow = GenericRowData.of(StringData.fromString("val1")); + + // WHEN + var queryCreator = new ElasticSearchLiteQueryCreator(lookupRow); + var createdQuery = queryCreator.createLookupQuery(lookupDataRow); + + // THEN + assertThat(createdQuery.getLookupQuery()).isEqualTo(""); + assertThat(createdQuery.getBodyBasedUrlQueryParameters()).isEmpty(); + } + @Test public void testQueryCreationForSingleQueryStringParam() { diff --git a/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/GenericJsonQueryCreatorTest.java b/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/GenericJsonQueryCreatorTest.java index 3fcfe00d..bb951926 100644 --- a/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/GenericJsonQueryCreatorTest.java +++ b/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/GenericJsonQueryCreatorTest.java @@ -52,6 +52,23 @@ public void shouldSerializeToJson() { row.setField(0, 11); row.setField(1, StringData.fromString("myUuid")); + this.jsonQueryCreator.createLookupQuery(row); + LookupQueryInfo lookupQuery = this.jsonQueryCreator.createLookupQuery(row); + assertThat(lookupQuery.getBodyBasedUrlQueryParameters().isEmpty()); + assertThat(lookupQuery.getLookupQuery()).isEqualTo("{\"id\":11,\"uuid\":\"myUuid\"}"); + } + + @Test + public void shouldSerializeToJsonTwice() { + GenericRowData row = new GenericRowData(2); + row.setField(0, 11); + row.setField(1, StringData.fromString("myUuid")); + + this.jsonQueryCreator.createLookupQuery(row); + + // Call createLookupQuery two times + // to check that serialization schema is not opened Two times. + this.jsonQueryCreator.createLookupQuery(row); LookupQueryInfo lookupQuery = this.jsonQueryCreator.createLookupQuery(row); assertThat(lookupQuery.getBodyBasedUrlQueryParameters().isEmpty()); assertThat(lookupQuery.getLookupQuery()).isEqualTo("{\"id\":11,\"uuid\":\"myUuid\"}"); diff --git a/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/QueryFormatAwareConfigurationTest.java b/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/QueryFormatAwareConfigurationTest.java new file mode 100644 index 00000000..9daaecb5 --- /dev/null +++ b/src/test/java/com/getindata/connectors/http/internal/table/lookup/querycreators/QueryFormatAwareConfigurationTest.java @@ -0,0 +1,38 @@ +package com.getindata.connectors.http.internal.table.lookup.querycreators; + +import java.util.Collections; +import java.util.Optional; + +import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.configuration.ConfigOptions; +import org.apache.flink.configuration.Configuration; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + +class QueryFormatAwareConfigurationTest { + + private static final ConfigOption configOption = ConfigOptions.key("key") + .stringType() + .noDefaultValue(); + + @Test + public void testWithDot() { + QueryFormatAwareConfiguration queryConfig = new QueryFormatAwareConfiguration( + "prefix.", Configuration.fromMap(Collections.singletonMap("prefix.key", "val")) + ); + + Optional optional = queryConfig.getOptional(configOption); + assertThat(optional.get()).isEqualTo("val"); + } + + @Test + public void testWithoutDot() { + QueryFormatAwareConfiguration queryConfig = new QueryFormatAwareConfiguration( + "prefix", Configuration.fromMap(Collections.singletonMap("prefix.key", "val")) + ); + + Optional optional = queryConfig.getOptional(configOption); + assertThat(optional.get()).isEqualTo("val"); + } + +}