Skip to content

Commit 89d1414

Browse files
Cleaned up tests
1 parent 37c9f72 commit 89d1414

5 files changed

Lines changed: 134 additions & 95 deletions

File tree

spring-data-eclipse-store/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@
258258
<configuration>
259259
<argLine>
260260
--add-opens java.base/java.util=ALL-UNNAMED
261+
--add-opens java.base/java.math=ALL-UNNAMED
262+
--add-opens java.base/java.time=ALL-UNNAMED
263+
--add-opens java.base/java.time.zone=ALL-UNNAMED
264+
--add-opens java.base/java.util.concurrent=ALL-UNNAMED
265+
--add-opens java.base/sun.util.calendar=ALL-UNNAMED
261266
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED
262267
</argLine>
263268
</configuration>

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/support/copier/working/RecursiveWorkingCopier.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,24 @@ private <E> void mergeValues(
160160
// alreadyMergedTargets prevent endless loops
161161
return;
162162
}
163-
alreadyMergedTargets.collectMergedTarget(targetObject);
164-
165-
if(sourceObject instanceof String)
163+
try
166164
{
167-
// no merge needed and no merge possible
168-
return;
165+
alreadyMergedTargets.collectMergedTarget(targetObject);
166+
167+
if(sourceObject instanceof String)
168+
{
169+
// no merge needed and no merge possible
170+
return;
171+
}
172+
AccessHelper.getInheritedPrivateFieldsByName(sourceObject.getClass()).values().forEach(
173+
field ->
174+
this.mergeValueOfField(sourceObject, targetObject, field, alreadyMergedTargets, changedCollector)
175+
);
176+
}
177+
catch(final Exception e)
178+
{
179+
throw new MergeFailedException(sourceObject, targetObject, e);
169180
}
170-
AccessHelper.getInheritedPrivateFieldsByName(sourceObject.getClass()).values().forEach(
171-
field ->
172-
this.mergeValueOfField(sourceObject, targetObject, field, alreadyMergedTargets, changedCollector)
173-
);
174181
}
175182

