Author: akazakov
Date: 2010-12-16 10:24:16 -0500 (Thu, 16 Dec 2010)
New Revision: 27551
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreTestSetup.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/CoreValidationTest.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidatorManager.java
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java
Log:
https://issues.jboss.org/browse/JBIDE-7919
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreTestSetup.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreTestSetup.java 2010-12-16
14:34:43 UTC (rev 27550)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/CDICoreTestSetup.java 2010-12-16
15:24:16 UTC (rev 27551)
@@ -14,9 +14,6 @@
import junit.framework.Test;
import org.eclipse.core.resources.IProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.internal.core.JavaModelManager;
-import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
import org.jboss.tools.cdi.core.test.tck.TCKTest;
import org.jboss.tools.test.util.JobUtils;
import org.jboss.tools.test.util.ResourcesUtils;
@@ -26,7 +23,7 @@
*/
public class CDICoreTestSetup extends TestSetup {
- protected IProject tckProject;
+ protected IProject tckProject;
public CDICoreTestSetup(Test test) {
super(test);
@@ -34,7 +31,7 @@
@Override
protected void setUp() throws Exception {
- tckProject = TCKTest .importPreparedProject("/");
+ tckProject = TCKTest.importPreparedProject("/");
}
@Override
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java 2010-12-16
14:34:43 UTC (rev 27550)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/TCKTest.java 2010-12-16
15:24:16 UTC (rev 27551)
@@ -31,11 +31,13 @@
import org.jboss.tools.cdi.core.IParametedType;
import org.jboss.tools.cdi.core.IQualifier;
import org.jboss.tools.cdi.core.IQualifierDeclaration;
+import org.jboss.tools.cdi.core.test.tck.validation.CoreValidationTest;
import org.jboss.tools.cdi.internal.core.impl.CDIProject;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.common.text.ITextSourceReference;
import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager;
import org.jboss.tools.test.util.JobUtils;
import org.jboss.tools.test.util.ResourcesUtils;
import org.osgi.framework.Bundle;
@@ -69,6 +71,7 @@
try {
tckProject = findTestProject();
if(tckProject==null || !tckProject.exists()) {
+ ValidatorManager.setStatus(CoreValidationTest.VALIDATION_STATUS);
tckProject = importPreparedProject("/");
}
} catch (Exception e) {
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/CoreValidationTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/CoreValidationTest.java 2010-12-16
14:34:43 UTC (rev 27550)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/src/org/jboss/tools/cdi/core/test/tck/validation/CoreValidationTest.java 2010-12-16
15:24:16 UTC (rev 27551)
@@ -8,19 +8,21 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
-
package org.jboss.tools.cdi.core.test.tck.validation;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.preference.IPreferenceStore;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.common.preferences.SeverityPreferences;
+import org.jboss.tools.jst.web.kb.internal.validation.ValidatorManager;
/**
* @author Alexey Kazakov
*/
public class CoreValidationTest extends ValidationTest {
+ public static final String VALIDATION_STATUS = "Testing CDI";
+
/**
*
https://jira.jboss.org/browse/JBIDE-6507
*
@@ -28,14 +30,25 @@
*/
public void testDisabledValidator() throws Exception {
IPreferenceStore preferenceStore = CDICorePlugin.getDefault().getPreferenceStore();
- preferenceStore.setValue(SeverityPreferences.ENABLE_BLOCK_PREFERENCE_NAME, false);
- ((IPersistentPreferenceStore)preferenceStore).save();
-
- assertNull("CDICoreValidator is still enabled.", getCDIValidator());
-
- preferenceStore.setValue(SeverityPreferences.ENABLE_BLOCK_PREFERENCE_NAME, true);
- ((IPersistentPreferenceStore)preferenceStore).save();
-
+ try {
+ preferenceStore.setValue(SeverityPreferences.ENABLE_BLOCK_PREFERENCE_NAME, false);
+ ((IPersistentPreferenceStore)preferenceStore).save();
+
+ assertNull("CDICoreValidator is still enabled.", getCDIValidator());
+ } finally {
+ preferenceStore.setValue(SeverityPreferences.ENABLE_BLOCK_PREFERENCE_NAME, true);
+ ((IPersistentPreferenceStore)preferenceStore).save();
+ }
assertNotNull("CDICoreValidator is disabled.", getCDIValidator());
}
+
+ /**
+ *
https://issues.jboss.org/browse/JBIDE-7919
+ *
+ * @throws Exception
+ */
+ public void testValidatorInvoked() throws Exception {
+ String status = ValidatorManager.getStatus();
+ assertNotSame("Validation job has not been run (validation status: " + status
+ ")", VALIDATION_STATUS, status);
+ }
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidatorManager.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidatorManager.java 2010-12-16
14:34:43 UTC (rev 27550)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/internal/validation/ValidatorManager.java 2010-12-16
15:24:16 UTC (rev 27551)
@@ -35,7 +35,10 @@
*/
public class ValidatorManager implements IValidatorJob {
- private static Set<IProject> validatingProjects = new HashSet<IProject>();
+ private static Set<IProject> validatingProjects = new HashSet<IProject>();
+ private static final String SLEEPING = "Sleeping"; //$NON-NLS-1$
+ private static final String RUNNING = "Running"; //$NON-NLS-1$
+ private static String STATUS = SLEEPING;
public ValidatorManager() {
super();
@@ -53,41 +56,46 @@
* @see
org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#validateInJob(org.eclipse.wst.validation.internal.provisional.core.IValidationContext,
org.eclipse.wst.validation.internal.provisional.core.IReporter)
*/
public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws
ValidationException {
- ContextValidationHelper validationHelper = (ContextValidationHelper)helper;
- IProject project = validationHelper.getProject();
- if(project==null) {
- return OK_STATUS;
- }
- IProject rootProject = validationHelper.getValidationContext().getRootProject();
- IStatus status = OK_STATUS;
- synchronized (validatingProjects) {
- if(validatingProjects.contains(rootProject)) {
+ STATUS = RUNNING;
+ try {
+ ContextValidationHelper validationHelper = (ContextValidationHelper)helper;
+ IProject project = validationHelper.getProject();
+ if(project==null) {
return OK_STATUS;
}
- validatingProjects.add(rootProject);
- }
- synchronized (validatingProjects) {
- org.jboss.tools.jst.web.kb.validation.IValidationContext validationContext = null;
- try {
- validationContext = new ValidationContext(project);
- validationHelper.setValidationContext(validationContext);
-
- List<IValidator> validators =
validationHelper.getValidationContext().getValidators();
- Set<IFile> changedFiles = validationHelper.getChangedFiles();
- if(!changedFiles.isEmpty()) {
- status = validate(validators, changedFiles, rootProject, validationHelper,
reporter);
- } else if(!validationContext.getRegisteredFiles().isEmpty()) {
- validationContext.clearAllResourceLinks();
- status = validateAll(validators, rootProject, validationHelper, reporter);
+ IProject rootProject = validationHelper.getValidationContext().getRootProject();
+ IStatus status = OK_STATUS;
+ synchronized (validatingProjects) {
+ if(validatingProjects.contains(rootProject)) {
+ return OK_STATUS;
}
- } finally {
- if(validationContext!=null) {
- validationContext.clearRegisteredFiles();
+ validatingProjects.add(rootProject);
+ }
+ synchronized (validatingProjects) {
+ org.jboss.tools.jst.web.kb.validation.IValidationContext validationContext = null;
+ try {
+ validationContext = new ValidationContext(project);
+ validationHelper.setValidationContext(validationContext);
+
+ List<IValidator> validators =
validationHelper.getValidationContext().getValidators();
+ Set<IFile> changedFiles = validationHelper.getChangedFiles();
+ if(!changedFiles.isEmpty()) {
+ status = validate(validators, changedFiles, rootProject, validationHelper,
reporter);
+ } else if(!validationContext.getRegisteredFiles().isEmpty()) {
+ validationContext.clearAllResourceLinks();
+ status = validateAll(validators, rootProject, validationHelper, reporter);
+ }
+ } finally {
+ if(validationContext!=null) {
+ validationContext.clearRegisteredFiles();
+ }
+ validatingProjects.remove(rootProject);
}
- validatingProjects.remove(rootProject);
}
+ return status;
+ } finally {
+ STATUS = SLEEPING;
}
- return status;
}
private IStatus validate(List<IValidator> validators, Set<IFile>
changedFiles, IProject rootProject, ContextValidationHelper validationHelper, IReporter
reporter) throws ValidationException {
@@ -133,4 +141,20 @@
public void validate(IValidationContext helper, IReporter reporter) throws
ValidationException {
validateInJob(helper, reporter);
}
+
+ /**
+ * This method returns a string with status message of the validator. This method is
supposed to be used in unit tests.
+ * @return
+ */
+ public static String getStatus() {
+ return STATUS;
+ }
+
+ /**
+ * This method is supposed to be used in unit tests.
+ * @param status
+ */
+ public static void setStatus(String status) {
+ STATUS = status;
+ }
}
\ No newline at end of file
Modified:
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java 2010-12-16
14:34:43 UTC (rev 27550)
+++
trunk/tests/plugins/org.jboss.tools.tests/src/org/jboss/tools/tests/AbstractResourceMarkerTest.java 2010-12-16
15:24:16 UTC (rev 27551)
@@ -136,8 +136,22 @@
List<Integer> lines = findMarkerLines(
resource, type, errorMessage, pattern);
- assertFalse("Marker matches the '" + errorMessage + "' pattern
wasn't found", //$NON-NLS-1$ //$NON-NLS-2$
- lines.isEmpty());
+ if(lines.isEmpty()) {
+ IMarker[] allMarkers = findMarkers(resource, null, "*", true);
+ StringBuffer sb = new StringBuffer("Marker matches the '");
//$NON-NLS-1$
+ sb.append(errorMessage).append("' pattern wasn't found. Here is a list of
found markers in ").append(resource.getFullPath().toOSString()).append(" :
[\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
+ int i=0;
+ for (IMarker marker : allMarkers) {
+ String message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
+ marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$
+ int line = marker.getAttribute(IMarker.LINE_NUMBER, -1);
+ String mType = marker.getType();
+ sb.append(i).append(") line: \"").append(line).append("\";
type: \"").append(mType).append("\"; message:
\"").append(message).append("\";\r\n"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ i++;
+ }
+ sb.append("\r\n]"); //$NON-NLS-1$
+ fail(sb.toString());
+ }
assertEquals("Wrong number of found marker matches the '" + errorMessage
+ "' pattern", //$NON-NLS-1$//$NON-NLS-2$
expectedLines.length, lines.size());