1 19 20 package org.netbeans.modules.j2ee.clientproject; 21 22 import java.io.File ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.modules.j2ee.clientproject.test.TestUtil; 27 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 28 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 29 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 30 import org.netbeans.spi.project.support.ant.AntProjectHelper; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 34 37 public class AppClientProviderTest extends NbTestCase { 38 39 private static final String APPLICATION_CLIENT_XML = "application-client.xml"; 40 41 public AppClientProviderTest(String testName) { 42 super(testName); 43 } 44 45 protected void setUp() throws Exception { 46 super.setUp(); 47 TestUtil.makeScratchDir(this); 48 } 49 50 53 public void testPathsAreReturned() throws Exception { 54 File f = new File (getDataDir().getAbsolutePath(), "projects/ApplicationClient1"); 55 Project project = ProjectManager.getDefault().findProject(FileUtil.toFileObject(f)); 56 AntProjectHelper helper = ((AppClientProject) project).getAntProjectHelper(); 58 59 String metaInf = helper.getStandardPropertyEvaluator().getProperty("meta.inf"); 61 assertTrue(metaInf.endsWith("conf")); 62 FileObject metaInfFO =helper.resolveFileObject(metaInf); 63 assertNotNull(metaInfFO); 64 65 FileObject appXmlFO = metaInfFO.getFileObject(APPLICATION_CLIENT_XML); 67 assertNotNull(appXmlFO); 68 69 J2eeModuleProvider provider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 71 assertEquals(appXmlFO, provider.findDeploymentConfigurationFile(APPLICATION_CLIENT_XML)); 72 assertEquals(FileUtil.toFile(metaInfFO.getFileObject(APPLICATION_CLIENT_XML)), 73 provider.getDeploymentConfigurationFile(APPLICATION_CLIENT_XML)); 74 75 J2eeModule j2eeModule = (J2eeModule)project.getLookup().lookup(J2eeModule.class); 76 assertNotNull(j2eeModule.getDeploymentDescriptor(J2eeModule.CLIENT_XML)); 77 } 78 79 public void testThatProjectWithoutDDCanBeOpened() throws Exception { 80 File prjDirOrigF = new File (getDataDir().getAbsolutePath(), "projects/ApplicationClient1"); 81 File prjDirF = TestUtil.copyFolder(getWorkDir(), prjDirOrigF); 82 TestUtil.deleteRec(new File (new File (prjDirF, "src"), "conf")); 83 84 Project project = ProjectManager.getDefault().findProject(FileUtil.toFileObject(prjDirF)); 85 86 J2eeModuleProvider provider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 88 File someConfFile = provider.getDeploymentConfigurationFile("does-not-matter.xml"); 89 assertNotNull("J2eeModuleProvider.getDeploymentConfigurationFile() cannot return null", someConfFile); 90 File expected = new File (prjDirF + File.separator + "src" + 91 File.separator + "conf" + File.separator + "does-not-matter.xml"); 92 assertEquals("expected path", expected, someConfFile); 93 } 94 95 public void testNeedConfigurationFolder() { 96 assertTrue("1.3 needs configuration folder", 97 AppClientProvider.needConfigurationFolder(AppClientProjectProperties.J2EE_1_3)); 98 assertTrue("1.4 needs configuration folder", 99 AppClientProvider.needConfigurationFolder(AppClientProjectProperties.J2EE_1_4)); 100 assertFalse("5.0 does not need configuration folder", 101 AppClientProvider.needConfigurationFolder(AppClientProjectProperties.JAVA_EE_5)); 102 assertFalse("Anything else does not need configuration folder", 103 AppClientProvider.needConfigurationFolder("5.0")); 104 assertFalse("Anything else does not need configuration folder", 105 AppClientProvider.needConfigurationFolder("6.0.hmmm?")); 106 assertFalse("Even null does not need configuration folder", 107 AppClientProvider.needConfigurationFolder(null)); 108 } 109 110 } 111 | Popular Tags |