Skip to content

Commit

Permalink
Add missing tests (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz8 authored Oct 17, 2024
1 parent e14ae6a commit d712792
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@

public class ElasticSearchLiteQueryCreatorTest {


@Test
public void testWithEmptyLookupResult() {

// 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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,18 @@ public void shouldSerializeToJson() {
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"));

// 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\"}");
}
}
Original file line number Diff line number Diff line change
@@ -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<String> configOption = ConfigOptions.key("key")
.stringType()
.noDefaultValue();

@Test
public void testWithDot() {
QueryFormatAwareConfiguration queryConfig = new QueryFormatAwareConfiguration(
"prefix.", Configuration.fromMap(Collections.singletonMap("prefix.key", "val"))
);

Optional<String> 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<String> optional = queryConfig.getOptional(configOption);
assertThat(optional.get()).isEqualTo("val");
}

}

0 comments on commit d712792

Please sign in to comment.