[129953] Updated XSD validator to use validator jobs API. Removed Validate XSD File action. Added XSD validation unit tests.
diff --git a/tests/org.eclipse.wst.xsd.validation.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.xsd.validation.tests/META-INF/MANIFEST.MF index 356f4c8..c795641 100644 --- a/tests/org.eclipse.wst.xsd.validation.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.wst.xsd.validation.tests/META-INF/MANIFEST.MF
@@ -11,6 +11,8 @@ org.junit, org.eclipse.wst.xml.core, org.eclipse.core.runtime, - org.eclipse.wst.xsd.ui + org.eclipse.wst.xsd.core, + org.eclipse.wst.validation, + org.eclipse.wst.common.uriresolver Eclipse-LazyStart: true Export-Package: org.eclipse.wst.xsd.validation.tests.internal;x-internal:=true
diff --git a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/ValidatorTest.java b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/ValidatorTest.java new file mode 100644 index 0000000..173d1ea --- /dev/null +++ b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/ValidatorTest.java
@@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2001, 2004 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.xsd.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.validation.core.ValidationMessage; +import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport; +import org.eclipse.wst.xsd.validation.tests.internal.XSDValidationTestsPlugin; + +/** + * A test class for the Validator class. + */ +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 "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)); + } + + /** + * 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, 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.xsd"; + 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); + } + } +}
diff --git a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/ValidatorWrapper.java b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/ValidatorWrapper.java new file mode 100644 index 0000000..6822392 --- /dev/null +++ b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/ValidatorWrapper.java
@@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2001, 2004 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.xsd.core.internal.validation.eclipse; + +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; + +/** + * A wrapper class to allow for testing the Validator class. + */ +public class ValidatorWrapper extends Validator +{ + /* (non-Javadoc) + * @see org.eclipse.wst.xsd.core.internal.validation.eclipse.Validator#addInfoToMessage(org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage, org.eclipse.wst.validation.internal.provisional.core.IMessage) + */ + public void addInfoToMessage(ValidationMessage validationMessage, IMessage message) + { + super.addInfoToMessage(validationMessage, message); + } +}
diff --git a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDMessageInfoHelperTest.java b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDMessageInfoHelperTest.java new file mode 100644 index 0000000..dc6eb1a --- /dev/null +++ b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDMessageInfoHelperTest.java
@@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.xsd.core.internal.validation.eclipse; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Test case to test the XSDMessageInfoHelper class. + */ +public class XSDMessageInfoHelperTest extends TestCase +{ + private XSDMessageInfoHelperWrapper helper = new XSDMessageInfoHelperWrapper(); + + /** + * Create a tests suite from this test class. + * + * @return A test suite containing this test class. + */ + public static Test suite() + { + return new TestSuite(XSDMessageInfoHelperTest.class); + } + + /** + * Test that the createMessageInfo method returns {"", ""} 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]); + assertEquals("The nameOrValue returned was not an empty string.", "", messageInfo[1]); + } + + /** + * Test that the createMessageInfo method returns {"", ""} when + * given a non-existant key an null message arguments. + */ + public void testNullKeyAndMessageArguments() + { + String[] messageInfo = helper.createMessageInfo(null, null); + assertEquals("The selection strategy returned was not an empty string.", "", messageInfo[0]); + assertEquals("The nameOrValue returned was not an empty string.", "", messageInfo[1]); + } + + /** + * Test the method getFirstStringBetweenSingleQuotes. There are a few tests: + * 1. Test that a simple string with single quotes 'name' returns name. + * 2. Test that a string with no single quotes returns null. + * 3. Test that a string with a single single quote 'name returns null. + * 4. Test that a string with 3 single quotes 'name'name2' returns name. + */ + public void testGetFirstStringBetweenSingleQuotes() + { + // 1. Test that a simple string with single quotes 'name' returns name. + String result = helper.getFirstStringBetweenSingleQuotes("'name'"); + assertEquals("The returned string was not \"name\" for the string \"'name'\".", "name", result); + + // 2. Test that a string with no single quotes returns null. + result = helper.getFirstStringBetweenSingleQuotes("name"); + assertNull("The returned string was not null for the string \"name\" with no single quotes.", result); + + // 3. Test that a string with a single single quote 'name returns null. + result = helper.getFirstStringBetweenSingleQuotes("'name"); + assertNull("The returned string was not null for the string \"'name\" with one single quote.", result); + + // 4. Test that a string with 3 single quotes 'name'name2' returns name. + result = helper.getFirstStringBetweenSingleQuotes("'name'name2'"); + assertEquals("The returned string was not \"name\" for the string \"'name'name2'\" with 3 single quotes.", "name", result); + } + +}
diff --git a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDMessageInfoHelperWrapper.java b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDMessageInfoHelperWrapper.java new file mode 100644 index 0000000..0442964 --- /dev/null +++ b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDMessageInfoHelperWrapper.java
@@ -0,0 +1,25 @@ +/******************************************************************************* + * 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.xsd.core.internal.validation.eclipse; + +/** + * A wrapper class for the XSDMessageInfoHelper class for testing. + */ +public class XSDMessageInfoHelperWrapper extends XSDMessageInfoHelper +{ + /* (non-Javadoc) + * @see org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDMessageInfoHelper#getFirstStringBetweenSingleQuotes(java.lang.String) + */ + public String getFirstStringBetweenSingleQuotes(String s) + { + return super.getFirstStringBetweenSingleQuotes(s); + } +}
diff --git a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDValidatorTest.java b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDValidatorTest.java new file mode 100644 index 0000000..25a7458 --- /dev/null +++ b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDValidatorTest.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.xsd.core.internal.validation.eclipse; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Test the Eclipse specific XSD validator. + */ +public class XSDValidatorTest 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(XSDValidatorTest.class); + } + + /** + * Test to ensure the URI resolver is not null in the Eclipse + * specific XSD validator. + */ + public void testURIResolverIsRegistered() + { + XSDValidatorWrapper validator = new XSDValidatorWrapper(); + assertNotNull("The URI resolver is null.", validator.getURIResolver()); + } + +}
diff --git a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDValidatorWrapper.java b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDValidatorWrapper.java new file mode 100644 index 0000000..9147eea --- /dev/null +++ b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/core/internal/validation/eclipse/XSDValidatorWrapper.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.xsd.core.internal.validation.eclipse; + +import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; + +/** + * Wrapper for the Eclipse XSD validator class to allow for testing. + */ +public class XSDValidatorWrapper extends XSDValidator +{ + /** + * Constructor. + */ + public XSDValidatorWrapper() + { + 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.xsd.validation.tests/src/org/eclipse/wst/xsd/validation/tests/internal/AllXSDTests.java b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/validation/tests/internal/AllXSDTests.java index 4cf53cf..8eb384a 100644 --- a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/validation/tests/internal/AllXSDTests.java +++ b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/validation/tests/internal/AllXSDTests.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 @@ -10,6 +10,10 @@ *******************************************************************************/ package org.eclipse.wst.xsd.validation.tests.internal; import junit.framework.Test; + +import org.eclipse.wst.xsd.core.internal.validation.eclipse.ValidatorTest; +import org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDMessageInfoHelperTest; +import org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDValidatorTest; /** * The root test suite that contains all other XSD validator test suites. */ @@ -31,6 +35,9 @@ public AllXSDTests() { super("AllXSDTests"); + addTest(ValidatorTest.suite()); + addTest(XSDMessageInfoHelperTest.suite()); + addTest(XSDValidatorTest.suite()); addTest(BugFixesTest.suite()); addTest(PathsTest.suite()); }
diff --git a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/validation/tests/internal/BaseTestCase.java b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/validation/tests/internal/BaseTestCase.java index 0ceaadf..1e5999c 100644 --- a/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/validation/tests/internal/BaseTestCase.java +++ b/tests/org.eclipse.wst.xsd.validation.tests/src/org/eclipse/wst/xsd/validation/tests/internal/BaseTestCase.java
@@ -32,7 +32,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage; import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport; -import org.eclipse.wst.xsd.ui.internal.validation.XSDValidator; +import org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDValidator; /** * Base test case class which provides methods to