Utility libary for easier unit testing of Structure extensions?

16 views
Skip to first unread message

ri...@idalko.com

unread,
Sep 15, 2014, 11:16:38 AM9/15/14
to structure-pl...@googlegroups.com
Hello,

Besides the base Structure API jar, do you also have a Maven dependency available that provides some utility code for easier unit testing my own extension(s) to the Structure plugin? I am thinking in the direction of complete mocked forrests. This would make my life much easier in testing my forrest traversal algorithms.

Greetings,

Ringo

Pavel Zvyagin

unread,
Sep 15, 2014, 11:27:42 PM9/15/14
to structure-pl...@googlegroups.com
Hello Ringo,

Unfortunately there is no such library. In both production and test code we use a single Forest implementation, which is self-contained, and which definitely should have been in the API, but it is not. This is going to change in Structure 3.0, but for the time being there is no easy way to have a working Forest implementation for your tests, apart from adding the entire Structure plug-in JAR to your test classpath. Sorry about that.

What else would you need from such a library? We'll think what we can do.

-- Pavel, ALM Works

ri...@idalko.com

unread,
Sep 16, 2014, 2:00:43 PM9/16/14
to structure-pl...@googlegroups.com
Pavel,


On Tuesday, 16 September 2014 05:27:42 UTC+2, Pavel Zvyagin wrote:

Unfortunately there is no such library. In both production and test code we use a single Forest implementation, which is self-contained, and which definitely should have been in the API, but it is not. This is going to change in Structure 3.0, but for the time being there is no easy way to have a working Forest implementation for your tests, apart from adding the entire Structure plug-in JAR to your test classpath. Sorry about that.

What else would you need from such a library? We'll think what we can do.

So having a Forest implementation available to easily create an in-memory structure would be handy. As unit tests should not go to the database, definitely make sure that mocking is possible at the right locations. This is the case now as most types are interfaces. But when adding classes, one might overlook to decouple it from the storage.

Next to that - not unit testing related - it would be handy to have a Visitor mechanism available for one tree in a forest. Based on issue events, I only need to traverse the tree that single issue is in to update field values, not modify the tree. Having top-down and bottom-up traversals would be welcome.

Ringo  

Pavel Zvyagin

unread,
Sep 19, 2014, 1:31:45 PM9/19/14
to structure-pl...@googlegroups.com
Ringo,

Sorry for the delayed reply. I suggest that you do the following:
  1. Create an in-project Maven repository in your project directory and POM, e.g. as described in this Stack Overflow answer or this blog post.
    <repositories>
      <repository>
        <id>lib</id>
        <url>${project.baseUri}lib</url>
      </repository>
    </repositories>
  2. Download the latest Structure plug-in JAR from the download page.
  3. Install the JAR into the in-project repository. I used this command:
    atlas-mvn install:install-file -DcreateChecksum=true -DgeneratePom=true -DgroupId=com.almworks.jira.structure -DartifactId=structure -Dversion=2.9.0 -Dpackaging=jar -Dfile=/path/to/structure-2.9.0.jar
    and then moved the com/almworks/jira/structure/structure directory from my local repository into the in-project repository.
  4. Add the dependency to your POM:
    <dependency>
      <groupId>com.almworks.jira.structure</groupId>
      <artifactId>structure</artifactId>
      <version>2.9.0</version>
      <scope>test</scope>
    </dependency>
  5. Commit your POM and the in-project repository into your VCS. This way other developers on your team (or yourself in the future) will be able to check out, build and test the code without any additional manipulations.
This will allow you to use com.almworks.jira.structure.services.ArrayForest in your tests. The constructor of ArrayForest takes issue IDs as a com.almworks.integers.LongArray and their depths as a com.almworks.integers.IntArray:
Forest f = new ArrayForest(LongArray.create(100, 200), IntArray.create(0, 0));

For traversing the forest you can use visitParentChildrenUpwards() and foldUpwards() methods in the Forest interface.

I hope this helps.

-- Pavel, ALM Works
Reply all
Reply to author
Forward
0 new messages