[jbosstools-commits] JBoss Tools SVN: r41850 - in trunk: common/tests/org.jboss.tools.common.base.test/META-INF and 5 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Sat Jun 9 10:04:08 EDT 2012
Author: vrubezhny
Date: 2012-06-09 10:04:08 -0400 (Sat, 09 Jun 2012)
New Revision: 41850
Added:
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/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/validation/
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/java/
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/java/JSFAsYouTypeInJavaValidationTest.java
Modified:
trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java
trunk/common/tests/org.jboss.tools.common.base.test/META-INF/MANIFEST.MF
trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java
Log:
JBIDE-10738
As-you-type EL validation
JUnit test is added for JSF project
Modified: trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java 2012-06-09 07:36:04 UTC (rev 41849)
+++ trunk/common/plugins/org.jboss.tools.common.validation/src/org/jboss/tools/common/validation/java/JavaDirtyRegionProcessor.java 2012-06-09 14:04:08 UTC (rev 41850)
@@ -65,9 +65,11 @@
private boolean fIsCanceled = false;
private boolean fInRewriteSession = false;
private IDocumentRewriteSessionListener fDocumentRewriteSessionListener = new DocumentRewriteSessionListener();
+ // AsYouType EL Validation 'marker type' name.
+ // marker type is used in the quickFixProcessor extension point
+ public static final String MARKER_TYPE= "org.jboss.tools.common.validation.el"; //$NON-NLS-1$
public final class JavaELProblemReporter implements IReporter {
- public static final String MARKER_TYPE= "org.jboss.tools.common.validation.el"; //$NON-NLS-1$
private IFile fFile;
private ICompilationUnit fCompilationUnit;
private IAnnotationModel fAnnotationModel;
@@ -163,7 +165,7 @@
}
fAnnotations.put(annotation, position);
- getAnnotationModel().addAnnotation(annotation, position);
+ fAnnotationModel.addAnnotation(annotation, position);
}
@Override
@@ -195,10 +197,6 @@
}
class CoreELProblem extends CategorizedProblem {
- // spelling 'marker type' name. Only virtual as spelling problems are never persisted in markers.
- // marker type is used in the quickFixProcessor extension point
- public static final String MARKER_TYPE= "org.jboss.tools.common.validation.el"; //$NON-NLS-1$
-
/** The end offset of the problem */
private int fSourceEnd= 0;
@@ -471,7 +469,7 @@
}
for (int i = 0; i < partitions.length; i++) {
if (partitions[i] != null && !fIsCanceled && IJavaPartitions.JAVA_STRING.equals(partitions[i].getType())) {
- if (fValidatorManager != null)
+ if (fValidatorManager != null)
fValidatorManager.validate(partitions[i], fHelper, fReporter);
}
}
Modified: trunk/common/tests/org.jboss.tools.common.base.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/tests/org.jboss.tools.common.base.test/META-INF/MANIFEST.MF 2012-06-09 07:36:04 UTC (rev 41849)
+++ trunk/common/tests/org.jboss.tools.common.base.test/META-INF/MANIFEST.MF 2012-06-09 14:04:08 UTC (rev 41850)
@@ -10,7 +10,8 @@
org.jboss.tools.common.base.test.contentassist,
org.jboss.tools.common.base.test.kb,
org.jboss.tools.common.base.test.model,
- org.jboss.tools.common.base.test.validation
+ org.jboss.tools.common.base.test.validation,
+ org.jboss.tools.common.base.test.validation.java
Require-Bundle: org.jboss.tools.common,
org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.ui;bundle-version="3.7.0",
Added: 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 (rev 0)
+++ trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/java/BaseAsYouTypeInJavaValidationTest.java 2012-06-09 14:04:08 UTC (rev 41850)
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * 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.java;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+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.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+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.common.EclipseUtil;
+import org.jboss.tools.test.util.JobUtils;
+import org.jboss.tools.test.util.WorkbenchUtils;
+
+/**
+ *
+ * @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;
+ protected ICompilationUnit unit = null;
+ IAnnotationModel annotationModel = null;
+
+ /** The working copy owner */
+ protected final WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() {
+ };
+
+ 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 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) {
+ if (!(editorPart instanceof JavaEditor)
+ || editorPart instanceof ClassFileEditor)
+ return;
+
+ javaEditor = (JavaEditor) editorPart;
+
+ assertNotNull(
+ "Cannot get the Java Text Editor instance for Java Class file \"" //$NON-NLS-1$
+ + fileName + "\"", javaEditor);
+
+ assertTrue("Java Editor is opened for a binary Java Class",
+ javaEditor.getEditorInput() instanceof IFileEditorInput);
+ file = ((IFileEditorInput) javaEditor.getEditorInput()).getFile();
+ assertNotNull("Java Editor is opened for a binary Java Class", file);
+
+ unit = EclipseUtil.getCompilationUnit(file);
+ assertNotNull("Cannot find a Compilation Unit for Source file", unit);
+
+ 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;
+ }
+
+ protected void doAsYouTipeInJavaValidationTest(String elToValidate,
+ String errorMessage) throws JavaModelException {
+ 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();
+ modifyDocumentContent(unit, start, length, elToValidate, monitor);
+
+ 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);
+ }
+
+ private void modifyDocumentContent(final ICompilationUnit unit,
+ final int start, final int length, final String text,
+ final IProgressMonitor monitor) {
+ // Display.getDefault().syncExec(new Runnable() {
+ // public void run() {
+ ICompilationUnit workingCopy;
+ try {
+ workingCopy = unit.getWorkingCopy(monitor);
+ TextEdit edit = new MultiTextEdit();
+ ReplaceEdit replaceEdit = new ReplaceEdit(start, length, text);
+ edit.addChild(replaceEdit);
+
+ workingCopy.applyTextEdit(edit, monitor);
+ workingCopy.commitWorkingCopy(true, monitor);
+ } catch (JavaModelException e) {
+ fail("An error occured while modifying the document content");
+ }
+
+ String newDocumentContent = document.get();
+ assertTrue("Document isn't modified",
+ newDocumentContent.indexOf(text) != -1);
+ // }
+ // });
+
+ }
+
+ 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];
+ }
+
+}
Property changes on: trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/java/BaseAsYouTypeInJavaValidationTest.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-06-09 07:36:04 UTC (rev 41849)
+++ trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/JsfUiAllTests.java 2012-06-09 14:04:08 UTC (rev 41850)
@@ -46,6 +46,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.java.JSFAsYouTypeInJavaValidationTest;
import org.jboss.tools.test.util.ProjectImportTestSetup;
public class JsfUiAllTests {
@@ -54,7 +55,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);
@@ -170,6 +171,11 @@
CAJsfResourceBundlePropertyApplyTest.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(
+ JSFAsYouTypeInJavaValidationTest.class), "org.jboss.tools.jsf.base.test", //$NON-NLS-1$
+ new String[] { "projects/JSF2KickStartWithoutLibs", }, //$NON-NLS-1$
+ new String[] { "JSF2KickStartWithoutLibs" })); //$NON-NLS-1$
return suite;
}
Added: trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/java/JSFAsYouTypeInJavaValidationTest.java
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/java/JSFAsYouTypeInJavaValidationTest.java (rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/java/JSFAsYouTypeInJavaValidationTest.java 2012-06-09 14:04:08 UTC (rev 41850)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.jsf.ui.test.validation.java;
+
+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.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 JSFAsYouTypeInJavaValidationTest extends BaseAsYouTypeInJavaValidationTest {
+ private static final String PROJECT_NAME = "JSF2KickStartWithoutLibs";
+ private static final String PAGE_NAME = "JavaSource/demo/User.java";
+
+ private static final String [][] EL2VALIDATE =
+ {
+ {"#{user.names}", "\"names\" cannot be resolved"},
+ {"#{suser.name}", "\"suser\" cannot be resolved"},
+ {"#{['}", "EL syntax error: Expecting expression."}
+ };
+
+ public void setUp() throws Exception {
+ project = ProjectImportTestSetup.loadProject(PROJECT_NAME);
+ project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ }
+
+ public void testAsYouTypeInJavaValidation() throws JavaModelException {
+ assertNotNull("Test project '" + PROJECT_NAME + "' is not prepared", project);
+ openEditor(PAGE_NAME);
+ IPreferenceStore store = WebKbPlugin.getDefault().getPreferenceStore();
+ String defaultValidateUnresolvedEL = SeverityPreferences.ENABLE;
+ String defaultUnknownELVariableName = SeverityPreferences.IGNORE;
+ try {
+ defaultValidateUnresolvedEL = store.getString(ELSeverityPreferences.RE_VALIDATE_UNRESOLVED_EL);
+ defaultUnknownELVariableName = store.getString(ELSeverityPreferences.UNKNOWN_EL_VARIABLE_NAME);
+ store.setValue(ELSeverityPreferences.RE_VALIDATE_UNRESOLVED_EL, SeverityPreferences.ENABLE);
+ store.setValue(ELSeverityPreferences.UNKNOWN_EL_VARIABLE_NAME, SeverityPreferences.ERROR);
+ for (int i = 0; i < EL2VALIDATE.length; i++) {
+ doAsYouTipeInJavaValidationTest(EL2VALIDATE[i][0], EL2VALIDATE[i][1]);
+ }
+ } finally {
+ store.setValue(ELSeverityPreferences.RE_VALIDATE_UNRESOLVED_EL, defaultValidateUnresolvedEL);
+ store.setValue(ELSeverityPreferences.UNKNOWN_EL_VARIABLE_NAME, defaultUnknownELVariableName);
+ closeEditor();
+ }
+ }
+}
Property changes on: trunk/jsf/tests/org.jboss.tools.jsf.ui.test/src/org/jboss/tools/jsf/ui/test/validation/java/JSFAsYouTypeInJavaValidationTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
More information about the jbosstools-commits
mailing list