KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > AppClientProviderTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.clientproject;
21
22 import java.io.File JavaDoc;
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 /**
35  * @author Andrei Badea
36  */

37 public class AppClientProviderTest extends NbTestCase {
38     
39     private static final String JavaDoc APPLICATION_CLIENT_XML = "application-client.xml";
40     
41     public AppClientProviderTest(String JavaDoc testName) {
42         super(testName);
43     }
44     
45     protected void setUp() throws Exception JavaDoc {
46         super.setUp();
47         TestUtil.makeScratchDir(this);
48     }
49     
50     /**
51      * Tests that the deployment descriptor and beans are returned correctly.
52      */

53     public void testPathsAreReturned() throws Exception JavaDoc {
54         File JavaDoc f = new File JavaDoc(getDataDir().getAbsolutePath(), "projects/ApplicationClient1");
55         Project project = ProjectManager.getDefault().findProject(FileUtil.toFileObject(f));
56         // XXX should not cast a Project
57
AntProjectHelper helper = ((AppClientProject) project).getAntProjectHelper();
58         
59         // first ensure meta.inf exists
60
String JavaDoc metaInf = helper.getStandardPropertyEvaluator().getProperty("meta.inf");
61         assertTrue(metaInf.endsWith("conf"));
62         FileObject metaInfFO =helper.resolveFileObject(metaInf);
63         assertNotNull(metaInfFO);
64         
65         // ensuer application-client.xml exists
66
FileObject appXmlFO = metaInfFO.getFileObject(APPLICATION_CLIENT_XML);
67         assertNotNull(appXmlFO);
68         
69         // ensure deployment descriptor file is returned
70
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 JavaDoc {
80         File JavaDoc prjDirOrigF = new File JavaDoc(getDataDir().getAbsolutePath(), "projects/ApplicationClient1");
81         File JavaDoc prjDirF = TestUtil.copyFolder(getWorkDir(), prjDirOrigF);
82         TestUtil.deleteRec(new File JavaDoc(new File JavaDoc(prjDirF, "src"), "conf"));
83         
84         Project project = ProjectManager.getDefault().findProject(FileUtil.toFileObject(prjDirF));
85         
86         // ensure deployment descriptor file is returned
87
J2eeModuleProvider provider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class);
88         File JavaDoc someConfFile = provider.getDeploymentConfigurationFile("does-not-matter.xml");
89         assertNotNull("J2eeModuleProvider.getDeploymentConfigurationFile() cannot return null", someConfFile);
90         File JavaDoc expected = new File JavaDoc(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