Version 3

    This is just some random thoughts about testing Java EE, maybe about test systems in general.


    It should be easier to write EE tests, so that we can write more of them with better clarity and succinctness.  We should do for EE deployments what Javassist did for class generation.  For example:

    public void testServlet() {
      WebApp webapp = new WebApp();
      webapp.addServlet("foo", new Servlet());

    Basically, build a model of the deployment and materialize said deployment (ie, create the zip on the filesystem, call the URLDeployer).  Then use the same model to validate the deployment automatically using invariants provided by the model. 


    The model for a servlet would default to just generating a class with a doGet() which return a "success" method.  So the default validation code for a servlet would just check for "success" from the servlet using HTTP.  The validation code for a webapp would query the JMX console to verify things are as expected.  More sophisticated validation would assert these as facts into a working memory for validation by a production rule system.


    To replicate this using the current test suite, you would have to create the servlet class & web.xml, write the ant scripts to package the war, and then finally get to write your test. 


    A little more involved:

    public void testWebAppInSAR() {
      ServiceArchive sar = new ServiceArchive();
      sar.addSubDeployment(new WebApp());
      sar.addSubDeployment(new EAR(new SFSB());

    Each deployment would have dummy descriptors and classes for basic validation of the deployment.


    See also: