Skip to content

Commit ef65016

Browse files
committed
added a few tests
1 parent e346077 commit ef65016

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

document-store/src/test/java/org/hypertrace/core/documentstore/model/config/TypesafeConfigDatastoreConfigExtractorTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,32 @@ void testBuildPostgresUsingDefaultKeys() {
321321
assertEquals(expected, config);
322322
}
323323

324+
@Test
325+
void testBuildPostgresUsingDefaultKeysAndCustomParams() {
326+
final ConnectionConfig config =
327+
TypesafeConfigDatastoreConfigExtractor.from(
328+
buildConfigMapWithDefaultKeysAndCustomParamsForPostgres(), TYPE_KEY)
329+
.extract()
330+
.connectionConfig();
331+
final ConnectionConfig expected =
332+
ConnectionConfig.builder()
333+
.type(DatabaseType.POSTGRES)
334+
.addEndpoint(Endpoint.builder().host(host).port(port).build())
335+
.database(database)
336+
.credentials(ConnectionCredentials.builder().username(user).password(password).build())
337+
.applicationName(appName)
338+
.connectionPoolConfig(
339+
ConnectionPoolConfig.builder()
340+
.maxConnections(maxConnections)
341+
.connectionAccessTimeout(accessTimeout)
342+
.connectionSurrenderTimeout(surrenderTimeout)
343+
.build())
344+
.customParameter("flatStructureCollection", "earth")
345+
.build();
346+
347+
assertEquals(expected, config);
348+
}
349+
324350
private Config buildConfigMap() {
325351
return ConfigFactory.parseMap(
326352
Map.ofEntries(
@@ -355,6 +381,22 @@ private Config buildConfigMapWithDefaultKeysForPostgres() {
355381
entry("connectionIdleTime", surrenderTimeout)));
356382
}
357383

384+
private Config buildConfigMapWithDefaultKeysAndCustomParamsForPostgres() {
385+
return ConfigFactory.parseMap(
386+
Map.ofEntries(
387+
entry(TYPE_KEY, "postgres"),
388+
entry("postgres.host", host),
389+
entry("postgres.port", port),
390+
entry("postgres.database", database),
391+
entry("postgres.user", user),
392+
entry("postgres.password", password),
393+
entry("appName", appName),
394+
entry("maxPoolSize", maxConnections),
395+
entry("connectionAccessTimeout", accessTimeout),
396+
entry("connectionIdleTime", surrenderTimeout),
397+
entry("customParams.flatStructureCollection", "earth")));
398+
}
399+
358400
private Config buildConfigMapUsingDefaultKeysForMongo() {
359401
return ConfigFactory.parseMap(
360402
Map.ofEntries(

document-store/src/test/java/org/hypertrace/core/documentstore/postgres/query/v1/PostgresQueryParserTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ void testFindWithSortingAndPagination() {
638638
.setPagination(pagination)
639639
.build();
640640

641+
// json field
641642
PostgresQueryParser postgresQueryParser =
642643
new PostgresQueryParser(TEST_TABLE, PostgresQueryTransformer.transform(query));
643644
String sql = postgresQueryParser.parse();
@@ -661,6 +662,21 @@ void testFindWithSortingAndPagination() {
661662
assertEquals("Bottle", params.getObjectParams().get(7));
662663
assertEquals(1, params.getObjectParams().get(9));
663664
assertEquals(3, params.getObjectParams().get(10));
665+
666+
// non-json field
667+
postgresQueryParser =
668+
new PostgresQueryParser(
669+
TEST_TABLE, PostgresQueryTransformer.transform(query), "testCollection");
670+
assertEquals(
671+
"SELECT \"item\" AS \"item\", "
672+
+ "\"price\" AS \"price\", "
673+
+ "\"quantity\" AS \"quantity\", "
674+
+ "\"date\" AS \"date\" "
675+
+ "FROM \"testCollection\" "
676+
+ "WHERE \"item\" && ARRAY[?, ?, ?, ?]::text[] "
677+
+ "ORDER BY \"quantity\" DESC NULLS LAST,\"item\" ASC NULLS FIRST "
678+
+ "OFFSET ? LIMIT ?",
679+
postgresQueryParser.parse());
664680
}
665681

666682
@Test

0 commit comments

Comments
 (0)