Sunday, November 30, 2008

Best of this Week Summary 17 November - 30 November 2008

  • Interesting recent long discussion (with a bit of framework flame-war in between) and tips on when to pick what web client framework. Tapestry, Wicket, Stripes, GWT, Flex seem to jump out.

  • Interesting Javascript optimizer: Razor Optimizer. It dynamically analyzes the runtime profile information, trying to load each Javascript function only when needed, potentially creating 60-90% savings. It does require a client and server component. The question is: are you prepared to take a (small?) risk that your Javascript is dynamically modified?

  • Good article that explains why Scrum often fails as implementation of Agile. Lots of times Scrum is only seen as fast Sprints and Scrums. But: "Don't leave out the 'regular' agile good engineering practices". Check also the comments for good tips.

  • A good introduction to RESTful webservices.

  • Great, soapUI 2.5 now also suppports testing RESTful webservices. It includes testing JSON output.

Thursday, November 20, 2008

JSFUnit static analysis unit testing in ADF

Introduction
Currently I'm working on the framework design of an ADF application in JDeveloper 11.1.1.0.0 (yes sometimes a man's got to do what a man's got to do ;-). One of the parts is how we are going to do (unit) testing. And one of elements in there is testing the JSF part of the ADF application. Application Developer Framework consists of several layers where the View layer consists of a JSF implementation. This JSF implementation is named ADF Faces (RichFaces) and built on top of Trinidad, the open source JSF components implementation. ADF Faces has many components Ajax-ized and has more components than Trinidad.
My eye caught JSFUnit, an open source project from JBoss. I was only able to focus on the static analysis part JSFUnit offers (it offers also other dynamic "regular unit" tests). But little information was found about that. I couldn't find any installation tips for ADF (JBoss here and here, and Websphere setup tips were available).
Thus it was just me and the computer. Here's the steps that in the end did do the job (running on Windows XP).

Setup
A couple of things are needed for all types of static analysis.

  1. Download via JSFUnit Getting Started under the section “Files”: jboss-jsfunit-core-1.0.0.Beta3.jar en jboss-jsfunit-analysis-1.0.0.Beta3.jar

  2. Note that it was not necessary to download/install myfaces-api-1.2.0.jar or JSF 1.2 API.

  3. Start JDeveloper 11.1.1.0.0 and open an ADF application with Model and ViewController project.

  4. Right-click the ViewController project, select Properties and select Libraries and Classpath in the popup. Add the above downloaded jars there.

Three types of static tests are possible with JSFUnit. I'll describe setting up each type seperately. Most information was deducted from this part of the JSFUnit documentation.

Configuration static analysis
These tests test your JSF configuration. See the above mentioned documentation part for examples of what tests are performed.
  1. Create a JUnit testclass in your ViewController project. Modify it such that it matches this example class:


    package test.com.project;

    import java.io.File;
    import java.util.HashSet;
    import java.util.Set;
    import org.jboss.jsfunit.analysis.AbstractFacesConfigTestCase;

    public class JSFUnitStaticAnalysisConfigTest extends AbstractFacesConfigTestCase {

    private static Set paths = new HashSet() {{
    // Example absolute path: add("C:/work/workspace/jsf-unit/src/faces-config.xml");
    // Relative path example below.
    add("public_html\\WEB-INF\\faces-config.xml");
    }};

    public JSFUnitStaticAnalysisConfigTest() {
    super(paths);
    }
    }



    Note the paths variable which points to the faces-config file to validate. Relative paths work too. Of course might not be valid in your test/production environment.

    Tip: notice for easier separation at deployment, I put the test class in a separate package, starting with "test.".

  2. And you're set: run the test. Of course you should see a green bar. If not, your config is probably not 100% ok (probably because what if a JSFUnit test is incorrect... Of course you then immediately contribute to the JSFUnit community project :-). I had for example several Serialization errors.

    Below is a screenshot with the result of running the config testcase:



TLD analysis
These tests test your TLDs. See the above mentioned documentation part for examples of what tests are performed.
  1. Add the dependent libraries mentioned here, at the bottom of the page: maven-taglib and commons-logging. For the commons-logging you can use the one provided by JDeveloper: Commons Logging 1.0.4. The third one, jsp-api-2.1.jar does not seem to be necessary in the ADF project.

  2. Create a JUnit testclass in the ViewController project with .tld files. Modify it such that it matches this example class:


    package test.com.project;

    import java.util.HashSet;
    import java.util.Set;
    import org.jboss.jsfunit.analysis.AbstractTldTestCase;
    import static org.junit.Assert.*;

    public class JSFUnitStaticAnalysisTLDTest extends AbstractTldTestCase {

    private static Set paths = new HashSet() {{
    // Example: add("C:/work/workspace/jsf-unit/src/demo.tld");
    add("C:\\myprojects\\app\\src\\META-INF\\myjsf.tld");
    }};

    public JSFUnitStaticAnalysisTLDTest() {
    super(paths);
    }
    }



    Note the paths variable which points to the .tld to validate. Did not try if a relative path also works.

  3. And you're set: run the test. Of course you should see a green bar. If not, your .tld is probably not 100% ok.

    Below is a screenshot with the result of running the TLD testcase:



View static analysis
These tests test your JSF views. See the above mentioned documentation part for examples of what tests are performed.
  1. No extra libs are needed, so we can immediately create a JUnit testclass in the ViewController project. Modify it such that it matches this example class:


    package test.com.project;

    import java.io.File;
    import java.util.HashSet;
    import java.util.Set;
    import org.jboss.jsfunit.analysis.AbstractFacesConfigTestCase;
    import org.jboss.jsfunit.analysis.AbstractViewTestCase;

    public class JSFUnitStaticAnalysisViewTest extends AbstractViewTestCase {


    private static Set absoluteViewPaths = new HashSet() {{
    // Example: add("C:/work/project/src/home.xhtml");
    add("C:\\myprojects\\app\\mysite\\ViewController\\public_html\\detailsPage.jspx");
    }};

    private static Set recursiveViewPaths = new HashSet() {{
    // Example: add("C:/work/project/src/views");
    add("C:\\myprojects\\app\\mysite\\ViewController\\public_html");
    }};

    public JSFUnitStaticAnalysisViewTest() {
    super(absoluteViewPaths, recursiveViewPaths,
    "public_html\\WEB-INF\\faces-config.xml");
    }

    }



    Note the paths variables. Nowhere I could find what they exactly mean. The above runs a test that passes, so I assume the paths are set correctly...

  2. And you're set: run the test. Of course you should see a green bar. If not, your view is probably not 100% ok.

    Below is a screenshot with the result of running the view testcase:


Conclusion
So that's it. Not hard at all! If you want to know a bit more high level stuff about JSFUnit, check this presentation by the project lead at the Javapolis conference (currently rebranded to Devox conference). And here's another introduction presentation.

The Shale Test Framework could be an interesting alternative for unittesting JSF. Needs some more investigation...

Saturday, November 15, 2008

Best of this Week Summary 04 November - 16 November 2008

Sunday, November 9, 2008

Best of this Week Summary 03 November - 09 November 2008

Saturday, November 1, 2008

Best of this Week Summary 29 October - 02 November 2008