1515 */
1616package software .xdev .spring .data .eclipse .store .integration .isolated .tests .lazy ;
1717
18+ import static software .xdev .spring .data .eclipse .store .helper .TestUtil .restartDatastore ;
19+
1820import org .eclipse .serializer .collections .lazy .LazyArrayList ;
1921import org .eclipse .serializer .collections .lazy .LazyList ;
22+ import org .eclipse .serializer .reference .Lazy ;
2023import org .junit .jupiter .api .Assertions ;
2124import org .junit .jupiter .api .Test ;
2225import org .springframework .beans .factory .annotation .Autowired ;
2326import org .springframework .test .context .ContextConfiguration ;
2427
28+ import software .xdev .spring .data .eclipse .store .helper .TestData ;
2529import software .xdev .spring .data .eclipse .store .helper .TestUtil ;
2630import software .xdev .spring .data .eclipse .store .integration .isolated .IsolatedTestAnnotations ;
31+ import software .xdev .spring .data .eclipse .store .repository .lazy .SpringDataEclipseStoreLazy ;
2732
2833
2934@ IsolatedTestAnnotations
@@ -34,10 +39,10 @@ class LazyTest
3439 private LazyTestConfiguration configuration ;
3540
3641 @ Test
37- void lazyListStore (final ObjectWithLazyListRepository repository )
42+ void lazyListStore (@ Autowired final ObjectWithLazyListRepository repository )
3843 {
3944 final ObjectWithLazyList newList = new ObjectWithLazyList ();
40- final SimpleObject objectToStore = new SimpleObject ("Test" );
45+ final SimpleObject objectToStore = new SimpleObject (TestData . DUMMY_STRING );
4146 final LazyArrayList lazyArrayList = new LazyArrayList ();
4247 lazyArrayList .add (objectToStore );
4348 newList .setLazyList (lazyArrayList );
@@ -53,4 +58,121 @@ void lazyListStore(final ObjectWithLazyListRepository repository)
5358 }
5459 );
5560 }
61+
62+ @ Test
63+ void lazyStore (@ Autowired final ObjectWithLazyRepository repository )
64+ {
65+ final ObjectWithLazy newLazy = new ObjectWithLazy ();
66+ final SimpleObject objectToStore = new SimpleObject (TestData .DUMMY_STRING );
67+ newLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore ));
68+ repository .save (newLazy );
69+
70+ TestUtil .doBeforeAndAfterRestartOfDatastore (
71+ this .configuration ,
72+ () -> {
73+ Assertions .assertEquals (1 , repository .findAll ().size ());
74+ final Lazy <SimpleObject > lazy = repository .findAll ().get (0 ).getLazy ();
75+ Assertions .assertEquals (objectToStore , lazy .get ());
76+ }
77+ );
78+ }
79+
80+ @ Test
81+ void lazyClearBeforeSave (@ Autowired final ObjectWithLazyRepository repository )
82+ {
83+ final ObjectWithLazy newLazy = new ObjectWithLazy ();
84+ final SimpleObject objectToStore = new SimpleObject (TestData .DUMMY_STRING );
85+ newLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore ));
86+ Assertions .assertThrows (IllegalStateException .class , () -> newLazy .getLazy ().clear ());
87+ }
88+
89+ @ Test
90+ void lazyClearAfterSave (@ Autowired final ObjectWithLazyRepository repository )
91+ {
92+ final ObjectWithLazy newLazy = new ObjectWithLazy ();
93+ final SimpleObject objectToStore = new SimpleObject (TestData .DUMMY_STRING );
94+ newLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore ));
95+ repository .save (newLazy );
96+ newLazy .getLazy ().clear ();
97+
98+ TestUtil .doBeforeAndAfterRestartOfDatastore (
99+ this .configuration ,
100+ () -> {
101+ Assertions .assertEquals (1 , repository .findAll ().size ());
102+ final Lazy <SimpleObject > lazy = repository .findAll ().get (0 ).getLazy ();
103+ Assertions .assertEquals (objectToStore , lazy .get ());
104+ }
105+ );
106+ }
107+
108+ @ Test
109+ void lazyChangeAfterSave (@ Autowired final ObjectWithLazyRepository repository )
110+ {
111+ final ObjectWithLazy newLazy = new ObjectWithLazy ();
112+ final SimpleObject objectToStore = new SimpleObject (TestData .DUMMY_STRING );
113+ newLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore ));
114+ repository .save (newLazy );
115+
116+ final SimpleObject objectToStore2 = new SimpleObject (TestData .DUMMY_STRING_ALTERNATIVE );
117+ newLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore2 ));
118+ repository .save (newLazy );
119+
120+ TestUtil .doBeforeAndAfterRestartOfDatastore (
121+ this .configuration ,
122+ () -> {
123+ Assertions .assertEquals (1 , repository .findAll ().size ());
124+ final Lazy <SimpleObject > lazy = repository .findAll ().get (0 ).getLazy ();
125+ Assertions .assertEquals (objectToStore2 , lazy .get ());
126+ }
127+ );
128+ }
129+
130+ @ Test
131+ void lazyChangeBeforeSave (@ Autowired final ObjectWithLazyRepository repository )
132+ {
133+ final ObjectWithLazy newLazy = new ObjectWithLazy ();
134+ final SimpleObject objectToStore = new SimpleObject (TestData .DUMMY_STRING );
135+ newLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore ));
136+
137+ final SimpleObject objectToStore2 = new SimpleObject (TestData .DUMMY_STRING_ALTERNATIVE );
138+ newLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore2 ));
139+ repository .save (newLazy );
140+
141+ TestUtil .doBeforeAndAfterRestartOfDatastore (
142+ this .configuration ,
143+ () -> {
144+ Assertions .assertEquals (1 , repository .findAll ().size ());
145+ final Lazy <SimpleObject > lazy = repository .findAll ().get (0 ).getLazy ();
146+ Assertions .assertEquals (objectToStore2 , lazy .get ());
147+ }
148+ );
149+ }
150+
151+ @ Test
152+ void lazyChangeAfterRestart (@ Autowired final ObjectWithLazyRepository repository )
153+ {
154+ final ObjectWithLazy newLazy = new ObjectWithLazy ();
155+ final SimpleObject objectToStore = new SimpleObject (TestData .DUMMY_STRING );
156+ newLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore ));
157+ repository .save (newLazy );
158+
159+ restartDatastore (this .configuration );
160+
161+ Assertions .assertEquals (1 , repository .findAll ().size ());
162+ final ObjectWithLazy reloadedObjectWithLazy = repository .findAll ().get (0 );
163+ Assertions .assertEquals (objectToStore , reloadedObjectWithLazy .getLazy ().get ());
164+
165+ final SimpleObject objectToStore2 = new SimpleObject (TestData .DUMMY_STRING_ALTERNATIVE );
166+ reloadedObjectWithLazy .setLazy (SpringDataEclipseStoreLazy .build (objectToStore2 ));
167+ repository .save (reloadedObjectWithLazy );
168+
169+ TestUtil .doBeforeAndAfterRestartOfDatastore (
170+ this .configuration ,
171+ () -> {
172+ Assertions .assertEquals (1 , repository .findAll ().size ());
173+ final Lazy <SimpleObject > lazy = repository .findAll ().get (0 ).getLazy ();
174+ Assertions .assertEquals (objectToStore2 , lazy .get ());
175+ }
176+ );
177+ }
56178}
0 commit comments