Modified ProjectTestEnvironment.createProject to take a boolean flag that determines how it behaves if the project to be created already exists.
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/appconfig/provider/TestJARFileJSFAppConfigProvider.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/appconfig/provider/TestJARFileJSFAppConfigProvider.java
index 0d0d39a..8ae9b12 100644
--- a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/appconfig/provider/TestJARFileJSFAppConfigProvider.java
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/appconfig/provider/TestJARFileJSFAppConfigProvider.java
@@ -49,7 +49,7 @@
(true, "www-proxy.us.oracle.com", "80");
_testEnv = new WebProjectTestEnvironment("ELValidationTest_"+this.getClass().getName()+"_"+getName());
- _testEnv.createProject();
+ _testEnv.createProject(false);
assertNotNull(_testEnv);
assertNotNull(_testEnv.getTestProject());
assertTrue(_testEnv.getTestProject().isAccessible());
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/sanity/TestJSFFacetedTestEnvironment.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/sanity/TestJSFFacetedTestEnvironment.java
index b3edd44..879b37f 100644
--- a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/sanity/TestJSFFacetedTestEnvironment.java
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/sanity/TestJSFFacetedTestEnvironment.java
@@ -22,7 +22,7 @@
public void testVersion_1_1_Facet() throws Exception
{
WebProjectTestEnvironment webTestEnv = new WebProjectTestEnvironment(getName());
- webTestEnv.createProject();
+ webTestEnv.createProject(false);
JSFFacetedTestEnvironment testEnv = new JSFFacetedTestEnvironment(webTestEnv);
testEnv.initialize(IJSFCoreConstants.FACET_VERSION_1_1);
@@ -35,7 +35,7 @@
public void testVersion_1_2_Facet() throws Exception
{
WebProjectTestEnvironment webTestEnv = new WebProjectTestEnvironment(getName());
- webTestEnv.createProject();
+ webTestEnv.createProject(false);
JSFFacetedTestEnvironment testEnv = new JSFFacetedTestEnvironment(webTestEnv);
testEnv.initialize(IJSFCoreConstants.FACET_VERSION_1_2);
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/BaseTagMatcherTestCase.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/BaseTagMatcherTestCase.java
index 410d2d3..076b7bd 100644
--- a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/BaseTagMatcherTestCase.java
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/BaseTagMatcherTestCase.java
@@ -54,7 +54,7 @@
JSFTestUtil.setInternetProxyPreferences(true, "www-proxy.uk.oracle.com", "80");
_testEnv = new WebProjectTestEnvironment("ELValidationTest_"+this.getClass().getName()+"_"+getName());
- _testEnv.createProject();
+ _testEnv.createProject(false);
assertNotNull(_testEnv);
assertNotNull(_testEnv.getTestProject());
assertTrue(_testEnv.getTestProject().isAccessible());
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJDTBeanIntrospector.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJDTBeanIntrospector.java
index c8473c4..722f408 100644
--- a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJDTBeanIntrospector.java
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJDTBeanIntrospector.java
@@ -56,7 +56,7 @@
final WebProjectTestEnvironment projectTestEnvironment =
new WebProjectTestEnvironment("TestJDTBeanIntrospectorProject");
- projectTestEnvironment.createProject();
+ projectTestEnvironment.createProject(true);
_jdtTestEnvironment = new JDTTestEnvironment(projectTestEnvironment);
TestFileResource codeRes = new TestFileResource();
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJDTBeanPropertyWorkingCopy.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJDTBeanPropertyWorkingCopy.java
index 740f9b5..32530a7 100644
--- a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJDTBeanPropertyWorkingCopy.java
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJDTBeanPropertyWorkingCopy.java
@@ -46,7 +46,7 @@
final WebProjectTestEnvironment projectTestEnvironment =
new WebProjectTestEnvironment("TestJDTBeanPropertyWorkingCopyProject");
- projectTestEnvironment.createProject();
+ projectTestEnvironment.createProject(true);
_jdtTestEnvironment = new JDTTestEnvironment(projectTestEnvironment);
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJSFAppConfigUtils.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJSFAppConfigUtils.java
index cf6f908..b488db4 100644
--- a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJSFAppConfigUtils.java
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/util/TestJSFAppConfigUtils.java
@@ -55,7 +55,7 @@
{
WebProjectTestEnvironment testEnv =
new WebProjectTestEnvironment(this.getClass().getName()+"_"+name);
- testEnv.createProject();
+ testEnv.createProject(true);
assertNotNull(testEnv);
assertNotNull(testEnv.getTestProject());
assertTrue(testEnv.getTestProject().isAccessible());
diff --git a/jsf/tests/org.eclipse.jst.jsf.metadata.tests/src/org/eclipse/jst/jsf/common/metadata/tests/AbstractBaseMetaDataTestCase.java b/jsf/tests/org.eclipse.jst.jsf.metadata.tests/src/org/eclipse/jst/jsf/common/metadata/tests/AbstractBaseMetaDataTestCase.java
index e97a5c4..c29a4af 100644
--- a/jsf/tests/org.eclipse.jst.jsf.metadata.tests/src/org/eclipse/jst/jsf/common/metadata/tests/AbstractBaseMetaDataTestCase.java
+++ b/jsf/tests/org.eclipse.jst.jsf.metadata.tests/src/org/eclipse/jst/jsf/common/metadata/tests/AbstractBaseMetaDataTestCase.java
@@ -39,8 +39,8 @@
JSFTestUtil.setInternetProxyPreferences(true, "www-proxy.us.oracle.com", "80");
projectTestEnvironment =
- new WebProjectTestEnvironment(projName);
- projectTestEnvironment.createProject();
+ new WebProjectTestEnvironment(projName/*+"_"+getClass().getName()+"_"+getName()*/);
+ projectTestEnvironment.createProject(true);
project = projectTestEnvironment.getTestProject();
@@ -53,8 +53,17 @@
docContext = getDocContext(path, offset);
}
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+// projectTestEnvironment.getTestProject().close(null);
+// projectTestEnvironment.getTestProject().delete(true, null);
+ }
- private IStructuredDocumentContext getDocContext(String path, int offset) throws Exception{
+
+
+ private IStructuredDocumentContext getDocContext(String path, int offset) throws Exception{
IFile jspFile = project.getFile(new Path(path));
assertTrue(jspFile.exists());
diff --git a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/ProjectTestEnvironment.java b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/ProjectTestEnvironment.java
index 47aac9c..9e2b66c 100644
--- a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/ProjectTestEnvironment.java
+++ b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/ProjectTestEnvironment.java
@@ -57,16 +57,25 @@
}
/**
- * Construct the basic web project
+ * @param ignoreProjectExists -- only has impact if _projectName already
+ * exists in the workspace. In this case, if set to true, then createProject
+ * will return without error if the project exists (it will be deleted and recreated)
+ *
+ * If set to false and the project exists, a runtime exception will be thrown
*/
- public void createProject()
+ public void createProject(boolean ignoreProjectExists)
{
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(_projectName);
+
+ if (project.isAccessible() && !ignoreProjectExists)
+ {
+ throw new RuntimeException("Project was not expected to exist but does: "+project.getName());
+ }
+
if(!isProjectCreated())
{
// first delete the projects of these names, if present
deleteProject();
-
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(_projectName);
if (!project.exists())
{
@@ -122,7 +131,7 @@
*/
public void recreateProject() {
setProjectDirtied();
- createProject();
+ createProject(true);
}
/**
diff --git a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/WebProjectTestEnvironment.java b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/WebProjectTestEnvironment.java
index b3b23ec..c0dd847 100644
--- a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/WebProjectTestEnvironment.java
+++ b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/WebProjectTestEnvironment.java
@@ -68,16 +68,103 @@
_webFacetVersion = webVersion;
}
- public void createProject()
+ /**
+ * NOTE: behaviour override compared to super. This method doesn't
+ * delete existing
+ *
+ * Create the web project. If this method completes successfully
+ * without throwing RuntimeExceptions, this test environment will
+ * point to an IProject with Java and Web facets set as configured
+ * in the constructor.
+ *
+ * NOTE: create behaviour is significantly altered by the ignoreExisting
+ * flag
+ *
+ * @param ignoreProjectExists -- only has impact if _projectName already
+ * exists in the workspace. In this case, if set to true, then createProject
+ * will return without error if the project exists and is properly facted, but
+ * throw a RuntimeException if faceting doesn't match what is expected.
+ *
+ * If set to false and the project exists, a runtime exception will be thrown
+ *
+ */
+ @Override
+ public void createProject(boolean ignoreProjectExists)
{
+ boolean doCreate = true;
+
try
{
- _project = createWebProject(_projectName);
+ _project = ResourcesPlugin.getWorkspace().getRoot().getProject(_projectName);
+
+ if (_project.isAccessible())
+ {
+ if (ignoreProjectExists)
+ {
+ if (hasFacets(_project))
+ {
+ doCreate = false;
+ }
+ }
+ else
+ {
+ throw new RuntimeException("Project was not expected to exist but does: "+_project.getName());
+ }
+ }
+
+ if (doCreate)
+ {
+ _project = createWebProject(_projectName);
+ }
_projectCreated = true;
} catch (Exception t) {
throw new RuntimeException(t);
}
}
+
+ private boolean hasFacets(IProject project) throws CoreException
+ {
+ boolean javaInstalled = false;
+ boolean webInstalled = false;
+
+ IFacetedProject facetedProject = ProjectFacetsManager.create(project);
+
+ IProjectFacetVersion version =
+ facetedProject.getInstalledVersion(_javaFacetVersion.getProjectFacet());
+
+ if (version != null)
+ {
+ if (version.compareTo(_javaFacetVersion) == 0)
+ {
+ javaInstalled = true;
+ }
+ else
+ {
+ throw new RuntimeException("Wrong Java version already installed. Has: "+version.getVersionString()+" but was expecting: "+_javaFacetVersion.getVersionString());
+ }
+ }
+
+ version = facetedProject.getInstalledVersion(_webFacetVersion.getProjectFacet());
+
+ if (version != null)
+ {
+ if (version.compareTo(_webFacetVersion) == 0)
+ {
+ webInstalled = true;
+ }
+ else
+ {
+ throw new RuntimeException("Wrong web version already installed. Has: "+version.getVersionString()+" but was expecting: "+_javaFacetVersion.getVersionString());
+ }
+ }
+
+ if (javaInstalled && webInstalled)
+ {
+ return true;
+ }
+
+ return false;
+ }
/**
* @param projectName
diff --git a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestJDTTestEnvironment.java b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestJDTTestEnvironment.java
index 09abf71..431903d 100644
--- a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestJDTTestEnvironment.java
+++ b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestJDTTestEnvironment.java
@@ -34,7 +34,7 @@
protected void setUp() throws Exception {
super.setUp();
_projectTestEnvironment = new ProjectTestEnvironment("JDTTestProject");
- _projectTestEnvironment.createProject();
+ _projectTestEnvironment.createProject(false);
_jdtTestEnv = new JDTTestEnvironment(_projectTestEnvironment);
TestFileResource codeRes = new TestFileResource();
codeRes.load(Activator.getDefault().getBundle(), "/testdata/TestClass1.java.data");
diff --git a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestProjectTestEnvironment.java b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestProjectTestEnvironment.java
index 6fcae24..1e9edf7 100644
--- a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestProjectTestEnvironment.java
+++ b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestProjectTestEnvironment.java
@@ -30,7 +30,7 @@
public void testCreateProject()
{
ProjectTestEnvironment testEnv = new ProjectTestEnvironment("TestProject1");
- testEnv.createProject();
+ testEnv.createProject(false);
assertTrue(testEnv.isProjectCreated());
IProject project = testEnv.getTestProject();
diff --git a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestWebProjectTestEnvironment.java b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestWebProjectTestEnvironment.java
index a4e19e7..7068e30 100644
--- a/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestWebProjectTestEnvironment.java
+++ b/jsf/tests/org.eclipse.jst.jsf.test.util/src/org/eclipse/jst/jsf/test/util/sanity/TestWebProjectTestEnvironment.java
@@ -34,7 +34,7 @@
// IPreferenceStore store = iPlugin.getPreferenceStore();
WebProjectTestEnvironment testEnv = new WebProjectTestEnvironment("TestProject1");
- testEnv.createProject();
+ testEnv.createProject(false);
assertTrue(testEnv.isProjectCreated());
IProject project = testEnv.getTestProject();
@@ -49,7 +49,7 @@
public void testAddFileToWebRoot()
{
WebProjectTestEnvironment testEnv = new WebProjectTestEnvironment("TestProject2");
- testEnv.createProject();
+ testEnv.createProject(false);
assertTrue(testEnv.isProjectCreated());
try
diff --git a/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/base/BaseTestCase.java b/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/base/BaseTestCase.java
index 4b92903..072f026 100644
--- a/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/base/BaseTestCase.java
+++ b/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/base/BaseTestCase.java
@@ -103,7 +103,7 @@
}
_testEnv = new WebProjectTestEnvironment("ELValidationTest_"+this.getClass().getName()+"_"+getName()+"_"+_configuration.getJsfVersion());
- _testEnv.createProject();
+ _testEnv.createProject(false);
assertNotNull(_testEnv);
assertNotNull(_testEnv.getTestProject());
assertTrue(_testEnv.getTestProject().isAccessible());
diff --git a/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/util/CreateTestCaseForJSP.java b/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/util/CreateTestCaseForJSP.java
index 11f7e68..cc50c7d 100644
--- a/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/util/CreateTestCaseForJSP.java
+++ b/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/util/CreateTestCaseForJSP.java
@@ -34,7 +34,7 @@
super.setUp();
_testEnv = new WebProjectTestEnvironment("ELValidationTest_"+getName());
- _testEnv.createProject();
+ _testEnv.createProject(false);
assertNotNull(_testEnv);
assertNotNull(_testEnv.getTestProject());
assertTrue(_testEnv.getTestProject().isAccessible());
diff --git a/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/util/FindELRegions.java b/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/util/FindELRegions.java
index cb8f045..8b71237 100644
--- a/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/util/FindELRegions.java
+++ b/jsf/tests/org.eclipse.jst.jsf.validation.el.tests/src/org/eclipse/jst/jsf/validation/el/tests/util/FindELRegions.java
@@ -66,7 +66,7 @@
super.setUp();
_testEnv = new WebProjectTestEnvironment("ELValidationTest_"+getName());
- _testEnv.createProject();
+ _testEnv.createProject(false);
assertNotNull(_testEnv);
assertNotNull(_testEnv.getTestProject());
assertTrue(_testEnv.getTestProject().isAccessible());