Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.hibernate.Hibernate;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.engine.spi.ActionQueue;
Expand All @@ -15,10 +16,10 @@
import org.hibernate.event.spi.PreUpdateEvent;
import org.hibernate.event.spi.PreUpdateEventListener;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.testing.orm.junit.BootstrapServiceRegistryProducer;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.ServiceRegistryFunctionalTesting;
import org.hibernate.testing.orm.junit.ServiceRegistryProducer;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Assertions;
Expand All @@ -36,7 +37,7 @@
@ServiceRegistryFunctionalTesting
@DomainModel(annotatedClasses = { Author.class, Book.class, Publisher.class, UnrelatedEntity.class })
@SessionFactory
public class TestAutoFlushBeforeQueryExecution implements ServiceRegistryProducer {
public class TestAutoFlushBeforeQueryExecution implements BootstrapServiceRegistryProducer {

@Test
public void testAutoflushIsRequired(SessionFactoryScope factoryScope) {
Expand Down Expand Up @@ -211,7 +212,7 @@ record Ids (Long publisherId, Long unrelatedEntityId ) {
}

@Override
public void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
public BootstrapServiceRegistry produceServiceRegistry(BootstrapServiceRegistryBuilder builder) {
builder.applyIntegrator(
new Integrator() {
@Override
Expand All @@ -229,6 +230,7 @@ private void integrate(SessionFactoryImplementor sessionFactory) {
}
}
);
return builder.build();
}

public static class InitializingPreUpdateEventListener implements PreUpdateEventListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ dependencies {
api project( ':hibernate-envers' )
implementation project( ':hibernate-scan-jandex' )

// todo : to get rid of these
testImplementation testLibs.junit4
testImplementation testLibs.junit4Engine
testImplementation testLibs.junitJupiterApi

//Provide the jakarta.cdi module, as it's required by module jakarta.transaction
//but not provided as transitive dependency of Narayana.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
* Test-only configuration.
*/

opens org.hibernate.orm.integrationtest.java.module.test to junit;
requires junit;
opens org.hibernate.orm.integrationtest.java.module.test to org.junit.platform.commons;
requires org.junit.jupiter.api;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
*/
package org.hibernate.orm.integrationtest.java.module.test;



import org.hibernate.Session;
import org.hibernate.envers.boot.internal.EnversIntegrator;
import org.hibernate.orm.integrationtest.java.module.test.service.AuthorService;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JavaModulePathIT {

Expand Down Expand Up @@ -67,9 +64,8 @@ public void integrator() {
}

private void checkIsInModulePath(Class<?> clazz) {
Assert.assertTrue(
clazz + " should be part of a named module - there is a problem in test setup",
clazz.getModule().isNamed()
assertTrue( clazz.getModule().isNamed(),
clazz + " should be part of a named module - there is a problem in test setup"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.hibernate.orm.integrationtest.java.module.test.entity.Author;
import org.junit.jupiter.api.Test;

import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* We need to test that the scanner works, including when there is a module-info.class
Expand All @@ -34,11 +35,11 @@ public void verifyModuleInfoScanner() {
StandardScanParameters.INSTANCE
);
Set<ClassDescriptor> locatedClasses = scan.getLocatedClasses();
Assert.assertEquals( 1, locatedClasses.size() );
assertEquals( 1, locatedClasses.size() );
ClassDescriptor classDescriptor = locatedClasses.iterator().next();
Assert.assertNotNull( classDescriptor );
Assert.assertEquals( Author.class.getName(), classDescriptor.getName() );
Assert.assertEquals( ClassDescriptor.Categorization.MODEL, classDescriptor.getCategorization() );
assertNotNull( classDescriptor );
assertEquals( Author.class.getName(), classDescriptor.getName() );
assertEquals( ClassDescriptor.Categorization.MODEL, classDescriptor.getCategorization() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;

/// Applies standard set of JUnit Jupiter [extensions][org.junit.jupiter.api.extension.Extension]
/// useful for all testing.
///
/// @see FailureExpectedExtension
/// @see ExpectedExceptionExtension
/// @see DialectFilterExtension
///
/// @author Steve Ebersole
@Inherited
@Target( ElementType.TYPE )
@Retention( RetentionPolicy.RUNTIME )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

import org.hibernate.integrator.spi.Integrator;

/**
* Used to define the bootstrap ServiceRegistry to be used for testing.
*/
/// Used to define the bootstrap [org.hibernate.boot.registry.BootstrapServiceRegistry] to be used for testing.
///
/// @see ServiceRegistryExtension
///
/// @author Steve Ebersole
@Inherited
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;

/**
* Producer of BootstrapServiceRegistry
*/
/// An alternative to [@BootstrapServiceRegistry][org.hibernate.testing.orm.junit.BootstrapServiceRegistry]
/// for producing a [BootstrapServiceRegistry] when programmatic building is needed.
///
/// @see ServiceRegistryExtension
///
/// @author Steve Ebersole
public interface BootstrapServiceRegistryProducer {
/// Produce the [BootstrapServiceRegistry]
BootstrapServiceRegistry produceServiceRegistry(BootstrapServiceRegistryBuilder builder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

import org.jboss.logging.Logger;

/// Provides [ClassLoader] isolation for tests.
/// Used in combination with the test class implementing the [IsolatedClassLoaderProvider], e.g.
///
/// ```java
/// @ExtendWith(ClassLoadingIsolaterExtension.class)
/// class SomeTestClass implements IsolatedClassLoaderProvider {
/// ...
/// }
/// ```
///
/// @author Andrea Boriero
public class ClassLoadingIsolaterExtension implements AfterEachCallback, BeforeEachCallback {

private static final Logger log = Logger.getLogger( ClassLoadingIsolaterExtension.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

import org.jboss.logging.Logger;

/**
* JUnit Jupiter extension used to add {@link RequiresDialect} and {@link SkipForDialect}
* handling
*
* @author Steve Ebersole
*/
/// JUnit Jupiter extension used to add [RequiresDialect] and [SkipForDialect]
/// handling
///
/// @author Steve Ebersole
public class DialectFilterExtension implements ExecutionCondition {
private static final Logger log = Logger.getLogger( DialectFilterExtension.class );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,26 @@

import jakarta.persistence.SharedCacheMode;

/**
* @asciidoc
*
* Used to define the test model ({@link org.hibernate.boot.spi.MetadataImplementor})
* to be used for testing.
*
* Can be used by itself, along with {@link DomainModelScopeAware}, to test the MetadataImplementor. E.g.
*
* [source, java, indent=0]
* ----
* @TestDomain ( ... )
* class MyTest implements TestDomainAware {
*
* @Test
* public void doTheTest() {
* // use the injected MetadataImplementor
* }
*
* private MetadataImplementor model;
*
* @Override
* public void injectTestModelScope(MetadataImplementor model) {
* this.model = model;
* }
* }
* ----
*
*
* Can optionally be used with {@link ServiceRegistry} to define the ServiceRegistry used to
* build the MetadataImplementor (passed to
* {@link org.hibernate.boot.MetadataSources#MetadataSources(org.hibernate.service.ServiceRegistry)}).
*
* [source, java, indent=0]
* ----
* @ServiceRegistry ( ... )
* @TestDomain ( ... )
* class MyTest implements TestDomainAware {
*
* @Test
* public void doTheTest() {
* // use the injected MetadataImplementor
* }
*
* private MetadataImplementor model;
*
* @Override
* public void injectTestModelScope(MetadataImplementor model) {
* this.model = model;
* }
* }
* ----
*
* It can also be used in conjunction with {@link SessionFactory}
*
* @see DomainModelScopeAware
*
* @author Steve Ebersole
*/
/// Used to define the [domain model][org.hibernate.boot.spi.MetadataImplementor] to be used for testing.
/// Produces a [DomainModelScope] which can be injected via [JUnit ParameterResolver][DomainModelParameterResolver]
/// or via [DomainModelScopeAware]; the ParameterResolver should be preferred.
///
/// ```java
/// @DomainModel(annotatedClasses=SomeEntity.class)
/// class SomeTest {
/// @Test
/// void testStuff(DomainModelScope modelScope) {
/// ...
/// }
/// }
/// ```
///
/// @see DomainModelExtension
/// @see DomainModelScope
/// @see DomainModelScopeAware
/// @see DomainModelProducer
///
/// @author Steve Ebersole
@Inherited
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

import jakarta.persistence.SharedCacheMode;

/**
* hibernate-testing implementation of a few JUnit5 contracts to support SessionFactory-based testing,
* including argument injection (or see {@link DomainModelScopeAware})
*
* @see ServiceRegistryScope
* @see DomainModelExtension
*
* @author Steve Ebersole
*/
/// Support for defining the [domain model][MetadataImplementor] used in a test.
///
/// @see DomainModel
/// @see DomainModelFunctionalTesting
/// @see DomainModelProducer
///
/// @implNote Leverages the [service registry][ServiceRegistryScope] defined using the [ServiceRegistryExtension].
///
/// @author Steve Ebersole
public class DomainModelExtension
implements TestInstancePostProcessor, BeforeEachCallback, TestExecutionExceptionHandler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,26 @@
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* @author Steve Ebersole
*/
/// Used in conjunction with [DomainModelProducer] to behave
/// as if [@DomainModel][DomainModel] were used. E.g.
///
/// ```java
/// @DomainModelFunctionalTesting
/// class SomeTest implements DomainModelProducer {
/// @Override
/// MetadataImplementor produceModel(StandardServiceRegistry serviceRegistry) {
/// }
///
/// @Test
/// void testStuff(DomainModelScope modelScope) {
/// ...
/// }
///
/// ...
/// }
/// ```
///
/// @author Steve Ebersole
@Inherited
@Retention( RetentionPolicy.RUNTIME )
@Target({ElementType.TYPE, ElementType.METHOD})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import org.junit.jupiter.api.extension.ParameterResolutionException;
import org.junit.jupiter.api.extension.ParameterResolver;

/**
* @author Steve Ebersole
*/
/// ParameterResolver for [DomainModelExtension], capable of resolving
/// either [DomainModelScope] or [MetadataImplementor].
///
/// @author Steve Ebersole
public class DomainModelParameterResolver implements ParameterResolver {
@Override
public boolean supportsParameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.MetadataImplementor;

/**
* @author Steve Ebersole
*/
/// Alternative to [@DomainModel][DomainModel] for defining the
/// [domain model][MetadataImplementor] to use for testing.
/// Generally used in conjunction with [DomainModelFunctionalTesting].
///
/// @author Steve Ebersole
public interface DomainModelProducer {
/// Produce the domain model
MetadataImplementor produceModel(StandardServiceRegistry serviceRegistry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.RootClass;

/**
* @author Steve Ebersole
*/
/// Access to the domain model for testing as defined by either [@DomainModel][DomainModel]
/// or [DomainModelProducer].
/// Can be injected via [JUnit][DomainModelParameterResolver] or via [DomainModelScopeAware].
///
/// @author Steve Ebersole
public interface DomainModelScope {
MetadataImplementor getDomainModel();
void releaseModel();
Expand Down
Loading