Search in sources :

Example 21 with ValidationResult

use of org.eclipse.wst.validation.ValidationResult in project webtools.sourceediting by eclipse.

the class JSPDirectiveValidatorTest method runNegativeTest.

/**
 * The purpose of a validator is to generate messages.  Let us make sure the expected messages are generated.
 * @param filePath
 * @param content
 * @param validator
 * @param expectedProblemMessages
 * @throws Exception
 */
protected void runNegativeTest(String filePath, String content, AbstractValidator validator, String expectedProblemMessages) throws Exception {
    IPath path = new Path(filePath);
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0));
    if (!project.exists()) {
        BundleResourceUtil.createJavaWebProject(path.segment(0));
    }
    ResourcesPlugin.getWorkspace().checkpoint(true);
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    file.create(new ByteArrayInputStream(content.getBytes("utf8")), true, null);
    ValidationResult result = validator.validate(file, IResourceDelta.ADDED, new ValidationState(), new NullProgressMonitor());
    assertEquals(expectedProblemMessages, sortMessages(result.getReporter(new NullProgressMonitor()).getMessages()));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ValidationState(org.eclipse.wst.validation.ValidationState) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) ValidationResult(org.eclipse.wst.validation.ValidationResult) IProject(org.eclipse.core.resources.IProject)

Aggregations

ValidationResult (org.eclipse.wst.validation.ValidationResult)21 IFile (org.eclipse.core.resources.IFile)14 IReporter (org.eclipse.wst.validation.internal.provisional.core.IReporter)9 CoreException (org.eclipse.core.runtime.CoreException)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IResource (org.eclipse.core.resources.IResource)4 IOException (java.io.IOException)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 ValidationState (org.eclipse.wst.validation.ValidationState)3 ValidatorMessage (org.eclipse.wst.validation.ValidatorMessage)3 List (java.util.List)2 Map (java.util.Map)2 IProject (org.eclipse.core.resources.IProject)2 ProjectScope (org.eclipse.core.resources.ProjectScope)2 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)2 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)2 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)2 JSPBatchValidator (org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator)2 JSPContentValidator (org.eclipse.jst.jsp.core.internal.validation.JSPContentValidator)2