1 19 20 package org.netbeans.modules.web.project.classpath; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.io.File ; 25 import java.lang.ref.WeakReference ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectManager; 28 import org.netbeans.junit.NbTestCase; 29 import org.netbeans.modules.web.project.WebProject; 30 import org.netbeans.modules.web.project.test.TestBase; 31 import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; 32 import org.netbeans.spi.java.classpath.PathResourceImplementation; 33 import org.netbeans.spi.project.support.ant.AntProjectHelper; 34 import org.netbeans.spi.project.support.ant.EditableProperties; 35 import org.openide.filesystems.FileObject; 36 import org.openide.filesystems.FileUtil; 37 38 42 public class JspSourcePathImplementationTest extends NbTestCase { 43 44 public JspSourcePathImplementationTest(String testName) { 45 super(testName); 46 } 47 48 public void setUp() throws Exception { 49 TestBase.setLookup(new Object [0]); 51 } 52 53 public void testJspSourcePathImplementation() throws Exception { 54 File f = new File (getDataDir().getAbsolutePath(), "projects/WebApplication1"); 55 FileObject projectDir = FileUtil.toFileObject(f); 56 FileUtil.createFolder(projectDir, "web2"); 57 58 Project p = ProjectManager.getDefault().findProject(projectDir); 59 60 final AntProjectHelper helper = ((WebProject)p).getAntProjectHelper(); 62 63 JspSourcePathImplementation jspi = new JspSourcePathImplementation(helper, helper.getStandardPropertyEvaluator()); 64 65 final boolean[] changed = new boolean[1]; 66 67 jspi.addPropertyChangeListener(new PropertyChangeListener () { 68 public void propertyChange(PropertyChangeEvent evt) { 69 if (evt.getPropertyName().equals(JspSourcePathImplementation.PROP_RESOURCES)) { 70 changed[0] = true; 71 } 72 } 73 }); 74 75 77 PathResourceImplementation res = (PathResourceImplementation)jspi.getResources().get(0); 78 assertTrue(res.getRoots()[0].equals(helper.resolveFileObject("web").getURL())); 79 80 82 ProjectManager.mutex().writeAccess(new Runnable () { 83 public void run() { 84 EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 85 props.setProperty(WebProjectProperties.WEB_DOCBASE_DIR, "web2"); 86 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); 87 } 88 }); 89 90 assertTrue(changed[0]); 91 res = (PathResourceImplementation)jspi.getResources().get(0); 92 assertTrue(res.getRoots()[0].equals(helper.resolveFileObject("web2").getURL())); 93 94 96 changed[0] = false; 97 projectDir.getFileObject("web2").delete(); 98 99 assertTrue(changed[0]); 100 assertTrue(jspi.getResources().size() == 0); 101 102 104 changed[0] = false; 105 FileUtil.createFolder(projectDir, "web2"); 106 107 assertTrue(changed[0]); 108 res = (PathResourceImplementation)jspi.getResources().get(0); 109 assertTrue(res.getRoots()[0].equals(helper.resolveFileObject("web2").getURL())); 110 111 113 changed[0] = false; 114 projectDir.getFileObject("web2").delete(); 115 116 assertTrue(changed[0]); 117 assertTrue(jspi.getResources().size() == 0); 118 119 changed[0] = false; 120 ProjectManager.mutex().writeAccess(new Runnable () { 121 public void run() { 122 EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 123 props.setProperty(WebProjectProperties.WEB_DOCBASE_DIR, "web"); 124 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props); 125 } 126 }); 127 128 assertTrue(changed[0]); 129 res = (PathResourceImplementation)jspi.getResources().get(0); 130 assertTrue(res.getRoots()[0].equals(helper.resolveFileObject("web").getURL())); 131 132 134 WeakReference ref = new WeakReference (jspi); 135 jspi = null; 136 137 assertGC("The JSPI instance could not be GC'd.", ref); 138 } 139 } 140 | Popular Tags |