use of org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage in project webtools.sourceediting by eclipse.
the class ValidatorTest method testAddInfoToMessage.
/**
* Test the addInfoToMessage method. The following tests are performed:<br/>
* 1. When the validation message contains a null key nothing is added to the message.<br/>
* 2. When the message contains the key "ENTIRE_ELEMENT" the three attributes are added
* to the method and the SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE is null.<br/>
* 3. When the message contains the key "EntityNotDeclared" the three attributes are set.
*/
public void testAddInfoToMessage() {
// These strings are common addition information types.
// $NON-NLS-1$
String COLUMN_NUMBER_ATTRIBUTE = "columnNumber";
// $NON-NLS-1$
String SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = "squiggleSelectionStrategy";
// $NON-NLS-1$
String SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = "squiggleNameOrValue";
// Test that the message does not contain the attributes when the method is called
// with a null key.
ValidationMessage validationMessage = new ValidationMessage("", 1, 1, "");
Message message = new Message();
validator.addInfoToMessage(validationMessage, message);
assertNull("COLUMN_NUMBER_ATTRIBUTE was not null for a ValidationMessage with a null key. COLUMN_NUMBER_ATTRIBUTE = " + message.getAttribute(COLUMN_NUMBER_ATTRIBUTE), message.getAttribute(COLUMN_NUMBER_ATTRIBUTE));
assertNull("SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE was not null for a ValidationMessage with a null key. SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = " + message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE), message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE));
assertNull("SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE was not null for a ValidationMessage with a null key. SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = " + message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE), message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE));
// Test that the message contains the three attributes when the key is set to "ElementUnterminated".
ValidationMessage validationMessage2 = new ValidationMessage("", 1, 1, "", "ElementUnterminated", null);
Message message2 = new Message();
validator.addInfoToMessage(validationMessage2, message2);
assertEquals("COLUMN_NUMBER_ATTRIBUTE was correctly set to 1 for a ValidationMessage with the key ENTIRE_ELEMENT. COLUMN_NUMBER_ATTRIBUTE = " + message2.getAttribute(COLUMN_NUMBER_ATTRIBUTE), new Integer(1), message2.getAttribute(COLUMN_NUMBER_ATTRIBUTE));
assertEquals("SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE was not ENTIRE_ELEMENT. SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = " + message2.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE), "ENTIRE_ELEMENT", message2.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE));
assertNull("SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE was not null for a ValidationMessage with the key ENTIRE_ELEMENT. SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = " + message2.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE), message2.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE));
// Test that the message contains the three attributes when the key is set to "EntityNotDeclared".
ValidationMessage validationMessage3 = new ValidationMessage("", 1, 1, "", "EntityNotDeclared", new Object[] { "MyName" });
Message message3 = new Message();
validator.addInfoToMessage(validationMessage3, message3);
assertEquals("COLUMN_NUMBER_ATTRIBUTE was correctly set to 1 for a ValidationMessage with the key EntityNotDeclared. COLUMN_NUMBER_ATTRIBUTE = " + message3.getAttribute(COLUMN_NUMBER_ATTRIBUTE), new Integer(1), message3.getAttribute(COLUMN_NUMBER_ATTRIBUTE));
assertEquals("SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE was not TEXT_ENTITY_REFERENCE. SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = " + message3.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE), "TEXT_ENTITY_REFERENCE", message3.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE));
assertEquals("SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE was not set to MyName for a ValidationMessage with the key EntityNotDeclared. SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = " + message3.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE), "MyName", message3.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE));
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage in project webtools.sourceediting by eclipse.
the class ValidatorTest method testAddInfoToMessage.
/**
* Test the addInfoToMessage method. The following tests are performed:<br/>
* 1. When the validation message contains a null key nothing is added to the message.<br/>
* 2. When the message contains the key "ENTIRE_ELEMENT" the three attributes are added
* to the method and the SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE is null.<br/>
* 3. When the message contains the key "EntityNotDeclared" the three attributes are set.
*/
public void testAddInfoToMessage() {
// These strings are common addition information types.
// $NON-NLS-1$
String COLUMN_NUMBER_ATTRIBUTE = "columnNumber";
// $NON-NLS-1$
String SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = "squiggleSelectionStrategy";
// $NON-NLS-1$
String SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = "squiggleNameOrValue";
// Test that the message does not contain the attributes when the method is called
// with a null key.
ValidationMessage validationMessage = new ValidationMessage("", 1, 1, "");
Message message = new Message();
validator.addInfoToMessage(validationMessage, message);
assertNull("COLUMN_NUMBER_ATTRIBUTE was not null for a ValidationMessage with a null key. COLUMN_NUMBER_ATTRIBUTE = " + message.getAttribute(COLUMN_NUMBER_ATTRIBUTE), message.getAttribute(COLUMN_NUMBER_ATTRIBUTE));
assertNull("SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE was not null for a ValidationMessage with a null key. SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = " + message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE), message.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE));
assertNull("SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE was not null for a ValidationMessage with a null key. SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = " + message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE), message.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE));
// Test that the message contains the three attributes when the key is set to "s4s-elt-character".
ValidationMessage validationMessage2 = new ValidationMessage("", 1, 1, "", "s4s-elt-character", null);
Message message2 = new Message();
validator.addInfoToMessage(validationMessage2, message2);
assertEquals("COLUMN_NUMBER_ATTRIBUTE was correctly set to 1 for a ValidationMessage with the key s4s-elt-character. COLUMN_NUMBER_ATTRIBUTE = " + message2.getAttribute(COLUMN_NUMBER_ATTRIBUTE), new Integer(1), message2.getAttribute(COLUMN_NUMBER_ATTRIBUTE));
assertEquals("SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE was not TEXT. SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = " + message2.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE), "TEXT", message2.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE));
assertEquals("SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE was not an empty string for a ValidationMessage with the key s4s-elt-character. SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = " + message2.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE), "", message2.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE));
// Test that the message contains the three attributes when the key is set to "src-resolve".
ValidationMessage validationMessage3 = new ValidationMessage("'MyName'", 1, 1, "", "src-resolve", null);
Message message3 = new Message();
validator.addInfoToMessage(validationMessage3, message3);
assertEquals("COLUMN_NUMBER_ATTRIBUTE was correctly set to 1 for a ValidationMessage with the key src-resolve. COLUMN_NUMBER_ATTRIBUTE = " + message3.getAttribute(COLUMN_NUMBER_ATTRIBUTE), new Integer(1), message3.getAttribute(COLUMN_NUMBER_ATTRIBUTE));
assertEquals("SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE was not VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE. SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = " + message3.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE), "VALUE_OF_ATTRIBUTE_WITH_GIVEN_VALUE", message3.getAttribute(SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE));
assertEquals("SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE was not set to MyName for a ValidationMessage with the key src-resolve. SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = " + message3.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE), "MyName", message3.getAttribute(SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE));
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage in project webtools.sourceediting by eclipse.
the class ErrorCustomizationManagerTest method testEndElement.
/**
* Test the endElement method with the following tests:
* 1. Check that the last element on the stack is successfully popped.
* 2. Test that an element in a sample namespace produces the expected message.
* 3. Test that an element not in a sample namespace retains its value.
*/
public void testEndElement() {
// 1. Check that the last element on the stack is successfully popped.
String namespace1 = "http://namespace1";
String localname1 = "localname";
ErrorCustomizationManagerWrapper manager = new ErrorCustomizationManagerWrapper();
manager.getElementInformationStack().push(new ElementInformation(namespace1, localname1));
manager.endElement(namespace1, localname1);
assertEquals("1. The stack still contains an element.", 0, manager.getElementInformationStack().size());
// 2. Test that an element in a sample namespace produces the expected message.
String namespace2 = "XMLValidationTestSampleNamespace";
ErrorCustomizationRegistry.getInstance().addErrorMessageCustomizer(namespace2, new SampleErrorMessageCustomizer());
ErrorCustomizationManagerWrapper manager2 = new ErrorCustomizationManagerWrapper();
manager2.getElementInformationStack().push(new ElementInformation(namespace2, localname1));
ErrorMessageInformation emi = manager2.new ErrorMessageInformation();
emi.message = new ValidationMessage("SampleMessage", 1, 2, namespace2);
manager2.setMessageForConsideration(emi);
manager2.endElement(namespace2, localname1);
assertEquals("2. The message was not customized to AAAA. The message is " + emi.message.getMessage(), "AAAA", emi.message.getMessage());
// 3. Test that an element not in a sample namespace retains its value.
String namespace3 = "XMLValidationTestSampleNamespace3";
ErrorCustomizationManagerWrapper manager3 = new ErrorCustomizationManagerWrapper();
manager3.getElementInformationStack().push(new ElementInformation(namespace3, localname1));
ErrorMessageInformation emi2 = manager3.new ErrorMessageInformation();
emi2.message = new ValidationMessage("SampleMessage", 1, 2, namespace3);
manager3.setMessageForConsideration(emi2);
manager3.endElement(namespace3, localname1);
assertEquals("3. The message did not retain its value of SampleMessage. The message is " + emi2.message.getMessage(), "SampleMessage", emi2.message.getMessage());
}
use of org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage 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.ValidationMessage in project webtools.sourceediting by eclipse.
the class BaseTestCase method createNestedMessageString.
private String createNestedMessageString(List nestedMessages, int depth) {
if (nestedMessages != null && nestedMessages.size() > 0) {
String messageString = "";
Iterator nestedMesIter = nestedMessages.iterator();
while (nestedMesIter.hasNext()) {
ValidationMessage nesvalmes = (ValidationMessage) nestedMesIter.next();
for (int i = 0; i < depth; i++) {
messageString += " ";
}
// If the message contains any file references make them relative.
String message = nesvalmes.getMessage();
message = message.replaceAll("'[^']*" + getPluginName() + "[^'/]*/", "'");
message = message.replaceAll("[(][^(]*" + getPluginName() + "[^'/]*/", "[(]");
messageString += ("-> " + message + " [" + nesvalmes.getLineNumber() + ", " + nesvalmes.getColumnNumber() + "]\n");
messageString += createNestedMessageString(nesvalmes.getNestedMessages(), depth + 1);
}
return messageString;
} else {
return "";
}
}
Aggregations