[jbosstools-commits] JBoss Tools SVN: r42063 - in trunk: cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java and 7 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Jun 18 14:49:24 EDT 2012


Author: vrubezhny
Date: 2012-06-18 14:49:23 -0400 (Mon, 18 Jun 2012)
New Revision: 42063

Added:
   trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/AbstractAsYouTypeValidationTest.java
   trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/src/org/jboss/tools/jst/jsp/test/validation/
   trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/src/org/jboss/tools/jst/jsp/test/validation/BaseAsYouTypeValidationTest.java
Modified:
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaValidationTest.java
   trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/java/BaseAsYouTypeInJavaValidationTest.java
   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/validation/JSFAsYouTypeValidationTest.java
   trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/META-INF/MANIFEST.MF
Log:
JBIDE-10738
As-you-type EL validation

JUnit tests are updated

Modified: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java	2012-06-18 17:26:56 UTC (rev 42062)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java	2012-06-18 18:49:23 UTC (rev 42063)
@@ -62,8 +62,13 @@
 		suite.addTestSuite(ELReferencesQueryParticipantTest.class);
 		suite.addTestSuite(CATest.class);
 		suite.addTestSuite(OpenCDINamedBeanDialogTest.class);
-		suite.addTestSuite(CDIAsYouTypeInJavaValidationTest.class);
 
+		/*
+		 * The following test is reserved for CDI As-You-Type Validation:
+		 * 
+		 * suite.addTestSuite(CDIAsYouTypeInJavaValidationTest.class); 
+		 */
+
 		suiteAll.addTest(new CDICoreTestSetup(suite));
 
 		suiteAll.addTestSuite(AddQualifiersToBeanWizardTest.class);

Modified: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaValidationTest.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaValidationTest.java	2012-06-18 17:26:56 UTC (rev 42062)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaValidationTest.java	2012-06-18 18:49:23 UTC (rev 42063)
@@ -1,25 +1,35 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
 package org.jboss.tools.cdi.ui.test.validation.java;
 
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.text.BadLocationException;
-import org.jboss.tools.cdi.core.ICDIProject;
 import org.jboss.tools.cdi.core.test.tck.TCKTest;
 import org.jboss.tools.common.base.test.validation.java.BaseAsYouTypeInJavaValidationTest;
 import org.jboss.tools.common.preferences.SeverityPreferences;
 import org.jboss.tools.jst.web.kb.WebKbPlugin;
 import org.jboss.tools.jst.web.kb.preferences.ELSeverityPreferences;
-import org.jboss.tools.test.util.ProjectImportTestSetup;
 
+/**
+ * 
+ * @author Victor V. Rubezhny
+ *
+ */
 public class CDIAsYouTypeInJavaValidationTest extends TCKTest {
 	private static final String PAGE_NAME = "JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/el/TestBean.java";
 
 	private BaseAsYouTypeInJavaValidationTest baseTest = null;
 	protected IProject project;
-
 	
 	private static final String [][] EL2VALIDATE = 
 		{ 
@@ -59,5 +69,4 @@
 		}
  */
 	}
-
 }

