GateIn Portal Test Component

Version 5

    The GateIn Test component defines the base class to extend for writing GateIn unit tests.

     

    The base AbstractGateInTest class

    This class is an extension of junit.framework.TestCase and it subclass its runbare method to perform logging of the current unit test which is useful.

     

    The base AbstractKernelTest class

     

    This class is an extension of the AbstractGateInTest class. It allows to define configuration for various important GateIn services such as a Java Content Repository or the Organization service. The goal is to make the configuration reused by other GateIn Portal components.

     

    The exo.portal.component.test artifact is an aggregator for several sub artifacts. The main sub artifacts it the exo.portal.component.test.core artifact that defines the framework part.

     

    The other sub artifacts define services that can be reused during unit test by creating a dependency on the artifact scoped at the test level and also by declaring in the unit test the relevant configuration files.

     

    • JCR test component
      • role : setup a JCR repository with a workspace named portal-test
      • dependency : exo.portal.component.test.jcr
      • path : configuration/jcr/jcr-configuration.xml

    Example of a unit test that needs to use a JCR repository

    The pom.xml section that is relevant for the unit test
      <dependency>
        <groupId>org.exoplatform.portal</groupId>
        <artifactId>exo.portal.component.test.core</artifactId>
        <scope>test</scope>
      </dependency>
    
      <dependency>
        <groupId>org.exoplatform.portal</groupId>
        <artifactId>exo.portal.component.test.jcr</artifactId>
        <scope>test</scope>
      </dependency>
    

     

    The maven dependency import at least the core component and in this exemple the JCR component. It scopes them with the test scope in order to not impact the dependencies provided by the module.

    The unit test code
    @ConfiguredBy({
       // We use the JCR configuration declared by the jcr test component
       @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/jcr/jcr-configuration.xml"),
       // We add custom configuration that contain the services for this unit test only
       @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/test-configuration.xml")
    })
    public class JCRIntegrationTestCase extends AbstractGateInTest
    {
       ...
    }