Skip to content

Commit b5612bf

Browse files
Added lazyWithComplexId tests
1 parent ecda6dd commit b5612bf

File tree

5 files changed

+164
-0
lines changed

5 files changed

+164
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright © 2024 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+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.lazy;
17+
18+
public record CompositeKeyAsRecord(int keyPart1, int keyPart2)
19+
{
20+
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/LazyTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,23 @@ void simpleEntityWithIdLazyWrappedRepository_FindById(
513513
Assertions.assertThrows(NoIdFieldFoundException.class, () -> repository.findById(all.get(0).get().getId()));
514514
}
515515

516+
@Test
517+
void simpleEntityWithIdLazyRepository_SimpleStore(@Autowired final SimpleEntityWithIdLazyRepository repository)
518+
{
519+
final SimpleEntityWithId objectToStore1 = new SimpleEntityWithId(TestData.DUMMY_STRING);
520+
final Long object1Id = repository.save(objectToStore1).getId();
521+
522+
TestUtil.doBeforeAndAfterRestartOfDatastore(
523+
this.configuration,
524+
() -> {
525+
LazyReferenceManager.get().cleanUp();
526+
final Optional<SimpleEntityWithId> reloadedObject = repository.findById(object1Id);
527+
Assertions.assertTrue(reloadedObject.isPresent());
528+
Assertions.assertEquals(objectToStore1, reloadedObject.get());
529+
}
530+
);
531+
}
532+
516533
@Test
517534
void simpleEntityWithIdLazyRepository_FindById(@Autowired final SimpleEntityWithIdLazyRepository repository)
518535
{
@@ -538,4 +555,34 @@ void simpleEntityWithIdLazyRepository_FindById(@Autowired final SimpleEntityWith
538555
Assertions.assertTrue(lazyEntitiesById.get(object1Id).isLoaded());
539556
Assertions.assertFalse(lazyEntitiesById.get(object2Id).isLoaded());
540557
}
558+
559+
@Test
560+
void simpleEntityWithComplexIdLazyRepository_FindById(
561+
@Autowired final SimpleEntityWithComplexIdLazyRepository repository)
562+
{
563+
final SimpleEntityWithComplexId objectToStore1 =
564+
new SimpleEntityWithComplexId(new CompositeKeyAsRecord(1, 1), TestData.DUMMY_STRING);
565+
final CompositeKeyAsRecord object1Id = repository.save(objectToStore1).getId();
566+
final SimpleEntityWithComplexId objectToStore2 =
567+
new SimpleEntityWithComplexId(new CompositeKeyAsRecord(1, 2), TestData.DUMMY_STRING);
568+
final CompositeKeyAsRecord object2Id = repository.save(objectToStore2).getId();
569+
570+
TestUtil.doBeforeAndAfterRestartOfDatastore(
571+
this.configuration,
572+
() -> {
573+
LazyReferenceManager.get().cleanUp();
574+
final Optional<SimpleEntityWithComplexId> reloadedObject = repository.findById(object1Id);
575+
Assertions.assertTrue(reloadedObject.isPresent());
576+
}
577+
);
578+
final EntityData<SimpleEntityWithComplexId, CompositeKeyAsRecord> entityData =
579+
this.configuration.getStorageInstance()
580+
.getRoot()
581+
.getCurrentRootData()
582+
.getEntityData(SimpleEntityWithComplexId.class);
583+
final HashMap<CompositeKeyAsRecord, Lazy<SimpleEntityWithComplexId>> lazyEntitiesById =
584+
((LazyEntityData<SimpleEntityWithComplexId, CompositeKeyAsRecord>)entityData).getNativeLazyEntitiesById();
585+
Assertions.assertTrue(lazyEntitiesById.get(object1Id).isLoaded());
586+
Assertions.assertFalse(lazyEntitiesById.get(object2Id).isLoaded());
587+
}
541588
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright © 2024 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+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.lazy;
17+
18+
import jakarta.persistence.GeneratedValue;
19+
import jakarta.persistence.GenerationType;
20+
import jakarta.persistence.Id;
21+
22+
23+
public class SimpleEntityWithComplexId
24+
{
25+
@Id
26+
private CompositeKeyAsRecord id;
27+
28+
private String name;
29+
30+
public SimpleEntityWithComplexId(final CompositeKeyAsRecord id, final String name)
31+
{
32+
this.id = id;
33+
this.name = name;
34+
}
35+
36+
public String getName()
37+
{
38+
return this.name;
39+
}
40+
41+
public void setName(final String name)
42+
{
43+
this.name = name;
44+
}
45+
46+
public CompositeKeyAsRecord getId()
47+
{
48+
return this.id;
49+
}
50+
51+
public void setId(final CompositeKeyAsRecord id)
52+
{
53+
this.id = id;
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright © 2024 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+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.lazy;
17+
18+
import software.xdev.spring.data.eclipse.store.repository.interfaces.lazy.LazyEclipseStoreRepository;
19+
20+
21+
public interface SimpleEntityWithComplexIdLazyRepository extends LazyEclipseStoreRepository<SimpleEntityWithComplexId, CompositeKeyAsRecord>
22+
{
23+
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/lazy/SimpleEntityWithId.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.lazy;
1717

18+
import java.util.Objects;
19+
1820
import jakarta.persistence.GeneratedValue;
1921
import jakarta.persistence.GenerationType;
2022
import jakarta.persistence.Id;
@@ -52,4 +54,21 @@ public void setId(final long id)
5254
{
5355
this.id = id;
5456
}
57+
58+
@Override
59+
public boolean equals(final Object o)
60+
{
61+
if(o == null || this.getClass() != o.getClass())
62+
{
63+
return false;
64+
}
65+
final SimpleEntityWithId that = (SimpleEntityWithId)o;
66+
return this.id == that.id && Objects.equals(this.name, that.name);
67+
}
68+
69+
@Override
70+
public int hashCode()
71+
{
72+
return Objects.hash(this.id, this.name);
73+
}
5574
}

0 commit comments

Comments
 (0)