1919import jakarta .nosql .column .ColumnDeleteQuery ;
2020import jakarta .nosql .column .ColumnEntity ;
2121import jakarta .nosql .column .ColumnFamilyManager ;
22+ import jakarta .nosql .column .ColumnQuery ;
2223import org .junit .jupiter .api .Assertions ;
2324import org .junit .jupiter .params .ParameterizedTest ;
2425
26+ import java .time .Duration ;
27+ import java .util .Collections ;
2528import java .util .List ;
2629import java .util .Optional ;
30+ import java .util .concurrent .TimeUnit ;
2731import java .util .stream .Collectors ;
2832
2933import static jakarta .nosql .column .ColumnDeleteQuery .delete ;
34+ import static org .junit .jupiter .api .Assertions .assertEquals ;
35+ import static org .junit .jupiter .api .Assertions .assertThrows ;
3036import static org .junit .jupiter .api .Assumptions .assumeTrue ;
3137
3238public class ColumnFamilyManagerTest {
@@ -53,12 +59,12 @@ public void shouldInsert(ColumnArgument argument) {
5359 public void shouldReturnErrorWhenInsertIsNull (ColumnArgument argument ) {
5460 assumeTrue (argument .isEmpty ());
5561 ColumnFamilyManager manager = getManager ();
56- Assertions . assertThrows (NullPointerException .class , () -> manager .insert ((ColumnEntity ) null ));
62+ assertThrows (NullPointerException .class , () -> manager .insert ((ColumnEntity ) null ));
5763 }
5864
5965 @ ParameterizedTest
6066 @ ColumnSource ("column_insert_ttl.properties" )
61- public void shouldInsert (ColumnArgument argument ) {
67+ public void shouldInsertTTL (ColumnArgument argument ) throws InterruptedException {
6268 assumeTrue (argument .isEmpty ());
6369 ColumnFamilyManager manager = getManager ();
6470 Optional <ColumnEntity > entityOptional = argument .getQuery ().stream ().flatMap (manager ::query )
@@ -69,8 +75,22 @@ public void shouldInsert(ColumnArgument argument) {
6975
7076 final Column id = entity .find (argument .getIdName ())
7177 .orElseThrow (() -> new ColumnDriverException ("Should return the id in the entity" ));
72- ColumnDeleteQuery deleteQuery = delete ().from (entity .getName ()).where (id .getName ()).eq (id .get ()).build ();
73- manager .delete (deleteQuery );
78+
79+ TimeUnit .SECONDS .sleep (2L );
80+ final ColumnQuery query = ColumnQuery .select ().from (entity .getName ()).where (id .getName ()).eq (id .get ()).build ();
81+ final long count = manager .select (query ).count ();
82+ assertEquals (0L , count );
83+ }
84+
85+ @ ParameterizedTest
86+ @ ColumnSource ("column_insert_ttl.properties" )
87+ public void shouldReturnErrorWhenInsertTTLHasNullParameter (ColumnArgument argument ) throws InterruptedException {
88+ assumeTrue (argument .isEmpty ());
89+ ColumnFamilyManager manager = getManager ();
90+ assertThrows (NullPointerException .class ,
91+ () -> manager .insert ((ColumnEntity ) null , Duration .ZERO ));
92+ assertThrows (NullPointerException .class ,
93+ () -> manager .insert (ColumnEntity .of ("entity" ), null ));
7494 }
7595
7696 @ ParameterizedTest
@@ -88,7 +108,7 @@ public void shouldInsertIterable(ColumnArgument argument) {
88108 .map (Column ::get )
89109 .collect (Collectors .toList ());
90110
91- Assertions . assertEquals (argument .getQuery ().size (), ids .size ());
111+ assertEquals (argument .getQuery ().size (), ids .size ());
92112
93113 ColumnDeleteQuery deleteQuery = delete ().from (entities .get (0 ).getName ())
94114 .where (argument .getIdName ()).in (ids ).build ();
@@ -100,7 +120,42 @@ public void shouldInsertIterable(ColumnArgument argument) {
100120 public void shouldReturnErrorWhenInsertIterableIsNull (ColumnArgument argument ) {
101121 assumeTrue (argument .isEmpty ());
102122 ColumnFamilyManager manager = getManager ();
103- Assertions .assertThrows (NullPointerException .class , () -> manager .insert ((Iterable <ColumnEntity >) null ));
123+ assertThrows (NullPointerException .class , () -> manager .insert ((Iterable <ColumnEntity >) null ));
124+ }
125+
126+ @ ParameterizedTest
127+ @ ColumnSource ("column_insert_iterable_ttl.properties" )
128+ public void shouldInsertIterableTTL (ColumnArgument argument ) throws InterruptedException {
129+ assumeTrue (argument .isEmpty ());
130+ ColumnFamilyManager manager = getManager ();
131+ List <ColumnEntity > entities = argument .getQuery ().stream ().flatMap (manager ::query )
132+ .collect (Collectors .toList ());
133+ Assertions .assertEquals (argument .getQuery ().size (), entities .size ());
134+
135+ final List <Object > ids = entities .stream ().map (c -> c .find (argument .getIdName ()))
136+ .filter (Optional ::isPresent )
137+ .map (Optional ::get ).map (Column ::get ).collect (Collectors .toList ());
138+
139+ TimeUnit .SECONDS .sleep (2L );
140+ final ColumnQuery query = ColumnQuery .select ().from (entities .get (0 ).getName ())
141+ .where (argument .getIdName ()).in (ids ).build ();
142+ final long count = manager .select (query ).count ();
143+ assertEquals (0L , count );
144+ }
145+
146+ @ ParameterizedTest
147+ @ ColumnSource ("column_insert_iterable_ttl.properties" )
148+ public void shouldReturnErrorWhenInsertIterableTTL (ColumnArgument argument ) throws InterruptedException {
149+ assumeTrue (argument .isEmpty ());
150+ ColumnFamilyManager manager = getManager ();
151+
152+ assertThrows (NullPointerException .class , () -> manager .insert ((Iterable <ColumnEntity >) null ,
153+ null ));
154+ assertThrows (NullPointerException .class , () -> manager .insert ((Iterable <ColumnEntity >) null ,
155+ Duration .ZERO ));
156+ assertThrows (NullPointerException .class , () -> manager
157+ .insert (Collections .singletonList (ColumnEntity .of ("entity" )),
158+ null ));
104159 }
105160
106161 private ColumnFamilyManager getManager () {
0 commit comments