diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ScanningCoordinator.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ScanningCoordinator.java index 3c8b7f15ad..5c17da6f32 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ScanningCoordinator.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/ScanningCoordinator.java @@ -271,7 +271,7 @@ public class ScanningCoordinator { log.debugf( "Unable to resolve class [%s] named in persistence unit [%s]", unresolvedListedClassName, - scanEnvironment.getRootUrl().toExternalForm() + scanEnvironment.getRootUrl() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/boot/model/process/internal/ScanningCoordinatorTest.java b/hibernate-core/src/test/java/org/hibernate/boot/model/process/internal/ScanningCoordinatorTest.java new file mode 100644 index 0000000000..a78cf0730e --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/boot/model/process/internal/ScanningCoordinatorTest.java @@ -0,0 +1,93 @@ +package org.hibernate.boot.model.process.internal; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Arrays; + +import org.hibernate.boot.archive.scan.spi.ScanEnvironment; +import org.hibernate.boot.archive.scan.spi.ScanResult; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; +import org.hibernate.boot.spi.MetadataBuildingOptions; +import org.hibernate.boot.spi.XmlMappingBinderAccess; +import org.hibernate.internal.CoreMessageLogger; + +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.hibernate.testing.logger.LoggerInspectionRule; +import org.hibernate.testing.logger.Triggerable; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import org.jboss.logging.Logger; + +import org.mockito.Mockito; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; + +/** + * @author Vlad Mihalcea + */ +public class ScanningCoordinatorTest extends BaseUnitTestCase { + + private ManagedResourcesImpl managedResources = Mockito.mock( ManagedResourcesImpl.class ); + private ScanResult scanResult = Mockito.mock( ScanResult.class ); + private MetadataBuildingOptions options = Mockito.mock( MetadataBuildingOptions.class ); + private XmlMappingBinderAccess xmlMappingBinderAccess = Mockito.mock( XmlMappingBinderAccess.class ); + + private ScanEnvironment scanEnvironment = Mockito.mock( ScanEnvironment.class ); + private StandardServiceRegistry serviceRegistry = Mockito.mock( StandardServiceRegistry.class ); + + private ClassLoaderService classLoaderService = Mockito.mock( ClassLoaderService.class ); + + private Triggerable triggerable; + + @Rule + public LoggerInspectionRule logInspection = new LoggerInspectionRule( + Logger.getMessageLogger( CoreMessageLogger.class, ScanningCoordinator.class.getName() ) ); + + @Before + public void init(){ + Mockito.reset( scanEnvironment ); + + when( options.getScanEnvironment() ).thenReturn( scanEnvironment ); + when( options.getServiceRegistry() ).thenReturn( serviceRegistry ); + when( serviceRegistry.getService( ClassLoaderService.class ) ).thenReturn( classLoaderService ); + + when( scanEnvironment.getExplicitlyListedClassNames() ).thenReturn( + Arrays.asList( "a.b.C" ) ); + + when( classLoaderService.classForName( "a.b.C" ) ).thenReturn( Object.class ); + + triggerable = logInspection.watchForLogMessages( "Unable" ); + triggerable.reset(); + } + + @Test + public void testApplyScanResultsToManagedResourcesWithNullRootUrl() { + + ScanningCoordinator.INSTANCE.applyScanResultsToManagedResources( + managedResources, + scanResult, + options, + xmlMappingBinderAccess + ); + assertEquals( "Unable to resolve class [a.b.C] named in persistence unit [null]", triggerable.triggerMessage() ); + } + + @Test + public void testApplyScanResultsToManagedResourcesWithNotNullRootUrl() + throws MalformedURLException { + when( scanEnvironment.getRootUrl() ).thenReturn( new URL( "http://http://hibernate.org/" ) ); + + ScanningCoordinator.INSTANCE.applyScanResultsToManagedResources( + managedResources, + scanResult, + options, + xmlMappingBinderAccess + ); + assertEquals( "Unable to resolve class [a.b.C] named in persistence unit [http://http://hibernate.org/]", triggerable.triggerMessage() ); + } + +} \ No newline at end of file diff --git a/hibernate-core/src/test/resources/log4j.properties b/hibernate-core/src/test/resources/log4j.properties index 07c8869084..eb96581a28 100644 --- a/hibernate-core/src/test/resources/log4j.properties +++ b/hibernate-core/src/test/resources/log4j.properties @@ -57,3 +57,4 @@ log4j.logger.org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry=debug ### log4j.logger.org.hibernate.event.internal.EntityCopyAllowedLoggedObserver=debug log4j.logger.org.hibernate.testing.junit4.TestClassMetadata=info, unclosedSessionFactoryFile +log4j.logger.org.hibernate.boot.model.process.internal.ScanningCoordinator=debug diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java index c7fc8946b1..bf0594ac33 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseUnitTestCase.java @@ -10,6 +10,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import javax.transaction.SystemException; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; @@ -42,7 +43,7 @@ public abstract class BaseUnitTestCase { protected final ExecutorService executorService = Executors.newSingleThreadExecutor(); @Rule - public TestRule globalTimeout = new Timeout( 30 * 60 * 1000 ); // no test should run longer than 30 minutes + public TestRule globalTimeout = Timeout.millis( TimeUnit.MINUTES.toMillis( 30 ) ); // no test should run longer than 30 minutes public BaseUnitTestCase() { if ( enableConnectionLeakDetection ) {