Merge commit
diff --git a/.gitignore b/.gitignore
index 60d351c..87dd2ae 100755
--- a/.gitignore
+++ b/.gitignore
@@ -32,8 +32,12 @@
javaCompiler...args
<<<<<<< HEAD
+<<<<<<< HEAD
# maven
=======
# maven
>>>>>>> 5f48a07d3516fa5c4baca8276da4de29170c0ab3
+=======
+# maven
+>>>>>>> 996353e9042b00642903ca56071dd13d1d7a3c09
target/
\ No newline at end of file
diff --git a/features/org.eclipse.wst.common_tests.feature/.cvsignore b/features/org.eclipse.wst.common_tests.feature/.cvsignore
new file mode 100644
index 0000000..e304b65
--- /dev/null
+++ b/features/org.eclipse.wst.common_tests.feature/.cvsignore
@@ -0,0 +1,3 @@
+build.xml
+org.eclipse.wst.common_tests.feature_1.0.0.bin.dist.zip
+org.eclipse.wst.common_tests.feature_1.0.1.200602150104.bin.dist.zip
diff --git a/features/org.eclipse.wst.common_tests.feature/.project b/features/org.eclipse.wst.common_tests.feature/.project
new file mode 100644
index 0000000..6069a82
--- /dev/null
+++ b/features/org.eclipse.wst.common_tests.feature/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.common_tests.feature</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.pde.FeatureBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.FeatureNature</nature>
+ </natures>
+</projectDescription>
diff --git a/features/org.eclipse.wst.common_tests.feature/build.properties b/features/org.eclipse.wst.common_tests.feature/build.properties
new file mode 100644
index 0000000..7c626e2
--- /dev/null
+++ b/features/org.eclipse.wst.common_tests.feature/build.properties
@@ -0,0 +1,3 @@
+bin.includes = feature.xml,\
+ eclipse_update_120.jpg,\
+ feature.properties
diff --git a/features/org.eclipse.wst.common_tests.feature/eclipse_update_120.jpg b/features/org.eclipse.wst.common_tests.feature/eclipse_update_120.jpg
new file mode 100644
index 0000000..bfdf708
--- /dev/null
+++ b/features/org.eclipse.wst.common_tests.feature/eclipse_update_120.jpg
Binary files differ
diff --git a/features/org.eclipse.wst.common_tests.feature/feature.properties b/features/org.eclipse.wst.common_tests.feature/feature.properties
new file mode 100644
index 0000000..5dd6e9a
--- /dev/null
+++ b/features/org.eclipse.wst.common_tests.feature/feature.properties
@@ -0,0 +1,48 @@
+###############################################################################
+# Copyright (c) 2006 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+# feature.properties
+# contains externalized strings for feature.xml
+# "%foo" in feature.xml corresponds to the key "foo" in this file
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# This file should be translated.
+
+# "featureName" property - name of the feature
+featureName=WST Common Tests
+
+# "providerName" property - name of the company that provides the feature
+providerName=Eclipse Web Tools Platform
+
+
+# "description" property - description of the feature
+description=WST common tests
+
+# "copyright" property - text of the "Feature Update Copyright"
+copyright=\
+Copyright (c) 2006 IBM Corporation and others.\n\
+All rights reserved. This program and the accompanying materials\n\
+are made available under the terms of the Eclipse Public License v1.0\n\
+which accompanies this distribution, and is available at\n\
+http://www.eclipse.org/legal/epl-v10.html\n\
+\n\
+Contributors:\n\
+ IBM Corporation - initial API and implementation\n
+################ end of copyright property ####################################
+
+# "licenseURL" property - URL of the "Feature License"
+# do not translate value - just change to point to a locale-specific HTML page
+# license and licenseURL properties were removed as a result to migrating to new PDE license support.
+# Those properties are now added at build time. See http://wiki.eclipse.org/Equinox/p2/License_Mechanism.
+
+# "license" property - text of the "Feature Update License"
+# should be plain text version of license agreement pointed to be "licenseURL"
+# license and licenseURL properties were removed as a result to migrating to new PDE license support.
+# Those properties are now added at build time. See http://wiki.eclipse.org/Equinox/p2/License_Mechanism.
+########### end of license property ##########################################
diff --git a/features/org.eclipse.wst.common_tests.feature/feature.xml b/features/org.eclipse.wst.common_tests.feature/feature.xml
new file mode 100644
index 0000000..0b398f1
--- /dev/null
+++ b/features/org.eclipse.wst.common_tests.feature/feature.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<feature
+ id="org.eclipse.wst.common_tests.feature"
+ label="%featureName"
+ version="3.6.0.qualifier"
+ provider-name="%providerName"
+ license-feature="org.eclipse.license"
+ license-feature-version="1.0.1.qualifier">
+
+ <description>
+ %description
+ </description>
+
+ <copyright>
+ %copyright
+ </copyright>
+
+ <license url="%licenseURL">
+ %license
+ </license>
+
+ <plugin
+ id="org.eclipse.wst.common.tests"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+ <plugin
+ id="org.eclipse.wst.common.tests.collector"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+ <plugin
+ id="org.eclipse.wst.common.tests.ui"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+ <plugin
+ id="org.eclipse.wst.common.snippets.tests"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+ <plugin
+ id="org.eclipse.wst.internet.cache.tests"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+ <plugin
+ id="org.eclipse.wst.common.project.facet.core.tests"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+ <plugin
+ id="org.eclipse.wst.common.project.facet.ui.tests"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+ <plugin
+ id="org.eclipse.wst.common.tests.validation"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+ <plugin
+ id="org.eclipse.wst.common.tests.validation.guard"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
+ <plugin
+ id="org.eclipse.wst.common.uriresolver.tests"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"/>
+
+</feature>
diff --git a/features/org.eclipse.wst.common_tests.feature/pom.xml b/features/org.eclipse.wst.common_tests.feature/pom.xml
new file mode 100644
index 0000000..a1b723b
--- /dev/null
+++ b/features/org.eclipse.wst.common_tests.feature/pom.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2012, 2013 Eclipse Foundation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Distribution License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/org/documents/edl-v10.php
+
+ Contributors:
+ Thanh Ha (Eclipse Foundation) - initial implementation
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.webtools.common.tests</artifactId>
+ <version>3.6.0-SNAPSHOT</version>
+ <relativePath>../../</relativePath>
+ </parent>
+
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.wst.common_tests.feature</artifactId>
+ <version>3.6.0-SNAPSHOT</version>
+ <packaging>eclipse-feature</packaging>
+</project>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 8a9b42d..bfed550 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,15 +23,20 @@
<groupId>org.eclipse.webtools.common</groupId>
<<<<<<< HEAD
+<<<<<<< HEAD
<artifactId>org.eclipse.webtools.common</artifactId>
=======
<artifactId>org.eclipse.webtools.common.fproj</artifactId>
>>>>>>> 5f48a07d3516fa5c4baca8276da4de29170c0ab3
+=======
+ <artifactId>org.eclipse.webtools.common.tests</artifactId>
+>>>>>>> 996353e9042b00642903ca56071dd13d1d7a3c09
<version>3.6.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<<<<<<< HEAD
+<<<<<<< HEAD
<tycho.scmUrl>scm:git:git://git.eclipse.org/gitroot/webtools-common/webtools.common.git</tycho.scmUrl>
</properties>
@@ -83,3 +88,20 @@
>>>>>>> 5f48a07d3516fa5c4baca8276da4de29170c0ab3
</modules>
</project>
+=======
+ <tycho.scmUrl>scm:git:git://git.eclipse.org/gitroot/webtools-common/webtools.common.tests.git</tycho.scmUrl>
+ </properties>
+
+ <modules>
+ <module>features/org.eclipse.wst.common_tests.feature</module>
+
+ <module>tests/org.eclipse.wst.common.tests</module>
+ <module>tests/org.eclipse.wst.common.tests.collector</module>
+ <module>tests/org.eclipse.wst.common.tests.ui</module>
+ <module>tests/org.eclipse.wst.common.tests.validation</module>
+ <module>tests/org.eclipse.wst.common.tests.validation.guard</module>
+ <module>tests/org.eclipse.wst.common.uriresolver.tests</module>
+ <module>tests/org.eclipse.wst.internet.cache.tests</module>
+ </modules>
+</project>
+>>>>>>> 996353e9042b00642903ca56071dd13d1d7a3c09
diff --git a/tests/org.eclipse.wst.common.tests.collector/.classpath b/tests/org.eclipse.wst.common.tests.collector/.classpath
new file mode 100644
index 0000000..4a382ec
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="collector"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.wst.common.tests.collector/.cvsignore b/tests/org.eclipse.wst.common.tests.collector/.cvsignore
new file mode 100644
index 0000000..4d7b745
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/.cvsignore
@@ -0,0 +1,5 @@
+bin
+build.xml
+runtime
+temp.folder
+javaCompiler.runtime_collector.jar.args
diff --git a/tests/org.eclipse.wst.common.tests.collector/.project b/tests/org.eclipse.wst.common.tests.collector/.project
new file mode 100644
index 0000000..7441769
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.common.tests.collector</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.wst.common.tests.collector/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.wst.common.tests.collector/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..542da41
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Sun Jun 03 02:20:21 EDT 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/tests/org.eclipse.wst.common.tests.collector/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.common.tests.collector/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..f3a87e4
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %org.eclipse.wst.common.tests.collector
+Bundle-SymbolicName: org.eclipse.wst.common.tests.collector; singleton:=true
+Bundle-Version: 1.1.100.qualifier
+Bundle-ClassPath: runtime/collector.jar
+Bundle-Activator: org.eclipse.wst.common.tests.collector.TestCollectorPlugin
+Bundle-Localization: plugin
+Require-Bundle: org.junit,
+ org.eclipse.ui,
+ org.eclipse.core.runtime
+Eclipse-LazyStart: true
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
diff --git a/tests/org.eclipse.wst.common.tests.collector/about.html b/tests/org.eclipse.wst.common.tests.collector/about.html
new file mode 100644
index 0000000..2199df3
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/about.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>June, 2008</P>
+
+<H3>License</H3>
+
+<P>The Eclipse Foundation makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from the Eclipse Foundation, the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributors license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P>
+
+</BODY>
+</HTML>
diff --git a/tests/org.eclipse.wst.common.tests.collector/build.properties b/tests/org.eclipse.wst.common.tests.collector/build.properties
new file mode 100644
index 0000000..e6b007b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/build.properties
@@ -0,0 +1,7 @@
+bin.includes = plugin.xml,\
+ runtime/collector.jar,\
+ about.html,\
+ META-INF/,\
+ plugin.properties
+source.runtime/collector.jar = collector/
+output.runtime/collector.jar = bin/
diff --git a/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/SuiteHelper.java b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/SuiteHelper.java
new file mode 100644
index 0000000..b43f8ec
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/SuiteHelper.java
@@ -0,0 +1,140 @@
+package org.eclipse.wst.common.tests.collector;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author jsholl
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class SuiteHelper {
+
+ private Hashtable allTests = new Hashtable();
+
+ public SuiteHelper(TestSuite suite) {
+ addTest(suite);
+ }
+
+ private void addTest(Test test) {
+ if (test instanceof TestSuite) {
+ Enumeration tests = ((TestSuite) test).tests();
+ while (tests.hasMoreElements()) {
+ Test t = (Test) tests.nextElement();
+ allTests.put(t.toString(), t);
+ }
+ return;
+ }
+ allTests.put(test.toString(), test);
+ }
+
+ public String[] getAllTests() {
+ ArrayList testList = new ArrayList();
+ Enumeration enumeration = allTests.keys();
+ while (enumeration.hasMoreElements()) {
+ testList.add(enumeration.nextElement());
+ }
+ Collections.sort(testList, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return ((String) o1).compareTo(((String) o2));
+ }
+ });
+
+ String[] strArray = new String[testList.size()];
+ for (int i = 0; i < strArray.length; i++) {
+ strArray[i] = (String) testList.get(i);
+ }
+
+ return strArray;
+ }
+
+ public TestSuite buildSuite(String[] completeTests, String[] partialTests) {
+ TestSuite suite = new TestSuite();
+ for (int i = 0; i < completeTests.length; i++) {
+ suite.addTest((Test) allTests.get(completeTests[i]));
+ }
+ for (int i = 0; i < partialTests.length; i++) {
+ suite.addTest(getTest(partialTests[i]));
+ }
+ return suite;
+ }
+
+ public String[] getTestMethods(String testName) {
+ ArrayList methodList = new ArrayList();
+ Test test = (Test) allTests.get(testName);
+ if (test instanceof TestSuite) {
+ Enumeration testsEnum = ((TestSuite) test).tests();
+ while (testsEnum.hasMoreElements()) {
+ Test t = (Test) testsEnum.nextElement();
+ methodList.add(t.toString());
+ }
+ }
+
+ Collections.sort(methodList, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return ((String) o1).compareTo(((String) o2));
+ }
+ });
+
+ String[] strArray = new String[methodList.size()];
+ for (int i = 0; i < strArray.length; i++) {
+ strArray[i] = (String) methodList.get(i);
+ }
+
+ return strArray;
+ }
+
+ private Test getSubTest(TestSuite suite, String testName) {
+ if (null != suite) {
+ Enumeration tests = suite.tests();
+ while (tests.hasMoreElements()) {
+ Test t = (Test) tests.nextElement();
+ if (t.toString().equals(testName)) {
+ return t;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns a TestSuite to run
+ */
+ private Test getTest(String testName) {
+ int firstIndex = testName.indexOf("."); //$NON-NLS-1$
+ String suiteName = testName.substring(0, firstIndex);
+ String subTestName = testName.substring(firstIndex + 1);
+
+ //check the obvious suite first
+ TestSuite suite = (TestSuite) allTests.get(suiteName);
+ Test test = getSubTest(suite, subTestName);
+ if (test != null) {
+ return test;
+ }
+ //otherwise check all suites
+ Enumeration keys = allTests.keys();
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ if (testName.startsWith(key)) {
+ suite = (TestSuite) allTests.get(key);
+ subTestName = testName.substring(key.length() + 1);
+ test = getSubTest(suite, subTestName);
+ if (test != null) {
+ return test;
+ }
+ }
+ }
+
+ return null;
+
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/SuiteTestRunner.java b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/SuiteTestRunner.java
new file mode 100644
index 0000000..4459ce2
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/SuiteTestRunner.java
@@ -0,0 +1,40 @@
+package org.eclipse.wst.common.tests.collector;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * @author jsholl
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class SuiteTestRunner extends TestRunner {
+
+ private TestSuite suite;
+
+ /**
+ * PluginTestRunner constructor comment.
+ */
+ public SuiteTestRunner(TestSuite suiteToRun) {
+ super();
+ suite = suiteToRun;
+ }
+
+ /**
+ * Only return the specified suite
+ */
+ public Test getTest(String suiteClassName) {
+ return suite;
+ }
+
+ /**
+ * called by the gui
+ */
+ public void launch() {
+ doRun(suite);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorActionDelegate.java b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorActionDelegate.java
new file mode 100644
index 0000000..2b2bd28
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorActionDelegate.java
@@ -0,0 +1,57 @@
+package org.eclipse.wst.common.tests.collector;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+
+/**
+ * @author jsholl
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class TestCollectorActionDelegate implements IWorkbenchWindowActionDelegate {
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
+ */
+ public void dispose() {
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
+ */
+ public void init(IWorkbenchWindow window) {
+ }
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ Shell shell = new Shell();
+ GridLayout gridLayout = new GridLayout();
+ shell.setLayout(gridLayout);
+ shell.setText("Test Collector"); //$NON-NLS-1$
+ TestCollectorGUI testCollectorGUI = new TestCollectorGUI(shell, SWT.NULL);
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 1;
+ testCollectorGUI.setLayoutData(gridData);
+
+ shell.setSize(500, 500);
+ shell.open();
+ }
+
+
+ /**
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorGUI.java b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorGUI.java
new file mode 100644
index 0000000..606252f
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorGUI.java
@@ -0,0 +1,141 @@
+/*
+ * Created on Mar 6, 2003
+ *
+ * To change this generated comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.eclipse.wst.common.tests.collector;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+/**
+ * @author jsholl
+ *
+ * To change this generated comment go to Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TestCollectorGUI extends Composite implements ModifyListener {
+
+ private static final String PLUGIN_ID = "org.eclipse.wst.common.tests.collector"; //$NON-NLS-1$
+ private static final String SUITES_EXT_PT = "suites"; //$NON-NLS-1$
+// private static final String NAME = "name"; //$NON-NLS-1$
+// private static final String CLASS = "class"; //$NON-NLS-1$
+
+ private Composite innerPanes = null;
+ private Combo combo = null;
+
+ private Hashtable testSuites = new Hashtable();
+
+ /**
+ * @param parent
+ * @param style
+ */
+ public TestCollectorGUI(Composite parent, int style) {
+ super(parent, style);
+
+ loadConfiguration();
+
+ createPartControl();
+ }
+
+ private void loadConfiguration() {
+ IExtensionPoint suiteExtPt = Platform.getExtensionRegistry().getExtensionPoint(PLUGIN_ID, SUITES_EXT_PT);
+ IExtension[] suitesExtensions = suiteExtPt.getExtensions();
+
+ for (int i = 0; i < suitesExtensions.length; i++) {
+ IExtension extension = suitesExtensions[i];
+ IConfigurationElement[] tests = extension.getConfigurationElements();
+ for (int j = 0; j < tests.length; j++) {
+ try {
+ IConfigurationElement element = tests[j];
+ String suiteName = element.getAttribute("name"); //$NON-NLS-1$
+ testSuites.put(suiteName, element);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public void createPartControl() {
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 1;
+ setLayout(gridLayout);
+
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = 1;
+
+ combo = new Combo(this, SWT.READ_ONLY);
+ Enumeration keys = testSuites.keys();
+ ArrayList arrayList = new ArrayList();
+ while (keys.hasMoreElements()) {
+ arrayList.add(keys.nextElement());
+ }
+
+ Collections.sort(arrayList, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return ((String) o1).compareTo(((String) o2));
+ }
+ });
+
+ for (int i = 0; i < arrayList.size(); i++) {
+ combo.add((String) arrayList.get(i));
+ }
+ combo.setLayoutData(gridData);
+ combo.addModifyListener(this);
+ if (combo.getItemCount() > 0) {
+ combo.select(0);
+ }
+ }
+
+ public void modifyText(ModifyEvent e) {
+ if (e.getSource() == combo) {
+ updateCombo(e);
+ }
+ }
+
+ private void updateCombo(ModifyEvent e) {
+ if (null != innerPanes) {
+ innerPanes.dispose();
+ }
+ try {
+ String testName = combo.getText();
+ IConfigurationElement element = (IConfigurationElement) testSuites.get(testName);
+ TestSuite suite = (TestSuite) element.createExecutableExtension("class"); //$NON-NLS-1$
+ innerPanes = new TestCollectorInnerPanes(this, SWT.NULL, new SuiteHelper(suite));
+ } catch (Exception ex) {
+ innerPanes = new Composite(this, SWT.NULL);
+ innerPanes.setLayout(new GridLayout());
+ innerPanes.setBackground(getBackground());
+ Label errorLabel = new Label(innerPanes, SWT.NONE);
+ errorLabel.setText(ex.getMessage());
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 1;
+ errorLabel.setLayoutData(gridData);
+ }
+ GridData gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 1;
+ innerPanes.setLayoutData(gridData);
+ layout();
+
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorInnerPanes.java b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorInnerPanes.java
new file mode 100644
index 0000000..f62d96b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorInnerPanes.java
@@ -0,0 +1,212 @@
+package org.eclipse.wst.common.tests.collector;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import junit.framework.TestSuite;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+
+/**
+ * @author jsholl
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class TestCollectorInnerPanes extends Composite {
+
+ private Table testClassTable;
+ private Table testMethodTable;
+
+ private Button launchTestButton;
+
+ private SuiteHelper pluginTestLoader;
+
+ private HashSet partialSetHash = new HashSet();
+ private Hashtable shortToFullHashtable = new Hashtable();
+ private Hashtable fullToShortHashtable = new Hashtable();
+
+ public TestCollectorInnerPanes(Composite parent, int style, SuiteHelper loader) {
+ super(parent, style);
+ pluginTestLoader = loader;
+ createPartControl();
+ }
+
+ public void createPartControl() {
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 1;
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ setLayout(gridLayout);
+ GridData gridData = null;
+
+ Group tableGroup = new Group(this, SWT.NULL);
+ GridLayout tableGroupLayout = new GridLayout();
+ tableGroupLayout.makeColumnsEqualWidth = true;
+ tableGroupLayout.numColumns = 1;
+ tableGroupLayout.marginWidth = 0;
+ tableGroupLayout.marginHeight = 0;
+ tableGroup.setLayout(tableGroupLayout);
+ tableGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ SashForm splitView = new SashForm(tableGroup, SWT.HORIZONTAL);
+ splitView.setBackground(getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
+
+ gridData = new GridData(GridData.FILL_BOTH);
+ gridData.horizontalSpan = 2;
+ splitView.setLayoutData(gridData);
+
+ Composite leftComposite = new Composite(splitView, SWT.NONE);
+ GridLayout leftLayout = new GridLayout();
+ leftLayout.numColumns = 1;
+ leftComposite.setLayout(leftLayout);
+ Label label2 = new Label(leftComposite, SWT.NULL);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.CENTER;
+ label2.setLayoutData(gridData);
+ label2.setText("Test Suites"); //$NON-NLS-1$
+
+ Composite rightComposite = new Composite(splitView, SWT.NONE);
+ GridLayout rightLayout = new GridLayout();
+ rightLayout.numColumns = 1;
+ rightComposite.setLayout(rightLayout);
+ Label label3 = new Label(rightComposite, SWT.NULL);
+ gridData = new GridData();
+ gridData.horizontalAlignment = GridData.CENTER;
+ label3.setLayoutData(gridData);
+ label3.setText("Tests"); //$NON-NLS-1$
+
+ testClassTable = new Table(leftComposite, SWT.CHECK);
+ testClassTable.setBackground(getBackground());
+ gridData = new GridData(GridData.FILL_BOTH);
+ testClassTable.setLayoutData(gridData);
+ String[] allTests = pluginTestLoader.getAllTests();
+ for (int i = 0; i < allTests.length; i++) {
+ TableItem tableItem = new TableItem(testClassTable, SWT.NULL);
+ tableItem.setText(allTests[i]);
+ }
+ testClassTable.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ TableItem item = (TableItem) e.item;
+ String testName = item.getText();
+ updateMethodTable(testName, pluginTestLoader.getTestMethods(testName));
+ testClassTable.setSelection(new TableItem[] { item });
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ });
+
+ Label label = new Label(leftComposite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ final Button selectAllCheckbox = new Button(leftComposite, SWT.CHECK);
+ selectAllCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ selectAllCheckbox.setText("Select All"); //$NON-NLS-1$
+ selectAllCheckbox.addSelectionListener(new SelectionAdapter(){
+ public void widgetSelected(SelectionEvent e) {
+ boolean checked = selectAllCheckbox.getSelection();
+ TableItem [] items = testClassTable.getItems();
+ for(int i=0;i<items.length; i++){
+ items[i].setChecked(checked);
+ }
+ }
+ });
+
+ testMethodTable = new Table(rightComposite, SWT.CHECK);
+ testMethodTable.setBackground(getBackground());
+ gridData = new GridData(GridData.FILL_BOTH);
+ testMethodTable.setLayoutData(gridData);
+
+ launchTestButton = new Button(this, SWT.PUSH);
+ gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalAlignment = GridData.CENTER;
+ gridData.horizontalSpan = 2;
+ launchTestButton.setLayoutData(gridData);
+ launchTestButton.setText("Run Tests"); //$NON-NLS-1$
+ launchTestButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ SuiteTestRunner runner = new SuiteTestRunner(buildSuite());
+ runner.launch();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ }
+
+ private void storeMethodsTable() {
+ TableItem[] items = testMethodTable.getItems();
+ for (int i = 0; null != items && i < items.length; i++) {
+ String partialTestName = (String)shortToFullHashtable.get(items[i].getText());
+ if (items[i].getChecked() && !partialSetHash.contains(partialTestName)) {
+ partialSetHash.add(partialTestName);
+ } else if (!items[i].getChecked() && partialSetHash.contains(partialTestName)) {
+ partialSetHash.remove(partialTestName);
+ }
+ }
+ }
+
+ private void updateMethodTable(String testName, String[] methodArray) {
+ storeMethodsTable();
+ testMethodTable.removeAll();
+ shortToFullHashtable.clear();
+ fullToShortHashtable.clear();
+
+ for (int i = 0; null != methodArray && i < methodArray.length; i++) {
+ String partialTestName = testName + "." + methodArray[i]; //$NON-NLS-1$
+ int endIndex = methodArray[i].indexOf('(');
+ String methodName = endIndex > 0 ? methodArray[i].substring(0, endIndex) : methodArray[i];
+ shortToFullHashtable.put(methodName, partialTestName);
+ fullToShortHashtable.put(partialTestName, methodName);
+ TableItem tableItem = new TableItem(testMethodTable, SWT.NULL);
+ tableItem.setText(methodName);
+ tableItem.setChecked(partialSetHash.contains(partialTestName));
+ }
+
+ }
+
+ private TestSuite buildSuite() {
+ ArrayList completeTests = new ArrayList();
+ TableItem[] items = testClassTable.getItems();
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].getChecked()) {
+ completeTests.add(items[i].getText());
+ }
+ }
+
+ String[] completeArray = new String[completeTests.size()];
+ for (int i = 0; i < completeArray.length; i++) {
+ completeArray[i] = (String) completeTests.get(i);
+ }
+
+ ArrayList partialTests = new ArrayList();
+ storeMethodsTable();
+ Iterator iterator = partialSetHash.iterator();
+ while (iterator.hasNext()) {
+ partialTests.add(iterator.next());
+ }
+
+ String[] partialArray = new String[partialTests.size()];
+ for (int i = 0; i < partialArray.length; i++) {
+ partialArray[i] = (String) partialTests.get(i);
+ }
+
+ return pluginTestLoader.buildSuite(completeArray, partialArray);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorPlugin.java b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorPlugin.java
new file mode 100644
index 0000000..9780327
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/collector/org/eclipse/wst/common/tests/collector/TestCollectorPlugin.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.collector;
+
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.Plugin;
+
+
+public class TestCollectorPlugin extends Plugin {
+ public static String PLUGIN_ID = "org.eclipse.wst.common.tests.collector";
+ public static TestCollectorPlugin instance = null;
+ public IExtensionPoint dataModelVerifierExt = null;
+
+ /**
+ * @param descriptor
+ */
+ public TestCollectorPlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ instance = this;
+ dataModelVerifierExt = descriptor.getExtensionPoint("DataModelVerifier");
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.collector/plugin.properties b/tests/org.eclipse.wst.common.tests.collector/plugin.properties
new file mode 100644
index 0000000..144de79
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/plugin.properties
@@ -0,0 +1,6 @@
+org.eclipse.wst.common.tests.collector=org.eclipse.wst.common.tests.collector
+suites=suites
+Test_Collector=Test Collector
+WTP_Tests=WTP Tests
+Open=Open
+Test_Collector=Test Collector
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests.collector/plugin.xml b/tests/org.eclipse.wst.common.tests.collector/plugin.xml
new file mode 100644
index 0000000..28986ff
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/plugin.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+ <extension-point id="suites" name="%suites" schema="schema/suites.exsd"/>
+
+
+
+ <extension
+ point="org.eclipse.ui.actionSets">
+ <actionSet
+ label="%Test_Collector"
+ visible="true"
+ id="testCollector">
+ <menu
+ label="%WTP_Tests"
+ path="additions"
+ id="org.eclipse.wst.common.tests.collector.testsMenu">
+ <separator
+ name="group1">
+ </separator>
+ </menu>
+ <action
+ label="%Open"
+ tooltip="%Test_Collector"
+ class="org.eclipse.wst.common.tests.collector.TestCollectorActionDelegate"
+ menubarPath="org.eclipse.wst.common.tests.collector.testsMenu/group1"
+ id="org.eclipse.wst.common.tests.collector.testsAction">
+ </action>
+ </actionSet>
+ </extension>
+
+</plugin>
diff --git a/tests/org.eclipse.wst.common.tests.collector/pom.xml b/tests/org.eclipse.wst.common.tests.collector/pom.xml
new file mode 100644
index 0000000..a5b7632
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/pom.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2012, 2013 Eclipse Foundation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Distribution License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/org/documents/edl-v10.php
+
+ Contributors:
+ Thanh Ha (Eclipse Foundation) - initial implementation
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.webtools.common.tests</artifactId>
+ <version>3.6.0-SNAPSHOT</version>
+ <relativePath>../../</relativePath>
+ </parent>
+
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.wst.common.tests.collector</artifactId>
+ <version>1.1.100-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+</project>
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests.collector/schema/suites.exsd b/tests/org.eclipse.wst.common.tests.collector/schema/suites.exsd
new file mode 100644
index 0000000..dfec3c5
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.collector/schema/suites.exsd
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.wst.common.tests.collector">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.wst.common.tests.collector" id="suites" name="suites"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="suite"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="suite">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/tests/org.eclipse.wst.common.tests.ui/.classpath b/tests/org.eclipse.wst.common.tests.ui/.classpath
new file mode 100644
index 0000000..4a72458
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/.classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/wst/common/**"/>
+ </accessrules>
+ </classpathentry>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.wst.common.tests.ui/.cvsignore b/tests/org.eclipse.wst.common.tests.ui/.cvsignore
new file mode 100644
index 0000000..f2c0c6d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/.cvsignore
@@ -0,0 +1,5 @@
+bin
+temp.folder
+build.xml
+ui.jar
+javaCompiler.ui.jar.args
diff --git a/tests/org.eclipse.wst.common.tests.ui/.project b/tests/org.eclipse.wst.common.tests.ui/.project
new file mode 100644
index 0000000..8efe78d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.common.tests.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.wst.common.tests.ui/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.wst.common.tests.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..9c78d3d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Sun Jun 03 02:20:54 EDT 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/tests/org.eclipse.wst.common.tests.ui/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.common.tests.ui/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..645503d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,19 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Ui_Plug-in
+Bundle-SymbolicName: org.eclipse.wst.common.tests.ui; singleton:=true
+Bundle-Version: 1.1.300.qualifier
+Bundle-ClassPath: ui.jar
+Bundle-Activator: org.eclipse.wst.common.tests.ui.UiPlugin
+Bundle-Vendor: %Eclipse
+Bundle-Localization: plugin
+Export-Package: org.eclipse.wst.common.tests.ui,
+ org.eclipse.wst.common.tests.ui.manager,
+ org.eclipse.wst.common.tests.ui.wizard
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.wst.common.frameworks.ui,
+ org.eclipse.wst.common.tests,
+ org.eclipse.wst.common.environment
+Eclipse-LazyStart: true
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
diff --git a/tests/org.eclipse.wst.common.tests.ui/about.html b/tests/org.eclipse.wst.common.tests.ui/about.html
new file mode 100644
index 0000000..2199df3
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/about.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>June, 2008</P>
+
+<H3>License</H3>
+
+<P>The Eclipse Foundation makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from the Eclipse Foundation, the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributors license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P>
+
+</BODY>
+</HTML>
diff --git a/tests/org.eclipse.wst.common.tests.ui/build.properties b/tests/org.eclipse.wst.common.tests.ui/build.properties
new file mode 100644
index 0000000..cee1739
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/build.properties
@@ -0,0 +1,7 @@
+source.ui.jar = src/
+output.ui.jar = bin/
+bin.includes = plugin.xml,\
+ ui.jar,\
+ about.html,\
+ plugin.properties,\
+ META-INF/
diff --git a/tests/org.eclipse.wst.common.tests.ui/plugin.properties b/tests/org.eclipse.wst.common.tests.ui/plugin.properties
new file mode 100644
index 0000000..43069c8
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/plugin.properties
@@ -0,0 +1,2 @@
+Ui_Plug-in=Test Ui Plug-in
+Eclipse=Eclipse.org
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests.ui/plugin.xml b/tests/org.eclipse.wst.common.tests.ui/plugin.xml
new file mode 100644
index 0000000..cb8cb61
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/plugin.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.wst.common.tests.collector.suites">
+ <suite
+ class="org.eclipse.wst.common.tests.ui.DataModelUIAPITests"
+ name="DataModel UI API Tests">
+ </suite>
+ </extension>
+ <extension
+ point="org.eclipse.wst.common.frameworks.ui.DataModelWizardExtension">
+ <DataModelWizard
+ class="org.eclipse.wst.common.tests.ui.TestDataModelWizard"
+ id="org.eclipse.wst.common.frameworks.datamodel.tests.ITestDataModel"/>
+ </extension>
+ <extension
+ point="org.eclipse.wst.common.frameworks.ui.wizardPageGroup">
+ <wizardPageGroup
+ pageGroupID="foo"
+ wizardID="org.eclipse.wst.common.tests.ui.wizard.Test2DataModelProvider">
+ <factory className="org.eclipse.wst.common.tests.ui.wizard.Test2DataModelWizardFactory"/>
+ </wizardPageGroup>
+ <wizardPageGroup
+ pageGroupID="bar"
+ wizardID="org.eclipse.wst.common.tests.ui.wizard.Test2DataModelProvider">
+ <factory className="org.eclipse.wst.common.tests.ui.wizard.Test2DataModelWizardFactory2"/>
+ </wizardPageGroup>
+ <wizardPageGroup
+ pageGroupID="foobar"
+ wizardID="org.eclipse.wst.common.tests.ui.wizard.Test2DataModelProvider">
+ <factory className="org.eclipse.wst.common.tests.ui.wizard.Test2DataModelWizardFactory3"/>
+ </wizardPageGroup>
+ <wizardPage
+ wizardID="org.eclipse.wst.common.tests.ui.wizard.Test2DataModelProvider">
+ <factory
+ className="org.eclipse.wst.common.tests.ui.wizard.Test2PageWizardExtensionFactory">
+ </factory>
+ </wizardPage>
+ <wizardPage
+ wizardID="org.eclipse.wst.common.tests.ui.wizard.Test2DataModelProvider">
+ <factory
+ className="org.eclipse.wst.common.tests.ui.wizard.Test2PageWizardExtensionFactory2">
+ </factory>
+ </wizardPage>
+ </extension>
+
+ <!--
+ A picture of the operation tree
+ /**
+ * Operations are organized as follows: <code>
+ * D
+ * / \
+ * / \
+ * B F
+ * / \ / \
+ * A C E G
+ * </code>
+ */
+ -->
+
+ <extension
+ point="org.eclipse.wst.common.frameworks.OperationExtension"
+ id="org.eclipse.wst.common.tests.ui.manager">
+ <operationExtension
+ id="org.eclipse.wst.common.tests.ui.manager.D"
+ postOperationClass="org.eclipse.wst.common.tests.ui.manager.F"
+ preOperationClass="org.eclipse.wst.common.tests.ui.manager.B"/>
+ <operationExtension
+ id="org.eclipse.wst.common.tests.ui.manager.B"
+ postOperationClass="org.eclipse.wst.common.tests.ui.manager.C"
+ preOperationClass="org.eclipse.wst.common.tests.ui.manager.A"/>
+ <operationExtension
+ id="org.eclipse.wst.common.tests.ui.manager.F"
+ postOperationClass="org.eclipse.wst.common.tests.ui.manager.G"
+ preOperationClass="org.eclipse.wst.common.tests.ui.manager.E"/>
+ </extension>
+
+
+</plugin>
diff --git a/tests/org.eclipse.wst.common.tests.ui/pom.xml b/tests/org.eclipse.wst.common.tests.ui/pom.xml
new file mode 100644
index 0000000..7f2212b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/pom.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2012, 2013 Eclipse Foundation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Distribution License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/org/documents/edl-v10.php
+
+ Contributors:
+ Thanh Ha (Eclipse Foundation) - initial implementation
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.webtools.common.tests</artifactId>
+ <version>3.6.0-SNAPSHOT</version>
+ <relativePath>../../</relativePath>
+ </parent>
+
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.wst.common.tests.ui</artifactId>
+ <version>1.1.300-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+</project>
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/DataModelUIAPITests.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/DataModelUIAPITests.java
new file mode 100644
index 0000000..db71e2d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/DataModelUIAPITests.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.wst.common.tests.SimpleTestSuite;
+import org.eclipse.wst.common.tests.ui.wizard.TestWizardTestcase;
+
+/**
+ * @author jsholl
+ *
+ */
+public class DataModelUIAPITests extends TestSuite {
+
+ public static Test suite() {
+ return new DataModelUIAPITests();
+ }
+
+ public DataModelUIAPITests() {
+ super();
+ addTest(new SimpleTestSuite(DataModelUIFactoryTest.class));
+ addTest(new SimpleTestSuite(TestWizardTestcase.class));
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/DataModelUIFactoryTest.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/DataModelUIFactoryTest.java
new file mode 100644
index 0000000..5f2d281
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/DataModelUIFactoryTest.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui;
+
+import junit.framework.TestCase;
+
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.tests.ITestDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.tests.TestDataModelProvider;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardFactory;
+
+public class DataModelUIFactoryTest extends TestCase {
+
+ public void testValidExtensionID() {
+ IDataModel dataModel = DataModelFactory.createDataModel("org.eclipse.wst.common.frameworks.datamodel.tests.ITestDataModel"); //$NON-NLS-1$
+ assertTrue(dataModel.isProperty(ITestDataModel.FOO));
+ DataModelWizard wizard = DataModelWizardFactory.createWizard("org.eclipse.wst.common.frameworks.datamodel.tests.ITestDataModel"); //$NON-NLS-1$
+ assertNotNull(wizard);
+ assertNotNull(wizard.getDataModel());
+ }
+
+
+ public void testValidExtensionClass() {
+ IDataModel dataModel = DataModelFactory.createDataModel(ITestDataModel.class);
+ assertTrue(dataModel.isProperty(ITestDataModel.FOO));
+ DataModelWizard wizard = DataModelWizardFactory.createWizard(ITestDataModel.class);
+ assertNotNull(wizard);
+ assertNotNull(wizard.getDataModel());
+ }
+
+ public void testValidExtensionInstance() {
+ int startInstanceCount = TestDataModelProvider.getInstanceCount();
+ IDataModel dataModel = DataModelFactory.createDataModel(new TestDataModelProvider());
+ assertTrue(dataModel.isProperty(ITestDataModel.FOO));
+ DataModelWizard wizard = DataModelWizardFactory.createWizard(dataModel);
+ assertNotNull(wizard);
+ assertTrue(dataModel == wizard.getDataModel());
+ int endInstanceCount = TestDataModelProvider.getInstanceCount();
+ assertEquals(1, endInstanceCount-startInstanceCount);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/TestDataModelWizard.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/TestDataModelWizard.java
new file mode 100644
index 0000000..b6044c4
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/TestDataModelWizard.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui;
+
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.tests.TestDataModelProvider;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard;
+
+public class TestDataModelWizard extends DataModelWizard {
+
+ public TestDataModelWizard() {
+ super();
+ }
+
+ public TestDataModelWizard(IDataModel dataModel) {
+ super(dataModel);
+ }
+
+ protected IDataModelProvider getDefaultProvider() {
+ return new TestDataModelProvider();
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/UiPlugin.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/UiPlugin.java
new file mode 100644
index 0000000..976fc6e
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/UiPlugin.java
@@ -0,0 +1,86 @@
+package org.eclipse.wst.common.tests.ui;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class UiPlugin extends AbstractUIPlugin {
+ //The shared instance.
+ private static UiPlugin plugin;
+ //Resource bundle.
+ private ResourceBundle resourceBundle;
+
+ /**
+ * The constructor.
+ */
+ public UiPlugin() {
+ super();
+ plugin = this;
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ plugin = null;
+ resourceBundle = null;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static UiPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the string from the plugin's resource bundle,
+ * or 'key' if not found.
+ */
+ public static String getResourceString(String key) {
+ ResourceBundle bundle = UiPlugin.getDefault().getResourceBundle();
+ try {
+ return (bundle != null) ? bundle.getString(key) : key;
+ } catch (MissingResourceException e) {
+ return key;
+ }
+ }
+
+ /**
+ * Returns the plugin's resource bundle,
+ */
+ public ResourceBundle getResourceBundle() {
+ try {
+ if (resourceBundle == null)
+ resourceBundle = ResourceBundle.getBundle("org.eclipse.wst.common.tests.ui.UiPluginResources"); //$NON-NLS-1$
+ } catch (MissingResourceException x) {
+ resourceBundle = null;
+ }
+ return resourceBundle;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path.
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.wst.common.tests.ui", path); //$NON-NLS-1$
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/A.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/A.java
new file mode 100644
index 0000000..e0a7f57
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/A.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+public class A extends BaseOperation {
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/B.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/B.java
new file mode 100644
index 0000000..ce641b4
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/B.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+public class B extends BaseOperation {
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/BaseOperation.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/BaseOperation.java
new file mode 100644
index 0000000..e72b1f6
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/BaseOperation.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+import java.util.Vector;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.common.environment.ILog;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+
+public abstract class BaseOperation extends AbstractDataModelOperation {
+ public static Vector resultList;
+ public static Vector undoList;
+ private IStatus status;
+ private boolean checkModels;
+ private boolean modelsOK = false;
+
+ public BaseOperation() {
+ super();
+ }
+
+ public void setStatus(IStatus status) {
+ this.status = status;
+ }
+
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ resultList.add(getID());
+
+ getDataModel().setProperty("executedOps", resultList);
+ getDataModel().setProperty("executedUndoOps", undoList);
+ if (checkModels)
+ modelsOK = checkModels();
+
+ getEnvironment().getLog().log(ILog.OK, 1234, this, "BaseOperation", (Throwable) null); //$NON-NLS-1$
+
+ return status;
+ }
+
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return Status.OK_STATUS;
+ }
+
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ resultList.remove(resultList.size() - 1);
+ undoList.add(getID());
+ return Status.OK_STATUS;
+ }
+
+ public void setCheckModels(boolean checkModels) {
+ this.checkModels = checkModels;
+ }
+
+ public boolean getModelsOK() {
+ return modelsOK;
+ }
+
+ private boolean checkModels() {
+ IDataModel model = getDataModel();
+
+ boolean containsModel1 = model.isNestedModel("testprovider1");
+ boolean containsModel2 = model.isNestedModel("testprovider2");
+ boolean prop1 = model.isPropertySet("provider1Prop1");
+ boolean prop2 = model.isPropertySet("provider1Prop2");
+ boolean prop3 = model.isPropertySet("provider1Prop3");
+ boolean prop4 = model.isPropertySet("provider1Prop4");
+ boolean prop5 = model.isPropertySet("provider2Prop1");
+ boolean prop6 = model.isPropertySet("provider2Prop2");
+ boolean prop7 = model.isPropertySet("provider2Prop3");
+ boolean prop8 = model.isPropertySet("provider2Prop4");
+ boolean value1 = model.getProperty("provider1Prop1").equals("11");
+ boolean value2 = model.getProperty("provider1Prop2").equals("22");
+ boolean value3 = model.getProperty("provider1Prop3").equals("33");
+ boolean value4 = model.getProperty("provider1Prop4").equals("44");
+ boolean value5 = model.getProperty("provider2Prop1").equals("1111");
+ boolean value6 = model.getProperty("provider2Prop2").equals("2222");
+ boolean value7 = model.getProperty("provider2Prop3").equals("3333");
+ boolean value8 = model.getProperty("provider2Prop4").equals("4444");
+
+ return containsModel1 && containsModel2 && prop1 && prop2 && prop3 && prop4 && prop5 && prop6 && prop7 && prop8 && value1 && value2 && value3 && value4 && value5 && value6 && value7 && value8;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/C.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/C.java
new file mode 100644
index 0000000..f29751b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/C.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+public class C extends BaseOperation {
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/D.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/D.java
new file mode 100644
index 0000000..b4aad22
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/D.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+public class D extends BaseOperation {
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/E.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/E.java
new file mode 100644
index 0000000..600c671
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/E.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+public class E extends BaseOperation {
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/F.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/F.java
new file mode 100644
index 0000000..f42328e
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/F.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+public class F extends BaseOperation {
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/G.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/G.java
new file mode 100644
index 0000000..4f8a40f
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/G.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+public class G extends BaseOperation {
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestExtendedProvider.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestExtendedProvider.java
new file mode 100644
index 0000000..7610e30
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestExtendedProvider.java
@@ -0,0 +1,34 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+import java.util.Set;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+
+public class TestExtendedProvider extends AbstractDataModelProvider
+{
+ public Set getPropertyNames(){
+ Set propertyNames = super.getPropertyNames();
+ propertyNames.add("executedOps");
+ propertyNames.add("executedUndoOps");
+
+ return propertyNames;
+ }
+
+ public void init()
+ {
+ }
+
+ public String getID()
+ {
+ return "TestExtendedProvider";
+ }
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestGroupManager.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestGroupManager.java
new file mode 100644
index 0000000..6443deb
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestGroupManager.java
@@ -0,0 +1,525 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.wst.common.environment.EnvironmentService;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+import org.eclipse.wst.common.frameworks.internal.datamodel.DataModelImpl;
+import org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl;
+import org.eclipse.wst.common.frameworks.internal.datamodel.IDataModelPausibleOperation;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.IDMPageGroupHandler;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.IDMPageHandler;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.SimplePageGroup;
+import org.eclipse.wst.common.frameworks.internal.ui.PageGroupManager;
+
+public class TestGroupManager extends TestCase {
+
+ private IDataModelPausibleOperation rootOperation;
+
+ private PageGroupManager pageGroupManager;
+ private SimplePageGroup pgA;
+ private SimplePageGroup pgB;
+ private SimplePageGroup pgC;
+ private SimplePageGroup pgD;
+ private SimplePageGroup pgE;
+ private SimplePageGroup pgF;
+ private SimplePageGroup pgG;
+ private SimplePageGroup pgH;
+ private SimplePageGroup pgRoot;
+ private WizardPage r1;
+ private WizardPage b1;
+ private WizardPage b2;
+ private WizardPage c1;
+ private WizardPage d1;
+ private WizardPage d2;
+ private WizardPage d3;
+ private WizardPage f1;
+ private WizardPage f2;
+ private WizardPage f3;
+ private WizardPage f4;
+ private WizardPage f5;
+ private WizardPage f6;
+ private WizardPage g1;
+
+ private AGroupHandler aGroupHandler;
+ private FGroupHandler fGroupHandler;
+ private Vector expectedOps;
+ private Vector expectedUndoOps;
+ private IDataModel dataModel;
+
+ public static final String a = A.class.getName();
+ public static final String b = B.class.getName();
+ public static final String c = C.class.getName();
+ public static final String d = D.class.getName();
+ public static final String e = E.class.getName();
+ public static final String f = F.class.getName();
+ public static final String g = G.class.getName();
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ BaseOperation.resultList = new Vector();
+ BaseOperation.undoList = new Vector();
+
+ expectedOps = new Vector();
+ expectedUndoOps = new Vector();
+ dataModel = new DataModelImpl(new EmptyProvider());
+ dataModel.addNestedModel("testprovider1", DataModelFactory.createDataModel(new TestProvider1()));
+ dataModel.addNestedModel("testprovider2", DataModelFactory.createDataModel(new TestProvider2()));
+ dataModel.addNestedModel("testextendedprovider", DataModelFactory.createDataModel(new TestExtendedProvider()));
+
+ /**
+ * Operations are organized as follows: <code>
+ * D
+ * / \
+ * / \
+ * B F
+ * / \ / \
+ * A C E G
+ * </code>
+ */
+ rootOperation = new DataModelPausibleOperationImpl(new D());
+ rootOperation.setDataModel(dataModel);
+ rootOperation.setEnvironment(EnvironmentService.getEclipseConsoleEnvironment());
+
+ /**
+ * Page groups are organized as follows:
+ *
+ * <code>
+ *
+ * B - C
+ * / \
+ * Root - A - D \ G
+ * \ \ /
+ * ------ E - F - H
+ * \ null
+ * </code>
+ */
+
+ // The page group handler for A will return either B and then E or D and
+ // then E. The group handler for F will return either G or H and then null or
+ // just null.
+ //
+ // Some of these group require operations to run first:
+ //
+ // Page group B requires operation C.
+ // Page group D requires operation C.
+ // Page group E requires operation E.
+ // Page group F requires operation C.( C will already have been run and should not be
+ // rerun.)
+ //
+ // Each page group has some pages associated with it as follows:
+ //
+ // Root has page r1.
+ // A has no pages.
+ // B has b1 and b2.
+ // C has c1
+ // D has d1, d2, and d3
+ // E has no pages.
+ // F has pages f1, f2, f3, f4, f5, f6
+ // the page handler for F will return the following:
+ // expected = f1 returns f1
+ // expected = f2 returns skip
+ // expected = f3 returns before f6
+ // expected = f4 returns null
+ // expected = f5 returns after f5
+ // expected = f6 returns f4
+ // G has pages g1
+ // H has no pages.
+ r1 = new WizardPage("r1"); //$NON-NLS-1$
+ b1 = new WizardPage("b1"); //$NON-NLS-1$
+ b2 = new WizardPage("b2"); //$NON-NLS-1$
+ c1 = new WizardPage("c1"); //$NON-NLS-1$
+ d1 = new WizardPage("d1"); //$NON-NLS-1$
+ d2 = new WizardPage("d2"); //$NON-NLS-1$
+ d3 = new WizardPage("d3"); //$NON-NLS-1$
+ f1 = new WizardPage("f1"); //$NON-NLS-1$
+ f2 = new WizardPage("f2"); //$NON-NLS-1$
+ f3 = new WizardPage("f3"); //$NON-NLS-1$
+ f4 = new WizardPage("f4"); //$NON-NLS-1$
+ f5 = new WizardPage("f5"); //$NON-NLS-1$
+ f6 = new WizardPage("f6"); //$NON-NLS-1$
+ g1 = new WizardPage("g1"); //$NON-NLS-1$
+
+ String wizardID = "testWizard"; //$NON-NLS-1$
+
+ pgRoot = new SimplePageGroup("Root", wizardID); //$NON-NLS-1$
+ pgA = new SimplePageGroup("A", wizardID); //$NON-NLS-1$
+ pgB = new SimplePageGroup("B", wizardID, true, c); //$NON-NLS-1$ //$NON-NLS-2$
+ pgC = new SimplePageGroup("C", wizardID); //$NON-NLS-1$
+ pgD = new SimplePageGroup("D", wizardID, true, c); //$NON-NLS-1$ //$NON-NLS-2$
+ pgE = new SimplePageGroup("E", wizardID, true, e); //$NON-NLS-1$ //$NON-NLS-2$
+ pgF = new SimplePageGroup("F", wizardID, true, c); //$NON-NLS-1$ //$NON-NLS-2$
+ pgG = new SimplePageGroup("G", wizardID); //$NON-NLS-1$
+ pgH = new SimplePageGroup("H", wizardID); //$NON-NLS-1$
+
+ pgRoot.addPages(new WizardPage[]{r1});
+ pgB.addPages(new WizardPage[]{b1, b2});
+ pgC.addPages(new WizardPage[]{c1});
+ pgD.addPages(new WizardPage[]{d1, d2, d3});
+ pgF.addPages(new WizardPage[]{f1, f2, f3, f4, f5, f6});
+ pgG.addPages(new WizardPage[]{g1});
+
+ pgF.setPageHandler(new FPageHandler());
+
+ aGroupHandler = new AGroupHandler();
+ fGroupHandler = new FGroupHandler();
+
+ pgA.setPageGroupHandler(aGroupHandler);
+ pgF.setPageGroupHandler(fGroupHandler);
+
+ pageGroupManager = new PageGroupManager(rootOperation, pgRoot);
+ pageGroupManager.addGroupAfter("Root", pgA); //$NON-NLS-1$
+ pageGroupManager.addGroupAfter("A", pgB); //$NON-NLS-1$
+ pageGroupManager.addGroupAfter("A", pgD); //$NON-NLS-1$
+ pageGroupManager.addGroupAfter("A", pgE); //$NON-NLS-1$
+ pageGroupManager.addGroupAfter("B", pgC); //$NON-NLS-1$
+ pageGroupManager.addGroupAfter("E", pgF); //$NON-NLS-1$
+ pageGroupManager.addGroupAfter("F", pgG); //$NON-NLS-1$
+ pageGroupManager.addGroupAfter("F", pgH); //$NON-NLS-1$
+ }
+
+ public void testSimpleRun() throws Exception {
+ HashSet ids = new HashSet();
+ ids.add("testprovider1");
+ ids.add("testprovider2");
+ pgA.setDataModelIDs(ids);
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The root page should be null", pageGroupManager.getCurrentPage() == null); //$NON-NLS-1$
+ pageGroupManager.moveBackOnePage(); // Should do nothing.
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ aGroupHandler.setGroupIDToSelect("B"); //$NON-NLS-1$
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be r1", pageGroupManager.getCurrentPage() == r1); //$NON-NLS-1$
+ checkResults();
+ assertTrue("Data models not Ok for page group A", checkDataModels()); //$NON-NLS-1$
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be b1", pageGroupManager.getCurrentPage() == b1); //$NON-NLS-1$
+ expectedOps.add(a);
+ expectedOps.add(b);
+ expectedOps.add(c);
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be b2", pageGroupManager.getCurrentPage() == b2); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be c1", pageGroupManager.getCurrentPage() == c1); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f1", pageGroupManager.getCurrentPage() == f1); //$NON-NLS-1$
+ expectedOps.add(d);
+ expectedOps.add(e);
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f3", pageGroupManager.getCurrentPage() == f3); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f5", pageGroupManager.getCurrentPage() == f5); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f6", pageGroupManager.getCurrentPage() == f6); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ fGroupHandler.setGroupIDToSelect("G"); //$NON-NLS-1$
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f4", pageGroupManager.getCurrentPage() == f4); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertFalse("There should not be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be g1", pageGroupManager.getCurrentPage() == g1); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f4", pageGroupManager.getCurrentPage() == f4); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f4", pageGroupManager.getCurrentPage() == f6); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f4", pageGroupManager.getCurrentPage() == f5); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f4", pageGroupManager.getCurrentPage() == f3); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f4", pageGroupManager.getCurrentPage() == f1); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f4", pageGroupManager.getCurrentPage() == c1); //$NON-NLS-1$
+ expectedOps.setSize(3);
+ expectedUndoOps.add(e);
+ expectedUndoOps.add(d);
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be b2", pageGroupManager.getCurrentPage() == b2); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be b1", pageGroupManager.getCurrentPage() == b1); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveBackOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The root page should be r1", pageGroupManager.getCurrentPage() == r1); //$NON-NLS-1$
+ expectedOps = new Vector();
+ expectedUndoOps.add(c);
+ expectedUndoOps.add(b);
+ expectedUndoOps.add(a);
+ checkResults();
+
+ reset();
+ aGroupHandler.setGroupIDToSelect("D"); //$NON-NLS-1$
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be d1", pageGroupManager.getCurrentPage() == d1); //$NON-NLS-1$
+ expectedOps.add(a);
+ expectedOps.add(b);
+ expectedOps.add(c);
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be d2", pageGroupManager.getCurrentPage() == d2); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be d3", pageGroupManager.getCurrentPage() == d3); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f1", pageGroupManager.getCurrentPage() == f1); //$NON-NLS-1$
+ expectedOps.add(d);
+ expectedOps.add(e);
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f3", pageGroupManager.getCurrentPage() == f3); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f5", pageGroupManager.getCurrentPage() == f5); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ assertTrue("There should be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f6", pageGroupManager.getCurrentPage() == f6); //$NON-NLS-1$
+ checkResults();
+
+ pageGroupManager.moveForwardOnePage();
+ fGroupHandler.setGroupIDToSelect(null);
+ assertFalse("There should not be a next page", pageGroupManager.hasNextPage()); //$NON-NLS-1$
+ assertTrue("The page should be f4", pageGroupManager.getCurrentPage() == f4); //$NON-NLS-1$
+ checkResults();
+ }
+
+ private void checkResults() {
+ assertTrue("Expected=" + expectedOps.size() + " executed=" + BaseOperation.resultList.size(), BaseOperation.resultList.size() == expectedOps.size()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ for (int index = 0; index < BaseOperation.resultList.size(); index++) {
+ assertEquals(expectedOps.elementAt(index), BaseOperation.resultList.elementAt(index));
+ }
+
+ assertTrue("Expected undo=" + expectedUndoOps.size() + " executed=" + BaseOperation.undoList.size(), BaseOperation.undoList.size() == expectedUndoOps.size()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ for (int index = 0; index < BaseOperation.undoList.size(); index++) {
+ assertEquals(expectedUndoOps.elementAt(index), BaseOperation.undoList.elementAt(index));
+ }
+ }
+
+ private void reset() {
+ BaseOperation.resultList.removeAllElements();
+ expectedOps.removeAllElements();
+ BaseOperation.undoList.removeAllElements();
+ expectedUndoOps.removeAllElements();
+ }
+
+ private boolean checkDataModels() {
+ IDataModel model = dataModel;
+
+ boolean containsModel1 = model.isNestedModel("testprovider1");
+ boolean containsModel2 = model.isNestedModel("testprovider2");
+ boolean prop1 = model.isPropertySet("provider1Prop1");
+ boolean prop2 = model.isPropertySet("provider1Prop2");
+ boolean prop3 = model.isPropertySet("provider1Prop3");
+ boolean prop4 = model.isPropertySet("provider1Prop4");
+ boolean prop5 = model.isPropertySet("provider2Prop1");
+ boolean prop6 = model.isPropertySet("provider2Prop2");
+ boolean prop7 = model.isPropertySet("provider2Prop3");
+ boolean prop8 = model.isPropertySet("provider2Prop4");
+ boolean value1 = model.getProperty("provider1Prop1").equals("11");
+ boolean value2 = model.getProperty("provider1Prop2").equals("22");
+ boolean value3 = model.getProperty("provider1Prop3").equals("33");
+ boolean value4 = model.getProperty("provider1Prop4").equals("44");
+ boolean value5 = model.getProperty("provider2Prop1").equals("1111");
+ boolean value6 = model.getProperty("provider2Prop2").equals("2222");
+ boolean value7 = model.getProperty("provider2Prop3").equals("3333");
+ boolean value8 = model.getProperty("provider2Prop4").equals("4444");
+
+ return containsModel1 && containsModel2 && prop1 && prop2 && prop3 && prop4 && prop5 && prop6 && prop7 && prop8 && value1 && value2 && value3 && value4 && value5 && value6 && value7 && value8;
+ }
+
+ private class AGroupHandler implements IDMPageGroupHandler {
+ private String groupID_;
+
+ public String getNextPageGroup(String currentPageGroupID, String[] pageGroupIDs) {
+ String result = null;
+
+ if (currentPageGroupID == null) {
+ result = groupID_;
+ } else if (currentPageGroupID.equals("E")) { //$NON-NLS-1$
+ result = null;
+ } else {
+ result = "E"; //$NON-NLS-1$
+ }
+
+ return result;
+ }
+
+ public void setGroupIDToSelect(String id) {
+ groupID_ = id;
+ }
+ }
+
+ private class FGroupHandler implements IDMPageGroupHandler {
+ private String groupID_;
+
+ public String getNextPageGroup(String currentPageGroupID, String[] pageGroupIDs) {
+ if (currentPageGroupID == null)
+ return groupID_;
+
+ return null;
+ }
+
+ public void setGroupIDToSelect(String id) {
+ groupID_ = id;
+ }
+ }
+
+ //
+ // F has pages f1, f2, f3, f4, f5, f6
+ // the page handler for F will return the following:
+ // expected = f1 returns f1
+ // expected = f2 returns skip
+ // expected = f3 returns before f6
+ // expected = f4 returns null
+ // expected = f5 returns after f5
+ // expected = f6 returns f4
+ //
+ // This handle should cause the following pages to be used.
+ // f1, f3, f5, f6, f4, null
+ //
+ private class FPageHandler implements IDMPageHandler {
+ public String getNextPage(String currentPageName, String expectedNextPageName) {
+ String result = null;
+
+ if (currentPageName == null) {
+ result = "f1"; //$NON-NLS-1$
+ } else if (currentPageName.equals("f1")) { //$NON-NLS-1$
+ result = IDMPageHandler.SKIP_PAGE;
+ } else if (currentPageName.equals("f3")) { //$NON-NLS-1$
+ result = IDMPageHandler.PAGE_BEFORE + "f6"; //$NON-NLS-1$
+ } else if (currentPageName.equals("f4")) { //$NON-NLS-1$
+ result = null;
+ } else if (currentPageName.equals("f5")) { //$NON-NLS-1$
+ result = IDMPageHandler.PAGE_AFTER + "f5"; //$NON-NLS-1$
+ } else if (currentPageName.equals("f6")) { //$NON-NLS-1$
+ result = "f4"; //$NON-NLS-1$
+ }
+
+ return result;
+ }
+
+ public String getPreviousPage(String currentPageName, String expectedPreviousPageName) {
+ return expectedPreviousPageName;
+ }
+
+ }
+
+ private class EmptyProvider extends AbstractDataModelProvider {
+
+ public Set getPropertyNames() {
+ return new HashSet();
+ }
+ }
+
+ private class WizardPage extends DataModelWizardPage {
+ private boolean canFinish_ = true;
+
+ public WizardPage(String id) {
+ super(dataModel, id);
+ }
+
+ protected Composite createTopLevelComposite(Composite parent) {
+ return null;
+ }
+
+ protected String[] getValidationPropertyNames() {
+ return new String[0];
+ }
+
+ public void setCanFinish(boolean canFinish) {
+ canFinish_ = canFinish;
+ }
+
+ public boolean canPageFinish() {
+ return canFinish_;
+ }
+
+ public IDataModelOperation createOperation() {
+ return null;
+ }
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestProvider1.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestProvider1.java
new file mode 100644
index 0000000..996b02f
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestProvider1.java
@@ -0,0 +1,40 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+import java.util.Set;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+
+public class TestProvider1 extends AbstractDataModelProvider
+{
+ public Set getPropertyNames(){
+ Set propertyNames = super.getPropertyNames();
+ propertyNames.add("provider1Prop1");
+ propertyNames.add("provider1Prop2");
+ propertyNames.add("provider1Prop3");
+ propertyNames.add("provider1Prop4");
+
+ return propertyNames;
+ }
+
+ public void init()
+ {
+ setProperty( "provider1Prop1", "11" );
+ setProperty( "provider1Prop2", "22" );
+ setProperty( "provider1Prop3", "33" );
+ setProperty( "provider1Prop4", "44" );
+ }
+
+ public String getID()
+ {
+ return "testprovider1";
+ }
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestProvider2.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestProvider2.java
new file mode 100644
index 0000000..670149d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/manager/TestProvider2.java
@@ -0,0 +1,39 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.manager;
+
+import java.util.Set;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+
+public class TestProvider2 extends AbstractDataModelProvider
+{
+ public Set getPropertyNames(){
+ Set propertyNames = super.getPropertyNames();
+ propertyNames.add("provider2Prop1");
+ propertyNames.add("provider2Prop2");
+ propertyNames.add("provider2Prop3");
+ propertyNames.add("provider2Prop4");
+
+ return propertyNames;
+ }
+
+ public void init()
+ {
+ setProperty( "provider2Prop1", "1111" );
+ setProperty( "provider2Prop2", "2222" );
+ setProperty( "provider2Prop3", "3333" );
+ setProperty( "provider2Prop4", "4444" );
+ }
+
+ public String getID()
+ {
+ return "testprovider2";
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelProvider.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelProvider.java
new file mode 100644
index 0000000..d619d48
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelProvider.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+
+public class Test2DataModelProvider extends AbstractDataModelProvider {
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizard.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizard.java
new file mode 100644
index 0000000..63eb6e6
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizard.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.AddablePageGroup;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.SimplePageGroup;
+import org.eclipse.wst.common.frameworks.internal.ui.SimplePageGroupHandler;
+
+public class Test2DataModelWizard extends DataModelWizard {
+
+ protected IDataModelProvider getDefaultProvider() {
+ return new Test2DataModelProvider();
+ }
+
+ protected AddablePageGroup createRootPageGroup() {
+ SimplePageGroup pg = (SimplePageGroup) super.createRootPageGroup();
+ pg.setPageGroupHandler(new SimplePageGroupHandler() {
+ public String getNextPageGroup(String currentPageGroupID, String[] pageGroupIDs) {
+ if (currentPageGroupID == null) {
+ for (int i = 0; i < pageGroupIDs.length; i++) {
+ if (pageGroupIDs[i].equals("bar")) { //$NON-NLS-1$
+ return "bar"; //$NON-NLS-1$
+ }
+ }
+ }
+ return super.getNextPageGroup(currentPageGroupID, pageGroupIDs);
+ }
+ });
+ return pg;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory.java
new file mode 100644
index 0000000..9215d0d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
+import org.eclipse.wst.common.frameworks.internal.operation.extensionui.DMWizardExtensionFactory;
+
+public class Test2DataModelWizardFactory extends DMWizardExtensionFactory {
+
+ protected String getPageName() {
+ return "A Page"; //$NON-NLS-1$
+ }
+
+ protected IDataModelProvider getProvider(){
+ return new Test2DataModelProvider(){
+ public IDataModelOperation getDefaultOperation() {
+ return new AbstractDataModelOperation(){
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ System.out.println(getPageName());
+ return OK_STATUS;
+ }
+ };
+ }
+ };
+ }
+
+ public DataModelWizardPage[] createPageGroup(IDataModel dataModel, String pageGroupID) {
+ return new DataModelWizardPage[]{new DataModelWizardPage(DataModelFactory.createDataModel(getProvider()), getPageName()) {
+ protected String[] getValidationPropertyNames() {
+ return null;
+ }
+
+ protected Composite createTopLevelComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ composite.setLayout(new GridLayout());
+ GridData data = new GridData(GridData.FILL_BOTH);
+ Label label = new Label(composite, SWT.NULL);
+ label.setLayoutData(data);
+ label.setText(getPageName());
+ return composite;
+ }
+ }};
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory2.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory2.java
new file mode 100644
index 0000000..0f758a7
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory2.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+public class Test2DataModelWizardFactory2 extends Test2DataModelWizardFactory {
+
+ protected String getPageName() {
+ return "A Better Page"; //$NON-NLS-1$
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory3.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory3.java
new file mode 100644
index 0000000..891e403
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2DataModelWizardFactory3.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+public class Test2DataModelWizardFactory3 extends Test2DataModelWizardFactory {
+
+ protected String getPageName() {
+ return "Another Page, but not better"; //$NON-NLS-1$
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2PageWizardExtensionFactory.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2PageWizardExtensionFactory.java
new file mode 100644
index 0000000..fc27174
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2PageWizardExtensionFactory.java
@@ -0,0 +1,27 @@
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.internal.operation.extensionui.DMWizardPageExtensionFactory;
+
+public class Test2PageWizardExtensionFactory extends
+ DMWizardPageExtensionFactory {
+
+ public void createAdditionalControls(Composite parent, IDataModel model,
+ String pageName) {
+ String labelName;
+ if ("A Better Page".equals(pageName)) {
+ labelName = "An additonal text box for the better page";
+ } else if ("Another Page, but not better".equals(pageName)) {
+ labelName = "An additonal text box for the NOT better page";
+ } else {
+ return;
+ }
+
+ Label label = new Label(parent, SWT.NONE);
+ label.setText(labelName);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2PageWizardExtensionFactory2.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2PageWizardExtensionFactory2.java
new file mode 100644
index 0000000..83c0b2f
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/Test2PageWizardExtensionFactory2.java
@@ -0,0 +1,20 @@
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.internal.operation.extensionui.DMWizardPageExtensionFactory;
+
+public class Test2PageWizardExtensionFactory2 extends
+ DMWizardPageExtensionFactory {
+
+ public void createAdditionalControls(Composite parent, IDataModel model,
+ String pageName) {
+ if ("A Better Page".equals(pageName)) {
+ Button checkbox = new Button(parent, SWT.CHECK);
+ checkbox.setText("Additional checkbox for a better page");
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestDataModelProvider.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestDataModelProvider.java
new file mode 100644
index 0000000..5fb74f4
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestDataModelProvider.java
@@ -0,0 +1,33 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+
+public class TestDataModelProvider extends AbstractDataModelProvider {
+ public String getID() {
+ return "TestWizardID"; //$NON-NLS-1$
+ }
+
+ public Set getPropertyNames() {
+ HashSet result = new HashSet();
+
+ result.add("prop1"); //$NON-NLS-1$
+ result.add("prop2"); //$NON-NLS-1$
+
+ return result;
+ }
+
+ public IDataModelOperation getDefaultOperation() {
+ return new TestOperation();
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestDataWizard.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestDataWizard.java
new file mode 100644
index 0000000..ce6dde7
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestDataWizard.java
@@ -0,0 +1,41 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.AddablePageGroup;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.SimplePageGroup;
+import org.eclipse.wst.common.frameworks.internal.ui.PageGroupManager;
+
+public class TestDataWizard extends DataModelWizard {
+ private SimplePageGroup root;
+
+ public TestDataWizard() {
+ setForcePreviousAndNextButtons(true);
+ setNeedsProgressMonitor(true);
+ }
+
+ protected void doAddPages() {
+ PageGroupManager pageManager = getPageGroupManager();
+ pageManager.addGroupAfter(root.getPageGroupID(), new TestPageGroup2(getDataModel()));
+
+ super.doAddPages();
+ }
+
+ protected IDataModelProvider getDefaultProvider() {
+ return new TestDataModelProvider();
+ }
+
+ protected AddablePageGroup createRootPageGroup() {
+ root = new TestRootPageGroup(getDataModel());
+
+ return root;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestOperation.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestOperation.java
new file mode 100644
index 0000000..ecf4a34
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestOperation.java
@@ -0,0 +1,49 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation;
+
+public class TestOperation extends AbstractDataModelOperation {
+
+ public TestOperation() {
+ setID("TestOperation"); //$NON-NLS-1$
+ }
+
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ System.out.println("In execute: data model=" + getDataModel()); //$NON-NLS-1$
+
+ try {
+ monitor.beginTask("Test operation: ", 5); //$NON-NLS-1$
+ for (int index = 1; index < 6; index++) {
+ monitor.subTask("part " + index + " of 5 complete."); //$NON-NLS-1$ //$NON-NLS-2$
+ Thread.sleep(1000);
+ }
+ } catch (Exception exc) {
+ throw new ExecutionException("execute threw and exception ", exc); //$NON-NLS-1$
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ return Status.OK_STATUS;
+ }
+
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ System.out.println("Undo test operation"); //$NON-NLS-1$
+
+ return Status.OK_STATUS;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPage1.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPage1.java
new file mode 100644
index 0000000..62a71b4
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPage1.java
@@ -0,0 +1,51 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
+
+public class TestPage1 extends DataModelWizardPage {
+ public TestPage1(IDataModel model) {
+ super(model, "Page1"); //$NON-NLS-1$
+ setTitle("Title for test page1"); //$NON-NLS-1$
+ setDescription("Description for test page 1"); //$NON-NLS-1$
+ }
+
+ public boolean canPageFinish() {
+ return true;
+ }
+
+ public IDataModelOperation createOperation() {
+ return null;
+ }
+
+ protected Composite createTopLevelComposite(Composite parent) {
+ Composite group = new Composite(parent, SWT.NONE);
+ Button button1 = new Button(group, SWT.PUSH);
+ Button button2 = new Button(group, SWT.PUSH);
+
+ button1.setText("Button1"); //$NON-NLS-1$
+ button2.setText("Button2"); //$NON-NLS-1$
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ return group;
+ }
+
+ protected String[] getValidationPropertyNames() {
+ return new String[0];
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPage2.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPage2.java
new file mode 100644
index 0000000..78963f9
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPage2.java
@@ -0,0 +1,51 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
+
+public class TestPage2 extends DataModelWizardPage {
+ public TestPage2(IDataModel model) {
+ super(model, "Page2"); //$NON-NLS-1$
+ setTitle("Title for test page2"); //$NON-NLS-1$
+ setDescription("Description for test page 2"); //$NON-NLS-1$
+ }
+
+ public boolean canPageFinish() {
+ return true;
+ }
+
+ public IDataModelOperation createOperation() {
+ return null;
+ }
+
+ protected Composite createTopLevelComposite(Composite parent) {
+ Composite group = new Composite(parent, SWT.NONE);
+ Button button1 = new Button(group, SWT.PUSH);
+ Button button2 = new Button(group, SWT.PUSH);
+
+ button1.setText("Page 2 button1"); //$NON-NLS-1$
+ button2.setText("Page 2 button2"); //$NON-NLS-1$
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ return group;
+ }
+
+ protected String[] getValidationPropertyNames() {
+ return new String[0];
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPageGroup2.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPageGroup2.java
new file mode 100644
index 0000000..98a8355
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestPageGroup2.java
@@ -0,0 +1,24 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.SimplePageGroup;
+
+public class TestPageGroup2 extends SimplePageGroup {
+ private IDataModel dataModel;
+
+ public TestPageGroup2(IDataModel dataModel) {
+ super("group2", dataModel.getID(), true, "TestOperation"); //$NON-NLS-1$ //$NON-NLS-2$
+ this.dataModel = dataModel;
+
+ addPages(new IWizardPage[]{new TestPage2(this.dataModel)});
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestRootPageGroup.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestRootPageGroup.java
new file mode 100644
index 0000000..ad285b9
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestRootPageGroup.java
@@ -0,0 +1,24 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.internal.datamodel.ui.SimplePageGroup;
+
+public class TestRootPageGroup extends SimplePageGroup {
+ private IDataModel dataModel;
+
+ public TestRootPageGroup(IDataModel dataModel) {
+ super(dataModel.getID(), dataModel.getID());
+ this.dataModel = dataModel;
+
+ addPages(new IWizardPage[]{new TestPage1(this.dataModel)});
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestWizardTestcase.java b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestWizardTestcase.java
new file mode 100644
index 0000000..0d05a9b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.ui/src/org/eclipse/wst/common/tests/ui/wizard/TestWizardTestcase.java
@@ -0,0 +1,39 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.tests.ui.wizard;
+
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Display;
+
+import junit.framework.TestCase;
+
+public class TestWizardTestcase extends TestCase {
+ private TestDataWizard wizard_;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ wizard_ = new TestDataWizard();
+ }
+
+ public void testSimpleWizard() throws Exception {
+ WizardDialog dialog = new WizardDialog(null, wizard_);
+
+ dialog.open();
+ }
+
+ public void test2DataModelWizard() throws Exception {
+ Display.getDefault().syncExec( new Runnable(){
+ public void run() {
+ WizardDialog dialog = new WizardDialog(null, new Test2DataModelWizard());
+ dialog.open();
+ }
+ });
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/.classpath b/tests/org.eclipse.wst.common.tests.validation.guard/.classpath
new file mode 100644
index 0000000..304e861
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/.project b/tests/org.eclipse.wst.common.tests.validation.guard/.project
new file mode 100644
index 0000000..0e255c9
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.common.tests.validation.guard</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.wst.common.tests.validation.guard/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..73e4b8d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Sat Mar 29 07:53:31 EDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.common.tests.validation.guard/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..4bbfa9f
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name.0
+Bundle-SymbolicName: org.eclipse.wst.common.tests.validation.guard;singleton:=true
+Bundle-Version: 1.0.200.qualifier
+Bundle-Activator: org.eclipse.wst.common.tests.validation.guard.Activator
+Bundle-Vendor: %Bundle-Vendor.0
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.wst.validation;bundle-version="[1.1.103,1.3.0)",
+ org.eclipse.core.resources
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Localization: plugin
+Bundle-ActivationPolicy: lazy
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/about.html b/tests/org.eclipse.wst.common.tests.validation.guard/about.html
new file mode 100644
index 0000000..2199df3
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/about.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>June, 2008</P>
+
+<H3>License</H3>
+
+<P>The Eclipse Foundation makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from the Eclipse Foundation, the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributors license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P>
+
+</BODY>
+</HTML>
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/build.properties b/tests/org.eclipse.wst.common.tests.validation.guard/build.properties
new file mode 100644
index 0000000..f7540fb
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/build.properties
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.properties,\
+ plugin.xml,\
+ about.html
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/plugin.properties b/tests/org.eclipse.wst.common.tests.validation.guard/plugin.properties
new file mode 100644
index 0000000..b6bc9c1
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/plugin.properties
@@ -0,0 +1,3 @@
+Bundle-Name.0 = Validation Framework Guard Test cases
+Bundle-Vendor.0 = Eclipse Web Tools Platform
+
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/plugin.xml b/tests/org.eclipse.wst.common.tests.validation.guard/plugin.xml
new file mode 100644
index 0000000..84daa2b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/plugin.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.wst.validation.validatorV2"
+ id="T3A" name="T3A">
+ <validator
+ build="false"
+ class="org.eclipse.wst.common.tests.validation.guard.T3A"
+ manual="false">
+ </validator>
+ </extension>
+ <extension
+ point="org.eclipse.wst.validation.validatorV2"
+ id="T3B" name="T3B">
+ <validator class="org.eclipse.wst.common.tests.validation.guard.T3B">
+ <include>
+ <rules>
+ <facet
+ id="a.bogus.facet">
+ </facet>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+</plugin>
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/pom.xml b/tests/org.eclipse.wst.common.tests.validation.guard/pom.xml
new file mode 100644
index 0000000..839c28c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/pom.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2012, 2013 Eclipse Foundation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Distribution License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/org/documents/edl-v10.php
+
+ Contributors:
+ Thanh Ha (Eclipse Foundation) - initial implementation
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.webtools.common.tests</artifactId>
+ <version>3.6.0-SNAPSHOT</version>
+ <relativePath>../../</relativePath>
+ </parent>
+
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.wst.common.tests.validation.guard</artifactId>
+ <version>1.0.200-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
+</project>
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/Activator.java b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/Activator.java
new file mode 100644
index 0000000..e512afe
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/Activator.java
@@ -0,0 +1,67 @@
+package org.eclipse.wst.common.tests.validation.guard;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The purpose of this plug-in is to ensure that it never gets loaded. If it does it means that we are
+ * activating validators too early.
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.wst.common.tests.validation.guard";
+
+ // The shared instance
+ private static Activator plugin;
+
+ public Activator() {
+ RuntimeException re = new RuntimeException("This plug-in should never be loaded. If it is it means that we are loading " +
+ "validators too early, and causing unneccessary plug-in activation.");
+ handleException(re);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Write this exception to the log.
+ * <p>
+ * We are in the transition of moving to a new approach for localized messages. This is the new
+ * approach for exceptions.
+ *
+ * @param e the throwable, this can be null in which case it is a nop.
+ */
+ public void handleException(Throwable e){
+ if (e == null)return;
+ Status status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e);
+ getLog().log(status);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3A.java b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3A.java
new file mode 100644
index 0000000..7146182
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3A.java
@@ -0,0 +1,31 @@
+package org.eclipse.wst.common.tests.validation.guard;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * A test validator that we never expect to be activated. The reason we never expect it to be validated is that by
+ * default it is turned off. The user can still explicitly turn it on, in which case it will run, and that would not
+ * be considered an error.
+ * @author karasiuk
+ *
+ */
+public class T3A extends AbstractValidator {
+
+ private boolean _invoked;
+
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor){
+ if (!_invoked){
+ _invoked = true;
+ throw new RuntimeException("The T3A validator should never be activated or called. If this validator was manually turned on " +
+ "though the preferences, then this is not a real error.");
+ }
+
+ return null;
+ }
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3B.java b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3B.java
new file mode 100644
index 0000000..bb649ae
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation.guard/src/org/eclipse/wst/common/tests/validation/guard/T3B.java
@@ -0,0 +1,29 @@
+package org.eclipse.wst.common.tests.validation.guard;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * A test validator that we never expect to be activated. The reason we never expect it to be validated is that it has a bogus facet filter.
+ * @author karasiuk
+ *
+ */
+public class T3B extends AbstractValidator {
+
+ private boolean _invoked;
+
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor){
+ if (!_invoked){
+ _invoked = true;
+ throw new RuntimeException("The T3B validator should never be activated or called. If this validator was manually chnaged " +
+ "though the preferences, and the bogus filter was removed, then this isn't a real error.");
+ }
+
+ return null;
+ }
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/.classpath b/tests/org.eclipse.wst.common.tests.validation/.classpath
new file mode 100644
index 0000000..389f521
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="validators"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.wst.common.tests.validation/.project b/tests/org.eclipse.wst.common.tests.validation/.project
new file mode 100644
index 0000000..e05c75d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.common.tests.validation</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.wst.common.tests.validation/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.wst.common.tests.validation/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..7952069
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,15 @@
+#Sun Apr 20 07:23:01 EDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.codeComplete.argumentPrefixes=
+org.eclipse.jdt.core.codeComplete.argumentSuffixes=
+org.eclipse.jdt.core.codeComplete.fieldPrefixes=_
+org.eclipse.jdt.core.codeComplete.fieldSuffixes=
+org.eclipse.jdt.core.codeComplete.localPrefixes=
+org.eclipse.jdt.core.codeComplete.localSuffixes=
+org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=_
+org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/tests/org.eclipse.wst.common.tests.validation/.settings/org.eclipse.jdt.ui.prefs b/tests/org.eclipse.wst.common.tests.validation/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..3982d6b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,6 @@
+#Sun Apr 20 07:23:01 EDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.ui.exception.name=e
+org.eclipse.jdt.ui.gettersetter.use.is=true
+org.eclipse.jdt.ui.keywordthis=false
+org.eclipse.jdt.ui.overrideannotation=true
diff --git a/tests/org.eclipse.wst.common.tests.validation/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.common.tests.validation/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..36d46b6
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/META-INF/MANIFEST.MF
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name.0
+Bundle-SymbolicName: org.eclipse.wst.common.tests.validation;singleton:=true
+Bundle-Version: 1.0.400.qualifier
+Bundle-Activator: org.eclipse.wst.common.tests.validation.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.wst.validation,
+ org.junit;bundle-version="3.8.2",
+ org.eclipse.core.resources,
+ org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Bundle-Vendor: %Bundle-Vendor.0
+Bundle-Localization: plugin
+Export-Package: org.eclipse.wst.validation.tests.testcase
diff --git a/tests/org.eclipse.wst.common.tests.validation/about.html b/tests/org.eclipse.wst.common.tests.validation/about.html
new file mode 100644
index 0000000..2199df3
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/about.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>June, 2008</P>
+
+<H3>License</H3>
+
+<P>The Eclipse Foundation makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from the Eclipse Foundation, the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributors license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P>
+
+</BODY>
+</HTML>
diff --git a/tests/org.eclipse.wst.common.tests.validation/build.properties b/tests/org.eclipse.wst.common.tests.validation/build.properties
new file mode 100644
index 0000000..077a48c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/build.properties
@@ -0,0 +1,9 @@
+source.. = src/,\
+ validators/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ plugin.properties,\
+ test.xml,\
+ about.html
diff --git a/tests/org.eclipse.wst.common.tests.validation/plugin.properties b/tests/org.eclipse.wst.common.tests.validation/plugin.properties
new file mode 100644
index 0000000..84f4499
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/plugin.properties
@@ -0,0 +1,16 @@
+Bundle-Name.0 = Validation Framework Test cases
+Bundle-Vendor.0 = Eclipse Web Tools Platform
+
+Test1.Validator.Name=Test1 Validator
+Test2.Validator.Name=Test2 Validator
+Test3.Validator.Name=Test3 Validator
+Test4.Validator.Name=Test4 Validator
+Test5.Validator.Name=Test5 Validator
+Test5D.Validator.Name=Test5D Validator
+Test6.Validator.Name=Test6 Validator
+Test7.Validator.Name=Test7 Validator
+
+Message.bad=Really bad things
+Message.sortof=Sort of bad things
+Message.nice=Nice things
+Message.long=A line that is a bit long, just to see how it looks
diff --git a/tests/org.eclipse.wst.common.tests.validation/plugin.xml b/tests/org.eclipse.wst.common.tests.validation/plugin.xml
new file mode 100644
index 0000000..c2c6cad
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/plugin.xml
@@ -0,0 +1,401 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.wst.validation.validatorV2"
+ id="Test1" name="%Test1.Validator.Name">
+ <validator
+ build="false"
+ class="org.eclipse.wst.validation.tests.TestValidator"
+ manual="false">
+ <include>
+ <rules>
+ <fileext
+ ext="test1">
+ </fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+ <extension
+ point="org.eclipse.wst.validation.validatorV2"
+ id="Test2" name="%Test2.Validator.Name">
+ <validator
+ build="false"
+ class="org.eclipse.wst.validation.tests.TestValidator2"
+ manual="false">
+ <include>
+ <rules>
+ <fileext
+ ext="jsp">
+ </fileext>
+ <file name="somefile.txt" type="file"/>
+ <fileext
+ ext="jspx">
+ </fileext>
+ <fileext
+ ext="java">
+ </fileext>
+ <fileext
+ ext="test2">
+ </fileext>
+ </rules>
+ </include>
+ <include>
+ <rules>
+ <projectNature id="org.eclipse.sample" />
+ <facet id="com.ibm.vf.test.facet2"/>
+ </rules>
+ </include>
+ <include>
+ <rules>
+ <contentType
+ id="com.ibm.vf.test.contentType2">
+ </contentType>
+ </rules>
+ </include>
+ <exclude>
+ <rules>
+ <facet
+ id="org.eclipse.wst.wid.facet">
+ </facet>
+ </rules>
+ </exclude>
+ <messageCategory id="bad" label="%Message.bad" severity="error"/>
+ <messageCategory id="sortof" label="%Message.sortof" severity="warning"/>
+ <messageCategory id="nice" label="%Message.nice" severity="ignore"/>
+ <messageCategory id="long" label="%Message.long" severity="ignore"/>
+
+ </validator>
+ </extension>
+
+ <extension
+ point="org.eclipse.wst.validation.validatorV2"
+ id="Test3" name="%Test3.Validator.Name">
+ <validator
+ build="false"
+ class="org.eclipse.wst.validation.tests.TestValidator3"
+ manual="false">
+ <include>
+ <rules>
+ <fileext
+ ext="html">
+ </fileext>
+ <fileext
+ ext="htm">
+ </fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="Test4" name="%Test4.Validator.Name">
+ <validator build="false"
+ class="org.eclipse.wst.validation.tests.TestValidator4"
+ manual="false">
+ <include>
+ <rules>
+ <fileext
+ ext="test4">
+ </fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension id="Test5" name="%Test5.Validator.Name" point="org.eclipse.wst.validation.validatorV2">
+ <validator build="false" class="org.eclipse.wst.validation.tests.TestValidator5" manual="false">
+ <include>
+ <rules>
+ <fileext
+ ext="test5">
+ </fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorDelegates">
+ <delegate
+ class="org.eclipse.wst.validation.tests.TestValidator5D"
+ name="%Test5D.Validator.Name"
+ target="org.eclipse.wst.validation.tests.TestValidator5">
+ </delegate>
+ </extension>
+ <extension
+ id="Test6"
+ name="%Test6.Validator.Name"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ build="false"
+ class="org.eclipse.wst.validation.tests.TestValidator6"
+ manual="false">
+ <include>
+ <rules>
+ <contentType id="org.eclipse.core.runtime.xml"></contentType>
+ <contentType id="org.eclipse.wst.xml.core.xmlsource"></contentType>
+ <contentType id="org.eclipse.wst.xml.core.xslsource"></contentType>
+ <contentType id="org.eclipse.jst.jsp.core.tldsource"></contentType>
+ </rules>
+ </include>
+ <exclude>
+ <rules>
+ <file
+ caseSensitive="true"
+ name=".project"
+ type="file">
+ </file>
+ </rules>
+ </exclude>
+ </validator>
+ </extension>
+ <extension
+ point="org.eclipse.wst.validation.validatorV2"
+ id="Test7" name="%Test7.Validator.Name">
+ <validator
+ build="false"
+ class="org.eclipse.wst.validation.tests.TestValidator7"
+ manual="false">
+ <include>
+ <rules>
+ <fileext
+ ext="test1">
+ </fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension
+ point="org.eclipse.wst.validation.validatorV2"
+ id="Test8" name="Test8">
+ <validator
+ build="false"
+ class="org.eclipse.wst.validation.tests.TestValidator8"
+ manual="false">
+ <include>
+ <rules>
+ <file name="file.specific" type="file"/>
+ <file name="source/full.specific" type="full"/>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension
+ point="org.eclipse.wst.validation.validatorV2"
+ id="T1A" name="T1A Validator">
+ <validator
+ build="false"
+ class="org.eclipse.wst.validation.tests.T1AValidator"
+ manual="false">
+ <include>
+ <rules>
+ <fileext
+ ext="test1">
+ </fileext>
+ </rules>
+ </include>
+ <group
+ id="org.eclipse.wst.common.tests.validation.t1group">
+ </group>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T1B" name="T1B Validator">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T1B"
+ markerId="org.eclipse.wst.common.tests.validation.t1bmarker">
+ <include>
+ <rules>
+ <fileext
+ ext="t1b">
+ </fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T1C" name="T1C">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T1C" manual="false">
+ <include>
+ <rules>
+ <fileext
+ ext="t1c">
+ </fileext>
+ </rules>
+ </include>
+ <exclude>
+ <rules>
+ <file
+ caseSensitive="false"
+ name="ignore"
+ type="folder">
+ </file>
+ </rules>
+ </exclude>
+ <group
+ id="org.eclipse.wst.common.tests.validation.t1group">
+ </group>
+ </validator>
+ </extension>
+
+ <extension id="t2a" name="T2A" point="org.eclipse.wst.validation.validator">
+ <validator>
+ <helper
+ class="org.eclipse.wst.validation.tests.T2AHelper">
+ </helper>
+ <run
+ class="org.eclipse.wst.validation.tests.T2A"
+ enabled="false">
+ </run>
+ </validator>
+ </extension>
+ <extension
+ id="t2b"
+ name="T2B"
+ point="org.eclipse.wst.validation.validator">
+ <validator>
+ <helper
+ class="org.eclipse.wst.validation.tests.T2AHelper">
+ </helper>
+ <run
+ class="org.eclipse.wst.validation.tests.T2B"
+ enabled="true">
+ </run>
+ </validator>
+ </extension>
+ <extension
+ id="t1bmarker"
+ name="T1B Message"
+ point="org.eclipse.core.resources.markers">
+ <super
+ type="org.eclipse.core.resources.problemmarker">
+ </super>
+ <persistent
+ value="true">
+ </persistent>
+ </extension>
+ <extension
+ point="org.eclipse.wst.validation.validatorGroup">
+ <group
+ id="t1group">
+ <listener
+ class="org.eclipse.wst.validation.tests.T1Group">
+ </listener>
+ </group>
+ </extension>
+ <extension id="exclude1" point="org.eclipse.wst.validation.exclude">
+ <validator
+ id="org.eclipse.wst.common.tests.validation.T1A">
+ <exclude>
+ <rules>
+ <projectNature
+ id="org.eclipse.jst.j2ee.ModuleCoreNature">
+ </projectNature>
+ </rules>
+ </exclude>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T4A" name="T4A">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T4A" manual="false">
+ <include>
+ <rules>
+ <fileext ext="test1"></fileext>
+ <facet id="java" version="1.5"/>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T4B" name="T4B">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T4B" manual="false">
+ <include>
+ <rules>
+ <fileext ext="test1"></fileext>
+ <facet id="java" version="1.6"/>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T5A" name="T5A">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T5A" manual="false">
+ <include>
+ <rules>
+ <pattern regex=".*/second/third/.*"></pattern>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T5B" name="T5B">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T5B" manual="false">
+ <include>
+ <rules>
+ <pattern regex=".*/secondx/third/.*"></pattern>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T5C" name="T5C">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T5C" manual="false">
+ <include>
+ <rules>
+ <fileext ext="test1"></fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension id="exclude2" point="org.eclipse.wst.validation.exclude">
+ <validator id="org.eclipse.wst.common.tests.validation.T5C">
+ <exclude>
+ <rules>
+ <pattern regex=".*/second/third/.*"></pattern>
+ </rules>
+ </exclude>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T6A" name="T6A">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T6A">
+ <include>
+ <rules>
+ <fileext ext="t6a"></fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <extension point="org.eclipse.wst.validation.validatorV2" id="T7A" name="T7A">
+ <validator build="false" class="org.eclipse.wst.validation.tests.T7A">
+ <include>
+ <rules>
+ <fileext ext="t7a"></fileext>
+ </rules>
+ </include>
+ </validator>
+ </extension>
+
+ <!-- New Test Validator to test exclude/include target runtime rule -->
+ <extension
+ id="TargetRuntimeValidator"
+ name="J2EE Test"
+ point="org.eclipse.wst.validation.validatorV2">
+ <validator
+ class="org.eclipse.wst.validation.tests.TestValidator">
+ <include>
+ <rules>
+ <facet id="java" version="1.5"/>
+ </rules>
+ </include>
+ <exclude>
+ <rules>
+ <targetRuntime id="JBoss v5.0"/>
+ </rules>
+ </exclude>
+ </validator>
+ </extension>
+</plugin>
diff --git a/tests/org.eclipse.wst.common.tests.validation/pom.xml b/tests/org.eclipse.wst.common.tests.validation/pom.xml
new file mode 100644
index 0000000..8ff1202
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2012, 2014 Eclipse Foundation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Distribution License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/org/documents/edl-v10.php
+
+ Contributors:
+ Thanh Ha (Eclipse Foundation) - initial implementation
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.webtools.common.tests</artifactId>
+ <version>3.6.0-SNAPSHOT</version>
+ <relativePath>../../</relativePath>
+ </parent>
+
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.wst.common.tests.validation</artifactId>
+ <version>1.0.400-SNAPSHOT</version>
+ <packaging>eclipse-test-plugin</packaging>
+
+ <properties>
+ <testSuite>${project.artifactId}</testSuite>
+ <testClass>org.eclipse.wst.validation.tests.testcase.ValidationTestSuite</testClass>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <version>${tycho.version}</version>
+ <configuration>
+ <dependencies>
+ <dependency>
+ <type>p2-installable-unit</type>
+ <groupId>org.eclipse.webtools.common</groupId>
+ <artifactId>org.eclipse.jst.common.project.facet.core</artifactId>
+ </dependency>
+ </dependencies>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/common/tests/validation/Activator.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/common/tests/validation/Activator.java
new file mode 100644
index 0000000..5a0e0c4
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/common/tests/validation/Activator.java
@@ -0,0 +1,73 @@
+package org.eclipse.wst.common.tests.validation;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.wst.common.tests.validation";
+
+ // The shared instance
+ private static Activator plugin;
+
+ private BundleContext _context;
+
+ public BundleContext getContext() {
+ return _context;
+ }
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ _context = context;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Write this exception to the log.
+ * <p>
+ * We are in the transition of moving to a new approach for localized messages. This is the new
+ * approach for exceptions.
+ *
+ * @param e the throwable, this can be null in which case it is a nop.
+ */
+ public void handleException(Throwable e){
+ if (e == null)return;
+ Status status = new Status(IStatus.ERROR, PLUGIN_ID, e.getLocalizedMessage(), e);
+ getLog().log(status);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/FileNames.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/FileNames.java
new file mode 100644
index 0000000..af06105
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/FileNames.java
@@ -0,0 +1,13 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+/**
+ * Store file names in a single place so that they are easy to find.
+ * @author karasiuk
+ *
+ */
+public interface FileNames {
+ String disabled = "disabled";
+
+ String firstTest2x = "first.test2x";
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestEnvironment.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestEnvironment.java
new file mode 100644
index 0000000..aaeaced
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestEnvironment.java
@@ -0,0 +1,222 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.IMutableValidator;
+import org.eclipse.wst.validation.MutableWorkspaceSettings;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.internal.ValConstants;
+import org.eclipse.wst.validation.internal.operations.ValidatorManager;
+
+public class TestEnvironment {
+
+ public static final boolean DEBUG = true;
+
+ private IWorkspace _workspace;
+ private HashMap<String, IProject> _projects = new HashMap<String, IProject>(20);
+
+ public TestEnvironment() throws CoreException {
+ _workspace = ResourcesPlugin.getWorkspace();
+ if (DEBUG){
+ _workspace.getRoot().delete(true, true, null);
+ }
+ }
+
+ public IPath addFolder(IPath root, String folderName) throws CoreException {
+ IPath path = root.append(folderName);
+ createFolder(path);
+ return path;
+ }
+
+ public void incrementalBuild() throws CoreException{
+ getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
+ }
+
+ /**
+ * Run an incremental build and wait for it to finish.
+ * @param monitor
+ * @throws CoreException
+ */
+ public void incrementalBuildAndWait(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
+ Thread.sleep(2000);
+ ValidationFramework.getDefault().join(monitor);
+ }
+
+ /**
+ * Start a full build.
+ */
+ public void fullBuild2(IProgressMonitor monitor) throws CoreException{
+ getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, monitor);
+ }
+
+ /**
+ * Do a full build, and wait until all the validation has finished.
+ * @param monitor
+ */
+ public void fullBuild(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ fullBuild2(monitor);
+ Thread.sleep(1000);
+ ValidationFramework.getDefault().join(monitor);
+ Thread.sleep(2000); // we need to sleep here to give the "finished" job a chance to run.
+ }
+
+ /**
+ * Do a clean build, and wait until all the validation has finished.
+ * @param monitor
+ */
+ public void cleanBuild(IProgressMonitor monitor) throws CoreException, InterruptedException {
+ getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, monitor);
+ Thread.sleep(1000);
+ ValidationFramework.getDefault().join(monitor);
+ }
+
+ private IFolder createFolder(IPath path) throws CoreException {
+ if (path.segmentCount() <= 1)return null;
+
+ IFolder folder = _workspace.getRoot().getFolder(path);
+ if (!folder.exists()){
+ folder.create(true, true, null);
+ }
+ return folder;
+ }
+
+ public IProject createProject(String name) throws CoreException {
+ final IProject project = _workspace.getRoot().getProject(name);
+ IWorkspaceRunnable create = new IWorkspaceRunnable() {
+
+ public void run(IProgressMonitor monitor) throws CoreException {
+ project.create(monitor);
+ project.open(monitor);
+ ValidatorManager.addProjectBuildValidationSupport(project);
+ }
+ };
+
+ _workspace.run(create, null);
+ _projects.put(name, project);
+
+ return project;
+ }
+
+ public void dispose() throws CoreException {
+ if (DEBUG)return;
+ for (Iterator<IProject> it=_projects.values().iterator(); it.hasNext();){
+ IProject project = it.next();
+ project.delete(true, null);
+ }
+ }
+
+ public IFile addFile(IPath folder, String fileName, String contents) throws CoreException, UnsupportedEncodingException {
+ IPath filePath = folder.append(fileName);
+ return createFile(filePath, contents.getBytes("UTF8"));
+ }
+
+ private IFile createFile(IPath filePath, byte[] contents) throws CoreException {
+ IFile file = _workspace.getRoot().getFile(filePath);
+ ByteArrayInputStream in = new ByteArrayInputStream(contents);
+ if (file.exists())file.setContents(in, true, false, null);
+ else file.create(in, true, null);
+ return file;
+ }
+
+ public IWorkspace getWorkspace(){
+ return _workspace;
+ }
+
+ public IProject findProject(String name) {
+ IProject project = _workspace.getRoot().getProject(name);
+ if (project.exists())return project;
+ return null;
+ }
+
+ /**
+ * Since other plug-ins can add and remove validators, turn off all the ones that are not part of
+ * these tests.
+ *
+ * @param validatorPrefix The start of the validator class name, but without the package name. For example "T5".
+ */
+ public static void enableOnlyTheseValidators(String validatorPrefix) throws InvocationTargetException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ String name = "org.eclipse.wst.validation.tests." + validatorPrefix;
+ MutableWorkspaceSettings ws = vf.getWorkspaceSettings();
+ for (IMutableValidator v : ws.getValidators()){
+ boolean enable = v.getValidatorClassname().startsWith(name);
+ v.setBuildValidation(enable);
+ v.setManualValidation(enable);
+ }
+ vf.applyChanges(ws, true);
+ }
+
+ /**
+ * Since other plug-ins can add and remove validators, turn off all the validators except this one.
+ *
+ * @param name Fully qualified class name of the validator to turn on. For example
+ * org.eclipse.wst.validation.tests.TestValidator
+ */
+ public static void enableOnlyThisValidator(String name) throws InvocationTargetException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ MutableWorkspaceSettings ws = vf.getWorkspaceSettings();
+ for (IMutableValidator v : ws.getValidators()){
+ boolean enable = v.getValidatorClassname().equals(name);
+ v.setBuildValidation(enable);
+ v.setManualValidation(enable);
+ }
+ vf.applyChanges(ws, true);
+ }
+
+ public void turnoffAutoBuild() throws CoreException {
+ IWorkspaceDescription wd = _workspace.getDescription();
+ if (wd.isAutoBuilding()){
+ wd.setAutoBuilding(false);
+ _workspace.setDescription(wd);
+ }
+
+ }
+
+ public void turnOnAutoBuild() throws CoreException {
+ IWorkspaceDescription wd = _workspace.getDescription();
+ if (!wd.isAutoBuilding()){
+ wd.setAutoBuilding(true);
+ _workspace.setDescription(wd);
+ }
+ }
+
+ /**
+ * Answer the number of validation errors on this resource.
+ *
+ * @param resource
+ * The resource being checked.
+ * @return the number of problem markers that have the error severity.
+ */
+ public int getErrors(IResource resource) {
+ int errors = 0;
+ try {
+ IMarker[] markers = resource.findMarkers(ValConstants.ProblemMarker, false, IResource.DEPTH_ZERO);
+ for (IMarker marker : markers){
+ int severity = marker.getAttribute(IMarker.SEVERITY, -1);
+ if (severity == IMarker.SEVERITY_ERROR)errors++;
+ }
+ }
+ catch (CoreException e){
+ //eat it
+ }
+ return errors;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite1.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite1.java
new file mode 100644
index 0000000..bad6c7c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite1.java
@@ -0,0 +1,346 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.validation.IDependencyIndex;
+import org.eclipse.wst.validation.IMutableValidator;
+import org.eclipse.wst.validation.MessageSeveritySetting;
+import org.eclipse.wst.validation.MutableWorkspaceSettings;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.ValidationResults;
+import org.eclipse.wst.validation.Validator;
+import org.eclipse.wst.validation.internal.Deserializer;
+import org.eclipse.wst.validation.internal.Serializer;
+import org.eclipse.wst.validation.internal.Tracing;
+import org.eclipse.wst.validation.internal.ValConstants;
+import org.eclipse.wst.validation.internal.ValManager;
+import org.eclipse.wst.validation.tests.Misc;
+import org.eclipse.wst.validation.tests.TestValidator;
+import org.eclipse.wst.validation.tests.TestValidator2;
+import org.eclipse.wst.validation.tests.TestValidator4;
+import org.eclipse.wst.validation.tests.TestValidator5D;
+import org.eclipse.wst.validation.tests.TestValidator6;
+import org.eclipse.wst.validation.tests.TestValidator7;
+import org.eclipse.wst.validation.tests.ValCounters;
+
+public class TestSuite1 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _testProject;
+
+ private IFile _mapTest1;
+
+ public static Test suite() {
+ return new TestSuite(TestSuite1.class);
+ }
+
+ public TestSuite1(String name){
+ super(name);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ _testProject = _env.findProject("TestProject");
+ if (_testProject != null)return;
+ _env.turnoffAutoBuild();
+ enableOnlyTestValidators();
+ _testProject = _env.createProject("TestProject");
+ IPath folder = _env.addFolder(_testProject.getFullPath(), "source");
+ _env.addFile(folder, "first.test1", "include map.test1\n" +
+ "info - information\n" +
+ "warning - warning\n" +
+ "error - error\n\n" +
+ "t1error - extra error\n" +
+ "t1warning - extra warning");
+ _env.addFile(folder, "second.test1", "info - information\n" +
+ "warning - warning\n" +
+ "error - error\n\n" +
+ "t1error - extra error\n" +
+ "t1warning - extra warning");
+ _mapTest1 = _env.addFile(folder, "map.test1",
+ "# will hold future mappings\n\n" +
+ "# syntax: map target replacement\n" +
+ "# for example map t1error error - would replace all t1error tokens with error");
+ _env.addFile(folder, "first.test2", "# sample file");
+ _env.addFile(folder, "third.test4",
+ "# Doesn't really matter\n" +
+ "# We just want to make the build a bit slower.");
+ _env.addFile(folder, "fourth.test4", "# Doesn't really matter");
+ _env.addFile(folder, "fifth.test5", "# Doesn't really matter");
+ _env.addFile(folder, "forFun.xml", "<fun>times</fun>");
+
+ _env.addFile(_testProject.getFullPath(), "file.specific", "# This should be validated by Test2");
+ _env.addFile(folder, "file.specific", "# This should be validated by Test2");
+
+ _env.addFile(_testProject.getFullPath(), "full.specific", "# This should not be validated by Test2");
+ _env.addFile(folder, "full.specific", "# This should be validated by Test2");
+ }
+
+ /**
+ * Since other plug-ins can add and remove validators, turn off all the ones that are not part of
+ * these tests.
+ */
+ private static void enableOnlyTestValidators() throws InvocationTargetException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ MutableWorkspaceSettings ws = vf.getWorkspaceSettings();
+ for (IMutableValidator v : ws.getValidators()){
+ boolean enable = v.getValidatorClassname().startsWith("org.eclipse.wst.validation.tests.Test");
+ v.setBuildValidation(enable);
+ v.setManualValidation(enable);
+ }
+ vf.applyChanges(ws, true);
+ }
+
+ protected void tearDown() throws Exception {
+ _env.dispose();
+ super.tearDown();
+ }
+
+ public void testIndex(){
+ ValidationFramework vf = ValidationFramework.getDefault();
+ IDependencyIndex index = vf.getDependencyIndex();
+ assertNotNull(index);
+ }
+
+ public void testIndex2() throws CoreException, InterruptedException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ IDependencyIndex index = vf.getDependencyIndex();
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+
+ IResource r = root.findMember("TestProject/source/map.test1");
+ IProject p = r.getProject();
+ p.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ ValidationFramework.getDefault().join(null);
+
+ r = root.findMember("TestProject/source/first.test1");
+ assertFalse(index.isDependedOn(r));
+ }
+
+ public void testGetValidators(){
+ ValidationFramework vf = ValidationFramework.getDefault();
+ IResource resource = _env.getWorkspace().getRoot().findMember("TestProject/source/first.test1");
+ Validator[] validators = vf.getValidatorsFor(resource, false, false);
+ assertTrue(validators.length > 0);
+
+ String id = TestValidator.id();
+ int count = 0;
+ for (int i =0; i<validators.length; i++){
+ if (validators[i].getId().equals(id))count++;
+ }
+ assertEquals(1, count);
+ }
+
+ public void testTest1() throws CoreException, UnsupportedEncodingException, InterruptedException {
+ Tracing.log("TestSuite-02: testTest1 starting");
+ IProgressMonitor monitor = new NullProgressMonitor();
+ ValidationFramework vf = ValidationFramework.getDefault();
+ IProject[] projects = {_testProject};
+ /*
+ * After the validation we expect first.test1 to have 1 error, 1 warning and 1 info. And for
+ * second.test1 to have 1 error, 1 warning and 1 info.
+ */
+ ValidationResults vr = vf.validate(projects, true, false, monitor);
+
+ IResource resource = _env.getWorkspace().getRoot().findMember("TestProject/source/first.test1");
+ checkFirstPass(resource, vr);
+
+ // add a first build so that we know that only the map file has changed
+ _env.incrementalBuild();
+ Thread.sleep(2000);
+ vf.join(monitor);
+
+ ByteArrayInputStream in = new ByteArrayInputStream("map t1error error\nmap t1warning warning".getBytes());
+ _mapTest1.setContents(in, true, true, monitor);
+
+ Thread.sleep(2000); // we need to sleep here to give the "finished" job a chance to run.
+ TestValidator4.getCounters().reset();
+ TestValidator5D.getCounters().reset();
+ _env.incrementalBuild();
+ Thread.sleep(2000);
+ vf.join(monitor);
+
+ ValCounters vc = TestValidator4.getCounters();
+ Tracing.log("TestSuite-03: testTest1: " + vc.toString());
+ assertEquals(vc.startingCount, vc.finishedCount);
+ assertEquals(vc.startingProjectCount, vc.finishedProjectCount);
+ assertEquals(vc.startingCount, 1);
+ assertEquals(vc.finishedCount, 1);
+
+ vc = TestValidator5D.getCounters();
+ assertEquals(vc.startingCount, vc.finishedCount);
+ assertEquals(vc.startingProjectCount, vc.finishedProjectCount);
+ assertEquals(vc.startingCount, 1);
+ assertEquals(vc.finishedCount, 1);
+
+ assertTrue("We expect the delegating validator Test5D to be called at least once",
+ TestValidator5D.getCalledCount()>0);
+
+ checkSecondPass(resource);
+ Tracing.log("TestSuite-04:testTest1 finished");
+ }
+
+ public void testTest2() {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ IResource test2 = _testProject.findMember("source/first.test2");
+ assertNotNull(test2);
+ Validator[] vals = vf.getValidatorsFor(test2, true, true);
+ for (Validator v : vals){
+ String id = v.getId();
+ if (id.equals(TestValidator.id()))fail("first.test2 should not be validated by the test1 validator");
+ }
+
+ IResource test1 = _testProject.findMember("source/first.test1");
+ assertNotNull(test1);
+ vals = vf.getValidatorsFor(test1, true, true);
+ boolean found = false;
+ for (Validator v : vals){
+ String id = v.getId();
+ if (id.equals(TestValidator.id()))found = true;
+ }
+ assertTrue(found);
+ }
+
+ /**
+ * Count the number of test validators.
+ */
+ public void testCountValidators(){
+ int count = 0;
+ for (Validator v : ValManager.getDefault().getValidators()){
+ int i = v.getId().indexOf(".Test");
+ if (i != -1)count++;
+ }
+ assertEquals("Expected number of Test validators", 8, count);
+ }
+
+ /**
+ * Test if we can get a message that was defined through the extension point.
+ */
+ public void testMessages() {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ Validator v = vf.getValidator(TestValidator2.id(), null);
+ assertNotNull("We expected to find TestValidator2", v);
+ MessageSeveritySetting ms = v.getMessage("bad");
+ assertNotNull("We expected to find a message for 'bad'", ms);
+ assertEquals(MessageSeveritySetting.Severity.Error, ms.getCurrent());
+ assertEquals(4, v.getMessageSettings().size());
+ }
+
+ public void testSerialize(){
+ Serializer s = new Serializer(20);
+ s.put(true);
+ s.put(false);
+ s.put("Hi there");
+ s.put(25);
+ String test = s.toString();
+
+ Deserializer d = new Deserializer(test);
+ assertTrue(d.getBoolean());
+ assertFalse(d.getBoolean());
+ assertEquals("Hi there", d.getString());
+ assertTrue(d.hasNext());
+ assertEquals(25, d.getInt());
+ assertFalse(d.hasNext());
+ }
+
+ public void testSuspend() throws CoreException, InterruptedException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ Validator v = vf.getValidator(TestValidator6.id(), null);
+ TestValidator6 t6 = (TestValidator6)v.asV2Validator().getValidator();
+
+ v = vf.getValidator(TestValidator7.id(), null);
+ TestValidator7 t7 = (TestValidator7)v.asV2Validator().getValidator();
+ t7.reset();
+
+ long start = System.currentTimeMillis();
+ _env.fullBuild2(null);
+ Thread.sleep(1000);
+ vf.join(null);
+ long first = System.currentTimeMillis();
+ long valBuild = first-start;
+ assertTrue("We expect the build to take longer than 3s, but it completed in " + valBuild + "ms", valBuild > 3000);
+
+ IResource projectFile = _testProject.findMember(".project");
+ assertFalse("We should not be validating the .product file", t6.getSet().contains(projectFile));
+
+ assertEquals("We expected the validation to be suspended after the first call", 1, t7.getSet().size());
+
+ vf.suspendAllValidation(true);
+ _env.fullBuild2(null);
+ Thread.sleep(1000);
+ vf.join(null);
+ long second = System.currentTimeMillis();
+ vf.suspendAllValidation(false);
+ long novalBuild = second - first;
+ assertTrue("We except the build to go faster with validation turned off, but it was " + (novalBuild-valBuild) +
+ " ms faster" , novalBuild < valBuild);
+ assertEquals("We expected the validation to be suspended after the first call", 1, t7.getSet().size());
+
+ }
+
+ private void checkFirstPass(IResource resource, ValidationResults vr) throws CoreException {
+ assertEquals("Expected number of error messages", 5, vr.getSeverityError());
+ assertEquals("Expected number of warning messages", 2, vr.getSeverityWarning());
+ assertEquals("Expected number of info messages", 2, vr.getSeverityInfo());
+
+ assertEquals("Expected number of messages", 9, vr.getMessages().length);
+
+ IMarker[] markers = resource.findMarkers(ValConstants.ProblemMarker, false, IResource.DEPTH_ZERO);
+ int errors =0, warnings=0, info=0;
+ for (IMarker marker : markers){
+ int severity = marker.getAttribute(IMarker.SEVERITY, -1);
+ switch (severity){
+ case IMarker.SEVERITY_ERROR: errors++;
+ break;
+ case IMarker.SEVERITY_WARNING: warnings++;
+ break;
+ case IMarker.SEVERITY_INFO: info++;
+ break;
+ }
+ }
+ assertTrue("We expect there to be exactly one error message, but errors=" + errors, errors == 1);
+ assertTrue("We expect there to be exactly one warning message, but warnings="+warnings, warnings == 1);
+ assertTrue("We expect there to be exactly one info message, but info="+info, info == 1);
+ }
+
+ private void checkSecondPass(IResource resource) throws CoreException {
+ IMarker[] markers = resource.findMarkers(ValConstants.ProblemMarker, false, IResource.DEPTH_ZERO);
+ int errors =0, warnings=0, info=0;
+ for (int i=0; i<markers.length; i++){
+ int severity = markers[i].getAttribute(IMarker.SEVERITY, -1);
+ switch (severity){
+ case IMarker.SEVERITY_ERROR: errors++;
+ break;
+ case IMarker.SEVERITY_WARNING: warnings++;
+ break;
+ case IMarker.SEVERITY_INFO: info++;
+ break;
+ }
+ }
+ if (Tracing.isLogging()){
+ Tracing.log("TestSuite-01: checkSecondPass: " + Misc.listMarkers(resource));
+ }
+ assertTrue("We expect there to be exactly two error messages, but errors=" + errors, errors == 2);
+ assertTrue("We expect there to be exactly two warning messages, but warnings="+warnings, warnings == 2);
+ assertTrue("We expect there to be exactly one info message, but info="+info, info == 1);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite10.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite10.java
new file mode 100644
index 0000000..d0d4405
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite10.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.UnsupportedEncodingException;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.validation.internal.model.FilterRule;
+
+/** Test the new target runtime filter rule. Can be used for new filter rules in general*/
+@SuppressWarnings("restriction")
+public class TestSuite10 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _project;
+
+ private static final String TARGET_RUNTIME_VALIDATOR_ID = "org.eclipse.wst.common.tests.validation.TargetRuntimeValidator"; //$NON-NLS-1$
+ private static final String TARGET_RUNTIME = "targetRuntime"; //$NON-NLS-1$
+ private static final String RULES = "rules"; //$NON-NLS-1$
+ private static final String ID = "id"; //$NON-NLS-1$
+
+ public static Test suite() {
+ return new TestSuite(TestSuite10.class);
+ }
+
+ public TestSuite10(String name){
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ _project = _env.createProject("TestSuite10");
+
+ TestEnvironment.enableOnlyTheseValidators("T10");
+ }
+
+ protected void tearDown() throws Exception {
+ _project.delete(true, null);
+ _env.dispose();
+ super.tearDown();
+ }
+
+ /**
+ * Ensure the target runtime rule is working.
+ * @throws Exception
+ */
+
+ public void testTargetRuntimeFilterRule() throws CoreException, UnsupportedEncodingException, InterruptedException {
+
+ String ruleName = null;
+ String ruleID = null;
+
+ IConfigurationElement[] children = getIncludesAndExcludes(TARGET_RUNTIME_VALIDATOR_ID);
+ for (IConfigurationElement child : children) {
+ IConfigurationElement[] rules = child.getChildren(RULES);
+ for (int i=0; i<rules.length; i++){
+ IConfigurationElement[] r = rules[i].getChildren();
+ for(int j=0; j<r.length; j++){
+ IConfigurationElement rule = r[j];
+ ruleName = rule.getName();
+
+ if(ruleName.equals(TARGET_RUNTIME)) {
+ FilterRule filterRule = FilterRule.create(rule);
+ assertNotNull(filterRule);
+ ruleID = rule.getAttribute(ID);
+ assertNotNull(ruleName);
+ assertNotNull(ruleID);
+ }
+ }
+ }
+ }
+ }
+
+ private IConfigurationElement[] getIncludesAndExcludes(String validatorID){
+
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.wst.validation", "validatorV2");
+
+ for (IExtension ext : extensionPoint.getExtensions()){
+ for (IConfigurationElement validator : ext.getConfigurationElements()){
+ String id = ext.getUniqueIdentifier();
+ if(id.equals(validatorID)) {
+ return validator.getChildren();
+ }
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite2.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite2.java
new file mode 100644
index 0000000..8f5b29c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite2.java
@@ -0,0 +1,192 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.validation.IMutableValidator;
+import org.eclipse.wst.validation.MutableWorkspaceSettings;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.internal.ValConstants;
+import org.eclipse.wst.validation.tests.T1B;
+import org.eclipse.wst.validation.tests.T1Group;
+import org.osgi.framework.Bundle;
+
+public class TestSuite2 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _testProject;
+
+ private IFile _firstTest1;
+ private IFile _secondTest1;
+ private IFile _firstT1B;
+
+ private IFile _firstTest2x;
+
+ private IFile _firstT1C;
+
+ public static Test suite() {
+ return new TestSuite(TestSuite2.class);
+ }
+
+ public TestSuite2(String name){
+ super(name);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ _testProject = _env.findProject("TestProject");
+ if (_testProject != null)return;
+ _env.turnoffAutoBuild();
+ adjustEnabledValidators();
+ _testProject = _env.createProject("TestProject");
+ IPath folder = _env.addFolder(_testProject.getFullPath(), "source");
+ _firstTest1 = _env.addFile(folder, "first.test1", "include map.test1\ninfo - information\nwarning - warning\nerror - error\n\n" +
+ "t1error - extra error\nt1warning - extra warning");
+ _secondTest1 = _env.addFile(folder, "second.test1", "info - information\nwarning - warning\nerror - error\n\n" +
+ "t1error - extra error\nt1warning - extra warning");
+ _firstT1B = _env.addFile(folder, "first.t1b", "include map.test1\ninfo - information\nwarning - warning\nerror - error\n\n" +
+ "t1error - extra error\nt1warning - extra warning");
+
+ _env.addFile(folder, "map.test1", "# will hold future mappings");
+ _env.addFile(folder, "first.test2", "# sample file");
+ _firstTest2x = _env.addFile(folder, FileNames.firstTest2x, "# a file that will be validated as a side effect of running the T1A validator");
+ _env.addFile(folder, "third.test4", "# Doesn't really matter\nWe just want to make the build a bit slower.");
+ _env.addFile(folder, "fourth.test4", "# Doesn't really matter");
+ _env.addFile(folder, "fifth.test5", "# Doesn't really matter");
+
+ IPath ignore = _env.addFolder(_testProject.getFullPath(), "ignore");
+ IPath nested = _env.addFolder(ignore, "nested");
+ _firstT1C = _env.addFile(nested, "first.t1c", "error - error");
+
+ }
+
+ /**
+ * Since other plug-ins can add and remove validators, turn off all the ones that are not part of
+ * these tests.
+ */
+ private static void adjustEnabledValidators() throws InvocationTargetException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ MutableWorkspaceSettings ws = vf.getWorkspaceSettings();
+ for (IMutableValidator v : ws.getValidators()){
+ boolean enable = v.getValidatorClassname().startsWith("org.eclipse.wst.validation.tests.T1");
+ v.setBuildValidation(enable);
+ v.setManualValidation(enable);
+ }
+ vf.applyChanges(ws, true);
+ }
+
+ protected void tearDown() throws Exception {
+ _env.dispose();
+ super.tearDown();
+ }
+
+ public void testFullBuild() throws CoreException, InterruptedException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+// Listener listener = new Listener(_firstTest2x);
+// IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ try {
+// workspace.addResourceChangeListener(listener);
+ IProgressMonitor monitor = new NullProgressMonitor();
+ _env.fullBuild2(monitor);
+
+ vf.join(monitor);
+ Thread.sleep(1000);
+
+ T1Group.getGroup().reset();
+ _env.turnOnAutoBuild();
+
+
+ _firstTest1.touch(monitor);
+ Thread.sleep(50);
+ _secondTest1.touch(monitor);
+ vf.join(monitor);
+ Thread.sleep(1000);
+
+ checkClear();
+ checkT1B();
+ checkGuardValidators();
+
+ checkT1C();
+ checkGroup();
+ }
+ finally {
+// workspace.removeResourceChangeListener(listener);
+ }
+ }
+
+ private void checkGroup() {
+ T1Group group = T1Group.getGroup();
+ assertNotNull("The validation group listener T1Group was never created", group);
+ assertEquals("The starting count must equal the finishing count", group.getStarting(), group.getFinishing());
+ assertEquals("Number of times the group should be signalled", 2, group.getStarting());
+ }
+
+ private void checkT1B() throws CoreException {
+ IMarker[] markers = _firstT1B.findMarkers(T1B.MarkerId, false, IResource.DEPTH_ZERO);
+ assertEquals("Number of T1B markers", 3, markers.length);
+ }
+
+ private void checkT1C() throws CoreException {
+ IMarker[] markers = _firstT1C.findMarkers(null, false, IResource.DEPTH_ZERO);
+ assertEquals("Number of T1C markers", 0, markers.length);
+ }
+
+ /**
+ * Check if the clear function worked.
+ */
+ private void checkClear() throws CoreException {
+ IMarker[] markers = _firstTest2x.findMarkers(ValConstants.ProblemMarker, false, IResource.DEPTH_ZERO);
+ assertEquals(1, markers.length);
+ }
+
+ private void checkGuardValidators(){
+ Bundle b = Platform.getBundle("org.eclipse.wst.common.tests.validation.guard");
+ if (b != null){
+ int state = b.getState();
+ if (state == Bundle.ACTIVE){
+ fail("The guard plug-in should never be activated.");
+ }
+ }
+ }
+
+ public static class Listener implements IResourceChangeListener {
+
+ private IResource _interested;
+
+ public Listener(IResource resource){
+ _interested = resource;
+ }
+
+ public void resourceChanged(IResourceChangeEvent event) {
+ IMarkerDelta[] markers = event.findMarkerDeltas(ValConstants.ProblemMarker, false);
+ for (IMarkerDelta marker : markers){
+ IResource resource = marker.getResource();
+ if (_interested.equals(resource)){
+ // added=1, removed=2, changed=4
+// int kind = marker.getKind();
+// Map map = marker.getAttributes();
+// int len = map.size();
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite3.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite3.java
new file mode 100644
index 0000000..d78ca12
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite3.java
@@ -0,0 +1,129 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.validation.IMutableValidator;
+import org.eclipse.wst.validation.MutableWorkspaceSettings;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.internal.Tracing;
+
+public class TestSuite3 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _testProject;
+
+ private IResource _folder;
+ private IFile _firstTest1;
+
+ public static Test suite() {
+ return new TestSuite(TestSuite3.class);
+ }
+
+ public TestSuite3(String name){
+ super(name);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ _testProject = _env.findProject("TestProject");
+ if (_testProject != null)return;
+ _env.turnoffAutoBuild();
+ enableOnlyTestValidators();
+ _testProject = _env.createProject("TestProject");
+ IPath folder = _env.addFolder(_testProject.getFullPath(), "source");
+ ResourcesPlugin.getWorkspace().getRoot().findMember(folder);
+ _env.addFile(folder, "first.test1", "include map.test1\n" +
+ "info - information\n" +
+ "warning - warning\n" +
+ "error - error\n\n" +
+ "t1error - extra error\n" +
+ "t1warning - extra warning");
+ _env.addFile(folder, "second.test1", "info - information\n" +
+ "warning - warning\n" +
+ "error - error\n\n" +
+ "t1error - extra error\n" +
+ "t1warning - extra warning");
+ _env.addFile(folder, "map.test1",
+ "# will hold future mappings\n\n" +
+ "# syntax: map target replacement\n" +
+ "# for example map t1error error - would replace all t1error tokens with error");
+ _env.addFile(folder, "first.test2", "# sample file");
+ _env.addFile(folder, "third.test4",
+ "# Doesn't really matter\n" +
+ "# We just want to make the build a bit slower.");
+ _env.addFile(folder, "fourth.test4", "# Doesn't really matter");
+ _env.addFile(folder, "fifth.test5", "# Doesn't really matter");
+
+ folder = _env.addFolder(_testProject.getFullPath(), FileNames.disabled);
+ _folder = ResourcesPlugin.getWorkspace().getRoot().findMember(folder);
+ _firstTest1 = _env.addFile(folder, "first.test1", "include map.test1\n" +
+ "info - information\n" +
+ "warning - warning\n" +
+ "error - error\n\n" +
+ "t1error - extra error\n" +
+ "t1warning - extra warning");
+
+ }
+
+ /**
+ * Since other plug-ins can add and remove validators, turn off all the ones that are not part of
+ * these tests.
+ */
+ private static void enableOnlyTestValidators() throws InvocationTargetException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ MutableWorkspaceSettings ws = vf.getWorkspaceSettings();
+ for (IMutableValidator v : ws.getValidators()){
+ boolean enable = v.getValidatorClassname().startsWith("org.eclipse.wst.validation.tests.Test");
+ v.setBuildValidation(enable);
+ v.setManualValidation(enable);
+ }
+ vf.applyChanges(ws, true);
+ }
+
+ protected void tearDown() throws Exception {
+ _env.dispose();
+ super.tearDown();
+ }
+
+ public void testTest1() throws CoreException, UnsupportedEncodingException, InterruptedException {
+ Tracing.log("TestSuite3-01: testTest1 starting");
+ IProgressMonitor monitor = new NullProgressMonitor();
+ ValidationFramework vf = ValidationFramework.getDefault();
+
+ vf.disableValidation(_folder);
+ _env.fullBuild(monitor);
+ IMarker[] markers = _firstTest1.findMarkers(null, true, IResource.DEPTH_ZERO);
+ assertEquals("The file should not have been validated.", 0, markers.length);
+
+ vf.enableValidation(_folder);
+ _env.fullBuild(monitor);
+ markers = _firstTest1.findMarkers(null, true, IResource.DEPTH_ZERO);
+ assertTrue("The file should have some markers", markers.length > 0);
+
+ vf.disableValidation(_folder);
+ _env.fullBuild(monitor);
+ markers = _firstTest1.findMarkers(null, true, IResource.DEPTH_ZERO);
+ assertEquals("The file should not have been validated.", 0, markers.length);
+
+ Tracing.log("TestSuite3-02:testTest1 finished");
+ }
+
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite4.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite4.java
new file mode 100644
index 0000000..3eec122
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite4.java
@@ -0,0 +1,109 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
+import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy;
+import org.eclipse.wst.common.project.facet.core.IProjectFacet;
+import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
+import org.eclipse.wst.validation.IMutableValidator;
+import org.eclipse.wst.validation.MutableWorkspaceSettings;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.ValidationResults;
+import org.eclipse.wst.validation.internal.Tracing;
+
+public class TestSuite4 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _project;
+
+ public static Test suite() {
+ return new TestSuite(TestSuite4.class);
+ }
+
+ public TestSuite4(String name){
+ super(name);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ IFacetedProjectWorkingCopy project = FacetedProjectFramework.createNewProject();
+ project.setProjectName("FacetProject");
+ IProjectFacet pf = ProjectFacetsManager.getProjectFacet("java");
+ IProjectFacetVersion ipv = pf.getVersion("1.5");
+ Set<IProjectFacetVersion> set = new HashSet<IProjectFacetVersion>(1);
+ set.add(ipv);
+ project.setProjectFacets(set);
+ project.commitChanges(null);
+ _project = project.getProject();
+
+ IPath folder = _env.addFolder(_project.getFullPath(), "source");
+ ResourcesPlugin.getWorkspace().getRoot().findMember(folder);
+ _env.addFile(folder, "first.test1",
+ "info - information\n" +
+ "warning - warning\n" +
+ "error - error\n\n" +
+ "t1error - extra error\n" +
+ "t1warning - extra warning");
+
+ enableOnlyT4Validators();
+ }
+
+ /**
+ * Since other plug-ins can add and remove validators, turn off all the ones that are not part of
+ * these tests.
+ */
+ private static void enableOnlyT4Validators() throws InvocationTargetException {
+ ValidationFramework vf = ValidationFramework.getDefault();
+ MutableWorkspaceSettings ws = vf.getWorkspaceSettings();
+ for (IMutableValidator v : ws.getValidators()){
+ boolean enable = v.getValidatorClassname().startsWith("org.eclipse.wst.validation.tests.T4");
+ v.setBuildValidation(enable);
+ v.setManualValidation(enable);
+ }
+ vf.applyChanges(ws, true);
+ }
+
+ protected void tearDown() throws Exception {
+ _project.delete(true, null);
+ _env.dispose();
+ super.tearDown();
+ }
+
+ /**
+ * Ensure that the facet version expressions are working. We define two validators T4A and T4B. The first one operates on Java 5
+ * and the second on Java 6. Since we have created a project that has been set to Java 5, we only expect the T4A validator
+ * to be called.
+ */
+ public void testFacetVersions() throws CoreException, UnsupportedEncodingException, InterruptedException {
+ Tracing.log("TestSuite4-01: testFacetVersions starting");
+ IProgressMonitor monitor = new NullProgressMonitor();
+ ValidationFramework vf = ValidationFramework.getDefault();
+ IProject[] projects = new IProject[1];
+ projects[0] = _project;
+ ValidationResults vr = vf.validate(projects, true, false, monitor);
+ int errors = vr.getSeverityError();
+ assertEquals("Number of errors", 1, errors);
+
+ Tracing.log("TestSuite4-02:testFacetVersions finished");
+ }
+
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite5.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite5.java
new file mode 100644
index 0000000..4d45b47
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite5.java
@@ -0,0 +1,75 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.ValidationResults;
+import org.eclipse.wst.validation.internal.Tracing;
+
+/** Test the new pattern rule. */
+public class TestSuite5 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _project;
+
+ public static Test suite() {
+ return new TestSuite(TestSuite5.class);
+ }
+
+ public TestSuite5(String name){
+ super(name);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ _project = _env.createProject("TestSuite5");
+
+ IPath first = _env.addFolder(_project.getFullPath(), "first");
+ IPath second = _env.addFolder(first, "second");
+ IPath third = _env.addFolder(second, "third");
+ _env.addFile(third, "sample.test1",
+ "info - information\n" +
+ "warning - warning\n" +
+ "error - error\n\n" +
+ "t1error - extra error\n" +
+ "t1warning - extra warning");
+
+ TestEnvironment.enableOnlyTheseValidators("T5");
+ }
+
+ protected void tearDown() throws Exception {
+ _project.delete(true, null);
+ _env.dispose();
+ super.tearDown();
+ }
+
+ /**
+ * Ensure that the pattern filters are working.
+ */
+ public void testPatterns() throws CoreException, UnsupportedEncodingException, InterruptedException {
+ Tracing.log("TestSuite5-01: testFacetVersions starting");
+ IProgressMonitor monitor = new NullProgressMonitor();
+ ValidationFramework vf = ValidationFramework.getDefault();
+ IProject[] projects = new IProject[1];
+ projects[0] = _project;
+ ValidationResults vr = vf.validate(projects, true, false, monitor);
+ int errors = vr.getSeverityError();
+ assertEquals("Number of errors", 1, errors);
+
+ Tracing.log("TestSuite5-02:testFacetVersions finished");
+ }
+
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite6.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite6.java
new file mode 100644
index 0000000..ccdd829
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite6.java
@@ -0,0 +1,76 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.validation.internal.Tracing;
+import org.eclipse.wst.validation.tests.T6A;
+
+/** Test what happens when a dependent resource is deleted. */
+public class TestSuite6 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _project;
+ private IFile _sample;
+ private IFile _master;
+
+ public static Test suite() {
+ return new TestSuite(TestSuite6.class);
+ }
+
+ public TestSuite6(String name){
+ super(name);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ _env.turnoffAutoBuild();
+ _project = _env.createProject("TestSuite6");
+
+ IPath first = _env.addFolder(_project.getFullPath(), "first");
+ _sample = _env.addFile(first, "sample.t6a", "include master.t6a");
+ _master = _env.addFile(first, "master.t6a", "# a dummy file");
+
+ TestEnvironment.enableOnlyThisValidator("org.eclipse.wst.validation.tests.T6A");
+ }
+
+ protected void tearDown() throws Exception {
+ _project.delete(true, null);
+ _env.dispose();
+ super.tearDown();
+ }
+
+ /**
+ * Ensure that the validator gets called when a dependent resource is deleted.
+ */
+ public void testDelete() throws CoreException, UnsupportedEncodingException, InterruptedException {
+ Tracing.log("TestSuite6-01: testDelete starting");
+ IProgressMonitor monitor = new NullProgressMonitor();
+ T6A.resetCounters();
+
+ _env.incrementalBuildAndWait(monitor);
+ assertEquals("We do not expect any errors by this point", 0, _env.getErrors(_sample));
+
+ _master.delete(true, monitor);
+ _env.incrementalBuildAndWait(monitor);
+ assertEquals("The missing depenency should have been reported.", 1, _env.getErrors(_sample));
+ assertEquals("The simple version of the validate method should never be called", 0, T6A.getCountSimple());
+ assertTrue("The complex method must be called at least once", T6A.getCountComplex() > 0);
+
+ Tracing.log("TestSuite6-02:testDelete finished");
+ }
+
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite7.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite7.java
new file mode 100644
index 0000000..892350e
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite7.java
@@ -0,0 +1,94 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.validation.internal.Tracing;
+import org.eclipse.wst.validation.tests.T7A;
+import org.eclipse.wst.validation.tests.T7A.ValEntryPoint;
+
+/** Test the order of validation events. */
+public class TestSuite7 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _projectA;
+ private IProject _projectB;
+
+ public static Test suite() {
+ return new TestSuite(TestSuite7.class);
+ }
+
+ public TestSuite7(String name){
+ super(name);
+ }
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ TestEnvironment.enableOnlyThisValidator("org.eclipse.wst.validation.tests.T7A");
+ _env = new TestEnvironment();
+ _projectA = _env.createProject("TestSuite7a");
+ _projectB = _env.createProject("TestSuite7b");
+ makeFiles(_projectA);
+ makeFiles(_projectB);
+
+ }
+
+ private void makeFiles(IProject project) throws Exception{
+ IPath first = _env.addFolder(project.getFullPath(), "some-folder");
+ _env.addFile(first, "first.t7a", "# a dummy file");
+ _env.addFile(first, "second.t7a", "# a dummy file");
+
+ }
+
+ protected void tearDown() throws Exception {
+ _projectA.delete(true, null);
+ _projectB.delete(true, null);
+ _env.dispose();
+ super.tearDown();
+ }
+
+ /**
+ * Test the order of a clean build.
+ */
+ public void testClean() throws CoreException, UnsupportedEncodingException, InterruptedException {
+ Tracing.log("TestSuite7-01: testClean starting");
+ IProgressMonitor monitor = new NullProgressMonitor();
+ _env.turnOnAutoBuild();
+ _env.cleanBuild(monitor);
+ T7A.resetList();
+
+ _env.cleanBuild(monitor);
+ ValEntryPoint[] array = T7A.getArray();
+ int start = 0;
+ int finish = 0;
+ for (ValEntryPoint vep : array){
+ switch (vep.getType()){
+ case Starting:
+ if (start == 0)assertNull("First starting entry must be null", vep.getResource());
+ start++;
+ break;
+ case Finishing:
+ finish++;
+ break;
+ case Normal:
+ assertEquals("All normal validation events must be two levels deep", 2, start-finish);
+ }
+ }
+ assertEquals("Starting must equal finishing", start, finish);
+ assertNull("Last entry must be null", array[array.length-1].getResource());
+
+ Tracing.log("TestSuite7-02:testClean finished");
+ }
+
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite8.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite8.java
new file mode 100644
index 0000000..6f3993b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite8.java
@@ -0,0 +1,160 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.validation.IMutableValidator;
+import org.eclipse.wst.validation.MutableProjectSettings;
+import org.eclipse.wst.validation.MutableWorkspaceSettings;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.ValidationResults;
+import org.eclipse.wst.validation.internal.Tracing;
+import org.eclipse.wst.validation.internal.plugin.ValidationPlugin;
+import org.osgi.framework.Bundle;
+
+/**
+ * Test the transient settings support. That is the ability to change validator settings without changing
+ * the property files.
+ */
+public class TestSuite8 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _project;
+
+
+ public static Test suite() {
+ return new TestSuite(TestSuite8.class);
+ }
+
+ public TestSuite8(String name){
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ _env.turnoffAutoBuild();
+ _project = _env.createProject("TestSuite8");
+ IPath first = _env.addFolder(_project.getFullPath(), "some-folder");
+ _env.addFile(first, "first.t6a", "error - one error line");
+ }
+
+ protected void tearDown() throws Exception {
+ _project.delete(true, null);
+ _env.dispose();
+ super.tearDown();
+ }
+
+
+ /**
+ * Test the transient settings support. That is the ability to change validator settings without changing
+ * the property files.
+ */
+ public void testPrefs() throws CoreException, UnsupportedEncodingException, InterruptedException, InvocationTargetException {
+ Tracing.log("TestSuite8-01: testClean starting");
+
+ Bundle bundle = Platform.getBundle("org.eclipse.core.runtime");
+ IPath path = Platform.getStateLocation(bundle);
+ path = path.append(".settings/"+ValidationPlugin.PLUGIN_ID+".prefs");
+ File file = path.toFile();
+ long lastModified = file.lastModified();
+
+ ValidationFramework vf = ValidationFramework.getDefault();
+ MutableWorkspaceSettings mws = vf.getWorkspaceSettings();
+ IMutableValidator[] validators = mws.getValidators();
+ assertTrue("There must be sime validators defined", validators.length > 0);
+ for (IMutableValidator val : validators){
+ val.setBuildValidation(false);
+ val.setManualValidation(true);
+ }
+ vf.applyChanges(mws, false);
+ assertEquals("The global preference file should not have changed", lastModified, file.lastModified());
+
+ IProgressMonitor monitor = new NullProgressMonitor();
+ ValidationResults vr = vf.validate(new IProject[]{_project}, true, false, monitor);
+ assertEquals("We expect exactly one error", 1, vr.getSeverityError());
+
+ mws = vf.getWorkspaceSettings();
+ validators = mws.getValidators();
+ for (IMutableValidator val : validators){
+ assertEquals("We expected " + val.getName() + " to have build turned off", false, val.isBuildValidation());
+ assertEquals("We expected " + val.getName() + " to have manual turned on", true, val.isManualValidation());
+
+ val.setBuildValidation(true);
+ val.setManualValidation(false);
+ }
+ vf.applyChanges(mws, true);
+ assertTrue("The global preference file should have changed", lastModified < file.lastModified());
+
+ vr = vf.validate(new IProject[]{_project}, true, false, monitor);
+ assertEquals("The validator is off, there should be no errors", 0, vr.getSeverityError());
+
+ projectTest();
+
+ Tracing.log("TestSuite8-02:testClean finished");
+ }
+
+ private void projectTest() throws CoreException {
+ long lastModified = lastModifiedForProject();
+
+ ValidationFramework vf = ValidationFramework.getDefault();
+
+ MutableProjectSettings mps = vf.getProjectSettings(_project);
+ assertFalse("By default, projects can not override workspace settings", mps.getOverride());
+
+ mps.setOverride(true);
+ vf.applyChanges(mps, false);
+
+ IMutableValidator[] validators = mps.getValidators();
+ assertTrue("There must be sime validators defined", validators.length > 0);
+ for (IMutableValidator val : validators){
+ val.setBuildValidation(false);
+ val.setManualValidation(true);
+ }
+ vf.applyChanges(mps, false);
+ assertEquals("The project preference file should not have changed", lastModified, lastModifiedForProject());
+
+ IProgressMonitor monitor = new NullProgressMonitor();
+ ValidationResults vr = vf.validate(new IProject[]{_project}, true, false, monitor);
+ assertEquals("We expect exactly one error", 1, vr.getSeverityError());
+
+ mps = vf.getProjectSettings(_project);
+ validators = mps.getValidators();
+ for (IMutableValidator val : validators){
+ assertEquals("We expected " + val.getName() + " to have build turned off", false, val.isBuildValidation());
+ assertEquals("We expected " + val.getName() + " to have manual turned on", true, val.isManualValidation());
+
+ val.setBuildValidation(true);
+ val.setManualValidation(false);
+ }
+ vf.applyChanges(mps, true);
+ assertTrue("The project preference file should have changed", lastModified < lastModifiedForProject());
+
+ vr = vf.validate(new IProject[]{_project}, true, false, monitor);
+ assertEquals("The validator is off, there should be no errors", 0, vr.getSeverityError());
+
+ }
+
+ private long lastModifiedForProject(){
+ long lastModified = 0;
+ IResource prefs = _project.findMember(".settings/" + ValidationPlugin.PLUGIN_ID + ".prefs");
+ if (prefs != null){
+ File pf = prefs.getLocation().toFile();
+ lastModified = pf.lastModified();
+ }
+ return lastModified;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite9.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite9.java
new file mode 100644
index 0000000..c7a4d3c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/TestSuite9.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.wst.validation.tests.testcase;
+
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.ValidationResults;
+import org.eclipse.wst.validation.internal.Tracing;
+
+/** Tests for derived resources. */
+public class TestSuite9 extends TestCase {
+
+ private TestEnvironment _env;
+ private IProject _project;
+
+ public static Test suite() {
+ return new TestSuite(TestSuite9.class);
+ }
+
+ public TestSuite9(String name){
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ _env = new TestEnvironment();
+ _project = _env.createProject("TestSuite9");
+
+ IPath first = _env.addFolder(_project.getFullPath(), "first");
+ IFile file = _env.addFile(first, "test.xml",
+ "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<root>");
+ file.setDerived(true);
+
+ TestEnvironment.enableOnlyThisValidator("org.eclipse.wst.xml.core.internal.validation.eclipse.Validator");
+ }
+
+ protected void tearDown() throws Exception {
+ _project.delete(true, null);
+ _env.dispose();
+ super.tearDown();
+ }
+
+ /**
+ * Ensure that the framework ignores derived resources.
+ */
+ public void testIgnoresDerivedResources() throws CoreException, UnsupportedEncodingException, InterruptedException {
+ Tracing.log("TestSuite9-01: testIgnoresDerivedResources starting");
+ IProgressMonitor monitor = new NullProgressMonitor();
+ ValidationFramework vf = ValidationFramework.getDefault();
+ IProject[] projects = new IProject[1];
+ projects[0] = _project;
+ ValidationResults vr = vf.validate(projects, true, false, monitor);
+ int errors = vr.getSeverityError();
+ assertEquals("Number of errors", 0, errors);
+
+ Tracing.log("TestSuite9-02: testIgnoresDerivedResources finished");
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/ValidationTestSuite.java b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/ValidationTestSuite.java
new file mode 100644
index 0000000..bdc7a68
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/src/org/eclipse/wst/validation/tests/testcase/ValidationTestSuite.java
@@ -0,0 +1,31 @@
+package org.eclipse.wst.validation.tests.testcase;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class ValidationTestSuite extends TestSuite {
+
+ public ValidationTestSuite() {
+ super();
+ TestSuite suite = (TestSuite)ValidationTestSuite.suite();
+ for (int i = 0; i < suite.testCount(); i++) {
+ addTest(suite.testAt(i));
+ }
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for org.eclipse.wst.validation.tests.testcase");
+ suite.addTest(TestSuite1.suite());
+ suite.addTest(TestSuite2.suite());
+ suite.addTest(TestSuite3.suite());
+ suite.addTest(TestSuite4.suite());
+ suite.addTest(TestSuite5.suite());
+ suite.addTest(TestSuite6.suite());
+ suite.addTest(TestSuite7.suite());
+ suite.addTest(TestSuite8.suite());
+ suite.addTest(TestSuite9.suite());
+ suite.addTest(TestSuite10.suite());
+ return suite;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/test.xml b/tests/org.eclipse.wst.common.tests.validation/test.xml
new file mode 100644
index 0000000..1dd64fc
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/test.xml
@@ -0,0 +1,64 @@
+<?xml version="1.0"?>
+
+<project name="testsuite" default="run" basedir=".">
+ <!--==============================================================-->
+ <!-- The property ${eclipse-home} should be passed into this script. -->
+ <!-- Set a meaningful default value for when it is not. -->
+ <!--==============================================================-->
+ <!-- <property name="eclipse-home" value="${basedir}\.."/> -->
+
+ <!--==============================================================-->
+ <!-- Set the environment properties. -->
+ <!--==============================================================-->
+ <property name="plugin-name" value="org.eclipse.wst.common.tests.validation"/>
+ <property name="library-file" value="${eclipse-home}/plugins/org.eclipse.test_3.2.0/library.xml"/>
+ <property name="extraVMargs" value="-Xmx768M"/>
+
+ <!--===============================================================-->
+ <!-- This target initializes all of the tests that will run. -->
+ <!-- Initialization for individual tests should be done within the -->
+ <!-- body of the suite target. -->
+ <!--===============================================================-->
+ <target name="init">
+ <tstamp/>
+ <delete>
+ <fileset dir="${eclipse-home}" includes="org.*.xml"/>
+ </delete>
+ </target>
+
+ <!--==============================================================-->
+ <!-- This target defines the tests that need to run. -->
+ <!--==============================================================-->
+ <target name="suite">
+ <property name="workspace" value="${eclipse-home}/wst_vf"/>
+ <delete dir="${workspace}" quiet="true"/>
+ <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}">
+ <property name="data-dir" value="${workspace}"/>
+ <property name="plugin-name" value="${plugin-name}"/>
+ <property name="classname" value="org.eclipse.wst.validation.tests.testcase.ValidationTestSuite"/>
+ <property name="plugin-path" value="${eclipse-home}/plugins/${plugin-name}"/>
+ <property name="extraVMargs" value="${extraVMargs}"/>
+ </ant>
+ </target>
+
+ <!--==================================================================-->
+ <!-- This target holds code to cleanup the testing environment after -->
+ <!-- all of the tests have been run. You can use this target to -->
+ <!-- delete temporary files that have been created. -->
+ <!--==================================================================-->
+ <target name="cleanup">
+ </target>
+
+ <!--==================================================================-->
+ <!-- This target runs the test suite. Any actions that need to happen -->
+ <!-- after all the tests have been run should go here. -->
+ <!--==================================================================-->
+ <target name="run" depends="init,suite,cleanup">
+ <ant target="collect" antfile="${library-file}" dir="${eclipse-home}">
+ <property name="includes" value="org.*.xml"/>
+ <property name="output-file" value="${plugin-name}.xml"/>
+ </ant>
+ </target>
+
+</project>
+
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/Misc.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/Misc.java
new file mode 100644
index 0000000..b9ecacb
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/Misc.java
@@ -0,0 +1,80 @@
+package org.eclipse.wst.validation.tests;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Some miscellaneous helper methods.
+ * @author karasiuk
+ *
+ */
+public class Misc {
+
+ private static DateFormat _df = new SimpleDateFormat("HH:mm:ss.SSSS"); //$NON-NLS-1$
+
+ public static void close(InputStream in){
+ if (in == null)return;
+ try {
+ in.close();
+ }
+ catch (IOException e){
+ // eat it
+ }
+ }
+
+ public static void close(OutputStream out) {
+ if (out == null)return;
+ try {
+ out.close();
+ }
+ catch (IOException e){
+ // eat it
+ }
+ }
+
+ public static String listMarkers(IResource resource){
+ StringBuffer b = new StringBuffer(2000);
+ b.append("Markers on ");
+ b.append(resource.getName());
+ b.append(' ');
+ try {
+ IMarker[] markers = resource.findMarkers(null, true, IResource.DEPTH_ZERO);
+ for (IMarker m : markers){
+ Object o = m.getAttribute(IMarker.MESSAGE);
+ if (o != null){
+ b.append(o);
+ }
+ o = m.getAttribute(IMarker.SEVERITY);
+ if (o != null){
+ b.append(", Severity=");
+ b.append(o);
+ }
+ b.append("; ");
+ }
+ }
+ catch (CoreException e){
+
+ }
+ return b.toString();
+ }
+
+ public static String timestampIt(String line){
+ Date date = new Date();
+ long thread = Thread.currentThread().getId();
+ return _df.format(date) + " " + thread + " " + line;//$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ public static void niy(String msg){
+ if (msg == null)msg = "Sorry, this function is not implemented yet"; //$NON-NLS-1$
+ throw new RuntimeException(msg);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1AValidator.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1AValidator.java
new file mode 100644
index 0000000..4a87c4c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1AValidator.java
@@ -0,0 +1,60 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationFramework;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.eclipse.wst.validation.internal.Tracing;
+import org.eclipse.wst.validation.tests.testcase.FileNames;
+
+/**
+ * Test validating a side file.
+ * @author karasiuk
+ *
+ */
+public class T1AValidator extends AbstractValidator {
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T1A";
+ }
+
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor){
+ Tracing.log("T1AValidator-01: is validating: " + resource.getName());
+ ValidationResult vr = new ValidationResult();
+ clearTest(resource.getProject(), vr);
+ return vr;
+ }
+
+
+ private void clearTest(IProject project, ValidationResult vr) {
+ IResource resource = project.findMember("source/" + FileNames.firstTest2x);
+ try {
+ ValidationFramework.getDefault().clearMessages(resource, id());
+ }
+ catch (CoreException e){
+ throw new RuntimeException(e);
+ }
+ String msg = Tracing.timestampIt("Side effect validation from T1A");
+ ValidatorMessage vm = ValidatorMessage.create(msg, resource);
+ vm.setAttribute(IMarker.LINE_NUMBER, 1);
+ vm.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ vr.add(vm);
+ vr.setValidated(new IResource[]{resource});
+ }
+
+ public String getId(){
+ return id();
+ }
+
+ public String getName(){
+ return "T1AValidator";
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1B.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1B.java
new file mode 100644
index 0000000..2fe0703
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1B.java
@@ -0,0 +1,32 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.ValidatorMessage;
+
+/**
+ * Used to test custom markers.
+ * @author karasiuk
+ *
+ */
+public class T1B extends TestValidator {
+
+ public static final String MarkerId = Activator.PLUGIN_ID+".t1bmarker";
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T1B";
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ ValidationResult vr = super.validate(resource, kind, state, monitor);
+
+ for (ValidatorMessage vm : vr.getMessages()){
+ vm.setType(MarkerId);
+ }
+ return vr;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1C.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1C.java
new file mode 100644
index 0000000..0c7ee62
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1C.java
@@ -0,0 +1,29 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.common.tests.validation.Activator;
+
+/**
+ * A validator that is used to test the folder filters.
+ *
+ * It looks at files with a file extension of t1c.
+ * @author karasiuk
+ *
+ */
+public class T1C extends TestValidator {
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T1C";
+ }
+
+ @Override
+ public String getId() {
+ return id();
+ }
+
+ @Override
+ public String getName() {
+ return "T1C";
+ }
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1Group.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1Group.java
new file mode 100644
index 0000000..3ff9dc5
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T1Group.java
@@ -0,0 +1,49 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.IValidatorGroupListener;
+import org.eclipse.wst.validation.ValidationState;
+
+public class T1Group implements IValidatorGroupListener {
+
+ private int _starting;
+ private int _finishing;
+ private static T1Group _me;
+
+ public static T1Group getGroup(){
+ return _me;
+ }
+
+ public T1Group(){
+ if (_me != null)throw new IllegalStateException("Only one instance can be constructed.");
+ _me = this;
+ }
+
+ public void validationFinishing(IResource resource,
+ IProgressMonitor monitor, ValidationState state) {
+ _starting++;
+
+ }
+
+ public void validationStarting(IResource resource,
+ IProgressMonitor monitor, ValidationState state) {
+ _finishing++;
+
+ }
+
+ public int getStarting() {
+ return _starting;
+ }
+
+ public int getFinishing() {
+ return _finishing;
+ }
+
+ public void reset() {
+ _starting = 0;
+ _finishing = 0;
+
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2A.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2A.java
new file mode 100644
index 0000000..9da9a43
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2A.java
@@ -0,0 +1,24 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.validation.internal.Tracing;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
+import org.eclipse.wst.validation.internal.provisional.core.IValidator;
+
+/**
+ * A V1 validator that is off by default.
+ * @author karasiuk
+ *
+ */
+public class T2A implements IValidator {
+
+ public void cleanup(IReporter reporter) {
+ }
+
+ public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
+ String[] uris = helper.getURIs();
+ if (uris != null)Tracing.log("T2A-01: number of urs = " + uris.length);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2AHelper.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2AHelper.java
new file mode 100644
index 0000000..3ed44f1
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2AHelper.java
@@ -0,0 +1,26 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.validation.internal.Tracing;
+import org.eclipse.wst.validation.internal.operations.WorkbenchContext;
+
+public class T2AHelper extends WorkbenchContext {
+
+ public String[] getURIs() {
+ return null;
+ }
+
+ public Object loadModel(String symbolicName) {
+ logit("T2AHelper#loadModule: " + symbolicName);
+ return null;
+ }
+
+ public Object loadModel(String symbolicName, Object[] parms) {
+ logit("T2AHelper#loadModule2: " + symbolicName);
+ return null;
+ }
+
+ private void logit(String line){
+ Tracing.log(line);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2B.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2B.java
new file mode 100644
index 0000000..ad4b47a
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T2B.java
@@ -0,0 +1,24 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.validation.internal.Tracing;
+import org.eclipse.wst.validation.internal.core.ValidationException;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
+import org.eclipse.wst.validation.internal.provisional.core.IValidator;
+
+/**
+ * A V1 validator that is on by default.
+ * @author karasiuk
+ *
+ */
+public class T2B implements IValidator {
+
+ public void cleanup(IReporter reporter) {
+ }
+
+ public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
+ String[] uris = helper.getURIs();
+ if (uris != null)Tracing.log("T2B-01: number of URIs = " + uris.length);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T4A.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T4A.java
new file mode 100644
index 0000000..9d08d58
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T4A.java
@@ -0,0 +1,20 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.common.tests.validation.Activator;
+
+/**
+ * This validator is used to test facet versions. It should be called on projects that have a version 5 java facet.
+ * @author karasiuk
+ *
+ */
+public class T4A extends TestValidator {
+
+ public String getName() {
+ return "T4A";
+ }
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T4A";
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T4B.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T4B.java
new file mode 100644
index 0000000..8f9f7e1
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T4B.java
@@ -0,0 +1,20 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.common.tests.validation.Activator;
+
+/**
+ * This validator is used to test facet versions. It should be called on projects that have a version 6 java facet.
+ * @author karasiuk
+ *
+ */
+public class T4B extends TestValidator {
+
+ public String getName() {
+ return "T4B";
+ }
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T4B";
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5A.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5A.java
new file mode 100644
index 0000000..093e3fa
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5A.java
@@ -0,0 +1,20 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.common.tests.validation.Activator;
+
+/**
+ * This validator is used to test pattern filters.
+ * @author karasiuk
+ *
+ */
+public class T5A extends TestValidator {
+
+ public String getName() {
+ return "T5A";
+ }
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T5A";
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5B.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5B.java
new file mode 100644
index 0000000..ee400f2
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5B.java
@@ -0,0 +1,20 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.common.tests.validation.Activator;
+
+/**
+ * This validator is used to test pattern filters.
+ * @author karasiuk
+ *
+ */
+public class T5B extends TestValidator {
+
+ public String getName() {
+ return "T5B";
+ }
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T5B";
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5C.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5C.java
new file mode 100644
index 0000000..5ea735c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T5C.java
@@ -0,0 +1,21 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.wst.common.tests.validation.Activator;
+
+/**
+ * This validator is used to test pattern filters. This validator would normally validate *.test1 files, but an exclusion rule
+ * has been added (via the exclude extension point) to not validate /second/third/ files.
+ * @author karasiuk
+ *
+ */
+public class T5C extends TestValidator {
+
+ public String getName() {
+ return "T5C";
+ }
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T5C";
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T6A.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T6A.java
new file mode 100644
index 0000000..7cff037
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T6A.java
@@ -0,0 +1,54 @@
+package org.eclipse.wst.validation.tests;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.ValidationEvent;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * This validator is used to test the new validate entry point that includes dependency information
+ * @author karasiuk
+ *
+ */
+public class T6A extends TestValidator {
+
+ private static AtomicInteger _countSimple = new AtomicInteger();
+ private static AtomicInteger _countComplex = new AtomicInteger();
+
+ public static void resetCounters(){
+ _countSimple.set(0);
+ _countComplex.set(0);
+ }
+
+ public static int getCountSimple(){
+ return _countSimple.get();
+ }
+
+ public static int getCountComplex(){
+ return _countComplex.get();
+ }
+
+ public String getName() {
+ return "T6A";
+ }
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".T6A";
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ _countSimple.incrementAndGet();
+ return super.validate(resource, kind, state, monitor);
+ }
+
+ @Override
+ public ValidationResult validate(ValidationEvent event, ValidationState state, IProgressMonitor monitor) {
+ _countComplex.incrementAndGet();
+ return super.validate(event.getResource(), event.getKind(), state, monitor);
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T7A.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T7A.java
new file mode 100644
index 0000000..c8236c3
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/T7A.java
@@ -0,0 +1,88 @@
+package org.eclipse.wst.validation.tests;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * A validator that tests the order of the validate calls.
+ * @author karasiuk
+ *
+ */
+public final class T7A extends AbstractValidator {
+
+ private static List<ValEntryPoint> _list = new LinkedList<ValEntryPoint>();
+
+ public static void resetList(){
+ _list.clear();
+ }
+
+ public static List<ValEntryPoint> getList(){
+ return _list;
+ }
+
+ public static ValEntryPoint[] getArray(){
+ ValEntryPoint[] array = new ValEntryPoint[_list.size()];
+ _list.toArray(array);
+ return array;
+ }
+
+ @Override
+ public void validationStarting(IProject project, ValidationState state, IProgressMonitor monitor) {
+ _list.add(new ValEntryPoint(EntryType.Starting, project));
+ }
+
+ @Override
+ public void validationFinishing(IProject project, ValidationState state, IProgressMonitor monitor) {
+ _list.add(new ValEntryPoint(EntryType.Finishing, project));
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ _list.add(new ValEntryPoint(EntryType.Normal, resource));
+ return null;
+ }
+
+ @Override
+ public void clean(IProject project, ValidationState state, IProgressMonitor monitor) {
+ _list.add(new ValEntryPoint(EntryType.Clean, project));
+ }
+
+ /**
+ * An immutible object that records an entry into the validator.
+ * @author karasiuk
+ *
+ */
+ public final static class ValEntryPoint {
+ private final EntryType _type;
+ private final IResource _resource;
+
+ public ValEntryPoint(EntryType type, IResource resource){
+ _type = type;
+ _resource = resource;
+ }
+
+ @Override
+ public String toString() {
+ String resource = _resource == null ? "null" : _resource.getName();
+ return "ValEntryPoint: " + _type + " " + resource;
+ }
+
+ public EntryType getType() {
+ return _type;
+ }
+
+ public IResource getResource() {
+ return _resource;
+ }
+ }
+
+ public enum EntryType {Starting, Normal, Finishing, Clean}
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator.java
new file mode 100644
index 0000000..9f701b9
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator.java
@@ -0,0 +1,149 @@
+package org.eclipse.wst.validation.tests;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.ValidatorMessage;
+
+/**
+ * Simple test validator.
+ * <p>
+ * This validator processes a file looking for certain magic tokens:
+ * <ul>
+ * <li>include fileName - open the file with name fileName and process it as an include
+ * <li>error - create an error marker for this line
+ * <li>warning - create a warning marker for this line
+ * <li>info - create an info marker for this line
+ * </ul>
+ * </p>
+ * <p>
+ * Include files contain the magic token map. For example the line "map t1error error" will
+ * cause occurrences of t1error to be mapped to error.
+ * </p>
+ * @author karasiuk
+ *
+ */
+public class TestValidator extends AbstractValidator {
+
+ private static final String SimpleName = "Test1";
+
+ public static String id(){
+ return Activator.PLUGIN_ID +"." + SimpleName;
+ }
+
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor){
+ ValidationResult vr = new ValidationResult();
+ InputStream in = null;
+ try {
+ if (resource instanceof IFile) {
+ IFile file = (IFile) resource;
+ in = file.getContents();
+ BufferedReader rdr = new BufferedReader(new InputStreamReader(in));
+ process(vr, rdr, resource, state);
+ }
+ }
+ catch (Exception e){
+ Activator.getDefault().handleException(e);
+ }
+ finally {
+ Misc.close(in);
+ }
+
+ return vr;
+ }
+
+ public String getId(){
+ return id();
+ }
+
+ private void process(ValidationResult vr, BufferedReader rdr, IResource resource, ValidationState state) throws IOException, CoreException {
+ String line = null;
+ int count = 0;
+ Map<String, String> map = null;
+ while (null != (line = rdr.readLine())){
+ count++;
+ int severity = -1;
+ String[] tokens = line.split("\\s");
+ if (tokens.length == 0)continue;
+ String token = tokens[0];
+ severity = findSeverity(token, severity);
+ if (severity == -1 && map != null){
+ String renamed = map.get(token);
+ severity = findSeverity(renamed, severity);
+ }
+
+ if (severity != -1){
+ ValidatorMessage message = ValidatorMessage.create(line + "(by " + getName() +")", resource);
+ message.setAttribute(IMarker.LINE_NUMBER, count);
+ message.setAttribute(IMarker.SEVERITY, severity);
+ vr.add(message);
+ }
+
+ if (token.equals("include")){
+ map = new HashMap<String, String>(10);
+ String msg = processInclude(vr, tokens, resource, map);
+ if (msg != null){
+ ValidatorMessage message = ValidatorMessage.create(msg, resource);
+ message.setAttribute(IMarker.LINE_NUMBER, count);
+ message.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ vr.add(message);
+ }
+ }
+ }
+
+ }
+
+ private int findSeverity(String token, int dft){
+ if (token == null)return dft;
+ if (token.equals("error"))return IMarker.SEVERITY_ERROR;
+ if (token.equals("warning"))return IMarker.SEVERITY_WARNING;
+ if (token.equals("info"))return IMarker.SEVERITY_INFO;
+ return dft;
+ }
+
+ private String processInclude(ValidationResult vr, String[] tokens, IResource resource, Map<String, String> map) throws IOException, CoreException{
+ IContainer parent = resource.getParent();
+ IFile file = parent.getFile(new Path(tokens[1]));
+ if (!file.exists())return "Could not find file: " + file;
+
+ InputStream in = null;
+ try {
+ in = file.getContents();
+ BufferedReader rdr = new BufferedReader(new InputStreamReader(in));
+ String line = null;
+ while(null != (line = rdr.readLine())){
+ String[] p = line.split("\\s");
+ if (p.length == 3 && "map".equals(p[0])){
+ map.put(p[1], p[2]);
+ }
+ }
+ }
+ finally {
+ Misc.close(in);
+ }
+ IResource[] depends = {file};
+ vr.setDependsOn(depends);
+ return null;
+
+ }
+
+ public String getName(){
+ return "TestValidator1";
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator2.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator2.java
new file mode 100644
index 0000000..747f7e2
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator2.java
@@ -0,0 +1,51 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.MessageSeveritySetting;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.eclipse.wst.validation.MessageSeveritySetting.Severity;
+
+/**
+ * A simple test validator that always returns an error marker and a warning marker.
+ * @author karasiuk
+ *
+ */
+public class TestValidator2 extends AbstractValidator {
+
+ public String getName() {
+ return "TestValidator2";
+ }
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".Test2";
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor){
+ ValidationResult vr = new ValidationResult();
+ ValidatorMessage vm = ValidatorMessage.create("A sample message from " + getName(), resource);
+ vm.setAttribute(IMarker.LINE_NUMBER, 1);
+ vm.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ vr.add(vm);
+
+ MessageSeveritySetting sev = getParent().getMessage("sortof");
+ if (sev != null){
+ Severity ms = sev.getCurrent();
+ if (ms != Severity.Ignore){
+ vm = ValidatorMessage.create("A different message from " + getName(), resource);
+ vm.setAttribute(IMarker.LINE_NUMBER, 2);
+ vm.setAttribute(IMarker.SEVERITY, ms.getMarkerSeverity());
+ vr.add(vm);
+ }
+ }
+
+ return vr;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator3.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator3.java
new file mode 100644
index 0000000..4d19243
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator3.java
@@ -0,0 +1,94 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.ValidatorMessage;
+import org.eclipse.wst.validation.internal.Tracing;
+
+/**
+ * A validator that processes *.html and *.htm files.
+ * @author karasiuk
+ *
+ */
+public class TestValidator3 extends AbstractValidator {
+
+ private static final String Name = "TestValidator3";
+ static final String ID = "org.eclipse.wst.validation.tests.TestValidator3";
+
+ public String getName() {
+ return Name;
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor){
+ Tracing.log(Name+"-04: validating: " + resource);
+ checkState(state);
+
+ if (resource.getName().equals("test.html")){
+ ValidationResult vr = new ValidationResult();
+ ValidatorMessage vm = ValidatorMessage.create("A specific test.html error", resource);
+ vm.setAttribute(IMarker.LINE_NUMBER, 1);
+ vm.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ vr.add(vm);
+
+ IResource other = resource.getParent().findMember("test2.html");
+ if (other != null)vr.setValidated(new IResource[]{other});
+
+ IResource depends = resource.getParent().findMember("master.html");
+ if (depends != null)vr.setDependsOn(new IResource[]{depends});
+ return vr;
+ }
+
+ ValidationResult vr = new ValidationResult();
+ ValidatorMessage vm = ValidatorMessage.create("A sample message from " + getName(), resource);
+ vm.setAttribute(IMarker.LINE_NUMBER, 1);
+ vm.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ vr.add(vm);
+
+ vm = ValidatorMessage.create("A different message from " + getName(), resource);
+ vm.setAttribute(IMarker.LINE_NUMBER, 3);
+ vm.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
+ vr.add(vm);
+
+ return vr;
+ }
+
+ @Override
+ public void validationStarting(IProject project, ValidationState state, IProgressMonitor monitor) {
+ String name = project == null ? "NULL" : project.getName();
+ Tracing.log(Name+"-05: thinks validation is starting for project: ", name);
+ if (!checkState(state)){
+ state.put(ID, "my state");
+ }
+
+
+ }
+
+ @Override
+ public void validationFinishing(IProject project, ValidationState state, IProgressMonitor monitor) {
+ String name = project == null ? "NULL" : project.getName();
+ Tracing.log(Name+"-01: thinks validation is finishing for project: ", name);
+ checkState(state);
+ }
+
+ @Override
+ public void clean(IProject project, ValidationState state, IProgressMonitor monitor) {
+ String name = project == null ? "NULL" : project.getName();
+ Tracing.log(Name+"-02: thinks a clean has been requested for project: ", name);
+ checkState(state);
+ }
+
+ private boolean checkState(ValidationState state){
+ if (state.get(ID) != null){
+ Tracing.log(Name+"-03: has state information");
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator4.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator4.java
new file mode 100644
index 0000000..417b862
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator4.java
@@ -0,0 +1,55 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * A slower validator. This validator takes at least 2 seconds to run.
+ *
+ * It looks at files with a file extension of test4.
+ * @author karasiuk
+ *
+ */
+public class TestValidator4 extends TestValidator {
+
+ private static ValCounters _counters = new ValCounters();
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".Test4";
+ }
+
+ public static ValCounters getCounters() {
+ return _counters;
+ }
+
+ @Override
+ public void validationStarting(IProject project, ValidationState state, IProgressMonitor monitor) {
+ if (project == null)_counters.startingCount++;
+ else _counters.startingProjectCount++;
+ }
+
+ @Override
+ public void validationFinishing(IProject project, ValidationState state, IProgressMonitor monitor) {
+ if (project == null)_counters.finishedCount++;
+ else _counters.finishedProjectCount++;
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ ValidationResult vr = super.validate(resource, kind, state, monitor);
+ //long j = 0;
+ try {
+ //for (long i=0; i< 10000000; i++)j = i + 1;
+ Thread.sleep(2000);
+ }
+ catch (InterruptedException e){
+ // eat it
+ }
+ //j++; // just to get rid of the compiler warning
+ return vr;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator5.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator5.java
new file mode 100644
index 0000000..50e7c5d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator5.java
@@ -0,0 +1,21 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * This validator never gets called, it just serves as a definition for a delegating validator.
+ * @author karasiuk
+ *
+ */
+public class TestValidator5 extends AbstractValidator {
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ return null;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator5D.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator5D.java
new file mode 100644
index 0000000..e577d06
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator5D.java
@@ -0,0 +1,51 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * This is a delegating validator.
+ * @author karasiuk
+ *
+ */
+public class TestValidator5D extends AbstractValidator {
+
+ private static int _calledCount;
+ private static ValCounters _counters = new ValCounters();
+
+ public static ValCounters getCounters() {
+ return _counters;
+ }
+
+ @Override
+ public void validationStarting(IProject project, ValidationState state, IProgressMonitor monitor) {
+ if (project == null)_counters.startingCount++;
+ else _counters.startingProjectCount++;
+ }
+
+ @Override
+ public void validationFinishing(IProject project, ValidationState state, IProgressMonitor monitor) {
+ if (project == null)_counters.finishedCount++;
+ else _counters.finishedProjectCount++;
+ }
+
+ public String getName() {
+ return "TestValidator5D";
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ ValidationResult vr = new ValidationResult();
+ _calledCount++;
+ return vr;
+ }
+
+ public static int getCalledCount() {
+ return _calledCount;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator6.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator6.java
new file mode 100644
index 0000000..bc7ab48
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator6.java
@@ -0,0 +1,38 @@
+package org.eclipse.wst.validation.tests;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * A validator that has similar rules as the XML validator.
+ * @author karasiuk
+ *
+ */
+public class TestValidator6 extends AbstractValidator {
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".Test6";
+ }
+
+
+ private Set<IResource> _set = new HashSet<IResource>(100);
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ ValidationResult result = new ValidationResult();
+ _set.add(resource);
+ return result;
+ }
+
+ public Set<IResource> getSet() {
+ return _set;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator7.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator7.java
new file mode 100644
index 0000000..35ade9f
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator7.java
@@ -0,0 +1,42 @@
+package org.eclipse.wst.validation.tests;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+
+/**
+ * A validator that has similar rules as the Test1 Validator, used to test the suspend validation API.
+ * @author karasiuk
+ *
+ */
+public class TestValidator7 extends AbstractValidator {
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".Test7";
+ }
+
+ private Set<IResource> _set = new HashSet<IResource>(100);
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ ValidationResult result = new ValidationResult();
+ _set.add(resource);
+ result.setSuspendValidation(resource.getProject());
+ return result;
+ }
+
+ public Set<IResource> getSet() {
+ return _set;
+ }
+
+ public void reset(){
+ _set.clear();
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator8.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator8.java
new file mode 100644
index 0000000..9e9b610
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/TestValidator8.java
@@ -0,0 +1,40 @@
+package org.eclipse.wst.validation.tests;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.tests.validation.Activator;
+import org.eclipse.wst.validation.AbstractValidator;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
+import org.eclipse.wst.validation.ValidatorMessage;
+
+/**
+ * A simple test validator that always returns an error marker on line 1. This can be extended by other testcases.
+ *
+ * Test8 is used to test the file filter. The both files named file.specific should be validated, where as only
+ * source/full.specific should be validated.
+ * @author karasiuk
+ *
+ */
+public class TestValidator8 extends AbstractValidator {
+
+ public String getName() {
+ return "TestValidator8";
+ }
+
+ public static String id(){
+ return Activator.PLUGIN_ID +".Test8";
+ }
+
+ @Override
+ public ValidationResult validate(IResource resource, int kind, ValidationState state, IProgressMonitor monitor){
+ ValidationResult vr = new ValidationResult();
+ ValidatorMessage vm = ValidatorMessage.create("A sample error from " + getName(), resource);
+ vm.setAttribute(IMarker.LINE_NUMBER, 1);
+ vm.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
+ vr.add(vm);
+ return vr;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/ValCounters.java b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/ValCounters.java
new file mode 100644
index 0000000..6a0fc4a
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests.validation/validators/org/eclipse/wst/validation/tests/ValCounters.java
@@ -0,0 +1,26 @@
+package org.eclipse.wst.validation.tests;
+
+/**
+ * Some miscellaneous counters.
+ * @author karasiuk
+ *
+ */
+public class ValCounters {
+ public int startingCount;
+ public int finishedCount;
+ public int startingProjectCount;
+ public int finishedProjectCount;
+
+ public void reset(){
+ startingCount = 0;
+ startingProjectCount = 0;
+ finishedCount = 0;
+ finishedProjectCount = 0;
+ }
+
+ @Override
+ public String toString() {
+ return "ValCounters: startingCount=" + startingCount + ", finishedCount="+finishedCount+
+ ", startProjectCount="+startingProjectCount+", finishedProjectCount="+finishedProjectCount;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/.classpath b/tests/org.eclipse.wst.common.tests/.classpath
new file mode 100644
index 0000000..0c793d6
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/.classpath
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="commontests"/>
+ <classpathentry kind="src" path="frameworktests"/>
+ <classpathentry kind="src" path="apitools"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.wst.common.tests/.cvsignore b/tests/org.eclipse.wst.common.tests/.cvsignore
new file mode 100644
index 0000000..a36ac25
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/.cvsignore
@@ -0,0 +1,5 @@
+bin
+build.xml
+temp.folder
+commontests.jar
+javaCompiler.commontests.jar.args
diff --git a/tests/org.eclipse.wst.common.tests/.project b/tests/org.eclipse.wst.common.tests/.project
new file mode 100644
index 0000000..78b0951
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.wst.common.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.wst.common.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.wst.common.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..b1f0a3a
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Thu May 10 18:38:31 EDT 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/tests/org.eclipse.wst.common.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.common.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..fe8f2ce
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,38 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %Bundle-Name.0
+Bundle-SymbolicName: org.eclipse.wst.common.tests; singleton:=true
+Bundle-Version: 1.2.400.qualifier
+Bundle-ClassPath: commontests.jar
+Bundle-Activator: org.eclipse.wst.common.tests.CommonTestsPlugin
+Bundle-Vendor: %Bundle-Vendor.0
+Export-Package: org.eclipse.etools.common.test.apitools,
+ org.eclipse.wst.common.environment.tests,
+ org.eclipse.wst.common.extras,
+ org.eclipse.wst.common.frameworks.artifactedit.tests,
+ org.eclipse.wst.common.frameworks.componentcore.tests,
+ org.eclipse.wst.common.frameworks.componentcore.virtualpath.tests,
+ org.eclipse.wst.common.frameworks.datamodel.tests,
+ org.eclipse.wst.common.frameworks.datamodel.tests.extended,
+ org.eclipse.wst.common.frameworks.tests.bvt,
+ org.eclipse.wst.common.tests,
+ org.eclipse.wst.common.tests.xml
+Require-Bundle: org.junit;visibility:=reexport,
+ org.eclipse.core.resources;visibility:=reexport,
+ org.eclipse.wst.common.frameworks;visibility:=reexport,
+ org.eclipse.wst.common.emfworkbench.integration,
+ org.eclipse.emf.common,
+ org.eclipse.emf.ecore,
+ org.eclipse.core.commands,
+ org.eclipse.wst.common.modulecore,
+ org.eclipse.wst.common.tests.collector;visibility:=reexport,
+ org.eclipse.jem.util,
+ org.eclipse.wst.common.environment,
+ org.eclipse.wst.common.emf,
+ org.eclipse.wst.validation;bundle-version="1.2.0",
+ org.eclipse.wst.common.uriresolver.tests,
+ org.eclipse.core.runtime
+Eclipse-LazyStart: true
+Plugin-Class: org.eclipse.wst.common.tests.CommonTestsPlugin
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Localization: plugin
diff --git a/tests/org.eclipse.wst.common.tests/about.html b/tests/org.eclipse.wst.common.tests/about.html
new file mode 100644
index 0000000..2199df3
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/about.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<HTML>
+
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+
+<BODY lang="EN-US">
+
+<H3>About This Content</H3>
+
+<P>June, 2008</P>
+
+<H3>License</H3>
+
+<P>The Eclipse Foundation makes available all content in this plug-in
+("Content"). Unless otherwise indicated below, the Content is provided to you
+under the terms and conditions of the Eclipse Public License Version 1.0
+("EPL"). A copy of the EPL is available at
+<A href="http://www.eclipse.org/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</A>.
+For purposes of the EPL, "Program" will mean the Content.</P>
+
+<P>If you did not receive this Content directly from the Eclipse Foundation, the
+Content is being redistributed by another party ("Redistributor") and different
+terms and conditions may apply to your use of any object code in the Content.
+Check the Redistributors license that was provided with the Content. If no such
+license exists, contact the Redistributor. Unless otherwise indicated below, the
+terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at
+<A href="http://www.eclipse.org/">http://www.eclipse.org/</A>.</P>
+
+</BODY>
+</HTML>
diff --git a/tests/org.eclipse.wst.common.tests/apitools/org/eclipse/etools/common/test/apitools/ProjectUnzipUtil.java b/tests/org.eclipse.wst.common.tests/apitools/org/eclipse/etools/common/test/apitools/ProjectUnzipUtil.java
new file mode 100644
index 0000000..5767d21
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/apitools/org/eclipse/etools/common/test/apitools/ProjectUnzipUtil.java
@@ -0,0 +1,139 @@
+package org.eclipse.etools.common.test.apitools;
+
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.eclipse.core.internal.resources.ProjectDescription;
+import org.eclipse.core.internal.resources.ProjectDescriptionReader;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+public class ProjectUnzipUtil {
+
+ private IPath zipLocation;
+ private String[] projectNames;
+ private IPath rootLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
+ private static final String META_PROJECT_NAME = ".project";
+
+
+
+ public ProjectUnzipUtil(IPath aZipLocation, String[] aProjectNames) {
+ zipLocation = aZipLocation;
+ projectNames = aProjectNames;
+
+ }
+
+ public boolean createProjects() {
+ try {
+ expandZip();
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
+ buildProjects();
+ } catch (CoreException e) {
+ e.printStackTrace();
+ return false;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ }
+
+ return true;
+
+ }
+
+ private IProgressMonitor getProgessMonitor() {
+ return new NullProgressMonitor();
+ }
+
+ private void expandZip() throws CoreException, IOException {
+ IProgressMonitor monitor = getProgessMonitor();
+ ZipFile zipFile = null;
+ try {
+ zipFile = new ZipFile(zipLocation.toFile());
+ } catch (IOException e1) {
+ throw e1;
+ }
+ Enumeration entries = zipFile.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry) entries.nextElement();
+ monitor.subTask(entry.getName());
+ File aFile = computeLocation(entry.getName()).toFile();
+ File parentFile = null;
+ try {
+ if (entry.isDirectory()) {
+ aFile.mkdirs();
+ } else {
+ parentFile = aFile.getParentFile();
+ if (!parentFile.exists())
+ parentFile.mkdirs();
+ if (!aFile.exists())
+ aFile.createNewFile();
+ copy(zipFile.getInputStream(entry), new FileOutputStream(aFile));
+ if (entry.getTime() > 0)
+ aFile.setLastModified(entry.getTime());
+ }
+ } catch (IOException e) {
+ throw e;
+ }
+ monitor.worked(1);
+ }
+ }
+
+ private IPath computeLocation(String name) {
+ return rootLocation.append(name);
+ }
+
+
+ public static void copy(InputStream in, OutputStream out) throws IOException {
+ byte[] buffer = new byte[1024];
+ try {
+ int n = in.read(buffer);
+ while (n > 0) {
+ out.write(buffer, 0, n);
+ n = in.read(buffer);
+ }
+ } finally {
+ in.close();
+ out.close();
+ }
+ }
+
+ public void setRootLocation(IPath rootLocation) {
+ this.rootLocation = rootLocation;
+ }
+
+ private void buildProjects() throws IOException, CoreException {
+ for (int i = 0; i < projectNames.length; i++) {
+ ProjectDescriptionReader pd = new ProjectDescriptionReader();
+ IPath projectPath = new Path("/" + projectNames[i] + "/" + META_PROJECT_NAME);
+ IPath path = rootLocation.append(projectPath);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectNames[i]);
+ ProjectDescription description;
+ try {
+ description = pd.read(path);
+ project.create(description, (getProgessMonitor()));
+ project.open(getProgessMonitor());
+
+ } catch (IOException e) {
+ throw e;
+ } catch (CoreException e) {
+ throw e;
+ }
+ }
+ }
+
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/build.properties b/tests/org.eclipse.wst.common.tests/build.properties
new file mode 100644
index 0000000..c8e1e20
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/build.properties
@@ -0,0 +1,11 @@
+bin.includes = commontests.jar,\
+ plugin.xml,\
+ testData/,\
+ test.xml,\
+ about.html,\
+ META-INF/,\
+ plugin.properties
+source.commontests.jar = commontests/,\
+ frameworktests/,\
+ apitools/
+output.commontests.jar = bin/
diff --git a/tests/org.eclipse.wst.common.tests/build/buildcontrol.properties b/tests/org.eclipse.wst.common.tests/build/buildcontrol.properties
new file mode 100644
index 0000000..8db5dee
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/build/buildcontrol.properties
@@ -0,0 +1,7 @@
+CONTACT=danberg@us.ibm.com
+ComponentShortName=commontests
+ComponentFullName=Common Tests
+ComponentCompetency=Common Tests
+JavaCompile.1=srcjar
+BuildVerification.1=call webbvt.bat
+Export.jarFile=commontests.jar
diff --git a/tests/org.eclipse.wst.common.tests/build/package.xml b/tests/org.eclipse.wst.common.tests/build/package.xml
new file mode 100644
index 0000000..d5988c4
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/build/package.xml
@@ -0,0 +1,17 @@
+<project name="org.eclipse.wst.common.tests" default="packagingPlugin" basedir="./..">
+ <target name="init">
+ <property name="packageDir" value=""/>
+ <property name="plugin.directory" value="${basedir}"/>
+ <property name="plugin.id" value="org.eclipse.wst.common.tests"/>
+ <property name="plugin.version" value=""/>
+ </target>
+ <target name="packagingPlugin" depends="init">
+ <echo message="${plugin.id}"/>
+ <copy todir="${packageDir}/plugins/${plugin.id}_${plugin.version}">
+ <fileset dir="${plugin.directory}">
+ <include name="plugin.xml"/>
+ <include name="runtime/commontests.jar"/>
+ </fileset>
+ </copy>
+ </target>
+</project>
diff --git a/tests/org.eclipse.wst.common.tests/build/wsBuild.xml b/tests/org.eclipse.wst.common.tests/build/wsBuild.xml
new file mode 100644
index 0000000..77c0b82
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/build/wsBuild.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<!DOCTYPE project [
+ <!ENTITY baseBuild SYSTEM "file:../../wsBuildDef.xml">
+]>
+
+<project name="buildPlugin" default="build" basedir="./..">
+
+<!-- include the common xml build file -->
+&baseBuild;
+
+<target name="build" depends="prepare" if="plugin.id">
+ <antcall target="buildjar">
+ <param name="jarname" value="${defaultjarname}"/>
+ <param name="jarclasspath" value="${plugin.classpath}"/>
+ </antcall>
+</target>
+</project>
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/extras/MemoryUsageTestSuite.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/extras/MemoryUsageTestSuite.java
new file mode 100644
index 0000000..c1d7c96
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/extras/MemoryUsageTestSuite.java
@@ -0,0 +1,114 @@
+package org.eclipse.wst.common.extras;
+
+
+import junit.framework.TestResult;
+import junit.framework.TestSuite;
+/*
+ * Licensed Material - Property of IBM
+ * (C) Copyright IBM Corp. 2002 - All Rights Reserved.
+ * US Government Users Restricted Rights - Use, duplication or disclosure
+ * restricted by GSA ADP Schedule Contract with IBM Corp.
+ */
+public class MemoryUsageTestSuite extends TestSuite {
+ //protected String GLOBAL_OUTPUT_FILENAME = "d:/eclipse/common_archive/memoryUsage/CommonArchive_MOF5.out";
+ protected String GLOBAL_OUTPUT_FILENAME = "./EMF_Data.txt";
+ protected boolean TRACK_MEMORY = true;
+ protected String outputFileName;
+ /**
+ * Constructor for MemoryUsageTestSuite.
+ */
+ public MemoryUsageTestSuite() {
+ super();
+ }
+ /**
+ * Constructor for MemoryUsageTestSuite.
+ * @param theClass
+ */
+ public MemoryUsageTestSuite(Class theClass) {
+ super(theClass);
+ }
+ /**
+ * Constructor for MemoryUsageTestSuite.
+ * @param name
+ */
+ public MemoryUsageTestSuite(String name) {
+ super(name);
+ }
+
+ public void run(TestResult result) {
+// TimerStep step = null;
+// if (TRACK_MEMORY) {
+// step = TimerStep.instance();
+// step.setLogFile(getOutputName());
+// if (!step.isOn())
+// step.setIsOn(true);
+// step.write("", "Before " + getMemoryName() + " Test Run");
+// step.totalMemory(0);
+// step.usedMemory(0);
+// }
+// super.run(result);
+// if (TRACK_MEMORY) {
+// step.write("", "After " + getMemoryName() + " Test Run");
+// step.totalMemory(0);
+// step.usedMemory(0);
+// }
+
+ super.run(result);
+ }
+
+ /**
+ * Method getOutputName.
+ * @return String
+ */
+ private String getOutputName() {
+ if (outputFileName != null && outputFileName.length() > 0)
+ return outputFileName;
+ return GLOBAL_OUTPUT_FILENAME;
+ }
+
+
+ /**
+ * Method getMemoryName.
+ * @return String
+ */
+ private String getMemoryName() {
+ if (getName() != null && getName().length() > 0)
+ return getName();
+ if (getClass() != null)
+ return getClass().getName();
+ return "Unknown Test";
+ }
+
+ /**
+ * Sets the outputFileName.
+ * @param outputFileName The outputFileName to set
+ */
+ public void setOutputFileName(String outputFileName) {
+ this.outputFileName = outputFileName;
+ }
+
+ /**
+ * Returns the gLOBAL_OUTPUT_FILENAME.
+ * @return String
+ */
+ public String getGLOBAL_OUTPUT_FILENAME() {
+ return GLOBAL_OUTPUT_FILENAME;
+ }
+
+ /**
+ * Sets the gLOBAL_OUTPUT_FILENAME.
+ * @param gLOBAL_OUTPUT_FILENAME The fileName to set
+ */
+ public void setGLOBAL_OUTPUT_FILENAME(String fileName) {
+ GLOBAL_OUTPUT_FILENAME = fileName;
+ }
+
+ /**
+ * Sets the tRACK_MEMORY.
+ * @param tRACK_MEMORY The aBoolean to set
+ */
+ public void setTRACK_MEMORY(boolean aBoolean) {
+ TRACK_MEMORY = aBoolean;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/AssertWarn.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/AssertWarn.java
new file mode 100644
index 0000000..1b7e79a
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/AssertWarn.java
@@ -0,0 +1,286 @@
+package org.eclipse.wst.common.tests;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+
+public class AssertWarn extends Assert {
+ private static List<AssertionFailedError> warnings = new ArrayList<AssertionFailedError>();
+
+ public static void warnEquals(boolean expected, boolean actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(byte expected, byte actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(char expected, char actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(double expected, double actual, double delta) {
+ try{
+ assertEquals(expected, actual, delta);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(float expected, float actual, float delta) {
+ try{
+ assertEquals(expected, actual, delta);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(int expected, int actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(Object expected, Object actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(long expected, long actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(short expected, short actual) {
+ try{
+ assertEquals(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, boolean expected, boolean actual) {
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, byte expected, byte actual) {
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, char expected, char actual) {
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, double expected, double actual, double delta) {
+ try{
+ assertEquals(message, expected, actual, delta);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, float expected, float actual, float delta) {
+ try{
+ assertEquals(message, expected, actual, delta);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, int expected, int actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, Object expected, Object actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, String expected, String actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, long expected, long actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnEquals(String message, short expected, short actual){
+ try{
+ assertEquals(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnFalse(boolean condition){
+ try{
+ assertFalse(condition);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnFalse(String message, boolean condition){
+ try{
+ assertFalse(message, condition);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNotNull(Object object) {
+ try{
+ assertNotNull(object);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNotNull(String message, Object object) {
+ try{
+ assertNotNull(message, object);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNotSame(Object expected, Object actual) {
+ try{
+ assertNotSame(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNotSame(String message, Object expected, Object actual) {
+ try{
+ assertNotSame(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNull(Object object) {
+ try{
+ assertNull(object);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnNull(String message, Object object) {
+ try{
+ assertNull(message, object);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnSame(Object expected, Object actual) {
+ try{
+ assertSame(expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnSame(String message, Object expected, Object actual) {
+ try{
+ assertSame(message, expected, actual);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnTrue(boolean condition){
+ try{
+ assertTrue(condition);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warnTrue(String message, boolean condition){
+ try{
+ assertTrue(message, condition);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warn() {
+ try{
+ fail();
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void warn(String message) {
+ try{
+ fail(message);
+ } catch(AssertionFailedError e){
+ warnings.add(e);
+ }
+ }
+
+ public static void clearWarnings(){
+ warnings.clear();
+ }
+
+ public static List <AssertionFailedError> getWarnings() {
+ return Collections.unmodifiableList(warnings);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/BaseTestCase.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/BaseTestCase.java
new file mode 100644
index 0000000..fd028ce
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/BaseTestCase.java
@@ -0,0 +1,259 @@
+package org.eclipse.wst.common.tests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IStatus;
+
+public class BaseTestCase extends TestCase {
+
+ private static boolean fFailOnLoggedStatus = true;
+
+ /**
+ *
+ */
+ public BaseTestCase() {
+ super();
+ }
+
+ /**
+ * @param name
+ */
+ public BaseTestCase(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ public void setUpTest() throws Exception {
+ setUp();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public final void tearDownTest() throws Exception {
+ tearDown();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#runBare()
+ */
+ public final void runCoreTest() throws Throwable {
+ runTest();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ //TODO register any plugins with the JUnitLogListener here that you want to fail on when their log is written too
+ //EX: CommonTestsPlugin.instance.getLog().addLogListener(JUnitLogListener.INSTANCE);
+
+ //list of plugins whos logs if written to will cause JUnits to fail
+// ArrayList<String> pluginIDs = new ArrayList<String>();
+
+ //TODO uncomment these to make tests start failing on logged errors
+// pluginIDs.add(JEMUtilPlugin.ID);
+// pluginIDs.add("org.eclipse.jst.common.annotations.controller");
+// pluginIDs.add("org.eclipse.jst.common.annotations.core");
+// pluginIDs.add("org.eclipse.jst.common.annotations.ui");
+// pluginIDs.add(CommonFrameworksPlugin.PLUGIN_ID);
+// pluginIDs.add(EJBUIPlugin.PLUGIN_ID);
+// pluginIDs.add(J2EEPlugin.PLUGIN_ID);
+// pluginIDs.add(J2EECorePlugin.PLUGIN_ID);
+// pluginIDs.add(EjbPlugin.PLUGIN_ID);
+// pluginIDs.add(ModelPlugin.PLUGINID);
+// pluginIDs.add("org.eclipse.jst.j2ee.ejb.annotations.emitter");
+// pluginIDs.add(XDocletAnnotationPlugin.PLUGINID);
+// pluginIDs.add(JcaPlugin.PLUGIN_ID);
+// pluginIDs.add(JCAUIPlugin.PLUGIN_ID);
+// pluginIDs.add(J2EENavigatorPlugin.PLUGIN_ID);
+// pluginIDs.add(J2EEUIPlugin.PLUGIN_ID);
+// pluginIDs.add(WebPlugin.PLUGIN_ID);
+// pluginIDs.add(WebServicePlugin.PLUGIN_ID);
+// pluginIDs.add(WebServiceUIPlugin.PLUGIN_ID);
+// pluginIDs.add(JEEPlugin.PLUGIN_ID);
+// pluginIDs.add(Activator.PLUGIN_ID);
+// pluginIDs.add(J2EEUIPlugin.PLUGIN_ID);
+// pluginIDs.add(org.eclipse.jst.jee.web.Activator.PLUGIN_ID);
+// pluginIDs.add(ServletUIPlugin.PLUGIN_ID);
+// pluginIDs.add(PropertiesValidatorPlugin.PLUGIN_ID);
+// pluginIDs.add(BVTValidationPlugin.PLUGIN_ID);
+// pluginIDs.add(EcoreUtilitiesPlugin.ID);
+// pluginIDs.add(EMFWorkbenchEditPlugin.ID);
+// pluginIDs.add(WTPCommonPlugin.PLUGIN_ID);
+// pluginIDs.add(WTPUIPlugin.PLUGIN_ID);
+// pluginIDs.add(ModulecorePlugin.PLUGIN_ID);
+// pluginIDs.add(ValidationPlugin.PLUGIN_ID);
+// pluginIDs.add(ValidationUIPlugin.PLUGIN_ID);
+// pluginIDs.add(WSTWebPlugin.PLUGIN_ID);
+// pluginIDs.add(WSTWebUIPlugin.PLUGIN_ID);
+// pluginIDs.add("org.eclipse.wst.xml.core");
+// pluginIDs.add("org.eclipse.jem");
+// pluginIDs.add(BeaninfoPlugin.PI_BEANINFO_PLUGINID);
+// pluginIDs.add("org.eclipse.jem.proxy");
+// pluginIDs.add("org.eclipse.jem.ui");
+// pluginIDs.add("org.eclipse.jem.workbench");
+// pluginIDs.add("org.eclipse.jem.tests");
+// pluginIDs.add("org.eclipse.jst.standard.schemas");
+// pluginIDs.add(CommonTestsPlugin.PLUGIN_ID);
+// pluginIDs.add("org.eclipse.wst.common.tests.collector");
+// pluginIDs.add("org.eclipse.wst.common.tests.ui");
+// pluginIDs.add("org.eclipse.jst.j2ee.core.tests");
+// pluginIDs.add("org.eclipse.jst.j2ee.core.tests.performance");
+// pluginIDs.add("org.eclipse.jst.j2ee.tests");
+// pluginIDs.add("org.eclipse.jst.j2ee.tests.performance");
+// pluginIDs.add("org.eclipse.jst.servlet.tests");
+
+// for(String pluginID : pluginIDs) {
+// InternalPlatform.getDefault().getLog(InternalPlatform.getDefault().getBundle(pluginID)).addLogListener(JUnitLogListener.INSTANCE);
+// }
+ }
+
+ /**
+ * Set weather to fail junit tests on status logged to plugins registered with the <code>JUnitLogListener</code>
+ * Default value is set to true.
+ *
+ * @param failOnLoggedStatus
+ * if <code>true</code> then fail tests when statuses logged to plugins registered with <code>JUnitLogListener</code>,
+ * if <code>false</code> then dont fail on logged statuses.
+ */
+ protected static void failOnLoggedStatus(boolean failOnLoggedStatus) {
+ fFailOnLoggedStatus = failOnLoggedStatus;
+ }
+
+// @Override
+// public void run(TestResult result) {
+// try{
+// AssertWarn.clearWarnings();
+// super.run(result);
+//
+// } finally {
+// List <StackTraceElement> stackTrace = new ArrayList<StackTraceElement>();
+//
+// //check to see if this test already failed with an error
+// //if so add error to stack trace
+// Enumeration errorsEnum = result.errors();
+// TestFailure errorOrFailure = null;
+// boolean hadError = false;
+// for(int i = 0; errorsEnum.hasMoreElements() && !hadError; i++) {
+// Object o = errorsEnum.nextElement();
+// errorOrFailure = (TestFailure)o;
+// if(errorOrFailure.failedTest() == this) {
+// hadError = true;
+//
+// Throwable thrown = errorOrFailure.thrownException();
+// List<StackTraceElement> errorTrace = Arrays.asList(thrown.getStackTrace());
+// stackTrace.addAll(errorTrace);
+// }
+// }
+//
+// //check to see if this test already failed with a failure if it didn't
+// // fail with an error. if so add failure to stack trace
+// boolean hadFailure = false;
+// if(!hadError) {
+// Enumeration failuresEnum = result.failures();
+// for(int i = 0; failuresEnum.hasMoreElements() && !hadFailure; i++) {
+// Object o = failuresEnum.nextElement();
+// errorOrFailure = (TestFailure)o;
+// if(errorOrFailure.failedTest() == this) {
+// hadFailure = true;
+//
+// Throwable thrown = errorOrFailure.thrownException();
+// List<StackTraceElement> failureTrace = Arrays.asList(thrown.getStackTrace());
+// stackTrace.addAll(failureTrace);
+// }
+// }
+// }
+//
+// //add any warnings to the stack trace and deal with if this test already failed
+// List <AssertionFailedError> warnings = AssertWarn.getWarnings();
+// boolean hadWarnings = warnings.size() != 0;
+// if(hadWarnings) {
+// int warningNum = 1;
+// List<StackTraceElement> warningTrace = null;
+// for(AssertionFailedError e : warnings){
+// stackTrace.add(new StackTraceElement("---------->","", "WARNING MESSAGE: " + e.getMessage() + ") (WARNING NUMBER", warningNum++));
+//
+// warningTrace = Arrays.asList(e.getStackTrace());
+// stackTrace.addAll(warningTrace);
+// }
+// }
+//
+// //add any logged statuses to the stack trace, as long as fFailOnLoggedStatus == true
+// HashMap<IStatus,String> loggedStatuses = JUnitLogListener.INSTANCE.getLoggedStatuses();
+// boolean hadLoggedStatuses = loggedStatuses.size() != 0;
+// if(hadLoggedStatuses && fFailOnLoggedStatus) {
+// int loggedMessageNum = 1;
+// List<StackTraceElement> loggedMessageTrace = null;
+//
+// Set<IStatus> loggedStatusesKeys = loggedStatuses.keySet();
+// String statusType;
+// for(IStatus status : loggedStatusesKeys) {
+// stackTrace.add(new StackTraceElement("---------->","", "LOGGED " + statusTypeToString(status.getSeverity()) + " STATUS: " + loggedStatuses.get(status) + ": " + status.getMessage() + ") (LOGGED STATUS NUMBER", loggedMessageNum++));
+//
+// if(status.getException() != null) {
+// loggedMessageTrace = Arrays.asList(status.getException().getStackTrace());
+// stackTrace.addAll(loggedMessageTrace);
+// }
+// }
+// }
+//
+// //deal with making a new formated failure and added it to the result
+// String message = "";
+// String warningsMessage = "Test had " + warnings.size() + " warnings occur";
+// String loggedStatusesMessage = "Test logged " + loggedStatuses.size() + " statuses";
+// if(hadError || hadFailure) {
+// message = errorOrFailure.exceptionMessage();
+//
+// if(hadWarnings) {
+// message += " (" + warningsMessage + ")";
+// }
+//
+// if(hadLoggedStatuses && fFailOnLoggedStatus) {
+// message += " (" + loggedStatusesMessage + ")";
+// }
+// } else if(hadWarnings) {
+// message = warningsMessage;
+//
+// if(hadLoggedStatuses && fFailOnLoggedStatus) {
+// message += " (" + loggedStatusesMessage + ")";
+// }
+// } else if(hadLoggedStatuses && fFailOnLoggedStatus) {
+// message = loggedStatusesMessage;
+// }
+//
+// if(hadError || hadFailure || hadWarnings || (hadLoggedStatuses && fFailOnLoggedStatus)) {
+// AssertionFailedError error = new AssertionFailedError(message);
+// StackTraceElement[] stackTraceArray = stackTrace.toArray(new StackTraceElement[stackTrace.size()]);
+// error.setStackTrace(stackTraceArray);
+//
+// if(hadError) {
+// result.addError(this, error);
+// } else {
+// result.addFailure(this, error);
+// }
+// }
+//
+//
+// }
+// }
+
+ private String statusTypeToString(int statusType) {
+ String sStatusType = "";
+ switch (statusType) {
+ case IStatus.ERROR :
+ sStatusType = "ERROR";
+ break;
+ case IStatus.CANCEL :
+ sStatusType = "CANCEL";
+ break;
+ case IStatus.WARNING :
+ sStatusType = "WARNING";
+ break;
+ }
+
+ return sStatusType;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/CommonTestsPlugin.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/CommonTestsPlugin.java
new file mode 100644
index 0000000..e52465a
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/CommonTestsPlugin.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests;
+
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
+import org.osgi.framework.BundleContext;
+
+public class CommonTestsPlugin extends Plugin {
+ public static String PLUGIN_ID = "org.eclipse.wst.common.tests";
+ public static CommonTestsPlugin instance = null;
+ public IExtensionPoint dataModelVerifierExt = null;
+
+ /**
+ * @param descriptor
+ */
+ public CommonTestsPlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ instance = this;
+ dataModelVerifierExt = descriptor.getExtensionPoint("DataModelVerifier");
+ }
+
+ // default constructor for use of start() and stop()
+ public CommonTestsPlugin()
+ {
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ instance = this;
+ Platform.getExtensionRegistry().getExtensionPoint(PLUGIN_ID, "DataModelVerifier");
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ instance = null;
+ super.stop(context);
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifier.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifier.java
new file mode 100644
index 0000000..1d03d53
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifier.java
@@ -0,0 +1,22 @@
+/*
+ * Created on Jan 5, 2004
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+package org.eclipse.wst.common.tests;
+
+
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+
+/**
+ * @author Administrator
+ *
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+public class DataModelVerifier {
+
+ public void verify(IDataModel model) throws Exception {
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierFactory.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierFactory.java
new file mode 100644
index 0000000..a9b6501
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierFactory.java
@@ -0,0 +1,129 @@
+/*
+ * Created on Jan 5, 2004
+ *
+ * To change the template for this generated file go to Window - Preferences - Java - Code
+ * Generation - Code and Comments
+ */
+package org.eclipse.wst.common.tests;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.jem.util.RegistryReader;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+
+/**
+ * @author Administrator
+ * @author Ian Tewksbury (ictewksb@us.ibm.com)
+ *
+ * To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Generation - Code and Comments
+ */
+public class DataModelVerifierFactory extends RegistryReader{
+ static final String DATA_MODEL_VERIFIER_LIST_EXT = "dataModelVerifierList";
+ static final String LIST_CLASS = "listClass";
+ private Map dataModelVerifiersMap = null;
+ private static DataModelVerifierFactory instance = null;
+ private DataModelVerifier defaultDataModelVerifier = new DataModelVerifier();
+
+ public DataModelVerifierFactory() {
+ super(CommonTestsPlugin.PLUGIN_ID, "DataModelVerifier");//$NON-NLS-1$
+ }
+
+ public static DataModelVerifierFactory getInstance() {
+ if (instance == null){
+ instance = new DataModelVerifierFactory();
+ instance.readRegistry();
+ }
+ return instance;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jem.util.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ public boolean readElement(IConfigurationElement element) {
+ if (!element.getName().equals(DATA_MODEL_VERIFIER_LIST_EXT))
+ return false;
+ try {
+ DataModelVerifierList list = (DataModelVerifierList)element.createExecutableExtension(LIST_CLASS);
+ addToDataModelVerifiersMap(list.getDataModelVerifiers());
+ }
+ catch(CoreException e){
+ e.printStackTrace();
+ }
+ return true;
+
+ }
+
+ public void addToDataModelVerifiersMap(Map dataModelVerifiers){
+ if (dataModelVerifiersMap == null)
+ dataModelVerifiersMap = initDataModelVerifiersMap();
+ dataModelVerifiersMap.putAll(dataModelVerifiers);
+ }
+
+ /**
+ * @return Returns the dataModelVerifiersMap.
+ */
+ public Map getDataModelVerifiersMap() {
+ if (dataModelVerifiersMap == null) {
+ dataModelVerifiersMap = initDataModelVerifiersMap();
+ }
+ return dataModelVerifiersMap;
+ }
+
+ protected Map initDataModelVerifiersMap() {
+ return new HashMap();
+ }
+
+ /**
+ * @return Returns the defaultDataModelVerifier.
+ */
+ protected DataModelVerifier getDefaultDataModelVerifier() {
+ return defaultDataModelVerifier;
+ }
+
+ /*private void loadConfiguration() {
+ //TestCollectorPlugin plugin = TestCollectorPlugin.instance;
+ CommonTestsPlugin plugin = CommonTestsPlugin.instance;
+ IExtension[] dataModelVerifierExts = plugin.dataModelVerifierExt.getExtensions();
+
+ for (int i = 0; i < dataModelVerifierExts.length; i++) {
+ IExtension extension = dataModelVerifierExts[i];
+ IConfigurationElement[] factories = extension.getConfigurationElements();
+ for (int j = 0; j < factories.length; j++) {
+ try {
+ IConfigurationElement element = factories[j];
+ DataModelVerifierList list = (DataModelVerifierList)element.createExecutableExtension("listClass");
+ //ClassLoader classLoader = (ClassLoader) extension.getDeclaringPluginDescriptor().getPluginClassLoader();
+ //DataModelVerifierList list = (DataModelVerifierList) classLoader.loadClass(factoryClass).newInstance();
+ addToDataModelVerifiersMap(list.getDataModelVerifiers());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }*/
+
+ public DataModelVerifier createVerifier(IDataModel model) {
+ DataModelVerifier verifier = getDefaultDataModelVerifier();
+
+ if (model != null) {
+ Object verifierObject = getDataModelVerifiersMap().get(model.getID());
+ if(verifierObject != null){
+ try {
+ if(verifierObject instanceof Class){
+ return (DataModelVerifier)((Class)verifierObject).newInstance();
+ } else if(verifierObject instanceof String){
+ Class verifierClass = Class.forName((String)verifierObject);
+ verifier = (DataModelVerifier) verifierClass.newInstance();
+ }
+ } catch (Exception e) {
+ verifier = getDefaultDataModelVerifier();
+ }
+ }
+ }
+ return verifier;
+ }
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierList.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierList.java
new file mode 100644
index 0000000..f386588
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/DataModelVerifierList.java
@@ -0,0 +1,12 @@
+package org.eclipse.wst.common.tests;
+
+import java.util.Map;
+
+/**
+ * @author eteration
+ */
+public abstract class DataModelVerifierList {
+
+ public abstract Map getDataModelVerifiers();
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/JUnitLogListener.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/JUnitLogListener.java
new file mode 100644
index 0000000..7b3f9f2
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/JUnitLogListener.java
@@ -0,0 +1,42 @@
+/**
+ *
+ */
+package org.eclipse.wst.common.tests;
+
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * @author itewk
+ *
+ */
+public class JUnitLogListener implements ILogListener {
+
+ public static final JUnitLogListener INSTANCE = new JUnitLogListener();
+ private HashMap<IStatus, String> loggedStatuses = new HashMap<IStatus, String>();
+
+ private JUnitLogListener() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.ILogListener#logging(org.eclipse.core.runtime.IStatus, java.lang.String)
+ */
+ public void logging(IStatus status, String plugin) {
+ int severity = status.getSeverity();
+ if(severity == IStatus.CANCEL || severity == IStatus.ERROR || severity == IStatus.WARNING) {
+ loggedStatuses.put(status, plugin);
+ }
+ }
+
+ /**
+ *
+ * @return the current list of logged statuses, clears list after return.
+ */
+ public HashMap<IStatus,String> getLoggedStatuses() {
+ HashMap<IStatus,String> returnStatuses = new HashMap<IStatus,String>(loggedStatuses);
+ loggedStatuses.clear();
+ return returnStatuses;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/LogUtility.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/LogUtility.java
new file mode 100644
index 0000000..f3d028e
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/LogUtility.java
@@ -0,0 +1,96 @@
+/*
+ * Created on Jun 30, 2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.eclipse.wst.common.tests;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * @author jsholl
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class LogUtility implements ILogListener {
+
+ private static LogUtility instance = new LogUtility();
+ private ArrayList loggedMessages = new ArrayList();
+ private boolean logging = false;
+
+ private LogUtility() {
+ registerPlugins();
+ }
+
+ private void registerPlugins() {
+// TODO DCB Disable for now due to other plugins failing.
+// IPluginRegistry registry = Platform.getPluginRegistry();
+// IPluginDescriptor[] descriptors = registry.getPluginDescriptors();
+// for (int i = 0; i < descriptors.length; i++) {
+// try {
+// Plugin plugin = descriptors[i].getPlugin();
+// ILog log = plugin.getLog();
+// log.addLogListener(this);
+// } catch (Exception e) {
+// }
+// }
+ }
+
+ public static LogUtility getInstance() {
+ return instance;
+ }
+
+ public void clearLogs() {
+ loggedMessages.clear();
+ }
+
+ public void resetLogging() {
+ stopLogging();
+ clearLogs();
+ startLogging();
+ }
+
+ public void startLogging() {
+ logging = true;
+ }
+
+ public void stopLogging() {
+ logging = false;
+ }
+
+ public void verifyNoWarnings() {
+ //TODO DCB Disable for now due to other plugins failing.
+// String warnings = "";
+// for (int i = 0; i < loggedMessages.size(); i++) {
+// IStatus status = (IStatus) loggedMessages.get(i);
+// if (status.getSeverity() == IStatus.WARNING || status.getSeverity() == IStatus.ERROR) {
+// warnings += "\nLogUtility: " + ((status.getSeverity() == IStatus.WARNING) ? "WARNING " : "ERROR ");
+// warnings += "\nFrom plugin: " + ((null != status.getPlugin()) ? status.getPlugin() : "null");
+// warnings += "\nMessage: " + ((null != status.getMessage()) ? status.getMessage() : "null");
+// warnings += "\nStack:\n";
+// try {
+// ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+// status.getException().printStackTrace(new PrintStream(outputStream));
+// warnings += outputStream.toString();
+// } catch (Exception e) {
+// warnings += " Stack not available";
+// }
+//
+// }
+// }
+// if (!warnings.equals("")) {
+// Assert.fail(warnings);
+// }
+ }
+
+ public void logging(IStatus status, String plugin) {
+ if (logging) {
+ loggedMessages.add(status);
+ }
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/OperationTestCase.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/OperationTestCase.java
new file mode 100644
index 0000000..ad58348
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/OperationTestCase.java
@@ -0,0 +1,275 @@
+/*
+ * Created on Nov 6, 2003
+ *
+ * To change the template for this generated file go to Window>Preferences>Java>Code Generation>Code and
+ * Comments
+ */
+package org.eclipse.wst.common.tests;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IWorkspaceDescription;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.common.frameworks.internal.datamodel.IWorkspaceRunnableWithStatus;
+import org.eclipse.wst.common.internal.emf.resource.RendererFactory;
+import org.eclipse.wst.validation.internal.operations.ValidationBuilder;
+
+
+/**
+ * @author jsholl
+ * @author itewk
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public abstract class OperationTestCase extends BaseTestCase {
+
+ public static final String VALIDATOR_JOB_FAMILY = "validators";
+ public static String fileSep = System.getProperty("file.separator"); //$NON-NLS-1$
+ public static IStatus OK_STATUS = new Status(IStatus.OK, "org.eclipse.jem.util", 0, "OK", null); //$NON-NLS-1$ //$NON-NLS-2$
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ try{
+ deleteAllProjects();
+ } finally {
+ RendererFactory.getDefaultRendererFactory().setValidating(false);
+ }
+ }
+
+ public static void deleteAllProjects() {
+ try {
+ waitOnJobs();
+ } catch (InterruptedException e1) {
+
+ }
+ IWorkspaceRunnableWithStatus workspaceRunnable = new IWorkspaceRunnableWithStatus(null) {
+ public void run(IProgressMonitor pm) throws CoreException {
+ try {
+ ProjectUtility.deleteAllProjects();
+ } catch (Exception e) {
+ }
+ }
+ };
+ try {
+ ResourcesPlugin.getWorkspace().run(workspaceRunnable, null);
+ } catch (CoreException e) {
+
+ }
+ }
+
+ public OperationTestCase() {
+ super("OperationsTestCase"); //$NON-NLS-1$
+ }
+
+ public OperationTestCase(String name) {
+ super(name);
+ }
+
+ public static void runAndVerify(IDataModel dataModel) throws Exception {
+ OperationTestCase.runAndVerify(dataModel, true, true);
+ }
+ public static void runDataModel(IDataModel dataModel) throws Exception {
+ OperationTestCase.runDataModel(dataModel, true, true);
+ }
+
+ public static void runDataModel(IDataModel dataModel, boolean checkTasks, boolean checkLog) throws Exception {
+ OperationTestCase.runDataModel(dataModel, checkTasks, checkLog, null, true, false);
+ }
+
+ public static void runAndVerify(IDataModel dataModel, boolean checkTasks, boolean checkLog) throws Exception {
+ runAndVerify(dataModel, checkTasks, checkLog, null, true, false);
+ }
+
+ public static void runAndVerify(IDataModel dataModel, boolean checkTasks, boolean checkLog, boolean waitForBuildToComplete) throws Exception {
+ runAndVerify(dataModel, checkTasks, checkLog, null, true, waitForBuildToComplete);
+ }
+
+ public static void runAndVerify(IDataModel dataModel, boolean checkTasks, boolean checkLog, List errorOKList, boolean reportIfExpectedErrorNotFound) throws Exception {
+ runAndVerify(dataModel, checkTasks, checkLog, errorOKList, reportIfExpectedErrorNotFound, false);
+ }
+
+ public static void runAndVerify(IDataModel dataModel, boolean checkTasks, boolean checkLog, List errorOKList, boolean reportIfExpectedErrorNotFound, boolean waitForBuildToComplete) throws Exception {
+ runAndVerify(dataModel, checkTasks, checkLog, errorOKList, reportIfExpectedErrorNotFound, waitForBuildToComplete, false);
+ }
+
+ public static void runDataModel(IDataModel dataModel, boolean checkTasks, boolean checkLog, List errorOKList, boolean reportIfExpectedErrorNotFound, boolean waitForBuildToComplete) throws Exception {
+ runDataModel(dataModel, checkTasks, checkLog, errorOKList, reportIfExpectedErrorNotFound, waitForBuildToComplete, false);
+ }
+
+ /**
+ * Guaranteed to close the dataModel
+ *
+ * @param dataModel
+ * @throws Exception
+ */
+ public static void runAndVerify(IDataModel dataModel, boolean checkTasks, boolean checkLog, List errorOKList, boolean reportIfExpectedErrorNotFound, boolean waitForBuildToComplete, boolean removeAllSameTypesOfErrors) throws Exception {
+ PostBuildListener listener = null;
+ IWorkspaceDescription desc = null;
+ try {
+ if (waitForBuildToComplete) {
+ listener = new PostBuildListener();
+ desc = ResourcesPlugin.getWorkspace().getDescription();
+ desc.setAutoBuilding(false);
+ ResourcesPlugin.getWorkspace().setDescription(desc);
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_BUILD);
+ }
+
+ //deal with weather to fail on logged statuses or not
+ BaseTestCase.failOnLoggedStatus(checkLog);
+
+ IStatus operationStatus = dataModel.getDefaultOperation().execute(new NullProgressMonitor(), null);
+
+ if (waitForBuildToComplete) {
+ desc.setAutoBuilding(true);
+ ResourcesPlugin.getWorkspace().setDescription(desc);
+ while (!listener.isBuildComplete()) {
+ Thread.sleep(3000);// do nothing till all the jobs are completed
+ }
+ }
+
+ // bug 173933 - runAndVerify() fails to check return IStatus
+ if (operationStatus.getSeverity() == IStatus.ERROR) {
+ Throwable throwable = operationStatus.getException();
+ String throwableStr = null;
+ if(throwable != null){
+ throwable.printStackTrace();
+ throwableStr = getStackTrace(throwable);
+ }
+ if(throwableStr == null){
+ throwableStr = "no message";
+ }
+ Assert.fail(operationStatus.getMessage()+"\n caused by: "+throwableStr);
+ }
+
+ //run data model verifications
+ DataModelVerifierFactory verifierFactory = DataModelVerifierFactory.getInstance();
+ DataModelVerifier verifier = verifierFactory.createVerifier(dataModel);
+ verifier.verify(dataModel);
+
+ if (checkTasks && (errorOKList == null || errorOKList.isEmpty())) {
+ checkTasksList();
+ } else if (checkTasks && errorOKList != null && !errorOKList.isEmpty()) {
+ TaskViewUtility.verifyErrors(errorOKList, reportIfExpectedErrorNotFound, removeAllSameTypesOfErrors);
+ }
+
+ } finally {
+ if (listener != null)
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
+ dataModel.dispose();
+ }
+ }
+
+ public static String getStackTrace(Throwable throwable){
+ StringBuffer buffer = new StringBuffer(throwable.toString()+"\n");
+ StackTraceElement[] stack = throwable.getStackTrace();
+ for (int i=0; i<stack.length; i++)
+ buffer.append("\tat " + stack[i]+"\n");
+
+ StackTraceElement[] parentStack = stack;
+ throwable = throwable.getCause();
+ while (throwable != null) {
+ buffer.append("Caused by: ");
+ buffer.append(throwable);
+ buffer.append("\n");
+ StackTraceElement[] currentStack = throwable.getStackTrace();
+ parentStack = currentStack;
+ throwable = throwable.getCause();
+ }
+ return buffer.toString();
+ }
+ /**
+ * Guaranteed to close the dataModel
+ *
+ * @param dataModel
+ * @throws Exception
+ */
+ public static void runDataModel(IDataModel dataModel, boolean checkTasks, boolean checkLog, List errorOKList, boolean reportIfExpectedErrorNotFound, boolean waitForBuildToComplete, boolean removeAllSameTypesOfErrors) throws Exception {
+ PostBuildListener listener = null;
+ IWorkspaceDescription desc = null;
+ try {
+ if (waitForBuildToComplete) {
+ listener = new PostBuildListener();
+ desc = ResourcesPlugin.getWorkspace().getDescription();
+ desc.setAutoBuilding(false);
+ ResourcesPlugin.getWorkspace().setDescription(desc);
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_BUILD);
+ }
+
+ //deal with weather to fail on logged statuses or not
+ BaseTestCase.failOnLoggedStatus(checkLog);
+
+ dataModel.getDefaultOperation().execute(new NullProgressMonitor(), null);
+
+ if (waitForBuildToComplete) {
+ desc.setAutoBuilding(true);
+ ResourcesPlugin.getWorkspace().setDescription(desc);
+ while (!listener.isBuildComplete()) {
+ Thread.sleep(3000);// do nothing till all the jobs are completeled
+ }
+ }
+ if (checkTasks && (errorOKList == null || errorOKList.isEmpty())) {
+ checkTasksList();
+ } else if (checkTasks && errorOKList != null && !errorOKList.isEmpty()) {
+ TaskViewUtility.verifyErrors(errorOKList, reportIfExpectedErrorNotFound, removeAllSameTypesOfErrors);
+ }
+
+ } finally {
+ if (listener != null)
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
+ dataModel.dispose();
+ }
+ }
+
+
+ protected static void checkTasksList() {
+ //TaskViewUtility.verifyNoErrors();
+ }
+
+ public static void verifyValidDataModel(IDataModel dataModel) {
+ IStatus status = dataModel.validate();
+
+ if (!status.isOK() && status.getSeverity() == IStatus.ERROR) {
+ Assert.assertTrue("DataModel is invalid operation will not run:" + status.toString(), false); //$NON-NLS-1$
+ }
+ }
+
+ public static void verifyInvalidDataModel(IDataModel dataModel) {
+ IStatus status = dataModel.validate();
+ if (status.isOK()) {
+ Assert.assertTrue("DataModel should be invalid:" + status.getMessage(), false); //$NON-NLS-1$
+ }
+ }
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ // Wait for all validation jobs to end before ending test....
+ waitOnJobs();
+
+ }
+
+ public static void waitOnJobs() throws InterruptedException {
+ IProject[] projects = ProjectUtility.getAllProjects();
+ try {
+ for (int i = 0; i < projects.length; i++) {
+ IProject project = projects[i];
+ Job.getJobManager().join(project.getName() + VALIDATOR_JOB_FAMILY,null);
+ }
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_BUILD,null);
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD,null);
+ Job.getJobManager().join(ValidationBuilder.FAMILY_VALIDATION_JOB,null);
+ } catch (InterruptedException ex) {
+
+ }
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/PlatformModuleURLTest.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/PlatformModuleURLTest.java
new file mode 100644
index 0000000..cc97f6c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/PlatformModuleURLTest.java
@@ -0,0 +1,40 @@
+package org.eclipse.wst.common.tests;
+
+import java.net.URL;
+import java.net.URLConnection;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.wst.common.componentcore.internal.impl.PlatformURLModuleConnection;
+
+public class PlatformModuleURLTest extends TestCase {
+
+ public PlatformModuleURLTest(String name) {
+ super(name);
+ }
+
+
+ public static Test suite() {
+ return new TestSuite(PlatformModuleURLTest.class);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ PlatformURLModuleConnection.startup();
+ }
+
+ /**
+ *
+ */
+ public void testURLResolve() throws Exception {
+ URL url = new URL("platform:/module:/MyModule/META-INF/ejb-jar.xml");
+ URLConnection conx = url.openConnection();
+ System.out.println(conx.getURL());
+
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/PostBuildListener.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/PostBuildListener.java
new file mode 100644
index 0000000..03f4192
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/PostBuildListener.java
@@ -0,0 +1,27 @@
+package org.eclipse.wst.common.tests;
+
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+
+/**
+ * @author nirav
+ */
+public class PostBuildListener implements IResourceChangeListener {
+ private boolean buildComplete = false;
+ /* (non-Javadoc)
+ * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ if (event.getType() == IResourceChangeEvent.POST_BUILD){
+ buildComplete = true;
+ }
+ }
+
+ public boolean isBuildComplete() {
+ return buildComplete;
+ }
+
+ public void testComplete() {
+ buildComplete = false;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/ProjectUtility.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/ProjectUtility.java
new file mode 100644
index 0000000..88febea
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/ProjectUtility.java
@@ -0,0 +1,214 @@
+package org.eclipse.wst.common.tests;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.jem.util.logger.proxy.Logger;
+/**
+ * @author jsholl
+ *
+ * To change this generated comment edit the template variable "typecomment": Window>Preferences>Java>Templates. To
+ * enable and disable the creation of type comments go to Window>Preferences>Java>Code Generation.
+ */
+public class ProjectUtility {
+ public static IProject[] getAllProjects() {
+ IProject[] projects = new IProject[0];
+ try {
+ projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ } catch (AssertionFailedException ex) {
+ // Catch Malformed tree exception that occurs from time to time...
+ }
+ return projects;
+ }
+ public static boolean projectExists(String projectName) {
+ return getProject(projectName) != null;
+ }
+ public static IProject verifyAndReturnProject(String projectName, boolean exists) {
+ IProject project = getProject(projectName);
+ if (exists) {
+ Assert.assertTrue("Project Does Not Exist:" + projectName, project.exists());
+ } else {
+ Assert.assertTrue("Project Exists:" + projectName, !project.exists());
+ }
+ return project;
+ }
+ public static void verifyProject(String projectName, boolean exists) {
+ IProject project = getProject(projectName);
+ if (exists) {
+ Assert.assertTrue("Project Does Not Exist:" + projectName, project.exists());
+ } else {
+ Assert.assertTrue("Project Exists:" + projectName, !project.exists());
+ }
+ }
+ public static IProject getProject(String projectName) {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ String pathString = projectName;
+ if (!(workspace.getRoot().getProject(pathString) == null))
+ return workspace.getRoot().getProject(pathString);
+ else
+ return null;
+ }
+ public static void verifyNoProjects() {
+ IProject[] projects = getAllProjects();
+ String projectNames = "";
+ for (int i = 0; i < projects.length; i++) {
+ projectNames += " " + projects[i].getName();
+ }
+ Assert.assertTrue("All projects not deleted" + projectNames, projects.length == 0);
+ }
+ public static void deleteProjectIfExists(String projectName) {
+ if (projectName == null)
+ return;
+ IProject project = getProject(projectName);
+ if (project != null && project.isAccessible()) {
+ try {
+ project.close(null);
+ project.delete(true, true, null);
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+ }
+ public static void deleteAllProjects() throws Exception {
+ //closing projects and tread work in here is a hack because of a BeanInfo bug holding
+ //onto jars loaded in another VM
+
+// for (int i = 0; i < projects.length; i++) {
+// if (projects[i].exists()) {
+// projects[i].close(null); // This should signal the extra VM to kill itself
+// }
+// }
+ // Thread.yield(); // give the VM a chance to die
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+
+ public void run(IProgressMonitor monitor) {
+ IProject[] projects = getAllProjects();
+ for (int i = 0; i < projects.length; i++) {
+ IProject project = projects[i];
+ boolean success = false;
+ Exception lastException = null;
+ // Don't make 2^12 is about 4 seconds which is the max we
+ // will wait for the VM to die
+ for (int j = 0; j < 13 && !success; j++) {
+ try {
+ if (project.exists()) {
+ project.delete(true, true, null);
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+ success = true;
+ } catch (Exception e) {
+ lastException = e;
+ if (project.exists()) {
+ try {
+ project.close(null);
+ project.open(null);
+ } catch (Exception e2) {
+ }
+ }
+ try {
+ Thread.sleep((int) Math.pow(2, j));
+ } catch (InterruptedException e1) {
+ } // if the VM
+ // isn't dead,
+ // try sleeping
+ }
+ }
+ if (!success && lastException != null) {
+ Logger.getLogger().log("Problem while deleting: " + lastException.getMessage());
+ // Assert.fail("Caught Exception=" +
+ // lastException.getMessage() + " when deleting
+ // project=" + project.getName());
+ }
+ }
+ }
+ };
+ try {
+ ResourcesPlugin.getWorkspace().run(runnable, null);
+ } catch (CoreException ce) {
+ }
+ //verifyNoProjects();
+ }
+ /**
+ * Return the absolute path Strings to the files based on the fileSuffix and
+ * path within the plugin.
+ *
+ * @param path
+ * @param fileSuffix
+ * the file ending with the "." if required (the suffix will be
+ * used as is)
+ * @return
+ */
+ public static List getSpecificFilesInDirectory(Plugin plugin, String path, final String fileSuffix) {
+ URL entry = null;
+ entry = plugin.getBundle().getEntry(path);
+ List result = null;
+ File folder = null;
+ if (entry != null) {
+ try {
+ entry = Platform.asLocalURL(entry);
+ folder = new File(new URI(entry.toString()));
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ return Collections.EMPTY_LIST;
+ }
+ List files = Arrays.asList(folder.list());
+ if (!files.isEmpty()) {
+ String folderPath = folder.getAbsolutePath() + File.separator;
+ result = new ArrayList();
+ for (int i = 0; i < files.size(); i++) {
+ String fileName = (String) files.get(i);
+ if (!fileName.endsWith(fileSuffix))
+ continue;
+ result.add(folderPath + fileName);
+ }
+ }
+ }
+ if (result == null)
+ result = Collections.EMPTY_LIST;
+ return result;
+ }
+ public static List getJarsInDirectory(Plugin plugin, String path) {
+ return getSpecificFilesInDirectory(plugin, path, ".jar");
+ }
+ public static List getRarsInDirectory(Plugin plugin, String path) {
+ return getSpecificFilesInDirectory(plugin, path, ".rar");
+ }
+ public static List getEarsInDirectory(Plugin plugin, String path) {
+ return getSpecificFilesInDirectory(plugin, path, ".ear");
+ }
+ public static List getWarsInDirectory(Plugin plugin, String path) {
+ return getSpecificFilesInDirectory(plugin, path, ".war");
+ }
+ public static String getFullFileName(Plugin plugin, String pluginRelativeFileName) throws IOException {
+ IPath path = new Path(pluginRelativeFileName);
+ if (path.getDevice() != null)
+ return pluginRelativeFileName;
+ URL url = plugin.getBundle().getEntry(pluginRelativeFileName);
+ if (url != null) {
+ url = Platform.asLocalURL(url);
+ IPath iPath = new Path(url.getPath());
+ return iPath.toOSString();
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/SimpleTestSuite.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/SimpleTestSuite.java
new file mode 100644
index 0000000..5fe16e6
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/SimpleTestSuite.java
@@ -0,0 +1,31 @@
+/*
+ * Created on Feb 2, 2004
+ *
+ * To change the template for this generated file go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+package org.eclipse.wst.common.tests;
+
+import junit.framework.TestSuite;
+
+/**
+ * @author jsholl
+ *
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+public class SimpleTestSuite extends TestSuite {
+
+ public SimpleTestSuite(Class theClass) {
+ super(theClass, getShortName(theClass));
+ }
+
+ public static String getShortName(Class c){
+ String name = c.getName();
+ if(name.lastIndexOf('.') > 0){
+ name = name.substring(name.lastIndexOf('.')+1);
+ }
+ return name;
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/TaskViewUtility.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/TaskViewUtility.java
new file mode 100644
index 0000000..821355c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/TaskViewUtility.java
@@ -0,0 +1,193 @@
+package org.eclipse.wst.common.tests;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * @author jsholl
+ *
+ * To change this generated comment edit the template variable "typecomment":
+ * Window>Preferences>Java>Templates.
+ * To enable and disable the creation of type comments go to
+ * Window>Preferences>Java>Code Generation.
+ */
+public class TaskViewUtility {
+
+ public static IResource getWorkspaceRoot() {
+ return ResourcesPlugin.getWorkspace().getRoot();
+ }
+
+ public static void verifyNoNewTasks(HashSet hashSet) {
+ verifyNoNewTasks(null, hashSet);
+ }
+
+ public static void verifyNoNewTasks(IResource resource, HashSet hashSet) {
+ verifyNoNewTasksImpl(resource, hashSet, true);
+ }
+
+ private static void verifyNoNewTasksImpl(IResource resource, HashSet hashSet, boolean failOnFailure) {
+ IResource markerSource = resource == null ? getWorkspaceRoot() : resource;
+ IMarker[] markers = null;
+ try {
+ markers = markerSource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ Assert.fail();
+ }
+ for (int j = 0; markers != null && j < markers.length; j++) {
+ String message = markers[j].toString();
+ try {
+ message = (String) markers[j].getAttribute(IMarker.MESSAGE);
+ } catch (Exception e) {
+ }
+
+ if (null == hashSet) {
+ String failMsg = "Task in Tasks List: " + message;
+ if (failOnFailure) {
+ Assert.fail(failMsg);
+ } else {
+ System.out.println(failMsg);
+ }
+ } else if (!hashSet.contains(markers[j])) {
+ String failMsg = "New Task in Tasks List: " + message;
+ if (failOnFailure) {
+ Assert.fail(failMsg);
+ } else {
+ System.out.println(failMsg);
+ }
+
+ }
+ }
+ }
+
+ public static void verifyNoErrors() {
+ verifyNoErrors(null);
+ }
+
+ public static void verifyNoErrors(IResource resource) {
+ List markers = getErrors(resource);
+ if (null != markers && markers.size() > 0) {
+ int size = markers.size();
+ String message = "" + size + " errors in tasks view:";
+ IMarker marker;
+ for (int i = 0; i < size; i++) {
+ marker = (IMarker) markers.get(i);
+ try {
+ message += "\n" + i + " " + (String) marker.getAttribute(IMarker.MESSAGE);
+ } catch (Exception e) {
+ }
+ }
+ Assert.fail(message);
+ }
+ }
+
+ /**
+ * @param resource
+ * @return
+ */
+ public static List getErrors(IResource resource) {
+ IResource markerSource = resource == null ? getWorkspaceRoot() : resource;
+ List markers = null;
+ try {
+ markers = findSeverityMarkers(markerSource, IMarker.SEVERITY_ERROR);
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ }
+ return markers;
+ }
+
+ private static List findSeverityMarkers(IResource markerSource, int severityLevel) throws CoreException {
+ IMarker[] markers = markerSource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
+ List results = null;
+ Integer severity;
+ for (int i = 0; i < markers.length; i++) {
+ severity = (Integer) markers[i].getAttribute(IMarker.SEVERITY);
+ if (severity.intValue() == severityLevel) {
+ if (results == null)
+ results = new ArrayList();
+ results.add(markers[i]);
+ }
+ }
+ if (results == null)
+ results = Collections.EMPTY_LIST;
+ return results;
+ }
+
+ public static void verifyNoWarnings() {
+
+ }
+
+ public static void verifyNoTasks() {
+ verifyNoTasks(null);
+ }
+
+ public static void verifyNoTasks(IResource resource) {
+ verifyNoNewTasksImpl(resource, null, true);
+ }
+
+ public static void verifyNoTasks(boolean failOnFailure) {
+ verifyNoTasks(null, failOnFailure);
+ }
+
+ public static void verifyNoTasks(IResource resource, boolean failOnFailure) {
+ verifyNoNewTasksImpl(resource, null, failOnFailure);
+ }
+ public static void verifyErrors(List markerDescriptionsExpected) {
+ verifyErrors(markerDescriptionsExpected,true,false);
+ }
+
+
+ public static void verifyErrors(List markerDescriptionsExpected, boolean reportIfExpectedErrorNotFound, boolean removeAllSameTypesOfError) {
+ List markerDescriptionsFound = null;
+ try {
+ List markersFound = findSeverityMarkers(getWorkspaceRoot(), IMarker.SEVERITY_ERROR);
+ markerDescriptionsFound = new ArrayList(markersFound.size());
+ for (int i = 0; i < markersFound.size(); i++) {
+ markerDescriptionsFound.add(((IMarker) markersFound.get(i)).getAttribute("message"));
+ }
+ } catch (CoreException e1) {
+ e1.printStackTrace();
+ Assert.fail();
+ }
+
+ ArrayList markerDescriptionsNotFound = new ArrayList();
+ List markersDescriptionsToRemove = new ArrayList();
+ for (int i = 0; i < markerDescriptionsExpected.size(); i++) {
+ String messageToFind = (String)markerDescriptionsExpected.get(i);
+ boolean found = false;
+ for(int j=0;j<markerDescriptionsFound.size() &&(!found || removeAllSameTypesOfError);j++){
+ if(messageToFind.equals(markerDescriptionsFound.get(j))){
+ found = true;
+ markersDescriptionsToRemove.add(markerDescriptionsFound.get(j));
+ }
+ }
+ if (!found) {
+ markerDescriptionsNotFound.add(messageToFind);
+ }
+ }
+ markerDescriptionsFound.removeAll(markersDescriptionsToRemove);
+ if (markerDescriptionsNotFound.size() > 0 || markerDescriptionsFound.size() > 0) {
+ String messages = "";
+ if (reportIfExpectedErrorNotFound){
+ for (int i = 0; i < markerDescriptionsNotFound.size(); i++) {
+ messages += "\nError not found:\"" + markerDescriptionsNotFound.get(i)+"\"";
+ }
+ }
+ for (int i = 0; i < markerDescriptionsFound.size(); i++) {
+ messages += "\nUnexpected error found:\"" + markerDescriptionsFound.get(i)+"\"";
+ }
+ if (!messages.equals(""))
+ Assert.fail(messages);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/WindowUtility.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/WindowUtility.java
new file mode 100644
index 0000000..9edc779
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/WindowUtility.java
@@ -0,0 +1,43 @@
+/*
+ * Created on Jun 5, 2003
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package org.eclipse.wst.common.tests;
+
+
+/**
+ * @author jsholl
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class WindowUtility {
+
+// public static void closeAllOpenWindows() {
+// IWorkbench workbench = WorkbenchPlugin.getDefault().getWorkbench();
+// IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
+//
+// for (int i = 0; i < windows.length; i++) {
+// final IWorkbenchWindow window = windows[i];
+// final Shell shell = window.getShell();
+// shell.getDisplay().syncExec(new Runnable() {
+// public void run() {
+// Shell[] otherShells = shell.getDisplay().getShells();
+// //this can be imporoved, but basically this is to work out shell dependencies.
+// for (int j = 0; j < otherShells.length; j++) {
+// //step through shells backwards in case one shell opens another -- this is how they are usually odered
+// for (int i = otherShells.length - 1; i > 0; i--) {
+// int index = (i+j) % otherShells.length; // mix things up a little to work out shell dependencies
+// if (otherShells[index] != shell && otherShells[index].isVisible() && !otherShells[index].isDisposed()) {
+// otherShells[index].close();
+// }
+// }
+// }
+// }
+// });
+// }
+// }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider.java
new file mode 100644
index 0000000..b4927da
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider.java
@@ -0,0 +1,24 @@
+package org.eclipse.wst.common.tests.flatten;
+
+import java.util.Properties;
+
+import org.eclipse.wst.common.componentcore.internal.flat.AbstractFlattenParticipant;
+import org.eclipse.wst.common.componentcore.internal.flat.IFlattenParticipant;
+import org.eclipse.wst.common.componentcore.internal.flat.IFlattenParticipantProvider;
+
+public class ExampleFlattenParticipantProvider implements
+ IFlattenParticipantProvider {
+
+ public static final String DUMMY_PARTICIPANT = "example1";
+ public IFlattenParticipant findParticipant(String id, Properties props) {
+ if( DUMMY_PARTICIPANT.equals(id)) {
+ return new DummyFlattenParticipant();
+ }
+ return null;
+ }
+
+ public static class DummyFlattenParticipant extends AbstractFlattenParticipant {
+
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider2.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider2.java
new file mode 100644
index 0000000..e6f6cec
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider2.java
@@ -0,0 +1,29 @@
+package org.eclipse.wst.common.tests.flatten;
+
+import java.util.Properties;
+
+import org.eclipse.wst.common.componentcore.internal.flat.AbstractFlattenParticipant;
+import org.eclipse.wst.common.componentcore.internal.flat.IFlattenParticipant;
+import org.eclipse.wst.common.componentcore.internal.flat.IFlattenParticipantProvider;
+
+public class ExampleFlattenParticipantProvider2 implements
+ IFlattenParticipantProvider {
+
+ public static final String DUMMY_PARTICIPANT = "example2";
+
+ public static final String COMMON_KEY = "common";
+ public IFlattenParticipant findParticipant(String id, Properties props) {
+ if( DUMMY_PARTICIPANT.equals(id)) {
+ return new Dummy2FlattenParticipant();
+ }
+ if( COMMON_KEY.equals(id))
+ return new Dummy2FlattenParticipant();
+
+ return null;
+ }
+
+ public static class Dummy2FlattenParticipant extends AbstractFlattenParticipant {
+
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider3.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider3.java
new file mode 100644
index 0000000..2a75b89
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/ExampleFlattenParticipantProvider3.java
@@ -0,0 +1,26 @@
+package org.eclipse.wst.common.tests.flatten;
+
+import java.util.Properties;
+
+import org.eclipse.wst.common.componentcore.internal.flat.AbstractFlattenParticipant;
+import org.eclipse.wst.common.componentcore.internal.flat.IFlattenParticipant;
+import org.eclipse.wst.common.componentcore.internal.flat.IFlattenParticipantProvider;
+
+public class ExampleFlattenParticipantProvider3 implements
+ IFlattenParticipantProvider {
+
+ public static final String DUMMY_PARTICIPANT = "example3";
+ public static final String COMMON_KEY = ExampleFlattenParticipantProvider2.COMMON_KEY;
+ public IFlattenParticipant findParticipant(String id, Properties props) {
+ if( DUMMY_PARTICIPANT.equals(id))
+ return new Dummy3FlattenParticipant();
+ if( COMMON_KEY.equals(id))
+ return new Dummy3FlattenParticipant();
+ return null;
+ }
+
+ public static class Dummy3FlattenParticipant extends AbstractFlattenParticipant {
+
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/FlattenParticipantProviderTest.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/FlattenParticipantProviderTest.java
new file mode 100644
index 0000000..01c12ab
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/flatten/FlattenParticipantProviderTest.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.flatten;
+
+import junit.framework.TestCase;
+
+import org.eclipse.wst.common.componentcore.internal.flat.FlattenParticipantModel;
+import org.eclipse.wst.common.componentcore.internal.flat.IFlattenParticipant;
+
+
+public class FlattenParticipantProviderTest extends TestCase {
+
+ public FlattenParticipantProviderTest(String name) {
+ super(name);
+ }
+
+ public void testNotFoundParticipantFound() {
+ assertNull(searchModel("NOT FOUND"));
+ }
+
+ public void testExample1ParticipantFound() {
+ IFlattenParticipant fp = searchModel(ExampleFlattenParticipantProvider.DUMMY_PARTICIPANT);
+ assertNotNull(fp);
+ assertTrue(fp.getClass().getName().endsWith("DummyFlattenParticipant"));
+ }
+
+ public void testExample2ParticipantFound() {
+ IFlattenParticipant fp = searchModel(ExampleFlattenParticipantProvider2.DUMMY_PARTICIPANT);
+ assertNotNull(fp);
+ assertTrue(fp.getClass().getName().endsWith("Dummy2FlattenParticipant"));
+ }
+
+ public void testExample3ParticipantFound() {
+ IFlattenParticipant fp = searchModel(ExampleFlattenParticipantProvider3.DUMMY_PARTICIPANT);
+ assertNotNull(fp);
+ assertTrue(fp.getClass().getName().endsWith("Dummy3FlattenParticipant"));
+ }
+
+ /**
+ * This test ensures that the weighting is done properly.
+ * providers with a higher weight should be consulted first.
+ * Weight 10 should be asked before weight 0
+ */
+ public void testCommonParticipantFound() {
+ IFlattenParticipant fp = searchModel(ExampleFlattenParticipantProvider2.COMMON_KEY);
+ assertNotNull(fp);
+ assertTrue(fp.getClass().getName().endsWith("Dummy3FlattenParticipant"));
+ }
+
+ private IFlattenParticipant searchModel(String id) {
+ return FlattenParticipantModel.getDefault().getParticipant(id);
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/xml/DomComparitor.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/xml/DomComparitor.java
new file mode 100644
index 0000000..378c2d8
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/xml/DomComparitor.java
@@ -0,0 +1,273 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.xml;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.CharacterData;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+
+public class DomComparitor {
+ private static HashSet attributeList;
+
+ public static String compareDoms(InputSource source1, InputSource source2, HashSet ignorableAtts, EntityResolver entityResolver) throws Exception {
+// attributeList = ignorableAtts;
+// DOMParser parser = new DOMParser();
+// if (entityResolver == null) {
+// parser.setEntityResolver(new EntityResolver() {
+// public InputSource resolveEntity(String arg0, String arg1) throws SAXException, IOException {
+// return null;
+// }
+// });
+// } else {
+// parser.setEntityResolver(entityResolver);
+// }
+// parser.parse(source1);
+// Document doc1 = parser.getDocument();
+// parser.parse(source2);
+// Document doc2 = parser.getDocument();
+// return compareNodes(doc1, doc2);
+ return null;
+ }
+ public static String compareDoms(InputSource source1, InputSource source2, HashSet ignorableAtts) throws Exception {
+ return compareDoms(source1, source2, ignorableAtts, null);
+ }
+
+ public static String compareDoms(InputSource source1, InputSource source2) throws Exception {
+ return compareDoms(source1, source2, null);
+ }
+
+ public static String compareNodes(Node node1, Node node2) throws Exception {
+ // System.out.println("checking A:" + node1);
+ // System.out.println("checking B:" + node2);
+ // System.out.println("nodeType=" + node1.getNodeType());
+ // System.out.println("getNodeName=" + node1.getNodeName());
+ // System.out.println("getNodeValue=" + node1.getNodeValue());
+
+ //Generic Node Testing
+ // if (node1 == null && node2 == null)
+ // return null;
+ // else
+ if ((node1 != null && node2 == null) || node1 == null && node2 != null)
+ return nullNodeEncountered(node1, node2);
+ else if (node1.getNodeType() != node2.getNodeType()) {
+ return mismatch("Node.getNodeType() " + node1.getNodeType() + " " + node2.getNodeType(), node1, node2);
+ } else if (node1.getNodeName() != node2.getNodeName()) {
+ return mismatch("Node.getNodeName() <" + node1.getNodeName() + "> <" + node2.getNodeName() + ">", node1, node2);
+ } else if (!(node1.getNodeValue() == null && node2.getNodeValue() == null)) {
+ if (node1.getNodeValue() == null) {
+ return mismatch("Node.getNodeValue() node A is null", node1, node2);
+ } else if (node2.getNodeValue() == null) {
+ return mismatch("Node.getNodeValue() node B is null", node1, node2);
+ } else if (!node1.getNodeValue().trim().equals(node2.getNodeValue().trim())) {
+ return mismatch("Node.getNodeValue() <" + node1.getNodeValue() + "> <" + node2.getNodeValue() + ">", node1, node2);
+ }
+ }
+ //TODO strengthen node comparisons as necessary
+ //Specialized Node Testing
+ switch (node1.getNodeType()) {
+ case Node.TEXT_NODE :
+ case Node.CDATA_SECTION_NODE :
+ CharacterData cdata1 = (CharacterData) node1;
+ CharacterData cdata2 = (CharacterData) node2;
+ if (!cdata1.getData().trim().equals(cdata2.getData().trim())) {
+ return mismatch("CharacterData.getData() " + cdata1.getData() + " " + cdata2.getData(), node1, node2);
+ }
+ break;
+ case Node.ATTRIBUTE_NODE :
+ Attr attr1 = (Attr) node1;
+ Attr attr2 = (Attr) node2;
+ if (!attr1.getName().equals(attr2.getName())) {
+ return mismatch("Attr.getName() " + attr1.getName() + " " + attr2.getName(), node1, node2);
+ } else if (!attr1.getValue().equals(attr2.getValue())) {
+ return mismatch("Attr.getValue() " + attr1.getValue() + " " + attr2.getValue(), node1, node2);
+ } else if (attr1.getSpecified() != attr2.getSpecified()) {
+ return mismatch("Attr.getSpecified() " + attr1.getSpecified() + " " + attr2.getSpecified(), node1, node2);
+ }
+ break;
+ case Node.DOCUMENT_NODE :
+ Document doc1 = (Document) node1;
+ Document doc2 = (Document) node2;
+ String result = compareNodes(doc1.getDoctype(), doc2.getDoctype());
+ if (result != null) {
+ return result;
+ }
+ break;
+ case Node.DOCUMENT_TYPE_NODE :
+ DocumentType docType1 = (DocumentType) node1;
+ DocumentType docType2 = (DocumentType) node2;
+ if (!docType1.getPublicId().equals(docType2.getPublicId())) {
+ return mismatch("DocumentType.getPublicId() " + docType1.getPublicId() + " " + docType2.getPublicId(), node1, node2);
+ }
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE :
+ ProcessingInstruction pInst1 = (ProcessingInstruction) node1;
+ ProcessingInstruction pInst2 = (ProcessingInstruction) node2;
+ //System.out.println("ProcessingInstruction todo");
+ break;
+ case Node.DOCUMENT_FRAGMENT_NODE :
+ DocumentFragment frag1 = (DocumentFragment) node1;
+ DocumentFragment frag2 = (DocumentFragment) node2;
+ //System.out.println("DocumentFragment todo");
+ break;
+
+ case Node.ELEMENT_NODE :
+ case Node.COMMENT_NODE :
+ case Node.ENTITY_NODE :
+ case Node.NOTATION_NODE :
+ break;
+
+ }
+
+ //Recursion
+ NamedNodeMap attributes1 = node1.getAttributes();
+ NamedNodeMap attributes2 = node2.getAttributes();
+
+ if (attributes1 != null && attributes2 != null) {
+ ignoreAttributes(attributes1, attributes2);
+ if (attributes1.getLength() != attributes2.getLength()) {
+ return mismatch("getAttributes().getLength() " + attributes1.getLength() + " " + attributes2.getLength(), node1, node2);
+ }
+ for (int i = 0; i < attributes1.getLength(); i++) {
+ Attr attr1 = (Attr) attributes1.item(i);
+ Attr attr2 = (Attr) attributes2.item(i);
+ String results = compareNodes(attr1, attr2);
+ if (null != results) {
+ return results;
+ }
+ }
+
+ } else if (attributes1 != null || attributes2 != null) {
+ return mismatch("getAttributes() null", node1, node2);
+ }
+
+ ArrayList children1 = getAsArrayList(node1.getChildNodes());
+ ArrayList children2 = getAsArrayList(node2.getChildNodes());
+
+ ignoreComments(children1);
+ ignoreComments(children2);
+
+ ignoreEmptyTextNodes(children1);
+ ignoreEmptyTextNodes(children2);
+
+ if (children1.size() != children2.size()) {
+ return mismatch("Node.hasChildNodes() " + children1.size() + " " + children2.size(), node1, node2);
+ }
+
+ for (int i = 0; i < children1.size(); i++) {
+ Node child1 = (Node) children1.get(i);
+ Node child2 = (Node) children2.get(i);
+ String results = compareNodes(child1, child2);
+ if (null != results) {
+ return results;
+ }
+ }
+ return null;
+ }
+
+ private static ArrayList getAsArrayList(NodeList originalList) {
+ ArrayList newList = new ArrayList();
+ if (originalList != null) {
+ for (int i = 0; i < originalList.getLength(); i++) {
+ newList.add(originalList.item(i));
+ }
+ }
+ return newList;
+ }
+
+ private static void ignoreComments(ArrayList list) {
+ ArrayList toRemove = new ArrayList();
+ for (int i = 0; i < list.size(); i++) {
+ Node node = (Node) list.get(i);
+ if (node.getNodeType() == Node.COMMENT_NODE) {
+ toRemove.add(node);
+ }
+ }
+ for (int i = 0; i < toRemove.size(); i++) {
+ list.remove(toRemove.get(i));
+ }
+ }
+
+ private static void ignoreEmptyTextNodes(ArrayList list) {
+ ArrayList toRemove = new ArrayList();
+ for (int i = 0; i < list.size(); i++) {
+ Node node = (Node) list.get(i);
+ if (node.getNodeType() == Node.TEXT_NODE && (node.getNodeValue() == null || node.getNodeValue().trim().equals(""))) {
+ toRemove.add(node);
+ }
+ }
+ for (int i = 0; i < toRemove.size(); i++) {
+ list.remove(toRemove.get(i));
+ }
+ }
+
+ /**
+ * @param attributes1
+ */
+ private static void ignoreAttributes(NamedNodeMap attributes1, NamedNodeMap attributes2) {
+ if (attributeList != null) {
+ Iterator it = attributeList.iterator();
+ String ignore;
+ while (it.hasNext()) {
+ ignore = (String) it.next();
+ if (attributes1.getNamedItem(ignore) != null)
+ attributes1.removeNamedItem(ignore);
+ if (attributes2.getNamedItem(ignore) != null)
+ attributes2.removeNamedItem(ignore);
+ }
+ }
+ }
+
+ public static String nullNodeEncountered(Node node1, Node node2) {
+ String message = "Null node encountered";
+ Node nonNullNode = node1 == null ? node2 : node1;
+ char source = node1 == null ? 'B' : 'A';
+ while (nonNullNode != null) {
+ message += source + nonNullNode.getNodeName() + "\n";
+ nonNullNode = nonNullNode.getParentNode();
+ }
+ return message;
+ }
+
+ public static String nodeNotCompared(Node node) {
+ String message = "Node node compared:";
+ while (node != null) {
+ message += node.getNodeName() + "\n";
+ node = node.getParentNode();
+ }
+
+ return message;
+ }
+
+ public static String mismatch(String mismatchtype, Node node1, Node node2) throws Exception {
+ String message = "Nodes A and B do not match because of node." + mismatchtype + "\n";
+ while (node1 != null && node2 != null) {
+ message += "A:" + node1.getNodeName() + "\n";
+ message += "B:" + node2.getNodeName() + "\n";
+ node1 = node1.getParentNode();
+ node2 = node2.getParentNode();
+ }
+
+ return message;
+ }
+
+}
\ No newline at end of file
diff --git a/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/xml/DomComparitorTest.java b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/xml/DomComparitorTest.java
new file mode 100644
index 0000000..c8bdd8d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/commontests/org/eclipse/wst/common/tests/xml/DomComparitorTest.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.tests.xml;
+
+import java.io.File;
+import java.io.FileReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.xml.sax.InputSource;
+
+
+public class DomComparitorTest extends TestCase {
+
+ String baseDir = System.getProperty("user.dir") + java.io.File.separatorChar;
+ String testData = baseDir + "testData" + java.io.File.separatorChar;
+
+ public DomComparitorTest(String name) {
+ super(name);
+ }
+
+ public void testEqualDoms_01() {
+ checkEqual("baseData_01.xml", "baseData_01.xml");
+ }
+
+ public void testEqualDoms_01_01() {
+ checkEqual("baseData_01.xml", "equalTo_01_case_01.xml");
+ }
+
+ public void testEqualDoms_01_02() {
+ checkEqual("baseData_01.xml", "equalTo_01_case_02.xml");
+ }
+
+ public void testUnequalDom_01_01() {
+ checkUnequal("baseData_01.xml", "unequalTo_01_case_01.xml");
+ }
+
+ public void testUnequalDom_01_02() {
+ checkUnequal("baseData_01.xml", "unequalTo_01_case_02.xml");
+ }
+
+ public void testUnequalDom_01_03() {
+ checkUnequal("baseData_01.xml", "unequalTo_01_case_03.xml");
+ }
+
+ public void testUnequalDom_01_04() {
+ checkUnequal("baseData_01.xml", "unequalTo_01_case_04.xml");
+ }
+
+ //TODO figure out how to compare encodings
+ // public void testUnequalDom_01_05() {
+ // checkUnequal("baseData_01.xml", "unequalTo_01_case_05.xml");
+ // }
+
+ private void checkEqual(String fileName1, String fileName2) {
+ try {
+ InputSource source1 = new InputSource(new FileReader(new File(testData + fileName1)));
+ InputSource source2 = new InputSource(new FileReader(new File(testData + fileName2)));
+// String results = DomComparitor.compareDoms(source1, source2);
+// if (results != null) {
+// Assert.fail("Equal doms compared as unequal " + fileName1 + " " + fileName2 + "\ncompare results = " + results);
+// }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ private void checkUnequal(String fileName1, String fileName2) {
+ try {
+ InputSource source1 = new InputSource(new FileReader(new File(testData + fileName1)));
+ InputSource source2 = new InputSource(new FileReader(new File(testData + fileName2)));
+// String results = DomComparitor.compareDoms(source1, source2);
+// if (results == null) {
+// Assert.fail("Unequal doms compared as equal " + fileName1 + " " + fileName2);
+// }
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail(e.getMessage());
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EclipseSchemeTests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EclipseSchemeTests.java
new file mode 100644
index 0000000..cf2ff0b
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EclipseSchemeTests.java
@@ -0,0 +1,262 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.environment.tests;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.common.environment.EnvironmentService;
+import org.eclipse.wst.common.environment.uri.IURI;
+import org.eclipse.wst.common.environment.uri.IURIScheme;
+import org.eclipse.wst.common.environment.uri.URIException;
+
+public class EclipseSchemeTests extends TestCase
+{
+ private final String projectName_ = "TestProject";
+
+ public EclipseSchemeTests(String name)
+ {
+ super(name);
+ }
+ public static void main(String[] args)
+ {
+ if (args.length == 0)
+ {
+ runAll();
+ }
+ else if (args.length == 1)
+ {
+ String methodToRun = args[0].trim();
+ runOne(methodToRun);
+ }
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(EclipseSchemeTests.class);
+ }
+
+ protected static void runAll()
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static void runOne(String methodName)
+ {
+ TestSuite testSuite = new TestSuite();
+ TestCase test = new EclipseSchemeTests(methodName);
+ testSuite.addTest(test);
+ junit.textui.TestRunner.run(testSuite);
+ }
+
+ /**
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // Create a test project in the workbench
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = workspaceRoot.getProject( projectName_ );
+
+ if( project != null && project.exists() )
+ {
+ project.delete( true, null );
+ }
+
+ // Create the project
+ IProjectDescription desc = workspaceRoot.getWorkspace().newProjectDescription( projectName_ );
+ project.create( desc, null );
+ project.open( null );
+ }
+ /**
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ // Create a test project in the workbench
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = workspaceRoot.getProject( projectName_ );
+
+ project.delete( true, null );
+ }
+
+ public static Test getTest()
+ {
+ return new EclipseSchemeTests("EclipseSchemeTests");
+ }
+
+ public void testBadURIs()
+ {
+ IURIScheme scheme = EnvironmentService.getEclipseScheme();
+
+ try
+ {
+ IURI newURI = scheme.newURI( "bogus:/somefolder/somefile.txt");
+ assertTrue( "Non platform protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ IURI newURI = scheme.newURI( ":/somefolder/somefile.txt");
+ assertTrue( "Non platform protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+
+ try
+ {
+ IURI newURI = scheme.newURI( (String)null );
+ assertTrue( "Non platform protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ IURI newURI = scheme.newURI( (URL)null );
+ assertTrue( "Non platform protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ IURI newURI = scheme.newURI( (IURI)null );
+ assertTrue( "Non platform protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+ }
+
+ public void testNewURI()
+ {
+ IURIScheme scheme = EnvironmentService.getEclipseScheme() ;
+
+ try
+ {
+ IURI uri1 = scheme.newURI( "platform:/resource/" + projectName_ + "/myfile" );
+ IURI uri2 = scheme.newURI( "relativedirectory/relativefile" );
+ IURI uri3 = scheme.newURI( uri1 );
+ IURI uri4 = scheme.newURI( uri2 );
+ IURI uri5 = scheme.newURI( new URL( uri1.asString() ) );
+
+ File file1 = uri1.asFile();
+
+ uri1.touchLeaf();
+
+ assertTrue( "Is a file", file1.isFile() );
+ assertTrue( "File names not the same", uri1.asString().equals( uri3.toString() ));
+ assertTrue( "File names not the same", uri2.asString().equals( uri4.toString() ));
+ assertTrue( "File names not the same", uri1.asString().equals( uri5.toString() ));
+ assertTrue( "Protocol not platform", uri1.getURIScheme().toString().equals("platform"));
+ assertTrue( "Protocol not platform", uri3.getURIScheme().toString().equals("platform"));
+ assertTrue( "Protocol not platform", uri5.getURIScheme().toString().equals("platform"));
+ assertTrue( "Protocol not relative", uri2.getURIScheme().toString().equals("relative"));
+ assertTrue( "Protocol not relative", uri4.getURIScheme().toString().equals("relative"));
+
+ uri1.erase();
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testHierarchical()
+ {
+ IURIScheme scheme = EnvironmentService.getEclipseScheme() ;
+
+ assertTrue( "Not hierarchical", scheme.isHierarchical() == true );
+ }
+
+ public void testValidURIs()
+ {
+ try
+ {
+ IURIScheme scheme = EnvironmentService.getEclipseScheme();
+ IURI uri1 = scheme.newURI( "platform:/resource/somedir/somefile" );
+ IURI uri2 = scheme.newURI( "platform:/resource/somedir" );
+ IURI uri3 = scheme.newURI( "somerel" );
+ IURI uri4 = scheme.newURI( "somerel/somemorerel" );
+ IURI uri5 = scheme.newURI( "./somerel/somemore" );
+
+ assertTrue( "URI not valid", scheme.isValid( uri1 ) );
+ assertTrue( "URI not valid", scheme.isValid( uri2 ) );
+ assertTrue( "URI not valid", scheme.isValid( uri3 ) );
+ assertTrue( "URI not valid", scheme.isValid( uri4 ) );
+ assertTrue( "URI not valid", scheme.isValid( uri5 ) );
+ assertTrue( "URI has not valid status", scheme.validate( uri1 ).getSeverity() == IStatus.OK );
+ assertTrue( "URI has not valid status", scheme.validate( uri2 ).getSeverity() == IStatus.OK );
+ assertTrue( "URI has not valid status", scheme.validate( uri3 ).getSeverity() == IStatus.OK );
+ assertTrue( "URI has not valid status", scheme.validate( uri4 ).getSeverity() == IStatus.OK );
+ assertTrue( "URI has not valid status", scheme.validate( uri5 ).getSeverity() == IStatus.OK );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testInvalidURIs()
+ {
+ try
+ {
+ IURIScheme eclipseScheme = EnvironmentService.getEclipseScheme();
+ IURIScheme fileScheme = EnvironmentService.getFileScheme();
+
+ IURI uri1 = fileScheme.newURI( "file:/c:/temp/somedir/somefile" );
+
+ assertTrue( "URI valid", !eclipseScheme.isValid( uri1 ) );
+ assertTrue( "URI has a valid status", eclipseScheme.validate( uri1 ).getSeverity() == IStatus.ERROR );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EclipseURITests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EclipseURITests.java
new file mode 100644
index 0000000..b96bd5f
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EclipseURITests.java
@@ -0,0 +1,928 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * yyyymmdd bug Email and other contact information
+ * -------- -------- -----------------------------------------------------------
+ * 20060217 128456 pmoogk@ca.ibm.com - Peter Moogk
+ *******************************************************************************/
+package org.eclipse.wst.common.environment.tests;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.environment.EnvironmentService;
+import org.eclipse.wst.common.environment.IEnvironment;
+import org.eclipse.wst.common.environment.uri.IURI;
+import org.eclipse.wst.common.environment.uri.IURIFactory;
+import org.eclipse.wst.common.environment.uri.IURIFilter;
+import org.eclipse.wst.common.environment.uri.IURIScheme;
+import org.eclipse.wst.common.environment.uri.IURIVisitor;
+import org.eclipse.wst.common.environment.uri.URIException;
+
+public class EclipseURITests extends TestCase
+{
+ private final String projectName_ = "TestProject";
+ private File tempFile;
+ private File tempDir;
+
+ public EclipseURITests(String name)
+ {
+ super(name);
+ }
+ public static void main(String[] args)
+ {
+ if (args.length == 0)
+ {
+ runAll();
+ }
+ else if (args.length == 1)
+ {
+ String methodToRun = args[0].trim();
+ runOne(methodToRun);
+ }
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(EclipseURITests.class);
+ }
+
+ protected static void runAll()
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static void runOne(String methodName)
+ {
+ TestSuite testSuite = new TestSuite();
+ TestCase test = new EclipseURITests(methodName);
+ System.out.println("Calling EclipseURITests."+methodName);
+ testSuite.addTest(test);
+ junit.textui.TestRunner.run(testSuite);
+ }
+
+ /**
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ tempFile = File.createTempFile("tmp", "tmp", null );
+ tempDir = new File( tempFile.getParentFile(), "tmpDir" );
+ tempDir.mkdir();
+
+ // Create a test project in the workbench
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = workspaceRoot.getProject( projectName_ );
+
+ if( project != null && project.exists() )
+ {
+ project.delete( true, null );
+ }
+
+ // Create the project
+ IProjectDescription desc = workspaceRoot.getWorkspace().newProjectDescription( projectName_ );
+ project.create( desc, null );
+ project.open( null );
+ }
+ /**
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ // Create a test project in the workbench
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = workspaceRoot.getProject( projectName_ );
+
+ project.delete( true, null );
+ tempFile.delete();
+ deleteDir( tempDir );
+ }
+
+ public static Test getTest()
+ {
+ return new EclipseURITests("EclipseURITests");
+ }
+ public void testAvailable()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testAvailable()");
+
+ try
+ {
+ IURI uri1 = factory.newURI( "platform:/resource/" + projectName_ + "/myfile" );
+ IURI uri2 = factory.newURI( getTmpFileURL( "somefile" ) );
+ IURI uri3 = factory.newURI( "relativedirectory/relativefile" );
+
+ assertTrue( "Not available as URL", uri1.isAvailableAsURL() );
+ assertTrue( "Not available as URL", uri2.isAvailableAsURL() );
+ assertTrue( "Available as URL", !uri3.isAvailableAsURL() );
+
+ assertTrue( "Not available as File", uri1.isAvailableAsFile() );
+ assertTrue( "Not available as File", uri2.isAvailableAsFile() );
+ assertTrue( "Available as File", !uri3.isAvailableAsFile() );
+
+ File file1 = uri1.asFile();
+ File file2 = uri2.asFile();
+ URL url1 = uri1.asURL();
+ URL url2 = uri2.asURL();
+
+ uri1.touchLeaf();
+ uri2.touchLeaf();
+
+ assertTrue( "Is a file", file1.isFile() );
+ assertTrue( "Is a file", file2.isFile() );
+ assertTrue( "Wrong protocol", url1.getProtocol().equals( "platform" ));
+ assertTrue( "Wrong protocol", url2.getProtocol().equals( "file" ));
+ assertTrue( uri1.asString().length() > 5 );
+ assertTrue( uri2.asString().length() > 5 );
+ assertTrue( uri1.toString().length() > 5 );
+ assertTrue( uri2.toString().length() > 5 );
+ uri1.erase();
+ uri2.erase();
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testFactory()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testFactory()");
+ try
+ {
+ factory.newURIScheme( null );
+ assertTrue( "Null URI scheme should cause an exception", false );
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ factory.newURIScheme( "bogusProtocol:/somefolder/somefile.txt" );
+ assertTrue( "An undefined protocol should cause an exception", false );
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ factory.newURIScheme( "/somefolder/somefile.txt" );
+ assertTrue( "Absolute path with no protocol should cause an exception", false );
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ IURIScheme scheme1 = factory.newURIScheme( "platform:/resource/myproj/myfile" );
+ IURIScheme scheme2 = factory.newURIScheme( getTmpFileURL( "somefile2" ) );
+ IURIScheme scheme3 = factory.newURIScheme( "platform" );
+ IURIScheme scheme4 = factory.newURIScheme( "file" );
+ IURIScheme scheme5 = factory.newURI( "rel1/rel2" ).getURIScheme();
+
+ IURI uri1 = factory.newURI( "platform:/resource/myproj/myfile" );
+ IURI uri2 = factory.newURI( getTmpFileURL( "somefile3" ) );
+ IURI uri3 = factory.newURI( "relativedirectory/relativefile" );
+
+ IURI uri4 = factory.newURI( new URL( "platform:/resource/myproj/myfile" ));
+ IURI uri5 = factory.newURI( new URL( getTmpFileURL( "somefile4" ) ) );
+
+
+ assertTrue( "Scheme not platform protocol", scheme1.toString().equals("platform") );
+ assertTrue( "Scheme not file protocol", scheme2.toString().equals("file") );
+ assertTrue( "Scheme not platform", scheme3.toString().equals("platform") );
+ assertTrue( "Scheme not file", scheme4.toString().equals("file") );
+ assertTrue( "Scheme not relative", scheme5.toString().equals("relative") );
+
+ assertTrue( "Scheme not platform protocol", uri1.getURIScheme().toString().equals("platform") );
+ assertTrue( "Scheme not file protocol", uri2.getURIScheme().toString().equals("file") );
+ assertTrue( "Scheme not relative", uri3.getURIScheme().toString().equals("relative") );
+
+ assertTrue( "Scheme not platform protocol", uri4.getURIScheme().toString().equals("platform") );
+ assertTrue( "Scheme not file protocol", uri5.getURIScheme().toString().equals("file") );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testTouchFolder()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testTouchFolder()");
+ try
+ {
+ IPath folderPath = new Path( projectName_ ).append( "topFolder" ).makeAbsolute();
+ IPath folderPath2 = folderPath.append( "space folder" );
+ IURI uri = factory.newURI( getURLFromPath( folderPath ).toString() );
+ IURI uri2 = factory.newURI( getURLFromPath( folderPath2 ).toString() );
+
+ assertTrue( "topFolder should not exist", !uri.isPresent() );
+
+ uri.touchFolder();
+
+ assertTrue( "topFolder should exist", uri.isPresent() );
+
+ IPath nestedPath = folderPath.append( "level1" ).append( "level2" );
+ IURI nesteduri = factory.newURI( getURLFromPath( nestedPath ).toString() );
+
+ assertTrue( "nestedFolder should not exist", !nesteduri.isPresent() );
+
+ nesteduri.touchFolder();
+
+ assertTrue( "nestedFolder should exist", nesteduri.isPresent() );
+
+ IURI child1 = uri2.append( factory.newURI( "child1" ) );
+ IURI child2 = uri2.append( factory.newURI( "child2" ) );
+
+ child1.touchLeaf();
+ child2.touchLeaf();
+
+ assertTrue ( "Child 1 in blank folder should exist ", child1.isPresent() );
+ assertTrue ( "Child 2 in blank folder should exist ", child2.isPresent() );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testList()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testList()");
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "topFolder2" ).makeAbsolute();
+ IPath folderPath1 = new Path( projectName_ ).append( "topFolder2" ).append( "leaf1" ).makeAbsolute();
+ IPath folderPath2 = new Path( projectName_ ).append( "topFolder2" ).append( "leaf2" ).makeAbsolute();
+ IPath folderPath3 = new Path( projectName_ ).append( "topFolder2" ).append( "leaf3" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+ IURI uri1 = factory.newURI( getURLFromPath( folderPath1 ).toString() );
+ IURI uri2 = factory.newURI( getURLFromPath( folderPath2 ).toString() );
+ IURI uri3 = factory.newURI( getURLFromPath( folderPath3 ).toString() );
+
+ uri1.touchFolder();
+ uri2.touchFolder();
+ uri3.touchFolder();
+
+ IURI[] babies = uri0.list();
+
+ assertTrue( "folder path should have 3 children", babies.length == 3 );
+
+ for( int index = 0; index < babies.length; index++ )
+ {
+ String folderName = babies[index].toString();
+ String leafName = folderName.substring( folderName.length() - 5, folderName.length() );
+ boolean Ok = leafName.equals( "leaf1") || leafName.equals( "leaf2" ) || leafName.equals( "leaf3" );
+ assertTrue( "Wrong leaf baby uri:" + folderName + "," + leafName, Ok );
+ }
+
+ IURI[] babies2 = uri0.list( new IURIFilter()
+ {
+ public boolean accepts( IURI uri )
+ {
+ return !uri.toString().endsWith( "leaf2");
+ }
+ } );
+
+ assertTrue( "folder path should have 2 filtered children", babies2.length == 2 );
+
+ for( int index = 0; index < babies2.length; index++ )
+ {
+ String folderName = babies2[index].toString();
+ String leafName = folderName.substring( folderName.length() - 5, folderName.length() );
+ boolean Ok = leafName.equals( "leaf1") || leafName.equals( "leaf3" );
+
+ assertTrue( "Wrong leaf baby uri:" + folderName + "," + leafName, Ok );
+ }
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testGetURIScheme()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "testGetScheme" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+ IURIScheme scheme = uri0.getURIScheme();
+
+ assertTrue( "Scheme name is not platform", scheme.toString().equals( "platform" ) );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Unexpected exception", false );
+ }
+ }
+
+ public void testAppend()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testAppend()");
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "topFolder3" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "level2");
+
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+
+ newURI.touchFolder();
+
+ assertTrue( "newURI should exist", newURI.isPresent() );
+ assertTrue( "newURI should not be a leaf", !newURI.isLeaf() );
+
+ // Ensure that append parameter is relative.
+ try
+ {
+ IURI newURI2 = uri0.append( uri0 );
+ assertTrue( "Appending using a non-relative should throw and exception", true );
+
+ // This code should never run.
+ newURI2.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testTouchLeaf()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testTouchLeaf()");
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "topFolder4" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "leafFile.txt");
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+
+ newURI.touchLeaf();
+
+ assertTrue( "newURI should exist", newURI.isPresent() );
+ assertTrue( "newURI should be a leaf", newURI.isLeaf() );
+
+ InputStream stream = newURI.getInputStream();
+ int byteRead = 0;
+
+ try
+ {
+ byteRead = stream.read(); // Returns a -1 if no bytes are read, which should be the case here.
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ finally
+ {
+ try
+ {
+ stream.close();
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ assertTrue( "There should be no bytes in this stream", byteRead == -1 );
+
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testIOOperations()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+ OutputStreamWriter stream = null;
+ PrintWriter writer = null;
+ InputStreamReader inputStream = null;
+ BufferedReader reader = null;
+
+ System.out.println("EclipseURITests.testIOOperations()");
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "topFolder5" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "leafFile.txt");
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+ assertTrue( "newURI should not be readable", !newURI.isReadable() );
+ assertTrue( "newURI should be writable", !newURI.isWritable() );
+
+ stream = new OutputStreamWriter( newURI.getOutputStream() );
+ writer = new PrintWriter( stream );
+
+ writer.println( "This is line 1 of the file." );
+ writer.println( "This is line 2 of the file." );
+ writer.println( "This is the end of the file." );
+
+ writer.close();
+ stream.close();
+ writer = null;
+ stream = null;
+
+ assertTrue( "newURI should be readable", newURI.isReadable() );
+ assertTrue( "newURI should be writable", newURI.isWritable() );
+
+ // Now read back this new file.
+ inputStream = new InputStreamReader( newURI.getInputStream() );
+ reader = new BufferedReader( inputStream );
+
+ assertTrue( "Bad first line of file", reader.readLine().equals("This is line 1 of the file.") );
+ assertTrue( "Bad second line of file", reader.readLine().equals("This is line 2 of the file.") );
+ assertTrue( "Bad last line of file", reader.readLine().equals("This is the end of the file.") );
+ assertTrue( "Extra lines found in file", reader.readLine() == null );
+
+ reader.close();
+
+ //Now rename the folder.
+ IURI level1 = uri0.append( uriRelative1 );
+ IURI newLevel = uri0.append( factory.newURI("newLevel1") );
+ IURI oldFile = newLevel.append( uriRelative2 );
+ IURI newFile = newLevel.append( factory.newURI( "newFile" ) );
+
+ assertTrue( "URI is not present", newURI.isPresent() );
+ assertTrue( "URI is present", !newLevel.append(uriRelative2).isPresent() );
+
+ level1.rename( newLevel );
+
+ assertTrue( "URI is present", !newURI.isPresent() );
+ assertTrue( "URI is not present", newLevel.append(uriRelative2).isPresent() );
+
+ assertTrue( "URI is present", !newFile.isPresent() );
+ assertTrue( "URI is not present", oldFile.isPresent() );
+
+ oldFile.rename( newFile );
+
+ assertTrue( "URI is not present", newFile.isPresent() );
+ assertTrue( "URI is present", !oldFile.isPresent() );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ finally
+ {
+ if( stream != null )
+ {
+ try
+ {
+ writer.close();
+ stream.close();
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ if( inputStream != null )
+ {
+ try
+ {
+ inputStream.close();
+ reader.close();
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+ }
+
+ }
+
+ public void testRelative()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testRelative()");
+
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "relativeProj" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI level1URI = uri0.append( uriRelative1 );
+
+ assertTrue( "Uri is relative", !uri0.isRelative() );
+ assertTrue( "Uri is not relative", uriRelative1.isRelative() );
+ assertTrue( "Uri is relative", !level1URI.isRelative() );
+
+ assertTrue( "Uri is not hierarchical", uri0.isHierarchical() );
+ assertTrue( "Uri is not hierarchical", uriRelative1.isHierarchical() );
+ assertTrue( "Uri is not hierarchical", level1URI.isHierarchical() );
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testErase1()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testErase1()");
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "topFolder6" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "leafFile.txt");
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+ IURI level1URI = uri0.append( uriRelative1 );
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+
+ newURI.touchLeaf();
+
+ assertTrue( "newURI should exist", newURI.isPresent() );
+
+ newURI.erase();
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+
+ assertTrue( "folder root should exist", uri0.isPresent() );
+ assertTrue( "folder level1 should exist", level1URI.isPresent() );
+
+ uri0.erase();
+
+ assertTrue( "folder root should not exist", !uri0.isPresent() );
+ assertTrue( "folder level1 should not exist", !level1URI.isPresent() );
+
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+
+ public void testIsLeaf()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("EclipseURITests.testIsLeaf()");
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "topFolder7" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "leafFile.txt");
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+ IURI parent = newURI.parent();
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+ assertTrue( "parent should not exist", !parent.isPresent() );
+ assertTrue( "newURI should not be a leaf yet", !newURI.isLeaf() );
+ assertTrue( "parent should not be a leaf", !parent.isLeaf() );
+
+ newURI.touchLeaf();
+
+ assertTrue( "newURI should exist", newURI.isPresent() );
+ assertTrue( "parent should exist", parent.isPresent() );
+ assertTrue( "newURI should be a leaf", newURI.isLeaf() );
+ assertTrue( "parent should not be a leaf", !parent.isLeaf() );
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testVisit()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+ IURIScheme scheme = EnvironmentService.getEclipseScheme();
+
+ System.out.println("EclipseURITests.testVisit()");
+ try
+ {
+ IPath folderPath0 = new Path( projectName_ ).append( "root" ).makeAbsolute();
+ IURI uri0 = factory.newURI( getURLFromPath( folderPath0 ).toString() );
+
+ Hashtable table = buildTestEntries( scheme, uri0 );
+
+ uri0.visit( new TestVisitor( table ) );
+ verifyTable( table );
+
+ resetTableForTest2( table );
+ uri0.visit( new TestVisitor( table ) );
+ verifyTable( table );
+
+ resetTable( table );
+ uri0.visit( new TestVisitor( table ), new TestFilter( table ) );
+ verifyTable( table );
+
+ resetTableForTest3( table );
+ uri0.visit( new TestVisitor( table ), new TestFilter( table ) );
+ verifyTable( table );
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ private class TestVisitor implements IURIVisitor
+ {
+ private Hashtable table_;
+
+ public TestVisitor( Hashtable table)
+ {
+ table_ = table;
+ }
+
+ public boolean visit( IURI uri )
+ {
+ NodeEntry entry = (NodeEntry)table_.get( getName( uri ) );
+ entry.wasVisited_ = true;
+ return !entry.stopTraversing_;
+ }
+ }
+
+ private class TestFilter implements IURIFilter
+ {
+ private Hashtable table_;
+
+ public TestFilter( Hashtable table)
+ {
+ table_ = table;
+ }
+
+ public boolean accepts( IURI uri )
+ {
+ NodeEntry entry = (NodeEntry)table_.get( getName( uri ) );
+ return entry.visitNode_;
+ }
+ }
+
+ private Hashtable buildTestEntries( IURIScheme scheme, IURI rootURI )
+ {
+ Hashtable table = new Hashtable();
+
+ try
+ {
+ IURI rootc1 = rootURI.append( scheme.newURI( "rootc1") );
+ IURI rootc2 = rootURI.append( scheme.newURI( "rootc2") );
+ IURI rootc3 = rootURI.append( scheme.newURI( "rootc3") );
+
+ IURI rootc2c1 = rootc2.append( scheme.newURI( "rootc2c1") );
+ IURI rootc2c2 = rootc2.append( scheme.newURI( "rootc2c2") );
+ IURI rootc2c3 = rootc2.append( scheme.newURI( "rootc2c3") );
+
+ IURI rootc2c2c1 = rootc2c2.append( scheme.newURI( "rootc2c2c1") );
+ IURI rootc2c2c2 = rootc2c2.append( scheme.newURI( "rootc2c2c2") );
+
+ IURI rootc3c1 = rootc3.append( scheme.newURI( "rootc3c1") );
+ IURI rootc3c2 = rootc3.append( scheme.newURI( "rootc3c2") );
+
+ // Now that the URI's are created we need to create physical folders
+ // and files to represent them.
+ rootc3c1.touchLeaf();
+ rootc3c2.touchLeaf();
+
+ rootc2c2c1.touchLeaf();
+ rootc2c2c2.touchLeaf();
+
+ rootc2c1.touchLeaf();
+ rootc2c3.touchLeaf();
+
+ rootc1.touchFolder();
+
+ // Now create the the table entries that will be used to visit
+ // the URI nodes.
+ table.put( "root", new NodeEntry() );
+ table.put( "rootc1", new NodeEntry() );
+ table.put( "rootc2", new NodeEntry() );
+ table.put( "rootc3", new NodeEntry() );
+ table.put( "rootc2c1", new NodeEntry() );
+ table.put( "rootc2c2", new NodeEntry() );
+ table.put( "rootc2c3", new NodeEntry() );
+ table.put( "rootc2c2c1", new NodeEntry() );
+ table.put( "rootc2c2c2", new NodeEntry() );
+ table.put( "rootc3c1", new NodeEntry() );
+ table.put( "rootc3c2", new NodeEntry() );
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+
+ return table;
+ }
+
+ private String getName( IURI uri )
+ {
+ String fullName = uri.toString();
+ int slash = fullName.lastIndexOf( '/' );
+ String name = fullName.substring( slash + 1, fullName.length() );
+
+ return name;
+ }
+
+ private void verifyTable( Hashtable table )
+ {
+ Iterator entries = table.entrySet().iterator();
+
+ while( entries.hasNext() )
+ {
+ Map.Entry entry = (Map.Entry)entries.next();
+
+ String key = (String)entry.getKey();
+ NodeEntry node = (NodeEntry)entry.getValue();
+
+ assertTrue( "Bad table result for key:" + key + " visited=" + node.wasVisited_
+ + " shouldbe=" + node.shouldBeVisited_,
+ node.wasVisited_ == node.shouldBeVisited_ );
+ }
+ }
+
+ private void resetTableForTest2( Hashtable table )
+ {
+ resetTable( table );
+
+ NodeEntry rootc2 = (NodeEntry)table.get( "rootc2" );
+ rootc2.stopTraversing_ = true;
+
+ NodeEntry rootc2c1 = (NodeEntry)table.get( "rootc2c1" );
+ rootc2c1.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c2 = (NodeEntry)table.get( "rootc2c2" );
+ rootc2c2.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c3 = (NodeEntry)table.get( "rootc2c3" );
+ rootc2c3.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c2c1 = (NodeEntry)table.get( "rootc2c2c1" );
+ rootc2c2c1.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c2c2 = (NodeEntry)table.get( "rootc2c2c2" );
+ rootc2c2c2.shouldBeVisited_ = false;
+ }
+
+ private void resetTableForTest3( Hashtable table )
+ {
+ resetTable( table );
+
+ NodeEntry rootc3 = (NodeEntry)table.get( "rootc3" );
+ rootc3.visitNode_ = false;
+ rootc3.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c2 = (NodeEntry)table.get( "rootc2c2" );
+ rootc2c2.visitNode_ = false;
+ rootc2c2.shouldBeVisited_ = false;
+
+ NodeEntry rootc3c1 = (NodeEntry)table.get( "rootc3c1" );
+ rootc3c1.visitNode_ = false;
+ rootc3c1.shouldBeVisited_ = false;
+ }
+
+ private void resetTable( Hashtable table )
+ {
+ Iterator entries = table.values().iterator();
+
+ while( entries.hasNext() )
+ {
+ NodeEntry entry = (NodeEntry)entries.next();
+ entry.wasVisited_ = false;
+ entry.shouldBeVisited_=true;
+ entry.stopTraversing_=false;
+ entry.visitNode_=true;
+ }
+ }
+
+ private String getURLFromPath( IPath absolutePath )
+ {
+ return "platform:/resource" + absolutePath;
+ }
+
+ private String getTmpFileURL( String fileName )
+ {
+ File newFile = new File( tempDir, fileName );
+
+ return "file:/" + newFile.getAbsolutePath();
+ }
+
+ private void deleteDir( File fileOrDirectory )
+ {
+ File[] childFiles = fileOrDirectory.listFiles();
+
+ if( childFiles != null )
+ {
+ // Delete all the child files or directories first before this one.
+ for( int index = 0; index < childFiles.length; index++ )
+ {
+ deleteDir( childFiles[index] );
+ }
+ }
+
+ fileOrDirectory.delete();
+ }
+
+ private class NodeEntry
+ {
+ public NodeEntry()
+ {
+ this( true, false, true );
+ }
+
+ public NodeEntry( boolean visitNode, boolean stop, boolean shouldBeVisited )
+ {
+ visitNode_ = visitNode;
+ stopTraversing_ = stop;
+ shouldBeVisited_ = shouldBeVisited;
+ wasVisited_ = false;
+ }
+
+ public boolean visitNode_;
+ public boolean stopTraversing_;
+
+ public boolean wasVisited_;
+ public boolean shouldBeVisited_;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EnvironmentTests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EnvironmentTests.java
new file mode 100644
index 0000000..abe8641
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/EnvironmentTests.java
@@ -0,0 +1,35 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.environment.tests;
+
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class EnvironmentTests extends TestSuite
+{
+
+ public static Test suite()
+ {
+ return new EnvironmentTests();
+ }
+
+ public EnvironmentTests()
+ {
+ super();
+
+ addTest( EclipseSchemeTests.suite() );
+ addTest( EclipseURITests.suite() );
+ addTest( FileSchemeTests.suite() );
+ addTest( FileURITests.suite() );
+ addTest( StatusHandlerTests.suite() );
+ addTest( LoggerTests.suite() );
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/FileSchemeTests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/FileSchemeTests.java
new file mode 100644
index 0000000..44d7c14
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/FileSchemeTests.java
@@ -0,0 +1,262 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.environment.tests;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.common.environment.EnvironmentService;
+import org.eclipse.wst.common.environment.uri.IURI;
+import org.eclipse.wst.common.environment.uri.IURIScheme;
+import org.eclipse.wst.common.environment.uri.URIException;
+
+public class FileSchemeTests extends TestCase
+{
+ private final String projectName_ = "TestProject";
+
+ public FileSchemeTests(String name)
+ {
+ super(name);
+ }
+ public static void main(String[] args)
+ {
+ if (args.length == 0)
+ {
+ runAll();
+ }
+ else if (args.length == 1)
+ {
+ String methodToRun = args[0].trim();
+ runOne(methodToRun);
+ }
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(FileSchemeTests.class);
+ }
+
+ protected static void runAll()
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static void runOne(String methodName)
+ {
+ TestSuite testSuite = new TestSuite();
+ TestCase test = new FileSchemeTests(methodName);
+ testSuite.addTest(test);
+ junit.textui.TestRunner.run(testSuite);
+ }
+
+ /**
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // Create a test project in the workbench
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = workspaceRoot.getProject( projectName_ );
+
+ if( project != null && project.exists() )
+ {
+ project.delete( true, null );
+ }
+
+ // Create the project
+ IProjectDescription desc = workspaceRoot.getWorkspace().newProjectDescription( projectName_ );
+ project.create( desc, null );
+ project.open( null );
+ }
+ /**
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ // Create a test project in the workbench
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = workspaceRoot.getProject( projectName_ );
+
+ project.delete( true, null );
+ }
+
+ public static Test getTest()
+ {
+ return new FileSchemeTests("FileSchemeTests");
+ }
+
+ public void testBadURIs()
+ {
+ IURIScheme scheme = EnvironmentService.getFileScheme();
+
+ try
+ {
+ IURI newURI = scheme.newURI( "bogus:/somefolder/somefile.txt");
+ assertTrue( "Non file protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ IURI newURI = scheme.newURI( ":/somefolder/somefile.txt");
+ assertTrue( "Non file protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+
+ try
+ {
+ IURI newURI = scheme.newURI( (String)null );
+ assertTrue( "Non file protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ IURI newURI = scheme.newURI( (URL)null );
+ assertTrue( "Non file protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+ try
+ {
+ IURI newURI = scheme.newURI( (IURI)null );
+ assertTrue( "Non file protocol should cause an exception", false );
+
+ // This code should never run.
+ newURI.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+ }
+
+ public void testNewURI()
+ {
+ IURIScheme scheme = EnvironmentService.getFileScheme() ;
+
+ try
+ {
+ IURI uri1 = scheme.newURI( "file:/tmp/myfile" );
+ IURI uri2 = scheme.newURI( "relativedirectory/relativefile" );
+ IURI uri3 = scheme.newURI( uri1 );
+ IURI uri4 = scheme.newURI( uri2 );
+ IURI uri5 = scheme.newURI( new URL( uri1.asString() ) );
+
+ File file1 = uri1.asFile();
+
+ uri1.touchLeaf();
+
+ assertTrue( "Is a file", file1.isFile() );
+ assertTrue( "File names not the same", uri1.asString().equals( uri3.toString() ));
+ assertTrue( "File names not the same", uri2.asString().equals( uri4.toString() ));
+ assertTrue( "File names not the same", uri1.asString().equals( uri5.toString() ));
+ assertTrue( "Protocol not file", uri1.getURIScheme().toString().equals("file"));
+ assertTrue( "Protocol not file", uri3.getURIScheme().toString().equals("file"));
+ assertTrue( "Protocol not file", uri5.getURIScheme().toString().equals("file"));
+ assertTrue( "Protocol not relative", uri2.getURIScheme().toString().equals("relative"));
+ assertTrue( "Protocol not relative", uri4.getURIScheme().toString().equals("relative"));
+
+ uri1.erase();
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testHierarchical()
+ {
+ IURIScheme scheme = EnvironmentService.getFileScheme() ;
+
+ assertTrue( "Not hierarchical", scheme.isHierarchical() == true );
+ }
+
+ public void testValidURIs()
+ {
+ try
+ {
+ IURIScheme scheme = EnvironmentService.getFileScheme();
+ IURI uri1 = scheme.newURI( "file:/tmp/somedir/somefile" );
+ IURI uri2 = scheme.newURI( "file:/tmp" );
+ IURI uri3 = scheme.newURI( "somerel" );
+ IURI uri4 = scheme.newURI( "somerel/somemorerel" );
+ IURI uri5 = scheme.newURI( "./somerel/somemore" );
+
+ assertTrue( "URI not valid", scheme.isValid( uri1 ) );
+ assertTrue( "URI not valid", scheme.isValid( uri2 ) );
+ assertTrue( "URI not valid", scheme.isValid( uri3 ) );
+ assertTrue( "URI not valid", scheme.isValid( uri4 ) );
+ assertTrue( "URI not valid", scheme.isValid( uri5 ) );
+ assertTrue( "URI has not valid status", scheme.validate( uri1 ).getSeverity() == IStatus.OK );
+ assertTrue( "URI has not valid status", scheme.validate( uri2 ).getSeverity() == IStatus.OK );
+ assertTrue( "URI has not valid status", scheme.validate( uri3 ).getSeverity() == IStatus.OK );
+ assertTrue( "URI has not valid status", scheme.validate( uri4 ).getSeverity() == IStatus.OK );
+ assertTrue( "URI has not valid status", scheme.validate( uri5 ).getSeverity() == IStatus.OK );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testInvalidURIs()
+ {
+ try
+ {
+ IURIScheme eclipseScheme = EnvironmentService.getEclipseScheme();
+ IURIScheme fileScheme = EnvironmentService.getFileScheme();
+
+ IURI uri1 = eclipseScheme.newURI( "platform:/resource/somedir/somefile" );
+
+ assertTrue( "URI valid", !fileScheme.isValid( uri1 ) );
+ assertTrue( "URI has a valid status", fileScheme.validate( uri1 ).getSeverity() == IStatus.ERROR );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/FileURITests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/FileURITests.java
new file mode 100644
index 0000000..5af05b1
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/FileURITests.java
@@ -0,0 +1,861 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * yyyymmdd bug Email and other contact information
+ * -------- -------- -----------------------------------------------------------
+ * 20060217 128456 pmoogk@ca.ibm.com - Peter Moogk
+ *******************************************************************************/
+package org.eclipse.wst.common.environment.tests;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.wst.common.environment.EnvironmentService;
+import org.eclipse.wst.common.environment.IEnvironment;
+import org.eclipse.wst.common.environment.uri.IURI;
+import org.eclipse.wst.common.environment.uri.IURIFactory;
+import org.eclipse.wst.common.environment.uri.IURIFilter;
+import org.eclipse.wst.common.environment.uri.IURIScheme;
+import org.eclipse.wst.common.environment.uri.IURIVisitor;
+import org.eclipse.wst.common.environment.uri.URIException;
+
+public class FileURITests extends TestCase
+{
+ private File tempFile;
+ private File tempDir;
+
+ public FileURITests(String name)
+ {
+ super(name);
+ }
+ public static void main(String[] args)
+ {
+ if (args.length == 0)
+ {
+ runAll();
+ }
+ else if (args.length == 1)
+ {
+ String methodToRun = args[0].trim();
+ runOne(methodToRun);
+ }
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(FileURITests.class);
+ }
+
+ protected static void runAll()
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static void runOne(String methodName)
+ {
+ TestSuite testSuite = new TestSuite();
+ TestCase test = new FileURITests(methodName);
+ System.out.println("Calling FileURITests."+methodName);
+ testSuite.addTest(test);
+ junit.textui.TestRunner.run(testSuite);
+ }
+
+ /**
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ tempFile = File.createTempFile("tmp", "tmp", null );
+ tempDir = new File( tempFile.getParentFile(), "tmpDir" );
+ tempDir.mkdir();
+ }
+
+ /**
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ deleteFiles( tempDir );
+ tempFile.delete();
+ }
+
+ private void deleteFiles( File directory )
+ {
+ if (directory != null) {
+ File[] children = directory.listFiles();
+
+ /*
+ * If 'directory' is not a directory, directory.listFiles can
+ * return null.
+ */
+ if (children != null) {
+ for (int index = 0; index < children.length; index++) {
+ File child = children[index];
+
+ if (child.isDirectory()) {
+ deleteFiles(child);
+ }
+
+ child.delete();
+ }
+ }
+ }
+ }
+
+ private String getTmpFileURL( String fileName )
+ {
+ File newFile = new File( tempDir, fileName );
+
+ return "file:/" + newFile.getAbsolutePath();
+ }
+
+ public static Test getTest()
+ {
+ return new FileURITests("FileURITests");
+ }
+ public void testAvailable()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("FileURITests.testAvailable()");
+
+ try
+ {
+ IURI uri2 = factory.newURI( getTmpFileURL( "somefile" ) );
+ IURI uri3 = factory.newURI( "relativedirectory/relativefile" );
+
+ assertTrue( "Not available as URL", uri2.isAvailableAsURL() );
+ assertTrue( "Available as URL", !uri3.isAvailableAsURL() );
+
+ assertTrue( "Not available as File", uri2.isAvailableAsFile() );
+ assertTrue( "Available as File", !uri3.isAvailableAsFile() );
+
+ File file2 = uri2.asFile();
+ URL url2 = uri2.asURL();
+
+ uri2.touchLeaf();
+
+ assertTrue( "Is a file", file2.isFile() );
+ assertTrue( "Wrong protocol", url2.getProtocol().equals( "file" ));
+ assertTrue( uri2.asString().length() > 5 );
+ assertTrue( uri2.toString().length() > 5 );
+ uri2.erase();
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testTouchFolder()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("FileURITests.testTouchFolder()");
+ try
+ {
+ File folderPath = new File( tempDir, "topFolder" );
+ File folderPath2 = new File( folderPath, "space folder" );
+ IURI uri = factory.newURI( folderPath.toURL().toString() );
+ IURI uri2 = factory.newURI( folderPath2.toURL().toString() );
+
+ assertTrue( "topFolder should not exist", !uri.isPresent() );
+
+ uri.touchFolder();
+
+ assertTrue( "topFolder should exist", uri.isPresent() );
+
+ File nestedPath = new File( new File( folderPath, "level1" ), "level2" );
+ IURI nesteduri = factory.newURI( nestedPath.toURL().toString() );
+
+ assertTrue( "nestedFolder should not exist", !nesteduri.isPresent() );
+
+ nesteduri.touchFolder();
+
+ assertTrue( "nestedFolder should exist", nesteduri.isPresent() );
+
+ IURI child1 = uri2.append( factory.newURI( "child1" ) );
+ IURI child2 = uri2.append( factory.newURI( "child2" ) );
+
+ child1.touchLeaf();
+ child2.touchLeaf();
+
+ assertTrue ( "Child 1 in blank folder should exist ", child1.isPresent() );
+ assertTrue ( "Child 2 in blank folder should exist ", child2.isPresent() );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testList()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("FileURITests.testList()");
+ try
+ {
+ File folderPath0 = new File( tempDir, "topFolder2" );
+ File folderPath1 = new File( new File( tempDir, "topFolder2" ), "leaf1" );
+ File folderPath2 = new File( new File( tempDir, "topFolder2" ), "leaf2" );
+ File folderPath3 = new File( new File( tempDir, "topFolder2" ), "leaf3" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+ IURI uri1 = factory.newURI( folderPath1.toURL().toString() );
+ IURI uri2 = factory.newURI( folderPath2.toURL().toString() );
+ IURI uri3 = factory.newURI( folderPath3.toURL().toString() );
+
+ uri1.touchFolder();
+ uri2.touchFolder();
+ uri3.touchFolder();
+
+ IURI[] babies = uri0.list();
+
+ assertTrue( "folder path should have 3 children", babies.length == 3 );
+
+ for( int index = 0; index < babies.length; index++ )
+ {
+ String folderName = babies[index].toString();
+ String leafName = folderName.substring( folderName.length() - 5, folderName.length() );
+ boolean Ok = leafName.equals( "leaf1") || leafName.equals( "leaf2" ) || leafName.equals( "leaf3" );
+ assertTrue( "Wrong leaf baby uri:" + folderName + "," + leafName, Ok );
+ }
+
+ IURI[] babies2 = uri0.list( new IURIFilter()
+ {
+ public boolean accepts( IURI uri )
+ {
+ return !uri.toString().endsWith( "leaf2");
+ }
+ } );
+
+ assertTrue( "folder path should have 2 filtered children", babies2.length == 2 );
+
+ for( int index = 0; index < babies2.length; index++ )
+ {
+ String folderName = babies2[index].toString();
+ String leafName = folderName.substring( folderName.length() - 5, folderName.length() );
+ boolean Ok = leafName.equals( "leaf1") || leafName.equals( "leaf3" );
+
+ assertTrue( "Wrong leaf baby uri:" + folderName + "," + leafName, Ok );
+ }
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testGetURIScheme()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ try
+ {
+ File folderPath0 = new File( tempDir, "testGetScheme" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+ IURIScheme scheme = uri0.getURIScheme();
+
+ assertTrue( "Scheme name is not file", scheme.toString().equals( "file" ) );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Unexpected exception", false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testAppend()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("FileURITests.testAppend()");
+ try
+ {
+ File folderPath0 = new File( tempDir, "topFolder3" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "level2");
+
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+
+ newURI.touchFolder();
+
+ assertTrue( "newURI should exist", newURI.isPresent() );
+ assertTrue( "newURI should not be a leaf", !newURI.isLeaf() );
+
+ // Ensure that append parameter is relative.
+ try
+ {
+ IURI newURI2 = uri0.append( uri0 );
+ assertTrue( "Appending using a non-relative should throw and exception", true );
+
+ // This code should never run.
+ newURI2.asFile();
+ }
+ catch( URIException exc )
+ {
+ }
+
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testTouchLeaf()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("FileURITests.testTouchLeaf()");
+ try
+ {
+ File folderPath0 = new File( tempDir, "topFolder4" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "leafFile.txt");
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+
+ newURI.touchLeaf();
+
+ assertTrue( "newURI should exist", newURI.isPresent() );
+ assertTrue( "newURI should be a leaf", newURI.isLeaf() );
+
+ InputStream stream = newURI.getInputStream();
+ int byteRead = 0;
+
+ try
+ {
+ byteRead = stream.read(); // Returns a -1 if no bytes are read, which should be the case here.
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ finally
+ {
+ try
+ {
+ stream.close();
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ assertTrue( "There should be no bytes in this stream", byteRead == -1 );
+
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testIOOperations()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+ OutputStreamWriter stream = null;
+ PrintWriter writer = null;
+ InputStreamReader inputStream = null;
+ BufferedReader reader = null;
+
+ System.out.println("FileURITests.testIOOperations()");
+ try
+ {
+ File folderPath0 = new File( tempDir, "topFolder5" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "leafFile.txt");
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+ assertTrue( "newURI should not be readable", !newURI.isReadable() );
+ assertTrue( "newURI should be writable", !newURI.isWritable() );
+
+ stream = new OutputStreamWriter( newURI.getOutputStream() );
+ writer = new PrintWriter( stream );
+
+ writer.println( "This is line 1 of the file." );
+ writer.println( "This is line 2 of the file." );
+ writer.println( "This is the end of the file." );
+
+ writer.close();
+ stream.close();
+ writer = null;
+ stream = null;
+
+ assertTrue( "newURI should be readable", newURI.isReadable() );
+ assertTrue( "newURI should be writable", newURI.isWritable() );
+
+ // Now read back this new file.
+ inputStream = new InputStreamReader( newURI.getInputStream() );
+ reader = new BufferedReader( inputStream );
+
+ assertTrue( "Bad first line of file", reader.readLine().equals("This is line 1 of the file.") );
+ assertTrue( "Bad second line of file", reader.readLine().equals("This is line 2 of the file.") );
+ assertTrue( "Bad last line of file", reader.readLine().equals("This is the end of the file.") );
+ assertTrue( "Extra lines found in file", reader.readLine() == null );
+
+ reader.close();
+
+ //Now rename the folder.
+ IURI level1 = uri0.append( uriRelative1 );
+ IURI newLevel = uri0.append( factory.newURI("newLevel1") );
+ IURI oldFile = newLevel.append( uriRelative2 );
+ IURI newFile = newLevel.append( factory.newURI( "newFile" ) );
+
+ assertTrue( "URI is not present", newURI.isPresent() );
+ assertTrue( "URI is present", !newLevel.append(uriRelative2).isPresent() );
+
+ level1.rename( newLevel );
+
+ assertTrue( "URI is present", !newURI.isPresent() );
+ assertTrue( "URI is not present", newLevel.append(uriRelative2).isPresent() );
+
+ assertTrue( "URI is present", !newFile.isPresent() );
+ assertTrue( "URI is not present", oldFile.isPresent() );
+
+ oldFile.rename( newFile );
+
+ assertTrue( "URI is not present", newFile.isPresent() );
+ assertTrue( "URI is present", !oldFile.isPresent() );
+ }
+ catch( URIException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ finally
+ {
+ if( stream != null )
+ {
+ try
+ {
+ writer.close();
+ stream.close();
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ if( inputStream != null )
+ {
+ try
+ {
+ inputStream.close();
+ reader.close();
+ }
+ catch( IOException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+ }
+
+ }
+
+ public void testRelative()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("FileURITests.testRelative()");
+
+ try
+ {
+ File folderPath0 = new File( tempDir, "relativeProj" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI level1URI = uri0.append( uriRelative1 );
+
+ assertTrue( "Uri is relative", !uri0.isRelative() );
+ assertTrue( "Uri is not relative", uriRelative1.isRelative() );
+ assertTrue( "Uri is relative", !level1URI.isRelative() );
+
+ assertTrue( "Uri is not hierarchical", uri0.isHierarchical() );
+ assertTrue( "Uri is not hierarchical", uriRelative1.isHierarchical() );
+ assertTrue( "Uri is not hierarchical", level1URI.isHierarchical() );
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testErase1()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("FileURITests.testErase1()");
+ try
+ {
+ File folderPath0 = new File( tempDir, "topFolder6" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "leafFile.txt");
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+ IURI level1URI = uri0.append( uriRelative1 );
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+
+ newURI.touchLeaf();
+
+ assertTrue( "newURI should exist", newURI.isPresent() );
+
+ newURI.erase();
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+
+ assertTrue( "folder root should exist", uri0.isPresent() );
+ assertTrue( "folder level1 should exist", level1URI.isPresent() );
+
+ uri0.erase();
+
+ assertTrue( "folder root should not exist", !uri0.isPresent() );
+ assertTrue( "folder level1 should not exist", !level1URI.isPresent() );
+
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+
+ public void testIsLeaf()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+
+ System.out.println("FileURITests.testIsLeaf()");
+ try
+ {
+ File folderPath0 = new File( tempDir, "topFolder7" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+ IURI uriRelative1 = factory.newURI( "level1");
+ IURI uriRelative2 = factory.newURI( "leafFile.txt");
+ IURI newURI = uri0.append( uriRelative1 ).append( uriRelative2 );
+ IURI parent = newURI.parent();
+
+ assertTrue( "newURI should not exist", !newURI.isPresent() );
+ assertTrue( "parent should not exist", !parent.isPresent() );
+ assertTrue( "newURI should not be a leaf yet", !newURI.isLeaf() );
+ assertTrue( "parent should not be a leaf", !parent.isLeaf() );
+
+ newURI.touchLeaf();
+
+ assertTrue( "newURI should exist", newURI.isPresent() );
+ assertTrue( "parent should exist", parent.isPresent() );
+ assertTrue( "newURI should be a leaf", newURI.isLeaf() );
+ assertTrue( "parent should not be a leaf", !parent.isLeaf() );
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ public void testVisit()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IURIFactory factory = environment.getURIFactory();
+ IURIScheme scheme = EnvironmentService.getFileScheme();
+
+ System.out.println("FileURITests.testVisit()");
+ try
+ {
+ File folderPath0 = new File( tempDir, "root" );
+ IURI uri0 = factory.newURI( folderPath0.toURL().toString() );
+
+ Hashtable table = buildTestEntries( scheme, uri0 );
+
+ uri0.visit( new TestVisitor( table ) );
+ verifyTable( table );
+
+ resetTableForTest2( table );
+ uri0.visit( new TestVisitor( table ) );
+ verifyTable( table );
+
+ resetTable( table );
+ uri0.visit( new TestVisitor( table ), new TestFilter( table ) );
+ verifyTable( table );
+
+ resetTableForTest3( table );
+ uri0.visit( new TestVisitor( table ), new TestFilter( table ) );
+ verifyTable( table );
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ catch( MalformedURLException exc )
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+ }
+
+ private class TestVisitor implements IURIVisitor
+ {
+ private Hashtable table_;
+
+ public TestVisitor( Hashtable table)
+ {
+ table_ = table;
+ }
+
+ public boolean visit( IURI uri )
+ {
+ NodeEntry entry = (NodeEntry)table_.get( getName( uri ) );
+ entry.wasVisited_ = true;
+ return !entry.stopTraversing_;
+ }
+ }
+
+ private class TestFilter implements IURIFilter
+ {
+ private Hashtable table_;
+
+ public TestFilter( Hashtable table)
+ {
+ table_ = table;
+ }
+
+ public boolean accepts( IURI uri )
+ {
+ NodeEntry entry = (NodeEntry)table_.get( getName( uri ) );
+ return entry.visitNode_;
+ }
+ }
+
+ private Hashtable buildTestEntries( IURIScheme scheme, IURI rootURI )
+ {
+ Hashtable table = new Hashtable();
+
+ try
+ {
+ IURI rootc1 = rootURI.append( scheme.newURI( "rootc1") );
+ IURI rootc2 = rootURI.append( scheme.newURI( "rootc2") );
+ IURI rootc3 = rootURI.append( scheme.newURI( "rootc3") );
+
+ IURI rootc2c1 = rootc2.append( scheme.newURI( "rootc2c1") );
+ IURI rootc2c2 = rootc2.append( scheme.newURI( "rootc2c2") );
+ IURI rootc2c3 = rootc2.append( scheme.newURI( "rootc2c3") );
+
+ IURI rootc2c2c1 = rootc2c2.append( scheme.newURI( "rootc2c2c1") );
+ IURI rootc2c2c2 = rootc2c2.append( scheme.newURI( "rootc2c2c2") );
+
+ IURI rootc3c1 = rootc3.append( scheme.newURI( "rootc3c1") );
+ IURI rootc3c2 = rootc3.append( scheme.newURI( "rootc3c2") );
+
+ // Now that the URI's are created we need to create physical folders
+ // and files to represent them.
+ rootc3c1.touchLeaf();
+ rootc3c2.touchLeaf();
+
+ rootc2c2c1.touchLeaf();
+ rootc2c2c2.touchLeaf();
+
+ rootc2c1.touchLeaf();
+ rootc2c3.touchLeaf();
+
+ rootc1.touchFolder();
+
+ // Now create the the table entries that will be used to visit
+ // the URI nodes.
+ table.put( "root", new NodeEntry() );
+ table.put( "rootc1", new NodeEntry() );
+ table.put( "rootc2", new NodeEntry() );
+ table.put( "rootc3", new NodeEntry() );
+ table.put( "rootc2c1", new NodeEntry() );
+ table.put( "rootc2c2", new NodeEntry() );
+ table.put( "rootc2c3", new NodeEntry() );
+ table.put( "rootc2c2c1", new NodeEntry() );
+ table.put( "rootc2c2c2", new NodeEntry() );
+ table.put( "rootc3c1", new NodeEntry() );
+ table.put( "rootc3c2", new NodeEntry() );
+ }
+ catch( URIException exc)
+ {
+ assertTrue( "Exception throw:" + exc.getMessage(), false );
+ }
+
+ return table;
+ }
+
+ private String getName( IURI uri )
+ {
+ String fullName = uri.toString();
+ int slash = fullName.lastIndexOf( '/' );
+
+ if( slash == -1 ) slash = fullName.lastIndexOf( '\\' );
+
+ String name = fullName.substring( slash + 1, fullName.length() );
+
+ return name;
+ }
+
+ private void verifyTable( Hashtable table )
+ {
+ Iterator entries = table.entrySet().iterator();
+
+ while( entries.hasNext() )
+ {
+ Map.Entry entry = (Map.Entry)entries.next();
+
+ String key = (String)entry.getKey();
+ NodeEntry node = (NodeEntry)entry.getValue();
+
+ assertTrue( "Bad table result for key:" + key + " visited=" + node.wasVisited_
+ + " shouldbe=" + node.shouldBeVisited_,
+ node.wasVisited_ == node.shouldBeVisited_ );
+ }
+ }
+
+ private void resetTableForTest2( Hashtable table )
+ {
+ resetTable( table );
+
+ NodeEntry rootc2 = (NodeEntry)table.get( "rootc2" );
+ rootc2.stopTraversing_ = true;
+
+ NodeEntry rootc2c1 = (NodeEntry)table.get( "rootc2c1" );
+ rootc2c1.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c2 = (NodeEntry)table.get( "rootc2c2" );
+ rootc2c2.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c3 = (NodeEntry)table.get( "rootc2c3" );
+ rootc2c3.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c2c1 = (NodeEntry)table.get( "rootc2c2c1" );
+ rootc2c2c1.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c2c2 = (NodeEntry)table.get( "rootc2c2c2" );
+ rootc2c2c2.shouldBeVisited_ = false;
+ }
+
+ private void resetTableForTest3( Hashtable table )
+ {
+ resetTable( table );
+
+ NodeEntry rootc3 = (NodeEntry)table.get( "rootc3" );
+ rootc3.visitNode_ = false;
+ rootc3.shouldBeVisited_ = false;
+
+ NodeEntry rootc2c2 = (NodeEntry)table.get( "rootc2c2" );
+ rootc2c2.visitNode_ = false;
+ rootc2c2.shouldBeVisited_ = false;
+
+ NodeEntry rootc3c1 = (NodeEntry)table.get( "rootc3c1" );
+ rootc3c1.visitNode_ = false;
+ rootc3c1.shouldBeVisited_ = false;
+ }
+
+ private void resetTable( Hashtable table )
+ {
+ Iterator entries = table.values().iterator();
+
+ while( entries.hasNext() )
+ {
+ NodeEntry entry = (NodeEntry)entries.next();
+ entry.wasVisited_ = false;
+ entry.shouldBeVisited_=true;
+ entry.stopTraversing_=false;
+ entry.visitNode_=true;
+ }
+ }
+
+ private class NodeEntry
+ {
+ public NodeEntry()
+ {
+ this( true, false, true );
+ }
+
+ public NodeEntry( boolean visitNode, boolean stop, boolean shouldBeVisited )
+ {
+ visitNode_ = visitNode;
+ stopTraversing_ = stop;
+ shouldBeVisited_ = shouldBeVisited;
+ wasVisited_ = false;
+ }
+
+ public boolean visitNode_;
+ public boolean stopTraversing_;
+
+ public boolean wasVisited_;
+ public boolean shouldBeVisited_;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/LoggerTests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/LoggerTests.java
new file mode 100644
index 0000000..f95c777
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/LoggerTests.java
@@ -0,0 +1,82 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.environment.tests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.common.environment.EnvironmentService;
+import org.eclipse.wst.common.environment.IEnvironment;
+import org.eclipse.wst.common.environment.ILog;
+import org.eclipse.wst.common.environment.StatusException;
+
+public class LoggerTests extends TestCase
+{
+ public LoggerTests(String name)
+ {
+ super(name);
+ }
+
+ public static void main(String[] args)
+ {
+ if (args.length == 0)
+ {
+ runAll();
+ }
+ else if (args.length == 1)
+ {
+ String methodToRun = args[0].trim();
+ runOne(methodToRun);
+ }
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(LoggerTests.class);
+ }
+
+ protected static void runAll()
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static void runOne(String methodName)
+ {
+ TestSuite testSuite = new TestSuite();
+ TestCase test = new LoggerTests(methodName);
+ System.out.println("Calling LoggerTests."+methodName);
+ testSuite.addTest(test);
+ junit.textui.TestRunner.run(testSuite);
+ }
+
+ public void testLogger()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ ILog logger = environment.getLog();
+
+ //assertTrue("Logging enabled", !logger.isEnabled());
+ // We may or may not be called with the -debug option,
+ // so we can not test for it, but we can write an appropriate
+ // message, to help interpret results, if needed.
+ if (logger.isEnabled()) {
+ System.out.println(" Logging is enabled");
+ } else {
+ System.out.println(" Logging is is not enabled");
+ }
+ assertTrue( "Logging feature enabled", !logger.isEnabled( "bad option" ) );
+
+ logger.log( ILog.ERROR, 0, this, "test logger", Status.CANCEL_STATUS );
+ logger.log( ILog.INFO, 1, this, "another method", "object" );
+ logger.log( ILog.WARNING, 3, this, "one more method", new StatusException( Status.OK_STATUS ));
+ logger.log( ILog.ERROR, "option1", 0, this, "test logger", Status.CANCEL_STATUS );
+ logger.log( ILog.INFO, "option2", 1, this, "another method", "object" );
+ logger.log( ILog.WARNING, "option3", 3, this, "one more method", new StatusException( Status.OK_STATUS ));
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/StatusHandlerTests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/StatusHandlerTests.java
new file mode 100644
index 0000000..d68b988
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/environment/tests/StatusHandlerTests.java
@@ -0,0 +1,112 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2005 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.environment.tests;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.common.environment.Choice;
+import org.eclipse.wst.common.environment.EnvironmentService;
+import org.eclipse.wst.common.environment.IEnvironment;
+import org.eclipse.wst.common.environment.IStatusHandler;
+import org.eclipse.wst.common.environment.StatusException;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class StatusHandlerTests extends TestCase
+{
+ private IStatus error;
+ private IStatus info;
+ private IStatus warning;
+
+ public StatusHandlerTests(String name)
+ {
+ super(name);
+
+ error = new Status( IStatus.ERROR, "id", 0, "error message", null );
+ info = new Status( IStatus.INFO, "id", 0, "info message", null );
+ warning = new Status( IStatus.WARNING, "id", 0, "warning message", null );
+ }
+
+ public static void main(String[] args)
+ {
+ if (args.length == 0)
+ {
+ runAll();
+ }
+ else if (args.length == 1)
+ {
+ String methodToRun = args[0].trim();
+ runOne(methodToRun);
+ }
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(StatusHandlerTests.class);
+ }
+
+ protected static void runAll()
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static void runOne(String methodName)
+ {
+ TestSuite testSuite = new TestSuite();
+ TestCase test = new StatusHandlerTests(methodName);
+ System.out.println("Calling StatusHandlerTests."+methodName);
+ testSuite.addTest(test);
+ junit.textui.TestRunner.run(testSuite);
+ }
+
+ public void testEnvironmentStatusHandler()
+ {
+ IEnvironment environment = EnvironmentService.getEclipseConsoleEnvironment();
+ IStatusHandler handler = environment.getStatusHandler();
+
+ try
+ {
+ Choice choice1 = new Choice();
+ Choice choice2 = new Choice( 'o', "Ok", "description" );
+
+ StatusException someException = new StatusException( error );
+
+ assertTrue( "Status not the same ", someException.getStatus() == error );
+
+ handler.report( Status.OK_STATUS );
+ handler.report( error );
+ handler.report( warning );
+ handler.report( info );
+ choice1.setShortcut( 'c' );
+ choice1.setLabel( "cancel" );
+ choice1.setDescription( "cancel description" );
+
+ Choice result = handler.report( error, null );
+
+ assertTrue( "result not null ", result == null );
+
+ result = handler.report( error, new Choice[0] );
+ assertTrue( "result not null ", result == null );
+
+ result = handler.report( error, new Choice[]{ choice2, choice1 } );
+ assertTrue( "First choice shortcut not the same", result.getShortcut() == choice2.getShortcut());
+ assertTrue( "First choice label not the same", result.getLabel().equals( choice2.getLabel()));
+ assertTrue( "First choice description not the same", result.getDescription().equals( choice2.getDescription()));
+
+ handler.reportError( error );
+ handler.reportInfo( info );
+
+ }
+ catch( StatusException exc )
+ {
+ assertTrue( "unexpected exception:", false );
+ }
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/artifactedit/tests/ArtifactEditAPITests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/artifactedit/tests/ArtifactEditAPITests.java
new file mode 100644
index 0000000..615063d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/artifactedit/tests/ArtifactEditAPITests.java
@@ -0,0 +1,21 @@
+package org.eclipse.wst.common.frameworks.artifactedit.tests;
+
+
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class ArtifactEditAPITests extends TestSuite {
+
+
+
+ public static Test suite() {
+ return new ArtifactEditAPITests();
+ }
+
+ public ArtifactEditAPITests() {
+ super();
+ //addTest(new SimpleTestSuite(ArtifactEditTest.class));
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/artifactedit/tests/ArtifactEditTest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/artifactedit/tests/ArtifactEditTest.java
new file mode 100644
index 0000000..c1a0655
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/artifactedit/tests/ArtifactEditTest.java
@@ -0,0 +1,505 @@
+package org.eclipse.wst.common.frameworks.artifactedit.tests;
+
+
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.etools.common.test.apitools.ProjectUnzipUtil;
+import org.eclipse.wst.common.componentcore.ArtifactEdit;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.UnresolveableURIException;
+import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel;
+import org.eclipse.wst.common.componentcore.internal.StructureEdit;
+import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent;
+import org.eclipse.wst.common.frameworks.internal.operations.IOperationHandler;
+import org.eclipse.wst.common.internal.emfworkbench.EMFWorkbenchContext;
+import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelEvent;
+import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelListener;
+import org.eclipse.wst.common.tests.CommonTestsPlugin;
+
+
+
+public class ArtifactEditTest extends TestCase {
+ public static String fileSep = System.getProperty("file.separator");
+ public static final String PROJECT_NAME = "TestArtifactEdit";
+ public static final String WEB_MODULE_NAME = "WebModule1";
+ public static final URI moduleURI = URI.createURI("module:/resource/TestArtifactEdit/WebModule1");
+ public static final String EDIT_MODEL_ID = "jst.web";
+ private ArtifactEditModel artifactEditModelForRead;
+ private ArtifactEditModel artifactEditModelForWrite;
+ private ArtifactEdit artifactEditForRead;
+ private ArtifactEdit artifactEditForWrite;
+ private EditModelListener emListener;
+ private Path zipFilePath = new Path("TestData" + fileSep + "TestArtifactEdit.zip");
+ private IProject project;
+
+
+
+ private IOperationHandler handler = new IOperationHandler() {
+
+
+ public boolean canContinue(String message) {
+ return false;
+ }
+
+
+ public boolean canContinue(String message, String[] items) {
+
+ return false;
+ }
+
+ public int canContinueWithAllCheck(String message) {
+
+ return 0;
+ }
+
+ public int canContinueWithAllCheckAllowCancel(String message) {
+
+ return 0;
+ }
+
+ public void error(String message) {
+
+
+ }
+
+ public void inform(String message) {
+
+
+ }
+
+
+ public Object getContext() {
+
+ return null;
+ }
+ };
+
+ public ArtifactEditTest() {
+ super();
+
+ }
+
+ protected void setUp() throws Exception {
+ if (!getTargetProject().exists())
+ if (!createProject())
+ fail();
+ project = getTargetProject();
+ }
+
+
+ public IProject getTargetProject() {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
+ }
+
+ public boolean createProject() {
+ IPath localZipPath = getLocalPath();
+ ProjectUnzipUtil util = new ProjectUnzipUtil(localZipPath, new String[]{PROJECT_NAME});
+ return util.createProjects();
+ }
+
+
+
+ private IPath getLocalPath() {
+
+ URL url = Platform.getBundle("org.eclipse.wst.common.tests").getEntry("");
+
+ try {
+ url = new URL(url.toString() + zipFilePath);
+
+ } catch (MalformedURLException e1) {
+ e1.printStackTrace();
+ }
+
+ try {
+ url = FileLocator.toFileURL(url);
+ printLocalPath(url);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return new Path(url.getPath());
+ }
+
+
+
+ private void printLocalPath(URL url) {
+ IPath path = ResourcesPlugin.getWorkspace().getRoot().getLocation();
+ File file = new File(path.append("PlatformInfo.txt").toOSString());
+ BufferedWriter bw;
+ String osName = System.getProperty("os.name");
+ String fileSeperator = System.getProperty("path.separator");
+ URL urlFindUsingPlugin = CommonTestsPlugin.instance.find(zipFilePath);
+ try {
+ urlFindUsingPlugin = Platform.asLocalURL(urlFindUsingPlugin);
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ String javaFileSeperator = new Character(File.pathSeparatorChar).toString();
+
+
+ try {
+ bw = new BufferedWriter(new FileWriter(file));
+ bw.write("pluginDescriptor URL " + url.toString());
+ bw.write("\n");
+ bw.write("Operating System: " + osName);
+ bw.write("\n");
+ bw.write("System file seperator: " + fileSeperator);
+ bw.write("\n");
+ bw.write("Using Pluign.find URL:" + urlFindUsingPlugin.toString());
+ bw.write("\n");
+ bw.write("Java file seperator: " + javaFileSeperator);
+ bw.write("\n");
+ bw.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+
+ }
+
+
+
+ public void testGetArtifactEditForReadWorkbenchComponent() {
+ ArtifactEdit edit = null;
+ try {
+ edit = ArtifactEdit.getArtifactEditForRead(project);
+ } finally {
+ if (edit != null) {
+ edit.dispose();
+ }
+ assertTrue(edit != null);
+ }
+ }
+
+ public void testGetArtifactEditForWriteWorkbenchComponent() {
+ ArtifactEdit edit = null;
+ try {
+ edit = ArtifactEdit.getArtifactEditForWrite(project);
+
+ } finally {
+ if (edit != null) {
+ edit.dispose();
+ }
+ assertTrue(edit != null);
+ }
+ }
+
+
+ public void testGetArtifactEditForReadComponentHandle() {
+ StructureEdit moduleCore = null;
+ ArtifactEdit edit = null;
+ try {
+ moduleCore = StructureEdit.getStructureEditForRead(project);
+ WorkbenchComponent wbComponent = moduleCore.getComponent();
+ edit = ArtifactEdit.getArtifactEditForRead(project);
+
+ } finally {
+ if (moduleCore != null) {
+ moduleCore.dispose();
+ edit.dispose();
+ }
+ assertTrue(edit != null);
+ }
+ }
+
+
+ public void testGetArtifactEditForWriteComponentHandle() {
+ ArtifactEdit edit = null;
+ try {
+ edit = ArtifactEdit.getArtifactEditForWrite(project);
+ } finally {
+ if (edit != null) {
+ edit.dispose();
+ }
+ assertTrue(edit != null);
+ }
+ }
+
+ public void testIsValidEditableModule() {
+ assertTrue(ArtifactEdit.isValidEditableModule(ComponentCore.createComponent(project)));
+ }
+
+ public void testArtifactEditArtifactEditModel() {
+ ArtifactEdit edit = new ArtifactEdit(getArtifactEditModelforRead());
+ assertNotNull(edit);
+ edit.dispose();
+ }
+
+
+ public void testArtifactEditModuleCoreNatureWorkbenchComponentboolean() {
+ try {
+ StructureEdit.getModuleCoreNature(moduleURI);
+ } catch (UnresolveableURIException e) {
+ fail();
+ }
+ ArtifactEdit edit = null;
+ try {
+ edit = new ArtifactEdit(project, true);
+ assertNotNull(edit);
+ } finally {
+ if (edit != null)
+ edit.dispose();
+ }
+ }
+
+ public void testSave() {
+ ArtifactEdit edit = null;
+ try {
+ edit = ArtifactEdit.getArtifactEditForWrite(project);
+ try {
+ edit.save(new NullProgressMonitor());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ } finally {
+ if (edit != null) {
+ edit.dispose();
+ }
+ assertTrue(edit != null);
+ }
+ assertTrue(true);
+ }
+
+ public void testSaveIfNecessary() {
+ ArtifactEdit edit = null;
+ try {
+ edit = ArtifactEdit.getArtifactEditForWrite(project);
+ try {
+ edit.saveIfNecessary(new NullProgressMonitor());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ } finally {
+ if (edit != null) {
+ edit.dispose();
+ }
+ }
+ pass();
+ }
+
+ public void testSaveIfNecessaryWithPrompt() {
+ ArtifactEdit edit = null;
+ try {
+ edit = ArtifactEdit.getArtifactEditForWrite(project);
+ try {
+ edit.saveIfNecessaryWithPrompt(new NullProgressMonitor(), handler, true);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ } finally {
+ if (edit != null) {
+ edit.dispose();
+ }
+ pass();
+ }
+ }
+
+ public void testDispose() {
+ ArtifactEdit edit;
+ try {
+ edit = new ArtifactEdit(getArtifactEditModelforRead());
+ edit.dispose();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ pass();
+ }
+
+ public void testGetContentModelRoot() {
+ ArtifactEdit edit = null;
+ try {
+ edit = ArtifactEdit.getArtifactEditForRead(project);
+ Object object = edit.getContentModelRoot();
+ // assertNotNull(object);
+ } catch (Exception e) {
+ // TODO fail(e.getMessage());
+ } finally {
+ if (edit != null) {
+ edit.dispose();
+ }
+ }
+ }
+
+ public void testAddListener() {
+ ArtifactEdit edit = getArtifactEditForRead();
+ try {
+ edit.addListener(getEmListener());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ pass();
+ edit.dispose();
+ }
+
+ public void testRemoveListener() {
+ ArtifactEdit edit = getArtifactEditForRead();
+ try {
+ edit.removeListener(getEmListener());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ pass();
+ }
+
+ public void testHasEditModel() {
+
+ ArtifactEdit edit = getArtifactEditForRead();
+ assertTrue(edit.hasEditModel(artifactEditModelForRead));
+ edit.dispose();
+ }
+
+ public void testGetArtifactEditModel() {
+ ArtifactEdit edit = getArtifactEditForRead();
+ assertTrue(edit.hasEditModel(artifactEditModelForRead));
+ edit.dispose();
+ }
+
+ public void testObject() {
+ pass();
+ }
+
+ public void testGetClass() {
+ ArtifactEdit edit = getArtifactEditForRead();
+ assertNotNull(edit.getClass());
+ edit.dispose();
+ }
+
+ public void testHashCode() {
+ ArtifactEdit edit = getArtifactEditForRead();
+ int y = -999999999;
+ int x = edit.hashCode();
+ assertTrue(x != y);
+ edit.dispose();
+ }
+
+ public void testEquals() {
+ assertTrue(getArtifactEditForRead().equals(artifactEditForRead));
+ }
+
+ public void testClone() {
+ pass();
+ }
+
+ public void testToString() {
+ assertTrue(getArtifactEditForRead().toString() != null);
+ }
+
+ public void testNotify() {
+ try {
+ synchronized (getArtifactEditForRead()) {
+ artifactEditForRead.notify();
+ }
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ pass();
+
+ }
+
+ public void testNotifyAll() {
+ try {
+ synchronized (getArtifactEditForRead()) {
+ artifactEditForRead.notifyAll();
+ }
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+ pass();
+ }
+
+ public void testWaitlong() {
+ long x = 2;
+ try {
+ synchronized (getArtifactEditForRead()) {
+ getArtifactEditForRead().wait(x);
+ }
+ } catch (Exception e) {
+ // fail(e.getMessage());
+ }
+ pass();
+ }
+
+ /*
+ * Class under test for void wait(long, int)
+ */
+ public void testWaitlongint() {
+ int x = 2;
+ try {
+ synchronized (getArtifactEditForRead()) {
+ getArtifactEditForRead().wait(x);
+ }
+ } catch (Exception e) {
+ // fail(e.getMessage());
+ }
+ pass();
+ }
+
+ public void testWait() {
+ try {
+ synchronized (getArtifactEditForRead()) {
+ getArtifactEditForRead().wait();
+ }
+ } catch (Exception e) {
+ // fail(e.getMessage());
+ }
+ pass();
+ }
+
+ public void testFinalize() {
+ pass();
+ }
+
+
+ public ArtifactEditModel getArtifactEditModelforRead() {
+ EMFWorkbenchContext context = new EMFWorkbenchContext(project);
+ artifactEditModelForRead = new ArtifactEditModel(EDIT_MODEL_ID, context, true, moduleURI);
+ return artifactEditModelForRead;
+ }
+
+
+
+ public ArtifactEdit getArtifactEditForRead() {
+ artifactEditForRead = new ArtifactEdit(getArtifactEditModelforRead());
+ return artifactEditForRead;
+ }
+
+ public void pass() {
+ assertTrue(true);
+ }
+
+ public EditModelListener getEmListener() {
+ if (emListener == null)
+ emListener = new EditModelListener() {
+ public void editModelChanged(EditModelEvent anEvent) {
+ }
+ };
+ return emListener;
+ }
+
+ public ArtifactEditModel getArtifactEditModelForWrite() {
+ EMFWorkbenchContext context = new EMFWorkbenchContext(project);
+ return new ArtifactEditModel(EDIT_MODEL_ID, context, false, moduleURI);
+
+ }
+
+ public ArtifactEdit getArtifactEditForWrite() {
+ return new ArtifactEdit(getArtifactEditModelForWrite());
+
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/AllTests.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/AllTests.java
new file mode 100644
index 0000000..98603fd
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/AllTests.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AllTests extends TestCase {
+
+
+ public static TestSuite suite() {
+
+ TestSuite suite = new TestSuite();
+
+ suite.addTestSuite(IVirtualFolderAPITest.class);
+ suite.addTestSuite(ModuleCoreAPIFVTTest.class);
+ suite.addTestSuite(ModuleCoreURIConverterUnitTest.class);
+ //suite.addTestSuite(StructureEditAPITest.class);
+ suite.addTestSuite(StructureEditStressTest.class);
+
+
+ return suite;
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/BaseVirtualTest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/BaseVirtualTest.java
new file mode 100644
index 0000000..5d0cb6c
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/BaseVirtualTest.java
@@ -0,0 +1,81 @@
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
+import org.eclipse.wst.common.frameworks.componentcore.virtualpath.tests.TestWorkspace;
+
+public class BaseVirtualTest extends TestCase {
+
+ public static final IProject TEST_PROJECT = ResourcesPlugin.getWorkspace().getRoot().getProject(TestWorkspace.PROJECT_NAME);
+
+ public static final String TEST_FOLDER_NAME = "WEB-INF"; //$NON-NLS-1$
+
+ public static final Path WEBINF_FOLDER_REAL_PATH = new Path("/WebModule1/WebContent/"+TEST_FOLDER_NAME); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final Path WEBINF_FOLDER_RUNTIME_PATH = new Path("/"+TEST_FOLDER_NAME); //$NON-NLS-1$
+
+ public static final Path TESTDATA_FOLDER_REAL_PATH = new Path("WebModule1/testdata"); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final Path TESTDATA_FOLDER_RUNTIME_PATH = new Path("/"); //$NON-NLS-1$
+
+ protected static final IPath DELETEME_PATH = new Path("/deleteme"); //$NON-NLS-1$
+
+ protected IVirtualComponent component;
+
+ protected IVirtualFolder webInfFolder;
+ protected IContainer realWebInfFolder;
+
+ protected IVirtualFolder deletemeVirtualFolder;
+ protected IContainer deletemeFolder;
+
+ protected IVirtualFolder testdataFolder;
+ protected IContainer realTestdataFolder;
+
+
+
+ public BaseVirtualTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ if (!TestWorkspace.getTargetProject().exists())
+ if (!TestWorkspace.createProject())
+ fail();
+
+
+ realWebInfFolder = TEST_PROJECT.getFolder(WEBINF_FOLDER_REAL_PATH);
+
+ component = ComponentCore.createComponent(TEST_PROJECT);
+
+ IVirtualFolder rootFolder = component.getRootFolder();
+
+ webInfFolder = rootFolder.getFolder(WEBINF_FOLDER_RUNTIME_PATH);
+
+ testdataFolder = rootFolder.getFolder(TESTDATA_FOLDER_RUNTIME_PATH);
+ realTestdataFolder = TEST_PROJECT.getFolder(TESTDATA_FOLDER_REAL_PATH);
+
+ deletemeVirtualFolder = rootFolder.getFolder(DELETEME_PATH);
+ deletemeVirtualFolder.create(IVirtualResource.FORCE, null);
+
+ deletemeFolder = deletemeVirtualFolder.getUnderlyingFolder();
+
+ }
+
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ if(deletemeFolder.exists())
+ deletemeFolder.delete(IVirtualResource.FORCE, null);
+
+ }
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/ComponentCoreTest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/ComponentCoreTest.java
new file mode 100644
index 0000000..1aa1cc5
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/ComponentCoreTest.java
@@ -0,0 +1,140 @@
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import java.io.IOException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.etools.common.test.apitools.ProjectUnzipUtil;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.internal.resources.VirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.tests.CommonTestsPlugin;
+
+public class ComponentCoreTest extends TestCase {
+ public static String fileSep = System.getProperty("file.separator");
+ public static final String PROJECT_NAME = "TestArtifactEdit";
+ public static final String WEB_MODULE_NAME = "WebModule1";
+ public static final URI moduleURI = URI.createURI("module:/resource/TestArtifactEdit/WebModule1");
+ public static final String EDIT_MODEL_ID = "jst.web";
+ private Path zipFilePath = new Path("TestData" + fileSep + "TestArtifactEdit.zip");
+ private IProject project;
+ private int i, seed = 0;
+
+ protected void setUp() throws Exception {
+ if (!getTargetProject().exists())
+ if (!createProject())
+ fail();
+ project = getTargetProject();
+ }
+
+
+ public IProject getTargetProject() {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
+ }
+
+ public boolean createProject() {
+ IPath localZipPath = getLocalPath();
+ ProjectUnzipUtil util = new ProjectUnzipUtil(localZipPath, new String[]{PROJECT_NAME});
+ return util.createProjects();
+ }
+
+ private IPath getLocalPath() {
+ URL url = CommonTestsPlugin.instance.find(zipFilePath);
+ try {
+ url = Platform.asLocalURL(url);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return new Path(url.getPath());
+ }
+
+
+ public void testCreateComponent() {
+ try {
+ new ComponentCore();
+ ComponentCore.createComponent(project, "test");
+
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+ }
+ public void testCreateComponentUsingCreate() {
+
+ Job[] createComponentJob = new Job[500];
+ for ( i = 0; i < 500; i++) {
+
+ createComponentJob[i] = new Job("CreateComponent Test") {
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ IVirtualComponent c
+ = ComponentCore.createComponent( project, project.getName() + getNextSeed() );
+ c.create( 0, null );
+
+ } catch (Exception e) {
+ fail(e.toString());
+ return Status.CANCEL_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ }
+ for (int n = 0; n < createComponentJob.length; n++) {
+ createComponentJob[n].setRule(project);
+ createComponentJob[n].schedule();
+ }
+
+ }
+
+ protected int getNextSeed() {
+ return seed++;
+ }
+
+
+ public void testCreateFolder() {
+ try {
+ ComponentCore.createFolder(project, new Path("test/runtimePath"));
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+ }
+
+ public void testCreateFile() {
+ try {
+ ComponentCore.createFile(project, new Path("test/runtimePath/file"));
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+ }
+
+ public void testCreateReference() {
+ IVirtualComponent container = new VirtualComponent(project, new Path("test/runtimePath/file"));
+
+ try {
+ ComponentCore.createReference(container,container);
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+ }
+ public void testCreateResources() {
+ IResource res = project.getFile(new Path("WebModule1/WebContent/WEB-INF/web.xml"));
+
+ try {
+ ComponentCore.createResources(res);
+ } catch (Exception e) {
+ fail(e.toString());
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IEditModelHandlerTest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IEditModelHandlerTest.java
new file mode 100644
index 0000000..1b53254
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IEditModelHandlerTest.java
@@ -0,0 +1,39 @@
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.wst.common.componentcore.IEditModelHandler;
+
+public class IEditModelHandlerTest extends TestCase {
+ public class EditModelHandlerTest implements IEditModelHandler {
+ public EditModelHandlerTest() {
+ }
+
+ public void save(IProgressMonitor aMonitor) {
+ }
+
+ public void saveIfNecessary(IProgressMonitor aMonitor) {
+ }
+
+ public void dispose() {
+ }
+ }
+
+ public void testSave() {
+ IEditModelHandler handler = new EditModelHandlerTest();
+ handler.save(null);
+ }
+
+ public void testSaveIfNecessary() {
+ IEditModelHandler handler = new EditModelHandlerTest();
+ handler.saveIfNecessary(null);
+
+ }
+
+ public void testDispose() {
+ IEditModelHandler handler = new EditModelHandlerTest();
+ handler.dispose();
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualComponentAPITest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualComponentAPITest.java
new file mode 100644
index 0000000..4cad961
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualComponentAPITest.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
+
+public class IVirtualComponentAPITest extends BaseVirtualTest {
+
+ public IVirtualComponentAPITest(String name) {
+ super(name);
+ }
+
+ public void testGetName() {
+
+ String name = component.getName();
+ }
+
+// public void testGetComponentTypeId() {
+// String id = component.getComponentTypeId() ;
+// }
+//
+// public void testSetComponentTypeId() {
+// String id = "jst.ejb";
+// component.setComponentTypeId(id) ;
+// }
+
+ public void testGetMetaProperties() {
+ Properties properties = component.getMetaProperties() ;
+ }
+
+ public void testGetMetaResources() {
+ IPath[] metaresources = component.getMetaResources() ;
+
+ }
+
+ public void testSetMetaResources() {
+
+ IPath[] metaresources = new IPath[1];
+ metaresources[0] = new Path("/test");
+ component.setMetaResources(metaresources) ;
+
+ }
+
+ public void testGetResources() {
+ String resource = "/test";
+ IVirtualFolder rootFolder = component.getRootFolder();
+ IVirtualResource[] virtualResource = rootFolder.getResources(resource) ;
+
+ }
+
+ public void testExists(){
+ boolean exists = component.exists();
+ }
+
+ public void testGetRootFolder(){
+ component.getRootFolder();
+ }
+
+ public void testGetProject(){
+ component.getProject();
+ }
+
+
+ public void testAddMetaProperty(){
+ component.setMetaProperty("Test1", "test1Value");
+ }
+
+ public void testSetProperties(){
+ Properties props = new Properties();
+ props.setProperty("Test2", "Value2");
+ component.setMetaProperties(props);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualContainerTestAPI.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualContainerTestAPI.java
new file mode 100644
index 0000000..9e74ebb
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualContainerTestAPI.java
@@ -0,0 +1,104 @@
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.resources.IVirtualContainer;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
+
+public class IVirtualContainerTestAPI extends BaseVirtualTest {
+
+ protected IVirtualContainer deletemeVirtualFolder2;
+ protected static final IPath DELETEME_PATH2 = new Path("/deleteme2"); //$NON-NLS-1$
+
+ public IVirtualContainerTestAPI(String name) {
+ super(name);
+ }
+
+
+ public void test_create()
+ throws CoreException {
+
+ IVirtualFolder rootFolder = component.getRootFolder();
+ deletemeVirtualFolder2 = rootFolder.getFolder(DELETEME_PATH2);
+ deletemeVirtualFolder2.create(IVirtualResource.FORCE, null);
+ deletemeVirtualFolder2.delete(IVirtualResource.FORCE, null);
+ }
+
+ public void test_exists() {
+ IVirtualContainer container = webInfFolder;
+ IPath path = new Path("/deleteme");
+ boolean bRetValue = container.exists(path);
+ }
+
+ public void test_findMember() {
+ String name = "lib";
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource resource= container.findMember(name);
+
+ }
+
+ public void test_findMember2() {
+ String name = "lib";
+ int searchFlags = 0;
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource resource= container.findMember(name,searchFlags);
+ }
+
+ public void test_findMember3() {
+ IPath path = new Path("/lib");
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource resource= container.findMember(path);
+
+ }
+
+ public void test_findMember4() {
+ IPath path = new Path("/lib");
+ int searchFlags = 0;
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource resource= container.findMember(path,searchFlags);
+ }
+
+
+
+ public void test_getFile() {
+ IPath path = new Path("/deleteme");
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource resource= container.getFile(path);
+ }
+
+ public void test_getFolder() {
+ IPath path = new Path("/deleteme");
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource resource= container.getFolder(path);
+ }
+
+ public void test_getFile2() {
+ String name = "/deleteme";
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource resource= container.getFile(name);
+ }
+
+ public void test_getFolder2() {
+ String name = "/deleteme";
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource resource= container.getFolder(name);
+ }
+
+ public void test_members() throws CoreException {
+ IVirtualContainer container = webInfFolder;
+ IVirtualResource[] resource= container.members();
+ }
+
+ public void members() throws CoreException {
+ IVirtualContainer container = webInfFolder;
+ int memberFlags = 0;
+ IVirtualResource[] resource= container.members(memberFlags);
+
+
+ }
+
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualFileAPITest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualFileAPITest.java
new file mode 100644
index 0000000..6c4c311
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualFileAPITest.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
+
+
+public class IVirtualFileAPITest extends BaseVirtualTest {
+
+ protected IVirtualFile testFile1;
+ protected IFile realTestFile1;
+ public static final Path TEST_FILE_REAL_PATH = new Path("WebModule1/testdata/TestFile1.txt"); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final Path TEST_FILE_RUNTIME_PATH = new Path("/"); //$NON-NLS-1$
+
+
+ public IVirtualFileAPITest(String name) {
+ super(name);
+
+ }
+ protected void setUp() throws Exception {
+ super.setUp();
+ IVirtualFolder rootFolder = component.getRootFolder();
+ testFile1 = rootFolder.getFile(TESTDATA_FOLDER_RUNTIME_PATH);
+ realTestFile1 = TEST_PROJECT.getFile(TESTDATA_FOLDER_REAL_PATH);
+
+ }
+
+ public void testGetUnderlyingFile() {
+ IFile file = testFile1.getUnderlyingFile();
+ }
+
+ public void testGetUnderlyingFiles() {
+ IFile[] file = testFile1.getUnderlyingFiles();
+ }
+
+ public void testIsAccessible() throws CoreException {
+ assertEquals(((IVirtualResource)deletemeVirtualFolder).isAccessible(),true);
+ ((IVirtualResource)deletemeVirtualFolder).delete(IVirtualResource.FORCE, null);
+ //assertEquals(deletemeVirtualFolder.isAccessible(),false);
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualFolderAPITest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualFolderAPITest.java
new file mode 100644
index 0000000..7a3679d
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualFolderAPITest.java
@@ -0,0 +1,240 @@
+/*******************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
+import org.eclipse.wst.common.tests.SimpleTestSuite;
+
+public class IVirtualFolderAPITest extends TestCase {
+
+ public static final IProject TEST_PROJECT = ResourcesPlugin.getWorkspace().getRoot().getProject(TestWorkspace.PROJECT_NAME);
+
+ public static final String TEST_FOLDER_NAME = "WEB-INF"; //$NON-NLS-1$
+
+ public static final Path WEBINF_FOLDER_REAL_PATH = new Path("/WebModule1/WebContent/"+TEST_FOLDER_NAME); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final Path WEBINF_FOLDER_RUNTIME_PATH = new Path("/"+TEST_FOLDER_NAME); //$NON-NLS-1$
+
+ public static final Path TESTDATA_FOLDER_REAL_PATH = new Path("WebModule1/testdata"); //$NON-NLS-1$ //$NON-NLS-2$
+ public static final Path TESTDATA_FOLDER_RUNTIME_PATH = new Path("/"); //$NON-NLS-1$
+
+ private static final IPath DELETEME_PATH = new Path("/deleteme"); //$NON-NLS-1$
+
+ private IVirtualComponent component;
+
+ private IVirtualFolder webInfFolder;
+ private IContainer realWebInfFolder;
+
+ private IVirtualFolder deletemeVirtualFolder;
+ private IContainer deletemeFolder;
+
+ public IVirtualFolderAPITest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new SimpleTestSuite(IVirtualFolderAPITest.class);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ TestWorkspace.init();
+
+ realWebInfFolder = TEST_PROJECT.getFolder(WEBINF_FOLDER_REAL_PATH);
+
+ component = ComponentCore.createComponent(TEST_PROJECT);
+ IVirtualFolder rootFolder = component.getRootFolder();
+
+ webInfFolder = rootFolder.getFolder(WEBINF_FOLDER_RUNTIME_PATH);
+
+ rootFolder.getFolder(TESTDATA_FOLDER_RUNTIME_PATH);
+ TEST_PROJECT.getFolder(TESTDATA_FOLDER_REAL_PATH);
+
+ deletemeVirtualFolder = rootFolder.getFolder(DELETEME_PATH);
+ deletemeVirtualFolder.create(IVirtualResource.FORCE, null);
+
+ deletemeFolder = deletemeVirtualFolder.getUnderlyingFolder();
+
+ }
+
+ public void testDelete() throws CoreException {
+ assertEquals(((IVirtualResource)deletemeVirtualFolder).exists(),true);
+ ((IVirtualResource)deletemeVirtualFolder).delete(IVirtualResource.FORCE, null);
+ // assertEquals(deletemeFolder.exists(),false);
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ if(deletemeFolder.exists())
+ deletemeFolder.delete(IVirtualResource.FORCE, null);
+
+ }
+
+ public void testGetFileExtension() {
+ assertTrue("The /WEB-INF folder should have no file extension.", ((IVirtualResource)webInfFolder).getFileExtension() == null); //$NON-NLS-1$
+ }
+
+ public void testGetUnderlyingFolders() {
+ IContainer[] aDeletemeFolder = deletemeVirtualFolder.getUnderlyingFolders();
+ assertEquals(aDeletemeFolder.length==1,true);
+ }
+
+ public void testGetUnderlyingResources() {
+ IResource[] aDeletemeFolder = ((IVirtualResource)deletemeVirtualFolder).getUnderlyingResources();
+ assertEquals(aDeletemeFolder.length==1,true);
+ }
+ public void testGetVirtualComponentFromResource() {
+ IResource aDeletemeFolder = ((IVirtualResource)deletemeVirtualFolder).getUnderlyingResources()[0];
+ IVirtualComponent comp = (IVirtualComponent)aDeletemeFolder.getAdapter(IVirtualComponent.class);
+ assertEquals(comp.getName(),TestWorkspace.PROJECT_NAME);
+ }
+
+
+ public void testGetUnderlyingFolder() {
+ IContainer aDeletemeFolder = deletemeVirtualFolder.getUnderlyingFolder();
+ assertNotNull(aDeletemeFolder);
+ }
+
+ public void testGetUnderlyingResource() {
+ IResource aDeletemeFolder = ((IVirtualResource)deletemeVirtualFolder).getUnderlyingResource();
+ assertNotNull(aDeletemeFolder);
+ }
+
+ public void testGetWorkspaceRelativePath() {
+ IPath realPath = realWebInfFolder.getFullPath();
+ IPath virtualPath = ((IVirtualResource)webInfFolder).getWorkspaceRelativePath();
+ assertEquals("The workspace relative path of the virtual resource must match the real resource", realPath, virtualPath); //$NON-NLS-1$
+
+ }
+
+ public void testGetComponent() {
+ assertNotNull(((IVirtualResource)webInfFolder).getComponent()); //$NON-NLS-1$
+ }
+
+ public void testGetProjectRelativePath() {
+ IPath realPath = realWebInfFolder.getProjectRelativePath();
+ IPath virtualPath = webInfFolder.getProjectRelativePath();
+ assertEquals("The project relative path of the virtual resource must match the real resource", realPath, virtualPath); //$NON-NLS-1$
+ }
+
+ public void testGetRuntimePath() {
+ IPath virtualPath = ((IVirtualResource)webInfFolder).getRuntimePath();
+ assertEquals("The runtime path of the virtual resource must match the real resource", WEBINF_FOLDER_RUNTIME_PATH, virtualPath); //$NON-NLS-1$
+
+ }
+
+ public void testGetName() {
+ assertEquals("The name of the virtual resource must match the expected name.", TEST_FOLDER_NAME, webInfFolder.getName()); //$NON-NLS-1$
+ }
+
+ public void testGetParent() {
+ assertEquals("The parent of the virtual resource must match the components root folder.", component.getRootFolder(), webInfFolder.getParent()); //$NON-NLS-1$
+ }
+
+ public void testEquals() {
+ IVirtualResource resource = webInfFolder.getParent();
+ boolean bRetValue = resource.equals(component.getRootFolder());
+ assertTrue(bRetValue);
+ }
+
+ public void testGetProject() {
+ assertEquals("The project of the virtual resource must match the test project.", TEST_PROJECT, ((IVirtualResource)webInfFolder).getProject()); //$NON-NLS-1$
+ }
+
+ public void testGetType() {
+ assertEquals("The type of the virtual resource must match the type of the test project.", IVirtualResource.FOLDER, ((IVirtualResource)webInfFolder).getType()); //$NON-NLS-1$
+ }
+
+
+ /*public void testGetFilePath() {
+ IVirtualFile test3jsp = testdataFolder.getFile(new Path("/jsps/TestJsp3.jsp"));
+
+ IPath expectedPath = TESTDATA_FOLDER_REAL_PATH.append(new Path("/jsps/TestJsp3.jsp"));
+ assertEquals("The test file project relative path must match.", expectedPath, test3jsp.getProjectRelativePath()); //$NON-NLS-1$
+ }*/
+
+
+
+ /*
+ * Class under test for void delete(int, IProgressMonitor)
+ */
+ /*public void testDeleteintIProgressMonitor() throws Exception {
+ deletemeVirtualFolder.delete(0, null);
+
+ assertTrue("The real folder should be deleted when IVirtualResource.DELETE_METAMODEL_ONLY is NOT supplied.", !deletemeFolder.exists()); //$NON-NLS-1$
+
+ IVirtualResource[] members = component.members();
+
+ for (int i = 0; i < members.length; i++) {
+ if(members[i].getRuntimePath().equals(deletemeVirtualFolder.getRuntimePath())) {
+ fail("Found deleted folder in members()"); //$NON-NLS-1$
+ }
+ }
+ }*/
+
+ /*
+ * Class under test for void delete(int, IProgressMonitor)
+ */
+ /*public void testDeleteintIProgressMonitor2() throws Exception {
+ deletemeVirtualFolder.delete(IVirtualResource.IGNORE_UNDERLYING_RESOURCE, null);
+
+ assertTrue("The real folder should not be deleted when IVirtualResource.DELETE_METAMODEL_ONLY is supplied.", deletemeFolder.exists()); //$NON-NLS-1$
+
+ // only handles explicit mappings
+ StructureEdit moduleCore = null;
+ try {
+ URI runtimeURI = URI.createURI(deletemeVirtualFolder.getRuntimePath().toString());
+ moduleCore = StructureEdit.getStructureEditForWrite(TEST_PROJECT);
+ WorkbenchComponent wbComponent = moduleCore.findComponentByName(TestWorkspace.WEB_MODULE_1_NAME);
+ ComponentResource[] resources = wbComponent.findWorkbenchModuleResourceByDeployPath(runtimeURI);
+ assertTrue("There should be no matching components found in the model.", resources.length == 0); //$NON-NLS-1$
+
+ } finally {
+ if (moduleCore != null) {
+ moduleCore.saveIfNecessary(null);
+ moduleCore.dispose();
+ }
+ }
+ }*/
+
+ /*
+ * Class under test for void delete(boolean, IProgressMonitor)
+ */
+ /*public void testDeletebooleanIProgressMonitor() throws Exception {
+ deletemeVirtualFolder.delete(IVirtualResource.FORCE, null);
+
+ assertTrue("The real folder should be deleted when IVirtualResource.DELETE_METAMODEL_ONLY is NOT supplied.", !deletemeFolder.exists()); //$NON-NLS-1$
+
+ IVirtualResource[] members = component.members();
+
+ for (int i = 0; i < members.length; i++) {
+ if(members[i].getRuntimePath().equals(deletemeVirtualFolder.getRuntimePath())) {
+ fail("Found deleted folder in members()"); //$NON-NLS-1$
+ }
+ }
+ } */
+
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualReferenceAPITest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualReferenceAPITest.java
new file mode 100644
index 0000000..18a1013
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/IVirtualReferenceAPITest.java
@@ -0,0 +1,60 @@
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.common.componentcore.internal.resources.VirtualReference;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualReference;
+
+public class IVirtualReferenceAPITest extends TestCase {
+
+ public static void main(String[] args) {
+ }
+
+ public void testCreate() {
+ IVirtualReference reference = new VirtualReference();
+ reference.create(0,null);
+
+ }
+
+ public void testSetRuntimePath() {
+ IVirtualReference reference = new VirtualReference();
+ reference.setRuntimePath(new Path("/"));
+ }
+
+ public void testGetRuntimePath() {
+ IVirtualReference reference = new VirtualReference();
+ IPath path = reference.getRuntimePath();
+ }
+
+ public void testSetDependencyType() {
+ IVirtualReference reference = new VirtualReference();
+ int dependencyType = 0;
+ reference.setDependencyType(dependencyType);
+ }
+
+ public void testGetDependencyType() {
+ IVirtualReference reference = new VirtualReference();
+ int dependencyType = 0;
+ dependencyType = reference.getDependencyType();
+ }
+
+ public void testExists() {
+ IVirtualReference reference = new VirtualReference();
+ boolean exists = reference.exists();
+ }
+
+ public void testGetEnclosingComponent() {
+ IVirtualReference reference = new VirtualReference();
+ IVirtualComponent component = reference.getEnclosingComponent();
+ }
+
+ public void testGetReferencedComponent() {
+ IVirtualReference reference = new VirtualReference();
+ IVirtualComponent component = reference.getReferencedComponent();
+
+ }
+
+}
diff --git a/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/ModuleCoreAPIFVTTest.java b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/ModuleCoreAPIFVTTest.java
new file mode 100644
index 0000000..5c5c900
--- /dev/null
+++ b/tests/org.eclipse.wst.common.tests/frameworktests/org/eclipse/wst/common/frameworks/componentcore/tests/ModuleCoreAPIFVTTest.java
@@ -0,0 +1,364 @@
+/***************************************************************************************************
+ * Copyright (c) 2003, 2004 IBM Corporation and others. All rights reserved. This program and the
+ * accompanying materials are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
+package org.eclipse.wst.common.frameworks.componentcore.tests;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;