|
4 | 4 | */ |
5 | 5 | package org.hibernate.orm.test.annotations.strategy; |
6 | 6 |
|
7 | | -import org.hibernate.Session; |
8 | | -import org.hibernate.Transaction; |
9 | | -import org.hibernate.boot.MetadataBuilder; |
| 7 | +import org.hibernate.boot.model.naming.ImplicitNamingStrategy; |
10 | 8 | import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl; |
11 | | - |
12 | | -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; |
13 | | -import org.junit.Test; |
| 9 | +import org.hibernate.cfg.AvailableSettings; |
| 10 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 11 | +import org.hibernate.testing.orm.junit.ServiceRegistry; |
| 12 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 13 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 14 | +import org.hibernate.testing.orm.junit.SettingProvider; |
| 15 | +import org.junit.jupiter.api.Test; |
14 | 16 |
|
15 | 17 | /** |
16 | 18 | * @author Emmanuel Bernard |
17 | 19 | */ |
18 | | -public class StrategyTest extends BaseNonConfigCoreFunctionalTestCase { |
19 | | - @Test |
20 | | - public void testComponentSafeStrategy() throws Exception { |
21 | | - Session s = openSession(); |
22 | | - Transaction tx = s.beginTransaction(); |
23 | | - Location start = new Location(); |
24 | | - start.setCity( "Paris" ); |
25 | | - start.setCountry( "France" ); |
26 | | - Location end = new Location(); |
27 | | - end.setCity( "London" ); |
28 | | - end.setCountry( "UK" ); |
29 | | - Storm storm = new Storm(); |
30 | | - storm.setEnd( end ); |
31 | | - storm.setStart( start ); |
32 | | - s.persist( storm ); |
33 | | - s.flush(); |
34 | | - tx.rollback(); |
35 | | - s.close(); |
36 | | - } |
| 20 | +@DomainModel( |
| 21 | + annotatedClasses = { |
| 22 | + Storm.class |
| 23 | + } |
| 24 | +) |
| 25 | +@SessionFactory |
| 26 | +@ServiceRegistry( |
| 27 | + settingProviders = @SettingProvider( |
| 28 | + settingName = AvailableSettings.IMPLICIT_NAMING_STRATEGY, |
| 29 | + provider = StrategyTest.ImplicitNamyStrategyProvider.class |
| 30 | + ) |
| 31 | +) |
| 32 | +public class StrategyTest { |
37 | 33 |
|
38 | | - @Override |
39 | | - protected void configureMetadataBuilder(MetadataBuilder metadataBuilder) { |
40 | | - super.configureMetadataBuilder( metadataBuilder ); |
41 | | - metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyComponentPathImpl.INSTANCE ); |
| 34 | + public static class ImplicitNamyStrategyProvider implements SettingProvider.Provider<ImplicitNamingStrategy> { |
| 35 | + @Override |
| 36 | + public ImplicitNamingStrategy getSetting() { |
| 37 | + return ImplicitNamingStrategyComponentPathImpl.INSTANCE; |
| 38 | + } |
42 | 39 | } |
43 | 40 |
|
44 | | - @Override |
45 | | - protected Class[] getAnnotatedClasses() { |
46 | | - return new Class[] { Storm.class }; |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testComponentSafeStrategy(SessionFactoryScope scope) { |
| 44 | + scope.inTransaction( |
| 45 | + session -> { |
| 46 | + Location start = new Location(); |
| 47 | + start.setCity( "Paris" ); |
| 48 | + start.setCountry( "France" ); |
| 49 | + Location end = new Location(); |
| 50 | + end.setCity( "London" ); |
| 51 | + end.setCountry( "UK" ); |
| 52 | + Storm storm = new Storm(); |
| 53 | + storm.setEnd( end ); |
| 54 | + storm.setStart( start ); |
| 55 | + session.persist( storm ); |
| 56 | + session.flush(); |
| 57 | + } |
| 58 | + ); |
47 | 59 | } |
48 | 60 | } |
0 commit comments