Search in sources :

Example 1 with ValidationException

use of org.eclipse.wst.validation.internal.core.ValidationException in project webtools.sourceediting by eclipse.

the class TestDelegatingSourceValidatorForXML method testValidateAgainstDTD.

/**
 * Regression test for Bug 276337
 */
public void testValidateAgainstDTD() throws Exception {
    String projectName = "TestValidateAgainstDTD";
    IProject project = ProjectUtil.createProject(projectName, XMLUITestsPlugin.getDefault().getStateLocation().append(getName()), null);
    IFile testFile = null;
    try {
        // get test file
        ProjectUtil.copyBundleEntriesIntoWorkspace("testresources/TestValidateAgainstDTD", projectName);
        testFile = project.getFile("simple.xml");
        assertTrue("Test file " + testFile + " does not exist", testFile.exists());
        // set up for validator
        WorkbenchContext context = new WorkbenchContext();
        List fileList = new ArrayList();
        fileList.add(testFile.getFullPath().toPortableString());
        context.setValidationFileURIs(fileList);
        // validate file, there should be one error
        TestReporter reporter = new TestReporter();
        sourceValidator.validate(context, reporter);
        assertFalse("There should be an error message reported for not conforming to the DTD " + testFile, !reporter.isMessageReported());
    } catch (ValidationException e) {
        fail("Could not validate test file " + testFile + ": " + e.getMessage());
    }
    project.delete(true, null);
}
Also used : IFile(org.eclipse.core.resources.IFile) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IProject(org.eclipse.core.resources.IProject)

Example 2 with ValidationException

use of org.eclipse.wst.validation.internal.core.ValidationException in project webtools.sourceediting by eclipse.

the class TestDelegatingSourceValidatorForXML method testNon8BitChars.

/**
 * Test that files that contain non-8bit chars are validated
 * correctly. i.e. Do not produce incorrect validation messages.
 */
public void testNon8BitChars() {
    String projName = "Project";
    String fileName1 = "international-instance.xml";
    String fileName2 = "international.xsd";
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName);
    if (!project.isAccessible()) {
        IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(projName);
        try {
            project.create(description, new NullProgressMonitor());
            project.open(new NullProgressMonitor());
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(projName + "/" + fileName1));
    if (file != null && !file.exists()) {
        try {
            file.create(FileLocator.openStream(XMLUITestsPlugin.getDefault().getBundle(), new Path("/testresources/Non8BitChars/international-instance.xml"), false), true, new NullProgressMonitor());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(projName + "/" + fileName2));
    if (file != null && !file.exists()) {
        try {
            file.create(FileLocator.openStream(XMLUITestsPlugin.getDefault().getBundle(), new Path("/testresources/Non8BitChars/international.xsd"), false), true, new NullProgressMonitor());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    WorkbenchContext context = new WorkbenchContext();
    List fileList = new ArrayList();
    fileList.add("/" + projName + "/" + fileName1);
    context.setValidationFileURIs(fileList);
    TestReporter reporter = new TestReporter();
    try {
        sourceValidator.validate(context, reporter);
    } catch (ValidationException e) {
        e.printStackTrace();
    }
    assertFalse("Messages were reported on valid file 1.", reporter.isMessageReported());
    WorkbenchContext context2 = new WorkbenchContext();
    List fileList2 = new ArrayList();
    fileList2.add("/" + projName + "/" + fileName2);
    context2.setValidationFileURIs(fileList2);
    TestReporter reporter2 = new TestReporter();
    try {
        sourceValidator.validate(context2, reporter2);
    } catch (ValidationException e) {
        e.printStackTrace();
    }
    assertFalse("Messages were reported on valid file 2.", reporter2.isMessageReported());
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ValidationException

use of org.eclipse.wst.validation.internal.core.ValidationException in project webtools.sourceediting by eclipse.

the class TestDelegatingSourceValidatorForXSL method testDelegatingSourceValidatorNPEwithNoAttributeValue.

@Test
public void testDelegatingSourceValidatorNPEwithNoAttributeValue() throws Exception {
    WorkbenchContext context = setupFile(getxslTestFilesProjectName(), "bug272760.xsl");
    TestReporter reporter = new TestReporter();
    try {
        sourceValidator.validate(context, reporter);
    } catch (ValidationException e) {
    } catch (NullPointerException e) {
        StringWriter out = new StringWriter();
        e.printStackTrace(new PrintWriter(out));
        fail(out.toString());
    }
}
Also used : ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) StringWriter(java.io.StringWriter) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) AbstractXSLUITest(org.eclipse.wst.xsl.ui.tests.AbstractXSLUITest)

Example 4 with ValidationException

use of org.eclipse.wst.validation.internal.core.ValidationException in project webtools.sourceediting by eclipse.

the class JSPBatchValidator method validateInJob.

public IStatus validateInJob(final IValidationContext helper, final IReporter reporter) throws ValidationException {
    Job currentJob = Job.getJobManager().currentJob();
    ISchedulingRule rule = null;
    if (currentJob != null) {
        rule = currentJob.getRule();
    }
    IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            try {
                doValidate(helper, reporter);
            } catch (ValidationException e) {
                throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID_JSP_CORE, 0, PLUGIN_ID_JSP_CORE, e));
            }
        }
    };
    try {
        JavaCore.run(validationRunnable, rule, new NullProgressMonitor());
    } catch (CoreException e) {
        if (e.getCause() instanceof ValidationException) {
            throw (ValidationException) e.getCause();
        }
        throw new ValidationException(new LocalizedMessage(IMessage.ERROR_AND_WARNING, e.getMessage()), e);
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) CoreException(org.eclipse.core.runtime.CoreException) IValidatorJob(org.eclipse.wst.validation.internal.provisional.core.IValidatorJob) Job(org.eclipse.core.runtime.jobs.Job) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 5 with ValidationException

