Skip to content

Commit 29d503b

Browse files
Refactored tests
1 parent 7333143 commit 29d503b

File tree

84 files changed

+277
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+277
-243
lines changed

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/config/EclipseStoreClientConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
2222
import org.springframework.beans.factory.annotation.Autowired;
2323
import org.springframework.beans.factory.annotation.Qualifier;
24+
import org.springframework.context.annotation.Bean;
2425
import org.springframework.context.annotation.Configuration;
2526

2627
import software.xdev.spring.data.eclipse.store.repository.EclipseStoreStorage;
@@ -72,6 +73,7 @@ public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
7273
return this.getStoreProvider().createStorageFoundation(this.getStoreConfiguration());
7374
}
7475

76+
@Bean
7577
public EclipseStoreStorage getStorageInstance()
7678
{
7779
if(this.storageInstance == null)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright © 2023 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.helper;
17+
18+
import java.util.concurrent.atomic.AtomicInteger;
19+
20+
21+
public final class StorageDirectoryNameProvider
22+
{
23+
private static final AtomicInteger seqNumber = new AtomicInteger(1);
24+
25+
public static String getNewStorageDirectoryPath()
26+
{
27+
return String.format("./target/tempstorage-%05d", seqNumber.getAndIncrement());
28+
}
29+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.isolated.tests;
16+
package software.xdev.spring.data.eclipse.store.integration.isolated;
1717

1818
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD;
1919

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,53 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.isolated.tests;
16+
package software.xdev.spring.data.eclipse.store.integration.isolated;
1717

18+
import static org.eclipse.store.storage.embedded.types.EmbeddedStorage.Foundation;
19+
20+
import java.io.IOException;
1821
import java.nio.file.Path;
1922

20-
import org.springframework.beans.factory.DisposableBean;
21-
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.beans.factory.annotation.Value;
23+
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
24+
import org.eclipse.store.storage.types.Storage;
2325
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.context.event.ContextClosedEvent;
2427
import org.springframework.context.event.ContextRefreshedEvent;
2528
import org.springframework.context.event.EventListener;
2629
import org.springframework.util.FileSystemUtils;
2730

31+
import software.xdev.spring.data.eclipse.store.helper.StorageDirectoryNameProvider;
2832
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
2933
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
3034

3135

3236
@Configuration
33-
@EnableEclipseStoreRepositories
34-
public class IsolatedTestConfiguration implements DisposableBean
37+
@EnableEclipseStoreRepositories(
38+
value = "software.xdev.spring.data.eclipse.store.integration.isolated",
39+
clientConfigurationClass = IsolatedTestConfiguration.class)
40+
public class IsolatedTestConfiguration extends EclipseStoreClientConfiguration
3541
{
36-
@Autowired
37-
EclipseStoreClientConfiguration configuration;
42+
private final String storageDirectory = StorageDirectoryNameProvider.getNewStorageDirectoryPath();
3843

39-
@Value("${org.eclipse.store.storage-directory}")
40-
private String storageDirectory;
44+
@Override
45+
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
46+
{
47+
return Foundation(Storage.Configuration(Storage.FileProvider(Path.of(this.storageDirectory))));
48+
}
4149

4250
@EventListener
4351
public void handleContextRefresh(final ContextRefreshedEvent event)
4452
{
4553
// Init with empty root object
46-
this.configuration.getStorageInstance().clearData();
54+
this.getStorageInstance().clearData();
4755
}
4856

49-
@Override
50-
public void destroy() throws Exception
57+
@EventListener
58+
public void handleContextClosed(final ContextClosedEvent event) throws IOException
5159
{
5260
// End with empty root object
53-
this.configuration.getStorageInstance().clearData();
54-
this.configuration.getStorageInstance().stop();
61+
this.getStorageInstance().clearData();
62+
this.getStorageInstance().stop();
5563
FileSystemUtils.deleteRecursively(Path.of(this.storageDirectory));
5664
}
5765
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/keywords/KeywordsTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
import org.junit.jupiter.api.Disabled;
2020
import org.junit.jupiter.api.Test;
2121
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.test.context.TestPropertySource;
2322

2423
import software.xdev.spring.data.eclipse.store.helper.TestUtil;
25-
import software.xdev.spring.data.eclipse.store.integration.isolated.tests.IsolatedTestAnnotations;
26-
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
24+
import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations;
25+
import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestConfiguration;
2726

2827

2928
/**
@@ -32,14 +31,10 @@
3231
* keywords</a>
3332
*/
3433
@IsolatedTestAnnotations
35-
@TestPropertySource(
36-
properties =
37-
"org.eclipse.store.storage-directory=./target/keywords-tests-storage"
38-
)
3934
class KeywordsTest
4035
{
4136
@Autowired
42-
private EclipseStoreClientConfiguration configuration;
37+
private IsolatedTestConfiguration configuration;
4338

4439
@Test
4540
@Disabled("For now we don't need 'existsBy'")

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/special/types/TypesTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,15 @@
2626
import org.junit.jupiter.params.provider.MethodSource;
2727
import org.springframework.beans.factory.annotation.Autowired;
2828
import org.springframework.context.ApplicationContext;
29-
import org.springframework.test.context.TestPropertySource;
3029

3130
import software.xdev.spring.data.eclipse.store.exceptions.DataTypeNotSupportedException;
3231
import software.xdev.spring.data.eclipse.store.helper.TestUtil;
33-
import software.xdev.spring.data.eclipse.store.integration.isolated.tests.IsolatedTestAnnotations;
34-
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
32+
import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations;
33+
import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestConfiguration;
3534
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository;
3635

3736

3837
@IsolatedTestAnnotations
39-
@TestPropertySource(
40-
properties =
41-
"org.eclipse.store.storage-directory=./target/isolated-tests-storage"
42-
)
4338
class TypesTest
4439
{
4540
public static final String TYPES_DATA_SOURCE =
@@ -50,7 +45,7 @@ class TypesTest
5045
+ ".TypesData#generateNotWorkingData";
5146

5247
@Autowired
53-
private EclipseStoreClientConfiguration configuration;
48+
private IsolatedTestConfiguration configuration;
5449

5550
@ParameterizedTest
5651
@MethodSource(TYPES_DATA_SOURCE)
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration;
16+
package software.xdev.spring.data.eclipse.store.integration.shared;
1717

1818
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD;
1919

@@ -25,7 +25,6 @@
2525
import org.junit.jupiter.api.extension.ExtendWith;
2626
import org.springframework.test.annotation.DirtiesContext;
2727
import org.springframework.test.context.ContextConfiguration;
28-
import org.springframework.test.context.TestPropertySource;
2928
import org.springframework.test.context.junit.jupiter.SpringExtension;
3029

3130

@@ -34,7 +33,6 @@
3433
@ExtendWith(SpringExtension.class)
3534
@ContextConfiguration(classes = {TestConfiguration.class})
3635
@DirtiesContext(classMode = BEFORE_EACH_TEST_METHOD)
37-
@TestPropertySource("/application.properties")
3836
public @interface DefaultTestAnnotations
3937
{
4038
}
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,53 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration;
16+
package software.xdev.spring.data.eclipse.store.integration.shared;
1717

18+
import static org.eclipse.store.storage.embedded.types.EmbeddedStorage.Foundation;
19+
20+
import java.io.IOException;
1821
import java.nio.file.Path;
1922

20-
import org.springframework.beans.factory.DisposableBean;
21-
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.beans.factory.annotation.Value;
23+
import org.eclipse.store.storage.embedded.types.EmbeddedStorageFoundation;
24+
import org.eclipse.store.storage.types.Storage;
2325
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.context.event.ContextClosedEvent;
2427
import org.springframework.context.event.ContextRefreshedEvent;
2528
import org.springframework.context.event.EventListener;
2629
import org.springframework.util.FileSystemUtils;
2730

31+
import software.xdev.spring.data.eclipse.store.helper.StorageDirectoryNameProvider;
2832
import software.xdev.spring.data.eclipse.store.repository.config.EclipseStoreClientConfiguration;
2933
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
3034

3135

3236
@Configuration
33-
@EnableEclipseStoreRepositories
34-
public class TestConfiguration implements DisposableBean
37+
@EnableEclipseStoreRepositories(
38+
value = "software.xdev.spring.data.eclipse.store.integration.shared",
39+
clientConfigurationClass = TestConfiguration.class)
40+
public class TestConfiguration extends EclipseStoreClientConfiguration
3541
{
36-
@Autowired
37-
EclipseStoreClientConfiguration configuration;
42+
private final String storageDirectory = StorageDirectoryNameProvider.getNewStorageDirectoryPath();
3843

39-
@Value("${org.eclipse.store.storage-directory}")
40-
private String storageDirectory;
44+
@Override
45+
public EmbeddedStorageFoundation<?> createEmbeddedStorageFoundation()
46+
{
47+
return Foundation(Storage.Configuration(Storage.FileProvider(Path.of(this.storageDirectory))));
48+
}
4149

4250
@EventListener
4351
public void handleContextRefresh(final ContextRefreshedEvent event)
4452
{
4553
// Init with empty root object
46-
this.configuration.getStorageInstance().clearData();
54+
this.getStorageInstance().clearData();
4755
}
4856

49-
@Override
50-
public void destroy() throws Exception
57+
@EventListener
58+
public void handleContextClosed(final ContextClosedEvent event) throws IOException
5159
{
5260
// End with empty root object
53-
this.configuration.getStorageInstance().clearData();
54-
this.configuration.getStorageInstance().stop();
61+
this.getStorageInstance().clearData();
62+
this.getStorageInstance().stop();
5563
FileSystemUtils.deleteRecursively(Path.of(this.storageDirectory));
5664
}
5765
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.Objects;
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
public class ChildCustomer extends ParentCustomer
1919
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import org.springframework.data.repository.CrudRepository;
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.List;
1919
import java.util.Objects;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.List;
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.Optional;
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.Objects;
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.List;
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.List;
1919
import java.util.Optional;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import org.springframework.data.repository.CrudRepository;
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import org.springframework.data.repository.CrudRepository;
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.List;
1919
import java.util.Optional;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package software.xdev.spring.data.eclipse.store.integration.repositories;
16+
package software.xdev.spring.data.eclipse.store.integration.shared.repositories;
1717

1818
import java.util.List;
1919
import java.util.Objects;

0 commit comments

Comments
 (0)