1+ package org .typesense .api ;
2+
3+ import junit .framework .TestCase ;
4+ import org .junit .jupiter .api .Test ;
5+ import org .typesense .model .CollectionResponse ;
6+ import org .typesense .model .CollectionSchema ;
7+ import org .typesense .model .Field ;
8+
9+ import java .util .ArrayList ;
10+
11+
12+ public class CollectionsTest extends TestCase {
13+
14+ public Client client ;
15+ private Helper helper ;
16+
17+ public void setUp () throws Exception {
18+ super .setUp ();
19+ helper = new Helper ();
20+ this .client = helper .getClient ();
21+ }
22+
23+ public void tearDown () throws Exception {
24+ super .tearDown ();
25+ helper .teardown ();
26+ }
27+
28+
29+ @ Test
30+ public void testRetrieveAllCollections () {
31+ helper .createTestCollection ();
32+ CollectionResponse [] collectionResponses = client .collections ().retrieve ();
33+ for (CollectionResponse c :collectionResponses )
34+ System .out .println (c );
35+ }
36+
37+ @ Test
38+ public void testRetrieveSingleCollection (){
39+ helper .createTestCollection ();
40+ System .out .println (client .collections ("books" ).retrieve ());
41+ }
42+
43+ @ Test
44+ public void testDeleteCollection (){
45+ helper .createTestCollection ();
46+ System .out .println (client .collections ("books" ).delete ());
47+ }
48+
49+ @ Test
50+ public void testCreateCollection (){
51+
52+ ArrayList <Field > fields = new ArrayList <>();
53+ fields .add (new Field ().name ("countryName" ).type (Field .TypeEnum .STRING ));
54+ fields .add (new Field ().name ("capital" ).type (Field .TypeEnum .STRING ));
55+ fields .add (new Field ().name ("gdp" ).type (Field .TypeEnum .INT32 ).facet (true ));
56+
57+ CollectionSchema collectionSchema = new CollectionSchema ();
58+ collectionSchema .name ("Countries" ).fields (fields );
59+
60+ CollectionResponse cr = client .collections ().create (collectionSchema );
61+ System .out .println (cr );
62+ }
63+ }
0 commit comments