HHH-11529 - Getting NullPointerException from ScanningCoordinator debug log
Actually URL.toString() calls toExternalForm(), so it has exactly the same effect, but without NPE.
This commit is contained in:
parent
55c0d6cdaa
commit
ba9d1c779f
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in New Issue