File tree Expand file tree Collapse file tree
spring-data-eclipse-store-demo/src
main/java/software/xdev/spring/data/eclipse/store/demo
test/java/software/xdev/spring/data/eclipse/store/demo
spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222@ EnableEclipseStoreRepositories
2323public 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 /**
Original file line number Diff line number Diff line change 2424public 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}
Original file line number Diff line number Diff line change 2222@ EnableEclipseStoreRepositories
2323public 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}
Original file line number Diff line number Diff line change 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 number Diff line number Diff line change 11package 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 ;
56import org .junit .jupiter .api .Test ;
7+ import org .springframework .beans .factory .annotation .Autowired ;
68import 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 )
1016class 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 number Diff line number Diff line change 11package 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 ;
56import org .junit .jupiter .api .Test ;
7+ import org .springframework .beans .factory .annotation .Autowired ;
68import 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 )
1016class 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}
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments