99import com .meilisearch .integration .classes .TestData ;
1010import com .meilisearch .sdk .Index ;
1111import com .meilisearch .sdk .exceptions .MeilisearchApiException ;
12+ import com .meilisearch .sdk .model .IndexesQuery ;
13+ import com .meilisearch .sdk .model .Results ;
14+ import com .meilisearch .sdk .model .Task ;
1215import com .meilisearch .sdk .model .TaskInfo ;
1316import com .meilisearch .sdk .utils .Movie ;
1417import java .util .Arrays ;
15- import org .junit .jupiter .api .AfterAll ;
18+ import org .junit .jupiter .api .AfterEach ;
1619import org .junit .jupiter .api .BeforeEach ;
1720import org .junit .jupiter .api .Tag ;
1821import org .junit .jupiter .api .Test ;
@@ -30,8 +33,8 @@ public void initialize() {
3033 if (testData == null ) testData = this .getTestData (MOVIES_INDEX , Movie .class );
3134 }
3235
33- @ AfterAll
34- static void cleanMeilisearch () {
36+ @ AfterEach
37+ public void cleanMeilisearch () {
3538 cleanup ();
3639 }
3740
@@ -43,8 +46,6 @@ public void testCreateIndexWithoutPrimaryKey() throws Exception {
4346
4447 assertEquals (index .getUid (), indexUid );
4548 assertNull (index .getPrimaryKey ());
46-
47- client .deleteIndex (index .getUid ());
4849 }
4950
5051 /** Test Index creation without PrimaryKey with Jackson Json Handler */
@@ -57,8 +58,6 @@ public void testCreateIndexWithoutPrimaryKeyWithJacksonJsonHandler() throws Exce
5758
5859 assertEquals (index .getUid (), indexUid );
5960 assertNull (index .getPrimaryKey ());
60-
61- clientJackson .deleteIndex (index .getUid ());
6261 }
6362
6463 /** Test Index creation with PrimaryKey */
@@ -69,8 +68,6 @@ public void testCreateIndexWithPrimaryKey() throws Exception {
6968
7069 assertEquals (index .getUid (), indexUid );
7170 assertEquals (index .getPrimaryKey (), this .primaryKey );
72-
73- client .deleteIndex (index .getUid ());
7471 }
7572
7673 /** Test Index creation with PrimaryKey with Jackson Json Handler */
@@ -83,8 +80,6 @@ public void testCreateIndexWithPrimaryKeyWithJacksonJsonHandler() throws Excepti
8380
8481 assertEquals (index .getUid (), indexUid );
8582 assertEquals (index .getPrimaryKey (), this .primaryKey );
86-
87- clientJackson .deleteIndex (index .getUid ());
8883 }
8984
9085 /** Test Index creation twice doesn't throw an error: already exists */
@@ -102,8 +97,6 @@ public void testCreateIndexAlreadyExists() throws Exception {
10297 assertEquals (indexDuplicate .getUid (), indexUid );
10398 assertEquals (index .getPrimaryKey (), this .primaryKey );
10499 assertEquals (indexDuplicate .getPrimaryKey (), this .primaryKey );
105-
106- client .deleteIndex (index .getUid ());
107100 }
108101
109102 /** Test update Index PrimaryKey */
@@ -122,8 +115,6 @@ public void testUpdateIndexPrimaryKey() throws Exception {
122115 assertTrue (index instanceof Index );
123116 assertEquals (index .getUid (), indexUid );
124117 assertEquals (index .getPrimaryKey (), this .primaryKey );
125-
126- client .deleteIndex (index .getUid ());
127118 }
128119
129120 /** Test getIndex */
@@ -135,22 +126,6 @@ public void testGetIndex() throws Exception {
135126
136127 assertEquals (index .getUid (), getIndex .getUid ());
137128 assertEquals (index .getPrimaryKey (), getIndex .getPrimaryKey ());
138-
139- client .deleteIndex (index .getUid ());
140- }
141-
142- /** Test getRawIndex */
143- @ Test
144- public void testGetRawIndex () throws Exception {
145- String indexUid = "GetRawIndex" ;
146- Index index = createEmptyIndex (indexUid , this .primaryKey );
147- String getIndex = client .getRawIndex (indexUid );
148- JsonObject indexJson = JsonParser .parseString (getIndex ).getAsJsonObject ();
149-
150- assertEquals (index .getUid (), indexJson .get ("uid" ).getAsString ());
151- assertEquals (index .getPrimaryKey (), indexJson .get ("primaryKey" ).getAsString ());
152-
153- client .deleteIndex (index .getUid ());
154129 }
155130
156131 /** Test getIndexes */
@@ -159,14 +134,41 @@ public void testGetIndexes() throws Exception {
159134 String [] indexUids = {"GetIndexes" , "GetIndexes2" };
160135 createEmptyIndex (indexUids [0 ]);
161136 createEmptyIndex (indexUids [1 ], this .primaryKey );
162- Index [] indexes = client .getIndexes ();
137+ Results < Index > indexes = client .getIndexes ();
163138
164- assertEquals (2 , indexes .length );
139+ assertEquals (2 , indexes .getResults (). length );
165140 assert (Arrays .asList (indexUids ).contains (indexUids [0 ]));
166141 assert (Arrays .asList (indexUids ).contains (indexUids [1 ]));
142+ }
143+
144+ /** Test getIndexes with limit */
145+ @ Test
146+ public void testGetIndexesLimit () throws Exception {
147+ int limit = 1 ;
148+ String [] indexUids = {"GetIndexesLimit" , "GetIndexesLimit2" };
149+ IndexesQuery query = new IndexesQuery ().setLimit (limit );
150+ createEmptyIndex (indexUids [0 ]);
151+ createEmptyIndex (indexUids [1 ], this .primaryKey );
152+ Results <Index > indexes = client .getIndexes (query );
153+
154+ assertEquals (limit , indexes .getResults ().length );
155+ assertEquals (limit , indexes .getLimit ());
156+ }
157+
158+ /** Test getIndexes with limit and offset */
159+ @ Test
160+ public void testGetIndexesLimitAndOffset () throws Exception {
161+ int limit = 1 ;
162+ int offset = 1 ;
163+ String [] indexUids = {"GetIndexesLimitOffset" , "GetIndexesLimitOffset2" };
164+ IndexesQuery query = new IndexesQuery ().setLimit (limit ).setOffset (offset );
165+ createEmptyIndex (indexUids [0 ]);
166+ createEmptyIndex (indexUids [1 ], this .primaryKey );
167+ Results <Index > indexes = client .getIndexes (query );
167168
168- client .deleteIndex (indexUids [0 ]);
169- client .deleteIndex (indexUids [1 ]);
169+ assertEquals (limit , indexes .getResults ().length );
170+ assertEquals (limit , indexes .getLimit ());
171+ assertEquals (offset , indexes .getOffset ());
170172 }
171173
172174 /** Test getRawIndexes */
@@ -177,16 +179,14 @@ public void testGetRawIndexes() throws Exception {
177179 createEmptyIndex (indexUids [1 ], this .primaryKey );
178180
179181 String indexes = client .getRawIndexes ();
180- JsonArray jsonIndexArray = JsonParser .parseString (indexes ).getAsJsonArray ();
182+ JsonObject jsonIndexObject = JsonParser .parseString (indexes ).getAsJsonObject ();
183+ JsonArray jsonIndexArray = jsonIndexObject .getAsJsonArray ("results" );
181184
182- assertEquals (4 , jsonIndexArray .size ());
185+ assertEquals (2 , jsonIndexArray .size ());
183186 assert (Arrays .asList (indexUids )
184187 .contains (jsonIndexArray .get (0 ).getAsJsonObject ().get ("uid" ).getAsString ()));
185188 assert (Arrays .asList (indexUids )
186189 .contains (jsonIndexArray .get (1 ).getAsJsonObject ().get ("uid" ).getAsString ()));
187-
188- client .deleteIndex (indexUids [0 ]);
189- client .deleteIndex (indexUids [1 ]);
190190 }
191191
192192 /** Test deleteIndex */
0 commit comments