}
public void testEnhancementOfAllPUsWithinAResource()
throws IOException {
OpenJPAConfiguration conf = new OpenJPAConfigurationImpl();
Options opts = new Options();
opts.setProperty("p", "META-INF/persistence.xml");
Configurations.populateConfiguration(conf, opts);
MetaDataRepository repos = conf.getMetaDataRepositoryInstance();
ClassLoader loader = AccessController
.doPrivileged(J2DoPrivHelper.newTemporaryClassLoaderAction(
getClass().getClassLoader()));
Project project = new Project();
// make sure that the classes is not already enhanced for some reason
assertNotPC(loader, project,
"org.apache.openjpa.enhance.UnenhancedBootstrapInstance");
assertNotPC(loader, project,
"org.apache.openjpa.enhance.UnenhancedBootstrapInstance2");
// build up a writer that just stores to a list so that we don't
// mutate the disk.
final List<String> written = new ArrayList<String>();
BytecodeWriter writer = new BytecodeWriter() {
public void write(BCClass type) throws IOException {
assertTrue(Arrays.asList(type.getInterfaceNames()).contains(
PersistenceCapable.class.getName()));
written.add(type.getName());
}
};
opts = new Options();
// Use a restricted mdr. This mdr will not hand out metadata for excluded
// types. These are types that have known issues and should not be enhanced.
// This test tries to enhance all persistent types in the classpath and that
// can be problematic for tests which include entities that this test should
// not attempt to enhance.
opts.setProperty("MetaDataRepository",
"org.apache.openjpa.enhance.RestrictedMetaDataRepository(excludedTypes=" +
"org.apache.openjpa.persistence.jdbc.annotations.UnenhancedMixedAccess)");
opts.put(PCEnhancer.class.getName() + "#bytecodeWriter", writer);
PCEnhancer.run(null, opts);
// ensure that we do process the classes listed in the PUs
assertTrue(written.contains(
"org.apache.openjpa.enhance.UnenhancedBootstrapInstance"));