1
+ package com .redis .om .spring .annotations .document ;
2
+
3
+ import com .redis .om .spring .AbstractBaseDocumentTest ;
4
+ import com .redis .om .spring .fixtures .document .model .FlightWithLocation ;
5
+ import com .redis .om .spring .fixtures .document .repository .FlightWithLocationRepository ;
6
+ import com .redis .om .spring .fixtures .document .repository .FlightWithLocationRepository .FlightProjection ;
7
+ import com .redis .om .spring .fixtures .document .repository .FlightWithLocationRepository .FlightProjectionWithoutPoint ;
8
+ import org .junit .jupiter .api .BeforeEach ;
9
+ import org .junit .jupiter .api .Test ;
10
+ import org .springframework .beans .factory .annotation .Autowired ;
11
+ import org .springframework .data .geo .Point ;
12
+
13
+ import java .util .NoSuchElementException ;
14
+
15
+ import static org .assertj .core .api .Assertions .assertThat ;
16
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
17
+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
18
+
19
+ /**
20
+ * Test for issue #661 - NoSuchElementException when using Point in projection interface
21
+ * https://github.com/redis/redis-om-spring/issues/661
22
+ */
23
+ class PointProjectionTest extends AbstractBaseDocumentTest {
24
+
25
+ @ Autowired
26
+ private FlightWithLocationRepository repository ;
27
+
28
+ @ BeforeEach
29
+ void setup () {
30
+ repository .deleteAll ();
31
+
32
+ // Create test data
33
+ FlightWithLocation flight1 = new FlightWithLocation ("AA123" , "Flight to Paris" , new Point (2.3522 , 48.8566 ));
34
+ FlightWithLocation flight2 = new FlightWithLocation ("BA456" , "Flight to London" , new Point (-0.1276 , 51.5074 ));
35
+ FlightWithLocation flight3 = new FlightWithLocation ("LH789" , "Flight to Berlin" , new Point (13.4050 , 52.5200 ));
36
+
37
+ repository .save (flight1 );
38
+ repository .save (flight2 );
39
+ repository .save (flight3 );
40
+ }
41
+
42
+ @ Test
43
+ void testProjectionWithoutPointWorks () {
44
+ // This should work fine - projection without Point field
45
+ FlightProjectionWithoutPoint projection = repository .findByName ("Flight to Paris" );
46
+
47
+ assertThat (projection ).isNotNull ();
48
+ assertThat (projection .getNumber ()).isEqualTo ("AA123" );
49
+ assertThat (projection .getName ()).isEqualTo ("Flight to Paris" );
50
+ }
51
+
52
+ @ Test
53
+ void testProjectionWithPointNowWorks () {
54
+ // This test verifies that issue #661 has been fixed
55
+ // Previously would throw NoSuchElementException, now it works
56
+ FlightProjection projection = repository .findByNumber ("AA123" );
57
+
58
+ assertThat (projection ).isNotNull ();
59
+ assertThat (projection .getNumber ()).isEqualTo ("AA123" );
60
+ assertThat (projection .getName ()).isEqualTo ("Flight to Paris" );
61
+
62
+ // After fix, accessing Point field in projection should work
63
+ Point location = projection .getLocation ();
64
+ assertThat (location ).isNotNull ();
65
+ assertThat (location .getX ()).isEqualTo (2.3522 );
66
+ assertThat (location .getY ()).isEqualTo (48.8566 );
67
+ }
68
+
69
+ @ Test
70
+ void testDirectRepositoryAccessWithPointWorks () {
71
+ // Direct repository access should work fine
72
+ FlightWithLocation flight = repository .findById (
73
+ repository .findAll ().iterator ().next ().getId ()
74
+ ).orElseThrow ();
75
+
76
+ assertThat (flight .getLocation ()).isNotNull ();
77
+ assertThat (flight .getLocation ().getX ()).isEqualTo (2.3522 );
78
+ assertThat (flight .getLocation ().getY ()).isEqualTo (48.8566 );
79
+ }
80
+
81
+ @ Test
82
+ void testProjectionWithPointShouldWork () {
83
+ // After fix, this should work without throwing exception
84
+ FlightProjection projection = repository .findByNumber ("BA456" );
85
+
86
+ assertThat (projection ).isNotNull ();
87
+ assertThat (projection .getNumber ()).isEqualTo ("BA456" );
88
+ assertThat (projection .getName ()).isEqualTo ("Flight to London" );
89
+
90
+ // After fix, this should NOT throw exception
91
+ assertDoesNotThrow (() -> {
92
+ Point location = projection .getLocation ();
93
+ assertThat (location ).isNotNull ();
94
+ assertThat (location .getX ()).isEqualTo (-0.1276 );
95
+ assertThat (location .getY ()).isEqualTo (51.5074 );
96
+ });
97
+ }
98
+ }
0 commit comments