HHH-12505 - Add tests
This commit is contained in:
parent
cb68d60ce3
commit
15791a84fb
|
@ -3,15 +3,31 @@ package org.hibernate.boot.model.process.internal;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.archive.internal.ByteArrayInputStreamAccess;
|
||||
import org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl;
|
||||
import org.hibernate.boot.archive.scan.internal.DisabledScanner;
|
||||
import org.hibernate.boot.archive.scan.internal.MappingFileDescriptorImpl;
|
||||
import org.hibernate.boot.archive.scan.internal.PackageDescriptorImpl;
|
||||
import org.hibernate.boot.archive.scan.internal.ScanResultImpl;
|
||||
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
|
||||
import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor;
|
||||
import org.hibernate.boot.archive.scan.spi.PackageDescriptor;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanOptions;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanParameters;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanResult;
|
||||
import org.hibernate.boot.archive.scan.spi.Scanner;
|
||||
import org.hibernate.boot.archive.spi.InputStreamAccess;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.XmlMappingBinderAccess;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
|
@ -28,6 +44,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
* @author Petteri Pitkanen
|
||||
*/
|
||||
public class ScanningCoordinatorTest extends BaseUnitTestCase {
|
||||
|
||||
|
@ -49,6 +66,8 @@ public class ScanningCoordinatorTest extends BaseUnitTestCase {
|
|||
|
||||
@Before
|
||||
public void init(){
|
||||
Mockito.reset( scanResult );
|
||||
Mockito.reset( bootstrapContext );
|
||||
Mockito.reset( scanEnvironment );
|
||||
|
||||
when( bootstrapContext.getScanEnvironment() ).thenReturn( scanEnvironment );
|
||||
|
@ -90,4 +109,47 @@ public class ScanningCoordinatorTest extends BaseUnitTestCase {
|
|||
assertEquals( "Unable to resolve class [a.b.C] named in persistence unit [http://http://hibernate.org/]", triggerable.triggerMessage() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12505" )
|
||||
public void testManagedResourcesAfterCoordinateScanWithDisabledScanner() {
|
||||
assertManagedResourcesAfterCoordinateScanWithScanner( new DisabledScanner(), true );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12505" )
|
||||
public void testManagedResourcesAfterCoordinateScanWithCustomEnabledScanner() {
|
||||
final Scanner scanner = new Scanner() {
|
||||
@Override
|
||||
public ScanResult scan(final ScanEnvironment environment, final ScanOptions options, final ScanParameters parameters) {
|
||||
final InputStreamAccess dummyInputStreamAccess = new ByteArrayInputStreamAccess( "dummy", new byte[0] );
|
||||
return new ScanResultImpl(
|
||||
Collections.<PackageDescriptor>singleton( new PackageDescriptorImpl( "dummy", dummyInputStreamAccess ) ),
|
||||
Collections.<ClassDescriptor>singleton( new ClassDescriptorImpl( "dummy", ClassDescriptor.Categorization.MODEL, dummyInputStreamAccess ) ),
|
||||
Collections.<MappingFileDescriptor>singleton( new MappingFileDescriptorImpl( "dummy", dummyInputStreamAccess ) )
|
||||
);
|
||||
}
|
||||
};
|
||||
assertManagedResourcesAfterCoordinateScanWithScanner( scanner, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Run coordinateScan() with the given Scanner and assert the emptiness
|
||||
* of ManagedResources.
|
||||
*/
|
||||
private void assertManagedResourcesAfterCoordinateScanWithScanner(final Scanner scanner, final boolean expectedIsManagedResourcesEmpty) {
|
||||
when( bootstrapContext.getScanner() ).thenReturn( scanner );
|
||||
|
||||
final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( new MetadataSources(), bootstrapContext );
|
||||
|
||||
ScanningCoordinator.INSTANCE.coordinateScan( managedResources, bootstrapContext, xmlMappingBinderAccess );
|
||||
|
||||
assertEquals( 1, scanEnvironment.getExplicitlyListedClassNames().size() );
|
||||
assertEquals( "a.b.C", scanEnvironment.getExplicitlyListedClassNames().get(0) );
|
||||
|
||||
assertEquals( true, managedResources.getAttributeConverterDefinitions().isEmpty() );
|
||||
assertEquals( true, managedResources.getAnnotatedClassReferences().isEmpty() );
|
||||
assertEquals( expectedIsManagedResourcesEmpty, managedResources.getAnnotatedClassNames().isEmpty() );
|
||||
assertEquals( expectedIsManagedResourcesEmpty, managedResources.getAnnotatedPackageNames().isEmpty() );
|
||||
assertEquals( expectedIsManagedResourcesEmpty, managedResources.getXmlMappingBindings().isEmpty() );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue