Search in sources :

Example 1 with ErrorMessageInformation

use of org.eclipse.wst.xml.core.internal.validation.errorcustomization.ErrorCustomizationManager.ErrorMessageInformation 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());
}
Also used : ValidationMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage) ErrorMessageInformation(org.eclipse.wst.xml.core.internal.validation.errorcustomization.ErrorCustomizationManager.ErrorMessageInformation)

Aggregations

ValidationMessage (org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage)1 ErrorMessageInformation (org.eclipse.wst.xml.core.internal.validation.errorcustomization.ErrorCustomizationManager.ErrorMessageInformation)1