KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > BrokenProjectSupportTest


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;
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.deployment.devmodules.api.J2eeModule;
27 import org.netbeans.modules.j2ee.earproject.test.TestUtil;
28 import org.netbeans.modules.j2ee.earproject.ui.wizards.NewEarProjectWizardIteratorTest;
29 import org.netbeans.spi.project.support.ant.AntProjectHelper;
30 import org.netbeans.spi.project.support.ant.EditableProperties;
31 import org.openide.filesystems.FileObject;
32 import org.openide.filesystems.FileUtil;
33
34 /**
35  * @author Martin Krauskopf
36  */

37 public class BrokenProjectSupportTest extends NbTestCase {
38     
39     private static final String JavaDoc CAR_REFERENCE_EXPECTED_KEY = "reference.testEA-app-client.j2ee-module-car";
40     private static final String JavaDoc CAR_REFERENCE_EXPECTED_VALUE = "${project.testEA-app-client}/dist/testEA-app-client.jar";
41     
42     private String JavaDoc serverID;
43     private EarProject earProject;
44     private BrokenProjectSupport bps;
45     
46     public BrokenProjectSupportTest(String JavaDoc testName) {
47         super(testName);
48     }
49     
50     protected void setUp() throws Exception JavaDoc {
51         super.setUp();
52         TestUtil.makeScratchDir(this);
53         serverID = TestUtil.registerSunAppServer(this);
54         
55         // testing project
56
File JavaDoc prjDirF = new File JavaDoc(getWorkDir(), "testEA");
57         String JavaDoc name = "Test EnterpriseApplication";
58         String JavaDoc j2eeLevel = J2eeModule.JAVA_EE_5;
59         String JavaDoc carName = "testEA-app-client";
60         
61         NewEarProjectWizardIteratorTest.generateEARProject(prjDirF, name, j2eeLevel,
62                 serverID, null, null, carName, null, null, null);
63         FileObject prjDirFO = FileUtil.toFileObject(prjDirF);
64         
65         EditableProperties ep = TestUtil.loadProjectProperties(prjDirFO);
66         String JavaDoc carReferenceValue = ep.getProperty(CAR_REFERENCE_EXPECTED_KEY);
67         assertEquals("right initial car reference", CAR_REFERENCE_EXPECTED_VALUE, carReferenceValue);
68         // broke the project
69
ep.setProperty(CAR_REFERENCE_EXPECTED_KEY, CAR_REFERENCE_EXPECTED_VALUE + "-broken");
70         carReferenceValue = ep.getProperty(CAR_REFERENCE_EXPECTED_KEY);
71         assertFalse("broken car reference", CAR_REFERENCE_EXPECTED_VALUE.equals(carReferenceValue));
72         TestUtil.storeProjectProperties(prjDirFO, ep);
73         
74         Project project = ProjectManager.getDefault().findProject(prjDirFO);
75         this.earProject = (EarProject) project.getLookup().lookup(EarProject.class);
76         assertNotNull("project successfully created", this.earProject);
77         this.bps = (BrokenProjectSupport) this.earProject.getLookup().lookup(BrokenProjectSupport.class);
78         assertNotNull("has BrokenProjectSupport in the lookup", bps);
79     }
80     
81     protected void tearDown() throws Exception JavaDoc {
82         super.tearDown();
83         
84         serverID = null;
85         earProject = null;
86         bps = null;
87     }
88     
89     public void testAdjustReferences() {
90         EditableProperties projectProps = earProject.getAntProjectHelper().
91                 getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
92         assertFalse("reference property is broken",
93                 CAR_REFERENCE_EXPECTED_VALUE.equals(projectProps.getProperty(CAR_REFERENCE_EXPECTED_KEY)));
94         bps.adjustReferences();
95         EditableProperties fixedProjectProps = earProject.getAntProjectHelper().
96                 getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
97         assertEquals("reference property was fixed", CAR_REFERENCE_EXPECTED_VALUE,
98                 fixedProjectProps.getProperty(CAR_REFERENCE_EXPECTED_KEY));
99     }
100 }
101
Popular Tags