1 19 20 package org.netbeans.modules.j2ee.earproject.ui.wizards; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.URL ; 25 import java.util.Collections ; 26 import java.util.HashSet ; 27 import java.util.Set ; 28 import org.netbeans.api.java.classpath.ClassPath; 29 import org.netbeans.api.java.platform.JavaPlatformManager; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.api.project.ProjectManager; 32 import org.netbeans.junit.NbTestCase; 33 import org.netbeans.modules.j2ee.earproject.EarProject; 34 import org.netbeans.modules.j2ee.earproject.EarProjectTest; 35 import org.netbeans.modules.j2ee.earproject.TestPlatformProvider; 36 import org.netbeans.modules.j2ee.earproject.test.TestUtil; 37 import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties; 38 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 39 import org.netbeans.spi.project.SubprojectProvider; 40 import org.netbeans.spi.project.support.ant.EditableProperties; 41 import org.openide.filesystems.FileObject; 42 import org.openide.filesystems.FileUtil; 43 import org.openide.filesystems.Repository; 44 45 48 public class NewEarProjectWizardIteratorTest extends NbTestCase { 49 50 private static final String DEFAULT_PLATFORM_ROOT = "1.5"; 51 52 private String serverInstanceID; 53 54 59 public static void generateEARProject( 60 File prjDirF, String name, String j2eeLevel, 61 String serverInstanceID, String warName, 62 String jarName, String carName, String mainClass, 63 String platformName, String sourceLevel) throws IOException { 64 NewEarProjectWizardIterator.testableInstantiate(prjDirF, name, 65 j2eeLevel, serverInstanceID, warName, jarName, 66 carName, mainClass, platformName, sourceLevel, null); 67 } 68 69 75 public static void generateEARProject(File earDirF, String name, 76 String j2eeLevel, String serverID) throws IOException { 77 generateEARProject(earDirF, name, j2eeLevel, serverID, null, null, null, 78 null, null, null); 79 } 80 81 public NewEarProjectWizardIteratorTest(String testName) { 82 super(testName); 83 } 84 85 protected void setUp() throws Exception { 86 clearWorkDir(); 87 FileObject scratch = TestUtil.makeScratchDir(this); 88 FileObject defaultPlatformBootRoot = scratch.createFolder(DEFAULT_PLATFORM_ROOT); 89 ClassPath defBCP = ClassPathSupport.createClassPath(new URL [] { defaultPlatformBootRoot.getURL() }); 90 91 serverInstanceID = TestUtil.registerSunAppServer( 92 this, new Object [] { new TestPlatformProvider(defBCP, defBCP) }); 93 94 assertEquals("No Java platforms found.", 2, JavaPlatformManager.getDefault().getInstalledPlatforms().length); 95 } 96 97 public void testTestableInstantiate() throws Exception { 98 File dirF = new File (getWorkDir(), "testEA"); 99 String name = "Test EnterpriseApplication"; 100 String j2eeLevel = "1.4"; 101 String warName = null; 102 String jarName = null; 103 String carName = null; 104 String mainClass = null; 105 String platformName = null; 106 String sourceLevel = null; 107 108 Set result = NewEarProjectWizardIterator.testableInstantiate(dirF, name, 109 j2eeLevel, serverInstanceID, warName, jarName, 110 carName, mainClass, platformName, sourceLevel, null); 111 112 Set <FileObject> expResult = new HashSet <FileObject>(); 113 FileObject testEAFO = FileUtil.toFileObject(new File (getWorkDir(), "testEA")); 114 assertNotNull("testEA directory", testEAFO); 115 expResult = Collections.singleton(testEAFO); 116 assertEquals(expResult, result); 117 118 EditableProperties ep = TestUtil.loadProjectProperties(testEAFO); 119 assertNull("app.client is not set", ep.getProperty(EarProjectProperties.APPLICATION_CLIENT)); 120 assertEquals("client.module.uri is empty", "", ep.getProperty(EarProjectProperties.CLIENT_MODULE_URI)); 121 } 122 123 public void testTestableInstantiateWithAppClient() throws Exception { 124 String resource = "org-netbeans-modules-j2ee-clientproject/application-client-5.xml"; 125 assertNotNull("application client registered", Repository.getDefault().getDefaultFileSystem().findResource(resource)); 126 File dirF = new File (getWorkDir(), "testEA"); 127 String name = "Test EnterpriseApplication"; 128 String j2eeLevel = "1.4"; 129 String warName = null; 130 String jarName = null; 131 String carName = "testEA-app-client"; 132 String mainClass = "testEA.app.client.Main"; 133 String platformName = null; 134 String sourceLevel = null; 135 136 Set result = NewEarProjectWizardIterator.testableInstantiate(dirF, name, 137 j2eeLevel, serverInstanceID, warName, jarName, 138 carName, mainClass, platformName, sourceLevel, null); 139 140 Set <FileObject> expResult = new HashSet <FileObject>(); 141 File testEA = new File (getWorkDir(), "testEA"); 142 FileObject testEAFO = FileUtil.toFileObject(testEA); 143 assertNotNull("testEA directory", testEAFO); 144 FileObject testEAClientFO = FileUtil.toFileObject(new File (testEA, "testEA-app-client")); 145 assertNotNull("testEA-app-client directory", testEAClientFO); 146 expResult.add(testEAFO); 147 expResult.add(testEAClientFO); 148 assertEquals(expResult, result); 149 150 EditableProperties ep = TestUtil.loadProjectProperties(testEAFO); 151 assertEquals("app.client set", "testEA-app-client", ep.getProperty(EarProjectProperties.APPLICATION_CLIENT)); 152 assertEquals("client.module.uri is set to app. client", "Test EnterpriseApplication/${app.client}", ep.getProperty(EarProjectProperties.CLIENT_MODULE_URI)); 153 } 154 155 public void testTestableInstantiateWithWebAndEJBAppClient() throws Exception { 156 String resource = "org-netbeans-modules-j2ee-clientproject/application-client-5.xml"; 157 assertNotNull("application client registered", Repository.getDefault().getDefaultFileSystem().findResource(resource)); 158 File dirF = new File (getWorkDir(), "testEA"); 159 String name = "Test EnterpriseApplication"; 160 String j2eeLevel = "1.4"; 161 String warName = "testEA-war"; 162 String jarName = "testEA-ejb"; 163 String carName = "testEA-app-client"; 164 String mainClass = "testEA.app.client.Main"; 165 String platformName = null; 166 String sourceLevel = null; 167 168 Set result = NewEarProjectWizardIterator.testableInstantiate(dirF, name, 169 j2eeLevel, serverInstanceID, warName, jarName, 170 carName, mainClass, platformName, sourceLevel, null); 171 172 Set <FileObject> expResult = new HashSet <FileObject>(); 173 File testEA = new File (getWorkDir(), "testEA"); 174 FileObject testEAFO = FileUtil.toFileObject(testEA); 175 assertNotNull("testEA directory", testEAFO); 176 FileObject testEAEjbFO = FileUtil.toFileObject(new File (testEA, "testEA-ejb")); 177 assertNotNull("testEA-ejb directory", testEAEjbFO); 178 FileObject testEAClientFO = FileUtil.toFileObject(new File (testEA, "testEA-app-client")); 179 assertNotNull("testEA-app-client directory", testEAClientFO); 180 FileObject testEAWebFO = FileUtil.toFileObject(new File (testEA, "testEA-war")); 181 assertNotNull("testEA-war directory", testEAWebFO); 182 183 expResult.add(testEAFO); 184 expResult.add(testEAEjbFO); 185 expResult.add(testEAClientFO); 186 expResult.add(testEAWebFO); 187 assertEquals(expResult, result); 188 189 EditableProperties ep = TestUtil.loadProjectProperties(testEAFO); 190 assertNull("app.client not set", ep.getProperty(EarProjectProperties.APPLICATION_CLIENT)); 191 assertEquals("client.module.uri is set to war", "testEA-war.war", ep.getProperty(EarProjectProperties.CLIENT_MODULE_URI)); 192 EarProjectTest.openProject((EarProject) ProjectManager.getDefault().findProject(testEAFO)); 193 194 doTestThatEJBWasAddedToWebAndAC(testEAWebFO, testEAClientFO); } 196 197 static void doTestThatEJBWasAddedToWebAndAC( final FileObject testEAWebFO, final FileObject testEAClientFO) throws IOException { 199 200 Project testEAClientProject = ProjectManager.getDefault().findProject(testEAClientFO); 201 SubprojectProvider acSubProjects = (SubprojectProvider) 202 testEAClientProject.getLookup().lookup(SubprojectProvider.class); 203 assertNotNull("application client has SubprojectProvider in its lookup", acSubProjects); 204 assertEquals("ejb added to application client's", 1, acSubProjects.getSubprojects().size()); 205 206 Project testEAWebProject = ProjectManager.getDefault().findProject(testEAWebFO); 207 SubprojectProvider webSubProjects = (SubprojectProvider) 208 testEAWebProject.getLookup().lookup(SubprojectProvider.class); 209 assertNotNull("web project has SubprojectProvider in its lookup", webSubProjects); 210 assertEquals("ejb added to web project's", 1, webSubProjects.getSubprojects().size()); 211 } 212 213 } 214 | Popular Tags |