diff --git a/hibernate-integrationtest-java-modules/src/test/java/org/hibernate/orm/integrationtest/java/module/test/ScannerTest.java b/hibernate-integrationtest-java-modules/src/test/java/org/hibernate/orm/integrationtest/java/module/test/ScannerTest.java new file mode 100644 index 0000000000..7e00d53bd9 --- /dev/null +++ b/hibernate-integrationtest-java-modules/src/test/java/org/hibernate/orm/integrationtest/java/module/test/ScannerTest.java @@ -0,0 +1,46 @@ +/* + * 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 . + */ +package org.hibernate.orm.integrationtest.java.module.test; + +import java.net.URL; +import java.util.Set; + +import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory; +import org.hibernate.boot.archive.scan.internal.StandardScanOptions; +import org.hibernate.boot.archive.scan.internal.StandardScanParameters; +import org.hibernate.boot.archive.scan.internal.StandardScanner; +import org.hibernate.boot.archive.scan.spi.ClassDescriptor; +import org.hibernate.boot.archive.scan.spi.ScanResult; +import org.hibernate.orm.integrationtest.java.module.entity.Author; + +import org.junit.Assert; +import org.junit.Test; + +/** + * We need to test that the scanner works, including when there is a module-info.class + * resource in the project. See also HHH-13859. + */ +public class ScannerTest { + + @Test + public void verifyModuleInfoScanner() { + URL urlToThis = Author.class.getProtectionDomain().getCodeSource().getLocation(); + StandardScanner standardScanner = new StandardScanner( StandardArchiveDescriptorFactory.INSTANCE ); + ScanResult scan = standardScanner.scan( + new TestScanEnvironment( urlToThis ), + new StandardScanOptions(), + StandardScanParameters.INSTANCE + ); + Set locatedClasses = scan.getLocatedClasses(); + Assert.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() ); + } + +} diff --git a/hibernate-integrationtest-java-modules/src/test/java/org/hibernate/orm/integrationtest/java/module/test/TestScanEnvironment.java b/hibernate-integrationtest-java-modules/src/test/java/org/hibernate/orm/integrationtest/java/module/test/TestScanEnvironment.java new file mode 100644 index 0000000000..709bf0c5cb --- /dev/null +++ b/hibernate-integrationtest-java-modules/src/test/java/org/hibernate/orm/integrationtest/java/module/test/TestScanEnvironment.java @@ -0,0 +1,42 @@ +/* + * 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 . + */ +package org.hibernate.orm.integrationtest.java.module.test; + +import java.net.URL; +import java.util.Collections; +import java.util.List; + +import org.hibernate.boot.archive.scan.spi.ScanEnvironment; + +final class TestScanEnvironment implements ScanEnvironment { + + private final URL root; + + TestScanEnvironment(URL root) { + this.root = root; + } + + @Override + public URL getRootUrl() { + return root; + } + + @Override + public List getNonRootUrls() { + return Collections.emptyList(); + } + + @Override + public List getExplicitlyListedClassNames() { + return Collections.emptyList(); + } + + @Override + public List getExplicitlyListedMappingFiles() { + return Collections.emptyList(); + } +}