Search in sources :

Example 1 with WorkbenchContext

use of org.eclipse.wst.validation.internal.operations.WorkbenchContext in project webtools.sourceediting by eclipse.

the class TestHTMLValidator method testRemoveAndAddBackCommentEndTag.

/**
 * Regression test for Bug 285285
 *
 * @see org.eclipse.wst.xml.ui.internal.validation.TestDelegatingSourceValidatorForXML#testRemoveAndAddBackCommentEndTag
 * @see org.eclipse.wst.html.ui.tests.validation.TestHTMLValidator#testRemoveAndAddBackCommentEndTag
 * @see org.eclipse.jst.jsp.ui.tests.validation.JSPHTMLValidatorTest#testRemoveAndAddBackCommentEndTag
 */
public void testRemoveAndAddBackCommentEndTag() throws Exception {
    IFile testFile = null;
    IStructuredModel model = null;
    try {
        // get test file
        testFile = fProject.getFile("RemoveAndAddBackCommentEndTag.html");
        assertTrue("Test file " + testFile + " does not exist", testFile.exists());
        // get the document
        model = StructuredModelManager.getModelManager().getModelForEdit(testFile);
        IStructuredDocument document = model.getStructuredDocument();
        // set up for fValidator
        WorkbenchContext context = new WorkbenchContext();
        List fileList = new ArrayList();
        fileList.add(testFile.getFullPath().toPortableString());
        context.setValidationFileURIs(fileList);
        // validate clean file
        TestReporter reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
        // need to dynamically find where the --> is because
        // its different on unix vs windows because of line endings
        String contents = document.get();
        int endCommentIndex = contents.indexOf("-->");
        // remove -->
        document.replace(endCommentIndex, 3, "");
        // validate file with error
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertTrue("There should be validation errors on " + testFile, reporter.isMessageReported());
        // replace -->
        document.replace(endCommentIndex, 0, "-->");
        // validate clean file
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 2 with WorkbenchContext

use of org.eclipse.wst.validation.internal.operations.WorkbenchContext in project webtools.sourceediting by eclipse.

the class TestHTMLValidator method testInvalidateTagNameThenFix.

/**
 * Regression test for Bug 298472
 */
public void testInvalidateTagNameThenFix() throws Exception {
    IFile testFile = null;
    IStructuredModel model = null;
    try {
        // get test file
        testFile = fProject.getFile("InvalidateTagNameThenFix.html");
        assertTrue("Test file " + testFile + " does not exist", testFile.exists());
        // get the document
        model = StructuredModelManager.getModelManager().getModelForEdit(testFile);
        IStructuredDocument document = model.getStructuredDocument();
        // set up for validator
        WorkbenchContext context = new WorkbenchContext();
        List fileList = new ArrayList();
        fileList.add(testFile.getFullPath().toPortableString());
        context.setValidationFileURIs(fileList);
        // validate clean file
        TestReporter reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
        // need to dynamically find where the --> is because
        // its different on unix vs windows because of line endings
        String contents = document.get();
        int endOfStartTagIndex = contents.indexOf("></div>");
        // change to <divx></div>
        document.replace(endOfStartTagIndex, 0, "x");
        // validate file with error
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertTrue("There should be validation errors on " + testFile, reporter.isMessageReported());
        // change back to <div></div>
        document.replace(endOfStartTagIndex, 1, "");
        // validate clean file
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 3 with WorkbenchContext

use of org.eclipse.wst.validation.internal.operations.WorkbenchContext in project webtools.sourceediting by eclipse.

the class JSPHTMLValidatorTest method testRemoveAndAddBackCommentEndTag.

/**
 * Regression test for Bug 285285
 *
 * @see org.eclipse.wst.xml.ui.internal.validation.TestDelegatingSourceValidatorForXML#testRemoveAndAddBackCommentEndTag
 * @see org.eclipse.wst.html.ui.tests.validation.TestHTMLValidator#testRemoveAndAddBackCommentEndTag
 * @see org.eclipse.jst.jsp.ui.tests.validation.JSPHTMLValidatorTest#testRemoveAndAddBackCommentEndTag
 */
public void testRemoveAndAddBackCommentEndTag() throws Exception {
    JSPContentSourceValidator fValidator = new JSPContentSourceValidator();
    String projectName = "RemoveAndAddBackCommentEndTag";
    IProject project = ProjectUtil.createProject(projectName, JSPUITestsPlugin.getDefault().getStateLocation().append(getName()), null);
    IFile testFile = null;
    IStructuredModel model = null;
    try {
        // get test file
        ProjectUtil.copyBundleEntriesIntoWorkspace("testfiles/RemoveAndAddBackCommentEndTag", projectName);
        testFile = project.getFile("Test1.jsp");
        assertTrue("Test file " + testFile + " does not exist", testFile.exists());
        // get the document
        model = StructuredModelManager.getModelManager().getModelForEdit(testFile);
        IStructuredDocument document = model.getStructuredDocument();
        // set up for fValidator
        WorkbenchContext context = new WorkbenchContext();
        List fileList = new ArrayList();
        fileList.add(testFile.getFullPath().toPortableString());
        context.setValidationFileURIs(fileList);
        // validate clean file
        TestReporter reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
        // need to dynamically find where the --> is because
        // its different on unix vs windows because of line endings
        String contents = document.get();
        int endCommentIndex = contents.indexOf("-->");
        // remove -->
        document.replace(endCommentIndex, 3, "");
        // validate file with error
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertTrue("There should be validation errors on " + testFile, reporter.isMessageReported());
        // replace -->
        document.replace(endCommentIndex, 0, "-->");
        // validate clean file
        reporter = new TestReporter();
        fValidator.validate(context, reporter);
        assertFalse("There should be no validation errors on " + testFile, reporter.isMessageReported());
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
    project.delete(true, null);
}
Also used : IFile(org.eclipse.core.resources.IFile) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ArrayList(java.util.ArrayList) List(java.util.List) JSPContentSourceValidator(org.eclipse.jst.jsp.ui.internal.validation.JSPContentSourceValidator) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IProject(org.eclipse.core.resources.IProject)

Example 4 with WorkbenchContext

use of org.eclipse.wst.validation.internal.operations.WorkbenchContext in project webtools.sourceediting by eclipse.

the class TestDelegatingSourceValidatorForXSL method testXSL20Transform.

@Test
public void testXSL20Transform() throws Exception {
    String fileName = "XSLT20Transform.xsl";
    WorkbenchContext context = setupFile(getxslTestFilesProjectName(), fileName);
    TestReporter reporter = new TestReporter();
    sourceValidator.validate(context, reporter);
    assertFalse("Errors reported with XSLT 2.0 with Transform statement: " + fileName + ".", reporter.isMessageReported());
}
Also used : WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) Test(org.junit.Test) AbstractXSLUITest(org.eclipse.wst.xsl.ui.tests.AbstractXSLUITest)

Example 5 with WorkbenchContext

use of org.eclipse.wst.validation.internal.operations.WorkbenchContext in project webtools.sourceediting by eclipse.

the class TestDelegatingSourceValidatorForXSL method setupFile.

protected WorkbenchContext setupFile(String projName, String fileName1) {
    String validateFilePath = projName + File.separator + fileName1;
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(validateFilePath));
    if (file != null && !file.exists()) {
        fail("Unable to locate " + fileName1 + " stylesheet.");
    }
    WorkbenchContext context = new WorkbenchContext();
    List fileList = new ArrayList();
    fileList.add(File.separator + validateFilePath);
    context.setValidationFileURIs(fileList);
    return context;
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) WorkbenchContext(org.eclipse.wst.validation.internal.operations.WorkbenchContext) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

WorkbenchContext (org.eclipse.wst.validation.internal.operations.WorkbenchContext)14 ArrayList (java.util.ArrayList)8 List (java.util.List)8 IFile (org.eclipse.core.resources.IFile)7 AbstractXSLUITest (org.eclipse.wst.xsl.ui.tests.AbstractXSLUITest)6 Test (org.junit.Test)6 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 IProject (org.eclipse.core.resources.IProject)4 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)4 ValidationException (org.eclipse.wst.validation.internal.core.ValidationException)4 Path (org.eclipse.core.runtime.Path)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 JSPContentSourceValidator (org.eclipse.jst.jsp.ui.internal.validation.JSPContentSourceValidator)1