Author: vrubezhny
Date: 2008-02-11 14:37:10 -0500 (Mon, 11 Feb 2008)
New Revision: 6248
Added:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1759Test.java
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/JstJspAllTests.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-1766 Create a JUnit TestCase for JBIDE-1759
Modified:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/JstJspAllTests.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/JstJspAllTests.java 2008-02-11
17:54:28 UTC (rev 6247)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/JstJspAllTests.java 2008-02-11
19:37:10 UTC (rev 6248)
@@ -4,6 +4,7 @@
import org.jboss.tools.jst.jsp.test.ca.JsfJspJbide1717Test;
import org.jboss.tools.jst.jsp.test.ca.JstJspJbide1585Test;
import org.jboss.tools.jst.jsp.test.ca.JstJspJbide1641Test;
+import org.jboss.tools.jst.jsp.test.ca.JstJspJbide1759Test;
import org.jboss.tools.jst.jsp.test.ca.StrutsJspJbide1648Test;
import junit.framework.Test;
@@ -13,11 +14,13 @@
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.jboss.tools.jst.jsp.test");
- suite.addTestSuite(JstJspJbide1585Test.class);
+
+ suite.addTestSuite(JstJspJbide1585Test.class);
suite.addTestSuite(StrutsJspJbide1648Test.class);
suite.addTestSuite(JstJspJbide1641Test.class);
suite.addTestSuite(JsfJspJbide1704Test.class);
suite.addTestSuite(JsfJspJbide1717Test.class);
+ suite.addTestSuite(JstJspJbide1759Test.class);
return suite;
}
Added:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1759Test.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1759Test.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1759Test.java 2008-02-11
19:37:10 UTC (rev 6248)
@@ -0,0 +1,208 @@
+package org.jboss.tools.jst.jsp.test.ca;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
+import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
+import org.jboss.tools.common.test.util.TestProjectProvider;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
+import org.jboss.tools.jst.jsp.test.TestUtil;
+import org.jboss.tools.test.util.xpl.EditorTestHelper;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class JstJspJbide1759Test extends TestCase {
+ TestProjectProvider provider = null;
+ IProject project = null;
+ boolean makeCopy = false;
+ private static final String PROJECT_NAME = "JsfJbide1704Test";
+ private static final String PAGE_NAME = "/WebContent/pages/greeting.jsp";
+ private static final String INSERT_BEFORE_STRING = "<h:outputText";
+ private static final String INSERTION_BEGIN_STRING = "<h:outputText
value=\"";
+ private static final String INSERTION_END_STRING = "\" />";
+ private static final String WHITESPACE_INSERTION_STRING = "";
+
+ public static Test suite() {
+ return new TestSuite(JstJspJbide1759Test.class);
+ }
+
+ public void setUp() throws Exception {
+ provider = new TestProjectProvider("org.jboss.tools.jst.jsp.test", null,
PROJECT_NAME, makeCopy);
+ project = provider.getProject();
+ Throwable exception = null;
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (Exception x) {
+ exception = x;
+ x.printStackTrace();
+ }
+ assertNull("An exception caught: " + (exception != null?
exception.getMessage() : ""), exception);
+ }
+
+ protected void tearDown() throws Exception {
+ if(provider != null) {
+ provider.dispose();
+ }
+ }
+
+ public void testJstJspJbide1641() {
+ try {
+ EditorTestHelper.joinBackgroundActivities();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertTrue("Test project \"" + PROJECT_NAME + "\" is not
loaded", (project != null));
+
+ IFile jspFile = project.getFile(PAGE_NAME);
+
+ assertTrue("The file \"" + PAGE_NAME + "\" is not found",
(jspFile != null));
+ assertTrue("The file \"" + PAGE_NAME + "\" is not found",
(jspFile.exists()));
+
+ FileEditorInput editorInput = new FileEditorInput(jspFile);
+ Throwable exception = null;
+ IEditorPart editorPart = null;
+ try {
+ editorPart =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput,
"org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor");
+ } catch (PartInitException ex) {
+ exception = ex;
+ ex.printStackTrace();
+ assertTrue("The JSP Visual Editor couldn't be initialized.", false);
+ }
+
+ JSPMultiPageEditor jspEditor = null;
+
+ if (editorPart instanceof JSPMultiPageEditor)
+ jspEditor = (JSPMultiPageEditor)editorPart;
+
+ // Delay for 3 seconds so that
+ // the Favorites view can be seen.
+ try {
+ EditorTestHelper.joinBackgroundActivities();
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue("Waiting for the jobs to complete has failed.", false);
+ }
+ TestUtil.delay(3000);
+
+ JSPTextEditor jspTextEditor = jspEditor.getJspEditor();
+ StructuredTextViewer viewer = jspTextEditor.getTextViewer();
+ IDocument document = viewer.getDocument();
+ SourceViewerConfiguration config =
TestUtil.getSourceViewerConfiguration(jspTextEditor);
+ IContentAssistant contentAssistant = (config == null ? null :
config.getContentAssistant(viewer));
+
+ assertTrue("Cannot get the Content Assistant instance for the editor for page
\"" + PAGE_NAME + "\"", (contentAssistant != null));
+
+ // Find start of <h:outputText> tag
+ String documentContent = document.get();
+ int start = (documentContent == null ? -1 :
documentContent.indexOf(INSERT_BEFORE_STRING));
+
+ assertTrue("Cannot find the starting point in the test file \"" +
PAGE_NAME + "\"", (start != -1));
+
+ // First of all perform the test on a region placed in one space behind empty-valued
attribute -
+ // this is to return normal list of attribute names proposal list
+
+ String documentContentModified = documentContent.substring(0, start) +
+ INSERTION_BEGIN_STRING + WHITESPACE_INSERTION_STRING + INSERTION_END_STRING +
documentContent.substring(start);
+
+ int offsetToTest = start + INSERTION_BEGIN_STRING.length();
+
+// String visualizeCursorPosition = documentContentModified.substring(0, offsetToTest)
+
+// "|" + documentContentModified.substring(offsetToTest);
+
+// System.out.println(visualizeCursorPosition);
+
+ jspTextEditor.setText(documentContentModified);
+
+ 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();
+ }
+ errorMessage= p.getErrorMessage();
+ }
+
+// if (errorMessage != null && errorMessage.trim().length() > 0) {
+// System.out.println("#" + offsetToTest + ": ERROR MESSAGE: " +
errorMessage);
+// }
+
+ List<String> customCompletionProposals = new ArrayList<String>();
+ for (int i = 0; i < result.length; i++) {
+ // There should be at least one proposal of type CustomCompletionProposal in the
result
+ if (result[i] instanceof CustomCompletionProposal) {
+ customCompletionProposals.add(((CustomCompletionProposal)result[i]).getReplacementString());
+ }
+ }
+ assertFalse("Content Assistant returned no proposals of type
CustomCompletionProposal.",customCompletionProposals.isEmpty());
+
+ try {
+ EditorTestHelper.joinBackgroundActivities();
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue("Waiting for the jobs to complete has failed.", false);
+ }
+
+ // Next perform the test on a region placed in one space behind an attribute those
value is a container
+ // (contains JSF expression) - this has to return the same normal list of attribute
names proposal list as
+ // we got at the first step (because the tag is the same, but only the attribute value
is changed)
+
+ documentContentModified = documentContent.substring(0, start) +
+ INSERTION_BEGIN_STRING + INSERTION_END_STRING + documentContent.substring(start);
+
+ offsetToTest = start + INSERTION_BEGIN_STRING.length();
+
+// visualizeCursorPosition = documentContentModified.substring(0, offsetToTest) +
+// "|" + documentContentModified.substring(offsetToTest);
+
+// System.out.println(visualizeCursorPosition);
+
+ jspTextEditor.setText(documentContentModified);
+
+ p= TestUtil.getProcessor(viewer, offsetToTest, contentAssistant);
+ if (p != null) {
+ try {
+ result= p.computeCompletionProposals(viewer, offsetToTest);
+ } catch (Throwable x) {
+ x.printStackTrace();
+ }
+ errorMessage= p.getErrorMessage();
+ }
+
+// if (errorMessage != null && errorMessage.trim().length() > 0) {
+// System.out.println("#" + offsetToTest + ": ERROR MESSAGE: " +
errorMessage);
+// }
+
+ for (int i = 0; i < result.length; i++) {
+ // There should be the same proposals as in the saved result
+ if (result[i] instanceof CustomCompletionProposal) {
+ assertTrue("Content Assistant returned additional proposal (proposal returned
doesn't exist in the saved list).",
+ customCompletionProposals.contains(((CustomCompletionProposal)result[i]).getReplacementString()));
+ customCompletionProposals.remove(((CustomCompletionProposal)result[i]).getReplacementString());
+ }
+ }
+ assertTrue("Content Assistant didn't returned some
proposals.",customCompletionProposals.isEmpty());
+
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .closeEditor(editorPart, false);
+ }
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.jsp.test/src/org/jboss/tools/jst/jsp/test/ca/JstJspJbide1759Test.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain