Question

I am working on a Java project using spring2 and Maven.

I have already incorporated JSLint4Java into Maven, but now find myself needing to do some further validation.

There are a number of core pages in the build i.e. home page, search page etc. that I want to automatically test the final HTML output for specification validity i.e. Valid XHTML 1.1 strict from the Maven build. The html template files that generate the final HTML output are all modularised and separated so validating the components individually will not work as they do not become valid until executed as one.

I do not want to test each of the pages in the build as this would slow it down considerably, my preference would be to have an XML config file with a list of the URL's I wish to run through the validation process.

I have found the Jtidy project, but am unsure of how to incorporate this into the Maven build and get it call specific URLS to validate against.

Has anybody ever done this before? Could someone provide a brief walkthrough of the stages I would need to do this?

Cheers

Was it helpful?

Solution

If JTidy is really what you want, there is a Maven JTidy Plugin. It seems to work on files, not on URLs:

  <build>    
    <plugins> 
      <plugin>    
        <groupId>jtidy</groupId>   
        <artifactId>maven-jtidy-plugin</artifactId>    
        <configuration>    
          <srcdir>src/main/resources/html</srcdir>    
          <destdir>target/html</destdir>    
          <properties>src/main/resources/jtidy.properties</properties>    
        </configuration>
        <executions>
          <execution>    
            <goals>    
              <goal>jtidy</goal>    
            </goals>    
          </execution>    
        </executions>    
      </plugin>    
    </plugins>    
  </build>

Unless the plugin is not doing what you want, I wouldn't recommend using exec() (which would need Tidy installed and thus harm portability).

(EDIT: Actually, I'm not sure of what you are trying to achieve exactly, if you want a fully automated solution or not, if you'll need to automate the deployment of application, etc, but here are some more hints.

For something manual, you could maybe use wget to save the generated HTML. For GET:

wget http://www.mypage.com/index.jsp?foo=bar

Or POST with the --post-data option:

wget http://www.mypage.com/index.jsp --post-data="foo=bar"

And then run JTidy. If you want to automate things, you'll have to deploy your application first with the maven cargo plugin. Then, you could use the Ant's Get Task with the antrun plugin. And finally, perform the jtidy validation.

If you want to validate the generated HTML during the build, you'll need to deploy your application and to run some tool against it. You should look at the w3c-markup-validation-filter. Use the maven cargo plugin to deploy your application with the filter (cargo allows to merge web.xml so you can add the filter only for the validation test) and run a set of basic selenium tests to browse your pages and check if the little box injected by the W3cMarkupValidationFilter into the HTML page is green.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top