176183
private <E> void mergeValueOfField(

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types/TypesData.java

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright © 2023 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.special.types;
217

318
import java.math.BigDecimal;
@@ -142,51 +157,6 @@ public static Stream<Arguments> generateData()
142157
id -> new DateDaoObject(id, new Date(System.currentTimeMillis())),
143158
object -> object.getValue().setTime(System.currentTimeMillis() + 1)
144159
),
145-
new TestArguments<>(
146-
CalendarRepository.class,
147-
id -> new CalendarDaoObject(id, null),
148-
object -> object.setValue(Calendar.getInstance())
149-
),
150-
new TestArguments<>(
151-
CalendarRepository.class,
152-
id -> new CalendarDaoObject(id, Calendar.getInstance()),
153-
object -> object.getValue().add(Calendar.DAY_OF_MONTH, 1)
154-
),
155-
new TestArguments<>(
156-
EnumMapRepository.class,
157-
id -> new EnumMapDaoObject(id, new EnumMap<>(EnumMapDaoObject.Album.class)),
158-
object -> object.getValue().put(EnumMapDaoObject.Album.RUMOURS, "1")
159-
),
160-
new TestArguments<>(
161-
EnumMapRepository.class,
162-
id -> new EnumMapDaoObject(id, new EnumMap<>(Map.of(EnumMapDaoObject.Album.RUMOURS, "1"))),
163-
object -> object.getValue().put(EnumMapDaoObject.Album.TUSK, "2")
164-
),
165-
new TestArguments<>(
166-
EnumMapRepository.class,
167-
id -> new EnumMapDaoObject(id, new EnumMap<>(Map.of(EnumMapDaoObject.Album.RUMOURS, "1"))),
168-
object -> object.getValue().remove(EnumMapDaoObject.Album.RUMOURS)
169-
),
170-
new TestArguments<>(
171-
EnumMapRepository.class,
172-
id -> new EnumMapDaoObject(id, null),
173-
object -> object.setValue(new EnumMap<>(Map.of(EnumMapDaoObject.Album.RUMOURS, "1")))
174-
),
175-
new TestArguments<>(
176-
LazyRepository.class,
177-
id -> new LazyDaoObject(id, org.eclipse.serializer.reference.Lazy.Reference("1")),
178-
object -> object.setValue(org.eclipse.serializer.reference.Lazy.Reference("2"))
179-
),
180-
new TestArguments<>(
181-
LazyRepository.class,
182-
id -> new LazyDaoObject(id, null),
183-
object -> object.setValue(org.eclipse.serializer.reference.Lazy.Reference("1"))
184-
),
185-
new TestArguments<>(
186-
LazyRepository.class,
187-
id -> new LazyDaoObject(id, org.eclipse.serializer.reference.Lazy.Reference("1")),
188-
object -> object.getValue().clear()
189-
),
190160
new TestArguments<>(
191161
ListRepository.class,
192162
id -> new ListDaoObject(id, List.of()),
@@ -305,4 +275,44 @@ public static Stream<Arguments> generateData()
305275
)
306276
).toArguments();
307277
}
278+
279+
public static Stream<Arguments> generateNotWorkingData()
280+
{
281+
return new ListOfTestArguments(
282+
List.of(
283+
new TestArguments<>(
284+
LazyRepository.class,
285+
id -> new LazyDaoObject(id, org.eclipse.serializer.reference.Lazy.Reference("1")),
286+
object -> object.setValue(org.eclipse.serializer.reference.Lazy.Reference("2"))
287+
),
288+
new TestArguments<>(
289+
LazyRepository.class,
290+
id -> new LazyDaoObject(id, org.eclipse.serializer.reference.Lazy.Reference("1")),
291+
object -> object.getValue().clear()
292+
),
293+
// Here EclipseStore has problems too: https://github.com/microstream-one/microstream/issues/204
294+
new TestArguments<>(
295+
EnumMapRepository.class,
296+
id -> new EnumMapDaoObject(id, new EnumMap<>(EnumMapDaoObject.Album.class)),
297+
object -> object.getValue().put(EnumMapDaoObject.Album.RUMOURS, "1")
298+
),
299+
new TestArguments<>(
300+
EnumMapRepository.class,
301+
id -> new EnumMapDaoObject(id, new EnumMap<>(Map.of(EnumMapDaoObject.Album.RUMOURS, "1"))),
302+
object -> object.getValue().put(EnumMapDaoObject.Album.TUSK, "2")
303+
),
304+
new TestArguments<>(
305+
EnumMapRepository.class,
306+
id -> new EnumMapDaoObject(id, new EnumMap<>(Map.of(EnumMapDaoObject.Album.RUMOURS, "1"))),
307+
object -> object.getValue().remove(EnumMapDaoObject.Album.RUMOURS)
308+
),
309+
// Here EclipseStore has problems: https://github.com/microstream-one/microstream/issues/173
310+
new TestArguments<>(
311+
CalendarRepository.class,
312+
id -> new CalendarDaoObject(id, Calendar.getInstance()),
313+
object -> object.getValue().add(Calendar.DAY_OF_MONTH, 1)
314+
)
315+
)
316+
).toArguments();
317+
}
308318
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types/TypesTest.java

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,19 @@ class TypesTest
4444
public static final String TYPES_DATA_SOURCE =
4545
"software.xdev.spring.data.eclipse.store.integration.isolated.tests.special.types"
4646
+ ".TypesData#generateData";
47+
public static final String TYPES_NOT_WORKING_DATA_SOURCE =
48+
"software.xdev.spring.data.eclipse.store.integration.isolated.tests.special.types"
49+
+ ".TypesData#generateNotWorkingData";
4750

4851
@Autowired
4952
private EclipseStoreStorage storage;
5053

