Skip to content

Commit 232778b

Browse files
committed
HHH-19846 - Drop JUnit 4 usage
Not converted... * org.hibernate.orm.test.hql.PostgreSQLFunctionSelectClauseTest - registering custom function * org.hibernate.orm.test.hql.PostgreSQLFunctionWhereClauseTest - aux-db-object * org.hibernate.orm.test.id.usertype - type registrations * org.hibernate.orm.test.idgen.enhanced.HiloOptimizerConcurrencyTest - recreation of SF during tests * org.hibernate.orm.test.type.AbstractJavaTimeTypeTest subtypes - crazy parameterization (see org.hibernate.orm.test.tm.InterceptorTransactionTest) * org.hibernate.orm.test.cdi.general.hibernatesearch.extended.HibernateSearchExtendedCdiSupportTest - not sure yet, all the other tests here pass with conversion - shelved for now
1 parent ff52b41 commit 232778b

25 files changed

+788
-793
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/cdi/converters/MonitorBean.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*/
55
package org.hibernate.orm.test.cdi.converters;
66

7+
import org.junit.jupiter.api.extension.BeforeEachCallback;
8+
import org.junit.jupiter.api.extension.ExtensionContext;
9+
710
import java.util.concurrent.atomic.AtomicInteger;
811

912
/**
@@ -45,4 +48,11 @@ public void toDbCalled() {
4548
public void fromDbCalled() {
4649
fromDbCount.getAndIncrement();
4750
}
51+
52+
public static class Resetter implements BeforeEachCallback {
53+
@Override
54+
public void beforeEach(ExtensionContext context) throws Exception {
55+
MonitorBean.reset();
56+
}
57+
}
4858
}

hibernate-core/src/test/java/org/hibernate/orm/test/cdi/converters/delayed/DelayedCdiHostedConverterTest.java

Lines changed: 47 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
*/
55
package org.hibernate.orm.test.cdi.converters.delayed;
66

7-
import jakarta.enterprise.inject.se.SeContainer;
8-
import jakarta.enterprise.inject.se.SeContainerInitializer;
9-
import org.hibernate.boot.MetadataSources;
10-
import org.hibernate.boot.registry.BootstrapServiceRegistry;
11-
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
12-
import org.hibernate.boot.registry.StandardServiceRegistry;
13-
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
14-
import org.hibernate.cfg.AvailableSettings;
15-
import org.hibernate.engine.spi.SessionFactoryImplementor;
167
import org.hibernate.orm.test.cdi.converters.ConverterBean;
178
import org.hibernate.orm.test.cdi.converters.MonitorBean;
189
import org.hibernate.orm.test.cdi.converters.TheEntity;
10+
import org.hibernate.orm.test.cdi.testsupport.CdiContainer;
11+
import org.hibernate.orm.test.cdi.testsupport.CdiContainerLinker;
12+
import org.hibernate.orm.test.cdi.testsupport.CdiContainerScope;
1913
import org.hibernate.testing.orm.junit.BaseUnitTest;
20-
import org.hibernate.testing.util.ServiceRegistryUtil;
21-
import org.hibernate.tool.schema.Action;
14+
import org.hibernate.testing.orm.junit.DomainModel;
15+
import org.hibernate.testing.orm.junit.ServiceRegistry;
16+
import org.hibernate.testing.orm.junit.SessionFactory;
17+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
18+
import org.hibernate.testing.orm.junit.Setting;
19+
import org.junit.jupiter.api.AfterEach;
2220
import org.junit.jupiter.api.Test;
21+
import org.junit.jupiter.api.extension.ExtendWith;
2322

