1. Start Spring application context for your Tapestry unit tests

    Tapestry has a powerful tool to unit test your pages and services, but how to deal with it when your pages and services use Spring beans ?

    Tapestry PageTester can be extended like the TapestryFilter to provide your own ServiceModuleDef classes.  The tapestry-spring contribution already provides the one needed to load a Spring application context. Then, loading Spring for your unit tests will be as simple as extended the existing PageTester and provide the Tapestry Spring Module Definition class.

    Also, because this module definition uses the servlet application context to get the configuration files location, we will have to mock it. Let’s use Spring MockServletContext for this.

    • Update your maven dependencies to add spring web mock objects
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring-version}</version>
      </dependency>
    
    • Extend Tapestry PageTester, adapt the code below to your needs if you want to provide mock versions of your spring beans or make it more configurable
    public class WookiPageTester extends PageTester
    {
    
     private MockServletContext servletContext;
    
     public WookiPageTester(String appPackage, String appName, String contextPath,
     Class... moduleClasses)
     {
       super(appPackage, appName, contextPath, moduleClasses);
       Registry registry = this.getRegistry();
       // Set Tapestry registry in mock servlet context
       servletContext.setAttribute(TapestryFilter.REGISTRY_CONTEXT_NAME, registry);
     }
    
     public WookiPageTester(String appPackage, String appName)
     {
       super(appPackage, appName);
     }
    
     @Override
     protected ModuleDef[] provideExtraModuleDefs()
     {
       // Set spring configuration files location
       servletContext = new MockServletContext();
       servletContext.addInitParameter("contextConfigLocation", "classpath*:mock-applicationContext.xml");
       return new ModuleDef[] { new SpringModuleDef(servletContext) };
     }
    
    }
    

    Thanks for reading !

  2. Professional Java hosting with Rackspace Cloud Servers

    I always thought that Java hosting solutions were expensive compared to PHP, Python or any other trendy scripting language

    After reading on Tapestry mailing list that Sergey Didenko used Rackspace, which I knew to be the host of Github, we decided to consider it for hosting Wooki.

    Rackspace cloud is, as the name says, a cloud hosting solution. Their “servers” offer start at approximately 10$ a month for one part: 256Mo RAM and 10GB of space disk. You pay for what you use on a hour basis. It means if you want to use a part only for 12 hours, you will only be charged for something like 0,15$.

    Creating a new machine on the cloud is very easy, you choose the operating system, the size (how many parts do you want) and that’s it! Your new machine is build and in the next few minutes you will receive an email with the IP and the root password.

    The good thing is the fact that you can resize your machine whenever you want, i.e. you just made a killer application which is buzzing a lot, you can switch for some days from one part (256RAM/10GB) to four part (1024RAM/40GB) , and then go back to one part. The changes takes effect immediately after rebooting the machine.

    Of course, you have got a lot of additional stuff, like backup management, developer API, iPhone application to manage your servers, rackspace cloud “files” for storing lot of data etc.

    Finally, for Wooki, this solution is nearly perfect, we only need one part to run wookicentral.com. We have the modularity and the control we want over our server, and it’s cheap.