Skip to content

Commit

Permalink
Add missing tests
Browse files Browse the repository at this point in the history
These tests are needed to increase test coverage level to required
value.
  • Loading branch information
Grzegorz Kołakowski committed Oct 17, 2024
1 parent 99ffa43 commit b3eef5a
Show file tree
Hide file tree
Showing 3 changed files with 74 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 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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\"}");
Expand Down
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 b3eef5a

Please sign in to comment.