|
3 | 3 | import static org.hamcrest.MatcherAssert.assertThat; |
4 | 4 | import static org.hamcrest.Matchers.arrayWithSize; |
5 | 5 | import static org.hamcrest.Matchers.equalTo; |
| 6 | +import static org.hamcrest.Matchers.hasItemInArray; |
6 | 7 | import static org.hamcrest.Matchers.instanceOf; |
7 | 8 | import static org.hamcrest.Matchers.is; |
8 | 9 | import static org.hamcrest.Matchers.not; |
|
22 | 23 | import java.util.ArrayList; |
23 | 24 | import java.util.Arrays; |
24 | 25 | import java.util.List; |
| 26 | +import org.hamcrest.Matchers; |
25 | 27 | import org.jetbrains.annotations.NotNull; |
26 | 28 | import org.junit.jupiter.api.AfterAll; |
27 | 29 | import org.junit.jupiter.api.BeforeEach; |
|
30 | 32 |
|
31 | 33 | @Tag("integration") |
32 | 34 | public class DocumentsTest extends AbstractIT { |
33 | | - @BeforeEach |
34 | | - public void initialize() { |
35 | | - this.setUp(); |
36 | | - this.setUpJacksonClient(); |
37 | | - } |
38 | 35 |
|
39 | 36 | @AfterAll |
40 | 37 | static void cleanMeilisearch() { |
41 | 38 | cleanup(); |
42 | 39 | } |
43 | 40 |
|
| 41 | + @BeforeEach |
| 42 | + public void initialize() { |
| 43 | + this.setUp(); |
| 44 | + this.setUpJacksonClient(); |
| 45 | + } |
| 46 | + |
44 | 47 | /** Test Add single document */ |
45 | 48 | @Test |
46 | 49 | public void testAddDocumentsSingle() throws Exception { |
@@ -475,6 +478,46 @@ public void testGetDocumentsLimitAndOffsetAndSpecifiedFields() throws Exception |
475 | 478 | assertThat(movies[0].getRelease_date(), is(nullValue())); |
476 | 479 | } |
477 | 480 |
|
| 481 | + /** Test GetDocuments with limit, offset, specified fields and specified filter */ |
| 482 | + @Test |
| 483 | + void testGetDocumentsLimitAndOffsetAndSpecifiedFieldsAndSpecifiedFilter() throws Exception { |
| 484 | + String indexUid = "GetDocumentsLimitAndOffsetAndSpecifiedFieldsAndSpecifiedFilter"; |
| 485 | + int limit = 2; |
| 486 | + int offset = 0; |
| 487 | + List<String> fields = Arrays.asList("id", "title", "genres"); |
| 488 | + List<String> filters = Arrays.asList("(genres = Horror OR genres = Action)"); |
| 489 | + |
| 490 | + DocumentsQuery query = |
| 491 | + new DocumentsQuery() |
| 492 | + .setLimit(limit) |
| 493 | + .setOffset(offset) |
| 494 | + .setFields(fields.toArray(new String[0])) |
| 495 | + .setFilter(filters.toArray(new String[0])); |
| 496 | + Index index = client.index(indexUid); |
| 497 | + |
| 498 | + String[] filterAttributes = {"genres"}; |
| 499 | + index.waitForTask(index.updateFilterableAttributesSettings(filterAttributes).getTaskUid()); |
| 500 | + |
| 501 | + TestData<Movie> testData = this.getTestData(MOVIES_INDEX, Movie.class); |
| 502 | + TaskInfo task = index.addDocuments(testData.getRaw()); |
| 503 | + |
| 504 | + index.waitForTask(task.getTaskUid()); |
| 505 | + Results<Movie> result = index.getDocuments(query, Movie.class); |
| 506 | + Movie[] movies = result.getResults(); |
| 507 | + |
| 508 | + assertThat(movies, is(arrayWithSize(limit))); |
| 509 | + assertThat(movies[0].getId(), is(notNullValue())); |
| 510 | + assertThat(movies[0].getTitle(), is(notNullValue())); |
| 511 | + assertThat(movies[0].getGenres(), is(notNullValue())); |
| 512 | + assertThat( |
| 513 | + movies[0].getGenres(), |
| 514 | + hasItemInArray(Matchers.anyOf(equalTo("Horror"), equalTo("Action")))); |
| 515 | + assertThat(movies[0].getLanguage(), is(nullValue())); |
| 516 | + assertThat(movies[0].getOverview(), is(nullValue())); |
| 517 | + assertThat(movies[0].getPoster(), is(nullValue())); |
| 518 | + assertThat(movies[0].getRelease_date(), is(nullValue())); |
| 519 | + } |
| 520 | + |
478 | 521 | /** Test default GetRawDocuments */ |
479 | 522 | @Test |
480 | 523 | public void testGetRawDocuments() throws Exception { |
|
0 commit comments