Advanced Features

Unit Tests

The Merlin platform provides an abstract test case class that you can use as a component factory. To create a Merlin based unit test you simply extend AbstractMerlinTestCase.

To use AbstractMerlinTestCase you should include the following dependency in you maven project definition.

    <dependency>
      <groupId>merlin</groupId>
      <artifactId>merlin-unit</artifactId>
      <version>3.2.6-dev</version>
    </dependency>

The following code fragment declares a new test case using the abstract Merlin test case.

import org.apache.avalon.merlin.unit.AbstractMerlinTestCase;

public class ExampleTestCase extends AbstractMerlinTestCase
{
    public ExampleTestCase( String name )
    {
        super( name );
    }

    // ...
}
        

The default behaviour is to deploy a block based on the deployment path ${basedir}/target/classes/. Merlin will attempt to locate a block.xml file at the [DEPLOYMENT-PATH]/BLOCK-INF/block.xml. To make sure that a block.xml file and component meta-info is available under ${basedir}/target/classes/ you need to include the following resource statement in you maven project descriptor.

  <build>
    <sourceDirectory>${basedir}/src/java/</sourceDirectory>
    <unitTestSourceDirectory>${basedir}/src/test/</unitTestSourceDirectory>
    <resources>
      <resource>
        <directory>${basedir}/conf</directory>
        <targetPath>BLOCK-INF</targetPath>
        <includes>
          <include>block.xml</include>
        </includes>
      </resource>
      <resource>
        <directory>${basedir}/src/java</directory>
        <includes>
          <include>**/*.x*</include>
        </includes>
      </resource>
    </resources>
  </build>

You can now access components established by Merlin via the component path. For example, if your block.xml defines a component named "hello" in a container named "test" you access the component by requesting the path "/test/hello".

The following code fragment demonstrates the usage of the resolve method to locate a named component.

public void testServiceResolution() throws Exception
{
    Hello hello = (Hello) resolve( "/test/hello" );
    assertNotHull( "hello", hello );
}

Customizing Merlin behaviour

You can customize all of the deployment and runtime parameters of the embedded merlin instance by adding a "merlin.properties" file to your basedir.

Example merlin.properties

merlin.info = true
merlin.debug = true
merlin.override = conf/config.xml