1515 */
1616package software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .custom ;
1717
18+ import java .time .LocalDate ;
19+ import java .util .List ;
1820import java .util .Optional ;
1921import java .util .stream .Stream ;
2022
3133import software .xdev .spring .data .eclipse .store .integration .isolated .IsolatedTestAnnotations ;
3234import software .xdev .spring .data .eclipse .store .integration .isolated .tests .id .IdTestConfiguration ;
3335import 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 ;
3437import 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 ;
3542import 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 ;
3645import software .xdev .spring .data .eclipse .store .repository .interfaces .EclipseStoreRepository ;
3746
3847
@@ -49,6 +58,24 @@ public static Stream<Arguments> generateData()
4958 context -> context .getBean (CustomerWithIdCompositeKeyRepository .class ),
5059 () -> new CompositeKey (1 , 1 ),
5160 () -> 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 )
5279 ).toArguments ()
5380 );
5481 }
@@ -63,7 +90,7 @@ public CustomIdTest(final IdTestConfiguration configuration)
6390
6491 @ ParameterizedTest
6592 @ MethodSource ("generateData" )
66- <T , ID > void createSingleWithAutoIdInteger (
93+ <T , ID > void createSingleWithCustomKey (
6794 final SingleTestDataset <T , ID > data , @ Autowired final ApplicationContext context )
6895 {
6996 final EclipseStoreRepository <T , ID > repository = data .repositoryGenerator ().apply (context );
@@ -80,4 +107,94 @@ <T, ID> void createSingleWithAutoIdInteger(
80107 }
81108 );
82109 }
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+ }
83200}
0 commit comments