[129953] Updated XML validator to use validator jobs API. Removed Validate XML File action. Added XML validation unit tests.
diff --git a/tests/org.eclipse.wst.xml.validation.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.wst.xml.validation.tests/.settings/org.eclipse.jdt.core.prefs index d35e2c8..e4de90f 100644 --- a/tests/org.eclipse.wst.xml.validation.tests/.settings/org.eclipse.jdt.core.prefs +++ b/tests/org.eclipse.wst.xml.validation.tests/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@ -#Fri May 27 23:42:34 EDT 2005 +#Tue Mar 28 01:45:03 EST 2006 eclipse.preferences.version=1 org.eclipse.jdt.core.builder.cleanOutputFolder=clean org.eclipse.jdt.core.builder.duplicateResourceTask=warning @@ -7,11 +7,21 @@ org.eclipse.jdt.core.circularClasspath=error org.eclipse.jdt.core.classpath.exclusionPatterns=enabled org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning org.eclipse.jdt.core.compiler.problem.deprecation=warning org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning org.eclipse.jdt.core.compiler.problem.fieldHiding=warning org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=error @@ -44,5 +54,6 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=1.3 org.eclipse.jdt.core.incompatibleJDKLevel=ignore org.eclipse.jdt.core.incompleteClasspath=error
diff --git a/tests/org.eclipse.wst.xml.validation.tests/.settings/org.eclipse.jdt.ui.prefs b/tests/org.eclipse.wst.xml.validation.tests/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..18e4aed --- /dev/null +++ b/tests/org.eclipse.wst.xml.validation.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,3 @@ +#Mon Mar 27 18:15:32 EST 2006 +eclipse.preferences.version=1 +internal.default.compliance=default
diff --git a/tests/org.eclipse.wst.xml.validation.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.xml.validation.tests/META-INF/MANIFEST.MF index 17004d1..d863db0 100644 --- a/tests/org.eclipse.wst.xml.validation.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.wst.xml.validation.tests/META-INF/MANIFEST.MF
@@ -11,5 +11,8 @@ Require-Bundle: org.junit, org.eclipse.core.runtime, org.eclipse.wst.xml.core, - org.eclipse.wst.xml.ui + org.eclipse.wst.xml.ui, + org.eclipse.wst.validation, + org.eclipse.core.resources, + org.eclipse.wst.common.uriresolver Eclipse-LazyStart: true
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/XMLValidationConfigurationTest.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/XMLValidationConfigurationTest.java new file mode 100644 index 0000000..91f7f9a --- /dev/null +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/XMLValidationConfigurationTest.java
@@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.xml.core.internal.validation; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Test the XMLValidationConfiguration class. + */ +public class XMLValidationConfigurationTest extends TestCase +{ + XMLValidationConfiguration configuration; + + /** + * Create a tests suite from this test class. + * + * @return A test suite containing this test class. + */ + public static Test suite() + { + return new TestSuite(XMLValidationConfigurationTest.class); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + configuration = new XMLValidationConfiguration(); + } + + + protected void tearDown() throws Exception + { + configuration = null; + super.tearDown(); + } + + + /** + * Test the default setting of the WARN_NO_GRAMMAR feature. + */ + public void testSetWarnNoGrammarFeatureDefault() + { + try + { + assertFalse("The WARN_NO_GRAMMAR feature is not set by default to false.", configuration.getFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR)); + } + catch(Exception e) + { + fail("Unable to set read the WARN_NO_GRAMMAR feature: " + e); + } + } + + /** + * Test setting the WARN_NO_GRAMMAR feature to true. + */ + public void testSetWarnNoGrammarFeatureTrue() + { + try + { + configuration.setFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR, true); + assertTrue("The WARN_NO_GRAMMAR feature is not set to true.", configuration.getFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR)); + } + catch(Exception e) + { + fail("Unable to set WARN_NO_GRAMMAR to true: " + e); + } + } + + /** + * Test setting the WARN_NO_GRAMMAR feature to false. + */ + public void testSetWarnNoGrammarFeatureFalse() + { + try + { + configuration.setFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR, false); + assertFalse("The WARN_NO_GRAMMAR feature is not set to false.", configuration.getFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR)); + } + catch(Exception e) + { + fail("Unable to set WARN_NO_GRAMMAR to false: " + e); + } + } + + /** + * Test setting a feature that doesn't exist. + */ + public void testSetNotExistantFeature() + { + try + { + configuration.setFeature("NON_EXISTANT_FEATURE", false); + fail("Setting a non existant feature did not produce an exception."); + } + catch(Exception e) + { + // The test succeeds if the exception is caught. + } + } + + /** + * Test getting a feature that doesn't exist. + */ + public void testGetNotExistantFeature() + { + try + { + configuration.getFeature("NON_EXISTANT_FEATURE"); + fail("Getting a non existant feature did not produce an exception."); + } + catch(Exception e) + { + // The test succeeds if the exception is caught. + } + } + +}
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/ValidatorTest.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/ValidatorTest.java new file mode 100644 index 0000000..f0a68e7 --- /dev/null +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/ValidatorTest.java
@@ -0,0 +1,186 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.xml.core.internal.validation.eclipse; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.wst.validation.internal.core.Message; +import org.eclipse.wst.xml.core.internal.XMLCorePlugin; +import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; +import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; +import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport; +import org.eclipse.wst.xml.validation.tests.internal.XMLValidatorTestsPlugin; + +public class ValidatorTest extends TestCase +{ + ValidatorWrapper validator = new ValidatorWrapper(); + + /** + * Create a tests suite from this test class. + * + * @return A test suite containing this test class. + */ + public static Test suite() + { + return new TestSuite(ValidatorTest.class); + } + + /** + * 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. + String COLUMN_NUMBER_ATTRIBUTE = "columnNumber"; //$NON-NLS-1$ + String SQUIGGLE_SELECTION_STRATEGY_ATTRIBUTE = "squiggleSelectionStrategy"; //$NON-NLS-1$ + String SQUIGGLE_NAME_OR_VALUE_ATTRIBUTE = "squiggleNameOrValue"; //$NON-NLS-1$ + + // 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)); + } + + /** + * 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 = XMLValidatorTestsPlugin.getPluginLocation().toString() + "/"; + String uri = "file:///" + PLUGIN_ABSOLUTE_PATH + "testresources/samples/XMLExamples/PublicationCatalogue/Catalogue.xml"; + ValidationReport report1 = validator.validate(uri, null, null); + ValidationReport report2 = null; + InputStream is = null; + try + { + is = new URL(uri).openStream(); + report2 = validator.validate(uri, is, null); + } + 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.xml"; + report1 = validator.validate(uri, null, null); + report2 = null; + is = null; + try + { + is = new URL(uri).openStream(); + report2 = validator.validate(uri, is, null); + } + 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); + } + } + + /** + * Test that the warn no grammar preference is read from the XML core preferences. + * There are three tests to perform. + * 1. Test that the default preference is disabled. + * 2. Test that setting the preference to enabled works. + * 3. Test that setting the preference to disabled works. + */ + public void testWarnNoGrammarPreference() + { + // Test that the default preference is disabled. + validator.setupValidation(null); + assertFalse("The default warn no grammar preference is not false.", validator.getWarnNoGrammarPreference()); + + // Test that the preference is read when enabled. + XMLCorePlugin.getDefault().getPluginPreferences().setValue(XMLCorePreferenceNames.WARN_NO_GRAMMAR, true); + validator.setupValidation(null); + assertTrue("The warn no grammar preference is not true when the preference is set to true.", validator.getWarnNoGrammarPreference()); + + + // Test that the preference is read when disabled. + XMLCorePlugin.getDefault().getPluginPreferences().setValue(XMLCorePreferenceNames.WARN_NO_GRAMMAR, false); + validator.setupValidation(null); + assertFalse("The warn no grammar preference is not false when the preference is set to false.", validator.getWarnNoGrammarPreference()); + + } + +}
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/ValidatorWrapper.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/ValidatorWrapper.java new file mode 100644 index 0000000..eb6ad99 --- /dev/null +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/ValidatorWrapper.java
@@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.xml.core.internal.validation.eclipse; + +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext; +import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; + +/** + * This class extends validator to expose the protected methods + * for testing. + */ +public class ValidatorWrapper extends Validator +{ + /* (non-Javadoc) + * @see org.eclipse.wst.xml.core.internal.validation.eclipse.Validator#addInfoToMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage, org.eclipse.wst.validation.internal.provisional.core.IMessage) + */ + protected void addInfoToMessage(ValidationMessage validationMessage, IMessage message) + { + super.addInfoToMessage(validationMessage, message); + } + + /* (non-Javadoc) + * @see org.eclipse.wst.xml.core.internal.validation.eclipse.Validator#setupValidation(org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext) + */ + public void setupValidation(NestedValidatorContext context) + { + super.setupValidation(context); + } + +/** + * Export the warn no grammar preference for testing. + * + * @return The warn no grammar preference. + */ + public boolean getWarnNoGrammarPreference() + { + return warnNoGrammar; + } +}
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLMessageInfoHelperTest.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLMessageInfoHelperTest.java new file mode 100644 index 0000000..4dbf3cb --- /dev/null +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLMessageInfoHelperTest.java
@@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.xml.core.internal.validation.eclipse; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Test case to test the XMLMessageInfoHelper class. + */ +public class XMLMessageInfoHelperTest extends TestCase +{ + private XMLMessageInfoHelper helper = new XMLMessageInfoHelper(); + + /** + * Create a tests suite from this test class. + * + * @return A test suite containing this test class. + */ + public static Test suite() + { + return new TestSuite(XMLMessageInfoHelperTest.class); + } + + /** + * Test that the createMessageInfo method returns {"", null} when + * given a non-existant key and null message arguments. + */ + public void testNotExistantKeyAndNullMessageArguments() + { + String[] messageInfo = helper.createMessageInfo("NON_EXISTANT_KEY", null); + assertEquals("The selection strategy returned was not an empty string.", "", messageInfo[0]); + assertNull("The nameOrValue returned was not null.", messageInfo[1]); + } + + /** + * Test that the createMessageInfo method returns {"", null} when + * given a non-existant key and null message arguments. + */ + public void testNullKeyAndMessageArguments() + { + String[] messageInfo = helper.createMessageInfo(null, null); + assertEquals("The selection strategy returned was not an empty string.", "", messageInfo[0]); + assertNull("The nameOrValue returned was not null.", messageInfo[1]); + } + +}
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidatorTest.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidatorTest.java new file mode 100644 index 0000000..f0055c9 --- /dev/null +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidatorTest.java
@@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.xml.core.internal.validation.eclipse; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Test the Eclipse specific XML validator. + */ +public class XMLValidatorTest extends TestCase +{ + /** + * Create a tests suite from this test class. + * + * @return A test suite containing this test class. + */ + public static Test suite() + { + return new TestSuite(XMLValidatorTest.class); + } + + /** + * Test to ensure the URI resolver is not null in the Eclipse + * specific XML validator. + */ + public void testURIResolverIsRegistered() + { + XMLValidatorWrapper validator = new XMLValidatorWrapper(); + assertNotNull("The URI resolver is null.", validator.getURIResolver()); + } + +}
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidatorWrapper.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidatorWrapper.java new file mode 100644 index 0000000..8e1a096 --- /dev/null +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/core/internal/validation/eclipse/XMLValidatorWrapper.java
@@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.wst.xml.core.internal.validation.eclipse; + +import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; + +/** + * Wrapper for the Eclipse XML validator class to allow for testing. + */ +public class XMLValidatorWrapper extends XMLValidator +{ + /** + * Constructor. + */ + public XMLValidatorWrapper() + { + super(); + } + + /** + * Get the URI resolver registered on the XML validator. + * + * @return The URI resolver registered on the XML validator. + */ + public URIResolver getURIResolver() + { + return uriResolver; + } +}
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/AllXMLTests.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/AllXMLTests.java index 3241439..9f45a44 100644 --- a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/AllXMLTests.java +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/AllXMLTests.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. + * Copyright (c) 2001, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,10 +11,14 @@ package org.eclipse.wst.xml.validation.tests.internal; import junit.framework.Test; + +import org.eclipse.wst.xml.core.internal.validation.XMLValidationConfigurationTest; +import org.eclipse.wst.xml.core.internal.validation.eclipse.ValidatorTest; +import org.eclipse.wst.xml.core.internal.validation.eclipse.XMLMessageInfoHelperTest; +import org.eclipse.wst.xml.core.internal.validation.eclipse.XMLValidatorTest; + /** * The root test suite that contains all other XML validator test suites. - * - * @author Lawrence Mandel, IBM */ public class AllXMLTests extends junit.framework.TestSuite { @@ -34,6 +38,10 @@ public AllXMLTests() { super("XMLTestsTestSuite"); + addTest(XMLValidationConfigurationTest.suite()); + addTest(ValidatorTest.suite()); + addTest(XMLMessageInfoHelperTest.suite()); + addTest(XMLValidatorTest.suite()); addTest(XMLExamplesTest.suite()); addTest(BugFixesTest.suite()); addTest(PathsTest.suite());
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/BaseTestCase.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/BaseTestCase.java index 7adaba0..9bc17c8 100644 --- a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/BaseTestCase.java +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/BaseTestCase.java
@@ -16,9 +16,10 @@ import junit.framework.TestCase; +import org.eclipse.wst.xml.core.internal.validation.XMLValidationConfiguration; import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport; -import org.eclipse.wst.xml.ui.internal.validation.XMLValidator; +import org.eclipse.wst.xml.core.internal.validation.eclipse.XMLValidator; /** @@ -26,8 +27,6 @@ * - create logs * - read from logs * - run log comparison tests - * - * @author Lawrence Mandel, IBM */ public class BaseTestCase extends TestCase { @@ -35,6 +34,7 @@ protected String PLUGIN_ABSOLUTE_PATH; protected String SAMPLES_DIR = "testresources/samples/"; protected XMLValidator validator = XMLValidator.getInstance(); + protected XMLValidationConfiguration configuration; /* (non-Javadoc) * @see junit.framework.TestCase#setUp() @@ -42,6 +42,15 @@ protected void setUp() throws IOException { PLUGIN_ABSOLUTE_PATH = XMLValidatorTestsPlugin.getPluginLocation().toString() + "/"; + configuration = new XMLValidationConfiguration(); + try + { + configuration.setFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR, false); + } + catch(Exception e) + { + fail("Unable to set the feature on the XML validation configuration."); + } } /** @@ -55,7 +64,7 @@ */ public void runTest(String testfile, List keys, int numErrors, int numWarnings) { - ValidationReport valreport = validator.validate(testfile); + ValidationReport valreport = validator.validate(testfile, null, configuration); ValidationMessage[] valmessages = valreport.getValidationMessages(); int nummessages = valmessages.length;
diff --git a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/BugFixesTest.java b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/BugFixesTest.java index dc57b61..62ab48d 100644 --- a/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/BugFixesTest.java +++ b/tests/org.eclipse.wst.xml.validation.tests/src/org/eclipse/wst/xml/validation/tests/internal/BugFixesTest.java
@@ -15,6 +15,8 @@ import junit.framework.Test; import junit.framework.TestSuite; + +import org.eclipse.wst.xml.core.internal.validation.XMLValidationConfiguration; /** * Test class for the XML validator to test bug fixes. * @@ -135,4 +137,35 @@ runTest(testfile, keys, numErrors, numWarnings); } + + /** + * Test /bugfixes/NoGrammar/NoGrammar.xml. + */ + public void testNoGrammar() + { + String testname = "NoGrammar"; + String testfile = FILE_PROTOCOL + PLUGIN_ABSOLUTE_PATH + SAMPLES_DIR + BUGFIXES_DIR + "NoGrammar/" + testname + ".xml"; + List keys = new ArrayList(); + keys.add("NO_GRAMMAR_FOUND"); + int numErrors = 0; + int numWarnings = 1; + + try + { + configuration.setFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR, true); + } + catch(Exception e) + { + fail("Unable to set configuration WARN_NO_GRAMMAR."); + } + runTest(testfile, keys, numErrors, numWarnings); + try + { + configuration.setFeature(XMLValidationConfiguration.WARN_NO_GRAMMAR, false); + } + catch(Exception e) + { + fail("Unable to set configuration WARN_NO_GRAMMAR."); + } + } }
diff --git a/tests/org.eclipse.wst.xml.validation.tests/testresources/samples/bugfixes/NoGrammar/NoGrammar.xml b/tests/org.eclipse.wst.xml.validation.tests/testresources/samples/bugfixes/NoGrammar/NoGrammar.xml new file mode 100644 index 0000000..089c886 --- /dev/null +++ b/tests/org.eclipse.wst.xml.validation.tests/testresources/samples/bugfixes/NoGrammar/NoGrammar.xml
@@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<root> + <child> + <child2/> + </child> +</root> \ No newline at end of file