1 19 20 package org.netbeans.modules.j2ee.persistence.dd; 21 22 import java.io.IOException ; 23 import java.lang.ref.Reference ; 24 import java.lang.ref.WeakReference ; 25 import org.netbeans.api.java.classpath.ClassPath; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 31 35 public class WeakMetadataUnitTest extends NbTestCase { 36 37 private FileObject dataDir; 38 private FileObject workDir; 39 40 public WeakMetadataUnitTest(String testName) { 41 super(testName); 42 } 43 44 public void setUp() throws Exception { 45 clearWorkDir(); 46 dataDir = FileUtil.toFileObject(getDataDir()); 47 workDir = FileUtil.toFileObject(getWorkDir()); 48 } 49 50 private static FileObject copyFile(FileObject source, FileObject destFolder) throws IOException { 51 return FileUtil.copyFile(source, destFolder, source.getName()); 52 } 53 54 public void testWeakMetadataUnit() throws Exception { 55 FileObject cpRoot = workDir.createFolder("root"); 56 assertNotNull(cpRoot); 57 FileObject dd = copyFile(dataDir.getFileObject("orm.xml"), workDir); 58 assertNotNull(dd); 59 60 ClassPath classPath = ClassPathSupport.createClassPath(new FileObject[] { cpRoot }); 61 WeakMetadataUnit metadataUnit = new WeakMetadataUnit(dd, classPath); 62 63 assertSame(classPath, metadataUnit.getClassPath()); 64 assertSame(dd, metadataUnit.getDeploymentDescriptor()); 65 66 Reference <ClassPath> classPathRef = new WeakReference <ClassPath>(classPath); 67 classPath = null; 68 assertGC("Should be possible to GC classPath", classPathRef); 69 70 72 ClassPath newClassPath = metadataUnit.getClassPath(); 73 assertNotNull(newClassPath); 74 assertEquals(0, newClassPath.entries().size()); 75 } 76 77 public void testConstructorParametersCanBeNull() { 78 WeakMetadataUnit metadataUnit = new WeakMetadataUnit(null, null); 79 80 assertNull(metadataUnit.getDeploymentDescriptor()); 81 82 ClassPath classPath = metadataUnit.getClassPath(); 83 assertNotNull(classPath); 84 assertEquals(0, classPath.entries().size()); 85 } 86 } 87 | Popular Tags |