1 19 20 package org.netbeans.modules.java.j2seproject.applet; 21 22 import java.net.URL ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.Map ; 25 import java.util.Collection ; 26 import java.util.List ; 27 import java.util.Collections ; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.util.Lookup; 31 import org.openide.modules.SpecificationVersion; 32 import org.netbeans.junit.NbTestCase; 33 import org.netbeans.api.project.TestUtil; 34 import org.netbeans.api.project.Project; 35 import org.netbeans.api.project.ProjectManager; 36 import org.netbeans.api.java.platform.JavaPlatform; 37 import org.netbeans.api.java.platform.Specification; 38 import org.netbeans.api.java.classpath.ClassPath; 39 import org.netbeans.spi.project.support.ant.AntProjectHelper; 40 import org.netbeans.spi.project.support.ant.EditableProperties; 41 import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator; 42 import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; 43 import org.netbeans.modules.java.platform.JavaPlatformProvider; 44 45 public class AppletSupportTest extends NbTestCase { 46 47 private FileObject scratch; 48 private FileObject projdir; 49 private AntProjectHelper helper; 50 private FileObject source; 51 private FileObject buildFolder; 52 private FileObject classesFolder; 53 54 public AppletSupportTest (String name) { 55 super (name); 56 } 57 58 protected void setUp() throws Exception { 59 super.setUp(); 60 JavaPlatform platform1 = new TestPlatform("TP1","tp1",new Specification("j2se", new SpecificationVersion("1.4"))); 61 JavaPlatform platform2 = new TestPlatform("TP2","tp2",new Specification("j2se", new SpecificationVersion("1.5"))); 62 JavaPlatform platform3 = new TestPlatform("TP2","tp3",new Specification("j2se", new SpecificationVersion("1.5.1"))); 63 TestUtil.setLookup(new Object [] { 64 new PlatformProviderImpl(new JavaPlatform[] { 65 platform1, 66 platform2, 67 platform3 68 }), 69 }); 70 scratch = TestUtil.makeScratchDir(this); 71 FileObject folderWithSpaces = scratch.createFolder("Folder With Spaces"); 72 projdir = folderWithSpaces.createFolder("proj"); 73 J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4")); helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null); J2SEProjectGenerator.setDefaultSourceLevel(null); 76 Project p = ProjectManager.getDefault().findProject(projdir); 77 78 FileObject src = projdir.getFileObject("src"); 79 FileObject pkg = src.createFolder("pkg"); 80 source = pkg.createData("Applet","java"); 81 EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 82 String buildFolderName = (String ) J2SEProjectUtil.getEvaluatedProperty (p, ep.getProperty("build.dir")); 83 buildFolder = FileUtil.createFolder(projdir,buildFolderName); 84 String classesFolderName = (String ) J2SEProjectUtil.getEvaluatedProperty(p, ep.getProperty("build.classes.dir")); 85 classesFolder = FileUtil.createFolder(projdir,classesFolderName); 86 } 87 88 protected void tearDown() throws Exception { 89 scratch = null; 90 projdir = null; 91 helper = null; 92 super.tearDown(); 93 } 94 95 public void testgenerateHtmlFileURL () throws Exception { 96 URL url = AppletSupport.generateHtmlFileURL(source,buildFolder,classesFolder,"tp1"); 98 String [] parts = url.toExternalForm().split("/"); 99 assertTrue (parts.length>4); 100 assertEquals (parts[parts.length-1],"Applet.html"); 101 assertEquals (parts[parts.length-2],"build"); 102 assertEquals (parts[parts.length-3],"proj"); 103 assertEquals (parts[parts.length-4],"Folder%20With%20Spaces"); 104 url = AppletSupport.generateHtmlFileURL(source,buildFolder,classesFolder,"tp2"); 105 parts = url.toExternalForm().split("/"); 106 assertTrue (parts.length>4); 107 assertEquals (parts[parts.length-1],"Applet.html"); 108 assertEquals (parts[parts.length-2],"build"); 109 assertEquals (parts[parts.length-3],"proj"); 110 assertEquals (parts[parts.length-4],"Folder With Spaces"); 111 url = AppletSupport.generateHtmlFileURL(source,buildFolder,classesFolder,null); 112 parts = url.toExternalForm().split("/"); 113 assertTrue (parts.length>4); 114 assertEquals (parts[parts.length-1],"Applet.html"); 115 assertEquals (parts[parts.length-2],"build"); 116 assertEquals (parts[parts.length-3],"proj"); 117 assertEquals (parts[parts.length-4],"Folder%20With%20Spaces"); 118 url = AppletSupport.generateHtmlFileURL(source,buildFolder,classesFolder,"tp3"); 119 parts = url.toExternalForm().split("/"); 120 assertTrue (parts.length>4); 121 assertEquals (parts[parts.length-1],"Applet.html"); 122 assertEquals (parts[parts.length-2],"build"); 123 assertEquals (parts[parts.length-3],"proj"); 124 assertEquals (parts[parts.length-4],"Folder With Spaces"); 125 } 126 127 private static class PlatformProviderImpl implements JavaPlatformProvider { 128 private JavaPlatform[] platforms; 129 130 public PlatformProviderImpl (JavaPlatform[] platforms) { 131 this.platforms = platforms; 132 } 133 134 public JavaPlatform[] getInstalledPlatforms() { 135 return platforms; 136 } 137 138 public JavaPlatform getDefaultPlatform() { 139 return this.platforms[0]; 140 } 141 142 public void addPropertyChangeListener(PropertyChangeListener listener) { 143 } 144 145 public void removePropertyChangeListener(PropertyChangeListener listener) { 146 } 147 } 148 149 private static class TestPlatform extends JavaPlatform { 150 151 private String displayName; 152 private Map props; 153 private Specification spec; 154 155 public TestPlatform (String displayName, String antName, Specification spec) { 156 this.displayName = displayName; 157 this.props = Collections.singletonMap("platform.ant.name",antName); 158 this.spec = spec; 159 } 160 161 public String getDisplayName() { 162 return this.displayName; 163 } 164 165 public Specification getSpecification() { 166 return spec; 167 } 168 169 public Map getProperties() { 170 return this.props; 171 } 172 173 public ClassPath getBootstrapLibraries() { 174 return null; 175 } 176 177 public ClassPath getStandardLibraries() { 178 return null; 179 } 180 181 public String getVendor() { 182 return null; 183 } 184 185 public Collection getInstallFolders() { 186 return null; 187 } 188 189 public FileObject findTool(String toolName) { 190 return null; 191 } 192 193 public ClassPath getSourceFolders() { 194 return null; 195 } 196 197 public List getJavadocFolders() { 198 return null; 199 } 200 } 201 } 202 | Popular Tags |