Simple testing for sets and tagmatcher.
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/META-INF/MANIFEST.MF b/jsf/tests/org.eclipse.jst.jsf.core.tests/META-INF/MANIFEST.MF
index 194fef5..0e818b4 100644
--- a/jsf/tests/org.eclipse.jst.jsf.core.tests/META-INF/MANIFEST.MF
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/META-INF/MANIFEST.MF
@@ -30,7 +30,8 @@
  org.eclipse.jst.jsp.core,
  org.eclipse.jst.jsf.test.util,
  org.eclipse.jst.jsf.common,
- org.eclipse.wst.validation
+ org.eclipse.wst.validation,
+ org.eclipse.wst.sse.core
 Eclipse-LazyStart: true
 Export-Package: org.eclipse.jst.jsf.core.tests;x-friends:="org.eclipse.jst.jsf.ui.tests",
  org.eclipse.jst.jsf.core.tests.jsflibraryregistry,
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestElementToTagIdentifierMapping.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestElementToTagIdentifierMapping.java
new file mode 100644
index 0000000..d07f030
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestElementToTagIdentifierMapping.java
@@ -0,0 +1,21 @@
+package org.eclipse.jst.jsf.core.tests.set;
+
+import junit.framework.TestCase;
+
+import org.apache.xerces.dom.ElementImpl;
+import org.eclipse.jst.jsf.core.tests.tagmatcher.BaseTagMatcherTestCase;
+import org.w3c.dom.Element;
+
+public class TestElementToTagIdentifierMapping extends BaseTagMatcherTestCase
+{
+    protected void setUp() throws Exception {
+        _srcFileName = "/testfiles/jsps/testdata1.jsp.data";
+        _destFileName = "/testdata1.jsp";
+        super.setUp();
+    }
+
+    public void testElementToIdMapping()
+    {
+        // TODO:
+    }
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestMemberConstraint.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestMemberConstraint.java
new file mode 100644
index 0000000..3b0521e
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestMemberConstraint.java
@@ -0,0 +1,125 @@
+package org.eclipse.jst.jsf.core.tests.set;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.jst.jsf.common.sets.internal.provisional.AxiomaticSet;
+import org.eclipse.jst.jsf.common.sets.internal.provisional.ConcreteAxiomaticSet;
+import org.eclipse.jst.jsf.core.internal.provisional.set.constraint.MemberConstraint;
+
+public class TestMemberConstraint extends TestCase 
+{
+    private AxiomaticSet            _set1;
+    private AxiomaticSet            _set2;
+    private AxiomaticSet            _set3;
+
+    private AxiomaticSet            _constraintSet1;
+    private AxiomaticSet            _constraintSet2;
+    private AxiomaticSet            _constraintSet3;
+    
+    public void testMemberConstraint()
+    {
+        // A is always a subset of itself
+        assertTrue(new MemberConstraint(_set1).passesConstraint(_set1));
+        assertTrue(new MemberConstraint(_set2).passesConstraint(_set2));
+        assertTrue(new MemberConstraint(_set3).passesConstraint(_set3));
+        
+        // constraint 1
+        assertTrue(new MemberConstraint(_constraintSet1).passesConstraint(_set1));
+        Diagnostic fail = new MemberConstraint(_constraintSet1).isSatisfied(_set2);
+        assertEquals(Diagnostic.ERROR, fail.getSeverity());
+        assertEquals(1, fail.getData().size());
+        assertTrue(fail.getData().contains("element2"));
+        fail = new MemberConstraint(_constraintSet1).isSatisfied(_set3);
+        assertEquals(Diagnostic.ERROR, fail.getSeverity());
+        assertEquals(1, fail.getData().size());
+        assertTrue(fail.getData().contains("element2"));
+        
+        // constraint 2
+        fail = new MemberConstraint(_constraintSet2).isSatisfied(_set1);
+        assertEquals(Diagnostic.ERROR, fail.getSeverity());
+        assertTrue(fail.getData().contains("element7"));
+        assertEquals(1, fail.getData().size());
+        assertTrue(new MemberConstraint(_constraintSet2).passesConstraint(_set2));
+        fail = new MemberConstraint(_constraintSet2).isSatisfied(_set3);
+        assertEquals(Diagnostic.ERROR, fail.getSeverity());
+        assertEquals(1, fail.getData().size());
+        assertTrue(fail.getData().contains("element7"));
+        
+        // constraint 3
+        fail = new MemberConstraint(_constraintSet3).isSatisfied(_set1);
+        assertEquals(Diagnostic.ERROR, fail.getSeverity());
+        assertEquals(1, fail.getData().size());
+        assertTrue(fail.getData().contains("element7"));
+        fail = new MemberConstraint(_constraintSet3).isSatisfied(_set2);
+        assertEquals(Diagnostic.ERROR, fail.getSeverity());
+        assertEquals(2, fail.getData().size());
+        assertTrue(fail.getData().contains("element1"));
+        assertTrue(fail.getData().contains("element2"));
+        fail = new MemberConstraint(_constraintSet3).isSatisfied(_set3);
+        assertEquals(Diagnostic.ERROR, fail.getSeverity());
+        assertEquals(2, fail.getData().size());
+        assertTrue(fail.getData().contains("element2"));
+        assertTrue(fail.getData().contains("element7"));
+        
+    }
+    
+    public void setUp() throws Exception
+    {
+        super.setUp();
+        
+        List items = new ArrayList();
+        items.add("element1");
+        items.add("element2");
+        items.add("element3");
+        items.add("element4");
+        _set1 = createSet(items);
+        
+        items.clear();
+        items.add("element5");
+        items.add("element6");
+        items.add("element7");
+        items.add("element8");
+        _set2 = createSet(items);
+        
+        items.clear();
+        items.add("element1");
+        items.add("element5");
+        _set3 = createSet(items);
+        
+        // setup a constraint set that will pass for set1
+        // fail for set2 (they are disjoint)  and fail for set3
+        items.clear();
+        items.add("element2");
+        _constraintSet1 = createSet(items);
+        
+        // setup a constraint set that will pass for set2
+        // fail for set1 and fail for set3
+        items.clear();
+        items.add("element7");
+        _constraintSet2 = createSet(items);
+        
+        // setup a constraint set that will fail on all three
+        // even though it has common element with all sets
+        items.clear();
+        items.add("element1");  // match 1 and 3
+        items.add("element2");  // match 1
+        items.add("element7");  // match 2
+        _constraintSet3 = createSet(items);
+    }
+
+    protected AxiomaticSet createSet(List items) 
+    {
+        ConcreteAxiomaticSet  set = new ConcreteAxiomaticSet();
+        set = new ConcreteAxiomaticSet();
+        for (Iterator it = items.iterator(); it.hasNext();)
+        {
+            set.add(it.next());
+        }
+        return set;
+    }
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestXPathValidation.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestXPathValidation.java
new file mode 100644
index 0000000..f393985
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/set/TestXPathValidation.java
@@ -0,0 +1,58 @@
+package org.eclipse.jst.jsf.core.tests.set;
+
+import org.eclipse.jst.jsf.common.sets.internal.provisional.AxiomaticSet;
+import org.eclipse.jst.jsf.common.sets.internal.provisional.ConcreteAxiomaticSet;
+import org.eclipse.jst.jsf.core.internal.provisional.set.constraint.MemberConstraint;
+import org.eclipse.jst.jsf.core.internal.provisional.set.mapping.ElementToTagIdentifierMapping;
+import org.eclipse.jst.jsf.core.internal.provisional.tagmatcher.XPathMatchingAlgorithm;
+import org.eclipse.jst.jsf.core.internal.tld.ITLDConstants;
+import org.eclipse.jst.jsf.core.internal.tld.TagIdentifierFactory;
+import org.eclipse.jst.jsf.core.tests.tagmatcher.BaseTagMatcherTestCase;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+public class TestXPathValidation extends BaseTagMatcherTestCase {
+
+    protected void setUp() throws Exception {
+        _srcFileName = "/testfiles/jsps/testdata1.jsp.data";
+        _destFileName = "/testdata1.jsp";
+        super.setUp();
+    }
+
+    public void testValidateParentMembership()
+    {
+        AxiomaticSet inputAncestors = getAncestorsOfInputText();
+        
+        //map the set to TagIds
+        inputAncestors = new ElementToTagIdentifierMapping().map(inputAncestors);
+        // create constraint set: form and view must be parents of inputText
+        AxiomaticSet constraintSet = new ConcreteAxiomaticSet();
+        constraintSet.add(TagIdentifierFactory.createJSPTagWrapper(ITLDConstants.URI_JSF_HTML, "form"));
+        constraintSet.add(TagIdentifierFactory.createJSPTagWrapper(ITLDConstants.URI_JSF_CORE, "view"));
+
+        // create an apply member constraint
+        MemberConstraint memberConstraint = new MemberConstraint(constraintSet);
+        assertTrue(memberConstraint.passesConstraint(inputAncestors));
+        
+        // test a constraint set that isn't satisfied: no ancestor is inputLabel
+        constraintSet.clear();
+        constraintSet.add(TagIdentifierFactory.createJSPTagWrapper(ITLDConstants.URI_JSF_HTML, "form"));
+        memberConstraint = new MemberConstraint(constraintSet);
+        assertTrue(memberConstraint.failsConstraint(inputAncestors));
+    }
+    
+    protected AxiomaticSet getAncestorsOfInputText()
+    {
+        Document doc = ((IDOMModel)_structuredModel).getDocument();
+        System.out.println(System.currentTimeMillis());
+        XPathMatchingAlgorithm matcher = new XPathMatchingAlgorithm("/view/html/body/form/panelGrid/inputText");
+        AxiomaticSet  set = matcher.evaluate(doc);
+        assertEquals(1, set.size());
+     
+        // get all of the ancestors of the inputText
+        final Node inputText = (Node) set.getFirstElement();
+        matcher = new XPathMatchingAlgorithm("ancestor::*");
+        return matcher.evaluate(inputText);
+    }
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/BaseTagMatcherTestCase.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/BaseTagMatcherTestCase.java
new file mode 100644
index 0000000..410d2d3
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/BaseTagMatcherTestCase.java
@@ -0,0 +1,81 @@
+package org.eclipse.jst.jsf.core.tests.tagmatcher;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jst.jsf.core.tests.TestsPlugin;
+import org.eclipse.jst.jsf.test.util.JDTTestEnvironment;
+import org.eclipse.jst.jsf.test.util.JSFTestUtil;
+import org.eclipse.jst.jsf.test.util.WebProjectTestEnvironment;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+
+
+
+public class BaseTagMatcherTestCase extends TestCase {
+    /**
+     * The dynamic web project test environment
+     */
+    protected WebProjectTestEnvironment  _testEnv;
+    /**
+     * A handle to the Java project test environment
+     */
+    protected JDTTestEnvironment         _jdtTestEnv;
+    /**
+     * Name of the test data file containing the JSP source for this test
+     */
+    protected String                  _srcFileName;
+    /**
+     * Name of the file and path where the JSP source should be put in the
+     * test project
+     */
+    protected String                  _destFileName;
+    
+    /**
+     * The file handle to the JSP in the workspace
+     */
+    protected IFile                   _testJSP;
+    /**
+     * The SSE structured model for the JSP
+     */
+    protected IStructuredModel        _structuredModel;
+    /**
+     * The SSE structured document for the JSP
+     */
+    protected IStructuredDocument     _structuredDocument;
+
+    protected void setUp() throws Exception    
+    {
+        super.setUp();
+        
+        JSFTestUtil.setValidationEnabled(false);
+        
+        JSFTestUtil.setInternetProxyPreferences(true, "www-proxy.uk.oracle.com", "80");
+        
+        _testEnv = new WebProjectTestEnvironment("ELValidationTest_"+this.getClass().getName()+"_"+getName());
+        _testEnv.createProject();
+        assertNotNull(_testEnv);       
+        assertNotNull(_testEnv.getTestProject());
+        assertTrue(_testEnv.getTestProject().isAccessible());
+
+        _testJSP = (IFile) _testEnv.loadResourceInWebRoot
+            (TestsPlugin.getDefault().getBundle(),
+                    _srcFileName, _destFileName);
+
+        _structuredModel = StructuredModelManager.getModelManager().getModelForRead(_testJSP);
+        _structuredDocument = _structuredModel.getStructuredDocument();
+    }
+    
+    protected void tearDown() throws Exception 
+    {
+        super.tearDown();
+        
+        if (_structuredModel != null)
+        {
+            _structuredModel.releaseFromRead();
+        }
+        _testEnv.getTestProject().close(null);
+    }
+
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/TestXPathTagMatcher.java b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/TestXPathTagMatcher.java
new file mode 100644
index 0000000..1b7b7a4
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/src/org/eclipse/jst/jsf/core/tests/tagmatcher/TestXPathTagMatcher.java
@@ -0,0 +1,48 @@
+package org.eclipse.jst.jsf.core.tests.tagmatcher;
+
+import java.util.Iterator;
+
+import org.eclipse.jst.jsf.common.sets.internal.provisional.AxiomaticSet;
+import org.eclipse.jst.jsf.core.internal.provisional.tagmatcher.XPathMatchingAlgorithm;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+
+public class TestXPathTagMatcher extends BaseTagMatcherTestCase {
+
+    protected void setUp() throws Exception {
+        _srcFileName = "/testfiles/jsps/testdata1.jsp.data";
+        _destFileName = "/testdata1.jsp";
+        super.setUp();
+    }
+
+    public void testSimpleMatches()
+    {
+        // get the view tag
+        Document doc = ((IDOMModel)_structuredModel).getDocument();
+        System.out.println(System.currentTimeMillis());
+        XPathMatchingAlgorithm viewMatcher = new XPathMatchingAlgorithm("/view");
+        AxiomaticSet  set = viewMatcher.evaluate(doc);
+        System.out.println(System.currentTimeMillis());
+        
+        // get an input nested along a form path
+        assertEquals(1, set.size());
+        Node node = (Node) set.getFirstElement();
+        XPathMatchingAlgorithm  matcher = new XPathMatchingAlgorithm("html/body/form/panelGrid/inputText");
+        set = matcher.evaluate(node);
+        System.out.println(System.currentTimeMillis());
+        assertEquals(1, set.size());
+        
+        // get all of the ancestors of the inputText
+        final Node inputText = (Node) set.getFirstElement();
+        matcher = new XPathMatchingAlgorithm("ancestor::*");
+        set = matcher.evaluate(inputText);
+        assertEquals(5,set.size());
+        
+        for (final Iterator it = set.iterator(); it.hasNext();)
+        {
+            System.out.println(it.next());
+        }
+    }
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.core.tests/testfiles/jsps/testdata1.jsp.data b/jsf/tests/org.eclipse.jst.jsf.core.tests/testfiles/jsps/testdata1.jsp.data
new file mode 100644
index 0000000..ad170d3
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.core.tests/testfiles/jsps/testdata1.jsp.data
@@ -0,0 +1,40 @@
+
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+<%--
+The taglib directive below imports the JSTL library. If you uncomment it,
+you must also add the JSTL library to the project. The Add Library... action
+on Libraries node in Projects view can be used to add the JSTL 1.1 library.
+--%>
+
+<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
+
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+   "http://www.w3.org/TR/html4/loose.dtd">
+<f:view>
+	<f:loadBundle var="bundle" basename="resources.LoginPageBundle" />
+
+<html>
+  <head>
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+        <title><h:outputText value="#{bundle['page.title']}"/></title>
+  <link rel="stylesheet" href="style/style.css" media="screen"/>
+    </head>
+    <body>
+	<h:form id="mainForm">
+    <h1><h:outputText value="#{bundle['page.header']}"/></h1>
+    	<h:messages/>
+		<h:panelGrid columns="2">
+    		<h:outputLabel for="userId" value="Username:"/>
+	    	<h:inputText id="userId" value="#{loginRequest.id}"/>
+	    	<h:outputLabel for="password" value="Password:"/>
+			<h:inputSecret id="password" value="#{loginRequest.passwordPlainText}"/>
+    	</h:panelGrid>
+   		<h:commandButton action="#{appController.loginActions}" value="#{bundle['login.button.value']}"/>
+	</h:form>
+    
+    </body>
+</html>
+</f:view>
\ No newline at end of file