Skip to content

Commit 69f16ef

Browse files
LazyRepositories: first test with simple lazy wrapper
1 parent b4fb446 commit 69f16ef

3 files changed

Lines changed: 115 additions & 0 deletions

File tree

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import software.xdev.spring.data.eclipse.store.repository.lazy.SpringDataEclipseStoreLazy;
3838

3939

40+
@SuppressWarnings("checkstyle:MethodName")
4041
@IsolatedTestAnnotations
4142
@ContextConfiguration(classes = {LazyTestConfiguration.class})
4243
class LazyTest
@@ -457,4 +458,39 @@ void lazyChangeAfterRestart(@Autowired final ObjectWithLazyRepository<SimpleObje
457458
}
458459
);
459460
}
461+
462+
@Test
463+
void simpleEntityWithIdLazyRepository_PersistetAfterRestart(
464+
@Autowired final SimpleEntityWithIdLazyRepository repository)
465+
{
466+
final SimpleEntityWithId objectToStore = new SimpleEntityWithId(TestData.DUMMY_STRING);
467+
final SpringDataEclipseStoreLazy.Default<SimpleEntityWithId> lazyObject =
468+
SpringDataEclipseStoreLazy.build(objectToStore);
469+
repository.save(lazyObject);
470+
471+
TestUtil.doBeforeAndAfterRestartOfDatastore(
472+
this.configuration,
473+
() -> {
474+
Assertions.assertEquals(1, repository.findAll().size());
475+
final Lazy<SimpleEntityWithId> reloadedObject = repository.findAll().get(0);
476+
Assertions.assertEquals(objectToStore, reloadedObject.get());
477+
}
478+
);
479+
}
480+
481+
@Test
482+
void simpleEntityWithIdLazyRepository_OnlyLoadOnDemand(@Autowired final SimpleEntityWithIdLazyRepository repository)
483+
{
484+
final SimpleEntityWithId objectToStore = new SimpleEntityWithId(TestData.DUMMY_STRING);
485+
final SpringDataEclipseStoreLazy.Default<SimpleEntityWithId> lazyObject =
486+
SpringDataEclipseStoreLazy.build(objectToStore);
487+
repository.save(lazyObject);
488+
489+
restartDatastore(this.configuration);
490+
491+
final Lazy<SimpleEntityWithId> reloadedObject = repository.findAll().get(0);
492+
Assertions.assertFalse(reloadedObject.isLoaded());
493+
Assertions.assertEquals(objectToStore, reloadedObject.get());
494+
Assertions.assertTrue(reloadedObject.isLoaded());
495+
}
460496
}
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 SimpleEntityWithId
24+
{
25+
@Id
26+
@GeneratedValue(strategy = GenerationType.AUTO)
27+
private long id;
28+
29+
private String name;
30+
31+
public SimpleEntityWithId(final String name)
32+
{
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 long getId()
47+
{
48+
return this.id;
49+
}
50+
51+
public void setId(final long id)
52+
{
53+
this.id = id;
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 org.eclipse.serializer.reference.Lazy;
19+
import org.springframework.data.repository.ListCrudRepository;
20+
21+
22+
public interface SimpleEntityWithIdLazyRepository extends ListCrudRepository<Lazy<SimpleEntityWithId>, Long>
23+
{
24+
}

0 commit comments

Comments
 (0)