Skip to content

Commit 880aeb8

Browse files
committed
Tests for find and findAll
1 parent f05b170 commit 880aeb8

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

stargate-sdk/src/main/java/com/datastax/stargate/sdk/doc/CollectionClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ public <DOC> Page<Document<DOC>> findPage(PageableQuery query, DocumentMapper<DO
487487
raw.getPageSize(),
488488
raw.getPageState().orElse(null),
489489
raw.getResults().stream()
490-
.map(doc -> new Document<DOC>(doc.getDocument(), documentMapper.map(doc.getDocument())))
490+
.map(doc -> new Document<DOC>(doc.getDocumentId(), documentMapper.map(doc.getDocument())))
491491
.collect(Collectors.toList()));
492492
}
493493

stargate-sdk/src/main/java/com/datastax/stargate/sdk/doc/test/ApiDocumentDocumentTest.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.lang.reflect.Method;
66
import java.util.Optional;
77
import java.util.UUID;
8+
import java.util.stream.Stream;
89

910
import org.junit.jupiter.api.Assertions;
1011
import org.junit.jupiter.api.DisplayName;
@@ -20,6 +21,7 @@
2021
import com.datastax.stargate.sdk.doc.CollectionClient;
2122
import com.datastax.stargate.sdk.doc.Document;
2223
import com.datastax.stargate.sdk.doc.DocumentClient;
24+
import com.datastax.stargate.sdk.doc.DocumentMapper;
2325
import com.datastax.stargate.sdk.doc.NamespaceClient;
2426
import com.datastax.stargate.sdk.doc.domain.DocumentFunction;
2527
import com.datastax.stargate.sdk.doc.domain.PageableQuery;
@@ -172,19 +174,32 @@ public void f_should_update_document()
172174

173175
@Test
174176
@Order(7)
175-
@DisplayName("07-Find All Person")
176-
public void g_should_find_all_PersonAstra() {
177+
@DisplayName("07-Find all Person")
178+
public void g_should_find_page_PersonAstra() {
177179
LOGGER.info("should_find_all_PersonAstra");
178180
// Given
179181
Assertions.assertTrue(personClient.exist());
180182
// When
181-
Page<Document<Person>> results = personClient.findPage(Person.class);
183+
Stream<Document<Person>> results = personClient.findAll(Person.class);
182184
// Then
183185
Assertions.assertNotNull(results);
184-
for (Document<Person> p : results.getResults()) {
185-
Assertions.assertNotNull(p);
186-
}
187-
System.out.println( "[OK]" + " - Document list found");
186+
results.forEach(Assertions::assertNotNull);
187+
188+
// When
189+
Stream<Document<String>> resultsRaw = personClient.findAll();
190+
Assertions.assertNotNull(resultsRaw);
191+
resultsRaw.forEach(Assertions::assertNotNull);
192+
193+
// When
194+
Stream<Document<Person>> resultsMapper = personClient.findAll(new DocumentMapper<Person>() {
195+
@Override
196+
public Person map(String record) {
197+
Person p = new Person();
198+
p.setAge(10);
199+
return p;
200+
}});
201+
Assertions.assertNotNull(resultsMapper);
202+
resultsMapper.forEach(Assertions::assertNotNull);
188203
}
189204

190205
@Test
@@ -213,15 +228,22 @@ public void h_should_search_withQuery()
213228
.isGreaterOrEqualsThan(21)
214229
.build();
215230

216-
// Execute q query
231+
// Execute query
217232
Page<Document<Person>> results = personClient.findPage(query, Person.class);
218233
Assertions.assertNotNull(results);
219234
Assertions.assertTrue(results.getResults().size() > 0);
220-
221235
for (Document<Person> PersonAstra : results.getResults()) {
222236
Assertions.assertNotNull(PersonAstra);
223237
}
224-
System.out.println( "[OK]" + " - Document list found");
238+
239+
Page<Document<String>> results2 = personClient.findPage(query);
240+
Assertions.assertNotNull(results2);
241+
Assertions.assertTrue(results2.getResults().size() > 0);
242+
for (Document<String> ss : results2.getResults()) {
243+
Assertions.assertNotNull(ss);
244+
}
245+
246+
LOGGER.info("[OK]" + " - Document list found");
225247
}
226248

227249
@Test

0 commit comments

Comments
 (0)