Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Utilities to mock Atex' Polopoly's Policy classes using the data model objects the policy classes rely on. Basically it relies on the concepts and code examples explained on Polopoly's Guide on Writing Tests (You'll need a valid Polopoly Support Account'), extends them and creates a fluent API for it.

Any issues? Need more features for your policies? Create an issue, or drop me a line.


Release 1.3

  • Update to new fixpack: 10.16.5-fp2

Release 1.2

  • Fixes to maintain backwards compatibility (gerVersionInfo() remains uncomitted)

Release 1.1

  • Version for Polopoly 10.16 available:
  • Upgrade Polopoly Dependency to 10.16.5-fp1
  • Upgrade Gradle to latest 4.9
  • Add basic functionality to create several versions of the same policy

Release 1.0

  • Versions for Polopoly 10.16 and 10.8 available:
  • Some significant fixes in the mocked content setup regarding external IDs, content lists, and others.
  • Switching bintray organisation to allow some others to release fixes of this library

Release 0.4

  • Add branches for Polopoly 10.8 and 10.14, so there are two artifacts available
  • Add withExternalContentId(...) to allow external ContentIDs for mocked policies
  • Added mocked behavior for getAvailableContentListNames() (thanks to Fabian Oehlmann)
  • Support for Polopoly 10.6 discontinued

Release 0.3

  • Add branches for Polopoly 10.6 and 10.14, so there are two artifacts available. Since 10.6 is discontinued, you can stil grab it here:
  • Type MockPolicyBuilder with Generics, so casting is not necessary any more.
  • Add fluent API to MockPolicyBuilder to add slots
  • Add usage examples in MockPolicyBuilderTest
  • This library is now available on bintray

Basic usage


repositories {
	maven {
		url  ""


Add this to your repositories (or include it in your own nexus/artifactory):


Mocking a policy with a default constructor

The simplest way to created a mocked policy is, for example:

PolicyCMServer policyCMServer = mock(PolicyCMServer.class);
YourArticlePolicy articlePolicy = new MockPolicyBuilder<>(YourArticlePolicy.class, policyCMServer).withMajor(1).build();

All methods as articlePolicy.getContentId() will work. The PolicyCmServer needs to be a mock instance. It will be configured automatically to return the policy if you call policyCmServer.getPolicy() with the corresponding versioned id or content id. contentExists and getContent will be mocked as well.

Mocking content of the model behind the policy

MockPolicyBuilder is creating a new mocked Content to initialize the policy. If you want to configure this content mock to add data, you can create it on your own and give it to the builder later.

Content content = mock(Content.class);
when(content.getContentList("contentListName")).thenReturn(myContentList); // Just an example, you can add content lists using .withContentList(...) easier.
YourArticlePolicy articlePolicy = new MockPolicyBuilder<>(YourArticlePolicy.class, policyCMServer).withMajor(1).withContent(content).build();

This content mock is also used internally to mock the calls to getContentId() and getName().

Mocking child policy values

MockPolicyBuilder uses partial mocking based on Mockito's spy() to mock the child policies. It would be possible to mock the complete Polopoly behaviour with child policies as well, but that requires knowledge of classes and implementation of code not marked as @PublicApi, which I try to avoid and it would bring an huge overhead of code with it.

Assuming the input template of the model of the policy, we are working with, has a dropdown (select box) named "articleType", which should have "type1" as selected value:

YourArticlePolicy articlePolicy = new MockPolicyBuilder<>(YourArticlePolicy.class, policyCMServer).withMajor(1)
    .withSingleValuedChildPolicyValue("articleType", "type1", SelectPolicy.class)

Policies without public default constructor

If the policy you want to mock does not have a public default constructor you can use the InstanceCreator interface.

YourArticlePolicy articlePolicy = new MockPolicyBuilder<>(() -> new YourArticlePolicy(parameterYouNeedForInstantiation), policyCMServer).build();

Creating another version of an existing (mocked) policy

This feature is still very basic. You need to repeat the whole building commands, just call another build method. See the unit test MockPolicyBuilderTest#testCreateNewVersionOfPolicy for details.

		final ContentPolicy contentPolicyPreviousVersion = new MockPolicyBuilder<>(ContentPolicy.class, policyCMServer)
		final ContentPolicy contentPolicyLatestVersion = new MockPolicyBuilder<>(ContentPolicy.class, policyCMServer)
				.withNameChildPolicy("New Name")

Existing child policies or eve the input template are not taken automatically in the new version. The content ID and version including the correct mocking of Policy#getVersionInf() and return values of PolicyCmServer are detected automatically.

Building this project

You will need the polopoly jar from Atex' public maven repositories, so you have to put your credentials for this repository in your ~/.gradle/


After that, you can run ./gradlew build to build the project.

Release and deploy to bintray

./gradlew clean assemble release -Prelease.useAutomaticVersion=true -PpublishUser=<USER> -PpublishKey=<KEY>

Deploying artifact in your own maven repository (nexus, for example)

The build.gradle uses Gradle's publishing plugin. You will have to give the url and credentials for your repository.

./gradlew publish -Prepo="" -PpublishUser=user -PpublishPassword=password


Utilities to mock Atex' Polopoly's Policy classes using the data model objects the policy classes rely on.







No packages published