Skip to content

Commit 8ffb798

Browse files
Added multiple migration scripts tests
1 parent 7528d8d commit 8ffb798

File tree

11 files changed

+252
-11
lines changed

11 files changed

+252
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.data.migration.with.multiple.scripts;
17+
18+
import org.junit.jupiter.api.Assertions;
19+
import org.junit.jupiter.api.Test;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.test.context.ContextConfiguration;
22+
23+
import software.xdev.micromigration.version.MigrationVersion;
24+
import software.xdev.spring.data.eclipse.store.helper.TestUtil;
25+
import software.xdev.spring.data.eclipse.store.integration.isolated.IsolatedTestAnnotations;
26+
27+
28+
@IsolatedTestAnnotations
29+
@ContextConfiguration(classes = {DataMigrationWithMultipleScriptsTestConfiguration.class})
30+
class DataMigrationWithMultipleScriptsTest
31+
{
32+
@Autowired
33+
private DataMigrationWithMultipleScriptsTestConfiguration configuration;
34+
@Autowired
35+
private PersistedEntityRepository repository;
36+
37+
@Test
38+
void assertUpdateV1Executed()
39+
{
40+
Assertions.assertEquals(2, this.repository.count());
41+
Assertions.assertEquals(
42+
new MigrationVersion(1, 1, 0),
43+
this.configuration.getStorageInstance().getRoot().getDataVersion().getVersion());
44+
}
45+
46+
@Test
47+
void assertNotUpdatedAfterMigration()
48+
{
49+
TestUtil.doBeforeAndAfterRestartOfDatastore(
50+
this.configuration,
51+
() -> {
52+
Assertions.assertEquals(2, this.repository.count());
53+
Assertions.assertEquals(
54+
new MigrationVersion(1, 1, 0),
55+
this.configuration.getStorageInstance().getRoot().getDataVersion().getVersion());
56+
}
57+
);
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.data.migration.with.multiple.scripts;
17+
18+
import org.eclipse.serializer.reflect.ClassLoaderProvider;
19+
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
20+
import org.eclipse.store.integrations.spring.boot.types.factories.EmbeddedStorageFoundationFactory;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.context.annotation.ComponentScan;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
import software.xdev.spring.data.eclipse.store.integration.TestConfiguration;
26+
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
27+
28+
29+
@ComponentScan({
30+
"software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.multiple.scripts"})
31+
@Configuration
32+
@EnableEclipseStoreRepositories
33+
public class DataMigrationWithMultipleScriptsTestConfiguration extends TestConfiguration
34+
{
35+
@Autowired
36+
protected DataMigrationWithMultipleScriptsTestConfiguration(
37+
final EclipseStoreProperties defaultEclipseStoreProperties,
38+
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
39+
final ClassLoaderProvider classLoaderProvider)
40+
{
41+
super(defaultEclipseStoreProperties, defaultEclipseStoreProvider, classLoaderProvider);
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.data.migration.with.multiple.scripts;
17+
18+
import jakarta.persistence.GeneratedValue;
19+
import jakarta.persistence.GenerationType;
20+
import jakarta.persistence.Id;
21+
22+
23+
public class PersistedEntity
24+
{
25+
@Id
26+
@GeneratedValue(strategy = GenerationType.AUTO)
27+
private int id;
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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.data.migration.with.multiple.scripts;
17+
18+
import org.springframework.data.repository.CrudRepository;
19+
20+
21+
public interface PersistedEntityRepository extends CrudRepository<PersistedEntity, Integer>
22+
{
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.data.migration.with.multiple.scripts;
17+
18+
import org.springframework.beans.factory.annotation.Autowired;
19+
import org.springframework.stereotype.Component;
20+
21+
import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager;
22+
import software.xdev.micromigration.scripts.Context;
23+
import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot;
24+
import software.xdev.spring.data.eclipse.store.repository.root.data.version.DataMigrationScript;
25+
26+
27+
@SuppressWarnings("CheckStyle")
28+
@Component
29+
public class v1_0_0_Init extends DataMigrationScript
30+
{
31+
private final PersistedEntityRepository
32+
repository;
33+
34+
public v1_0_0_Init(@Autowired final PersistedEntityRepository repository)
35+
{
36+
this.repository = repository;
37+
}
38+
39+
@Override
40+
public void migrate(final Context<VersionedRoot, MigrationEmbeddedStorageManager> context)
41+
{
42+
this.repository.save(new PersistedEntity());
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.data.migration.with.multiple.scripts;
17+
18+
import org.springframework.beans.factory.annotation.Autowired;
19+
import org.springframework.stereotype.Component;
20+
21+
import software.xdev.micromigration.eclipsestore.MigrationEmbeddedStorageManager;
22+
import software.xdev.micromigration.scripts.Context;
23+
import software.xdev.spring.data.eclipse.store.repository.root.VersionedRoot;
24+
import software.xdev.spring.data.eclipse.store.repository.root.data.version.DataMigrationScript;
25+
26+
27+
@SuppressWarnings("CheckStyle")
28+
@Component
29+
public class v1_1_0_NextScript extends DataMigrationScript
30+
{
31+
private final PersistedEntityRepository
32+
repository;
33+
34+
public v1_1_0_NextScript(@Autowired final PersistedEntityRepository repository)
35+
{
36+
this.repository = repository;
37+
}
38+
39+
@Override
40+
public void migrate(final Context<VersionedRoot, MigrationEmbeddedStorageManager> context)
41+
{
42+
this.repository.save(new PersistedEntity());
43+
}
44+
}
Lines changed: 4 additions & 4 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.isolated.tests.data.migration.with.scripts;
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.script;
1717

1818
import org.junit.jupiter.api.Assertions;
1919
import org.junit.jupiter.api.Test;
@@ -26,11 +26,11 @@
2626

2727

2828
@IsolatedTestAnnotations
29-
@ContextConfiguration(classes = {DataMigrationWithScriptsTestConfiguration.class})
30-
class DataMigrationWithScriptsTest
29+
@ContextConfiguration(classes = {DataMigrationWithScriptTestConfiguration.class})
30+
class DataMigrationWithScriptTest
3131
{
3232
@Autowired
33-
private DataMigrationWithScriptsTestConfiguration configuration;
33+
private DataMigrationWithScriptTestConfiguration configuration;
3434
@Autowired
3535
private PersistedEntityRepository repository;
3636

Lines changed: 4 additions & 4 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.isolated.tests.data.migration.with.scripts;
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.script;
1717

1818
import org.eclipse.serializer.reflect.ClassLoaderProvider;
1919
import org.eclipse.store.integrations.spring.boot.types.configuration.EclipseStoreProperties;
@@ -26,13 +26,13 @@
2626
import software.xdev.spring.data.eclipse.store.repository.config.EnableEclipseStoreRepositories;
2727

2828

29-
@ComponentScan({"software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.scripts"})
29+
@ComponentScan({"software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.script"})
3030
@Configuration
3131
@EnableEclipseStoreRepositories
32-
public class DataMigrationWithScriptsTestConfiguration extends TestConfiguration
32+
public class DataMigrationWithScriptTestConfiguration extends TestConfiguration
3333
{
3434
@Autowired
35-
protected DataMigrationWithScriptsTestConfiguration(
35+
protected DataMigrationWithScriptTestConfiguration(
3636
final EclipseStoreProperties defaultEclipseStoreProperties,
3737
final EmbeddedStorageFoundationFactory defaultEclipseStoreProvider,
3838
final ClassLoaderProvider classLoaderProvider)
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.data.migration.with.scripts;
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.script;
1717

1818
import jakarta.persistence.GeneratedValue;
1919
import jakarta.persistence.GenerationType;
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.data.migration.with.scripts;
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.script;
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.isolated.tests.data.migration.with.scripts;
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.data.migration.with.script;
1717

1818
import org.springframework.beans.factory.annotation.Autowired;
1919
import org.springframework.stereotype.Component;

0 commit comments

Comments
 (0)