Added: trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/AbstractAsYouTypeValidationTest.java
===================================================================
--- trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/AbstractAsYouTypeValidationTest.java	                        (rev 0)
+++ trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/AbstractAsYouTypeValidationTest.java	2012-06-18 18:49:23 UTC (rev 42063)
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.base.test.validation;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.test.util.JobUtils;
+import org.jboss.tools.test.util.WorkbenchUtils;
+
+/**
+ * 
+ * @author Victor V. Rubezhny
+ *
+ */
+public abstract class AbstractAsYouTypeValidationTest extends TestCase {
+	private static final int MAX_SECONDS_TO_WAIT = 10;
+
+	protected String fileName;
+	protected IProject project = null;
+	protected IEditorPart editorPart = null;
+	protected ITextEditor textEditor = null;
+	protected ISourceViewer viewer = null;
+	protected IDocument document = null;
+	protected IFile file = null;
+	IAnnotationModel annotationModel = null;
+
+	public static final String EL2FIND_START = "#{";
+	public static final String EL2FIND_END = "}";
+
+	public AbstractAsYouTypeValidationTest(IProject project) {
+		this.project = project;
+	}
+	public AbstractAsYouTypeValidationTest() {
+	}
+	
+	public void openEditor(String fileName) {
+		this.fileName = fileName;
+		editorPart = WorkbenchUtils.openEditor(project.getName()
+				+ "/" + fileName); //$NON-NLS-1$
+		obtainEditor(editorPart);
+
+		annotationModel = getAnnotationModel();
+		assertNotNull("Cannot find an Annotation Model for the Java Editor",
+				annotationModel);
+
+		// clean deffered events
+		while (Display.getCurrent().readAndDispatch())
+			;
+
+		viewer = getTextViewer();
+		document = viewer.getDocument();
+	}
+
+	public void closeEditor() {
+		if (editorPart != null) {
+			PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+					.getActivePage().closeEditor(editorPart, false);
+			editorPart = null;
+			textEditor = null;
+			viewer = null;
+			document = null;
+		}
+	}
+
+	protected abstract void obtainEditor(IEditorPart editorPart);
+	
+	protected IAnnotationModel getAnnotationModel() {
+		final IDocumentProvider documentProvider = textEditor.getDocumentProvider();
+		if (documentProvider == null) {
+			return null;
+		}
+		return documentProvider.getAnnotationModel(textEditor.getEditorInput());
+	}
+
+	protected abstract ISourceViewer getTextViewer();
+
+	public void doAsYouTipeInJavaValidationTest(String elToValidate,
+			String errorMessage) throws JavaModelException, BadLocationException {
+		String documentContent = document.get();
+		int start = (documentContent == null ? -1 : documentContent
+				.indexOf(EL2FIND_START));
+		assertFalse("No EL found in Java Strings: Starting '" + EL2FIND_START
+				+ "' characters are not found in document", (start == -1));
+		int end = (documentContent == null ? -1 : documentContent.indexOf(
+				EL2FIND_END, start));
+		assertFalse("EL is not closed in Java Strings: Ending '"
+				+ EL2FIND_START + "' characters are not found in document",
+				(end == -1));
+
+		int length = end - start + EL2FIND_END.length();
+
+		document.replace(start, length, elToValidate);
+
+		end = start + elToValidate.length();
+
+		Annotation problemAnnotation = waitForProblemAnnotationAppearance(
+				start, end, MAX_SECONDS_TO_WAIT);
+		assertNotNull("No ProblemAnnotation found!", problemAnnotation);
+
+		String message = problemAnnotation.getText();
+		assertEquals(
+				"Not expected error message found in ProblemAnnotation. Expected: ["
+						+ errorMessage + "], Found: [" + message + "]",
+				errorMessage, message);
+	}
+
+	private Annotation waitForProblemAnnotationAppearance(
+			final int start, final int end, final int seconds) {
+		final Annotation[] result = new Annotation[] { null };
+
+		Display.getDefault().syncExec(new Runnable() {
+			public void run() {
+				int secondsLeft = seconds;
+				while (secondsLeft-- > 0) {
+					JobUtils.delay(1000);
+
+					// clean deffered events
+					while (Display.getCurrent().readAndDispatch())
+						;
+
+					annotationModel = getAnnotationModel();
+					boolean found = false;
+					@SuppressWarnings("rawtypes")
+					Iterator it = annotationModel.getAnnotationIterator();
+					while (!found && it.hasNext()) {
+						Object o = it.next();
+
+						if (!(o instanceof Annotation))
+							continue;
+						
+						Annotation annotation = (Annotation) o;
+						Position position = annotationModel
+								.getPosition(annotation);
+
+						if (position.getOffset() < start
+								|| position.getOffset() >= end)
+							continue;
+
+						if (position.getOffset() + position.getLength() >= end)
+							continue;
+
+						
+						if (!isAnnotationAcceptable(annotation))
+							continue;
+						
+						result[0] = (Annotation)o;
+						return;
+					}
+				}
+			}
+		});
+
+		return result[0];
+	}
+	
+	abstract protected boolean isAnnotationAcceptable(Annotation annotation);
+}


Property changes on: trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/AbstractAsYouTypeValidationTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/java/BaseAsYouTypeInJavaValidationTest.java
===================================================================
--- trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/java/BaseAsYouTypeInJavaValidationTest.java	2012-06-18 17:26:56 UTC (rev 42062)
+++ trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/java/BaseAsYouTypeInJavaValidationTest.java	2012-06-18 18:49:23 UTC (rev 42063)
@@ -10,54 +10,24 @@
  ******************************************************************************/
 package org.jboss.tools.common.base.test.validation.java;
 
-import java.util.Iterator;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.WorkingCopyOwner;
 import org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor;
 import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.ProblemAnnotation;
 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.Annotation;
 import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.jboss.tools.test.util.JobUtils;
