KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
24 import org.netbeans.api.project.Project;
25 import org.netbeans.api.project.ProjectManager;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.modules.j2ee.clientproject.AppClientProject.ProjectOpenedHookImpl;
28 import org.netbeans.modules.j2ee.clientproject.api.AppClientProjectGenerator;
29 import org.netbeans.modules.j2ee.clientproject.test.TestUtil;
30 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
31 import org.netbeans.spi.project.ui.ProjectOpenedHook;
32 import org.openide.filesystems.FileObject;
33 import org.openide.filesystems.FileUtil;
34 import org.xml.sax.SAXException JavaDoc;
35
36 /**
37  * @author Martin Krauskopf
38  */

39 public class AppClientProjectTest extends NbTestCase {
40     
41     private String JavaDoc serverID;
42     
43     public AppClientProjectTest(String JavaDoc testName) {
44         super(testName);
45     }
46     
47     protected void setUp() throws Exception JavaDoc {
48         super.setUp();
49         TestUtil.makeScratchDir(this);
50         serverID = TestUtil.registerSunAppServer(this);
51     }
52     
53     public void testBrokenAppClientOpening_73710() throws Exception JavaDoc {
54         doTestBrokenAppClientOpening_73710(generateApplicationClient(
55                 "TestCreateACProject_14", J2eeModule.J2EE_14));
56         doTestBrokenAppClientOpening_73710(generateApplicationClient(
57                 "TestCreateACProject_15", J2eeModule.JAVA_EE_5));
58     }
59     
60     private void doTestBrokenAppClientOpening_73710(final File JavaDoc prjDirF) throws IOException JavaDoc, IllegalArgumentException JavaDoc {
61         File JavaDoc dirCopy = TestUtil.copyFolder(getWorkDir(), prjDirF);
62         File JavaDoc ddF = new File JavaDoc(dirCopy, "src/conf/application-client.xml");
63         assertTrue("has deployment descriptor", ddF.isFile());
64         ddF.delete(); // one of #73710 scenario
65
FileObject fo = FileUtil.toFileObject(dirCopy);
66         Project project = ProjectManager.getDefault().findProject(fo);
67         assertNotNull("project is found", project);
68         // tests #73710
69
AppClientProjectTest.openProject((AppClientProject) project);
70     }
71     
72     private File JavaDoc generateApplicationClient(String JavaDoc prjDir, String JavaDoc version) throws IOException JavaDoc, SAXException JavaDoc {
73         File JavaDoc prjDirF = new File JavaDoc(getWorkDir(), prjDir);
74         AppClientProjectGenerator.createProject(prjDirF, "test-project",
75                 "test.MyMain", version, serverID);
76         return prjDirF;
77     }
78     
79     /**
80      * Accessor method for those who wish to simulate open of a project and in
81      * case of suite for example generate the build.xml.
82      */

83     public static void openProject(final Project p) {
84         ProjectOpenedHookImpl hook = (ProjectOpenedHookImpl) p.getLookup().lookup(ProjectOpenedHook.class);
85         assertNotNull("has an OpenedHook", hook);
86         hook.projectOpened(); // protected but can use package-private access
87
}
88     
89 }
90
Popular Tags