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

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Jul 6 18:13:39 EDT 2012


Author: dazarov
Date: 2012-07-06 18:13:38 -0400 (Fri, 06 Jul 2012)
New Revision: 42448

Added:
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.java
   trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.new
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java
   trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java
Modified:
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java
Log:
Make Quick Fix "Configure Problem Severity" work on Temporary annotations https://issues.jboss.org/browse/JBIDE-12232

Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.java	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.java	2012-07-06 22:13:38 UTC (rev 42448)
@@ -0,0 +1,10 @@
+package org.jboss.jsr299.tck.tests.jbt.quickfixes;
+
+import javax.ejb.Stateless;
+import javax.enterprise.inject.Produces;
+
+ at Stateless
+public class NonStaticProducerBroken {
+
+	public FunnelWeaver<String> anotherFunnelWeaver;
+}
\ No newline at end of file


Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.new
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.new	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/NonStaticProducerBroken.new	2012-07-06 22:13:38 UTC (rev 42448)
@@ -0,0 +1,10 @@
+package org.jboss.jsr299.tck.tests.jbt.quickfixes;
+
+import javax.ejb.Stateless;
+import javax.enterprise.inject.Produces;
+
+ at Stateless
+public class NonStaticProducerBroken {
+
+	@Produces public FunnelWeaver<String> anotherFunnelWeaver;
+}
\ No newline at end of file

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-07-06 22:09:27 UTC (rev 42447)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java	2012-07-06 22:13:38 UTC (rev 42448)
@@ -18,6 +18,7 @@
 import org.eclipse.wst.validation.ValidationFramework;
 import org.jboss.tools.cdi.core.test.CDICoreTestSetup;
 import org.jboss.tools.cdi.ui.test.marker.CDIMarkerResolutionTest;
+import org.jboss.tools.cdi.ui.test.marker.CDIQuickFixTest;
 import org.jboss.tools.cdi.ui.test.perspective.CDIPerspectiveTest;
 import org.jboss.tools.cdi.ui.test.preferences.CDIPreferencePageTest;
 import org.jboss.tools.cdi.ui.test.search.CDISearchParticipantTest;
@@ -50,6 +51,8 @@
 		TestSuite suite = new TestSuite("TCK Tests");
 
 		suiteAll.addTestSuite(CDIMarkerResolutionTest.class);
+		
+		suiteAll.addTestSuite(CDIQuickFixTest.class);
 
 		suiteAll.addTestSuite(CDIPerspectiveTest.class);
 		suiteAll.addTestSuite(NewCDIClassWizardFactoryTest.class);

