[275733] Markup Validation for JSPs is strict on HTML attributes
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPUITestSuite.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPUITestSuite.java
index 6cce0fa..0dcd911 100644
--- a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPUITestSuite.java
+++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPUITestSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2009 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
@@ -26,6 +26,7 @@
import org.eclipse.jst.jsp.ui.tests.partitioning.TestStructuredPartitionerJSP;
import org.eclipse.jst.jsp.ui.tests.registry.AdapterFactoryRegistryTest;
import org.eclipse.jst.jsp.ui.tests.validation.JSPHTMLValidatorTest;
+import org.eclipse.jst.jsp.ui.tests.validation.TestJSPMarkupValidator;
import org.eclipse.jst.jsp.ui.tests.viewer.TestViewerConfigurationJSP;
@@ -62,6 +63,7 @@
addTest(new TestSuite(TestContentDescription.class, "Content Description Tests"));
addTest(new TestSuite(JSPHTMLValidatorTest.class, "JSPHTMLValidatorTest"));
+ addTest(new TestSuite(TestJSPMarkupValidator.class, "TestJSPMarkupValidator"));
// pa_TODO fix this test
//addTest(new TestSuite(JSPSearchTests.class));
}
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/TestJSPMarkupValidator.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/TestJSPMarkupValidator.java
new file mode 100644
index 0000000..614fa2a
--- /dev/null
+++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/TestJSPMarkupValidator.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.jst.jsp.ui.tests.validation;
+
+import junit.framework.TestCase;
+
+import org.eclipse.jface.text.Region;
+import org.eclipse.jst.jsp.ui.internal.validation.JSPMarkupValidator;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.ui.internal.reconcile.validator.IncrementalReporter;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.eclipse.wst.xml.ui.internal.validation.MarkupValidator;
+
+public class TestJSPMarkupValidator extends TestCase {
+ private MarkupValidator fValidator;
+ private IReporter fReporter;
+ private IStructuredDocument fDocument;
+
+ /**
+ * Validates document
+ *
+ * @param contents
+ * contents to set in document
+ * @return true if there was a validation error false otherwise
+ */
+ private boolean validateError(String contents) {
+ fDocument.set(contents);
+ fValidator.validate(new Region(0, fDocument.getLength()), null, fReporter);
+ return fReporter.getMessages().isEmpty();
+ }
+
+ protected void setUp() throws Exception {
+ // just create once
+ if (fValidator == null)
+ fValidator = new JSPMarkupValidator();
+ if (fReporter == null)
+ fReporter = new IncrementalReporter(null);
+ if (fDocument == null)
+ fDocument = StructuredModelManager.getModelManager().createStructuredDocumentFor("onfire.xml", "", null);
+
+ fValidator.connect(fDocument);
+ }
+
+ protected void tearDown() throws Exception {
+ fValidator.disconnect(fDocument);
+ }
+
+ public void testAttributesInEndTag() {
+ // test for error
+ assertTrue("Should get attributes in end tag error", !validateError("<stop></stop drop=\"roll\">"));
+
+ // test for no error
+ assertTrue("Should not get attributes in end tag error", validateError("<stop></stop>"));
+ }
+
+ public void testClosingBracket() {
+ // test for error
+ assertTrue("Should get closing bracket error", !validateError("<stop </stop>"));
+
+ // test for no error
+ assertTrue("Should not get closing bracket error", validateError("<stop></stop>"));
+ }
+
+ public void testEmptyTag() {
+ // test for error
+ assertTrue("Should get empty tag error", !validateError("<>"));
+
+ // test for no error
+ assertTrue("Should not get empty tag error", validateError("<stop></stop>"));
+ }
+
+ public void testAttributeValue() {
+ // test for error
+ assertTrue("Should get attribute missing value error", !validateError("<stop drop=></stop>"));
+
+ // test for no error
+ assertTrue("Should not get attribute has no value error", validateError("<stop drop></stop>"));
+ assertTrue("Should not get attribute missing value error", validateError("<stop drop=\"roll\"></stop>"));
+ }
+
+ public void testSpaceBeforeName() {
+ // test for error
+ assertTrue("Should get tag has space before name error", !validateError("< stop></stop>"));
+
+ // test for no error
+ assertTrue("Should not get tag has space before name error", validateError("<stop></stop>"));
+ }
+
+ public void testQuotesForAttributeValues() {
+ // test for error
+ assertTrue("Should get missing end quote error", !validateError("<stop drop=\"></stop>"));
+ assertTrue("Should get missing end quote error", !validateError("<stop drop=\"roll></stop>"));
+ assertTrue("Should get missing end quote error", !validateError("<stop drop=\'></stop>"));
+
+ // test for no error
+ assertTrue("Should not get missing quotes error", validateError("<stop drop=roll></stop>"));
+ assertTrue("Should not get missing end quote error", validateError("<stop drop=\"\"></stop>"));
+ assertTrue("Should not get missing end quote error", validateError("<stop drop=\"roll\"></stop>"));
+ assertTrue("Should not get missing end quote error", validateError("<stop drop=\'\'></stop>"));
+ assertTrue("Should not get missing quotes error", validateError("<stop drop=\'roll\'></stop>"));
+ }
+}