Author: vrubezhny
Date: 2010-09-14 10:35:41 -0400 (Tue, 14 Sep 2010)
New Revision: 24912
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/TestUtil.java
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/ContentAssistantTestCase.java
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JsfJspJbide1704Test.java
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JsfJspJbide1717Test.java
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1585Test.java
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1641Test.java
Log:
JBIDE-6827: JUnit Content Assist tests don't work with WTP 3.2.0
The CA initialization is fixed
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/TestUtil.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/TestUtil.java 2010-09-14
11:25:25 UTC (rev 24911)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/TestUtil.java 2010-09-14
14:35:41 UTC (rev 24912)
@@ -2,19 +2,24 @@
import java.lang.reflect.Method;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistantExtension;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.wst.sse.ui.internal.contentassist.StructuredContentAssistant;
public class TestUtil {
+ /** The Constant MAX_IDLE. */
+ public static final long MAX_IDLE = 15*1000L;
/**
* Returns the CA Processor from content assistant for the given offset in the
document.
@@ -64,6 +69,18 @@
}
}
}
+
+ /**
+ * Wait for idle.
+ */
+ public static void waitForIdle(long maxIdle) {
+ long start = System.currentTimeMillis();
+ while (!Job.getJobManager().isIdle()) {
+ delay(500);
+ if ( (System.currentTimeMillis()-start) > maxIdle )
+ throw new RuntimeException("A long running task detected"); //$NON-NLS-1$
+ }
+ }
public static SourceViewerConfiguration getSourceViewerConfiguration(AbstractTextEditor
editor) {
Class editorClass = editor.getClass();
@@ -85,4 +102,16 @@
}
+ public static void prepareCAInvokation(IContentAssistant ca, ITextViewer viewer, int
offset) {
+ if (ca == null || viewer == null)
+ return;
+
+ // sets cursor position
+ viewer.getTextWidget().setCaretOffset(offset);
+
+ TestUtil.waitForIdle(TestUtil.MAX_IDLE);
+ TestUtil.delay(1000);
+
+ ca.showPossibleCompletions();
+ }
}
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/ContentAssistantTestCase.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/ContentAssistantTestCase.java 2010-09-14
11:25:25 UTC (rev 24911)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/ContentAssistantTestCase.java 2010-09-14
14:35:41 UTC (rev 24912)
@@ -4,6 +4,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
@@ -12,6 +13,7 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
+import org.eclipse.wst.sse.ui.internal.contentassist.StructuredContentAssistant;
import org.jboss.tools.common.text.ext.util.Utils;
import org.jboss.tools.jst.jsp.contentassist.AutoContentAssistantProposal;
import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
@@ -73,18 +75,20 @@
ICompletionProposal[] result = null;
// System.out.println("checkProposals >>> invoking TestUtil.getProcessor()
for position " + (position + offset));
+
IContentAssistProcessor p = TestUtil.getProcessor(viewer, position + offset,
contentAssistant);
-// System.out.println("checkProposals >>> TestUtil.getProcessor() is
invoked for " + (position + offset));
+ TestUtil.prepareCAInvokation(contentAssistant, viewer, position+offset);
+ // System.out.println("checkProposals >>> TestUtil.getProcessor() is
invoked for " + (position + offset));
if (p != null) {
try {
-// System.out.println("checkProposals >>> invoking
p.computeCompletionProposals() for position " + (position + offset));
+ // System.out.println("checkProposals >>> invoking
p.computeCompletionProposals() for position " + (position + offset));
result = p.computeCompletionProposals(viewer, position + offset);
-// System.out.println("checkProposals >>>
p.computeCompletionProposals() is invoked for " + (position + offset));
+ // System.out.println("checkProposals >>>
p.computeCompletionProposals() is invoked for " + (position + offset));
} catch (Throwable x) {
x.printStackTrace();
}
}
-// System.out.println("checkProposals >>> Performing the values check
up");
+ // System.out.println("checkProposals >>> Performing the values check
up");
assertTrue("Content Assistant returned no proposals", (result != null
&& result.length > 0));
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JsfJspJbide1704Test.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JsfJspJbide1704Test.java 2010-09-14
11:25:25 UTC (rev 24911)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JsfJspJbide1704Test.java 2010-09-14
14:35:41 UTC (rev 24912)
@@ -6,6 +6,7 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.jboss.tools.jst.jsp.contentassist.AutoContentAssistantProposal;
@@ -57,6 +58,8 @@
" var=\"msg\"", true, true, false, false);
String errorMessage = null;
+ TestUtil.prepareCAInvokation(contentAssistant, viewer, reg.getOffset());
+
final IContentAssistProcessor p= TestUtil.getProcessor(viewer, reg.getOffset(),
contentAssistant);
if (p != null) {
result= p.computeCompletionProposals(viewer, reg.getOffset());
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JsfJspJbide1717Test.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JsfJspJbide1717Test.java 2010-09-14
11:25:25 UTC (rev 24911)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JsfJspJbide1717Test.java 2010-09-14
14:35:41 UTC (rev 24912)
@@ -60,6 +60,7 @@
ICompletionProposal[] result= null;
String errorMessage = null;
+ TestUtil.prepareCAInvokation(contentAssistant, viewer, offsetToTest);
IContentAssistProcessor p= TestUtil.getProcessor(viewer, offsetToTest,
contentAssistant);
if (p != null) {
try {
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1585Test.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1585Test.java 2010-09-14
11:25:25 UTC (rev 24911)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1585Test.java 2010-09-14
14:35:41 UTC (rev 24912)
@@ -3,6 +3,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.jboss.tools.jst.jsp.contentassist.AutoContentAssistantProposal;
@@ -51,17 +52,26 @@
jspTextEditor.setText(documentContentModified);
+ // sets cursor position
+ viewer.getTextWidget().setCaretOffset(offsetToTest);
+
+ TestUtil.waitForIdle(TestUtil.MAX_IDLE);
+ TestUtil.delay(1000);
+
ICompletionProposal[] result= null;
String errorMessage = null;
- IContentAssistProcessor p= TestUtil.getProcessor(viewer, offsetToTest,
contentAssistant);
- if (p != null) {
- try {
- result= p.computeCompletionProposals(viewer, offsetToTest);
- } catch (Throwable x) {
- x.printStackTrace();
+ if (contentAssistant instanceof ContentAssistant) {
+ TestUtil.prepareCAInvokation(contentAssistant, viewer, offsetToTest);
+ IContentAssistProcessor p= TestUtil.getProcessor(viewer, offsetToTest,
contentAssistant);
+ if (p != null) {
+ try {
+ result= p.computeCompletionProposals(viewer, offsetToTest);
+ } catch (Throwable x) {
+ x.printStackTrace();
+ }
+ errorMessage= p.getErrorMessage();
}
- errorMessage= p.getErrorMessage();
}
assertTrue("Content Assistant returned no proposals", (result != null
&& result.length > 0));
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1641Test.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1641Test.java 2010-09-14
11:25:25 UTC (rev 24911)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1641Test.java 2010-09-14
14:35:41 UTC (rev 24912)
@@ -3,6 +3,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.jboss.tools.jst.jsp.contentassist.AutoContentAssistantProposal;
@@ -61,6 +62,8 @@
ICompletionProposal[] result= null;
String errorMessage = null;
+ TestUtil.prepareCAInvokation(contentAssistant, viewer, offsetToTest);
+
IContentAssistProcessor p= TestUtil.getProcessor(viewer, offsetToTest,
contentAssistant);
if (p != null) {
try {