Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

gsdenys/junit-server-cmis

Repository files navigation

JUnit Runner for CMIS

Build Status Codacy Badge License Maven Central

This project was developed to help starts a CMIS InMemory Server (described here) in a JUnit Test Case Class.

Using this module you need just annotate the Test Class with the @RunWith(CmisInMemoryRunner.class) Java annotation and the CMIS InMemory will starts itself before first method execution and stop after the last method was executed.

As this module use the CMIS InMemory, all content inserted, deleted or modifyed in a executed class cannot be used in another, because on server shutdown all data will be lost.

Build

To create your own build on JUnit Runner for CMIS, you can execute the follow commands.

To clone project and access the project directory execute:

git clone https://github.com/gsdenys/junit-server-cmis.git

cd junit-server-cmis

To generate the project dist (.jar) you can use a gradle local installation. Execute the follow command:

gradle build -x signArchives

In contrast of local gradle you also can use the wrapper way executing the command:

./gradlew build -x signArchives

this will download and install gradle locally and use it to build the project. After build the .jar file will be created at <project_home>/build/junit-server-cmis-<version>.jar

Notes: Before execute the gradle build command, put in your env the USER and PASSWORD variable initialized with any value.

Usage

To use the JUnit Runner for CMIS you need to import the required libs.

with Gradle

testCompile group: 'com.github.gsdenys', name: 'junit-server-cmis', version: '1.1.2'

with Maven

<dependency>
    <groupId>com.github.gsdenys</groupId>
    <artifactId>junit-server-cmis</artifactId>
    <version>1.1.2</version>
</dependency>

after import, create the test case for your application. To start the CMIS server you just want to add the @RunWith(CmisInMemoryRunner.class) annotation to your test class'.

@RunWith(CmisInMemoryRunner.class)
public class UsageTest {
    @Test
    public void someTest() throws Exception {
        //TODO: Your test code here
    }
}

Once running the Junit Test Case will starts a Jetty server with a deployed CMIS InMemory Server at localhost you can make use of a set of static method that can help diring the test development. Follow you can see all of them:

  • CmisInMemoryRunner.getCmisURI(): returns the CMIS server URI.
  • CmisInMemoryRunner.getCmisPort(): returns the CMIS server port
  • CmisInMemoryRunner.getSession(): returns the CMIS Session for default repository (A1).
  • CmisInMemoryRunner.getSession(String repositoryId): returns the CMIS Session for a repository id passed by parameter. In case of repositoryId was null this method call CmisInMemoryRunner.getSession().

Optionally, you also can define the port that the server will be initiated, the version of CMIS and the Document type that will be used during your tests. To meke these configuration you needs to use the @Configure annotation, that was introduced in 1.1.1 version and upgraded at 2.0.0 version.

Follow you hava a simple example of how to user the @Configure annotation.

@RunWith(CmisInMemoryRunner.class)
@Configure(
    port = 9090,
    cmisVersion = CmisVersion.CMIS_1_1,
    docTypes = {
        @TypeDescriptor(
            file = "cmis-type.json",
            loader = TypeLoader.JSON
        )
    }
)
public class UsageTest {
    @Test
    public void someTest() throws Exception {
        //TODO: Your test code here
    }
}

For now, the unic way to add a document type at Junit Runner for CMIS is using JSON descriptor. Future more will be possible to use Alfresco and Nuxeo model definition.