99import com .meilisearch .integration .classes .TestData ;
1010import com .meilisearch .sdk .Index ;
1111import com .meilisearch .sdk .exceptions .MeilisearchApiException ;
12+ import com .meilisearch .sdk .model .IndexesQuery ;
1213import com .meilisearch .sdk .model .Results ;
1314import com .meilisearch .sdk .model .TaskInfo ;
1415import com .meilisearch .sdk .utils .Movie ;
1516import java .util .Arrays ;
16- import org .junit .jupiter .api .AfterAll ;
17+ import org .junit .jupiter .api .AfterEach ;
1718import org .junit .jupiter .api .BeforeEach ;
1819import org .junit .jupiter .api .Tag ;
1920import org .junit .jupiter .api .Test ;
@@ -31,8 +32,8 @@ public void initialize() {
3132 if (testData == null ) testData = this .getTestData (MOVIES_INDEX , Movie .class );
3233 }
3334
34- @ AfterAll
35- static void cleanMeilisearch () {
35+ @ AfterEach
36+ public void cleanMeilisearch () {
3637 cleanup ();
3738 }
3839
@@ -44,8 +45,6 @@ public void testCreateIndexWithoutPrimaryKey() throws Exception {
4445
4546 assertEquals (index .getUid (), indexUid );
4647 assertNull (index .getPrimaryKey ());
47-
48- client .deleteIndex (index .getUid ());
4948 }
5049
5150 /** Test Index creation without PrimaryKey with Jackson Json Handler */
@@ -58,8 +57,6 @@ public void testCreateIndexWithoutPrimaryKeyWithJacksonJsonHandler() throws Exce
5857
5958 assertEquals (index .getUid (), indexUid );
6059 assertNull (index .getPrimaryKey ());
61-
62- clientJackson .deleteIndex (index .getUid ());
6360 }
6461
6562 /** Test Index creation with PrimaryKey */
@@ -70,8 +67,6 @@ public void testCreateIndexWithPrimaryKey() throws Exception {
7067
7168 assertEquals (index .getUid (), indexUid );
7269 assertEquals (index .getPrimaryKey (), this .primaryKey );
73-
74- client .deleteIndex (index .getUid ());
7570 }
7671
7772 /** Test Index creation with PrimaryKey with Jackson Json Handler */
@@ -84,8 +79,6 @@ public void testCreateIndexWithPrimaryKeyWithJacksonJsonHandler() throws Excepti
8479
8580 assertEquals (index .getUid (), indexUid );
8681 assertEquals (index .getPrimaryKey (), this .primaryKey );
87-
88- clientJackson .deleteIndex (index .getUid ());
8982 }
9083
9184 /** Test Index creation twice doesn't throw an error: already exists */
@@ -103,8 +96,6 @@ public void testCreateIndexAlreadyExists() throws Exception {
10396 assertEquals (indexDuplicate .getUid (), indexUid );
10497 assertEquals (index .getPrimaryKey (), this .primaryKey );
10598 assertEquals (indexDuplicate .getPrimaryKey (), this .primaryKey );
106-
107- client .deleteIndex (index .getUid ());
10899 }
109100
110101 /** Test update Index PrimaryKey */
@@ -123,8 +114,6 @@ public void testUpdateIndexPrimaryKey() throws Exception {
123114 assertTrue (index instanceof Index );
124115 assertEquals (index .getUid (), indexUid );
125116 assertEquals (index .getPrimaryKey (), this .primaryKey );
126-
127- client .deleteIndex (index .getUid ());
128117 }
129118
130119 /** Test getIndex */
@@ -136,8 +125,6 @@ public void testGetIndex() throws Exception {
136125
137126 assertEquals (index .getUid (), getIndex .getUid ());
138127 assertEquals (index .getPrimaryKey (), getIndex .getPrimaryKey ());
139-
140- client .deleteIndex (index .getUid ());
141128 }
142129
143130 /** Test getIndexes */
@@ -151,9 +138,36 @@ public void testGetIndexes() throws Exception {
151138 assertEquals (2 , indexes .getResults ().length );
152139 assert (Arrays .asList (indexUids ).contains (indexUids [0 ]));
153140 assert (Arrays .asList (indexUids ).contains (indexUids [1 ]));
141+ }
154142
155- client .deleteIndex (indexUids [0 ]);
156- client .deleteIndex (indexUids [1 ]);
143+ /** Test getIndexes with limit */
144+ @ Test
145+ public void testGetIndexesLimit () throws Exception {
146+ int limit = 1 ;
147+ String [] indexUids = {"GetIndexesLimit" , "GetIndexesLimit2" };
148+ IndexesQuery query = new IndexesQuery ().setLimit (limit );
149+ createEmptyIndex (indexUids [0 ]);
150+ createEmptyIndex (indexUids [1 ], this .primaryKey );
151+ Results <Index > indexes = client .getIndexes (query );
152+
153+ assertEquals (limit , indexes .getResults ().length );
154+ assertEquals (limit , indexes .getLimit ());
155+ }
156+
157+ /** Test getIndexes with limit and offset */
158+ @ Test
159+ public void testGetIndexesLimitAndOffset () throws Exception {
160+ int limit = 1 ;
161+ int offset = 1 ;
162+ String [] indexUids = {"GetIndexesLimitOffset" , "GetIndexesLimitOffset2" };
163+ IndexesQuery query = new IndexesQuery ().setLimit (limit ).setOffset (offset );
164+ createEmptyIndex (indexUids [0 ]);
165+ createEmptyIndex (indexUids [1 ], this .primaryKey );
166+ Results <Index > indexes = client .getIndexes (query );
167+
168+ assertEquals (limit , indexes .getResults ().length );
169+ assertEquals (limit , indexes .getLimit ());
170+ assertEquals (offset , indexes .getOffset ());
157171 }
158172
159173 /** Test getRawIndexes */
@@ -167,14 +181,11 @@ public void testGetRawIndexes() throws Exception {
167181 JsonObject jsonIndexObject = JsonParser .parseString (indexes ).getAsJsonObject ();
168182 JsonArray jsonIndexArray = jsonIndexObject .getAsJsonArray ("results" );
169183
170- assertEquals (4 , jsonIndexArray .size ());
184+ assertEquals (2 , jsonIndexArray .size ());
171185 assert (Arrays .asList (indexUids )
172186 .contains (jsonIndexArray .get (0 ).getAsJsonObject ().get ("uid" ).getAsString ()));
173187 assert (Arrays .asList (indexUids )
174188 .contains (jsonIndexArray .get (1 ).getAsJsonObject ().get ("uid" ).getAsString ()));
175-
176- client .deleteIndex (indexUids [0 ]);
177- client .deleteIndex (indexUids [1 ]);
178189 }
179190
180191 /** Test deleteIndex */
0 commit comments