Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Junit test case - Creating packages


Level 4

I am trying to create Junit test case for creating packages. I have used link for this. PFB my service and Junit code. I am getting an exception for creating package which i have mentioned below.


Any help would be great. Thanks in advance!!



javax.jcr.RepositoryException: not allowed on new item



at org.apache.jackrabbit.vault.packaging.impl.JcrPackageImpl.createNew(

at org.apache.jackrabbit.vault.packaging.impl.JcrPackageManagerImpl.create(


Service Code:


     private Packaging packaging;

     public void createPackage(Node rootNode, String pkgName) {
        JcrPackageManager jcrPackageManager = packaging.getPackageManager(session);
        JcrPackage jcrPackage = jcrPackageManager.create(rootNode, pkgName);
		JcrPackageDefinition jcrPackageDefinition = jcrPackage.getDefinition();
		DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter();
		for (PathFilterSet packageFilter : packageFilters) {
		jcrPackageDefinition.setFilter(workspaceFilter, AUTO_SAVE); 
		jcrPackageDefinition.set(JcrPackageDefinition.PN_DESCRIPTION, PACKAGE_DESCRIPTION + pkgName, false);
		jcrPackageDefinition.set(JcrPackageDefinition.PN_GROUP, rootNode.getName() , false);
		jcrPackageManager.assemble(jcrPackage, listener);



Junit Code:

@ExtendWith({AemContextExtension.class, MockitoExtension.class})
class CreateComplianceFileProcessTest {

	public final AemContext context = new AemContext(ResourceResolverType.JCR_OAK);

	private CreateComplianceFileProcess createCompFileWP;

	void testExecute() {
	        resolver = context.resourceResolver();
			session = resolver.adaptTo(Session.class);
			when(packaging.getPackageManager(any(Session.class))).thenReturn(new JcrPackageManagerImpl(session));
            createCompFileWP.execute(item, null, null);


1 Reply


Community Advisor
Hi, I would like to help you but reproducing the error locally is going to be very time-consuming. Could you provide a Java class and test that emulate this issue that I can just copy-paste?