24-
import static org.hibernate.testing.transaction.TransactionUtil2.inTransaction;
23+
import static org.hibernate.cfg.ManagedBeanSettings.CDI_BEAN_MANAGER;
24+
import static org.hibernate.cfg.ManagedBeanSettings.DELAY_CDI_ACCESS;
2525
import static org.junit.jupiter.api.Assertions.assertEquals;
2626
import static org.junit.jupiter.api.Assertions.assertFalse;
2727
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -30,75 +30,47 @@
3030
/**
3131
* @author Steve Ebersole
3232
*/
33+
@SuppressWarnings("JUnitMalformedDeclaration")
3334
@BaseUnitTest
3435
public class DelayedCdiHostedConverterTest {
35-
@Test
36-
public void testIt() {
37-
MonitorBean.reset();
38-
39-
final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance()
40-
.disableDiscovery()
41-
.addBeanClasses( MonitorBean.class, ConverterBean.class );
42-
try ( final SeContainer cdiContainer = cdiInitializer.initialize() ) {
43-
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
44-
45-
final StandardServiceRegistry ssr = ServiceRegistryUtil.serviceRegistryBuilder( bsr )
46-
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
47-
.applySetting( AvailableSettings.CDI_BEAN_MANAGER, cdiContainer.getBeanManager() )
48-
.applySetting( AvailableSettings.DELAY_CDI_ACCESS, "true" )
49-
.build();
50-
51-
final SessionFactoryImplementor sessionFactory;
52-
53-
try {
54-
sessionFactory = (SessionFactoryImplementor) new MetadataSources( ssr )
55-
.addAnnotatedClass( TheEntity.class )
56-
.buildMetadata()
57-
.getSessionFactoryBuilder()
58-
.build();
59-
}
60-
catch ( Exception e ) {
61-
StandardServiceRegistryBuilder.destroy( ssr );
62-
throw e;
63-
}
64-
65-
// The CDI bean should not have been built immediately...
66-
assertFalse( MonitorBean.wasInstantiated() );
67-
assertEquals( 0, MonitorBean.currentFromDbCount() );
68-
assertEquals( 0, MonitorBean.currentToDbCount() );
36+
@AfterEach
37+
void tearDown(SessionFactoryScope factoryScope) {
38+
factoryScope.dropData();
39+
}
6940

70-
try {
71-
inTransaction(
72-
sessionFactory,
73-
session -> session.persist( new TheEntity( 1, "me", 5 ) )
74-
);
41+
@Test
42+
@ExtendWith(MonitorBean.Resetter.class )
43+
@CdiContainer(beanClasses = {MonitorBean.class, ConverterBean.class})
44+
@ServiceRegistry(
45+
settings = @Setting(name=DELAY_CDI_ACCESS, value = "true"),
46+
resolvableSettings = @ServiceRegistry.ResolvableSetting(
47+
settingName = CDI_BEAN_MANAGER,
48+
resolver = CdiContainerLinker.StandardResolver.class
49+
)
50+
)
51+
@DomainModel(annotatedClasses = TheEntity.class)
52+
@SessionFactory
53+
public void testIt(CdiContainerScope containerScope, SessionFactoryScope factoryScope) {
54+
// The CDI bean should _not_ have been built immediately...
55+
assertFalse( MonitorBean.wasInstantiated() );
56+
assertEquals( 0, MonitorBean.currentFromDbCount() );
57+
assertEquals( 0, MonitorBean.currentToDbCount() );
7558

76-
// The CDI bean should have been built on first use
77-
assertTrue( MonitorBean.wasInstantiated() );
78-
assertEquals( 0, MonitorBean.currentFromDbCount() );
79-
assertEquals( 1, MonitorBean.currentToDbCount() );
59+
factoryScope.inTransaction( (session) -> {
60+
session.persist( new TheEntity( 1, "me", 5 ) );
61+
} );
8062

81-
inTransaction(
82-
sessionFactory,
83-
session -> {
84-
TheEntity it = session.find( TheEntity.class, 1 );
85-
assertNotNull( it );
86-
}
87-
);
63+
// The CDI bean should have been built on first use
64+
assertTrue( MonitorBean.wasInstantiated() );
65+
assertEquals( 0, MonitorBean.currentFromDbCount() );
66+
assertEquals( 1, MonitorBean.currentToDbCount() );
8867

89-
assertEquals( 1, MonitorBean.currentFromDbCount() );
90-
assertEquals( 1, MonitorBean.currentToDbCount() );
91-
}
92-
finally {
93-
inTransaction(
94-
sessionFactory,
95-
session -> {
96-
session.createQuery( "delete TheEntity" ).executeUpdate();
97-
}
98-
);
68+
factoryScope.inTransaction( (session) -> {
69+
TheEntity it = session.find( TheEntity.class, 1 );
70+
assertNotNull( it );
71+
} );
9972

100-
sessionFactory.close();
101-
}
102-
}
73+
assertEquals( 1, MonitorBean.currentFromDbCount() );
74+
assertEquals( 1, MonitorBean.currentToDbCount() );
10375
}
10476
}

0 commit comments

Comments
 (0)