HHH-16104 Clarify that tests in package org.hibernate.orm.test.cdi.general.nonregistrymanaged are about Hibernate Search

By renaming that package to
org.hibernate.orm.test.cdi.general.hibernatesearch, renaming the test
classes to include "HibernateSearch" in their name, and adapting
comments.
This commit is contained in:
Yoann Rodière 2023-01-26 09:45:06 +01:00
parent 2c78d83b5a
commit ff8b673689
21 changed files with 156 additions and 119 deletions

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import org.hibernate.boot.Metadata;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -21,12 +21,13 @@ import org.hamcrest.CoreMatchers;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Simulates a Hibernate ORM integrator consuming beans whose lifecycle is not managed by the registry,
* Simulates Hibernate Search's implementation of {@link Integrator},
* consuming beans whose lifecycle is not managed by the registry,
* but by the CDI engine only.
*
* @author Yoann Rodiere
*/
public class NonRegistryManagedBeanConsumingIntegrator implements Integrator, BeanContainer.LifecycleOptions {
public class HibernateSearchSimulatedIntegrator implements Integrator, BeanContainer.LifecycleOptions {
private final BeanInstanceProducer fallbackBeanInstanceProducer;
@ -43,7 +44,7 @@ public class NonRegistryManagedBeanConsumingIntegrator implements Integrator, Be
private ContainedBeanImplementor<TheReflectionInstantiatedBean> namedReflectionInstantiatedBean1;
private ContainedBeanImplementor<TheReflectionInstantiatedBean> namedReflectionInstantiatedBean2;
public NonRegistryManagedBeanConsumingIntegrator(BeanInstanceProducer fallbackBeanInstanceProducer) {
public HibernateSearchSimulatedIntegrator(BeanInstanceProducer fallbackBeanInstanceProducer) {
this.fallbackBeanInstanceProducer = fallbackBeanInstanceProducer;
}

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import java.util.concurrent.atomic.AtomicInteger;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import java.util.concurrent.atomic.AtomicInteger;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
/**
* @author Yoann Rodiere

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
/**
* @author Yoann Rodiere

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
@ -12,7 +12,8 @@ import jakarta.enterprise.context.Dependent;
/**
* A dependent bean required by other beans, but never requested directly
* to the {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry}.
* to the {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry}
* or {@link org.hibernate.resource.beans.container.spi.BeanContainer}.
*
* @author Yoann Rodiere
*/

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Singleton;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.enterprise.inject.Vetoed;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;
package org.hibernate.orm.test.cdi.general.hibernatesearch;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged.delayed;
package org.hibernate.orm.test.cdi.general.hibernatesearch.delayed;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.se.SeContainer;
@ -17,47 +17,55 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.tool.schema.Action;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.Monitor;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.NonRegistryManagedBeanConsumingIntegrator;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheAlternativeNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheAlternativeNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheEntity;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheFallbackBeanInstanceProducer;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheMainNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheMainNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNamedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNamedDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNestedDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNonHibernateBeanConsumer;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheSharedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.Monitor;
import org.hibernate.orm.test.cdi.general.hibernatesearch.HibernateSearchSimulatedIntegrator;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheAlternativeNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheAlternativeNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheEntity;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheFallbackBeanInstanceProducer;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheMainNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheMainNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNamedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNamedDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNestedDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNonHibernateBeanConsumer;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheSharedApplicationScopedBean;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Tests support for requesting CDI beans from the {@link ManagedBeanRegistry}
* when the CDI BeanManager access is delayed (not available during bootstrap),
* and when the registry should not manage the lifecycle of beans, but leave it up to CDI.
* Tests support for requesting CDI beans in Hibernate Search
* when the CDI BeanManager access is <strong>delayed</strong> (not available during bootstrap)
*
* In Hibernate Search,
* beans are retrieved directly from the {@link org.hibernate.resource.beans.container.spi.BeanContainer}
* because Hibernate Search is not bound by the JPA spec
* and wants to leave the lifecycle of beans up to CDI instead
* of controlling it in {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry}.
* This involves using {@code canUseCachedReferences = false} and {@code useJpaCompliantCreation = false}
* in {@link org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions}).
*
* @author Steve Ebersole
* @author Yoann Rodiere
*
* @see HibernateSearchSimulatedIntegrator
*/
public class NonRegistryManagedDelayedCdiSupportTest extends BaseUnitTestCase {
public class HibernateSearchDelayedCdiSupportTest extends BaseUnitTestCase {
@Test
public void testIt() {
Monitor.reset();
final TheFallbackBeanInstanceProducer fallbackBeanInstanceProducer =
new TheFallbackBeanInstanceProducer();
final NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator =
new NonRegistryManagedBeanConsumingIntegrator( fallbackBeanInstanceProducer );
final HibernateSearchSimulatedIntegrator beanConsumingIntegrator =
new HibernateSearchSimulatedIntegrator( fallbackBeanInstanceProducer );
final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance()
.disableDiscovery()
@ -91,8 +99,8 @@ public class NonRegistryManagedDelayedCdiSupportTest extends BaseUnitTestCase {
assertEquals( 1, Monitor.theNestedDependentBean().currentInstantiationCount() );
try (SessionFactoryImplementor sessionFactory = buildSessionFactory( cdiContainer, beanConsumingIntegrator )) {
// Here, the NonRegistryManagedBeanConsumingIntegrator has just been integrated and has requested beans
// See NonRegistryManagedBeanConsumingIntegrator for a detailed list of requested beans
// Here, the HibernateSearchSimulatedIntegrator has just been integrated and has requested beans
// See HibernateSearchSimulatedIntegrator for a detailed list of requested beans
beanConsumingIntegrator.ensureInstancesInitialized();
@ -167,7 +175,7 @@ public class NonRegistryManagedDelayedCdiSupportTest extends BaseUnitTestCase {
}
private SessionFactoryImplementor buildSessionFactory(SeContainer cdiContainer,
NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) {
HibernateSearchSimulatedIntegrator beanConsumingIntegrator) {
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
.applyIntegrator( beanConsumingIntegrator )
.build();

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged.extended;
package org.hibernate.orm.test.cdi.general.hibernatesearch.extended;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.se.SeContainer;
@ -17,39 +17,47 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.tool.schema.Action;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.Monitor;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.NonRegistryManagedBeanConsumingIntegrator;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheAlternativeNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheAlternativeNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheEntity;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheFallbackBeanInstanceProducer;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheMainNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheMainNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNamedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNamedDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNestedDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNonHibernateBeanConsumer;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheSharedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.Monitor;
import org.hibernate.orm.test.cdi.general.hibernatesearch.HibernateSearchSimulatedIntegrator;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheAlternativeNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheAlternativeNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheEntity;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheFallbackBeanInstanceProducer;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheMainNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheMainNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNamedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNamedDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNestedDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNonHibernateBeanConsumer;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheSharedApplicationScopedBean;
import org.hibernate.orm.test.cdi.testsupport.TestingExtendedBeanManager;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Tests support for requesting CDI beans from the {@link ManagedBeanRegistry}
* when the CDI BeanManager access is "lazy" (beans are instantiated when instances are first requested),
* and when the registry should not manage the lifecycle of beans, but leave it up to CDI.
* Tests support for requesting CDI beans in Hibernate Search
* when the CDI BeanManager access is <strong>lazy</strong> (beans are instantiated when instances are first requested).
*
* In Hibernate Search,
* beans are retrieved directly from the {@link org.hibernate.resource.beans.container.spi.BeanContainer}
* because Hibernate Search is not bound by the JPA spec
* and wants to leave the lifecycle of beans up to CDI instead
* of controlling it in {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry}.
* This involves using {@code canUseCachedReferences = false} and {@code useJpaCompliantCreation = false}
* in {@link org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions}).
*
* @author Steve Ebersole
* @author Yoann Rodiere
*
* @see HibernateSearchSimulatedIntegrator
*/
public class NonRegistryManagedExtendedCdiSupportTest extends BaseUnitTestCase {
public class HibernateSearchExtendedCdiSupportTest extends BaseUnitTestCase {
@Test
public void test() {
doTest( TestingExtendedBeanManager.create() );
@ -60,8 +68,8 @@ public class NonRegistryManagedExtendedCdiSupportTest extends BaseUnitTestCase {
final TheFallbackBeanInstanceProducer fallbackBeanInstanceProducer =
new TheFallbackBeanInstanceProducer();
final NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator =
new NonRegistryManagedBeanConsumingIntegrator( fallbackBeanInstanceProducer );
final HibernateSearchSimulatedIntegrator beanConsumingIntegrator =
new HibernateSearchSimulatedIntegrator( fallbackBeanInstanceProducer );
try (SessionFactoryImplementor sessionFactory = buildSessionFactory( beanManager, beanConsumingIntegrator )) {
final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance()
@ -81,7 +89,7 @@ public class NonRegistryManagedExtendedCdiSupportTest extends BaseUnitTestCase {
cdiContainer.getBeanManager().createInstance().select( TheNonHibernateBeanConsumer.class );
nonHibernateBeanConsumerInstance.get();
// Here, the NonRegistryManagedBeanConsumingIntegrator has just been integrated and has requested beans
// Here, the HibernateSearchSimulatedIntegrator has just been integrated and has requested beans
// BUT it has not fetched instances of beans yet, so non-shared beans should not have been instantiated yet.
assertEquals( 0, Monitor.theApplicationScopedBean().currentInstantiationCount() );
assertEquals( 0, Monitor.theMainNamedApplicationScopedBean().currentInstantiationCount() );
@ -99,9 +107,9 @@ public class NonRegistryManagedExtendedCdiSupportTest extends BaseUnitTestCase {
beanConsumingIntegrator.ensureInstancesInitialized();
// Here the NonRegistryManagedBeanConsumingIntegrator *did* fetch an instance of each bean,
// Here the HibernateSearchSimulatedIntegrator *did* fetch an instance of each bean,
// so all beans should have been instantiated.
// See NonRegistryManagedBeanConsumingIntegrator for a detailed list of requested beans
// See HibernateSearchSimulatedIntegrator for a detailed list of requested beans
// Application scope: maximum 1 instance as soon as at least one was requested
assertEquals( 1, Monitor.theApplicationScopedBean().currentInstantiationCount() );
@ -154,7 +162,7 @@ public class NonRegistryManagedExtendedCdiSupportTest extends BaseUnitTestCase {
assertEquals( 3, Monitor.theNestedDependentBean().currentPreDestroyCount() );
}
// Here, the NonRegistryManagedBeanConsumingIntegrator has just been disintegrated and has released beans
// Here, the HibernateSearchSimulatedIntegrator has just been disintegrated and has released beans
// The dependent beans should now have been released as well.
assertEquals( 1, Monitor.theApplicationScopedBean().currentPreDestroyCount() );
assertEquals( 1, Monitor.theMainNamedApplicationScopedBean().currentPreDestroyCount() );
@ -167,7 +175,7 @@ public class NonRegistryManagedExtendedCdiSupportTest extends BaseUnitTestCase {
}
private SessionFactoryImplementor buildSessionFactory(TestingExtendedBeanManager beanManager,
NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) {
HibernateSearchSimulatedIntegrator beanConsumingIntegrator) {
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
.applyIntegrator( beanConsumingIntegrator )
.build();

View File

@ -0,0 +1,25 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
/**
* Package for testing requests of CDI beans in Hibernate Search.
*
* In Hibernate Search,
* beans are retrieved directly from the {@link org.hibernate.resource.beans.container.spi.BeanContainer}
* because Hibernate Search is not bound by the JPA spec
* and wants to leave the lifecycle of beans up to CDI instead
* of controlling it in {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry}.
* This involves using {@code canUseCachedReferences = false} and {@code useJpaCompliantCreation = false}
* in {@link org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions}).
*
* Mainly these are regression tests against Hibernate Search's pattern of usage of ORM's
* {@link org.hibernate.resource.beans.container.spi.BeanContainer} as accessed
* via {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry#getBeanContainer()}.
*
* @see org.hibernate.orm.test.cdi.general.hibernatesearch.HibernateSearchSimulatedIntegrator
*/
package org.hibernate.orm.test.cdi.general.hibernatesearch;

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged.standard;
package org.hibernate.orm.test.cdi.general.hibernatesearch.standard;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.se.SeContainer;
@ -17,46 +17,58 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.orm.test.cdi.general.hibernatesearch.delayed.HibernateSearchDelayedCdiSupportTest;
import org.hibernate.orm.test.cdi.general.hibernatesearch.extended.HibernateSearchExtendedCdiSupportTest;
import org.hibernate.tool.schema.Action;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.Monitor;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.NonRegistryManagedBeanConsumingIntegrator;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheAlternativeNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheAlternativeNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheEntity;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheFallbackBeanInstanceProducer;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheMainNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheMainNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNamedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNamedDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNestedDependentBean;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheNonHibernateBeanConsumer;
import org.hibernate.orm.test.cdi.general.nonregistrymanaged.TheSharedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.Monitor;
import org.hibernate.orm.test.cdi.general.hibernatesearch.HibernateSearchSimulatedIntegrator;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheAlternativeNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheAlternativeNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheEntity;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheFallbackBeanInstanceProducer;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheMainNamedApplicationScopedBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheMainNamedDependentBeanImpl;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNamedApplicationScopedBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNamedDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNestedDependentBean;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheNonHibernateBeanConsumer;
import org.hibernate.orm.test.cdi.general.hibernatesearch.TheSharedApplicationScopedBean;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Tests support for requesting CDI beans from the {@link ManagedBeanRegistry}
* when the CDI BeanManager is available right away during bootstrap,
* and when the registry should not manage the lifecycle of beans, but leave it up to CDI.
* Tests support for requesting CDI beans in Hibernate Search
* when the CDI BeanManager access is <strong>available right away</strong> during bootstrap
* (not {@link HibernateSearchDelayedCdiSupportTest delayed}
* nor {@link HibernateSearchExtendedCdiSupportTest lazy}).
*
* In Hibernate Search,
* beans are retrieved directly from the {@link org.hibernate.resource.beans.container.spi.BeanContainer}
* because Hibernate Search is not bound by the JPA spec
* and wants to leave the lifecycle of beans up to CDI instead
* of controlling it in {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry}.
* This involves using {@code canUseCachedReferences = false} and {@code useJpaCompliantCreation = false}
* in {@link org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions}).
*
* @author Steve Ebersole
* @author Yoann Rodiere
*
* @see HibernateSearchSimulatedIntegrator
*/
public class NonRegistryManagedStandardCdiSupportTest extends BaseUnitTestCase {
public class HibernateSearchStandardCdiSupportTest extends BaseUnitTestCase {
@Test
public void testIt() {
Monitor.reset();
final TheFallbackBeanInstanceProducer fallbackBeanInstanceProducer =
new TheFallbackBeanInstanceProducer();
final NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator =
new NonRegistryManagedBeanConsumingIntegrator( fallbackBeanInstanceProducer );
final HibernateSearchSimulatedIntegrator beanConsumingIntegrator =
new HibernateSearchSimulatedIntegrator( fallbackBeanInstanceProducer );
final SeContainerInitializer cdiInitializer = SeContainerInitializer.newInstance()
.disableDiscovery()
@ -90,8 +102,8 @@ public class NonRegistryManagedStandardCdiSupportTest extends BaseUnitTestCase {
assertEquals( 1, Monitor.theNestedDependentBean().currentInstantiationCount() );
try (SessionFactoryImplementor sessionFactory = buildSessionFactory( cdiContainer, beanConsumingIntegrator )) {
// Here, the NonRegistryManagedBeanConsumingIntegrator has just been integrated and has requested beans
// See NonRegistryManagedBeanConsumingIntegrator for a detailed list of requested beans
// Here, the HibernateSearchSimulatedIntegrator has just been integrated and has requested beans
// See HibernateSearchSimulatedIntegrator for a detailed list of requested beans
beanConsumingIntegrator.ensureInstancesInitialized();
@ -134,7 +146,7 @@ public class NonRegistryManagedStandardCdiSupportTest extends BaseUnitTestCase {
assertEquals( 0, Monitor.theNestedDependentBean().currentPreDestroyCount() );
}
// Here, the NonRegistryManagedBeanConsumingIntegrator has just been disintegrated and has released beans
// Here, the HibernateSearchSimulatedIntegrator has just been disintegrated and has released beans
// release() should have an effect on exclusively used application-scoped beans
assertEquals( 1, Monitor.theApplicationScopedBean().currentPreDestroyCount() );
@ -166,7 +178,7 @@ public class NonRegistryManagedStandardCdiSupportTest extends BaseUnitTestCase {
}
private SessionFactoryImplementor buildSessionFactory(SeContainer cdiContainer,
NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) {
HibernateSearchSimulatedIntegrator beanConsumingIntegrator) {
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
.applyIntegrator( beanConsumingIntegrator )
.build();

View File

@ -1,18 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
/**
* Package for testing Hibernate's support for integrating
* with CDI for beans whose lifecycle is not managed by the
* {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry}
* (i.e. beans retrieved with shouldRegistryManageLifecycle = false).
*
* Mainly these are regression tests against Search's pattern of usage of ORM's
* {@link org.hibernate.resource.beans.container.spi.BeanContainer} as accessed
* via {@link org.hibernate.resource.beans.spi.ManagedBeanRegistry#getBeanContainer()}
*/
package org.hibernate.orm.test.cdi.general.nonregistrymanaged;