1 19 20 package org.netbeans.modules.j2ee.earproject; 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.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 37 public class BrokenProjectSupportTest extends NbTestCase { 38 39 private static final String CAR_REFERENCE_EXPECTED_KEY = "reference.testEA-app-client.j2ee-module-car"; 40 private static final String CAR_REFERENCE_EXPECTED_VALUE = "${project.testEA-app-client}/dist/testEA-app-client.jar"; 41 42 private String serverID; 43 private EarProject earProject; 44 private BrokenProjectSupport bps; 45 46 public BrokenProjectSupportTest(String testName) { 47 super(testName); 48 } 49 50 protected void setUp() throws Exception { 51 super.setUp(); 52 TestUtil.makeScratchDir(this); 53 serverID = TestUtil.registerSunAppServer(this); 54 55 File prjDirF = new File (getWorkDir(), "testEA"); 57 String name = "Test EnterpriseApplication"; 58 String j2eeLevel = J2eeModule.JAVA_EE_5; 59 String 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 carReferenceValue = ep.getProperty(CAR_REFERENCE_EXPECTED_KEY); 67 assertEquals("right initial car reference", CAR_REFERENCE_EXPECTED_VALUE, carReferenceValue); 68 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 { 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 |