5154
@ParameterizedTest
5255
@MethodSource(TYPES_DATA_SOURCE)
53-
@Disabled("Should get fixed")
54-
<T> void simpleStoreAndRead(
56+
<T extends ComplexObject<?>> void simpleStoreAndRead(
5557
final Class<? extends EclipseStoreRepository<T, Integer>> repositoryClass,
5658
final Function<Integer, T> objectCreator,
57-
final Consumer<T> objectChanger,
59+
final Consumer<T> ignoredObjectChanger,
5860
@Autowired final ApplicationContext context)
5961
{
6062
final EclipseStoreRepository<T, Integer> repository = context.getBean(repositoryClass);
@@ -64,39 +66,50 @@ <T> void simpleStoreAndRead(
6466
TestUtil.doBeforeAndAfterRestartOfDatastore(
6567
this.storage,
6668
() -> {
67-
final List<T> customers = TestUtil.iterableToList(repository.findAll());
68-
Assertions.assertEquals(1, customers.size());
69-
Assertions.assertEquals(objectToStore, customers.get(0));
69+
final List<T> storedObjects = TestUtil.iterableToList(repository.findAll());
70+
Assertions.assertEquals(1, storedObjects.size());
71+
Assertions.assertEquals(objectToStore, storedObjects.get(0));
7072
}
7173
);
7274
}
7375

76+
@ParameterizedTest
77+
@MethodSource(TYPES_NOT_WORKING_DATA_SOURCE)
78+
<T extends ComplexObject<?>> void simpleStoreAndReadForNotWorkingTypes(
79+
final Class<? extends EclipseStoreRepository<T, Integer>> repositoryClass,
80+
final Function<Integer, T> objectCreator,
81+
final Consumer<T> ignoredObjectChanger,
82+
@Autowired final ApplicationContext context)
83+
{
84+
Assertions.assertThrows(
85+
Exception.class,
86+
() -> this.simpleChangeAfterStore(repositoryClass, objectCreator, ignoredObjectChanger, context));
87+
}
88+
7489
@ParameterizedTest
7590
@MethodSource(TYPES_DATA_SOURCE)
76-
@Disabled("Should get fixed")
77-
<T extends ComplexObject> void simpleChangeToNullAfterStore(
91+
<T extends ComplexObject<?>> void simpleChangeToNullAfterStore(
7892
final Class<? extends EclipseStoreRepository<T, Integer>> repositoryClass,
7993
final Function<Integer, T> objectCreator,
80-
final Consumer<T> objectChanger,
94+
final Consumer<T> ignoredObjectChanger,
8195
@Autowired final ApplicationContext context)
8296
{
8397
this.simpleChangeAfterStore(repositoryClass, objectCreator, object -> object.setValue(null), context);
8498
}
8599

86100
@ParameterizedTest
87101
@MethodSource(TYPES_DATA_SOURCE)
88-
@Disabled("Should get fixed")
89-
<T extends ComplexObject> void simpleChangeAfterStore(
102+
<T extends ComplexObject<?>> void simpleChangeAfterStore(
90103
final Class<? extends EclipseStoreRepository<T, Integer>> repositoryClass,
91104
final Function<Integer, T> objectCreator,
92105
final Consumer<T> objectChanger,
93106
@Autowired final ApplicationContext context)
94107
{
95108
final EclipseStoreRepository<T, Integer> repository = context.getBean(repositoryClass);
96-
final T objectToStore = objectCreator.apply(2);
109+
final T objectToStore = objectCreator.apply(1);
97110
repository.save(objectToStore);
98111

99-
final Optional<T> storedObject = repository.findById(2);
112+
final Optional<T> storedObject = repository.findById(1);
100113
Assertions.assertTrue(storedObject.isPresent());
101114

102115
objectChanger.accept(storedObject.get());
@@ -105,7 +118,7 @@ <T extends ComplexObject> void simpleChangeAfterStore(
105118
TestUtil.doBeforeAndAfterRestartOfDatastore(
106119
this.storage,
107120
() -> {
108-
final Optional<T> storedObject2 = repository.findById(2);
121+
final Optional<T> storedObject2 = repository.findById(1);
109122
Assertions.assertTrue(storedObject2.isPresent());
110123
Assertions.assertEquals(storedObject, storedObject2);
111124
}
@@ -114,22 +127,48 @@ <T extends ComplexObject> void simpleChangeAfterStore(
114127

115128
@ParameterizedTest
116129
@MethodSource(TYPES_DATA_SOURCE)
117-
@Disabled("Should get fixed")
118-
<T extends ComplexObject> void simpleChangeBeforeStore(
130+
// TODO: Fix this.
131+
@Disabled("Is not fixed yet, but will be.")
132+
<T extends ComplexObject<?>> void doubleStoreSameEntityWithChange(
119133
final Class<? extends EclipseStoreRepository<T, Integer>> repositoryClass,
120134
final Function<Integer, T> objectCreator,
121135
final Consumer<T> objectChanger,
122136
@Autowired final ApplicationContext context)
123137
{
124138
final EclipseStoreRepository<T, Integer> repository = context.getBean(repositoryClass);
125-
final T objectToStore = objectCreator.apply(3);
139+
final T objectToStore = objectCreator.apply(1);
140+
repository.save(objectToStore);
141+
142+
objectChanger.accept(objectToStore);
143+
repository.save(objectToStore);
144+
145+
TestUtil.doBeforeAndAfterRestartOfDatastore(
146+
this.storage,
147+
() -> {
148+
final Optional<T> storedObject = repository.findById(1);
149+
Assertions.assertTrue(storedObject.isPresent());
150+
Assertions.assertEquals(objectToStore, storedObject.get());
151+
}
152+
);
153+
}
154+
155+
@ParameterizedTest
156+
@MethodSource(TYPES_DATA_SOURCE)
157+
<T extends ComplexObject<?>> void simpleChangeBeforeStore(
158+
final Class<? extends EclipseStoreRepository<T, Integer>> repositoryClass,
159+
final Function<Integer, T> objectCreator,
160+
final Consumer<T> objectChanger,
161+
@Autowired final ApplicationContext context)
162+
{
163+
final EclipseStoreRepository<T, Integer> repository = context.getBean(repositoryClass);
164+
final T objectToStore = objectCreator.apply(1);
126165
objectChanger.accept(objectToStore);
127166
repository.save(objectToStore);
128167

129168
TestUtil.doBeforeAndAfterRestartOfDatastore(
130169
this.storage,
131170
() -> {
132-
final Optional<T> storedObject2 = repository.findById(3);
171+
final Optional<T> storedObject2 = repository.findById(1);
133172
Assertions.assertTrue(storedObject2.isPresent());
134173
Assertions.assertEquals(objectToStore, storedObject2.get());
135174
}

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
import java.util.List;
1919
import java.util.Set;
2020

21-
import org.springframework.beans.factory.annotation.Autowired;
22-
2321
import org.junit.jupiter.api.Assertions;
24-
import org.junit.jupiter.api.Disabled;
2522
import org.junit.jupiter.api.Test;
23+
import org.springframework.beans.factory.annotation.Autowired;
2624

2725
import software.xdev.spring.data.eclipse.store.helper.TestData;
2826
import software.xdev.spring.data.eclipse.store.helper.TestUtil;
@@ -165,26 +163,6 @@ void testSaveAndSetNullAndFindAllNonFinal()
165163
);
166164
}
167165

168-
// TODO: Fix this.
169-
@Test
170-
@Disabled("Is not fixed yet, but will be.")
171-
void testDoubleSaveAndFindAll()
172-
{
173-
final CustomerWithHashSet customer = new CustomerWithHashSet(TestData.FIRST_NAME, TestData.LAST_NAME);
174-
this.repository.save(customer);
175-
customer.getValues().add("Test");
176-
this.repository.save(customer);
177-
178-
TestUtil.doBeforeAndAfterRestartOfDatastore(
179-
this.storage,
180-
() -> {
181-
final List<CustomerWithHashSet> customers = TestUtil.iterableToList(this.repository.findAll());
182-
Assertions.assertEquals(1, customers.size());
183-
Assertions.assertEquals(1, customers.get(0).getValues().size());
184-
}
185-
);
186-
}
187-
188166
@Test
189167
void testDoubleSaveWithNewInstanceAndFindAll()
190168
{

0 commit comments

Comments
 (0)