4747import lombok .Data ;
4848import lombok .NoArgsConstructor ;
4949import okhttp3 .Address ;
50+ import org .junit .Ignore ;
5051import org .junit .jupiter .api .Test ;
5152
5253import java .io .File ;
@@ -101,6 +102,11 @@ private Database getLocalDatabase() {
101102 private Database getQuickStartDatabase () {
102103 return getLocalDatabase ("http://localhost:8181" , "cassandra" , "cassandra" , "quickstart_keyspace" );
103104 }
105+ private Database getDatabase () {
106+ return getDatabaseVector ();
107+ //return getDatabaseVector();
108+ //return getLocalDatabase();
109+ }
104110
105111 private Database getLocalDatabase (String url , String username , String password , String keyspace ) {
106112 String authToken = new UsernamePasswordTokenProvider (username , password )
@@ -115,15 +121,15 @@ private Database getLocalDatabase(String url, String username, String password,
115121
116122 @ Test
117123 public void should_get_database_different_keyspace () {
118- getQuickStartDatabase ().listTableNames ().stream ().forEach (System .out ::println );
124+ getDatabase ().listTableNames ().stream ().forEach (System .out ::println );
119125 }
120126
121127 /**
122128 * Collection Name
123129 */
124130 @ Test
125131 public void should_backwardCompatible_findEmbeddingProviders () {
126- getDatabaseVector ().getDatabaseAdmin ()
132+ getDatabase ().getDatabaseAdmin ()
127133 .findEmbeddingProviders ()
128134 .getEmbeddingProviders ()
129135 .forEach ((k ,v ) -> {
@@ -136,7 +142,7 @@ public void should_backwardCompatible_findEmbeddingProviders() {
136142 @ Test
137143 public void should_findEmbeddingProviders () {
138144 // No Model Status will return all models
139- getLocalDatabase ()
145+ getDatabase ()
140146 .getDatabaseAdmin ()
141147 .findEmbeddingProviders ()
142148 .getEmbeddingProviders ()
@@ -150,7 +156,7 @@ public void should_findEmbeddingProviders() {
150156 // filter on SUPPORTED
151157 FindEmbeddingProvidersOptions options = new FindEmbeddingProvidersOptions ()
152158 .filterModelStatus (SupportModelStatus .SUPPORTED );
153- getLocalDatabase ()
159+ getDatabase ()
154160 .getDatabaseAdmin ()
155161 .findEmbeddingProviders (options )
156162 .getEmbeddingProviders ()
@@ -167,7 +173,7 @@ public void should_findEmbeddingProviders() {
167173 */
168174 @ Test
169175 public void should_backwardCompatible_findRerankingProviders () {
170- getLocalDatabase ().getDatabaseAdmin ()
176+ getDatabase ().getDatabaseAdmin ()
171177 .findRerankingProviders (new FindRerankingProvidersOptions ()
172178 .filterModelStatus (SupportModelStatus .SUPPORTED ))
173179 .getRerankingProviders ()
@@ -180,15 +186,15 @@ public void should_backwardCompatible_findRerankingProviders() {
180186
181187 @ Test
182188 public void should_findAvailableRegions () {
183- getDatabaseVector ()
189+ getDatabase ()
184190 .getAdmin ()
185191 .findAvailableRegions (new AstraFindAvailableRegionsOptions ().onlyOrgEnabledRegions (false ))
186192 .forEach (region -> System .out .println (JsonUtils .marshall (region )));
187193 }
188194
189195 @ Test
190196 public void shouldCreateTableIndex () {
191- Table <Row > table = getLocalDatabase ()
197+ Table <Row > table = getDatabase ()
192198 .createTable ("demo_table_index" , new TableDefinition ()
193199 .addColumnText ("email" )
194200 .addColumnText ("name" )
@@ -252,8 +258,9 @@ public static final class SampleTable {
252258 */
253259
254260 @ Test
261+ @ Ignore ("You need to have a table sample_table first" )
255262 public void should_read_table_with_timeuuid () {
256- Table <SampleTable > table3 = getLocalDatabase ().getTable (SampleTable .class );
263+ Table <SampleTable > table3 = getDatabase ().getTable (SampleTable .class );
257264
258265 // Read
259266 table3 .findAll ().forEach (row -> {
@@ -269,6 +276,7 @@ public void should_read_table_with_timeuuid() {
269276 }
270277
271278 @ Test
279+ @ Ignore ("You need to have a table video_ratings first" )
272280 public void should_read_table_with_counters () {
273281
274282 Table <VideoRatingTableEntity > table2 = getLocalDatabase ()
@@ -295,7 +303,7 @@ public void should_read_table_with_counters() {
295303
296304 @ Test
297305 public void should_create_type () {
298- getDatabaseVector ().createType ("udt_one" , new TableUserDefinedTypeDefinition ()
306+ getDatabase ().createType ("udt_one" , new TableUserDefinedTypeDefinition ()
299307 .addFieldUuid ("f_uuid" )
300308 .addFieldText ("f_text" )
301309 .addFieldAscii ("f_ascii" )
@@ -307,20 +315,15 @@ public void should_create_type() {
307315 , CreateTypeOptions .IF_NOT_EXISTS );
308316 }
309317
310- @ Test
311- public void should_drop_type () {
312- getLocalDatabase ().dropType ("udt_one" ,DropTypeOptions .IF_EXISTS );
313- }
314-
315318 @ Test
316319 public void should_alter_type_rename_fields () {
317- getLocalDatabase ().alterType ("udt_one" ,
320+ getDatabase ().alterType ("udt_one" ,
318321 new AlterTypeRenameFields ().addField ("f_bigint" , "f_bigint2" ));
319322 }
320323
321324 @ Test
322325 public void should_alter_type_add_fields () {
323- getLocalDatabase ().alterType ("udt_one" ,
326+ getDatabase ().alterType ("udt_one" ,
324327 new AlterTypeAddFields ()
325328 .addField ("x_bigint2" , new TableUserDefinedTypeFieldDefinition (BIGINT ))
326329 .addField ("x_text2" , new TableUserDefinedTypeFieldDefinition (TEXT ))
@@ -330,14 +333,19 @@ public void should_alter_type_add_fields() {
330333 .addField ("x_int2" , new TableUserDefinedTypeFieldDefinition (INT )));
331334 }
332335
336+ @ Test
337+ public void should_drop_type () {
338+ getDatabase ().dropType ("udt_one" ,DropTypeOptions .IF_EXISTS );
339+ }
340+
333341 @ Test
334342 public void should_create_type_bean () {
335- getQuickStartDatabase ().createType (SampleUdtAddress .class , null );
343+ getDatabase ().createType (SampleUdtAddress .class , null );
336344 }
337345
338346 @ Test
339347 public void should_create_table_with_udts () {
340- getQuickStartDatabase ().createTable ("demo_table_with_udts_3" ,
348+ getDatabase ().createTable ("demo_table_with_udts_3" ,
341349 new TableDefinition ()
342350 .addColumnText ("email" )
343351 .addColumnText ("name" )
@@ -351,7 +359,7 @@ public void should_create_table_with_udts() {
351359
352360 @ Test
353361 public void should_alter_table_with_udts () {
354- getQuickStartDatabase ()
362+ getDatabase ()
355363 .getTable ("demo_table_with_udts_3" )
356364 .alter (new AlterTableAddColumns ()
357365 .addColumnUserDefinedType ("member_x" , "member" )
@@ -361,10 +369,9 @@ public void should_alter_table_with_udts() {
361369
362370 @ Test
363371 public void should_list_tables_with_udt () {
364- getQuickStartDatabase ().listTables ().forEach (System .out ::println );
372+ getDatabase ().listTables ().forEach (System .out ::println );
365373 }
366374
367-
368375 @ Test
369376 public void should_create_index_on_map () {
370377 // Create a Table with a Map
@@ -373,7 +380,7 @@ public void should_create_index_on_map() {
373380 .addColumnMap ("example_map_column" , TableColumnTypes .TEXT , TableColumnTypes .TEXT )
374381 .partitionKey ("email" );
375382
376- Table <Row > table = getQuickStartDatabase ()
383+ Table <Row > table = getDatabase ()
377384 .createTable ("example_index_table" , tableDefinition );
378385
379386 // Index a column
@@ -401,7 +408,7 @@ public static class PersonAddress{
401408 @ Test
402409 public void should_insert_table_with_udts () {
403410
404- Database db = getDatabaseVector ();
411+ Database db = getDatabase ();
405412
406413 db .createType ("udt_address" , new TableUserDefinedTypeDefinition ()
407414 .addFieldText ("city" )
@@ -431,15 +438,15 @@ public void should_insert_table_with_udts() {
431438
432439 @ Test
433440 public void should_update_table_with_udts () {
434- Database db = getDatabaseVector ();
441+ Database db = getDatabase ();
435442 Table <Row > table = db .getTable ("person" );
436443 table .updateOne (eq ("name" , "sara" ),
437444 new TableUpdateOperation ().set ("address" , Map .of ("city" ,"Marseille" )));
438445 }
439446
440447 @ Test
441448 public void should_update_table_with_udts_2 () {
442- Database db = getDatabaseVector ();
449+ Database db = getDatabase ();
443450 Table <Row > table = db .getTable ("person" );
444451 table .updateOne (eq ("name" , "sara" ),
445452 new TableUpdateOperation ().set ("address" , Map
@@ -487,18 +494,6 @@ public void should_projection_table_with_udts() {
487494
488495 }
489496
490- @ Test
491- public void should_projection_table_with_sub_udt () {
492- Database db = getDatabaseVector ();
493- Table <Row > table = db .getTable ("person" );
494- TableFindCursor <Row , Row > r = table .find (new TableFindOptions ().projection (
495- Projection .include ("address.country" )));
496- r .forEach (row -> {
497- System .out .println ("Row: " + row );
498- });
499-
500- }
501-
502497 @ Test
503498 public void should_filter_all_udt () {
504499 Database db = getDatabaseVector ();
@@ -516,25 +511,24 @@ public void should_filter_keys_udtmap() {
516511 Database db = getDatabaseVector ();
517512 Table <Row > table = db .getTable ("person" );
518513
519- // Filter filter1 = new Filter();
520- // Map values = new HashMap();
521- // values.put("$values",
522- // Map.of("$in",
523- // List.of(Map.of("city","Marseille","zipcode",13000))
524- // )
525- // );
526- // filter1.put("address_map", values);
527- // table.find(filter1).forEach(row -> {
528- // System.out.println("Row: " + row);
529- // });
514+ // Manual Filters
515+ Filter filter1 = new Filter ();
516+ Map values = new HashMap ();
517+ values .put ("$values" ,
518+ Map .of ("$in" ,
519+ List .of (Map .of ("city" ,"Marseille" ,"zipcode" ,13000 ))
520+ )
521+ );
522+ filter1 .put ("address_map" , values );
523+ table .find (filter1 ).forEach (row -> {
524+ System .out .println ("Row: " + row );
525+ });
530526
531527 Map <?,?> innerConditions = Map .of ("city" ,"Marseille" ,"zipcode" ,13000 );
532528 Filter filterValues = Filters .values ("address_map" , Filters .in (innerConditions ).documentMap );
533529 table .find (filterValues ).forEach (row -> {
534530 System .out .println ("Row: " + row );
535531 });
536-
537-
538532 }
539533
540534 @ Test
@@ -565,6 +559,9 @@ public void should_non_string_keys() {
565559 .add ("normal_map" , Map .of ("k1" , "v1" , "k2" , "v2" ));
566560 tableExo .insertOne (entry1 );
567561
562+ tableExo .insertOne (new Row ()
563+ .addText ("name" , "entry2" )
564+ .addMap ("exotic_map_1" , Map .of ()));
568565 }
569566
570567 @ Data
0 commit comments