Author: vrubezhny
Date: 2012-08-17 16:04:56 -0400 (Fri, 17 Aug 2012)
New Revision: 43101
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/TestNamed.java
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaSupressWarningsTest.java
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/java/BaseAsYouTypeInJavaValidationTest.java
Log:
JBIDE-12436
False validation problem for elements annotated @SuppressWarnings
JUnit Test is added for the issue
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/TestNamed.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/TestNamed.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/TestNamed.java 2012-08-17
20:04:56 UTC (rev 43101)
@@ -0,0 +1,16 @@
+package org.jboss.jsr299.tck.tests.jbt.validation;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+public class TestNamed {
+
+ @SuppressWarnings("cdi-ambiguous-dependency")
+ @Inject String s; // Ambiguous
+
+ @Produces
+ public String foo1;
+
+ @Produces
+ public String foo2;
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/validation/TestNamed.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-08-17
20:01:53 UTC (rev 43100)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/CDIUIAllTests.java 2012-08-17
20:04:56 UTC (rev 43101)
@@ -25,6 +25,7 @@
import org.jboss.tools.cdi.ui.test.search.ELReferencesQueryParticipantTest;
import org.jboss.tools.cdi.ui.test.search.FiveDependentProjectsSearchParticipantTest;
import org.jboss.tools.cdi.ui.test.search.FiveDependentProjectsTestSetup;
+import
org.jboss.tools.cdi.ui.test.validation.java.CDIAsYouTypeInJavaSupressWarningsTest;
import org.jboss.tools.cdi.ui.test.validation.java.CDIAsYouTypeInJavaValidationTest;
import org.jboss.tools.cdi.ui.test.wizard.AddQualifiersToBeanWizardTest;
import org.jboss.tools.cdi.ui.test.wizard.NewCDIClassWizardFactoryTest;
@@ -66,11 +67,11 @@
suite.addTestSuite(CATest.class);
suite.addTestSuite(OpenCDINamedBeanDialogTest.class);
suite.addTestSuite(CDIAsYouTypeInJavaValidationTest.class);
+ suite.addTestSuite(CDIAsYouTypeInJavaSupressWarningsTest.class);
suiteAll.addTest(new CDICoreTestSetup(suite));
suiteAll.addTestSuite(AddQualifiersToBeanWizardTest.class);
-
suiteAll.addTestSuite(CDIRefactoringTest.class);
TestSuite dependentSuite = new TestSuite("Dependent Projects Tests");
Added:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaSupressWarningsTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaSupressWarningsTest.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaSupressWarningsTest.java 2012-08-17
20:04:56 UTC (rev 43101)
@@ -0,0 +1,125 @@
+package org.jboss.tools.cdi.ui.test.validation.java;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.source.Annotation;
+import org.jboss.tools.cdi.core.test.tck.TCKTest;
+import org.jboss.tools.cdi.internal.core.validation.CDICoreValidator;
+import org.jboss.tools.cdi.internal.core.validation.CDIValidationMessages;
+import org.jboss.tools.common.base.test.validation.AbstractAsYouTypeValidationTest;
+import
org.jboss.tools.common.base.test.validation.java.BaseAsYouTypeInJavaValidationTest;
+
+public class CDIAsYouTypeInJavaSupressWarningsTest extends TCKTest {
+ private static final String PAGE_NAME =
"JavaSource/org/jboss/jsr299/tck/tests/jbt/validation/TestNamed.java";
+
+ private BaseAsYouTypeInJavaValidationTest baseTest = null;
+ protected IProject project;
+
+ private static final String SUPPRESSWARNINGS_NAME =
"cdi-ambiguous-dependency";
+ private static final String INJECT_ANNOTATION_NAME = "@Inject";
+ private static final String ERROR_MESSAGE =
CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS;
+
+ @Override
+ public void setUp() throws Exception {
+ project = TCKTest.findTestProject();
+ if (baseTest == null) {
+ baseTest = new BaseAsYouTypeInJavaValidationTest(project,
CDICoreValidator.PROBLEM_TYPE);
+ }
+ }
+
+ public void testAsYouTypeInJavaValidation() throws BadLocationException, CoreException
{
+ assertNotNull("Test project '" + TCKTest.MAIN_PROJECT_NAME + "'
is not prepared", project);
+ baseTest.openEditor(PAGE_NAME);
+ try {
+ doAsYouTypeValidationMarkerAnnotationsRemovalTest();
+ } finally {
+ baseTest.closeEditor();
+ }
+ }
+
+ /**
+ * The test procedure steps:
+ * - Find EL by a given number
+ * - Set up a broken EL and save the document => see problem marker appearance on
that EL
+ * - Set up a another broken EL => see annotation appearance on that EL instead of a
problem marker
+ * (an old problem marker has to disappear)
+ * - Set up a good EL again => see annotation to disappear on that EL
+ *
+ * @param goodEL
+ * @param elToValidate
+ * @param errorMessage
+ * @param numberOfRegionToTest
+ * @throws BadLocationException
+ * @throws CoreException
+ */
+ public void doAsYouTypeValidationMarkerAnnotationsRemovalTest() throws
BadLocationException, CoreException {
+
+ //============================
+ // The test procedure steps:
+ // - Find annotation: @SuppressWarnings("cdi-ambiguous-dependency")
+ // - Find MarkerAnnotation in line: @Inject String s; // Ambiguous
+ //============================
+
+ String documentContent = baseTest.getDocument().get();
+
+ int start = (documentContent == null ? -1 : documentContent
+ .indexOf(SUPPRESSWARNINGS_NAME, 0));
+ assertFalse("No annotation for \'" + SUPPRESSWARNINGS_NAME + "\'
found in document", (start == -1));
+ int length = SUPPRESSWARNINGS_NAME.length();
+
+ int injectStart = (documentContent == null ? -1 : documentContent
+ .indexOf(INJECT_ANNOTATION_NAME, start));
+ int injectLength = INJECT_ANNOTATION_NAME.length();
+
+ // do check marker and marker annotation are absent at line of @Inject annotation
+ int line = baseTest.getDocument().getLineOfOffset(injectStart);
+ baseTest.assertNoResourceMarkerIsCreated(baseTest.getFile(), toRegex(ERROR_MESSAGE),
line + 1);
+
+ Annotation problemAnnotation = baseTest.waitForAnnotation(
+ start, start + length, ERROR_MESSAGE,
AbstractAsYouTypeValidationTest.MAX_SECONDS_TO_WAIT, true, false);
+ assertNull("Problem Marker Annotation found for \'" +
INJECT_ANNOTATION_NAME + "\'!", problemAnnotation);
+
+ //=================================================================================================
+ // - Remove some chars in @SuppressWarning Annotation Type => see error annotation
to appear
+ //=================================================================================================
+
+ baseTest.getDocument().replace(start, length, "xyz");
+
+ problemAnnotation = baseTest.waitForAnnotation(
+ start, start + length, null, AbstractAsYouTypeValidationTest.MAX_SECONDS_TO_WAIT,
false, true); // Still use the same length (Just to have a place to look in)
+ assertNotNull("Problem Annotation didn't appeare!", problemAnnotation);
+
+ String message = problemAnnotation.getText();
+ assertEquals(
+ "Not expected error message found in ProblemAnnotation. Expected: ["
+ + ERROR_MESSAGE + "], Found: [" + message + "]",
+ ERROR_MESSAGE, message);
+
+ //=================================================================================================
+ // - Restore broken @SupressWarnings Annotation Type => see error annotation
disappearance
+ //=================================================================================================
+
+ baseTest.getDocument().replace(start, 3, SUPPRESSWARNINGS_NAME);
+
+ problemAnnotation = baseTest.waitForAnnotation(
+ start, start + length, ERROR_MESSAGE,
AbstractAsYouTypeValidationTest.MAX_SECONDS_TO_WAIT, false, false);
+
+ assertNull("Problem Annotation didn't disappeare!", problemAnnotation);
+ }
+
+ private String toRegex(String text) {
+ StringBuilder result = new StringBuilder(text);
+
+ int i = -1;
+ while ((i = result.indexOf("[", i+1)) != -1) {
+ result.insert(i++, '\\');
+ }
+ i = -1;
+ while ((i = result.indexOf("]", i+1)) != -1) {
+ result.insert(i++, '\\');
+ }
+
+ return result.toString();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/validation/java/CDIAsYouTypeInJavaSupressWarningsTest.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-08-17
20:01:53 UTC (rev 43100)
+++
trunk/common/tests/org.jboss.tools.common.base.test/src/org/jboss/tools/common/base/test/validation/java/BaseAsYouTypeInJavaValidationTest.java 2012-08-17
20:04:56 UTC (rev 43101)
@@ -114,4 +114,21 @@
fail("Resource Marker not found for type: " + fResourceMarkerType + ",
message: [" + errorMessage + "] at line: " + line);
}
+
+ public void assertNoResourceMarkerIsCreated(IFile file,
+ String errorMessage, int line) throws CoreException {
+ IMarker[] markers = AbstractResourceMarkerTest.findMarkers(
+ file, fResourceMarkerType, errorMessage, true);
+
+ assertTrue("Resource Marker is found for type: " + fResourceMarkerType +
", message: [" + errorMessage + "] at line: " + line, (markers == null
|| markers.length == 0));
+
+ if (markers != null) {
+ for (IMarker m : markers) {
+ Integer l = m.getAttribute(IMarker.LINE_NUMBER, -1);
+ if (l != null && line == l.intValue()) {
+ fail("Resource Marker is found for type: " + fResourceMarkerType + ",
message: [" + errorMessage + "] at line: " + line);
+ }
+ }
+ }
+ }
}