Skip to content

Commit c59a8a3

Browse files
Add and fix tests for removing all inherited objects
1 parent af0a7cf commit c59a8a3

File tree

2 files changed

+131
-1
lines changed

2 files changed

+131
-1
lines changed

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/EclipseStoreStorage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,12 @@ public synchronized <T> void deleteAll(final Class<T> clazz)
223223
this.ensureEntitiesInRoot();
224224
final IdentitySet<?> entities = this.root.getEntityLists().get(this.getEntityName(clazz));
225225
final int oldSize = entities.size();
226+
final List<?> entitiesToRemove = entities.stream().toList();
226227
final List<IdentitySet<? super Object>> entityLists =
227228
this.entitySetCollector.getRelatedIdentitySets(clazz);
228229
entityLists.forEach(entityList ->
229230
{
230-
entityList.removeAll(entityList);
231+
entityList.removeAll(entitiesToRemove);
231232
this.storageManager.store(entityList.getInternalMap());
232233
});
233234
if(LOG.isDebugEnabled())

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/tests/InheritanceTest.java

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)