public class ScannerTest extends PackagingTestCase {
public void testNativeScanner() throws Exception {
File defaultPar = buildDefaultPar();
addPackageToClasspath( defaultPar );
Scanner scanner = new NativeScanner();
assertEquals( "defaultpar", scanner.getUnqualifiedJarName( defaultPar.toURL() ) );
Set<Class<? extends Annotation>> annotationsToLookFor = new HashSet<Class<? extends Annotation>>( 3 );
annotationsToLookFor.add( Entity.class );
annotationsToLookFor.add( MappedSuperclass.class );
annotationsToLookFor.add( Embeddable.class );
final Set<Class<?>> classes = scanner.getClassesInJar( defaultPar.toURL(), annotationsToLookFor );
assertEquals( 3, classes.size() );
assertTrue( classes.contains( ApplicationServer.class ) );
assertTrue( classes.contains( org.hibernate.ejb.test.pack.defaultpar.Version.class ) );
Set<String> filePatterns = new HashSet<String>( 2 );
filePatterns.add( "**/*.hbm.xml" );
filePatterns.add( "META-INF/orm.xml" );
final Set<NamedInputStream> files = scanner.getFilesInJar( defaultPar.toURL(), filePatterns );
assertEquals( 2, files.size() );
for ( NamedInputStream file : files ) {
assertNotNull( file.getStream() );
file.getStream().close();