What's new in AEM Mocks 2.5.0-2.7.0

The latest 3 versions of wcm.io AEM Mocks provide helpful new features. This blog article summarizes the most interesting ones.

Content Policies

If you are using Core Components and the Template Editor in AEM, you are also depending on Content Policies and have to test your component code with them. AEM Mocks 2.7.0 supports them in a easy way.

Example for creating a content policy on-the-fly using the AemContext:

1 2 3 4 // create a content policy with mapping for resource type context.contentPolicyMapping("app1/componenty/component1", "prop1", "value1", "prop2", 123);

This creates a new content policy for the resource type app1/componenty/component1. If your Sling Model is adapted from a resource with this resource type and injects a content policy it will get the mapping provided with the lines above in the unit test. This makes it easy testing it with different variants.

Advanced image file format support in AEM Mocks

AEM Assets supports a wide range of image file formats, whereas in unit tests with AEM Mocks it was only possible to use GIF, PNG and JPEG in combination with the AEM Layer class.

AEM Mocks 2.7.0 provides also support for TIFF and SVG file formats if you configure additional Java ImageIO plugins in your project as test dependency.

Additionally there is a mock implementation of the AssetStore DAM service and an AssetHandler that supports the old and the new file formats.

Content Fragments

AEM Mocks 2.5.0 comes with a support for Content Fragments (CF) - structured and unstructured ones. Structured CF provide “key-value pairs” and unstructured ones only a text fragment. Both can contain variants.

The ContentBuilder provides convenience methods for creating CFs on-the-fly. Example for creating a structured CF:

1 2 3 4 5 ContentFragment cf = context.create().contentFragmentStructured("/content/dam/cf1", "param1", "value1", "param2", 123, "param3", true, "param4", new String[] { "v1", "v2" });

Example for creating an unstructured CF:

1 2 ContentFragment cf = context.create().contentFragmentText("/content/dam/cf2", "<p>Text</p>", "text/html");

Besides this you can interact with the AEM ContentFragment API, adapting it from a DAM resource and reading and writing content to it or creating variations.

Granite ResourceCollectionManager and ResourceCollection

If you are writing code to test AEM workflow process step implementations it is useful that AEM Mocks 2.6.0 provides now mock implementations of ResourceCollectionManager and ResourceCollection.