Basic test coverage for content assist.
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/META-INF/MANIFEST.MF b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/META-INF/MANIFEST.MF
index 871a8a8..7a956c7 100644
--- a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/META-INF/MANIFEST.MF
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/META-INF/MANIFEST.MF
@@ -19,7 +19,8 @@
org.eclipse.jface.text;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jst.jsf.core;bundle-version="[1.0.0,1.1.0)",
org.eclipse.wst.html.core;bundle-version="[1.1.0,1.2.0)",
- org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)"
+ org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.emf.ecore
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.jst.jsf.contentassist.tests;x-internal:=true
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/AllTests.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/AllTests.java
index b664f7d..e78d4db 100644
--- a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/AllTests.java
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/AllTests.java
@@ -4,7 +4,7 @@
* 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:
* Oracle Corporation - initial API and implementation
*******************************************************************************/
@@ -15,7 +15,7 @@
/**
* All tests suite for content assist
- *
+ *
* @author cbateman
*
*/
@@ -23,13 +23,16 @@
/**
* @return the test suite
*/
- public static Test suite()
+ public static Test suite()
{
- TestSuite suite = new TestSuite("Test for org.eclipse.jst.jsf.contentassist");
+ final TestSuite suite = new TestSuite("Test for org.eclipse.jst.jsf.contentassist");
//$JUnit-BEGIN$
suite.addTestSuite(CompletionPrefixTest.class);
suite.addTestSuite(Test_bug_149224.class);
suite.addTestSuite(Test_bug_149743.class);
+ suite.addTestSuite(TestIdCompletionStrategy.class);
+ suite.addTestSuite(TestFunctionCompletionStrategy.class);
+ suite.addTestSuite(TestContentAssistParser.class);
//$JUnit-END$
return suite;
}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/BaseTestClass.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/BaseTestClass.java
new file mode 100644
index 0000000..a5d06b6
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/BaseTestClass.java
@@ -0,0 +1,211 @@
+package org.eclipse.jst.jsf.contentassist.tests;
+
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver;
+import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory;
+import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver;
+import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext;
+import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContextFactory;
+import org.eclipse.jst.jsf.context.symbol.ISymbol;
+import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistParser;
+import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistStrategy;
+import org.eclipse.jst.jsf.designtime.resolver.ISymbolContextResolver;
+import org.eclipse.jst.jsf.designtime.resolver.StructuredDocumentSymbolResolverFactory;
+import org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP;
+import org.eclipse.jst.jsp.core.internal.regions.DOMJSPRegionContexts;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Node;
+
+public class BaseTestClass extends TestCase {
+
+ protected static class ContextWrapper {
+ private final IStructuredDocumentContext _context;
+ private final IStructuredModel _model;
+
+ ContextWrapper(final IStructuredDocumentContext context,
+ final IStructuredModel model) {
+ super();
+ _context = context;
+ _model = model;
+ }
+
+ IStructuredDocumentContext getContext() {
+ return _context;
+ }
+
+ IStructuredModel getModel() {
+ return _model;
+ }
+
+ void dispose() {
+ _model.releaseFromRead();
+ }
+ }
+
+ /**
+ * @param jspFile
+ * @param offset
+ * @return the context wrapper. Caller must ensure dispose is called so
+ * model is released when finished.
+ * @throws Exception
+ */
+ protected final ContextWrapper getDocumentContext(final IFile jspFile,
+ final int offset) throws Exception {
+ final IModelManager modelManager = StructuredModelManager
+ .getModelManager();
+
+ IStructuredModel model = null;
+
+ model = modelManager.getModelForRead(jspFile);
+ assertTrue(model instanceof DOMModelForJSP);
+ final IStructuredDocumentContext context = IStructuredDocumentContextFactory.INSTANCE
+ .getContext(model.getStructuredDocument(), offset);
+ return new ContextWrapper(context, model);
+ }
+
+ protected final void assertELSanity(final IFile jspFile, final int offset,
+ final String attrName, final String elExpr) throws Exception {
+ ContextWrapper wrapper = null;
+ try {
+ wrapper = getDocumentContext(jspFile, offset);
+ final IStructuredDocumentContext context = wrapper.getContext();
+ final IDOMContextResolver resolver = IStructuredDocumentContextResolverFactory.INSTANCE
+ .getDOMContextResolver(context);
+ final Node node = resolver.getNode();
+ // bJSFTestUtil.getIndexedRegion((IStructuredDocument)
+ // context.getStructuredDocument(), 589);
+ assertTrue(node instanceof Attr);
+ assertEquals(attrName, ((Attr) node).getNodeName());
+ assertEquals(elExpr, ((Attr) node).getNodeValue());
+ } finally {
+ if (wrapper != null) {
+ wrapper.dispose();
+ }
+ }
+ }
+
+ protected final void assertELVariableSanity(final IFile jspFile,
+ final String varName) throws Exception {
+ ContextWrapper contextWrapper = null;
+
+ try {
+ contextWrapper = getDocumentContext(jspFile, -1);
+ final ISymbolContextResolver symbolResolver = StructuredDocumentSymbolResolverFactory
+ .getInstance().getSymbolContextResolver(
+ contextWrapper.getContext());
+ final ISymbol bundleVar = symbolResolver.getVariable(varName);
+ assertNotNull(bundleVar);
+ } finally {
+ if (contextWrapper != null) {
+ contextWrapper.dispose();
+ }
+ }
+ }
+
+ /**
+ * Uses the docOffset to find the EL text used to generate the proposals on.
+ * @param jspFile
+ * @param docOffset
+ * @param exprOffset
+ * @return the proposals
+ * @throws Exception
+ */
+ protected final List<ICompletionProposal> getProposals(final IFile jspFile,
+ final int docOffset, final int exprOffset) throws Exception {
+ ContextWrapper wrapper = null;
+
+ try {
+ wrapper = getDocumentContext(jspFile, docOffset);
+
+ final ITextRegionContextResolver resolver = IStructuredDocumentContextResolverFactory.INSTANCE
+ .getTextRegionResolver(wrapper.getContext());
+
+ assertEquals(DOMJSPRegionContexts.JSP_VBL_CONTENT, resolver.getRegionType());
+ final String elText = resolver.getRegionText().trim();
+ assertNotNull(elText);
+
+ final ContentAssistStrategy strategy = ContentAssistParser
+ .getPrefix(exprOffset, elText);
+ assertNotNull(strategy);
+ return strategy.getProposals(wrapper.getContext());
+ } finally {
+ if (wrapper != null) {
+ wrapper.dispose();
+ }
+ }
+ }
+
+ /**
+ * This method doesn't use the docOffset to find the EL text.
+ *
+ * @param jspFile
+ * @param exprOffset
+ * @param elText
+ * @return the proposals at 1-based exprOffset into elText
+ * @throws Exception
+ */
+ protected final List<ICompletionProposal> getProposals(final IFile jspFile,
+ final int docOffset, final String elText, final int exprOffset) throws Exception
+ {
+ ContextWrapper wrapper = null;
+
+ try {
+ wrapper = getDocumentContext(jspFile, docOffset);
+
+
+ final ContentAssistStrategy strategy = ContentAssistParser
+ .getPrefix(exprOffset, elText);
+ assertNotNull(strategy);
+ return strategy.getProposals(wrapper.getContext());
+ } finally {
+ if (wrapper != null) {
+ wrapper.dispose();
+ }
+ }
+
+ }
+
+ protected final void applyAndCheck(final IFile jspFile, final int offset, final ICompletionProposal applyMe, final String expectedResult)
+ throws Exception {
+ ContextWrapper wrapper = null;
+
+ try {
+ wrapper = getDocumentContext(jspFile, offset);
+
+ applyMe.apply(getDocumentContext(jspFile, offset).getContext()
+ .getStructuredDocument());
+
+ final ITextRegionContextResolver resolver = IStructuredDocumentContextResolverFactory.INSTANCE
+ .getTextRegionResolver(wrapper.getContext());
+
+ final String newELText = resolver.getRegionText();
+ assertEquals(expectedResult, newELText);
+ } finally {
+ if (wrapper != null) {
+ wrapper.dispose();
+ }
+ }
+ }
+
+ /**
+ * @param expected
+ * @param proposals
+ */
+ protected void assertDisplayNamesMatch(final Set<String> expected, final List<ICompletionProposal> proposals) {
+ assertEquals(expected.size(), proposals.size());
+
+ for (final ICompletionProposal proposal : proposals)
+ {
+ expected.contains(proposal.getDisplayString());
+ }
+ }
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/CompletionPrefixTest.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/CompletionPrefixTest.java
index c5a627d..f596e82 100644
--- a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/CompletionPrefixTest.java
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/CompletionPrefixTest.java
@@ -7,35 +7,35 @@
*
* Contributors:
* Cameron Bateman/Oracle - initial API and implementation
- *
+ *
********************************************************************************/
package org.eclipse.jst.jsf.contentassist.tests;
+import junit.framework.TestCase;
+
import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistParser;
import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistStrategy;
-import junit.framework.TestCase;
-
/**
* @author cbateman
*
*/
-public class CompletionPrefixTest extends TestCase
+public class CompletionPrefixTest extends TestCase
{
/* empty expresion */
private final static String empty_ = " ";
-
+
/* simple value expressions */
private final static String xxx = "xxx";
private final static String xxxDot = "xxx.";
private final static String xxxYYY = "xxx.yyy";
private final static String xxxYYYZZZ = "xxx.yyy.zzz";
-
+
/* value expressions with comparisons */
private final static String xxxLtYYY = "xxx < yyy";
private final static String xxxDotYYYLtZZZ = "xxx.yyy < zzz";
-
+
/* expressions using the ['yyy'] map syntax */
private final static String xxxMapYYY = "xxx['yyy']";
private final static String xxxMapXXXExpr = "xxx[XXX]";
@@ -43,9 +43,9 @@
private final static String xxxMapXXXDotYYYExpr = "xxx[XXX.YYY]";
private final static String xxxMapXXXDotYYYDotExpr = "xxx[XXX.YYY.]";
private final static String xxxMapXXXDotYYYDotZZZExpr = "xxx[XXX.YYY.ZZZ]";
-
-
-
+
+
+
/**
* Test passing null to the parser
*/
@@ -57,9 +57,9 @@
assertNull(prefix);
}
}
-
+
/**
- *
+ *
*/
public void testPrefix_empty_()
{
@@ -67,14 +67,14 @@
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, empty_);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testPrefix_xxx()
{
@@ -82,32 +82,32 @@
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxx);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x */
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxx);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x */
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxx);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testPrefix_xxxDot()
{
@@ -115,32 +115,32 @@
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxDot);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x . */
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxDot);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x . */
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxDot);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testSuffix_xxxDot()
{
@@ -148,14 +148,14 @@
/* ^*/
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxDot);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testPrefix_xxxYYY()
{
@@ -163,40 +163,40 @@
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxYYY);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x . y y y . z z z */
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxYYY);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x . y y y . z z z */
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxYYY);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testFirstSuffix_xxxYYY()
{
/* Test x x x . y y y . z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -204,17 +204,17 @@
/* Test x x x . y y y . z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(6, xxxYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(6, xxxYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x . y y y . z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -229,41 +229,41 @@
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxYYYZZZ);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x . y y y . z z z */
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxYYYZZZ);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x . y y y . z z z */
/* ^ */
{
final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxYYYZZZ);
-
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testFirstSuffix_xxxYYYZZZ()
{
/* Test x x x . y y y . z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxYYYZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxYYYZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -271,33 +271,33 @@
/* Test x x x . y y y . z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(6, xxxYYYZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(6, xxxYYYZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x . y y y . z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxYYYZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxYYYZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
}
-
-
+
+
/**
- *
+ *
*/
public void testSecondSuffix_xxxYYYZZZ()
{
/* Test x x x . y y y . z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(9, xxxYYYZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(9, xxxYYYZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx.yyy".equals(prefix.getValue()));
}
@@ -305,59 +305,59 @@
/* Test x x x . y y y . z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(10, xxxYYYZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(10, xxxYYYZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx.yyy".equals(prefix.getValue()));
}
-
+
/* Test x x x . y y y . z z z */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(12, xxxYYYZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(12, xxxYYYZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx.yyy".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testPrefix_xxxLtYYY()
{
/* Test x x x < y y y */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxLtYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxLtYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x < y y y */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxLtYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxLtYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x < y y y */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxLtYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxLtYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x < y y y */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(7, xxxLtYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(7, xxxLtYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "yyy".equals(prefix.getValue()));
}
@@ -365,32 +365,32 @@
/* Test x x x < y y y */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxLtYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxLtYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "yyy".equals(prefix.getValue()));
}
-
+
/* Test x x x < y y y */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(10, xxxLtYYY);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(10, xxxLtYYY);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "yyy".equals(prefix.getValue()));
}
}
/**
- *
+ *
*/
public void testPrefix_xxxDotYYYLtZZZ()
{
/* Test x x x . y y y < z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxDotYYYLtZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxDotYYYLtZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -398,8 +398,8 @@
/* Test x x x . y y y < z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxDotYYYLtZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxDotYYYLtZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -407,8 +407,8 @@
/* Test x x x . y y y < z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxDotYYYLtZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxDotYYYLtZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -416,8 +416,8 @@
/* Test x x x . y y y < z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxDotYYYLtZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxDotYYYLtZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -425,8 +425,8 @@
/* Test x x x . y y y < z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(6, xxxDotYYYLtZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(6, xxxDotYYYLtZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -434,8 +434,8 @@
/* Test x x x . y y y < z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxDotYYYLtZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxDotYYYLtZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
@@ -443,55 +443,55 @@
/* Test x x x . y y y < z z z */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(11, xxxDotYYYLtZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(11, xxxDotYYYLtZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "zzz".equals(prefix.getValue()));
}
-
+
/* Test x x x . y y y < z z z */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(14, xxxDotYYYLtZZZ);
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(14, xxxDotYYYLtZZZ);
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "zzz".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testSuffix_xxxDotYYYLtZZZ()
{
/* Test x x x . y y y < z z z . */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(15, xxxDotYYYLtZZZ+".");
-
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(15, xxxDotYYYLtZZZ+".");
+
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "zzz".equals(prefix.getValue()));
}
}
-
+
/**
- *
+ *
*/
public void testPrefix_xxxMapYYY()
{
/* Test x x x [ ' y y y ' ] */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxMapYYY);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(1, xxxMapYYY);
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x [ ' y y y ' ] */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxMapYYY);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(2, xxxMapYYY);
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
@@ -500,12 +500,12 @@
/* Test x x x [ ' y y y ' ] */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxMapYYY);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(4, xxxMapYYY);
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "xxx".equals(prefix.getValue()));
}
-
+
/* Test x x x [ ' y y y ' ] */
/* ^ */
// {
@@ -515,18 +515,18 @@
// assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
// && "xxx['yyy']".equals(prefix.getValue()));
// }
-
+
/* Test x x x [ ' y y y ' ] . */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(12, xxxMapYYY+".");
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(12, xxxMapYYY+".");
System.out.println(prefix.getValue());
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION
&& "xxx['yyy']".equals(prefix.getValue()));
}
}
-
+
/**
* Test completion inside an array
*/
@@ -535,7 +535,7 @@
/* Test x x x [ X X X ] */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxMapXXXExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(5, xxxMapXXXExpr);
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "XXX".equals(prefix.getValue()));
@@ -544,7 +544,7 @@
/* Test x x x [ X X X ] */
/* ^ */
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(6, xxxMapXXXExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(6, xxxMapXXXExpr);
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "XXX".equals(prefix.getValue()));
@@ -553,13 +553,13 @@
/* Test x x x [ X X X ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxMapXXXExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxMapXXXExpr);
assertTrue(prefix.getType() == ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION
&& "XXX".equals(prefix.getValue()));
}
}
-
+
/**
* Tests suffix completions on dots inside brackets
*/
@@ -568,22 +568,22 @@
/* Test x x x [ X X X . ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxMapXXXDotExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(8, xxxMapXXXDotExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_ID_COMPLETION, prefix.getType());
assertEquals("XXX", prefix.getValue());
}
-
+
/* Test x x x [ X X X . ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(9, xxxMapXXXDotExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(9, xxxMapXXXDotExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX", prefix.getValue());
}
}
-
+
/**
* Test dot completion inside an array expression
*/
@@ -592,49 +592,49 @@
/* Test x x x [ X X X . Y Y Y ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(9, xxxMapXXXDotYYYExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(9, xxxMapXXXDotYYYExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX", prefix.getValue());
}
/* Test x x x [ X X X . Y Y Y ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(10, xxxMapXXXDotYYYExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(10, xxxMapXXXDotYYYExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX", prefix.getValue());
}
-
+
/* Test x x x [ X X X . Y Y Y ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(12, xxxMapXXXDotYYYExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(12, xxxMapXXXDotYYYExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX", prefix.getValue());
}
/* Test x x x [ X X X . Y Y Y . ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(12, xxxMapXXXDotYYYDotExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(12, xxxMapXXXDotYYYDotExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX", prefix.getValue());
}
/* Test x x x [ X X X . Y Y Y . ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(13, xxxMapXXXDotYYYDotExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(13, xxxMapXXXDotYYYDotExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX.YYY", prefix.getValue());
}
}
-
+
/**
* Test dot completion on XXX.YYY.ZZZ type expressions
*/
@@ -643,27 +643,27 @@
/* Test x x x [ X X X . Y Y Y . Z Z Z] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(13, xxxMapXXXDotYYYDotZZZExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(13, xxxMapXXXDotYYYDotZZZExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX.YYY", prefix.getValue());
}
/* Test x x x [ X X X . Y Y Y . Z Z Z] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(14, xxxMapXXXDotYYYDotZZZExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(14, xxxMapXXXDotYYYDotZZZExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX.YYY", prefix.getValue());
}
/* Test x x x [ X X X . Y Y Y . Z Z Z ] */
/* ^*/
{
- ContentAssistStrategy prefix = ContentAssistParser.getPrefix(16, xxxMapXXXDotYYYDotZZZExpr);
+ final ContentAssistStrategy prefix = ContentAssistParser.getPrefix(16, xxxMapXXXDotYYYDotZZZExpr);
- assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
+ assertEquals(ContentAssistStrategy.PREFIX_TYPE_DOT_COMPLETION, prefix.getType());
assertEquals("XXX.YYY", prefix.getValue());
}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/ContentAssistTestsPlugin.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/ContentAssistTestsPlugin.java
index 883b8c9..4bda030 100644
--- a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/ContentAssistTestsPlugin.java
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/ContentAssistTestsPlugin.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Cameron Bateman/Oracle - initial API and implementation
- *
+ *
********************************************************************************/
package org.eclipse.jst.jsf.contentassist.tests;
@@ -27,7 +27,7 @@
// The shared instance
private static ContentAssistTestsPlugin plugin;
-
+
/**
* The constructor
*/
@@ -39,7 +39,8 @@
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
- public void start(BundleContext context) throws Exception {
+ @Override
+ public void start(final BundleContext context) throws Exception {
super.start(context);
}
@@ -47,7 +48,8 @@
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
- public void stop(BundleContext context) throws Exception {
+ @Override
+ public void stop(final BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestContentAssistParser.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestContentAssistParser.java
new file mode 100644
index 0000000..03cd4f1
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestContentAssistParser.java
@@ -0,0 +1,108 @@
+package org.eclipse.jst.jsf.contentassist.tests;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jst.jsf.context.symbol.IBeanInstanceSymbol;
+import org.eclipse.jst.jsf.context.symbol.IBeanMethodSymbol;
+import org.eclipse.jst.jsf.context.symbol.IBeanPropertySymbol;
+import org.eclipse.jst.jsf.core.IJSFCoreConstants;
+import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistParser;
+import org.eclipse.jst.jsf.core.internal.contentassist.el.SymbolInfo;
+import org.eclipse.jst.jsf.core.tests.util.JSFFacetedTestEnvironment;
+import org.eclipse.jst.jsf.test.util.JDTTestEnvironment;
+import org.eclipse.jst.jsf.test.util.JSFTestUtil;
+import org.eclipse.jst.jsf.test.util.TestFileResource;
+import org.eclipse.jst.jsf.test.util.WebProjectTestEnvironment;
+
+public class TestContentAssistParser extends BaseTestClass
+{
+ private WebProjectTestEnvironment _testEnv;
+ private IFile _jspFile;
+ private IType _myBeanType;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ JSFTestUtil.setValidationEnabled(false);
+
+ _testEnv = new WebProjectTestEnvironment(getClass().getName()+"_"+getName());
+ _testEnv.createProject(false);
+ assertNotNull(_testEnv);
+ assertNotNull(_testEnv.getTestProject());
+ assertTrue(_testEnv.getTestProject().isAccessible());
+
+ final JSFFacetedTestEnvironment jsfFacedEnv = new JSFFacetedTestEnvironment(_testEnv);
+ jsfFacedEnv.initialize(IJSFCoreConstants.FACET_VERSION_1_1);
+
+ _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
+ "/testdata/faces-config_basic.xml.data",
+ "/WEB-INF/faces-config.xml");
+ _jspFile = (IFile) _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
+ "/testdata/basicELExpressions.jsp.data",
+ "/basicELExpressions.jsp");
+ assertNotNull(_jspFile);
+ assertTrue(_jspFile.isAccessible());
+
+ final JDTTestEnvironment jdtTestEnv = new JDTTestEnvironment(_testEnv);
+ final TestFileResource resource = new TestFileResource();
+ resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
+ "/testdata/MyBean.java.data");
+ jdtTestEnv.addSourceFile("src", "beans", "MyBean", resource.toString());
+ _myBeanType = JavaCore.create(_testEnv.getTestProject()).findType("beans.MyBean");
+ assertNotNull(_myBeanType);
+ assertTrue(_myBeanType.exists());
+ }
+
+ public void testSanity() throws Exception
+ {
+ assertELSanity(_jspFile, 518, "value", "#{}");
+ assertELSanity(_jspFile, 547, "value", "#{ }");
+ assertELSanity(_jspFile, 579, "value", "#{myBean}");
+ assertELSanity(_jspFile, 614, "value", "#{myBean.property}");
+ assertELSanity(_jspFile, 658, "value", "#{paramValues.foo}");
+ assertELSanity(_jspFile, 706, "action", "#{myBean.actionMethod}");
+
+ assertELVariableSanity(_jspFile, "myBean");
+ }
+
+
+ public void testGetPrefix() {
+ // for now there's a enough coverage through TestIdCompletionStrategy
+ }
+
+ public void testGetSymbolInfo() throws Exception
+ {
+ assertNull(ContentAssistParser.getSymbolInfo(getDocumentContext(_jspFile, 518).getContext(), 1, null));
+ assertNull(ContentAssistParser.getSymbolInfo(getDocumentContext(_jspFile, 518).getContext(), 1, ""));
+ assertNull(ContentAssistParser.getSymbolInfo(getDocumentContext(_jspFile, 547).getContext(), 1, " "));
+
+ // variable test
+ SymbolInfo symbolInfo =
+ ContentAssistParser.getSymbolInfo(getDocumentContext(_jspFile, 579).getContext(), 1, "myBean");
+ assertNotNull(symbolInfo);
+ assertEquals("myBean", symbolInfo.getSymbol().getName());
+ assertTrue(symbolInfo.getSymbol() instanceof IBeanInstanceSymbol);
+ assertNotNull(symbolInfo.getRelativeRegion());
+ assertEquals(6, symbolInfo.getRelativeRegion().getLength());
+
+ // property test
+ symbolInfo =
+ ContentAssistParser.getSymbolInfo(getDocumentContext(_jspFile, 614).getContext(), 8, "myBean.property");
+ assertNotNull(symbolInfo);
+ assertEquals("property", symbolInfo.getSymbol().getName());
+ assertTrue(symbolInfo.getSymbol() instanceof IBeanPropertySymbol);
+ assertNotNull(symbolInfo.getRelativeRegion());
+
+ // method test
+ symbolInfo =
+ ContentAssistParser.getSymbolInfo(getDocumentContext(_jspFile, 706).getContext(), 8, "myBean.actionMethod");
+ assertNotNull(symbolInfo);
+ assertEquals("actionMethod", symbolInfo.getSymbol().getName());
+ assertTrue(symbolInfo.getSymbol() instanceof IBeanMethodSymbol);
+ assertNotNull(symbolInfo.getRelativeRegion());
+ }
+
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestFunctionCompletionStrategy.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestFunctionCompletionStrategy.java
index 5bd76be..3f7b7b2 100644
--- a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestFunctionCompletionStrategy.java
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestFunctionCompletionStrategy.java
@@ -4,14 +4,20 @@
* 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:
* Oracle Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.jsf.contentassist.tests;
-import junit.framework.TestCase;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jst.jsf.core.IJSFCoreConstants;
import org.eclipse.jst.jsf.core.tests.util.JSFFacetedTestEnvironment;
import org.eclipse.jst.jsf.test.util.JDTTestEnvironment;
@@ -24,10 +30,14 @@
* @author cbateman
*
*/
-public class TestFunctionCompletionStrategy extends TestCase {
+public class TestFunctionCompletionStrategy extends BaseTestClass
+{
private WebProjectTestEnvironment _testEnv;
-
- protected void setUp() throws Exception
+ private IFile _jspFile;
+ private IType _myBeanType;
+
+ @Override
+ protected void setUp() throws Exception
{
super.setUp();
@@ -35,32 +45,83 @@
_testEnv = new WebProjectTestEnvironment(getClass().getName()+"_"+getName());
_testEnv.createProject(false);
- assertNotNull(_testEnv);
+ assertNotNull(_testEnv);
assertNotNull(_testEnv.getTestProject());
assertTrue(_testEnv.getTestProject().isAccessible());
-
- JSFFacetedTestEnvironment jsfFacedEnv = new JSFFacetedTestEnvironment(_testEnv);
+
+ final JSFFacetedTestEnvironment jsfFacedEnv = new JSFFacetedTestEnvironment(_testEnv);
jsfFacedEnv.initialize(IJSFCoreConstants.FACET_VERSION_1_1);
-
+
_testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
- "/testdata/faces-config_bug149743.xml.data",
+ "/testdata/faces-config_basic.xml.data",
"/WEB-INF/faces-config.xml");
- _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
- "/testdata/bug_149743.jsp.data",
- "/bug_149743.jsp");
-
+ _jspFile = (IFile) _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
+ "/testdata/basicELExpressions.jsp.data",
+ "/basicELExpressions.jsp");
+ assertNotNull(_jspFile);
+ assertTrue(_jspFile.isAccessible());
+
final JDTTestEnvironment jdtTestEnv = new JDTTestEnvironment(_testEnv);
- TestFileResource resource = new TestFileResource();
- resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
+ final TestFileResource resource = new TestFileResource();
+ resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
"/testdata/MyBean.java.data");
jdtTestEnv.addSourceFile("src", "beans", "MyBean", resource.toString());
+ _myBeanType = JavaCore.create(_testEnv.getTestProject()).findType("beans.MyBean");
+ assertNotNull(_myBeanType);
+ assertTrue(_myBeanType.exists());
}
/**
* Sanity check
*/
-// public void testSanity()
-// {
-// }
+ public void testSanity() throws Exception
+ {
+ assertELSanity(_jspFile, 614, "value", "#{myBean.property}");
+ assertELSanity(_jspFile, 658, "value", "#{paramValues.foo}");
+ assertELSanity(_jspFile, 706, "action", "#{myBean.actionMethod}");
+
+ assertELVariableSanity(_jspFile, "myBean");
+ }
+
+ public void testFunctionCompletionStrategy() throws Exception
+ {
+ // normal value binding only has properties
+ List<ICompletionProposal> proposals = getProposals(_jspFile, 614, 8);
+
+ {
+ final Set<String> propNames = new HashSet<String>();
+ propNames.add("property");
+ propNames.add("class");
+ assertDisplayNamesMatch(propNames, proposals);
+ }
+
+ // method binding includes methods and also properties
+ proposals = getProposals(_jspFile, 706, 8);
+
+ {
+ final Set<String> propNames = new HashSet<String>();
+ propNames.add("property");
+ propNames.add("class");
+ propNames.add("getProperty");
+ propNames.add("actionMethod");
+ propNames.add("equals");
+ propNames.add("getClass");
+ propNames.add("hashCode");
+ propNames.add("notify");
+ propNames.add("notifyAll");
+ propNames.add("toString");
+ propNames.add("wait");
+ propNames.add("wait");
+ propNames.add("wait");
+
+ assertEquals(13, proposals.size());
+ // have to loop through explicitly here because wait appears
+ // in the list thrice, but can only be in the set once
+ for (final ICompletionProposal prop : proposals)
+ {
+ assertTrue(propNames.contains(prop.getDisplayString()));
+ }
+ }
+ }
}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestIdCompletionStrategy.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestIdCompletionStrategy.java
new file mode 100644
index 0000000..b73ee12
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/TestIdCompletionStrategy.java
@@ -0,0 +1,119 @@
+package org.eclipse.jst.jsf.contentassist.tests;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jst.jsf.core.IJSFCoreConstants;
+import org.eclipse.jst.jsf.core.tests.util.JSFFacetedTestEnvironment;
+import org.eclipse.jst.jsf.test.util.JDTTestEnvironment;
+import org.eclipse.jst.jsf.test.util.JSFTestUtil;
+import org.eclipse.jst.jsf.test.util.TestFileResource;
+import org.eclipse.jst.jsf.test.util.WebProjectTestEnvironment;
+
+public class TestIdCompletionStrategy extends BaseTestClass
+{
+ private final static Set<String> DISPLAY_NAMES;
+
+ static
+ {
+ final Set<String> displayNames = new HashSet<String>();
+ displayNames.add("requestScope");
+ displayNames.add("cookie");
+ displayNames.add("header");
+ displayNames.add("headerValues");
+ displayNames.add("param");
+ displayNames.add("paramValues");
+ displayNames.add("facesContext");
+ displayNames.add("view");
+ displayNames.add("initParam");
+ displayNames.add("sessionScope");
+ displayNames.add("applicationScope");
+ displayNames.add("myBean");
+ DISPLAY_NAMES = Collections.unmodifiableSet(displayNames);
+ }
+ private WebProjectTestEnvironment _testEnv;
+ private IFile _jspFile;
+ private IType _myBeanType;
+
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ JSFTestUtil.setValidationEnabled(false);
+
+ _testEnv = new WebProjectTestEnvironment(getClass().getName()+"_"+getName());
+ _testEnv.createProject(false);
+ assertNotNull(_testEnv);
+ assertNotNull(_testEnv.getTestProject());
+ assertTrue(_testEnv.getTestProject().isAccessible());
+
+ final JSFFacetedTestEnvironment jsfFacedEnv = new JSFFacetedTestEnvironment(_testEnv);
+ jsfFacedEnv.initialize(IJSFCoreConstants.FACET_VERSION_1_1);
+
+ _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
+ "/testdata/faces-config_basic.xml.data",
+ "/WEB-INF/faces-config.xml");
+ _jspFile = (IFile) _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
+ "/testdata/basicELExpressions.jsp.data",
+ "/basicELExpressions.jsp");
+ assertNotNull(_jspFile);
+ assertTrue(_jspFile.isAccessible());
+
+ final JDTTestEnvironment jdtTestEnv = new JDTTestEnvironment(_testEnv);
+ final TestFileResource resource = new TestFileResource();
+ resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
+ "/testdata/MyBean.java.data");
+ jdtTestEnv.addSourceFile("src", "beans", "MyBean", resource.toString());
+ _myBeanType = JavaCore.create(_testEnv.getTestProject()).findType("beans.MyBean");
+ assertNotNull(_myBeanType);
+ assertTrue(_myBeanType.exists());
+ }
+
+ public void testSanity() throws Exception
+ {
+ assertELSanity(_jspFile, 518, "value", "#{}");
+ assertELSanity(_jspFile, 547, "value", "#{ }");
+ assertELSanity(_jspFile, 579, "value", "#{myBean}");
+ assertELSanity(_jspFile, 614, "value", "#{myBean.property}");
+ assertELSanity(_jspFile, 658, "value", "#{paramValues.foo}");
+
+ assertEquals(12, DISPLAY_NAMES.size());
+ }
+
+ public void testGetProposals() {
+
+ }
+
+ public void testIdCompletionStrategy() throws Exception
+ {
+ // empty string has all
+ assertDisplayNamesMatch(DISPLAY_NAMES, getProposals(_jspFile, 518, "", 1));
+
+ // empty whitespace has all
+ assertDisplayNamesMatch(DISPLAY_NAMES, getProposals(_jspFile, 547, 1));
+
+ // at the very start of a variable, have all
+ assertDisplayNamesMatch(DISPLAY_NAMES, getProposals(_jspFile, 579, 1));
+ // one character in, only ones matching prefix
+ assertDisplayNamesMatch(Collections.singleton("myBean"), getProposals(_jspFile, 579, 2));
+
+ // having properties should not change the variable resolved
+ assertDisplayNamesMatch(DISPLAY_NAMES, getProposals(_jspFile, 614, 1));
+ // one character in, only ones matching prefix
+ assertDisplayNamesMatch(Collections.singleton("myBean"), getProposals(_jspFile, 614, 2));
+
+ // having properties should not change the variable resolved
+ assertDisplayNamesMatch(DISPLAY_NAMES, getProposals(_jspFile, 658, 1));
+ // one character in, only ones matching prefix
+ final Set<String> paramNames = new HashSet<String>();
+ paramNames.add("param");
+ paramNames.add("paramValues");
+ assertDisplayNamesMatch(Collections.unmodifiableSet(paramNames), getProposals(_jspFile, 658, 2));
+ }
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/Test_bug_149224.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/Test_bug_149224.java
index ddbe91c..4216c18 100644
--- a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/Test_bug_149224.java
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/Test_bug_149224.java
@@ -4,82 +4,65 @@
* 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:
* Oracle Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.jsf.contentassist.tests;
import java.io.ByteArrayInputStream;
-import java.util.Iterator;
import java.util.List;
-import junit.framework.TestCase;
-
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver;
-import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory;
-import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver;
-import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext;
-import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContextFactory;
-import org.eclipse.jst.jsf.context.symbol.ISymbol;
import org.eclipse.jst.jsf.core.IJSFCoreConstants;
-import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistParser;
-import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistStrategy;
import org.eclipse.jst.jsf.core.tests.util.JSFFacetedTestEnvironment;
-import org.eclipse.jst.jsf.designtime.resolver.ISymbolContextResolver;
-import org.eclipse.jst.jsf.designtime.resolver.StructuredDocumentSymbolResolverFactory;
import org.eclipse.jst.jsf.test.util.JDTTestEnvironment;
import org.eclipse.jst.jsf.test.util.JSFTestUtil;
import org.eclipse.jst.jsf.test.util.TestFileResource;
import org.eclipse.jst.jsf.test.util.WebProjectTestEnvironment;
-import org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Node;
/**
* Regression test for 149224 -- replace '.' on completion with [] style of
* map
- *
+ *
* @author cbateman
*
*/
-public class Test_bug_149224 extends TestCase
+public class Test_bug_149224 extends BaseTestClass
{
private WebProjectTestEnvironment _testEnv;
-
- protected void setUp() throws Exception
+ private IFile _jspFile;
+
+ @Override
+ protected void setUp() throws Exception
{
super.setUp();
JSFTestUtil.setValidationEnabled(false);
-
+
_testEnv = new WebProjectTestEnvironment("Test_bug_149224_"+getName());
_testEnv.createProject(false);
- assertNotNull(_testEnv);
+ assertNotNull(_testEnv);
assertNotNull(_testEnv.getTestProject());
assertTrue(_testEnv.getTestProject().isAccessible());
-
- JSFFacetedTestEnvironment jsfFacedEnv = new JSFFacetedTestEnvironment(_testEnv);
+
+ final JSFFacetedTestEnvironment jsfFacedEnv = new JSFFacetedTestEnvironment(_testEnv);
jsfFacedEnv.initialize(IJSFCoreConstants.FACET_VERSION_1_1);
-
- _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
+
+ _jspFile = (IFile) _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
"/testdata/bug_149224_1.jsp.data",
"/bug_149224.jsp");
-
+
+ assertNotNull(_jspFile);
+ assertTrue(_jspFile.isAccessible());
+
final JDTTestEnvironment jdtTestEnv = new JDTTestEnvironment(_testEnv);
TestFileResource resource = new TestFileResource();
- resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
+ resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
"/testdata/MyBean.java.data");
jdtTestEnv.addSourceFile("src", "beans", "MyBean", resource.toString());
-
+
resource = new TestFileResource();
resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
"/testdata/bug_149224.properties.data");
@@ -90,44 +73,15 @@
/**
* Sanity check
*/
- public void testSanity()
+ public void testSanity() throws Exception
{
- ContextWrapper wrapper = null;
-
+ final ContextWrapper wrapper = null;
+
try
{
- wrapper = getDocumentContext("/WebContent/bug_149224.jsp", 589);
- IStructuredDocumentContext context = wrapper.getContext();
- IDOMContextResolver resolver =
- IStructuredDocumentContextResolverFactory.INSTANCE.
- getDOMContextResolver(context);
- Node node = resolver.getNode();
- JSFTestUtil.getIndexedRegion((IStructuredDocument) context.getStructuredDocument(), 589);
- assertTrue(node instanceof Attr);
- assertEquals("value", ((Attr)node).getNodeName());
- assertEquals("#{bundle1.}", ((Attr)node).getNodeValue());
- wrapper.dispose();
-
- wrapper = getDocumentContext("/WebContent/bug_149224.jsp", 630);
- context = wrapper.getContext();
- resolver =
- IStructuredDocumentContextResolverFactory.INSTANCE.
- getDOMContextResolver(context);
- node = resolver.getNode();
- assertTrue(node instanceof Attr);
- assertEquals("value", ((Attr)node).getNodeName());
- assertEquals("#{bundle1.x}", ((Attr)node).getNodeValue());
-
- ISymbolContextResolver symbolResolver =
- StructuredDocumentSymbolResolverFactory.getInstance().
- getSymbolContextResolver(context);
- ISymbol bundleVar = symbolResolver.getVariable("bundle1");
- assertNotNull(bundleVar);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- fail(e.getLocalizedMessage());
+ assertELSanity(_jspFile, 589, "value", "#{bundle1.}");
+ assertELSanity(_jspFile, 630, "value", "#{bundle1.x}");
+ assertELVariableSanity(_jspFile, "bundle1");
}
finally
{
@@ -137,113 +91,67 @@
}
}
}
-
+
/**
* Test the completion:
- *
+ *
* # { b u n d l e 1 . }
- * ^
+ * ^
*/
- @SuppressWarnings("unchecked")
- public void testCompletionAtCloseBrace()
+ public void testCompletionAtCloseBrace() throws Exception
{
- ContextWrapper wrapper = null;
+ final List<ICompletionProposal> proposals =
+ getProposals(_jspFile, 589, "bundle1.",9);
+ assertNotNull(proposals);
+ ICompletionProposal proposal = null;
- try
+ FIND_ARRAY_PROPOSAL:
+ for (final ICompletionProposal findProp : proposals)
{
- wrapper = getDocumentContext("/WebContent/bug_149224.jsp", 589);
- final IStructuredDocumentContext context = wrapper.getContext();
- ITextRegionContextResolver resolver =
- IStructuredDocumentContextResolverFactory.INSTANCE.getTextRegionResolver(context);
- final ContentAssistStrategy strategy =
- ContentAssistParser.getPrefix(9, "bundle1.");
-
- assertNotNull(strategy);
- List proposals = strategy.getProposals(context);
-
- ICompletionProposal proposal = null;
-
- FIND_ARRAY_PROPOSAL:
- for (final Iterator it = proposals.iterator(); it.hasNext();)
+ // TODO: this is a bit of a hack. Would rather be able
+ // to query for the actual replacement text
+ if (findProp.getDisplayString().startsWith("['"))
{
- proposal = (ICompletionProposal) it.next();
- // TODO: this is a bit of a hack. Would rather be able
- // to query for the actual replacement text
- if (proposal.getDisplayString().startsWith("['"))
- {
- break FIND_ARRAY_PROPOSAL;
- }
- }
-
- assertNotNull(proposal);
-
- proposal.apply(wrapper.getContext().getStructuredDocument());
-
- String newELText = resolver.getRegionText();
- assertEquals("bundle1['prop.with.dots_x']", newELText);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- fail(e.getLocalizedMessage());
- }
- finally
- {
- if (wrapper != null)
- {
- wrapper.dispose();
+ proposal = findProp;
+ break FIND_ARRAY_PROPOSAL;
}
}
+
+ assertNotNull(proposal);
+
+ applyAndCheck(_jspFile, 589, proposal, "bundle1['prop.with.dots_x']");
}
/**
* Test the completion:
- *
+ *
* # { b u n d l e 1 . x }
- * ^
+ * ^
*/
- @SuppressWarnings("unchecked")
- public void testCompletionAtProperty()
+ public void testCompletionAtProperty() throws Exception
{
- ContextWrapper wrapper = null;
-
+ final ContextWrapper wrapper = null;
+
try
{
- wrapper = getDocumentContext("/WebContent/bug_149224.jsp", 630);
- final IStructuredDocumentContext context = wrapper.getContext();
- ITextRegionContextResolver resolver =
- IStructuredDocumentContextResolverFactory.INSTANCE.getTextRegionResolver(context);
- final ContentAssistStrategy strategy =
- ContentAssistParser.getPrefix(9, "bundle1.x");
-
- assertNotNull(strategy);
- List proposals = strategy.getProposals(context);
-
+ final List<ICompletionProposal> proposals =
+ getProposals(_jspFile, 630, 9);
+
ICompletionProposal proposal = null;
-
- FIND_ARRAY_PROPOSAL:
- for (final Iterator it = proposals.iterator(); it.hasNext();)
- {
- proposal = (ICompletionProposal) it.next();
- // TODO: this is a bit of a hack. Would rather be able
- // to query for the actual replacement text
- if (proposal.getDisplayString().startsWith("['"))
- {
- break FIND_ARRAY_PROPOSAL;
- }
- }
+
+ FIND_ARRAY_PROPOSAL:
+ for (final ICompletionProposal completionProposal : proposals) {
+ proposal = completionProposal;
+ // TODO: this is a bit of a hack. Would rather be able
+ // to query for the actual replacement text
+ if (proposal.getDisplayString().startsWith("['"))
+ {
+ break FIND_ARRAY_PROPOSAL;
+ }
+ }
assertNotNull(proposal);
-
- proposal.apply(wrapper.getContext().getStructuredDocument());
-
- String newELText = resolver.getRegionText();
- assertEquals("bundle1['prop.with.dots_x']x", newELText);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- fail(e.getLocalizedMessage());
+ applyAndCheck(_jspFile, 630, proposal, "bundle1['prop.with.dots_x']x");
}
finally
{
@@ -253,47 +161,4 @@
}
}
}
-
-
- private ContextWrapper getDocumentContext(String path, int offset) throws Exception
- {
- IProject project = _testEnv.getTestProject();
- IFile jspFile = project.getFile(new Path(path));
- assertTrue(jspFile.exists());
-
- final IModelManager modelManager =
- StructuredModelManager.getModelManager();
-
- IStructuredModel model = null;
-
- model = modelManager.getModelForRead(jspFile);
- assertTrue(model instanceof DOMModelForJSP);
- final IStructuredDocumentContext context =
- IStructuredDocumentContextFactory.INSTANCE.
- getContext(model.getStructuredDocument(), offset);
- return new ContextWrapper(context, model);
- }
-
-
- private static class ContextWrapper
- {
- private final IStructuredDocumentContext _context;
- private final IStructuredModel _model;
-
- ContextWrapper(final IStructuredDocumentContext context, final IStructuredModel model) {
- super();
- _context = context;
- _model = model;
- }
- IStructuredDocumentContext getContext() {
- return _context;
- }
- IStructuredModel getModel() {
- return _model;
- }
- void dispose()
- {
- _model.releaseFromRead();
- }
- }
}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/Test_bug_149743.java b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/Test_bug_149743.java
index 787a7f0..40e145c 100644
--- a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/Test_bug_149743.java
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/src/org/eclipse/jst/jsf/contentassist/tests/Test_bug_149743.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Cameron Bateman/Oracle - initial API and implementation
- *
+ *
********************************************************************************/
package org.eclipse.jst.jsf.contentassist.tests;
@@ -15,69 +15,53 @@
import java.util.List;
import java.util.Set;
-import junit.framework.TestCase;
-
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jst.jsf.context.resolver.structureddocument.IDOMContextResolver;
-import org.eclipse.jst.jsf.context.resolver.structureddocument.IStructuredDocumentContextResolverFactory;
-import org.eclipse.jst.jsf.context.resolver.structureddocument.internal.ITextRegionContextResolver;
-import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContext;
-import org.eclipse.jst.jsf.context.structureddocument.IStructuredDocumentContextFactory;
import org.eclipse.jst.jsf.core.IJSFCoreConstants;
-import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistParser;
-import org.eclipse.jst.jsf.core.internal.contentassist.el.ContentAssistStrategy;
import org.eclipse.jst.jsf.core.tests.util.JSFFacetedTestEnvironment;
import org.eclipse.jst.jsf.test.util.JDTTestEnvironment;
import org.eclipse.jst.jsf.test.util.JSFTestUtil;
import org.eclipse.jst.jsf.test.util.TestFileResource;
import org.eclipse.jst.jsf.test.util.WebProjectTestEnvironment;
-import org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Node;
/**
- * Test a situation where no expected return type information is
+ * Test a situation where no expected return type information is
* available for a tag.
- *
+ *
* @author cbateman
*
*/
-public class Test_bug_149743 extends TestCase
+public class Test_bug_149743 extends BaseTestClass
{
private WebProjectTestEnvironment _testEnv;
-
- protected void setUp() throws Exception
+ private IFile _jspFile;
+
+ @Override
+ protected void setUp() throws Exception
{
super.setUp();
JSFTestUtil.setValidationEnabled(false);
-
+
_testEnv = new WebProjectTestEnvironment("Test_bug_149743_"+getName());
_testEnv.createProject(false);
- assertNotNull(_testEnv);
+ assertNotNull(_testEnv);
assertNotNull(_testEnv.getTestProject());
assertTrue(_testEnv.getTestProject().isAccessible());
-
- JSFFacetedTestEnvironment jsfFacedEnv = new JSFFacetedTestEnvironment(_testEnv);
+
+ final JSFFacetedTestEnvironment jsfFacedEnv = new JSFFacetedTestEnvironment(_testEnv);
jsfFacedEnv.initialize(IJSFCoreConstants.FACET_VERSION_1_1);
-
+
_testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
- "/testdata/faces-config_bug149743.xml.data",
+ "/testdata/faces-config_bug149743.xml.data",
"/WEB-INF/faces-config.xml");
- _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
+ _jspFile = (IFile) _testEnv.loadResourceInWebRoot(ContentAssistTestsPlugin.getDefault().getBundle(),
"/testdata/bug_149743.jsp.data",
"/bug_149743.jsp");
-
+
final JDTTestEnvironment jdtTestEnv = new JDTTestEnvironment(_testEnv);
- TestFileResource resource = new TestFileResource();
- resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
+ final TestFileResource resource = new TestFileResource();
+ resource.load(ContentAssistTestsPlugin.getDefault().getBundle(),
"/testdata/MyBean.java.data");
jdtTestEnv.addSourceFile("src", "beans", "MyBean", resource.toString());
}
@@ -87,110 +71,29 @@
*/
public void testSanity() throws Exception
{
- ContextWrapper wrapper = null;
-
- try
- {
- wrapper = getDocumentContext();
- final IStructuredDocumentContext context = wrapper.getContext();
- final IDOMContextResolver resolver =
- IStructuredDocumentContextResolverFactory.INSTANCE.
- getDOMContextResolver(context);
- Node node = resolver.getNode();
- JSFTestUtil.getIndexedRegion((IStructuredDocument) context.getStructuredDocument(), context.getDocumentPosition());
- assertTrue(node instanceof Attr);
- assertEquals("value", ((Attr)node).getNodeName());
- assertEquals("#{myBean.property}", ((Attr)node).getNodeValue());
- }
- finally
- {
- if (wrapper != null)
- {
- wrapper.dispose();
- }
- }
+ assertELSanity(_jspFile, 529, "value" ,"#{myBean.property}");
+ assertELVariableSanity(_jspFile, "myBean");
}
-
+
/**
* Checks the scenario for Test_bug_149743
*/
public void testCompletionProposalsForId() throws Exception
{
- ContextWrapper wrapper = null;
-
- try
+ final List<ICompletionProposal> proposals =
+ getProposals(_jspFile, 529, 8);
+ assertEquals(2, proposals.size());
+ final Set<String> names = new HashSet<String>();
+
+ for (final ICompletionProposal proposal : proposals)
{
- wrapper = getDocumentContext();
- ITextRegionContextResolver resolver =
- IStructuredDocumentContextResolverFactory.INSTANCE.
- getTextRegionResolver(wrapper.getContext());
-
- final String elText = resolver.getRegionText().trim();
- assertNotNull(elText);
-
- final ContentAssistStrategy strategy =
- ContentAssistParser.getPrefix
- (wrapper.getContext().getDocumentPosition()
- - resolver.getStartOffset() + 1, elText);
-
- List<?> proposals = strategy.getProposals(wrapper.getContext());
- assertEquals(2, proposals.size());
- Set<String> names = new HashSet<String>();
-
- for (int i = 0; i < proposals.size(); i++)
- {
- names.add(((ICompletionProposal)proposals.get(i)).getDisplayString());
- }
- assertTrue(names.contains("class"));
- assertTrue(names.contains("property"));
+ names.add(proposal.getDisplayString());
}
- finally
- {
- if (wrapper != null)
- {
- wrapper.dispose();
- }
- }
- }
-
- private ContextWrapper getDocumentContext() throws Exception
- {
- IProject project = _testEnv.getTestProject();
- IFile jspFile = project.getFile(new Path("/WebContent/bug_149743.jsp"));
- assertTrue(jspFile.exists());
-
- final IModelManager modelManager =
- StructuredModelManager.getModelManager();
-
- IStructuredModel model = null;
-
- model = modelManager.getModelForRead(jspFile);
- assertTrue(model instanceof DOMModelForJSP);
- final IStructuredDocumentContext context =
- IStructuredDocumentContextFactory.INSTANCE.
- getContext(model.getStructuredDocument(), 529);
- return new ContextWrapper(context, model);
+ assertTrue(names.contains("class"));
+ assertTrue(names.contains("property"));
}
- private static class ContextWrapper
- {
- private final IStructuredDocumentContext _context;
- private final IStructuredModel _model;
-
- ContextWrapper(final IStructuredDocumentContext context, final IStructuredModel model) {
- super();
- _context = context;
- _model = model;
- }
- IStructuredDocumentContext getContext() {
- return _context;
- }
- IStructuredModel getModel() {
- return _model;
- }
- void dispose()
- {
- _model.releaseFromRead();
- }
- }
+
+
+
}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/MyBean.java.data b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/MyBean.java.data
index e683924..7de1772 100644
--- a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/MyBean.java.data
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/MyBean.java.data
@@ -5,4 +5,9 @@
{
return new String[]{"blah"};
}
-}
\ No newline at end of file
+
+ public String actionMethod()
+ {
+ return "foo";
+ }
+}
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/basicELExpressions.jsp.data b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/basicELExpressions.jsp.data
new file mode 100644
index 0000000..aba8370
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/basicELExpressions.jsp.data
@@ -0,0 +1,28 @@
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+
+<%@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">
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>JSP Page</title>
+ </head>
+ <body>
+ <f:view>
+ <h1>JSP Page</h1>
+ <!-- no errors -->
+ <h:outputText value="#{}"/>
+ <h:outputText value="#{ }"/>
+ <h:outputText value="#{myBean}"/>
+ <h:outputText value="#{myBean.property}"/>
+ <h:outputText value="#{paramValues.foo}"/>
+ <h:commandButton action="#{myBean.actionMethod}"/>
+ </f:view>
+ </body>
+</html>
diff --git a/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/faces-config_basic.xml.data b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/faces-config_basic.xml.data
new file mode 100644
index 0000000..e4a475b
--- /dev/null
+++ b/jsf/tests/org.eclipse.jst.jsf.contentassist.tests/testdata/faces-config_basic.xml.data
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE faces-config PUBLIC
+ "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
+ "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
+
+<faces-config>
+ <managed-bean>
+ <managed-bean-name>
+ myBean</managed-bean-name>
+ <managed-bean-class>
+ beans.MyBean</managed-bean-class>
+ <managed-bean-scope>
+ none</managed-bean-scope>
+ </managed-bean>
+
+</faces-config>