Skip to content

Commit 7ecb8d1

Browse files
committed
Add integration test
1 parent d68ea47 commit 7ecb8d1

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

src/test/java/com/meilisearch/integration/DocumentsTest.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.Matchers.arrayWithSize;
55
import static org.hamcrest.Matchers.equalTo;
6+
import static org.hamcrest.Matchers.hasItemInArray;
67
import static org.hamcrest.Matchers.instanceOf;
78
import static org.hamcrest.Matchers.is;
89
import static org.hamcrest.Matchers.not;
@@ -22,6 +23,7 @@
2223
import java.util.ArrayList;
2324
import java.util.Arrays;
2425
import java.util.List;
26+
import org.hamcrest.Matchers;
2527
import org.jetbrains.annotations.NotNull;
2628
import org.junit.jupiter.api.AfterAll;
2729
import org.junit.jupiter.api.BeforeEach;
@@ -30,17 +32,18 @@
3032

3133
@Tag("integration")
3234
public class DocumentsTest extends AbstractIT {
33-
@BeforeEach
34-
public void initialize() {
35-
this.setUp();
36-
this.setUpJacksonClient();
37-
}
3835

3936
@AfterAll
4037
static void cleanMeilisearch() {
4138
cleanup();
4239
}
4340

41+
@BeforeEach
42+
public void initialize() {
43+
this.setUp();
44+
this.setUpJacksonClient();
45+
}
46+
4447
/** Test Add single document */
4548
@Test
4649
public void testAddDocumentsSingle() throws Exception {
@@ -475,6 +478,46 @@ public void testGetDocumentsLimitAndOffsetAndSpecifiedFields() throws Exception
475478
assertThat(movies[0].getRelease_date(), is(nullValue()));
476479
}
477480

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+
478521
/** Test default GetRawDocuments */
479522
@Test
480523
public void testGetRawDocuments() throws Exception {

0 commit comments

Comments
 (0)