Skip to content

Commit 68a7265

Browse files
Added Tests to restart demos
1 parent 11cecf9 commit 68a7265

File tree

7 files changed

+131
-9
lines changed

7 files changed

+131
-9
lines changed

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/complex/ComplexConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
@EnableEclipseStoreRepositories
2323
public class ComplexConfiguration extends EclipseStoreClientConfiguration
2424
{
25+
26+
public static final String STORAGE_PATH = "storage-complex";
27+
2528
@Autowired
2629
public ComplexConfiguration(
2730
final EclipseStoreProperties defaultEclipseStoreProperties,
@@ -42,7 +45,7 @@ public ComplexConfiguration(
4245
@Override
4346
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
4447
{
45-
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of("storage-complex"))));
48+
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
4649
}
4750

4851
/**

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/dual/storage/invoice/PersistenceInvoiceConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
public class PersistenceInvoiceConfiguration extends EclipseStoreClientConfiguration
2525
{
2626

27+
public static final String STORAGE_PATH = "storage-invoice";
28+
2729
@Autowired
2830
protected PersistenceInvoiceConfiguration(
2931
final EclipseStoreProperties defaultEclipseStoreProperties,
@@ -43,6 +45,6 @@ protected PersistenceInvoiceConfiguration(
4345
@Override
4446
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
4547
{
46-
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of("storage-invoice"))));
48+
return EmbeddedStorage.Foundation(Storage.Configuration(Storage.FileProvider(Path.of(STORAGE_PATH))));
4749
}
4850
}

spring-data-eclipse-store-demo/src/main/java/software/xdev/spring/data/eclipse/store/demo/dual/storage/person/PersistencePersonConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
@EnableEclipseStoreRepositories
2323
public class PersistencePersonConfiguration extends EclipseStoreClientConfiguration
2424
{
25+
public static final String STORAGE_PATH = "storage-person";
26+
2527
private final EmbeddedStorageFoundationFactory foundation;
2628
private final EclipseStoreProperties properties;
2729

@@ -49,7 +51,7 @@ public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
4951
{
5052
final ConfigurationPair additionalProperties = new ConfigurationPair(
5153
EmbeddedStorageConfigurationPropertyNames.STORAGE_DIRECTORY,
52-
"storage-person");
54+
STORAGE_PATH);
5355
return this.foundation.createStorageFoundation(this.properties, additionalProperties);
5456
}
5557
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.demo;
17+
18+
import java.io.File;
19+
20+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
21+
22+
23+
public final class TestUtil
24+
{
25+
public static boolean deleteDirectory(final File directoryToDelete)
26+
{
27+
final File[] allContents = directoryToDelete.listFiles();
28+
if(allContents != null)
29+
{
30+
for(final File file : allContents)
31+
{
32+
deleteDirectory(file);
33+
}
34+
}
35+
return directoryToDelete.delete();
36+
}
37+
38+
public static void restartDatastore(final EclipseStoreClientConfiguration configuration)
39+
{
40+
configuration.getStorageInstance().stop();
41+
// Storage starts automatically again, if the repo is accessed
42+
}
43+
44+
private TestUtil()
45+
{
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
package software.xdev.spring.data.eclipse.store.demo.complex;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import java.io.File;
44

5+
import org.junit.jupiter.api.BeforeAll;
56
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
68
import org.springframework.boot.test.context.SpringBootTest;
79

10+
import software.xdev.spring.data.eclipse.store.demo.TestUtil;
11+
import software.xdev.spring.data.eclipse.store.demo.simple.SimpleDemoApplication;
12+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
13+
814

915
@SpringBootTest(classes = ComplexDemoApplication.class)
1016
class ComplexDemoApplicationTest
1117
{
18+
private final EclipseStoreClientConfiguration configuration;
19+
20+
@Autowired
21+
public ComplexDemoApplicationTest(final ComplexConfiguration configuration)
22+
{
23+
this.configuration = configuration;
24+
}
25+
26+
@BeforeAll
27+
static void clearPreviousData()
28+
{
29+
TestUtil.deleteDirectory(new File("./" + ComplexConfiguration.STORAGE_PATH));
30+
}
31+
1232
@Test
13-
void checkPossibilityToSimplyStartApplication()
33+
void checkPossibilityToSimplyStartAndRestartApplication()
1434
{
15-
assertTrue(true);
35+
this.configuration.getStorageInstance().clearData();
36+
this.configuration.getStorageInstance().stop();
37+
SimpleDemoApplication.main(new String[]{});
1638
}
1739
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
package software.xdev.spring.data.eclipse.store.demo.simple;
22

3-
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
import java.io.File;
44

5+
import org.junit.jupiter.api.BeforeAll;
56
import org.junit.jupiter.api.Test;
7+
import org.springframework.beans.factory.annotation.Autowired;
68
import org.springframework.boot.test.context.SpringBootTest;
79

10+
import software.xdev.spring.data.eclipse.store.demo.TestUtil;
11+
import software.xdev.spring.data.eclipse.store.repository.config.DefaultEclipseStoreClientConfiguration;
12+
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
13+
814

915
@SpringBootTest(classes = SimpleDemoApplication.class)
1016
class SimpleDemoApplicationTest
1117
{
18+
public static final String STORAGE_PATH = "storage";
19+
private final EclipseStoreClientConfiguration configuration;
20+
21+
@Autowired
22+
public SimpleDemoApplicationTest(final DefaultEclipseStoreClientConfiguration configuration)
23+
{
24+
this.configuration = configuration;
25+
}
26+
27+
@BeforeAll
28+
static void clearPreviousData()
29+
{
30+
TestUtil.deleteDirectory(new File("./" + STORAGE_PATH));
31+
}
32+
1233
@Test
13-
void checkPossibilityToSimplyStartApplication()
34+
void checkPossibilityToSimplyStartAndRestartApplication()
1435
{
15-
assertTrue(true);
36+
this.configuration.getStorageInstance().clearData();
37+
this.configuration.getStorageInstance().stop();
38+
SimpleDemoApplication.main(new String[]{});
1639
}
1740
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id/IdTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,29 @@ void testCreateSingleWithAutoIdString(@Autowired final CustomerWithIdStringRepos
239239
);
240240
}
241241

242+
@Test
243+
void testSaveAfterRestartSingleWithAutoIdString(@Autowired final CustomerWithIdStringRepository customerRepository)
244+
{
245+
final CustomerWithIdString customer1 = new CustomerWithIdString(TestData.FIRST_NAME, TestData.LAST_NAME);
246+
customerRepository.save(customer1);
247+
248+
TestUtil.restartDatastore(this.configuration);
249+
250+
customerRepository.deleteAll();
251+
final CustomerWithIdString customer2 =
252+
new CustomerWithIdString(TestData.FIRST_NAME_ALTERNATIVE, TestData.LAST_NAME_ALTERNATIVE);
253+
customerRepository.save(customer2);
254+
255+
TestUtil.doBeforeAndAfterRestartOfDatastore(
256+
this.configuration,
257+
() -> {
258+
final Optional<CustomerWithIdString> loadedCustomer = customerRepository.findById("2");
259+
Assertions.assertTrue(loadedCustomer.isPresent());
260+
Assertions.assertEquals(customer2, loadedCustomer.get());
261+
}
262+
);
263+
}
264+
242265
@Test
243266
void testCreateMultipleWithAutoIdString(@Autowired final CustomerWithIdStringRepository customerRepository)
244267
{

0 commit comments

Comments
 (0)