1
1
package com .redis .om .spring .annotations .document ;
2
2
3
3
import com .redis .om .spring .AbstractBaseDocumentTest ;
4
- import com .redis .om .spring .fixtures .document .model .SKU ;
5
- import com .redis .om .spring .fixtures .document .model .Student ;
6
- import com .redis .om .spring .fixtures .document .model .User2 ;
4
+ import com .redis .om .spring .fixtures .document .model .*;
5
+ import com .redis .om .spring .fixtures .document .repository .Doc5Repository ;
7
6
import com .redis .om .spring .fixtures .document .repository .SKUCacheRepository ;
8
7
import com .redis .om .spring .fixtures .document .repository .StudentRepository ;
9
8
import com .redis .om .spring .fixtures .document .repository .User2Repository ;
9
+ import com .redis .om .spring .search .stream .EntityStream ;
10
10
import org .junit .jupiter .api .BeforeEach ;
11
11
import org .junit .jupiter .api .Test ;
12
12
import org .springframework .beans .factory .annotation .Autowired ;
19
19
import java .util .List ;
20
20
import java .util .Set ;
21
21
import java .util .function .Function ;
22
+ import java .util .stream .Collectors ;
22
23
23
24
import static org .assertj .core .api .Assertions .assertThat ;
24
25
import static org .junit .jupiter .api .Assertions .assertAll ;
@@ -34,6 +35,12 @@ class RepositoryIssuesTest extends AbstractBaseDocumentTest {
34
35
@ Autowired
35
36
StudentRepository studentRepository ;
36
37
38
+ @ Autowired
39
+ private Doc5Repository doc5Repository ;
40
+
41
+ @ Autowired
42
+ private EntityStream entityStream ;
43
+
37
44
@ BeforeEach
38
45
void cleanUp () {
39
46
repository .deleteAll ();
@@ -54,6 +61,21 @@ void cleanUp() {
54
61
students .add (student );
55
62
}
56
63
studentRepository .saveAll (students );
64
+
65
+ doc5Repository .deleteAll ();
66
+
67
+ // Create test data
68
+ Doc5 model1 = new Doc5 ();
69
+ model1 .setAge (30 );
70
+ model1 .setRegistrationDate (LocalDateTime .now ().minusDays (5 ));
71
+ model1 .setIsActive (true );
72
+
73
+ Doc5 model2 = new Doc5 ();
74
+ model2 .setAge (40 );
75
+ model2 .setRegistrationDate (LocalDateTime .now ().minusDays (10 ));
76
+ model2 .setIsActive (false );
77
+
78
+ doc5Repository .saveAll (List .of (model1 , model2 ));
57
79
}
58
80
59
81
// RediSearchQuery wrong preparedQuery #187
@@ -130,4 +152,47 @@ void testQBEWithAliasWithHyphensAndOrderBy() {
130
152
Student result = studentRepository .findFirstByPropertyOrderByEventTimestamp (student , matcher , sortFunction );
131
153
assertThat (result .getUserName ()).isEqualTo ("Student2" );
132
154
}
155
+
156
+ @ Test
157
+ void testFindByAge () {
158
+ // This works fine
159
+ List <Doc5 > resultsByAge = doc5Repository .findByAge (30 );
160
+
161
+ assertThat (resultsByAge ).isNotEmpty ();
162
+ assertThat (resultsByAge ).hasSize (1 );
163
+ assertThat (resultsByAge .get (0 ).getAge ()).isEqualTo (30 );
164
+ }
165
+
166
+ @ Test
167
+ void testFindByDateBetween () {
168
+ // LocalDateTime query test
169
+ LocalDateTime from = LocalDateTime .now ().minusDays (20 );
170
+ LocalDateTime to = LocalDateTime .now ();
171
+
172
+ // First debug using EntityStream
173
+ List <Doc5 > resultsWithEntityStream = entityStream .of (Doc5 .class )
174
+ .filter (Doc5$ .REGISTRATION_DATE .between (from , to ))
175
+ .collect (Collectors .toList ());
176
+
177
+ // Now try repository method
178
+ List <Doc5 > resultsByDate = doc5Repository .findByRegistrationDateBetween (from , to );
179
+
180
+ assertThat (resultsByDate ).isNotEmpty ();
181
+ assertThat (resultsByDate ).hasSize (2 );
182
+ }
183
+
184
+ @ Test
185
+ void testFindByIsActive () {
186
+ // First debug using EntityStream
187
+ List <Doc5 > resultsWithEntityStream = entityStream .of (Doc5 .class )
188
+ .filter (Doc5$ .IS_ACTIVE .eq (true ))
189
+ .collect (Collectors .toList ());
190
+
191
+ // Now try repository method
192
+ List <Doc5 > resultsByActive = doc5Repository .findByIsActive (true );
193
+
194
+ assertThat (resultsByActive ).isNotEmpty ();
195
+ assertThat (resultsByActive ).hasSize (1 );
196
+ assertThat (resultsByActive .get (0 ).getIsActive ()).isTrue ();
197
+ }
133
198
}
0 commit comments