-import org.jboss.tools.test.util.WorkbenchUtils;
+import org.jboss.tools.common.base.test.validation.AbstractAsYouTypeValidationTest;
 
 /**
  * 
  * @author Victor V. Rubezhny
  *
  */
-public class BaseAsYouTypeInJavaValidationTest extends TestCase {
-	private static final int MAX_SECONDS_TO_WAIT = 10;
-
-	protected String fileName;
-	protected IProject project = null;
-	protected IEditorPart editorPart = null;
-	protected JavaEditor javaEditor = null;
-	protected ISourceViewer viewer = null;
-	protected IDocument document = null;
-	protected IFile file = null;
-	IAnnotationModel annotationModel = null;
-
-	/** The working copy owner */
-	protected final WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
-	};
-
+ at SuppressWarnings("restriction")
+public class BaseAsYouTypeInJavaValidationTest extends AbstractAsYouTypeValidationTest {
 	public static final String MARKER_TYPE = "org.jboss.tools.common.validation.el"; //$NON-NLS-1$
-	public static final String EL2FIND_START = "#{";
-	public static final String EL2FIND_END = "}";
 
 	public BaseAsYouTypeInJavaValidationTest(IProject project) {
 		this.project = project;
@@ -65,144 +35,39 @@
 	public BaseAsYouTypeInJavaValidationTest() {
 	}
 	
-	public void openEditor(String fileName) {
-		this.fileName = fileName;
-		editorPart = WorkbenchUtils.openEditor(project.getName()
-				+ "/" + fileName); //$NON-NLS-1$
-		obtainJavaEditor(editorPart);
-		viewer = getTextViewer();
-		document = viewer.getDocument();
-	}
-
-	public void closeEditor() {
-		if (editorPart != null) {
-			PlatformUI.getWorkbench().getActiveWorkbenchWindow()
-					.getActivePage().closeEditor(editorPart, false);
-			editorPart = null;
-			javaEditor = null;
-			viewer = null;
-			document = null;
-		}
-	}
-
-	protected void obtainJavaEditor(IEditorPart editorPart) {
+	@Override
+	protected void obtainEditor(IEditorPart editorPart) {
 		if (!(editorPart instanceof JavaEditor)
 				|| editorPart instanceof ClassFileEditor)
 			return;
 
-		javaEditor = (JavaEditor) editorPart;
+		textEditor = (JavaEditor) editorPart;
 
 		assertNotNull(
 				"Cannot get the Java Text Editor instance for Java Class file \"" //$NON-NLS-1$
-						+ fileName + "\"", javaEditor);
+						+ fileName + "\"", textEditor);
 
 		assertTrue("Java Editor is opened for a binary Java Class",
-				javaEditor.getEditorInput() instanceof IFileEditorInput);
-		file = ((IFileEditorInput) javaEditor.getEditorInput()).getFile();
+				textEditor.getEditorInput() instanceof IFileEditorInput);
+		file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
 		assertNotNull("Java Editor is opened for a binary Java Class", file);
-
-		annotationModel = getAnnotationModel();
-		assertNotNull("Cannot find an Annotation Model for the Java Editor",
-				annotationModel);
-
-		// clean deffered events
-		while (Display.getCurrent().readAndDispatch())
-			;
 	}
 
-	protected IAnnotationModel getAnnotationModel() {
-		final IDocumentProvider documentProvider = javaEditor
-				.getDocumentProvider();
-		if (documentProvider == null) {
-			return null;
-		}
-		return documentProvider.getAnnotationModel(javaEditor.getEditorInput());
-	}
-
 	protected ISourceViewer getTextViewer() {
-		return javaEditor != null ? javaEditor.getViewer() : null;
+		return textEditor instanceof JavaEditor ? ((JavaEditor)textEditor).getViewer() : null;
 	}
 
-	public void doAsYouTipeInJavaValidationTest(String elToValidate,
-			String errorMessage) throws JavaModelException, BadLocationException {
-		String documentContent = document.get();
-		int start = (documentContent == null ? -1 : documentContent
-				.indexOf(EL2FIND_START));
-		assertFalse("No EL found in Java Strings: Starting '" + EL2FIND_START
-				+ "' characters are not found in document", (start == -1));
-		int end = (documentContent == null ? -1 : documentContent.indexOf(
-				EL2FIND_END, start));
-		assertFalse("EL is not closed in Java Strings: Ending '"
-				+ EL2FIND_START + "' characters are not found in document",
-				(end == -1));
+	@Override
+	protected boolean isAnnotationAcceptable(Annotation annotation) {
+		if (!(annotation instanceof ProblemAnnotation))
+			return false;
 
-		int offset = start;
-		int length = end - start + EL2FIND_END.length();
+		ProblemAnnotation problemAnnotation = (ProblemAnnotation) annotation;
 
-		document.replace(start, length, elToValidate);
+		String markerType = problemAnnotation.getMarkerType();
+		if (!MARKER_TYPE.equalsIgnoreCase(markerType))
+			return false;
 
-		end = start + elToValidate.length();
-
-		ProblemAnnotation problemAnnotation = waitForProblemAnnotationAppearance(
-				start, end, MARKER_TYPE, MAX_SECONDS_TO_WAIT);
-		assertNotNull("No ProblemAnnotation found for Marker Type: "
-				+ MARKER_TYPE, problemAnnotation);
-
-		String message = problemAnnotation.getText();
-		assertEquals(
-				"Not expected error message found in ProblemAnnotation. Expected: ["
-						+ errorMessage + "], Found: [" + message + "]",
-				errorMessage, message);
+		return true;
 	}
-
-	private ProblemAnnotation waitForProblemAnnotationAppearance(
-			final int start, final int end, final String markerType,
-			final int seconds) {
-		final ProblemAnnotation[] result = new ProblemAnnotation[] { null };
-
-		Display.getDefault().syncExec(new Runnable() {
-			public void run() {
-				int secondsLeft = seconds;
-				while (secondsLeft-- > 0) {
-					JobUtils.delay(1000);
-
-					// clean deffered events
-					while (Display.getCurrent().readAndDispatch())
-						;
-
-					annotationModel = getAnnotationModel();
-					boolean found = false;
-					Iterator it = annotationModel.getAnnotationIterator();
-					while (!found && it.hasNext()) {
-						Object o = it.next();
-
-						if (!(o instanceof ProblemAnnotation))
-							continue;
-
-						ProblemAnnotation problemAnnotation = (ProblemAnnotation) o;
-						Position position = annotationModel
-								.getPosition(problemAnnotation);
-
-						if (position.getOffset() < start
-								|| position.getOffset() >= end)
-							continue;
-
-						if (position.getOffset() + position.getLength() >= end)
-							continue;
-
-						String paMarkerType = problemAnnotation.getMarkerType();
-						if (!markerType.equalsIgnoreCase(markerType))
-							continue;
-
-						System.out.println("Problem: " + problemAnnotation.getText());
-						result[0] = problemAnnotation;
-						return;
-					}
-				}
-			}
-		});
-
-		return result[0];
-	}
-
 }

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-06-18 17:26:56 UTC (rev 42062)
+++ trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java	2012-06-18 18:49:23 UTC (rev 42063)
@@ -47,6 +47,7 @@
 import org.jboss.tools.jsf.jsp.ca.test.WebContentAssistProviderTest;
 import org.jboss.tools.jsf.jsp.hover.ELTooltipTest;
 import org.jboss.tools.jsf.ui.test.refactoring.ELReferencesRenameTest;
+import org.jboss.tools.jsf.ui.test.validation.JSFAsYouTypeValidationTest;
 import org.jboss.tools.jsf.ui.test.validation.java.JSFAsYouTypeInJavaValidationTest;
 import org.jboss.tools.test.util.ProjectImportTestSetup;
 
@@ -56,6 +57,7 @@
 		TestSuite suite = new TestSuite("JSF UI tests"); //$NON-NLS-1$
 
 		ValidationFramework.getDefault().suspendAllValidation(true);
+
 		suite.addTestSuite(JBossPerspectiveTest.class);
 		suite.addTestSuite(NewJSFProjectTest.class);
 		suite.addTestSuite(CAForUnclosedELTest.class);
@@ -178,6 +180,11 @@
 				new String[] { "JSF2KickStartWithoutLibs" })); //$NON-NLS-1$
 
 		suite.addTest(new ProjectImportTestSetup(new TestSuite(
+				JSFAsYouTypeValidationTest.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(
 				CAJsfPredictiveTagNameProposalsTest.class), "org.jboss.tools.jsf.base.test", //$NON-NLS-1$
 				new String[] { "projects/JSF2KickStartWithoutLibs", }, //$NON-NLS-1$
 				new String[] { "JSF2KickStartWithoutLibs" })); //$NON-NLS-1$

Modified: trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/JSFAsYouTypeValidationTest.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/JSFAsYouTypeValidationTest.java	2012-06-18 17:26:56 UTC (rev 42062)
+++ trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/JSFAsYouTypeValidationTest.java	2012-06-18 18:49:23 UTC (rev 42063)
@@ -10,26 +10,16 @@
  ******************************************************************************/
 package org.jboss.tools.jsf.ui.test.validation;
 
-import java.util.Iterator;
-
 import org.eclipse.core.resources.IncrementalProjectBuilder;
-import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jdt.core.JavaModelException;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
 import org.eclipse.wst.validation.ValidationFramework;
 import org.jboss.tools.common.preferences.SeverityPreferences;
-import org.jboss.tools.jst.jsp.test.ca.ContentAssistantTestCase;
+import org.jboss.tools.jst.jsp.test.validation.BaseAsYouTypeValidationTest;
 import org.jboss.tools.jst.web.kb.WebKbPlugin;
 import org.jboss.tools.jst.web.kb.preferences.ELSeverityPreferences;
-import org.jboss.tools.test.util.JobUtils;
 import org.jboss.tools.test.util.ProjectImportTestSetup;
 
 /**
@@ -37,7 +27,7 @@
  * @author Victor V. Rubezhny
  *
  */
-public class JSFAsYouTypeValidationTest extends ContentAssistantTestCase {
+public class JSFAsYouTypeValidationTest extends BaseAsYouTypeValidationTest {
 	private static final String PROJECT_NAME = "JSF2KickStartWithoutLibs";
 	private static final String PAGE_NAME = "WebContent/pages/inputname.xhtml";
 
@@ -48,8 +38,6 @@
 			{"#{['}", "EL syntax error: Expecting expression."}
 		};
 
-	private static final int MAX_SECONDS_TO_WAIT = 10;
-	public static final String MARKER_TYPE = "org.jboss.tools.common.validation.asyoutype"; //$NON-NLS-1$
 	public static final String EL2FIND_START = "#{";
 	public static final String EL2FIND_END = "}";
 	
@@ -86,99 +74,4 @@
 			closeEditor();	
 		}
 	}
