File tree Expand file tree Collapse file tree 7 files changed +131
-9
lines changed
spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/id
spring-data-eclipse-store-demo/src
main/java/software/xdev/spring/data/eclipse/store/demo
test/java/software/xdev/spring/data/eclipse/store/demo Expand file tree Collapse file tree 7 files changed +131
-9
lines changed Original file line number Diff line number Diff line change 22
22
@ EnableEclipseStoreRepositories
23
23
public class ComplexConfiguration extends EclipseStoreClientConfiguration
24
24
{
25
+
26
+ public static final String STORAGE_PATH = "storage-complex" ;
27
+
25
28
@ Autowired
26
29
public ComplexConfiguration (
27
30
final EclipseStoreProperties defaultEclipseStoreProperties ,
@@ -42,7 +45,7 @@ public ComplexConfiguration(
42
45
@ Override
43
46
public EmbeddedStorageFoundation <?> createEmbeddedStorageFoundation ()
44
47
{
45
- return EmbeddedStorage .Foundation (Storage .Configuration (Storage .FileProvider (Path .of ("storage-complex" ))));
48
+ return EmbeddedStorage .Foundation (Storage .Configuration (Storage .FileProvider (Path .of (STORAGE_PATH ))));
46
49
}
47
50
48
51
/**
Original file line number Diff line number Diff line change 24
24
public class PersistenceInvoiceConfiguration extends EclipseStoreClientConfiguration
25
25
{
26
26
27
+ public static final String STORAGE_PATH = "storage-invoice" ;
28
+
27
29
@ Autowired
28
30
protected PersistenceInvoiceConfiguration (
29
31
final EclipseStoreProperties defaultEclipseStoreProperties ,
@@ -43,6 +45,6 @@ protected PersistenceInvoiceConfiguration(
43
45
@ Override
44
46
public EmbeddedStorageFoundation <?> createEmbeddedStorageFoundation ()
45
47
{
46
- return EmbeddedStorage .Foundation (Storage .Configuration (Storage .FileProvider (Path .of ("storage-invoice" ))));
48
+ return EmbeddedStorage .Foundation (Storage .Configuration (Storage .FileProvider (Path .of (STORAGE_PATH ))));
47
49
}
48
50
}
Original file line number Diff line number Diff line change 22
22
@ EnableEclipseStoreRepositories
23
23
public class PersistencePersonConfiguration extends EclipseStoreClientConfiguration
24
24
{
25
+ public static final String STORAGE_PATH = "storage-person" ;
26
+
25
27
private final EmbeddedStorageFoundationFactory foundation ;
26
28
private final EclipseStoreProperties properties ;
27
29
@@ -49,7 +51,7 @@ public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
49
51
{
50
52
final ConfigurationPair additionalProperties = new ConfigurationPair (
51
53
EmbeddedStorageConfigurationPropertyNames .STORAGE_DIRECTORY ,
52
- "storage-person" );
54
+ STORAGE_PATH );
53
55
return this .foundation .createStorageFoundation (this .properties , additionalProperties );
54
56
}
55
57
}
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 1
1
package software .xdev .spring .data .eclipse .store .demo .complex ;
2
2
3
- import static org . junit . jupiter . api . Assertions . assertTrue ;
3
+ import java . io . File ;
4
4
5
+ import org .junit .jupiter .api .BeforeAll ;
5
6
import org .junit .jupiter .api .Test ;
7
+ import org .springframework .beans .factory .annotation .Autowired ;
6
8
import org .springframework .boot .test .context .SpringBootTest ;
7
9
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
+
8
14
9
15
@ SpringBootTest (classes = ComplexDemoApplication .class )
10
16
class ComplexDemoApplicationTest
11
17
{
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
+
12
32
@ Test
13
- void checkPossibilityToSimplyStartApplication ()
33
+ void checkPossibilityToSimplyStartAndRestartApplication ()
14
34
{
15
- assertTrue (true );
35
+ this .configuration .getStorageInstance ().clearData ();
36
+ this .configuration .getStorageInstance ().stop ();
37
+ SimpleDemoApplication .main (new String []{});
16
38
}
17
39
}
Original file line number Diff line number Diff line change 1
1
package software .xdev .spring .data .eclipse .store .demo .simple ;
2
2
3
- import static org . junit . jupiter . api . Assertions . assertTrue ;
3
+ import java . io . File ;
4
4
5
+ import org .junit .jupiter .api .BeforeAll ;
5
6
import org .junit .jupiter .api .Test ;
7
+ import org .springframework .beans .factory .annotation .Autowired ;
6
8
import org .springframework .boot .test .context .SpringBootTest ;
7
9
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
+
8
14
9
15
@ SpringBootTest (classes = SimpleDemoApplication .class )
10
16
class SimpleDemoApplicationTest
11
17
{
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
+
12
33
@ Test
13
- void checkPossibilityToSimplyStartApplication ()
34
+ void checkPossibilityToSimplyStartAndRestartApplication ()
14
35
{
15
- assertTrue (true );
36
+ this .configuration .getStorageInstance ().clearData ();
37
+ this .configuration .getStorageInstance ().stop ();
38
+ SimpleDemoApplication .main (new String []{});
16
39
}
17
40
}
Original file line number Diff line number Diff line change @@ -239,6 +239,29 @@ void testCreateSingleWithAutoIdString(@Autowired final CustomerWithIdStringRepos
239
239
);
240
240
}
241
241
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
+
242
265
@ Test
243
266
void testCreateMultipleWithAutoIdString (@ Autowired final CustomerWithIdStringRepository customerRepository )
244
267
{
You can’t perform that action at this time.
0 commit comments