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);
}
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());
}
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());
}
}
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;
}
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);
}
Aggregations