AEM package creation programmatically- writing Junit TC for package creation | Community
Skip to main content
New Participant
September 1, 2023
Solved

AEM package creation programmatically- writing Junit TC for package creation

  • September 1, 2023
  • 1 reply
  • 797 views

Hi All,

      I was creating AEM package programattically for a usecase. while writing the test case for create package method im getting NPE, though all param was not null. Kinldy help on mocking below method for Junit.

method needs to be mocked below : 

packageHelper.createPackage(packageResource, session,PageConstants.DEFAULT_GROUP_NAME, "testPackage", PageConstants.DEFAULT_VERSION,
PackageHelper.ConflictResolution.Replace, packageDefinitionProperties);

 

 

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by EstebanBustamante

Hi, 

 

Assuming `PackageHelper` is from the ACSCommons package, you just need to mock the whole service and then mock the method with exactly the parameters you will be passing in runtime. 


Something like this:

@Mock private PackageHelper packageHelperMock; //Then you can mock the method createPackage when(packageHelperMock.createPackage(.....your expected parameter)).thenReturn(yourExpectedValue);

 

1 reply

EstebanBustamante
EstebanBustamanteAccepted solution
New Participant
September 1, 2023

Hi, 

 

Assuming `PackageHelper` is from the ACSCommons package, you just need to mock the whole service and then mock the method with exactly the parameters you will be passing in runtime. 


Something like this:

@Mock private PackageHelper packageHelperMock; //Then you can mock the method createPackage when(packageHelperMock.createPackage(.....your expected parameter)).thenReturn(yourExpectedValue);

 

Esteban Bustamante
New Participant
September 2, 2023

Hi @estebanbustamante , thanks much for your reply. you're rite... `PackageHelper` was from the ACSCommons package.as shown in the earlier screenshot attached, all param was not null. In the servlet test case file, while debug, im getting mock Jcrpackage as out come. when it reach to actual servlet packagehelper.create(your expected parameter) showing jcrpackage as Null, though all param's were not null.