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 ;
1618import org .junit .jupiter .api .BeforeEach ;
1719import org .junit .jupiter .api .Tag ;
1820import org .junit .jupiter .api .Test ;
@@ -28,10 +30,6 @@ public void initialize() {
2830 setUp ();
2931 setUpJacksonClient ();
3032 if (testData == null ) testData = this .getTestData (MOVIES_INDEX , Movie .class );
31- }
32-
33- @ AfterAll
34- static void cleanMeilisearch () {
3533 cleanup ();
3634 }
3735
@@ -43,8 +41,6 @@ public void testCreateIndexWithoutPrimaryKey() throws Exception {
4341
4442 assertEquals (index .getUid (), indexUid );
4543 assertNull (index .getPrimaryKey ());
46-
47- client .deleteIndex (index .getUid ());
4844 }
4945
5046 /** Test Index creation without PrimaryKey with Jackson Json Handler */
@@ -57,8 +53,6 @@ public void testCreateIndexWithoutPrimaryKeyWithJacksonJsonHandler() throws Exce
5753
5854 assertEquals (index .getUid (), indexUid );
5955 assertNull (index .getPrimaryKey ());
60-
61- clientJackson .deleteIndex (index .getUid ());
6256 }
6357
6458 /** Test Index creation with PrimaryKey */
@@ -69,8 +63,6 @@ public void testCreateIndexWithPrimaryKey() throws Exception {
6963
7064 assertEquals (index .getUid (), indexUid );
7165 assertEquals (index .getPrimaryKey (), this .primaryKey );
72-
73- client .deleteIndex (index .getUid ());
7466 }
7567
7668 /** Test Index creation with PrimaryKey with Jackson Json Handler */
@@ -83,8 +75,6 @@ public void testCreateIndexWithPrimaryKeyWithJacksonJsonHandler() throws Excepti
8375
8476 assertEquals (index .getUid (), indexUid );
8577 assertEquals (index .getPrimaryKey (), this .primaryKey );
86-
87- clientJackson .deleteIndex (index .getUid ());
8878 }
8979
9080 /** Test Index creation twice doesn't throw an error: already exists */
@@ -102,8 +92,6 @@ public void testCreateIndexAlreadyExists() throws Exception {
10292 assertEquals (indexDuplicate .getUid (), indexUid );
10393 assertEquals (index .getPrimaryKey (), this .primaryKey );
10494 assertEquals (indexDuplicate .getPrimaryKey (), this .primaryKey );
105-
106- client .deleteIndex (index .getUid ());
10795 }
10896
10997 /** Test update Index PrimaryKey */
@@ -122,8 +110,6 @@ public void testUpdateIndexPrimaryKey() throws Exception {
122110 assertTrue (index instanceof Index );
123111 assertEquals (index .getUid (), indexUid );
124112 assertEquals (index .getPrimaryKey (), this .primaryKey );
125-
126- client .deleteIndex (index .getUid ());
127113 }
128114
129115 /** Test getIndex */
@@ -135,22 +121,6 @@ public void testGetIndex() throws Exception {
135121
136122 assertEquals (index .getUid (), getIndex .getUid ());
137123 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 ());
154124 }
155125
156126 /** Test getIndexes */
@@ -159,14 +129,41 @@ public void testGetIndexes() throws Exception {
159129 String [] indexUids = {"GetIndexes" , "GetIndexes2" };
160130 createEmptyIndex (indexUids [0 ]);
161131 createEmptyIndex (indexUids [1 ], this .primaryKey );
162- Index [] indexes = client .getIndexes ();
132+ Results < Index > indexes = client .getIndexes ();
163133
164- assertEquals (2 , indexes .length );
134+ assertEquals (2 , indexes .getResults (). length );
165135 assert (Arrays .asList (indexUids ).contains (indexUids [0 ]));
166136 assert (Arrays .asList (indexUids ).contains (indexUids [1 ]));
137+ }
167138
168- client .deleteIndex (indexUids [0 ]);
169- client .deleteIndex (indexUids [1 ]);
139+ /** Test getIndexes with limit */
140+ @ Test
141+ public void testGetIndexesLimit () throws Exception {
142+ int limit = 1 ;
143+ String [] indexUids = {"GetIndexesLimit" , "GetIndexesLimit2" };
144+ IndexesQuery query = new IndexesQuery ().setLimit (limit );
145+ createEmptyIndex (indexUids [0 ]);
146+ createEmptyIndex (indexUids [1 ], this .primaryKey );
147+ Results <Index > indexes = client .getIndexes (query );
148+
149+ assertEquals (limit , indexes .getResults ().length );
150+ assertEquals (limit , indexes .getLimit ());
151+ }
152+
153+ /** Test getIndexes with limit and offset */
154+ @ Test
155+ public void testGetIndexesLimitAndOffset () throws Exception {
156+ int limit = 1 ;
157+ int offset = 1 ;
158+ String [] indexUids = {"GetIndexesLimitOffset" , "GetIndexesLimitOffset2" };
159+ IndexesQuery query = new IndexesQuery ().setLimit (limit ).setOffset (offset );
160+ createEmptyIndex (indexUids [0 ]);
161+ createEmptyIndex (indexUids [1 ], this .primaryKey );
162+ Results <Index > indexes = client .getIndexes (query );
163+
164+ assertEquals (limit , indexes .getResults ().length );
165+ assertEquals (limit , indexes .getLimit ());
166+ assertEquals (offset , indexes .getOffset ());
170167 }
171168
172169 /** Test getRawIndexes */
@@ -177,16 +174,14 @@ public void testGetRawIndexes() throws Exception {
177174 createEmptyIndex (indexUids [1 ], this .primaryKey );
178175
179176 String indexes = client .getRawIndexes ();
180- JsonArray jsonIndexArray = JsonParser .parseString (indexes ).getAsJsonArray ();
177+ JsonObject jsonIndexObject = JsonParser .parseString (indexes ).getAsJsonObject ();
178+ JsonArray jsonIndexArray = jsonIndexObject .getAsJsonArray ("results" );
181179
182- assertEquals (4 , jsonIndexArray .size ());
180+ assertEquals (2 , jsonIndexArray .size ());
183181 assert (Arrays .asList (indexUids )
184182 .contains (jsonIndexArray .get (0 ).getAsJsonObject ().get ("uid" ).getAsString ()));
185183 assert (Arrays .asList (indexUids )
186184 .contains (jsonIndexArray .get (1 ).getAsJsonObject ().get ("uid" ).getAsString ()));
187-
188- client .deleteIndex (indexUids [0 ]);
189- client .deleteIndex (indexUids [1 ]);
190185 }
191186
192187 /** Test deleteIndex */
0 commit comments