KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > customizer > EarProjectPropertiesTest


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.earproject.ui.customizer;
21
22 import java.io.File JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.api.project.ProjectManager;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.modules.j2ee.dd.api.application.Application;
29 import org.netbeans.modules.j2ee.dd.api.application.DDProvider;
30 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
31 import org.netbeans.modules.j2ee.earproject.EarProject;
32 import org.netbeans.modules.j2ee.earproject.EarProjectGenerator;
33 import org.netbeans.modules.j2ee.earproject.EarProjectTest;
34 import org.netbeans.modules.j2ee.earproject.EarProjectType;
35 import org.netbeans.modules.j2ee.earproject.test.TestUtil;
36 import org.netbeans.modules.j2ee.earproject.ui.wizards.NewEarProjectWizardIteratorTest;
37 import org.netbeans.spi.project.AuxiliaryConfiguration;
38 import org.netbeans.spi.project.support.ant.AntProjectHelper;
39 import org.netbeans.spi.project.support.ant.ReferenceHelper;
40 import org.openide.filesystems.FileObject;
41 import org.openide.filesystems.FileUtil;
42
43 /**
44  * @author Martin Krauskopf
45  */

46 public class EarProjectPropertiesTest extends NbTestCase {
47     
48     private String JavaDoc serverID;
49     
50     public EarProjectPropertiesTest(String JavaDoc testName) {
51         super(testName);
52     }
53     
54     protected void setUp() throws Exception JavaDoc {
55         super.setUp();
56         TestUtil.makeScratchDir(this);
57         serverID = TestUtil.registerSunAppServer(this);
58     }
59     
60     public void testPropertiesWithoutDD() throws Exception JavaDoc { // see #73751
61
File JavaDoc proj = new File JavaDoc(getWorkDir(), "EARProject");
62         AntProjectHelper aph = EarProjectGenerator.createProject(proj,
63                 "test-project", J2eeModule.JAVA_EE_5, serverID, "1.5");
64         FileObject prjDirFO = aph.getProjectDirectory();
65         // simulateing #73751
66
prjDirFO.getFileObject("src/conf/application.xml").delete();
67         Project p = ProjectManager.getDefault().findProject(prjDirFO);
68         AuxiliaryConfiguration aux = aph.createAuxiliaryConfiguration();
69         ReferenceHelper refHelper = new ReferenceHelper(aph, aux, aph.getStandardPropertyEvaluator());
70         EarProjectProperties epp = new EarProjectProperties((EarProject) p, refHelper, new EarProjectType());
71         assertNotNull("non-null application modules", epp.getApplicationModules());
72     }
73     
74     public void testPathInEARChanging() throws Exception JavaDoc { // see #76008
75
File JavaDoc earDirF = new File JavaDoc(getWorkDir(), "testEA");
76         String JavaDoc name = "Test EnterpriseApplication";
77         String JavaDoc j2eeLevel = J2eeModule.JAVA_EE_5;
78         String JavaDoc ejbName = "testEA-ejb";
79         NewEarProjectWizardIteratorTest.generateEARProject(earDirF, name, j2eeLevel,
80                 serverID, null, ejbName, null, null, null, null);
81         EarProject earProject = (EarProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(earDirF));
82         Application app = DDProvider.getDefault().getDDRoot(
83                 earProject.getAppModule().getDeploymentDescriptor());
84         assertEquals("ejb path", "testEA-ejb.jar", app.getModule(0).getEjb());
85         
86         // simulate change through customizer
87
EarProjectProperties epp = earProject.getProjectProperties();
88         List JavaDoc<VisualClassPathItem> vcpis = epp.getJarContentAdditional();
89         vcpis.get(0).setPathInEAR("otherPath");
90         epp.updateContentDependency(
91                 new HashSet JavaDoc<VisualClassPathItem>(vcpis),
92                 new HashSet JavaDoc<VisualClassPathItem>(vcpis));
93         
94         assertEquals("ejb path", "otherPath/testEA-ejb.jar", app.getModule(0).getEjb());
95     }
96     
97     public void testSetACPrivateProperties() throws Exception JavaDoc { // #81964
98
File JavaDoc earDirF = new File JavaDoc(getWorkDir(), "testEA");
99         String JavaDoc name = "Test EnterpriseApplication";
100         String JavaDoc j2eeLevel = J2eeModule.JAVA_EE_5;
101         String JavaDoc acName = "testEA-ac";
102         NewEarProjectWizardIteratorTest.generateEARProject(earDirF, name, j2eeLevel,
103                 serverID, null, null, acName, null, null, null);
104         EarProject earProject = (EarProject) ProjectManager.getDefault().findProject(FileUtil.toFileObject(earDirF));
105         earProject.getProjectDirectory().getFileObject(AntProjectHelper.PRIVATE_PROPERTIES_PATH).delete();
106         EarProjectTest.openProject(earProject);
107         assertNotNull("private properties successfully regenerated", earProject.getAntProjectHelper().getProperties(
108                 AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(EarProjectProperties.APPCLIENT_WA_COPY_CLIENT_JAR_FROM));
109     }
110 }
111
Popular Tags