11package org .typesense .api ;
22
3- import com .fasterxml .jackson .databind .JsonNode ;
4- import com .fasterxml .jackson .databind .ObjectMapper ;
5- import junit .framework .TestCase ;
6- import org .junit .Assert ;
7- import org .typesense .model .*;
3+ import org .junit .jupiter .api .BeforeEach ;
4+ import org .junit .jupiter .api .Test ;
85import org .typesense .api .exceptions .ObjectNotFound ;
6+ import org .typesense .model .CollectionSchema ;
7+ import org .typesense .model .DeleteDocumentsParameters ;
8+ import org .typesense .model .ExportDocumentsParameters ;
9+ import org .typesense .model .Field ;
10+ import org .typesense .model .ImportDocumentsParameters ;
11+ import org .typesense .model .SearchParameters ;
12+ import org .typesense .model .SearchResult ;
913
1014import java .util .ArrayList ;
1115import java .util .HashMap ;
1216import java .util .List ;
1317import java .util .Map ;
1418
15- public class DocumentsTest extends TestCase {
19+ import static org .junit .jupiter .api .Assertions .assertEquals ;
20+ import static org .junit .jupiter .api .Assertions .assertFalse ;
21+ import static org .junit .jupiter .api .Assertions .fail ;
1622
17- public Client client ;
23+ class DocumentsTest {
24+
25+ Client client ;
1826 private Helper helper ;
1927
20- public void setUp () throws Exception {
21- super . setUp ();
28+ @ BeforeEach
29+ void setUp () throws Exception {
2230 helper = new Helper ();
2331 this .client = helper .getClient ();
2432 helper .teardown ();
2533 helper .createTestCollection ();
2634 }
2735
28- public void testRetrieveDocument () throws Exception {
36+ @ Test
37+ void testRetrieveDocument () throws Exception {
2938 helper .createTestDocument ();
3039 Map <String , Object > resp = client .collections ("books" ).documents ("1" ).retrieve ();
31- Assert . assertEquals (6 , resp .size ());
32- Assert . assertEquals ("1" , resp .get ("id" ));
40+ assertEquals (6 , resp .size ());
41+ assertEquals ("1" , resp .get ("id" ));
3342 }
3443
35- public void testCreateDocument () throws Exception {
44+ @ Test
45+ void testCreateDocument () throws Exception {
3646 String [] authors = {"shakspeare" , "william" };
3747 HashMap <String , Object > hmap = new HashMap <>();
3848 hmap .put ("title" , "Romeo and juliet" );
@@ -46,15 +56,16 @@ public void testCreateDocument() throws Exception {
4656 hmap .put ("id" , "1" );
4757
4858 Map <String , Object > resp = client .collections ("books" ).documents ().create (hmap );
49- Assert . assertEquals (9 , resp .size ());
50- Assert . assertEquals ("1" , resp .get ("id" ));
59+ assertEquals (9 , resp .size ());
60+ assertEquals ("1" , resp .get ("id" ));
5161 }
5262
53- public void testUpsertDocument () throws Exception {
63+ @ Test
64+ void testUpsertDocument () throws Exception {
5465 helper .createTestDocument ();
5566
5667 Map <String , Object > resp = client .collections ("books" ).documents ("1" ).retrieve ();
57- Assert . assertEquals ("Romeo and juliet" , resp .get ("title" ));
68+ assertEquals ("Romeo and juliet" , resp .get ("title" ));
5869
5970 String [] authors = new String []{"jk" , "Rowling" };
6071 HashMap <String , Object > hmap = new HashMap <>();
@@ -69,16 +80,17 @@ public void testUpsertDocument() throws Exception {
6980 hmap .put ("id" , "1" );
7081
7182 resp = client .collections ("books" ).documents ().upsert (hmap );
72- Assert . assertEquals (9 , resp .size ());
73- Assert . assertEquals ("1" , resp .get ("id" ));
74- Assert . assertEquals ("harry potter" , resp .get ("title" ));
83+ assertEquals (9 , resp .size ());
84+ assertEquals ("1" , resp .get ("id" ));
85+ assertEquals ("harry potter" , resp .get ("title" ));
7586
7687 // try fetching the document back
7788 resp = client .collections ("books" ).documents ("1" ).retrieve ();
78- Assert . assertEquals ("harry potter" , resp .get ("title" ));
89+ assertEquals ("harry potter" , resp .get ("title" ));
7990 }
8091
81- public void testUpdateDocument () throws Exception {
92+ @ Test
93+ void testUpdateDocument () throws Exception {
8294 helper .createTestDocument ();
8395
8496 String [] authors = new String []{"JK Rowling" };
@@ -91,11 +103,12 @@ public void testUpdateDocument() throws Exception {
91103
92104 // try fetching the document back
93105 Map <String , Object > resp = client .collections ("books" ).documents ("1" ).retrieve ();
94- Assert . assertEquals ("harry potter" , resp .get ("title" ));
95- Assert . assertEquals (2000 , resp .get ("publication_year" ));
106+ assertEquals ("harry potter" , resp .get ("title" ));
107+ assertEquals (2000 , resp .get ("publication_year" ));
96108 }
97109
98- public void testDeleteDocument () throws Exception {
110+ @ Test
111+ void testDeleteDocument () throws Exception {
99112 helper .createTestDocument ();
100113 client .collections ("books" ).documents ("1" ).delete ();
101114
@@ -107,7 +120,8 @@ public void testDeleteDocument() throws Exception {
107120 }
108121 }
109122
110- public void testDeleteDocumentByQuery () throws Exception {
123+ @ Test
124+ void testDeleteDocumentByQuery () throws Exception {
111125 helper .createTestDocument ();
112126 DeleteDocumentsParameters deleteDocumentsParameters = new DeleteDocumentsParameters ();
113127 deleteDocumentsParameters .filterBy ("publication_year:=[1666]" );
@@ -121,19 +135,21 @@ public void testDeleteDocumentByQuery() throws Exception {
121135 }
122136 }
123137
124- public void testSearchDocuments () throws Exception {
138+ @ Test
139+ void testSearchDocuments () throws Exception {
125140 helper .createTestDocument ();
126141 SearchParameters searchParameters = new SearchParameters ()
127142 .q ("romeo" )
128143 .queryBy ("title,authors" )
129144 .prefix ("false,true" );
130145
131146 SearchResult searchResult = client .collections ("books" ).documents ().search (searchParameters );
132- Assert . assertEquals (1 , searchResult .getFound ().intValue ());
133- Assert . assertEquals (1 , searchResult .getHits ().size ());
147+ assertEquals (1 , searchResult .getFound ().intValue ());
148+ assertEquals (1 , searchResult .getHits ().size ());
134149 }
135150
136- public void testImport () throws Exception {
151+ @ Test
152+ void testImport () throws Exception {
137153 HashMap <String , Object > document1 = new HashMap <>();
138154 HashMap <String , Object > document2 = new HashMap <>();
139155 ImportDocumentsParameters queryParameters = new ImportDocumentsParameters ();
@@ -152,28 +168,31 @@ public void testImport() throws Exception {
152168
153169 String countriesImport = this .client .collections ("books" ).documents ()
154170 .import_ (documentList , queryParameters );
155- Assert . assertFalse (countriesImport .contains ("\" success\" :false" ));
171+ assertFalse (countriesImport .contains ("\" success\" :false" ));
156172 }
157173
158- public void testImportAsString () throws Exception {
174+ @ Test
175+ void testImportAsString () throws Exception {
159176 ImportDocumentsParameters queryParameters = new ImportDocumentsParameters ();
160177 queryParameters .action ("create" );
161178 String documentList = "{\" countryName\" : \" India\" , \" capital\" : \" Washington\" , \" gdp\" : 5215}\n " +
162179 "{\" countryName\" : \" Iran\" , \" capital\" : \" London\" , \" gdp\" : 5215}" ;
163180 String booksImport = this .client .collections ("books" ).documents ().import_ (documentList , queryParameters );
164- Assert . assertFalse (booksImport .contains ("\" success\" :false" ));
181+ assertFalse (booksImport .contains ("\" success\" :false" ));
165182 }
166183
167- public void testExportDocuments () throws Exception {
184+ @ Test
185+ void testExportDocuments () throws Exception {
168186 helper .createTestDocument ();
169187 ExportDocumentsParameters exportDocumentsParameters = new ExportDocumentsParameters ();
170188 exportDocumentsParameters .setExcludeFields ("id,publication_year,authors" );
171189 String exportStr = client .collections ("books" ).documents ().export (exportDocumentsParameters );
172190 String expectedExportStr = "{\" average_rating\" :3.2,\" ratings_count\" :124,\" title\" :\" Romeo and juliet\" }" ;
173- Assert . assertEquals (expectedExportStr , exportStr );
191+ assertEquals (expectedExportStr , exportStr );
174192 }
175193
176- public void testDirtyCreate () throws Exception {
194+ @ Test
195+ void testDirtyCreate () throws Exception {
177196 helper .createTestDocument ();
178197
179198 ImportDocumentsParameters queryParameters = new ImportDocumentsParameters ();
@@ -193,10 +212,11 @@ public void testDirtyCreate() throws Exception {
193212
194213 this .client .collections ("books" ).documents ().create (hmap , queryParameters );
195214 Map <String , Object > resp = client .collections ("books" ).documents ("1" ).retrieve ();
196- Assert . assertEquals ("1984" , resp .get ("title" ));
215+ assertEquals ("1984" , resp .get ("title" ));
197216 }
198217
199- public void testNestedObjectImport () throws Exception {
218+ @ Test
219+ void testNestedObjectImport () throws Exception {
200220 // create collection with nested objects support
201221 List <Field > fields = new ArrayList <>();
202222 fields .add (new Field ().name ("address" ).type (FieldTypes .OBJECT ).optional (true ));
@@ -215,15 +235,15 @@ public void testNestedObjectImport() throws Exception {
215235 .addTag ("weight" , "LOW" );
216236 docs .add (doc );
217237 String itemImport = this .client .collections ("items" ).documents ().import_ (docs , queryParameters );
218- Assert . assertFalse (itemImport .contains ("\" success\" :false" ));
238+ assertFalse (itemImport .contains ("\" success\" :false" ));
219239
220240 // try searching on the nested document
221241 SearchParameters searchParameters = new SearchParameters ()
222242 .q ("red" )
223243 .queryBy ("tags" );
224244
225245 SearchResult searchResult = client .collections ("items" ).documents ().search (searchParameters );
226- Assert . assertEquals (1 , searchResult .getFound ().intValue ());
227- Assert . assertEquals (1 , searchResult .getHits ().size ());
246+ assertEquals (1 , searchResult .getFound ().intValue ());
247+ assertEquals (1 , searchResult .getHits ().size ());
228248 }
229249}
0 commit comments