1
1
package tech .ydb .yoj .repository .test ;
2
2
3
- import org .assertj .core .api .Assertions ;
4
3
import org .junit .Test ;
5
4
import tech .ydb .yoj .databind .expression .FilterExpression ;
6
5
import tech .ydb .yoj .databind .expression .OrderExpression ;
@@ -72,23 +71,23 @@ public void basic() {
72
71
.orderBy (orderBy )
73
72
.filter (filter )
74
73
.build ());
75
- Assertions . assertThat (page1 ).containsExactly (p3 );
74
+ assertThat (page1 ).containsExactly (p3 );
76
75
77
76
ListResult <Project > page2 = listProjects (ListRequest .builder (Project .class )
78
77
.pageSize (1 )
79
78
.orderBy (orderBy )
80
79
.filter (filter )
81
80
.offset (1 )
82
81
.build ());
83
- Assertions . assertThat (page2 ).containsExactly (p2 );
82
+ assertThat (page2 ).containsExactly (p2 );
84
83
85
84
ListResult <Project > page3 = listProjects (ListRequest .builder (Project .class )
86
85
.pageSize (1 )
87
86
.orderBy (orderBy )
88
87
.filter (filter )
89
88
.offset (2 )
90
89
.build ());
91
- Assertions . assertThat (page3 ).containsExactly (p1 );
90
+ assertThat (page3 ).containsExactly (p1 );
92
91
assertThat (page3 .isLastPage ()).isTrue ();
93
92
});
94
93
}
@@ -106,7 +105,7 @@ public void complexIdRange() {
106
105
.pageSize (3 )
107
106
.filter (fb -> fb .where ("id.a" ).eq (999_999 ))
108
107
.build ());
109
- Assertions . assertThat (page ).containsExactly (c3 , c2 , c1 );
108
+ assertThat (page ).containsExactly (c3 , c2 , c1 );
110
109
assertThat (page .isLastPage ()).isTrue ();
111
110
});
112
111
}
@@ -124,7 +123,7 @@ public void complexIdFullScan() {
124
123
.pageSize (3 )
125
124
.filter (fb -> fb .where ("id.c" ).eq ("UUU" ))
126
125
.build ());
127
- Assertions . assertThat (page ).containsExactly (c2 );
126
+ assertThat (page ).containsExactly (c2 );
128
127
assertThat (page .isLastPage ()).isTrue ();
129
128
});
130
129
}
@@ -203,7 +202,7 @@ public void defaultOrderingIsByIdAscending() {
203
202
ListResult <Complex > page = listComplex (ListRequest .builder (Complex .class )
204
203
.pageSize (4 )
205
204
.build ());
206
- Assertions . assertThat (page ).containsExactly (c4 , c3 , c2 , c1 );
205
+ assertThat (page ).containsExactly (c4 , c3 , c2 , c1 );
207
206
assertThat (page .isLastPage ()).isTrue ();
208
207
});
209
208
}
@@ -222,7 +221,7 @@ public void and() {
222
221
.pageSize (3 )
223
222
.filter (fb -> fb .where ("id.a" ).eq (1 ).and ("id.b" ).gte (100L ).and ("id.b" ).lte (300L ))
224
223
.build ());
225
- Assertions . assertThat (page ).containsExactly (c1 , c2 , c3 );
224
+ assertThat (page ).containsExactly (c1 , c2 , c3 );
226
225
assertThat (page .isLastPage ()).isTrue ();
227
226
});
228
227
}
@@ -254,7 +253,7 @@ public void embeddedNulls() {
254
253
.pageSize (1 )
255
254
.build ()));
256
255
257
- Assertions . assertThat (lst ).isEmpty ();
256
+ assertThat (lst ).isEmpty ();
258
257
assertThat (lst .isLastPage ()).isTrue ();
259
258
}
260
259
@@ -302,7 +301,7 @@ public void simpleIdIn() {
302
301
.filter (filter )
303
302
.orderBy (orderBy )
304
303
.build ());
305
- Assertions . assertThat (page ).containsExactlyInAnyOrder (p1 , p2 , p3 );
304
+ assertThat (page ).containsExactlyInAnyOrder (p1 , p2 , p3 );
306
305
assertThat (page .isLastPage ()).isTrue ();
307
306
});
308
307
}
@@ -326,7 +325,7 @@ public void complexIdIn() {
326
325
)
327
326
.orderBy (ob -> ob .orderBy ("id" ).descending ())
328
327
.build ());
329
- Assertions . assertThat (page ).containsExactly (c1 , c3 );
328
+ assertThat (page ).containsExactly (c1 , c3 );
330
329
assertThat (page .isLastPage ()).isTrue ();
331
330
});
332
331
}
@@ -348,7 +347,7 @@ public void complexUnixTimestampRelational() {
348
347
.filter (fb -> fb .where ("id.a" ).in (999_999 , 999_000 ).and ("id.b" ).gte (now ).and ("id.b" ).lt (nowPlus2 ))
349
348
.orderBy (ob -> ob .orderBy ("id.a" ).descending ())
350
349
.build ());
351
- Assertions . assertThat (page ).containsExactlyInAnyOrder (c1 , c2 );
350
+ assertThat (page ).containsExactlyInAnyOrder (c1 , c2 );
352
351
assertThat (page .isLastPage ()).isTrue ();
353
352
});
354
353
}
@@ -370,7 +369,7 @@ public void complexUnixTimestampIn() {
370
369
.filter (fb -> fb .where ("id.a" ).in (999_999 , 999_000 ).and ("id.b" ).in (now , nowPlus2 ))
371
370
.orderBy (ob -> ob .orderBy ("id.a" ).descending ())
372
371
.build ());
373
- Assertions . assertThat (page ).containsExactly (c1 , c3 );
372
+ assertThat (page ).containsExactly (c1 , c3 );
374
373
assertThat (page .isLastPage ()).isTrue ();
375
374
});
376
375
}
@@ -389,7 +388,7 @@ public void or() {
389
388
.where ("id" ).eq ("uuid002" ).or ("id" ).eq ("uuid777" )
390
389
.build ())
391
390
.build ());
392
- Assertions . assertThat (page ).containsExactly (p1 , p2 );
391
+ assertThat (page ).containsExactly (p1 , p2 );
393
392
assertThat (page .isLastPage ()).isTrue ();
394
393
});
395
394
}
@@ -408,7 +407,7 @@ public void notOr() {
408
407
.where ("id" ).eq ("uuid002" ).or ("id" ).eq ("uuid777" )
409
408
.build ()))
410
409
.build ());
411
- Assertions . assertThat (page ).containsExactly (inOutput );
410
+ assertThat (page ).containsExactly (inOutput );
412
411
assertThat (page .isLastPage ()).isTrue ();
413
412
});
414
413
}
@@ -427,7 +426,7 @@ public void notRel() {
427
426
.where ("id" ).gt ("uuid002" )
428
427
.build ()))
429
428
.build ());
430
- Assertions . assertThat (page ).containsExactly (p1 );
429
+ assertThat (page ).containsExactly (p1 );
431
430
assertThat (page .isLastPage ()).isTrue ();
432
431
});
433
432
}
@@ -446,7 +445,7 @@ public void notIn() {
446
445
.where ("id" ).in ("uuid002" , "uuid777" )
447
446
.build ()))
448
447
.build ());
449
- Assertions . assertThat (page ).containsExactly (inOutput );
448
+ assertThat (page ).containsExactly (inOutput );
450
449
assertThat (page .isLastPage ()).isTrue ();
451
450
});
452
451
}
@@ -502,7 +501,7 @@ public void listByNamesWithUnderscores() {
502
501
.where ("customNamedColumn" ).eq ("CUSTOM NAMED COLUMN" )
503
502
.build ())
504
503
.build ());
505
- Assertions . assertThat (page ).containsExactly (tf );
504
+ assertThat (page ).containsExactly (tf );
506
505
assertThat (page .isLastPage ()).isTrue ();
507
506
});
508
507
}
@@ -703,6 +702,29 @@ public void endsWithEscaped() {
703
702
});
704
703
}
705
704
705
+
706
+ @ Test
707
+ public void view () {
708
+ LogEntry e1 = new LogEntry (new LogEntry .Id ("log1" , 1L ), LogEntry .Level .ERROR , "earliest msg" );
709
+ LogEntry notInOutput = new LogEntry (new LogEntry .Id ("log2" , 2L ), LogEntry .Level .DEBUG , "will be ignored" );
710
+ LogEntry e2 = new LogEntry (new LogEntry .Id ("log1" , 4L ), LogEntry .Level .WARN , "middle msg" );
711
+ LogEntry e3 = new LogEntry (new LogEntry .Id ("log1" , 5L ), LogEntry .Level .INFO , "latest msg" );
712
+ db .tx (() -> db .logEntries ().insert (e1 , e2 , notInOutput , e3 ));
713
+
714
+ db .tx (() -> {
715
+ ViewListResult <LogEntry , LogEntry .Message > page = listLogMessages (ListRequest .builder (LogEntry .class )
716
+ .pageSize (100 )
717
+ .filter (fb -> fb .where ("id.logId" ).eq ("log1" ))
718
+ .build ());
719
+ assertThat (page ).containsExactly (
720
+ new LogEntry .Message (new LogEntry .Id ("log1" , 1L ), "earliest msg" ),
721
+ new LogEntry .Message (new LogEntry .Id ("log1" , 4L ), "middle msg" ),
722
+ new LogEntry .Message (new LogEntry .Id ("log1" , 5L ), "latest msg" )
723
+ );
724
+ assertThat (page .isLastPage ()).isTrue ();
725
+ });
726
+ }
727
+
706
728
protected final ListResult <Project > listProjects (ListRequest <Project > request ) {
707
729
return db .projects ().list (request );
708
730
}
0 commit comments