[jbosstools-commits] JBoss Tools SVN: r43412 - trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Sep 5 09:01:30 EDT 2012


Author: vrubezhny
Date: 2012-09-05 09:01:29 -0400 (Wed, 05 Sep 2012)
New Revision: 43412

Modified:
   trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForJSF2BeanMapValuesTest.java
Log:
JBIDE-12441 
Wrong cursor position after using code assist for EL with '[]' 

JUnit Test Case is added

Modified: trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForJSF2BeanMapValuesTest.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForJSF2BeanMapValuesTest.java	2012-09-05 12:31:36 UTC (rev 43411)
+++ trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAForJSF2BeanMapValuesTest.java	2012-09-05 13:01:29 UTC (rev 43412)
@@ -1,6 +1,14 @@
 package org.jboss.tools.jsf.jsp.ca.test;
 
+import java.util.List;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.graphics.Point;
+import org.jboss.tools.common.base.test.contentassist.CATestUtil;
+import org.jboss.tools.jst.jsp.contentassist.AutoContentAssistantProposal;
 import org.jboss.tools.jst.jsp.test.ca.ContentAssistantTestCase;
+import org.jboss.tools.test.util.JobUtils;
 import org.jboss.tools.test.util.TestProjectProvider;
 
 public class CAForJSF2BeanMapValuesTest  extends ContentAssistantTestCase {
@@ -8,7 +16,13 @@
 	boolean makeCopy = true;
 	private static final String PROJECT_NAME = "JSF2Beans";
 	private static final String PAGE_NAME = "/src/test/beans/inputname.xhtml";
+	private static final String EL_TO_FIND = "#{myBean.myMap['100'].si";
+	private static final String PROPOSAL_TO_TEST = "myBean.myMap['100'].size()";
+	private static final String PROPOSAL_TO_APPLY = "size()";
+	
+	private static final String CURSOR_SIGNATURE = "<The cursor point>";
 
+
 	public void setUp() throws Exception {
 		provider = new TestProjectProvider("org.jboss.tools.jsf.base.test",
 				null, PROJECT_NAME, makeCopy);
@@ -26,9 +40,106 @@
 	 */
 	public void testForJSF2BeanMapValues() {
 		
-		String[] proposals = { "myBean.myMap['100'].size()" };
+		String[] proposals = { PROPOSAL_TO_TEST };
 
-		checkProposals(PAGE_NAME, "#{myBean.myMap['100'].si", 24, proposals, false);
+		checkProposals(PAGE_NAME, EL_TO_FIND, 24, proposals, false);
 	}
 
+	/**
+	 * JBIDE-12441
+	 */
+	public void testCursorPositionAfterApplyMethodProposalOnELWithSquareBrackets() {
+
+		openEditor(PAGE_NAME);
+		try {
+
+			assertNotNull("Text Viewer not found", getViewer());
+			IDocument document = getViewer().getDocument();
+			assertNotNull("Can't obtain a test Document.", document);
+
+			String documentContent = document.get();
+			int start = (documentContent == null ? -1 : documentContent
+					.indexOf(EL_TO_FIND));
+			assertFalse("Required text '" + EL_TO_FIND
+					+ "' not found in document", (start == -1));
+
+			int end = (documentContent == null ? -1 : documentContent
+					.indexOf('}', start));
+			assertFalse("Required text '}' not found in document", (end == -1));
+
+			int offsetToTest = start + EL_TO_FIND.length();
+
+			List<ICompletionProposal> res = CATestUtil.collectProposals(
+					getContentAssistant(), getViewer(), offsetToTest);
+
+			assertTrue("Content Assistant returned no proposals",
+					(res != null && res.size() > 0));
+
+			boolean bPropoosalToApplyFound = false;
+			for (ICompletionProposal p : res) {
+				if (!(p instanceof AutoContentAssistantProposal))
+					continue;
+				AutoContentAssistantProposal proposal = (AutoContentAssistantProposal) p;
+				String proposalString = proposal.getDisplayString();
+
+				if (proposalString.startsWith(PROPOSAL_TO_APPLY)) {
+					bPropoosalToApplyFound = true;
+					proposal.apply(document);
+
+					// The following is copied from CompletionProposalPopup
+					// class that actually applies the proposal.
+					// Node that fContentAssistSubjectControlAdapter object
+					// is replaced by the Viewer object (which is equivalent
+					// in many cases).
+					// So, after the proposal is applied a new selection is
+					// set in the Editor:
+					Point selection = p.getSelection(document);
+					if (selection != null) {
+						getViewer().setSelectedRange(selection.x,
+								selection.y);
+						getViewer().revealRange(selection.x, selection.y);
+					}
+					// End of code from CompletionProposalPopup
+
+					break;
+				}
+			}
+			assertTrue("The proposal to apply not found.",
+					bPropoosalToApplyFound);
+
+			try {
+				JobUtils.waitForIdle();
+			} catch (Exception e) {
+				e.printStackTrace();
+				assertTrue("Waiting for the jobs to complete has failed.",
+						false);
+			}
+
+			Point s = getViewer().getSelectedRange();
+			assertNotNull("Selection can't be obtained from the editor!", s);
+
+			String documentUpdatedContent = document.get();
+			String testUpdatedContent = documentUpdatedContent.substring(0,
+					s.x)
+					+ CURSOR_SIGNATURE
+					+ documentUpdatedContent.substring(s.x);
+			String testString = EL_TO_FIND.substring(0,
+					EL_TO_FIND.lastIndexOf('.') + 1)
+					+ PROPOSAL_TO_APPLY
+					+ CURSOR_SIGNATURE;
+			
+//			System.out.println("testString: [" + testString + "]");
+//			System.out.println("testUpdatedContent: [" + testUpdatedContent.substring(start,
+//					s.x + CURSOR_SIGNATURE.length()) + "]");
+			
+			assertTrue(
+					"The proposal replacement is failed.",
+					testUpdatedContent.substring(start,
+							s.x + CURSOR_SIGNATURE.length()).equals(
+							testString));
+		} finally {
+			closeEditor();
+		}
+	}
+
 }



More information about the jbosstools-commits mailing list