Static analysis is in the verification of properties of software used in safety-critical computer systems and locating potentially vulnerable/buggy code. it is desirable to make your build fails at compile/test phases to detect faults earlier. Thanks to JSFUnit and Maven, you’ll be able to plug a JSF checker in your build with no effort.
JSFUnit is a test framework for JSF applications. It is designed to allow complete integration testing and unit testing of JSF applications using a simplified API. JSFUnit tests run inside the container, which provides the developer full access to managed beans, the FacesContext, EL Expressions, and the internal JSF component tree. At the same time, you also have access to parsed HTML output of each client request.
JSFUnit provides a set of unit tests for static analysis of JSF applications. Compare to JSFUnit, you can run these tests without any container, in Maven phase “test” like any regular Unit Test
Views tests (JSFUnitStaticAnalysisViewTest.java)
Faces-configurations tests (JSFUnitStaticAnalysisFacesConfigTest.java)
TLD tests (JSFUnitStaticAnalysisFacesConfigTest.java)
Put the following in your web project pom.xml (the pom.xml with <packaging>war</packaging>) between <dependencies> .. </dependencies>, Note that this dependency is only available in scope “test”
<dependencies> <dependency> <groupId>org.jboss.jsfunit</groupId> <artifactId>jboss-jsfunit-analysis</artifactId> <version>1.0.0.GA</version> <scope>test</scope> </dependency> <!-- TLD test dependencies below, for View and facesConfig not needed--> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>test</scope> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> <scope>test</scope> </dependency> <dependency> <groupId>maven-taglib</groupId> <artifactId>maven-taglib-plugin</artifactId> <version>1.4.2</version> <scope>test</scope> </dependency> </dependencies>
Add the following repository in your pom, settings.xml or your Maven proxy repository (Artifactory for example).
<Repositories> <Repository> <id>jboss</id> <url>http://repository.jboss.com/maven2/</url> </Repository> </Repositories>
and
<PluginRepositories> <PluginRepository> <id>taglib</id> <url>http://maven-taglib.sourceforge.net/maven</url> </PluginRepository> </PluginRepositories>
package com.waltercedric.jsfunit; import java.util.HashSet; import java.util.Set; import org.jboss.jsfunit.analysis.AbstractViewTestCase; public class JSFUnitStaticAnalysisViewTest extends AbstractViewTestCase { private static Set absoluteViewPaths = new HashSet<String>() { { // add("C:/work/project/src/home.xhtml"); } }; private static Set recursiveViewPaths = new HashSet<String>() { { add("src/main/resources/pages"); add("src/main/resources/bottom"); add("src/main/resources/top"); add("src/main/resources/menu"); } }; public JSFUnitStaticAnalysisViewTest() { super(absoluteViewPaths, recursiveViewPaths, "src/main/resources/META-INF/faces-config.xml"); } }
package com.waltercedric.jsfunit; import java.util.HashSet; import java.util.Set; import org.jboss.jsfunit.analysis.AbstractFacesConfigTestCase; public class JSFUnitStaticAnalysisFacesConfigTest extends AbstractFacesConfigTestCase { private static Set<String> paths = new HashSet<String>() { { add("src/main/resources/META-INF/faces-config.xml"); } }; public JSFUnitStaticAnalysisFacesConfigTest() { super(paths); } }
package com.waltercedric.jsfunit; import java.util.HashSet; import java.util.Set; import org.jboss.jsfunit.analysis.AbstractTldTestCase; public class JSFUnitStaticAnalysisTldTest extends AbstractTldTestCase { private static Set<String> paths = new HashSet<String>() { { add("src/main/resources/META-INF/facelets.core.taglib.xml"); } }; public TldTestCase() { super(paths); } }
Privacy Statement | Copyright Notice | Licenses
© 1999-2012 Waltercedric.com. Designed by Cédric Walter. Sitemap
Reproduction without explicit permission is prohibited. All Rights Reserved. All photos remain copyright © their rightful owners. No copyright infringement is intended.
Disclaimer: The editor(s) reserve the right to edit any comments that are found to be abusive, offensive, contain profanity, serves as spam, is largely self-promotional, or displaying attempts to harbour irrelevant text links for any purpose.