|
32 | 32 | import java.util.List;
|
33 | 33 | import java.util.Map;
|
34 | 34 | import java.util.Objects;
|
| 35 | +import java.util.Optional; |
35 | 36 | import java.util.Set;
|
36 | 37 | import java.util.stream.Collectors;
|
37 | 38 | import java.util.stream.IntStream;
|
|
56 | 57 | import org.testcontainers.containers.GenericContainer;
|
57 | 58 | import org.testcontainers.containers.wait.strategy.Wait;
|
58 | 59 | import org.testcontainers.shaded.com.google.common.collect.Maps;
|
| 60 | +import org.testcontainers.shaded.org.apache.commons.lang.StringEscapeUtils; |
59 | 61 | import org.testcontainers.utility.DockerImageName;
|
60 | 62 |
|
61 | 63 | public class DocStoreTest {
|
@@ -85,22 +87,25 @@ public static void init() {
|
85 | 87 | Datastore mongoDatastore = DatastoreProvider.getDatastore("Mongo", config);
|
86 | 88 | System.out.println(mongoDatastore.listCollections());
|
87 | 89 |
|
88 |
| - postgres = |
89 |
| - new GenericContainer<>(DockerImageName.parse("postgres:13.1")) |
90 |
| - .withEnv("POSTGRES_PASSWORD", "postgres") |
91 |
| - .withEnv("POSTGRES_USER", "postgres") |
92 |
| - .withExposedPorts(5432) |
93 |
| - .waitingFor(Wait.forListeningPort()); |
94 |
| - postgres.start(); |
| 90 | +// postgres = |
| 91 | +// new GenericContainer<>(DockerImageName.parse("postgres:13.1")) |
| 92 | +// .withEnv("POSTGRES_PASSWORD", "postgres") |
| 93 | +// .withEnv("POSTGRES_USER", "postgres") |
| 94 | +// .withExposedPorts(5432) |
| 95 | +// .waitingFor(Wait.forListeningPort()); |
| 96 | +// postgres.start(); |
| 97 | + |
| 98 | +// String postgresConnectionUrl = |
| 99 | +// String.format("jdbc:postgresql://localhost:%s/", postgres.getMappedPort(5432)); |
95 | 100 |
|
96 | 101 | String postgresConnectionUrl =
|
97 |
| - String.format("jdbc:postgresql://localhost:%s/", postgres.getMappedPort(5432)); |
| 102 | + String.format("jdbc:postgresql://localhost:%s/", "5432"); |
98 | 103 | DatastoreProvider.register("POSTGRES", PostgresDatastore.class);
|
99 | 104 |
|
100 | 105 | Map<String, String> postgresConfig = new HashMap<>();
|
101 | 106 | postgresConfig.putIfAbsent("url", postgresConnectionUrl);
|
102 |
| - postgresConfig.putIfAbsent("user", "postgres"); |
103 |
| - postgresConfig.putIfAbsent("password", "postgres"); |
| 107 | + postgresConfig.putIfAbsent("user", "keycloak"); |
| 108 | + postgresConfig.putIfAbsent("password", "keycloak"); |
104 | 109 | Datastore postgresDatastore =
|
105 | 110 | DatastoreProvider.getDatastore("Postgres", ConfigFactory.parseMap(postgresConfig));
|
106 | 111 | System.out.println(postgresDatastore.listCollections());
|
@@ -139,6 +144,47 @@ private static Stream<Arguments> databaseContextMongo() {
|
139 | 144 | return Stream.of(Arguments.of(MONGO_STORE));
|
140 | 145 | }
|
141 | 146 |
|
| 147 | + @ParameterizedTest |
| 148 | + @MethodSource("databaseContextPostgres") |
| 149 | + public void debugSearch(String dataStoreName) throws Exception { |
| 150 | + /* |
| 151 | + SELECT document->'identifyingAttributes' AS "identifyingAttributes", |
| 152 | + document->'tenantId' AS "tenantId", |
| 153 | + document->'type' AS "type",id AS "id", |
| 154 | + document->'attributes' AS "attributes" |
| 155 | + FROM insights WHERE ((document->>'tenantId' = '14d8d0d8-c1a9-4100-83a4-97edfeb85606') AND (document->>'type' = 'API')) |
| 156 | + AND (document->'identifyingAttributes'->>'api_id' = '5e6f57d7-313d-34e1-a37e-a338c448c271') |
| 157 | + */ |
| 158 | + |
| 159 | + Datastore datastore = datastoreMap.get(dataStoreName); |
| 160 | + Collection collection = datastore.getCollection("insights"); |
| 161 | + |
| 162 | + Query query = new Query(); |
| 163 | + query.addSelection("identifyingAttributes"); |
| 164 | + query.addSelection("tenantId"); |
| 165 | + query.addSelection("id"); |
| 166 | + query.addSelection("attributes"); |
| 167 | + query.addSelection("type"); |
| 168 | + |
| 169 | + Filter f1 = Filter.eq("tenantId", "14d8d0d8-c1a9-4100-83a4-97edfeb85606"); |
| 170 | + Filter f2 = f1.and(Filter.eq("type", "API")); |
| 171 | + Filter f3 = f2.and(Filter.eq("identifyingAttributes.api_id", "5e6f57d7-313d-34e1-a37e-a338c448c271")); |
| 172 | + query.setFilter(f3); |
| 173 | + |
| 174 | + Iterator<Document> results = collection.search(query); |
| 175 | + List<Document> documents = new ArrayList<>(); |
| 176 | + while (results.hasNext()) { |
| 177 | + Document document = results.next(); |
| 178 | + String insightDocumentJson = document.toJson(); |
| 179 | + String processed = StringEscapeUtils.unescapeJava(insightDocumentJson); |
| 180 | + documents.add(document); |
| 181 | + Optional<InsightDto> mayBeInsightDto = |
| 182 | + Optional.ofNullable(OBJECT_MAPPER.readValue(processed, InsightDto.class)); |
| 183 | + Assertions.assertNotNull(mayBeInsightDto.get()); |
| 184 | + } |
| 185 | + Assertions.assertFalse(documents.isEmpty()); |
| 186 | + } |
| 187 | + |
142 | 188 | @ParameterizedTest
|
143 | 189 | @MethodSource("databaseContextProvider")
|
144 | 190 | public void testUpsert(String dataStoreName) throws Exception {
|
|
0 commit comments