1
- /*
2
- * This Java source file was generated by the Gradle 'init' task.
3
- */
4
1
package com .meilisearch .sdk ;
5
2
6
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
7
4
5
+ import java .util .Arrays ;
8
6
import com .google .gson .Gson ;
9
-
10
7
import org .junit .jupiter .api .BeforeEach ;
8
+ import org .junit .jupiter .api .AfterAll ;
11
9
import org .junit .jupiter .api .Test ;
12
10
13
11
public class IndexesTest {
14
12
15
13
Client ms ;
16
14
Gson gson = new Gson ();
17
-
18
- String indexUid = "movies" ;
19
- String indexUid2 = "movies2" ;
20
15
String primaryKey = "id" ;
21
16
22
17
@ BeforeEach
23
- public void initializeClient () {
18
+ public void initializeClient () throws Exception {
24
19
ms = new Client (new Config ("http://localhost:7700" , "masterKey" ));
25
20
}
26
21
22
+ @ AfterAll
23
+ static void cleanMeiliSearch () throws Exception {
24
+ Client ms = new Client (new Config ("http://localhost:7700" , "masterKey" ));
25
+ Index [] indexes = ms .getIndexList ();
26
+ for (int i = 0 ; i < indexes .length ; i ++) {
27
+ ms .deleteIndex (indexes [i ].uid );
28
+ }
29
+ }
30
+
27
31
/**
28
32
* Test Index creation without PrimaryKey
29
33
*/
30
34
@ Test
31
35
public void testCreateIndexWithoutPrimaryKey () throws Exception {
32
- ms .createIndex (this .indexUid );
33
- Index index = ms .getIndex (this .indexUid );
34
- assertEquals (index .uid , this .indexUid );
36
+ String indexUid = "IndexesTest" ;
37
+ ms .createIndex (indexUid );
38
+ Index index = ms .getIndex (indexUid );
39
+ assertEquals (index .uid , indexUid );
35
40
assertEquals (index .primaryKey , null );
36
41
ms .deleteIndex (index .uid );
37
42
}
@@ -41,9 +46,10 @@ public void testCreateIndexWithoutPrimaryKey() throws Exception {
41
46
*/
42
47
@ Test
43
48
public void testCreateIndexWithPrimaryKey () throws Exception {
44
- ms .createIndex (this .indexUid , this .primaryKey );
45
- Index index = ms .getIndex (this .indexUid );
46
- assertEquals (index .uid , this .indexUid );
49
+ String indexUid = "IndexesTest" ;
50
+ ms .createIndex (indexUid , this .primaryKey );
51
+ Index index = ms .getIndex (indexUid );
52
+ assertEquals (index .uid , indexUid );
47
53
assertEquals (index .primaryKey , this .primaryKey );
48
54
ms .deleteIndex (index .uid );
49
55
}
@@ -53,13 +59,14 @@ public void testCreateIndexWithPrimaryKey() throws Exception {
53
59
*/
54
60
@ Test
55
61
public void testUpdateIndexPrimaryKey () throws Exception {
56
- ms .createIndex (this .indexUid );
57
- Index index = ms .getIndex (this .indexUid );
58
- assertEquals (index .uid , this .indexUid );
62
+ String indexUid = "IndexesTest" ;
63
+ ms .createIndex (indexUid );
64
+ Index index = ms .getIndex (indexUid );
65
+ assertEquals (index .uid , indexUid );
59
66
assertEquals (index .primaryKey , null );
60
- ms .updateIndex (this . indexUid , this .primaryKey );
61
- index = ms .getIndex (this . indexUid );
62
- assertEquals (index .uid , this . indexUid );
67
+ ms .updateIndex (indexUid , this .primaryKey );
68
+ index = ms .getIndex (indexUid );
69
+ assertEquals (index .uid , indexUid );
63
70
assertEquals (index .primaryKey , this .primaryKey );
64
71
ms .deleteIndex (index .uid );
65
72
}
@@ -69,17 +76,16 @@ public void testUpdateIndexPrimaryKey() throws Exception {
69
76
*/
70
77
@ Test
71
78
public void testGetIndexList () throws Exception {
72
- ms .createIndex (this .indexUid );
73
- ms .createIndex (this .indexUid2 , this .primaryKey );
74
- Index index1 = ms .getIndex (this .indexUid );
75
- Index index2 = ms .getIndex (this .indexUid2 );
79
+ String [] indexUids = {"IndexesTest" , "IndexesTest2" };
80
+ ms .createIndex (indexUids [0 ]);
81
+ ms .createIndex (indexUids [1 ], this .primaryKey );
82
+ Index index1 = ms .getIndex (indexUids [0 ]);
83
+ Index index2 = ms .getIndex (indexUids [1 ]);
76
84
Index [] indexes = ms .getIndexList ();
77
- assertEquals (indexes [0 ].uid , this .indexUid );
78
- assertEquals (indexes [1 ].uid , this .indexUid2 );
79
- assertEquals (indexes [1 ].primaryKey , this .primaryKey );
80
- ms .deleteIndex (indexes [0 ].uid );
81
- ms .deleteIndex (indexes [1 ].uid );
82
- }
83
-
84
-
85
+ assertEquals (indexes .length , 2 );
86
+ assert (Arrays .stream (indexUids ).anyMatch (indexUids [0 ]::equals ));
87
+ assert (Arrays .stream (indexUids ).anyMatch (indexUids [1 ]::equals ));
88
+ ms .deleteIndex (indexUids [0 ]);
89
+ ms .deleteIndex (indexUids [1 ]);
90
+ }
85
91
}
0 commit comments