77import jakarta .enterprise .inject .Instance ;
88import jakarta .enterprise .inject .se .SeContainer ;
99import jakarta .enterprise .inject .se .SeContainerInitializer ;
10-
1110import org .hibernate .boot .MetadataSources ;
1211import org .hibernate .boot .registry .BootstrapServiceRegistry ;
1312import org .hibernate .boot .registry .BootstrapServiceRegistryBuilder ;
1413import org .hibernate .boot .registry .StandardServiceRegistry ;
1514import org .hibernate .boot .spi .MetadataImplementor ;
1615import org .hibernate .engine .spi .SessionFactoryImplementor ;
17- import org .hibernate .testing .orm .junit .BaseUnitTest ;
18- import org .hibernate .tool .schema .Action ;
19-
20- import org .hibernate .testing .util .ServiceRegistryUtil ;
21-
22- import org .hibernate .orm .test .cdi .general .hibernatesearch .Monitor ;
2316import org .hibernate .orm .test .cdi .general .hibernatesearch .HibernateSearchSimulatedIntegrator ;
17+ import org .hibernate .orm .test .cdi .general .hibernatesearch .Monitor ;
2418import org .hibernate .orm .test .cdi .general .hibernatesearch .TheAlternativeNamedApplicationScopedBeanImpl ;
2519import org .hibernate .orm .test .cdi .general .hibernatesearch .TheAlternativeNamedDependentBeanImpl ;
2620import org .hibernate .orm .test .cdi .general .hibernatesearch .TheApplicationScopedBean ;
3529import org .hibernate .orm .test .cdi .general .hibernatesearch .TheNonHibernateBeanConsumer ;
3630import org .hibernate .orm .test .cdi .general .hibernatesearch .TheSharedApplicationScopedBean ;
3731import org .hibernate .orm .test .cdi .testsupport .TestingExtendedBeanManager ;
38- import org .junit .Test ;
32+ import org .hibernate .testing .orm .junit .BaseUnitTest ;
33+ import org .hibernate .testing .util .ServiceRegistryUtil ;
34+ import org .hibernate .tool .schema .Action ;
35+ import org .junit .jupiter .api .Assertions ;
36+ import org .junit .jupiter .api .Test ;
3937
4038import static org .hibernate .cfg .ManagedBeanSettings .JAKARTA_CDI_BEAN_MANAGER ;
4139import static org .hibernate .cfg .SchemaToolingSettings .HBM2DDL_AUTO ;
42- import static org .junit .Assert .assertEquals ;
4340
4441/**
4542 * Tests support for requesting CDI beans in Hibernate Search
@@ -102,17 +99,21 @@ public void test() {
10299
103100 // Here, the HibernateSearchSimulatedIntegrator has just been integrated and has requested beans
104101 // BUT it has not fetched instances of beans yet, so non-shared beans should not have been instantiated yet.
105- assertEquals ( 0 , Monitor .theApplicationScopedBean ().currentInstantiationCount () );
106- assertEquals ( 0 , Monitor .theMainNamedApplicationScopedBean ().currentInstantiationCount () );
107- assertEquals ( 0 , Monitor .theAlternativeNamedApplicationScopedBean ().currentInstantiationCount () );
108- assertEquals ( 1 , Monitor .theSharedApplicationScopedBean ().currentInstantiationCount () );
109- assertEquals ( 0 , Monitor .theDependentBean ().currentInstantiationCount () );
110- assertEquals ( 0 , Monitor .theMainNamedDependentBean ().currentInstantiationCount () );
111- assertEquals ( 0 , Monitor .theAlternativeNamedDependentBean ().currentInstantiationCount () );
112- assertEquals ( 0 , fallbackBeanInstanceProducer .currentInstantiationCount () );
113- assertEquals ( 0 , fallbackBeanInstanceProducer .currentNamedInstantiationCount () );
102+ Assertions .assertEquals ( 0 , Monitor .theApplicationScopedBean ().currentInstantiationCount () );
103+ Assertions .assertEquals ( 0 ,
104+ Monitor .theMainNamedApplicationScopedBean ().currentInstantiationCount () );
105+ Assertions .assertEquals ( 0 ,
106+ Monitor .theAlternativeNamedApplicationScopedBean ().currentInstantiationCount () );
107+ Assertions .assertEquals ( 1 ,
108+ Monitor .theSharedApplicationScopedBean ().currentInstantiationCount () );
109+ Assertions .assertEquals ( 0 , Monitor .theDependentBean ().currentInstantiationCount () );
110+ Assertions .assertEquals ( 0 , Monitor .theMainNamedDependentBean ().currentInstantiationCount () );
111+ Assertions .assertEquals ( 0 ,
112+ Monitor .theAlternativeNamedDependentBean ().currentInstantiationCount () );
113+ Assertions .assertEquals ( 0 , fallbackBeanInstanceProducer .currentInstantiationCount () );
114+ Assertions .assertEquals ( 0 , fallbackBeanInstanceProducer .currentNamedInstantiationCount () );
114115 // Nested dependent bean: 1 instance per bean that depends on it
115- assertEquals ( 1 , Monitor .theNestedDependentBean ().currentInstantiationCount () );
116+ Assertions . assertEquals ( 1 , Monitor .theNestedDependentBean ().currentInstantiationCount () );
116117
117118 extendedBeanManager .notifyListenerReady ( cdiContainer .getBeanManager () );
118119
@@ -123,68 +124,80 @@ public void test() {
123124 // See HibernateSearchSimulatedIntegrator for a detailed list of requested beans
124125
125126 // Application scope: maximum 1 instance as soon as at least one was requested
126- assertEquals ( 1 , Monitor .theApplicationScopedBean ().currentInstantiationCount () );
127- assertEquals ( 1 , Monitor .theMainNamedApplicationScopedBean ().currentInstantiationCount () );
128- assertEquals ( 0 , Monitor .theAlternativeNamedApplicationScopedBean ().currentInstantiationCount () );
129- assertEquals ( 1 , Monitor .theSharedApplicationScopedBean ().currentInstantiationCount () );
127+ Assertions .assertEquals ( 1 , Monitor .theApplicationScopedBean ().currentInstantiationCount () );
128+ Assertions .assertEquals ( 1 ,
129+ Monitor .theMainNamedApplicationScopedBean ().currentInstantiationCount () );
130+ Assertions .assertEquals ( 0 ,
131+ Monitor .theAlternativeNamedApplicationScopedBean ().currentInstantiationCount () );
132+ Assertions .assertEquals ( 1 ,
133+ Monitor .theSharedApplicationScopedBean ().currentInstantiationCount () );
130134
131135 // Dependent scope: 1 instance per bean we requested explicitly
132- assertEquals ( 2 , Monitor .theDependentBean ().currentInstantiationCount () );
133- assertEquals ( 2 , Monitor .theMainNamedDependentBean ().currentInstantiationCount () );
134- assertEquals ( 0 , Monitor .theAlternativeNamedDependentBean ().currentInstantiationCount () );
136+ Assertions .assertEquals ( 2 , Monitor .theDependentBean ().currentInstantiationCount () );
137+ Assertions .assertEquals ( 2 , Monitor .theMainNamedDependentBean ().currentInstantiationCount () );
138+ Assertions .assertEquals ( 0 ,
139+ Monitor .theAlternativeNamedDependentBean ().currentInstantiationCount () );
135140
136141 // Reflection-instantiated: 1 instance per bean we requested explicitly
137- assertEquals ( 2 , fallbackBeanInstanceProducer .currentInstantiationCount () );
138- assertEquals ( 2 , fallbackBeanInstanceProducer .currentNamedInstantiationCount () );
142+ Assertions . assertEquals ( 2 , fallbackBeanInstanceProducer .currentInstantiationCount () );
143+ Assertions . assertEquals ( 2 , fallbackBeanInstanceProducer .currentNamedInstantiationCount () );
139144
140145 // Nested dependent bean: 1 instance per bean that depends on it
141- assertEquals ( 7 , Monitor .theNestedDependentBean ().currentInstantiationCount () );
146+ Assertions . assertEquals ( 7 , Monitor .theNestedDependentBean ().currentInstantiationCount () );
142147
143148 // Expect one PostConstruct call per CDI bean instance
144- assertEquals ( 1 , Monitor .theApplicationScopedBean ().currentPostConstructCount () );
145- assertEquals ( 1 , Monitor .theMainNamedApplicationScopedBean ().currentPostConstructCount () );
146- assertEquals ( 0 , Monitor .theAlternativeNamedApplicationScopedBean ().currentPostConstructCount () );
147- assertEquals ( 1 , Monitor .theSharedApplicationScopedBean ().currentPostConstructCount () );
148- assertEquals ( 2 , Monitor .theDependentBean ().currentPostConstructCount () );
149- assertEquals ( 2 , Monitor .theMainNamedDependentBean ().currentPostConstructCount () );
150- assertEquals ( 0 , Monitor .theAlternativeNamedDependentBean ().currentPostConstructCount () );
151- assertEquals ( 7 , Monitor .theNestedDependentBean ().currentPostConstructCount () );
149+ Assertions .assertEquals ( 1 , Monitor .theApplicationScopedBean ().currentPostConstructCount () );
150+ Assertions .assertEquals ( 1 ,
151+ Monitor .theMainNamedApplicationScopedBean ().currentPostConstructCount () );
152+ Assertions .assertEquals ( 0 ,
153+ Monitor .theAlternativeNamedApplicationScopedBean ().currentPostConstructCount () );
154+ Assertions .assertEquals ( 1 ,
155+ Monitor .theSharedApplicationScopedBean ().currentPostConstructCount () );
156+ Assertions .assertEquals ( 2 , Monitor .theDependentBean ().currentPostConstructCount () );
157+ Assertions .assertEquals ( 2 , Monitor .theMainNamedDependentBean ().currentPostConstructCount () );
158+ Assertions .assertEquals ( 0 ,
159+ Monitor .theAlternativeNamedDependentBean ().currentPostConstructCount () );
160+ Assertions .assertEquals ( 7 , Monitor .theNestedDependentBean ().currentPostConstructCount () );
152161
153162 // Expect no PreDestroy call yet
154- assertEquals ( 0 , Monitor .theApplicationScopedBean ().currentPreDestroyCount () );
155- assertEquals ( 0 , Monitor .theMainNamedApplicationScopedBean ().currentPreDestroyCount () );
156- assertEquals ( 0 , Monitor .theAlternativeNamedApplicationScopedBean ().currentPreDestroyCount () );
157- assertEquals ( 0 , Monitor .theSharedApplicationScopedBean ().currentPreDestroyCount () );
158- assertEquals ( 0 , Monitor .theDependentBean ().currentPreDestroyCount () );
159- assertEquals ( 0 , Monitor .theMainNamedDependentBean ().currentPreDestroyCount () );
160- assertEquals ( 0 , Monitor .theAlternativeNamedDependentBean ().currentPreDestroyCount () );
161- assertEquals ( 0 , Monitor .theNestedDependentBean ().currentPreDestroyCount () );
163+ Assertions .assertEquals ( 0 , Monitor .theApplicationScopedBean ().currentPreDestroyCount () );
164+ Assertions .assertEquals ( 0 ,
165+ Monitor .theMainNamedApplicationScopedBean ().currentPreDestroyCount () );
166+ Assertions .assertEquals ( 0 ,
167+ Monitor .theAlternativeNamedApplicationScopedBean ().currentPreDestroyCount () );
168+ Assertions .assertEquals ( 0 , Monitor .theSharedApplicationScopedBean ().currentPreDestroyCount () );
169+ Assertions .assertEquals ( 0 , Monitor .theDependentBean ().currentPreDestroyCount () );
170+ Assertions .assertEquals ( 0 , Monitor .theMainNamedDependentBean ().currentPreDestroyCount () );
171+ Assertions .assertEquals ( 0 ,
172+ Monitor .theAlternativeNamedDependentBean ().currentPreDestroyCount () );
173+ Assertions .assertEquals ( 0 , Monitor .theNestedDependentBean ().currentPreDestroyCount () );
162174 }
163175
164176 // After the CDI context has ended, PreDestroy should have been called on every "normal-scoped" CDI bean
165177 // (i.e. all CDI beans excepting the dependent ones we requested explicitly and haven't released yet)
166- assertEquals ( 1 , Monitor .theApplicationScopedBean ().currentPreDestroyCount () );
167- assertEquals ( 1 , Monitor .theMainNamedApplicationScopedBean ().currentPreDestroyCount () );
168- assertEquals ( 0 , Monitor .theAlternativeNamedApplicationScopedBean ().currentPreDestroyCount () );
169- assertEquals ( 1 , Monitor .theSharedApplicationScopedBean ().currentPreDestroyCount () );
170- assertEquals ( 0 , Monitor .theDependentBean ().currentPreDestroyCount () );
171- assertEquals ( 0 , Monitor .theMainNamedDependentBean ().currentPreDestroyCount () );
172- assertEquals ( 0 , Monitor .theAlternativeNamedDependentBean ().currentPreDestroyCount () );
173- assertEquals ( 3 , Monitor .theNestedDependentBean ().currentPreDestroyCount () );
178+ Assertions .assertEquals ( 1 , Monitor .theApplicationScopedBean ().currentPreDestroyCount () );
179+ Assertions .assertEquals ( 1 , Monitor .theMainNamedApplicationScopedBean ().currentPreDestroyCount () );
180+ Assertions .assertEquals ( 0 ,
181+ Monitor .theAlternativeNamedApplicationScopedBean ().currentPreDestroyCount () );
182+ Assertions .assertEquals ( 1 , Monitor .theSharedApplicationScopedBean ().currentPreDestroyCount () );
183+ Assertions .assertEquals ( 0 , Monitor .theDependentBean ().currentPreDestroyCount () );
184+ Assertions .assertEquals ( 0 , Monitor .theMainNamedDependentBean ().currentPreDestroyCount () );
185+ Assertions .assertEquals ( 0 , Monitor .theAlternativeNamedDependentBean ().currentPreDestroyCount () );
186+ Assertions .assertEquals ( 3 , Monitor .theNestedDependentBean ().currentPreDestroyCount () );
174187 }
175188 }
176189 }
177190
178191 // Here, the HibernateSearchSimulatedIntegrator has just been disintegrated and has released beans
179192 // The dependent beans should now have been released as well.
180- assertEquals ( 1 , Monitor .theApplicationScopedBean ().currentPreDestroyCount () );
181- assertEquals ( 1 , Monitor .theMainNamedApplicationScopedBean ().currentPreDestroyCount () );
182- assertEquals ( 0 , Monitor .theAlternativeNamedApplicationScopedBean ().currentPreDestroyCount () );
183- assertEquals ( 1 , Monitor .theSharedApplicationScopedBean ().currentPreDestroyCount () );
184- assertEquals ( 2 , Monitor .theDependentBean ().currentPreDestroyCount () );
185- assertEquals ( 2 , Monitor .theMainNamedDependentBean ().currentPreDestroyCount () );
186- assertEquals ( 0 , Monitor .theAlternativeNamedDependentBean ().currentPreDestroyCount () );
187- assertEquals ( 7 , Monitor .theNestedDependentBean ().currentPreDestroyCount () );
193+ Assertions . assertEquals ( 1 , Monitor .theApplicationScopedBean ().currentPreDestroyCount () );
194+ Assertions . assertEquals ( 1 , Monitor .theMainNamedApplicationScopedBean ().currentPreDestroyCount () );
195+ Assertions . assertEquals ( 0 , Monitor .theAlternativeNamedApplicationScopedBean ().currentPreDestroyCount () );
196+ Assertions . assertEquals ( 1 , Monitor .theSharedApplicationScopedBean ().currentPreDestroyCount () );
197+ Assertions . assertEquals ( 2 , Monitor .theDependentBean ().currentPreDestroyCount () );
198+ Assertions . assertEquals ( 2 , Monitor .theMainNamedDependentBean ().currentPreDestroyCount () );
199+ Assertions . assertEquals ( 0 , Monitor .theAlternativeNamedDependentBean ().currentPreDestroyCount () );
200+ Assertions . assertEquals ( 7 , Monitor .theNestedDependentBean ().currentPreDestroyCount () );
188201 }
189202
190203}
0 commit comments