-	
-	public void doAsYouTipeInJavaValidationTest(String elToValidate,
-			String errorMessage) throws JavaModelException, BadLocationException {
-		String documentContent = document.get();
-		int start = (documentContent == null ? -1 : documentContent
-				.indexOf(EL2FIND_START));
-		assertFalse("No EL found in Java Strings: Starting '" + EL2FIND_START
-				+ "' characters are not found in document", (start == -1));
-		int end = (documentContent == null ? -1 : documentContent.indexOf(
-				EL2FIND_END, start));
-		assertFalse("EL is not closed in Java Strings: Ending '"
-				+ EL2FIND_START + "' characters are not found in document",
-				(end == -1));
-
-		int offset = start;
-		int length = end - start + EL2FIND_END.length();
-
-		IProgressMonitor monitor = new NullProgressMonitor();
-		document.replace(start, length, elToValidate);
-
-		end = start + elToValidate.length();
-
-		TemporaryAnnotation problemAnnotation = waitForProblemAnnotationAppearance(
-				start, end, MARKER_TYPE, MAX_SECONDS_TO_WAIT);
-		assertNotNull("No ProblemAnnotation found for Marker Type: "
-				+ MARKER_TYPE, problemAnnotation);
-
-		String message = problemAnnotation.getText();
-		assertEquals(
-				"Not expected error message found in ProblemAnnotation. Expected: ["
-						+ errorMessage + "], Found: [" + message + "]",
-				errorMessage, message);
-	}
-	
-	private TemporaryAnnotation waitForProblemAnnotationAppearance(
-			final int start, final int end, final String markerType,
-			final int seconds) {
-		final TemporaryAnnotation[] result = new TemporaryAnnotation[] { null };
-
-		Display.getDefault().syncExec(new Runnable() {
-			public void run() {
-				int secondsLeft = seconds;
-				while (secondsLeft-- > 0) {
-					JobUtils.delay(1000);
-
-					// clean deffered events
-					while (Display.getCurrent().readAndDispatch())
-						;
-
-					IAnnotationModel annotationModel = getAnnotationModel(textEditor);
-					boolean found = false;
-					Iterator it = annotationModel.getAnnotationIterator();
-					while (!found && it.hasNext()) {
-						Object o = it.next();
-
-						if (!(o instanceof TemporaryAnnotation))
-							continue;
-
-						TemporaryAnnotation temporaryAnnotation = (TemporaryAnnotation) o;
-						Position position = annotationModel
-								.getPosition(temporaryAnnotation);
-
-						if (position.getOffset() < start
-								|| position.getOffset() >= end)
-							continue;
-
-						if (position.getOffset() + position.getLength() >= end)
-							continue;
-
-						if (temporaryAnnotation.getAttributes() == null && temporaryAnnotation.getAttributes().isEmpty())
-							continue;
-						
-						Object value = temporaryAnnotation.getAttributes().get(MARKER_TYPE);
-						
-						if (Boolean.TRUE != value)
-							continue;
-
-						result[0] = temporaryAnnotation;
-						return;
-					}
-				}
-			}
-		});
-
-		return result[0];
-	}
-
-	protected IAnnotationModel getAnnotationModel(ITextEditor editor) {
-		final IDocumentProvider documentProvider = editor.getDocumentProvider();
-		if (documentProvider == null) {
-			return null;
-		}
-		return documentProvider.getAnnotationModel(editor.getEditorInput());
-	}
-
 }

