Author: vrubezhny
Date: 2012-04-18 06:14:04 -0400 (Wed, 18 Apr 2012)
New Revision: 40275
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELApplyMethodProposalTest.java
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java
Log:
JBIDE-11492
When inserting methods with parameters, CA sets cursor incorrectly
JUnit Test is added
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELApplyMethodProposalTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELApplyMethodProposalTest.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELApplyMethodProposalTest.java 2012-04-18
10:14:04 UTC (rev 40275)
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.jsp.ca.test;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.NullProgressMonitor;
+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.ProjectImportTestSetup;
+
+/**
+ * @author Victor V. Rubezhny
+ */
+public class CAELApplyMethodProposalTest extends ContentAssistantTestCase {
+ private static final String PROJECT_NAME = "JSF2KickStartWithoutLibs";
+ private static final String PAGE_NAME = "WebContent/pages/inputname.xhtml";
+ private static final String EL_RBRACE = "}";
+
+ private static final String[] EL_TO_FIND = { "#{user.name",
"#{user.name" };
+ private static final String[] EL_TO_REPLACE_WITH = {
+ "#{user.name.substring(1).substr", "#{user.name.substring(1).by"
};
+ private static final String[] PROPOSALS_TO_APPLY = { "substring(",
"bytes" };
+ private static final String CURSOR_SIGNATURE = "<The cursor point>";
+
+ public void setUp() throws Exception {
+ project = ProjectImportTestSetup.loadProject(PROJECT_NAME);
+ project.build(IncrementalProjectBuilder.FULL_BUILD,
+ new NullProgressMonitor());
+ }
+
+ /*
+ * The test case for JBIDE-11492
+ */
+ public void testELApplyMethodProposal() {
+
+ openEditor(PAGE_NAME);
+ try {
+
+ assertNotNull("Text Viewer not found", getViewer());
+ IDocument document = getViewer().getDocument();
+ assertNotNull("Can't obtain a test Document.", document);
+
+ for (int i = 0; i < EL_TO_FIND.length; i++) {
+ String elToFind = EL_TO_FIND[i];
+ String elToReplaceWith = EL_TO_REPLACE_WITH[i];
+ String proposalToApply = PROPOSALS_TO_APPLY[i];
+
+ String documentContent = document.get();
+ int start = (documentContent == null ? -1 : documentContent
+ .indexOf(elToFind));
+ assertFalse("Required text '" + elToFind
+ + "' not found in document", (start == -1));
+
+ int end = (documentContent == null ? -1 : documentContent
+ .indexOf(EL_RBRACE, start));
+ assertFalse("Required text '" + EL_RBRACE
+ + "' not found in document", (end == -1));
+
+ String documentContentModified = documentContent.substring(0,
+ start)
+ + elToReplaceWith
+ + documentContent.substring(end);
+
+ int offsetToTest = start + elToReplaceWith.length();
+
+ jspTextEditor.setText(documentContentModified);
+
+ JobUtils.waitForIdle();
+
+ 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(proposalToApply)) {
+ 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 = elToReplaceWith.substring(0,
+ elToReplaceWith.lastIndexOf('.') + 1)
+ + proposalToApply
+ + CURSOR_SIGNATURE;
+ assertTrue(
+ "The proposal replacement is failed.",
+ testUpdatedContent.substring(start,
+ s.x + CURSOR_SIGNATURE.length()).equals(
+ testString));
+ }
+ } finally {
+ closeEditor();
+ }
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/jsp/ca/test/CAELApplyMethodProposalTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java 2012-04-18
10:10:43 UTC (rev 40274)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java 2012-04-18
10:14:04 UTC (rev 40275)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Copyright (c) 2007-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
@@ -17,6 +17,7 @@
import org.eclipse.wst.validation.ValidationFramework;
import org.jboss.tools.common.base.test.validation.ValidationProjectTestSetup;
import org.jboss.tools.jsf.jsp.ca.test.CADefaultELStartingCharTest;
+import org.jboss.tools.jsf.jsp.ca.test.CAELApplyMethodProposalTest;
import org.jboss.tools.jsf.jsp.ca.test.CAELInsideTagBodyInJspFileTest;
import org.jboss.tools.jsf.jsp.ca.test.CAForCompositeComponentTest;
import org.jboss.tools.jsf.jsp.ca.test.CAForELJavaAndJSTCompareTest;
@@ -151,6 +152,11 @@
new String[] { "JSF2KickStartWithoutLibs" })); //$NON-NLS-1$
suite.addTest(new ProjectImportTestSetup(new TestSuite(
+ CAELApplyMethodProposalTest.class), "org.jboss.tools.jsf.base.test",
//$NON-NLS-1$
+ new String[] { "projects/JSF2KickStartWithoutLibs", }, //$NON-NLS-1$
+ new String[] { "JSF2KickStartWithoutLibs" })); //$NON-NLS-1$
+
+ suite.addTest(new ProjectImportTestSetup(new TestSuite(
CAELInsideTagBodyInJspFileTest.class), "org.jboss.tools.jsf.ui.test",
//$NON-NLS-1$
new String[] { "projects/Jbide3845Test", }, //$NON-NLS-1$
new String[] { "Jbide3845Test" })); //$NON-NLS-1$