@@ -90,6 +90,135 @@ void testRemoveChildFindParent()
9090 );
9191 }
9292
93+ @ Test
94+ void testAddChildAndParent ()
95+ {
96+ final ChildCustomer customer1 =
97+ new ChildCustomer (TestData .FIRST_NAME , TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME );
98+ this .childCustomerRepository .save (customer1 );
99+
100+ final ParentCustomer parentCustomer =
101+ new ParentCustomer (TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME_ALTERNATIVE );
102+ this .parentCustomerRepository .save (parentCustomer );
103+
104+ TestUtil .doBeforeAndAfterRestartOfDatastore (
105+ this .storage ,
106+ () -> {
107+ final List <ParentCustomer > parentCustomers =
108+ TestUtil .iterableToList (this .parentCustomerRepository .findAll ());
109+ Assertions .assertEquals (2 , parentCustomers .size ());
110+ }
111+ );
112+ }
113+
114+ @ Test
115+ void testRemoveOnlyChildFindParent ()
116+ {
117+ final ChildCustomer customer1 =
118+ new ChildCustomer (TestData .FIRST_NAME , TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME );
119+ this .childCustomerRepository .save (customer1 );
120+
121+ final ParentCustomer parentCustomer =
122+ new ParentCustomer (TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME_ALTERNATIVE );
123+ this .parentCustomerRepository .save (parentCustomer );
124+
125+ this .childCustomerRepository .delete (customer1 );
126+
127+ TestUtil .doBeforeAndAfterRestartOfDatastore (
128+ this .storage ,
129+ () -> {
130+ final List <ParentCustomer > parentCustomers =
131+ TestUtil .iterableToList (this .parentCustomerRepository .findAll ());
132+ Assertions .assertEquals (1 , parentCustomers .size ());
133+
134+ final List <ChildCustomer > childCustomers =
135+ TestUtil .iterableToList (this .childCustomerRepository .findAll ());
136+ Assertions .assertTrue (childCustomers .isEmpty ());
137+ }
138+ );
139+ }
140+
141+ @ Test
142+ void testRemoveOnlyParentFindParent ()
143+ {
144+ final ChildCustomer customer1 =
145+ new ChildCustomer (TestData .FIRST_NAME , TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME );
146+ this .childCustomerRepository .save (customer1 );
147+
148+ final ParentCustomer parentCustomer =
149+ new ParentCustomer (TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME_ALTERNATIVE );
150+ this .parentCustomerRepository .save (parentCustomer );
151+
152+ this .parentCustomerRepository .delete (parentCustomer );
153+
154+ TestUtil .doBeforeAndAfterRestartOfDatastore (
155+ this .storage ,
156+ () -> {
157+ final List <ParentCustomer > parentCustomers =
158+ TestUtil .iterableToList (this .parentCustomerRepository .findAll ());
159+ Assertions .assertEquals (1 , parentCustomers .size ());
160+
161+ final List <ChildCustomer > childCustomers =
162+ TestUtil .iterableToList (this .childCustomerRepository .findAll ());
163+ Assertions .assertEquals (1 , childCustomers .size ());
164+ }
165+ );
166+ }
167+
168+ @ Test
169+ void testRemoveAllChildren ()
170+ {
171+ final ChildCustomer customer1 =
172+ new ChildCustomer (TestData .FIRST_NAME , TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME );
173+ this .childCustomerRepository .save (customer1 );
174+
175+ final ParentCustomer parentCustomer =
176+ new ParentCustomer (TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME_ALTERNATIVE );
177+ this .parentCustomerRepository .save (parentCustomer );
178+
179+ this .childCustomerRepository .deleteAll ();
180+
181+ TestUtil .doBeforeAndAfterRestartOfDatastore (
182+ this .storage ,
183+ () -> {
184+ final List <ParentCustomer > parentCustomers =
185+ TestUtil .iterableToList (this .parentCustomerRepository .findAll ());
186+ Assertions .assertEquals (1 , parentCustomers .size ());
187+
188+ final List <ChildCustomer > childCustomers =
189+ TestUtil .iterableToList (this .childCustomerRepository .findAll ());
190+ Assertions .assertTrue (childCustomers .isEmpty ());
191+ }
192+ );
193+ }
194+
195+ @ Test
196+ void testRemoveAllParents ()
197+ {
198+ final ChildCustomer customer1 =
199+ new ChildCustomer (TestData .FIRST_NAME , TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME );
200+ this .childCustomerRepository .save (customer1 );
201+
202+ final ParentCustomer parentCustomer =
203+ new ParentCustomer (TestData .FIRST_NAME_ALTERNATIVE , TestData .LAST_NAME_ALTERNATIVE );
204+ this .parentCustomerRepository .save (parentCustomer );
205+
206+ this .parentCustomerRepository .deleteAll ();
207+
208+ TestUtil .doBeforeAndAfterRestartOfDatastore (
209+ this .storage ,
210+ () -> {
211+ final List <ParentCustomer > parentCustomers =
212+ TestUtil .iterableToList (this .parentCustomerRepository .findAll ());
213+ Assertions .assertTrue (parentCustomers .isEmpty ());
214+
215+ final List <ChildCustomer > childCustomers =
216+ TestUtil .iterableToList (this .childCustomerRepository .findAll ());
217+ Assertions .assertEquals (1 , childCustomers .size ());
218+ }
219+ );
220+ }
221+
93222 @ Test
94223 void testChangeChildFindParent ()
95224 {
0 commit comments