Modified: trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/META-INF/MANIFEST.MF	2012-06-18 17:26:56 UTC (rev 42062)
+++ trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/META-INF/MANIFEST.MF	2012-06-18 18:49:23 UTC (rev 42063)
@@ -24,4 +24,5 @@
  org.jboss.tools.common.validation
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Export-Package: org.jboss.tools.jst.jsp.test.ca
+Export-Package: org.jboss.tools.jst.jsp.test.ca,
+ org.jboss.tools.jst.jsp.test.validation

Added: trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/src/org/jboss/tools/jst/jsp/test/validation/BaseAsYouTypeValidationTest.java
===================================================================
--- trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/src/org/jboss/tools/jst/jsp/test/validation/BaseAsYouTypeValidationTest.java	                        (rev 0)
+++ trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/src/org/jboss/tools/jst/jsp/test/validation/BaseAsYouTypeValidationTest.java	2012-06-18 18:49:23 UTC (rev 42063)
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * 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
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.test.validation;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation;
+import org.jboss.tools.common.base.test.validation.AbstractAsYouTypeValidationTest;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+
+/**
+ * 
+ * @author Victor V. Rubezhny
+ *
+ */
+ at SuppressWarnings("restriction")
+public class BaseAsYouTypeValidationTest extends AbstractAsYouTypeValidationTest {
+	public static final String MARKER_TYPE = "org.jboss.tools.common.validation.asyoutype"; //$NON-NLS-1$
+
+	public BaseAsYouTypeValidationTest(IProject project) {
+		this.project = project;
+	}
+	public BaseAsYouTypeValidationTest() {
+	}
+	
+	@Override
+	protected void obtainEditor(IEditorPart editorPart) {
+		JSPMultiPageEditor jspEditor = null;
+
+		if (editorPart instanceof JSPMultiPageEditor)
+			jspEditor = (JSPMultiPageEditor) editorPart;
+
+		assertNotNull("Cannot get the JSP Text Editor instance for page \"" //$NON-NLS-1$
+						+ fileName + "\"", jspEditor);
+		
+		// clean deffered events 
+		while (Display.getCurrent().readAndDispatch());
+
+		textEditor = jspEditor.getJspEditor();
+
+		assertNotNull("Cannot get the JSP Text Editor instance for page \"" //$NON-NLS-1$
+				+ fileName + "\"", textEditor);
+
+		file = ((IFileEditorInput) textEditor.getEditorInput()).getFile();
+		assertNotNull("Cannot get the JSP Text Editor instance for page \"" //$NON-NLS-1$
+				+ fileName + "\"", file);
+	}
+
+	protected ISourceViewer getTextViewer() {
+		return ((StructuredTextEditor)textEditor).getTextViewer();
+	}
+
+	@Override
+	protected boolean isAnnotationAcceptable(Annotation annotation) {
+		if (!(annotation instanceof TemporaryAnnotation))
+			return false;
+
+		TemporaryAnnotation temporaryAnnotation = (TemporaryAnnotation) annotation;
+
+		if (temporaryAnnotation.getAttributes() == null && temporaryAnnotation.getAttributes().isEmpty())
+			return false;
+		
+		Object value = temporaryAnnotation.getAttributes().get(MARKER_TYPE);
+		
+		if (Boolean.TRUE != value)
+			return false;
+
+		return true;
+	}
+}


Property changes on: trunk/jst/tests/org.jboss.tools.jst.jsp.base.test/src/org/jboss/tools/jst/jsp/test/validation/BaseAsYouTypeValidationTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list