Added: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java	2012-07-06 22:13:38 UTC (rev 42448)
@@ -0,0 +1,20 @@
+package org.jboss.tools.cdi.ui.test.marker;
+
+import org.eclipse.core.runtime.CoreException;
+import org.jboss.tools.cdi.core.test.tck.TCKTest;
+import org.jboss.tools.cdi.internal.core.validation.CDIValidationErrorManager;
+import org.jboss.tools.common.base.test.QuickFixTestUtil;
+import org.jboss.tools.common.ui.marker.ConfigureProblemSeverityMarkerResolution;
+
+public class CDIQuickFixTest extends TCKTest {
+	QuickFixTestUtil util = new QuickFixTestUtil();
+	
+	public void testConfigureProblemSeverity() throws CoreException {
+		util.checkPrpposal(tckProject,
+				"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/NonStaticProducerBroken.java",
+				"JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/NonStaticProducerBroken.new",
+				CDIValidationErrorManager.MESSAGE_ID_ATTRIBUTE_NAME,
+				CDIValidationErrorManager.ILLEGAL_PRODUCER_FIELD_IN_SESSION_BEAN_ID,
+				ConfigureProblemSeverityMarkerResolution.class);
+	} 
+}


Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIQuickFixTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java
===================================================================
--- trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java	                        (rev 0)
+++ trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/QuickFixTestUtil.java	2012-07-06 22:13:38 UTC (rev 42448)
@@ -0,0 +1,194 @@
+package org.jboss.tools.common.base.test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaMarkerAnnotation;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.jboss.tools.common.base.test.validation.TestUtil;
+import org.jboss.tools.common.quickfix.QuickFixManager;
+import org.jboss.tools.common.refactoring.TestableResolutionWithDialog;
+import org.jboss.tools.common.refactoring.TestableResolutionWithRefactoringProcessor;
+import org.jboss.tools.common.ui.marker.AddSuppressWarningsMarkerResolution;
+import org.jboss.tools.common.ui.marker.ConfigureProblemSeverityMarkerResolution;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.common.validation.java.JavaDirtyRegionProcessor.JavaProblemAnnotation;
+import org.jboss.tools.test.util.JobUtils;
+
+public class QuickFixTestUtil{
+	private static final int MAX_SECONDS_TO_WAIT = 10;
+	
+	protected ISourceViewer getViewer(IEditorPart editor){
+		if(editor instanceof JavaEditor){
+			return ((JavaEditor)editor).getViewer();
+		}
+		return null;
+	}
+	
+	protected String getEditorID(){
+		return "org.eclipse.jdt.ui.CompilationUnitEditor";
+	}
+
+	private void checkForConfigureProblemSeverity(IJavaCompletionProposal[] proposals){
+		for(IJavaCompletionProposal proposal : proposals){
+			if(proposal.getClass().equals(ConfigureProblemSeverityMarkerResolution.class))
+				return;
+		}
+		Assert.fail("Configure Problem Severity quick fix not found");
+	}
+
+	private void checkForAddSuppressWarnings(IFile file, JavaProblemAnnotation annotation, IJavaCompletionProposal[] proposals){
+		String severity = annotation.getMarkerType();
+		if(file.getFileExtension().equals("java") && severity.equals(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE)){
+			for(IJavaCompletionProposal proposal : proposals){
+				if(proposal.getClass().equals(AddSuppressWarningsMarkerResolution.class))
+					return;
+			}
+			Assert.fail("Add @SuppressWarnings marker resolution not found");
+		}
+	}
+	
+	public void checkPrpposal(IProject project, String fileName, String newFile, String idName, int id, Class<? extends IJavaCompletionProposal> proposalClass) throws CoreException {
+		IFile file = project.getFile(fileName);
+		IFile nFile = project.getFile(newFile);
+
+		Assert.assertTrue("File - "+file.getFullPath()+" must be exist",file.exists());
+		Assert.assertTrue("File - "+nFile.getFullPath()+" must be exist",nFile.exists());
+
+		IEditorInput input = new FileEditorInput(file);
+
+		IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input,	getEditorID(), true);
+		ISourceViewer viewer = getViewer(editor);
+		
+		// change file
+		IDocument document = viewer.getDocument();
+		
+		String text = FileUtil.getContentFromEditorOrFile(nFile);
+		
+		document.set(text);
+		
+		// Find annotation
+		JavaProblemAnnotation[] annotations = waitForProblemAnnotationAppearance(viewer);
+		
+		for(JavaProblemAnnotation annotation : annotations){
+			IJavaCompletionProposal[] proposals = getCompletionProposals(annotation);
+			checkForConfigureProblemSeverity(proposals);
+			checkForAddSuppressWarnings(file, annotation, proposals);
+			for(IJavaCompletionProposal proposal : proposals){
+				if (proposal.getClass().equals(proposalClass)) {
+
+					if(proposal instanceof TestableResolutionWithRefactoringProcessor){
+						RefactoringProcessor processor = ((TestableResolutionWithRefactoringProcessor)proposal).getRefactoringProcessor();
+						
+						RefactoringStatus status = processor.checkInitialConditions(new NullProgressMonitor());
+						
+						Assert.assertNull("Rename processor returns fatal error", status.getEntryMatchingSeverity(RefactoringStatus.FATAL));
+
+						status = processor.checkFinalConditions(new NullProgressMonitor(), null);
+
+						Assert.assertNull("Rename processor returns fatal error", status.getEntryMatchingSeverity(RefactoringStatus.FATAL));
+
+						CompositeChange rootChange = (CompositeChange)processor.createChange(new NullProgressMonitor());
+						
+						rootChange.perform(new NullProgressMonitor());
+					} else if(proposal instanceof TestableResolutionWithDialog){
+						((TestableResolutionWithDialog) proposal).runForTest(null);
+					} else {
+						proposal.apply(document);
+					}
+
+					TestUtil.validate(file);
+
+					JavaProblemAnnotation[] newAnnotations = waitForProblemAnnotationAppearance(viewer);
+
+					Assert.assertTrue("Quick fix did not decrease number of problems. was: "+annotations.length+" now: "+newAnnotations.length, newAnnotations.length < annotations.length);
+
+					//checkResults(project, fileNames, results);
+
+					return;
+				}
+			}
+		}
+		
+		Assert.fail("Quick fix: "+proposalClass+" not found");
+	}
+	
+	public static IJavaCompletionProposal[] getCompletionProposals(JavaProblemAnnotation annotation){
+		ArrayList<IJavaCompletionProposal> proposals = new ArrayList<IJavaCompletionProposal>();
+		
+		if(QuickFixManager.getInstance().hasProposals(annotation)){
+			List<IJavaCompletionProposal> list = QuickFixManager.getInstance().getProposals(annotation);
+			proposals.addAll(list);
+		}
+		
+		return proposals.toArray(new IJavaCompletionProposal[]{});
+	}
+
+	private static void checkResults(IProject project, String[] fileNames, String[] results) throws CoreException{
+		for(int i = 0; i < results.length; i++){
+			IFile file = project.getFile(fileNames[i]);
+			IFile resultFile = project.getFile(results[i]);
+
+			String fileContent = FileUtil.readStream(file);
+			String resultContent = FileUtil.readStream(resultFile);
+			
+			Assert.assertEquals("Wrong result of resolution", resultContent, fileContent);
+		}
+	}
+	
+	protected JavaProblemAnnotation[] waitForProblemAnnotationAppearance(final ISourceViewer viewer) {
+		final ArrayList<JavaProblemAnnotation> annotations = new ArrayList<JavaProblemAnnotation>();
+
+		Display.getDefault().syncExec(new Runnable() {
+			public void run() {
+				int secondsLeft = MAX_SECONDS_TO_WAIT;
+				boolean isFirstPass = true;
+				while (secondsLeft-- > 0) {
+					if (!isFirstPass) {
+						JobUtils.delay(1000);
+
+						// clean differed events
+						while (Display.getCurrent().readAndDispatch())
+							;
+					} else {
+						secondsLeft++; // because the wait step was skipped
+					}
+
+					//boolean found = false;
+					IAnnotationModel annotationModel = viewer.getAnnotationModel();
+					Iterator it = annotationModel.getAnnotationIterator();
+					while (it.hasNext()) {
+						Object o = it.next();
+
+						if (o instanceof JavaProblemAnnotation){
+							annotations.add((JavaProblemAnnotation) o);
+						}
+
+					}
+					isFirstPass = false;
+				}
+			}
+		});
+
+		return annotations.toArray(new JavaProblemAnnotation[]{});
+	}
+}


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



More information about the jbosstools-commits mailing list