How to make a new JCR UseCase test

Prerequisites

  • Make sure you understand how JUnit works :) (http://www.junit.org)
  • Make Test unit extend org.exoplatform.services.jcr.usecases.BaseUsecasesTest
  • Write your tests, to make it simpler you can use pre-initialized class variables: repository, session, root etc.

Recommendations:

  • Use a unique sub-root node name for each case. Use a test method name as a sub-root node name for example.
  • Make sure you remove permanently (i.e. using save()) the test item created for testing either in a test method itself or in tearDown()
  • It is highly recommended to make some comments :)

Example

public class SampleUseCaseTest extends BaseUsecasesTest {
 
  /**
   * Sample test. An example how to make it 
   * @throws Exception
   */
  public void testSomething() throws Exception {
    // make sub-root with a unique name;
    Node subRootNode = root.addNode("testSomething");
    
    // make the structure under subRootNode if you need so...
    subRootNode.setProperty("someProperty", "someValue");
    
    // and save if you need so...
    session.save();
    
    
    // and test 
    this.assertNotNull(subRootNode);
    
    // you have to remove and save it at the end of a method(recommended) or at the 
    // tearDown() as well
    subRootNode.remove();
    session.save();
    
  }
}

How to run JCR UseCase test:

  • Make sure you have uncommented:
<testSourceDirectory>src/test</testSourceDirectory>
  and commented
    <!-- testSourceDirectory>src/TCK</testSourceDirectory -->
  in the /exo-jcr/services/jcr/impl/pom.xml

  • Include your test into maven-surefire-plugin like
....
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <includes>
            <include>**/usecases/SomeTest.java</include>
      ....

NOTE: DO NOT COMMIT pom.xml with YOUR CHANGES PLEASE!

  • Make sure tests are enabled in your_home_dir/.m2/settings.xml:
<exo.test.skip>false</exo.test.skip>
to enable txt output also set

<exo.test.use.file>true</exo.test.use.file>

  • Call mvn clean install in /exo-jcr/services/jcr/impl
  • You can find the test results in the target/surefire-reports folder
Tags:
Created by Gennady Azarenkov on 06/06/2007
Last modified by Oleksandr Tkachenko on 03/20/2008

Products

generated on Thu Sep 02 15:49:50 UTC 2010

eXo Optional Modules

eXo Core Foundations


Copyright (c) 2000-2010. All Rights Reserved - eXo platform SAS
2.4.30451