diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/xml/JakartaXmlSmokeTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/xml/JakartaXmlSmokeTests.java new file mode 100644 index 0000000000..2d996897ce --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/xml/JakartaXmlSmokeTests.java @@ -0,0 +1,75 @@ +/* + * 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 org.hibernate.orm.test.jpa.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Collections; +import java.util.stream.Stream; +import javax.xml.transform.stream.StreamSource; + +import org.hibernate.boot.jaxb.Origin; +import org.hibernate.boot.jaxb.SourceType; +import org.hibernate.boot.jaxb.internal.MappingBinder; +import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity; +import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener; +import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings; +import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults; +import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata; +import org.hibernate.boot.jaxb.spi.Binding; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor; +import org.hibernate.jpa.boot.internal.PersistenceXmlParser; + +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.ServiceRegistryScope; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Steve Ebersole + */ +@ServiceRegistry +public class JakartaXmlSmokeTests { + @Test + public void testLoadingOrmXml(ServiceRegistryScope scope) { + final ClassLoaderService cls = scope.getRegistry().getService( ClassLoaderService.class ); + final MappingBinder mappingBinder = new MappingBinder( cls, true ); + final InputStream inputStream = cls.locateResourceStream( "xml/jakarta/simple/orm.xml" ); + try { + final Binding binding = mappingBinder.bind( new StreamSource( inputStream ), new Origin( SourceType.RESOURCE, "xml/jakarta/simple/orm.xml" ) ); + + assertThat( binding.getRoot().getEntity().stream().map( JaxbEntity::getClazz ) ).containsOnly( "Lighter", "ApplicationServer" ); + + final JaxbPersistenceUnitMetadata puMetadata = binding.getRoot().getPersistenceUnitMetadata(); + final JaxbPersistenceUnitDefaults puDefaults = puMetadata.getPersistenceUnitDefaults(); + final Stream listenerNames = puDefaults.getEntityListeners() + .getEntityListener() + .stream() + .map( JaxbEntityListener::getClazz ); + assertThat( listenerNames ).containsOnly( "org.hibernate.jpa.test.pack.defaultpar.IncrementListener" ); + } + finally { + try { + inputStream.close(); + } + catch (IOException ignore) { + } + } + } + + @Test + public void testLoadingPersistenceXml(ServiceRegistryScope scope) { + final ClassLoaderService cls = scope.getRegistry().getService( ClassLoaderService.class ); + final URL url = cls.locateResource( "xml/jakarta/simple/persistence.xml" ); + final ParsedPersistenceXmlDescriptor descriptor = PersistenceXmlParser.locateIndividualPersistenceUnit( url, Collections.emptyMap() ); + assertThat( descriptor.getName() ).isEqualTo( "defaultpar" ); + assertThat( descriptor.getManagedClassNames() ).contains( "org.hibernate.jpa.test.pack.defaultpar.Lighter" ); + } +} diff --git a/hibernate-core/src/test/resources/xml/jakarta.mapping/simple-jakarta-orm.xml b/hibernate-core/src/test/resources/xml/jakarta.mapping/simple-jakarta-orm.xml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/hibernate-core/src/test/resources/xml/jakarta/simple/orm.xml b/hibernate-core/src/test/resources/xml/jakarta/simple/orm.xml new file mode 100644 index 0000000000..ce1984e644 --- /dev/null +++ b/hibernate-core/src/test/resources/xml/jakarta/simple/orm.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + org.hibernate.jpa.test.pack.defaultpar + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hibernate-core/src/test/resources/xml/jakarta/simple/persistence.xml b/hibernate-core/src/test/resources/xml/jakarta/simple/persistence.xml new file mode 100644 index 0000000000..c0cd85e34d --- /dev/null +++ b/hibernate-core/src/test/resources/xml/jakarta/simple/persistence.xml @@ -0,0 +1,25 @@ + + + + + + + org.hibernate.jpa.test.pack.defaultpar.Lighter + CALLBACK + + + + + + + + + + + +