The JCR Mock Library makes creating complex content data structures efficient and concise.
A Java Content Repository consists of a tree of content nodes. Each node is related to one or more nodes often in parent/child hierarchical structures. An example would be content about a particular shirt and an associated parent category or a pointer to a matching (and therefore related) pair of pants.
To author unit tests that prove the correctness of business rules that interact with this content is a tedious exercise. It requires some forty to fifty lines of Java code to set up even the simplest of structures – let alone to test anything meaningful.
What we found in our experience implementing content management solutions like Adobe’s Experience Manager is that these tests simply weren’t being authored.
Enter JCR Mock: this library makes creating complex content data structures efficient and concise. Nodes and their relationships are defined in a simple JSON file. A sample excerpt is shown here:
InputStream assetsJsonFile = getClass().getResourceAsStream(“/assets.json”);
Node assetsNode = JcrMockingUtils.createNodesFromJsonFile(assetsJsonFile);
With the assets file in this format:
name: ‘Awesome Shoe’,
description: ‘Description for an awesome shoe’,
name: ‘Awesome Shirt’,
description: ‘Description for an awesome shirt’,
name: ‘Awesome Jeans’,
description: ‘Description for awesome jeans’,
Currently hosted on github here.