use of org.eclipse.wst.validation.internal.core.ValidationException in project webtools.sourceediting by eclipse.

the class TestDelegatingSourceValidatorForXML method testRemoveAndAddBackCommentEndTag.

/**
 * Regression test for Bug 285285
 *
 * @see org.eclipse.wst.xml.ui.internal.validation.TestDelegatingSourceValidatorForXML#testRemoveAndAddBackCommentEndTag
 * @see org.eclipse.wst.html.ui.tests.validation.TestHTMLValidator#testRemoveAndAddBackCommentEndTag
 * @see org.eclipse.jst.jsp.ui.tests.validation.JSPHTMLValidatorTest#testRemoveAndAddBackCommentEndTag
 */
public void testRemoveAndAddBackCommentEndTag() throws Exception {
    String projectName = "RemoveAndAddBackCommentEndTag";
    IProject project = ProjectUtil.createProject(projectName, XMLUITestsPlugin.getDefault().getStateLocation().append(getName()), null);
    IFile testFile = null;
    IStructuredModel model = null;
    try {
        // get test file
        ProjectUtil.copyBundleEntriesIntoWorkspace("testresources/RemoveAndAddBackCommentEndTag", projectName);
        testFile = project.getFile("Test1.xml");
        assertTrue("Test file " + testFile + " does not exist", testFile.exists());
        // get the document
        model = StructuredModelManager.getModelManager().getModelForEdit(testFile);
        IStructuredDocument document = model.getStructuredDocument();
        // set up for validator
        WorkbenchContext context = new WorkbenchContext();
        List fileList = new ArrayList();
        fileList.add(testFile.getFullPath().toPortableString());
        context.setValidationFileURIs(fileList);
        // validate clean file
        TestReporter reporter = new TestReporter();
        sourceValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
        // need to dynamically find where the --> is because
        // its different on unix vs windows because of line endings
        String contents = document.get();
        int endCommentIndex = contents.indexOf("-->");
        // remove -->
        document.replace(endCommentIndex, 3, "");
        // validate file with error
        reporter = new TestReporter();
        sourceValidator.validate(context, reporter);
        assertTrue("There should be validation errors on " + testFile, reporter.isMessageReported());
        // replace -->
        document.replace(endCommentIndex, 0, "-->");
        // validate clean file
        reporter = new TestReporter();
        sourceValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
    } catch (ValidationException e) {
        fail("Could not validate test file " + testFile + ": " + e.getMessage());
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
    project.delete(true, null);
}
Also used : IFile(org.eclipse.core.resources.IFile) ValidationException(org.eclipse.wst.validation.internal.core.ValidationException) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IProject(org.eclipse.core.resources.IProject)

Aggregations

ValidationException (org.eclipse.wst.validation.internal.core.ValidationException)5 WorkbenchContext (org.eclipse.wst.validation.internal.operations.WorkbenchContext)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Path (org.eclipse.core.runtime.Path)1 Status (org.eclipse.core.runtime.Status)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 Job (org.eclipse.core.runtime.jobs.Job)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1