1818import java .util .List ;
1919import java .util .Optional ;
2020
21+ import jakarta .inject .Inject ;
22+
2123import org .junit .jupiter .api .Assertions ;
2224import org .junit .jupiter .api .Test ;
2325import org .springframework .beans .factory .annotation .Autowired ;
2426
25- import jakarta .inject .Inject ;
2627import software .xdev .spring .data .eclipse .store .helper .TestData ;
2728import software .xdev .spring .data .eclipse .store .helper .TestUtil ;
2829import software .xdev .spring .data .eclipse .store .integration .DefaultTestAnnotations ;
2930import software .xdev .spring .data .eclipse .store .integration .repositories .Customer ;
31+ import software .xdev .spring .data .eclipse .store .integration .repositories .CustomerAsRecord ;
32+ import software .xdev .spring .data .eclipse .store .integration .repositories .CustomerAsRecordRepository ;
3033import software .xdev .spring .data .eclipse .store .integration .repositories .CustomerNotCrud ;
3134import software .xdev .spring .data .eclipse .store .integration .repositories .CustomerNotCrudRepository ;
3235import software .xdev .spring .data .eclipse .store .integration .repositories .CustomerRepository ;
@@ -38,6 +41,8 @@ class SimpleSingleTest
3841{
3942 @ Inject
4043 private CustomerRepository repository ;
44+ @ Inject
45+ private CustomerAsRecordRepository recordRepository ;
4146
4247 @ Inject
4348 private EclipseStoreStorage storage ;
@@ -54,6 +59,65 @@ void testNullFindAll()
5459 );
5560 }
5661
62+ @ Test
63+ void testBasicSaveAndFindSingleRecords ()
64+ {
65+ final CustomerAsRecord customer = new CustomerAsRecord (TestData .FIRST_NAME , TestData .LAST_NAME );
66+ this .recordRepository .save (customer );
67+
68+ TestUtil .doBeforeAndAfterRestartOfDatastore (
69+ this .storage ,
70+ () -> {
71+ final List <CustomerAsRecord > customers = TestUtil .iterableToList (this .recordRepository .findAll ());
72+ Assertions .assertEquals (1 , customers .size ());
73+ Assertions .assertEquals (customer , customers .get (0 ));
74+ }
75+ );
76+ }
77+
78+ @ Test
79+ void testBasicSaveAndFindMultipleRecords ()
80+ {
81+ final CustomerAsRecord customer = new CustomerAsRecord (TestData .FIRST_NAME , TestData .LAST_NAME );
82+ this .recordRepository .save (customer );
83+ final CustomerAsRecord customer2 = new CustomerAsRecord (null , null );
84+ this .recordRepository .save (customer2 );
85+
86+ TestUtil .doBeforeAndAfterRestartOfDatastore (
87+ this .storage ,
88+ () -> {
89+ final List <CustomerAsRecord > customers = TestUtil .iterableToList (this .recordRepository .findAll ());
90+ final CustomerAsRecord foundCustomer =
91+ customers .stream ().filter (c -> TestData .FIRST_NAME .equals (c .firstName ())).findFirst ().get ();
92+ final CustomerAsRecord foundCustomer2 =
93+ customers .stream ().filter (c -> c .firstName () == null ).findFirst ().get ();
94+ Assertions .assertEquals (2 , customers .size ());
95+ Assertions .assertEquals (customer , foundCustomer );
96+ Assertions .assertEquals (customer2 , foundCustomer2 );
97+ }
98+ );
99+ }
100+
101+ @ Test
102+ void testBasicSaveAndFindByFirstNameRecords ()
103+ {
104+ final CustomerAsRecord customer = new CustomerAsRecord (TestData .FIRST_NAME , TestData .LAST_NAME );
105+ this .recordRepository .save (customer );
106+ final CustomerAsRecord customer2 =
107+ new CustomerAsRecord (TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME_ALTERNATIVE );
108+ this .recordRepository .save (customer2 );
109+
110+ TestUtil .doBeforeAndAfterRestartOfDatastore (
111+ this .storage ,
112+ () -> {
113+ final Optional <CustomerAsRecord > foundCustomer =
114+ this .recordRepository .findByFirstName (TestData .FIRST_NAME );
115+ Assertions .assertTrue (foundCustomer .isPresent ());
116+ Assertions .assertEquals (customer , foundCustomer .get ());
117+ }
118+ );
119+ }
120+
57121 @ SuppressWarnings ("DataFlowIssue" )
58122 @ Test
59123 void testNullSave ()
0 commit comments