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 ;
1214import com .meilisearch .sdk .model .TaskInfo ;
1315import com .meilisearch .sdk .utils .Movie ;
1416import java .util .Arrays ;
15- import org .junit .jupiter .api .AfterAll ;
17+ import org .junit .jupiter .api .AfterEach ;
1618import org .junit .jupiter .api .BeforeEach ;
1719import org .junit .jupiter .api .Tag ;
1820import org .junit .jupiter .api .Test ;
@@ -30,8 +32,8 @@ public void initialize() {
3032 if (testData == null ) testData = this .getTestData (MOVIES_INDEX , Movie .class );
3133 }
3234
33- @ AfterAll
34- static void cleanMeilisearch () {
35+ @ AfterEach
36+ public void cleanMeilisearch () {
3537 cleanup ();
3638 }
3739
@@ -43,8 +45,6 @@ public void testCreateIndexWithoutPrimaryKey() throws Exception {
4345
4446 assertEquals (index .getUid (), indexUid );
4547 assertNull (index .getPrimaryKey ());
46-
47- client .deleteIndex (index .getUid ());
4848 }
4949
5050 /** Test Index creation without PrimaryKey with Jackson Json Handler */
@@ -57,8 +57,6 @@ public void testCreateIndexWithoutPrimaryKeyWithJacksonJsonHandler() throws Exce
5757
5858 assertEquals (index .getUid (), indexUid );
5959 assertNull (index .getPrimaryKey ());
60-
61- clientJackson .deleteIndex (index .getUid ());
6260 }
6361
6462 /** Test Index creation with PrimaryKey */
@@ -69,8 +67,6 @@ public void testCreateIndexWithPrimaryKey() throws Exception {
6967
7068 assertEquals (index .getUid (), indexUid );
7169 assertEquals (index .getPrimaryKey (), this .primaryKey );
72-
73- client .deleteIndex (index .getUid ());
7470 }
7571
7672 /** Test Index creation with PrimaryKey with Jackson Json Handler */
@@ -83,8 +79,6 @@ public void testCreateIndexWithPrimaryKeyWithJacksonJsonHandler() throws Excepti
8379
8480 assertEquals (index .getUid (), indexUid );
8581 assertEquals (index .getPrimaryKey (), this .primaryKey );
86-
87- clientJackson .deleteIndex (index .getUid ());
8882 }
8983
9084 /** Test Index creation twice doesn't throw an error: already exists */
@@ -102,8 +96,6 @@ public void testCreateIndexAlreadyExists() throws Exception {
10296 assertEquals (indexDuplicate .getUid (), indexUid );
10397 assertEquals (index .getPrimaryKey (), this .primaryKey );
10498 assertEquals (indexDuplicate .getPrimaryKey (), this .primaryKey );
105-
106- client .deleteIndex (index .getUid ());
10799 }
108100
109101 /** Test update Index PrimaryKey */
@@ -122,8 +114,6 @@ public void testUpdateIndexPrimaryKey() throws Exception {
122114 assertTrue (index instanceof Index );
123115 assertEquals (index .getUid (), indexUid );
124116 assertEquals (index .getPrimaryKey (), this .primaryKey );
125-
126- client .deleteIndex (index .getUid ());
127117 }
128118
129119 /** Test getIndex */
@@ -135,22 +125,6 @@ public void testGetIndex() throws Exception {
135125
136126 assertEquals (index .getUid (), getIndex .getUid ());
137127 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 ());
154128 }
155129
156130 /** Test getIndexes */
@@ -159,14 +133,41 @@ public void testGetIndexes() throws Exception {
159133 String [] indexUids = {"GetIndexes" , "GetIndexes2" };
160134 createEmptyIndex (indexUids [0 ]);
161135 createEmptyIndex (indexUids [1 ], this .primaryKey );
162- Index [] indexes = client .getIndexes ();
136+ Results < Index > indexes = client .getIndexes ();
163137
164- assertEquals (2 , indexes .length );
138+ assertEquals (2 , indexes .getResults (). length );
165139 assert (Arrays .asList (indexUids ).contains (indexUids [0 ]));
166140 assert (Arrays .asList (indexUids ).contains (indexUids [1 ]));
141+ }
142+
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 );
167167
168- client .deleteIndex (indexUids [0 ]);
169- client .deleteIndex (indexUids [1 ]);
168+ assertEquals (limit , indexes .getResults ().length );
169+ assertEquals (limit , indexes .getLimit ());
170+ assertEquals (offset , indexes .getOffset ());
170171 }
171172
172173 /** Test getRawIndexes */
@@ -177,16 +178,14 @@ public void testGetRawIndexes() throws Exception {
177178 createEmptyIndex (indexUids [1 ], this .primaryKey );
178179
179180 String indexes = client .getRawIndexes ();
180- JsonArray jsonIndexArray = JsonParser .parseString (indexes ).getAsJsonArray ();
181+ JsonObject jsonIndexObject = JsonParser .parseString (indexes ).getAsJsonObject ();
182+ JsonArray jsonIndexArray = jsonIndexObject .getAsJsonArray ("results" );
181183
182- assertEquals (4 , jsonIndexArray .size ());
184+ assertEquals (2 , jsonIndexArray .size ());
183185 assert (Arrays .asList (indexUids )
184186 .contains (jsonIndexArray .get (0 ).getAsJsonObject ().get ("uid" ).getAsString ()));
185187 assert (Arrays .asList (indexUids )
186188 .contains (jsonIndexArray .get (1 ).getAsJsonObject ().get ("uid" ).getAsString ()));
187-
188- client .deleteIndex (indexUids [0 ]);
189- client .deleteIndex (indexUids [1 ]);
190189 }
191190
192191 /** Test deleteIndex */
0 commit comments