use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class Validator method validate.
/* (non-Javadoc)
* @see org.eclipse.wst.xml.core.internal.validation.core.AbstractNestedValidator#validate(java.lang.String, java.io.InputStream, org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext)
*/
public ValidationReport validate(String uri, InputStream inputstream, NestedValidatorContext context) {
XSDValidator validator = XSDValidator.getInstance();
XSDValidationConfiguration configuration = (XSDValidationConfiguration) xsdConfigurations.get(context);
ValidationReport valreport = null;
valreport = validator.validate(uri, inputstream, configuration);
return valreport;
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class ValidatorTest method testValidate.
/**
* Test the validate method. Tests to be performed:<br/>
* 1. Test that validating a valid file from a URI or an input stream produces the same result.<br/>
* 2. Test that validating an invalid file from a URI or an input stream produces the same result.
*/
public void testValidate() {
try {
// Test that validating a valid file from a URI and an input stream produces the same result.
String PLUGIN_ABSOLUTE_PATH = XSDValidationTestsPlugin.getInstallURL();
String uri = "file:///" + PLUGIN_ABSOLUTE_PATH + "testresources/samples/Paths/Dash-InPath/DashInPathValid.xsd";
ValidationReport report1 = validator.validate(uri, null, new NestedValidatorContext());
ValidationReport report2 = null;
InputStream is = null;
try {
is = new URL(uri).openStream();
report2 = validator.validate(uri, is, new NestedValidatorContext());
} catch (Exception e) {
fail("A problem occurred while validating a valid file with an inputstream: " + e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Do nothing.
}
}
}
assertTrue("Validation using a URI did not product a valid validation result.", report1.isValid());
assertEquals("Validation using URI and using inputstream of the same file produces different numbers of errors.", report1.getValidationMessages().length, report2.getValidationMessages().length);
// Test that validating an invalid file from a URI and an input stream produces the same result.
uri = "file:///" + PLUGIN_ABSOLUTE_PATH + "testresources/samples/Paths/Dash-InPath/DashInPathInvalid.xsd";
report1 = validator.validate(uri, null, new NestedValidatorContext());
report2 = null;
is = null;
try {
is = new URL(uri).openStream();
report2 = validator.validate(uri, is, new NestedValidatorContext());
} catch (Exception e) {
fail("A problem occurred while validating an invalid file with an inputstream: " + e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Do nothing.
}
}
}
assertFalse("Validation using a URI did not product an invalid validation result.", report1.isValid());
assertEquals("Validation using URI and using inputstream of the same file produces different numbers of errors.", report1.getValidationMessages().length, report2.getValidationMessages().length);
} catch (Exception e) {
fail("Unable to locate plug-in location: " + e);
}
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class BaseTestCase method runTest.
/**
* Run a validator test. The test will run the validator, and compare the validation result with
* the information specified.
*
* @param testfile The file to run the validator test on.
* @param keys The list of allows message keys.
* @param numErrors The number of expected errors.
* @param numWarnings The number of expected warnings.
*/
public void runTest(String testfile, List keys, int numErrors, int numWarnings) {
ValidationReport valreport = validator.validate(testfile, null, configuration);
ValidationMessage[] valmessages = valreport.getValidationMessages();
int nummessages = valmessages.length;
int errorCount = 0;
int warningCount = 0;
for (int i = 0; i < nummessages; i++) {
ValidationMessage valmes = valmessages[i];
String key = valmes.getKey();
assertTrue("The message key " + key + " is not correct.", keys.contains(key));
if (valmes.getSeverity() == ValidationMessage.SEV_LOW) {
warningCount++;
} else {
errorCount++;
}
}
assertEquals(errorCount + " errors were reported but " + numErrors + " errors were expected.", numErrors, errorCount);
assertEquals(warningCount + " warnings were reported but " + numWarnings + " warnings were expected.", numWarnings, warningCount);
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class BaseTestCase method runTest.
/**
* Run a validator test. The test will run the validator, log the results and compare the results
* with the ideal results. The test will only pass if the two log files are the same.
*
* @param testfile
* The file to run the validator test on.
* @param loglocation
* The location to create the log file.
* @param idealloglocation
* The location of the ideal log file.
* @param configuration
* The XSDValidationConfiguration for this validation test.
*/
public void runTest(String testfile, String loglocation, String idealloglocation, XSDValidationConfiguration configuration) {
ValidationReport valreport = validator.validate(testfile, null, configuration);
try {
createLog(loglocation, valreport);
String generatedLog = getStringFromFile(loglocation);
String idealLog = getStringFromFile(idealloglocation);
assertEquals(idealLog, generatedLog);
} catch (Exception e) {
fail("Could not compare log files");
}
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationReport in project webtools.sourceediting by eclipse.
the class LineNumberAdjustmentsTest method runTest.
/**
* Run a validator test. The test will run the validator, and compare the validation result with
* the information specified.
*
* @param testfile
* The file to run the validator test on.
* @param key
* The message key.
* @param numErrors
* The number of expected errors.
* @param numWarnings
* The number of expected warnings.
* @param lineno
* The line number the message should be located on.
* @param columnno
* The column number the message should be located on.
*/
public void runTest(String testfile, String key, int numErrors, int numWarnings, int lineno, int columnno) {
ValidationReport valreport = validator.validate(testfile, null, configuration);
ValidationMessage[] valmessages = valreport.getValidationMessages();
int nummessages = valmessages.length;
int errorCount = 0;
int warningCount = 0;
for (int i = 0; i < nummessages; i++) {
ValidationMessage valmes = valmessages[i];
String messkey = valmes.getKey();
assertTrue("The message key " + key + " is not correct.", key.equals(messkey));
assertEquals("The line number is incorrect.", lineno, valmes.getLineNumber());
assertEquals("The column number is incorrect.", columnno, valmes.getColumnNumber());
if (valmes.getSeverity() == ValidationMessage.SEV_LOW) {
warningCount++;
} else {
errorCount++;
}
}
assertEquals(errorCount + " errors were reported but " + numErrors + " errors were expected.", numErrors, errorCount);
assertEquals(warningCount + " warnings were reported but " + numWarnings + " warnings were expected.", numWarnings, warningCount);
}
Aggregations