|
5 | 5 | import java.lang.reflect.Method; |
6 | 6 | import java.util.Optional; |
7 | 7 | import java.util.UUID; |
| 8 | +import java.util.stream.Stream; |
8 | 9 |
|
9 | 10 | import org.junit.jupiter.api.Assertions; |
10 | 11 | import org.junit.jupiter.api.DisplayName; |
|
20 | 21 | import com.datastax.stargate.sdk.doc.CollectionClient; |
21 | 22 | import com.datastax.stargate.sdk.doc.Document; |
22 | 23 | import com.datastax.stargate.sdk.doc.DocumentClient; |
| 24 | +import com.datastax.stargate.sdk.doc.DocumentMapper; |
23 | 25 | import com.datastax.stargate.sdk.doc.NamespaceClient; |
24 | 26 | import com.datastax.stargate.sdk.doc.domain.DocumentFunction; |
25 | 27 | import com.datastax.stargate.sdk.doc.domain.PageableQuery; |
@@ -172,19 +174,32 @@ public void f_should_update_document() |
172 | 174 |
|
173 | 175 | @Test |
174 | 176 | @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() { |
177 | 179 | LOGGER.info("should_find_all_PersonAstra"); |
178 | 180 | // Given |
179 | 181 | Assertions.assertTrue(personClient.exist()); |
180 | 182 | // When |
181 | | - Page<Document<Person>> results = personClient.findPage(Person.class); |
| 183 | + Stream<Document<Person>> results = personClient.findAll(Person.class); |
182 | 184 | // Then |
183 | 185 | 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); |
188 | 203 | } |
189 | 204 |
|
190 | 205 | @Test |
@@ -213,15 +228,22 @@ public void h_should_search_withQuery() |
213 | 228 | .isGreaterOrEqualsThan(21) |
214 | 229 | .build(); |
215 | 230 |
|
216 | | - // Execute q query |
| 231 | + // Execute query |
217 | 232 | Page<Document<Person>> results = personClient.findPage(query, Person.class); |
218 | 233 | Assertions.assertNotNull(results); |
219 | 234 | Assertions.assertTrue(results.getResults().size() > 0); |
220 | | - |
221 | 235 | for (Document<Person> PersonAstra : results.getResults()) { |
222 | 236 | Assertions.assertNotNull(PersonAstra); |
223 | 237 | } |
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"); |
225 | 247 | } |
226 | 248 |
|
227 | 249 | @Test |
|
0 commit comments