18
18
import java .util .List ;
19
19
import java .util .Optional ;
20
20
21
+ import jakarta .inject .Inject ;
22
+
21
23
import org .junit .jupiter .api .Assertions ;
22
24
import org .junit .jupiter .api .Test ;
23
25
import org .springframework .beans .factory .annotation .Autowired ;
24
26
25
- import jakarta .inject .Inject ;
26
27
import software .xdev .spring .data .eclipse .store .helper .TestData ;
27
28
import software .xdev .spring .data .eclipse .store .helper .TestUtil ;
28
29
import software .xdev .spring .data .eclipse .store .integration .DefaultTestAnnotations ;
29
30
import 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 ;
30
33
import software .xdev .spring .data .eclipse .store .integration .repositories .CustomerNotCrud ;
31
34
import software .xdev .spring .data .eclipse .store .integration .repositories .CustomerNotCrudRepository ;
32
35
import software .xdev .spring .data .eclipse .store .integration .repositories .CustomerRepository ;
@@ -38,6 +41,8 @@ class SimpleSingleTest
38
41
{
39
42
@ Inject
40
43
private CustomerRepository repository ;
44
+ @ Inject
45
+ private CustomerAsRecordRepository recordRepository ;
41
46
42
47
@ Inject
43
48
private EclipseStoreStorage storage ;
@@ -54,6 +59,65 @@ void testNullFindAll()
54
59
);
55
60
}
56
61
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
+
57
121
@ SuppressWarnings ("DataFlowIssue" )
58
122
@ Test
59
123
void testNullSave ()
0 commit comments