15
15
*/
16
16
package software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom ;
17
17
18
+ import java .time .LocalDate ;
19
+ import java .util .List ;
18
20
import java .util .Optional ;
19
21
import java .util .stream .Stream ;
20
22
31
33
import software .xdev .spring .data .eclipse .store .integration .isolated .IsolatedTestAnnotations ;
32
34
import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .IdTestConfiguration ;
33
35
import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CompositeKey ;
36
+ import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CompositeKeyAsRecord ;
34
37
import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CustomerWithIdCompositeKey ;
38
+ import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CustomerWithIdCompositeKeyAsRecord ;
39
+ import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CustomerWithIdCompositeKeyAsRecordRepository ;
40
+ import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CustomerWithIdCompositeKeyEmbeddedId ;
41
+ import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CustomerWithIdCompositeKeyEmbeddedIdRepository ;
35
42
import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CustomerWithIdCompositeKeyRepository ;
43
+ import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CustomerWithIdLocalDate ;
44
+ import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom .model .CustomerWithIdLocalDateRepository ;
36
45
import software .xdev .spring .data .eclipse .store .repository .interfaces .EclipseStoreRepository ;
37
46
38
47
@@ -49,6 +58,24 @@ public static Stream<Arguments> generateData()
49
58
context -> context .getBean (CustomerWithIdCompositeKeyRepository .class ),
50
59
() -> new CompositeKey (1 , 1 ),
51
60
() -> new CompositeKey (2 , 2 )
61
+ ).toArguments (),
62
+ new SingleTestDataset <>(
63
+ id -> new CustomerWithIdCompositeKeyEmbeddedId (id , TestData .FIRST_NAME ),
64
+ context -> context .getBean (CustomerWithIdCompositeKeyEmbeddedIdRepository .class ),
65
+ () -> new CompositeKey (1 , 1 ),
66
+ () -> new CompositeKey (2 , 2 )
67
+ ).toArguments (),
68
+ new SingleTestDataset <>(
69
+ id -> new CustomerWithIdCompositeKeyAsRecord (id , TestData .FIRST_NAME ),
70
+ context -> context .getBean (CustomerWithIdCompositeKeyAsRecordRepository .class ),
71
+ () -> new CompositeKeyAsRecord (1 , 1 ),
72
+ () -> new CompositeKeyAsRecord (2 , 2 )
73
+ ).toArguments (),
74
+ new SingleTestDataset <>(
75
+ id -> new CustomerWithIdLocalDate (id , TestData .FIRST_NAME ),
76
+ context -> context .getBean (CustomerWithIdLocalDateRepository .class ),
77
+ () -> LocalDate .of (2024 , 1 , 1 ),
78
+ () -> LocalDate .of (2024 , 1 , 2 )
52
79
).toArguments ()
53
80
);
54
81
}
@@ -63,7 +90,7 @@ public CustomIdTest(final IdTestConfiguration configuration)
63
90
64
91
@ ParameterizedTest
65
92
@ MethodSource ("generateData" )
66
- <T , ID > void createSingleWithAutoIdInteger (
93
+ <T , ID > void createSingleWithCustomKey (
67
94
final SingleTestDataset <T , ID > data , @ Autowired final ApplicationContext context )
68
95
{
69
96
final EclipseStoreRepository <T , ID > repository = data .repositoryGenerator ().apply (context );
@@ -80,4 +107,94 @@ <T, ID> void createSingleWithAutoIdInteger(
80
107
}
81
108
);
82
109
}
110
+
111
+ @ ParameterizedTest
112
+ @ MethodSource ("generateData" )
113
+ <T , ID > void createDoubleWithCustomKey (
114
+ final SingleTestDataset <T , ID > data , @ Autowired final ApplicationContext context )
115
+ {
116
+ final EclipseStoreRepository <T , ID > repository = data .repositoryGenerator ().apply (context );
117
+
118
+ final T customer1 = data .enitityGenerator ().apply (data .firstIdSupplier ().get ());
119
+ repository .save (customer1 );
120
+
121
+ final T customer2 = data .enitityGenerator ().apply (data .secondIdSupplier ().get ());
122
+ repository .save (customer2 );
123
+
124
+ TestUtil .doBeforeAndAfterRestartOfDatastore (
125
+ this .configuration ,
126
+ () -> {
127
+ Assertions .assertEquals (2 , repository .findAll ().size ());
128
+ Assertions .assertEquals (
129
+ 2 ,
130
+ repository .findAllById (List .of (data .firstIdSupplier ().get (), data .secondIdSupplier ().get ()))
131
+ .size ());
132
+
133
+ final Optional <T > loadedCustomer1 = repository .findById (data .firstIdSupplier ().get ());
134
+ Assertions .assertTrue (loadedCustomer1 .isPresent ());
135
+ Assertions .assertEquals (customer1 , loadedCustomer1 .get ());
136
+
137
+ final Optional <T > loadedCustomer2 = repository .findById (data .secondIdSupplier ().get ());
138
+ Assertions .assertTrue (loadedCustomer2 .isPresent ());
139
+ Assertions .assertEquals (customer2 , loadedCustomer2 .get ());
140
+ }
141
+ );
142
+ }
143
+
144
+ @ ParameterizedTest
145
+ @ MethodSource ("generateData" )
146
+ <T , ID > void createNullWithCustomKey (
147
+ final SingleTestDataset <T , ID > data , @ Autowired final ApplicationContext context )
148
+ {
149
+ final EclipseStoreRepository <T , ID > repository = data .repositoryGenerator ().apply (context );
150
+
151
+ final T customer = data .enitityGenerator ().apply (null );
152
+ Assertions .assertThrows (IllegalArgumentException .class , () -> repository .save (customer ));
153
+ }
154
+
155
+ @ ParameterizedTest
156
+ @ MethodSource ("generateData" )
157
+ <T , ID > void deleteBeforeRestartWithCustomKey (
158
+ final SingleTestDataset <T , ID > data , @ Autowired final ApplicationContext context )
159
+ {
160
+ final EclipseStoreRepository <T , ID > repository = data .repositoryGenerator ().apply (context );
161
+
162
+ final T customer = data .enitityGenerator ().apply (data .firstIdSupplier ().get ());
163
+ repository .save (customer );
164
+
165
+ repository .deleteById (data .firstIdSupplier ().get ());
166
+
167
+ TestUtil .doBeforeAndAfterRestartOfDatastore (
168
+ this .configuration ,
169
+ () -> {
170
+ Assertions .assertTrue (repository .findAll ().isEmpty ());
171
+ final Optional <T > loadedCustomer = repository .findById (data .firstIdSupplier ().get ());
172
+ Assertions .assertFalse (loadedCustomer .isPresent ());
173
+ }
174
+ );
175
+ }
176
+
177
+ @ ParameterizedTest
178
+ @ MethodSource ("generateData" )
179
+ <T , ID > void deleteAfterRestartWithCustomKey (
180
+ final SingleTestDataset <T , ID > data , @ Autowired final ApplicationContext context )
181
+ {
182
+ final EclipseStoreRepository <T , ID > repository = data .repositoryGenerator ().apply (context );
183
+
184
+ final T customer = data .enitityGenerator ().apply (data .firstIdSupplier ().get ());
185
+ repository .save (customer );
186
+
187
+ TestUtil .restartDatastore (this .configuration );
188
+
189
+ repository .deleteById (data .firstIdSupplier ().get ());
190
+
191
+ TestUtil .doBeforeAndAfterRestartOfDatastore (
192
+ this .configuration ,
193
+ () -> {
194
+ Assertions .assertTrue (repository .findAll ().isEmpty ());
195
+ final Optional <T > loadedCustomer = repository .findById (data .firstIdSupplier ().get ());
196
+ Assertions .assertFalse (loadedCustomer .isPresent ());
197
+ }
198
+ );
199
+ }
83
200
}
0 commit comments