Expand my Community achievements bar.

SOLVED

Need help for writing unit test case for exceltojson servlet

Avatar

Level 1

 

  • Creating an Asset: I want to create an asset using AemContext without using InjectMocks. Could anyone provide a sample code snippet or guidelines on how to achieve this?

  • Handling Excel Files in Tests: I need to place an Excel file in the test resources of my IntelliJ project and load it in my test cases. What’s the best way to do this? Any recommendations on file placement and loading mechanisms would be appreciated.

Example excel file is attached below

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi, 

 

1. For creating an Asset you could use something like this:

Asset asset = context.create().asset("/content/dam/myImage.jpg", 1600, 900, "image/jpeg", "dc:title", "title metadata for image");

Here is another example: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/junit-for-dam-asset/m-p/59... 

 

2. You can create a "resources" folder under your test folder, something similar to this:

EstebanBustamante_0-1728915774242.png

This will be available in your classPath if you use context().load() https://wcm.io/testing/aem-mock/usage-content-loader-builder.html, otherwise you can check this: https://stackoverflow.com/questions/28673651/how-to-get-the-path-of-src-test-resources-directory-in-... 

 

Hope this helps



Esteban Bustamante

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi, 

 

1. For creating an Asset you could use something like this:

Asset asset = context.create().asset("/content/dam/myImage.jpg", 1600, 900, "image/jpeg", "dc:title", "title metadata for image");

Here is another example: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/junit-for-dam-asset/m-p/59... 

 

2. You can create a "resources" folder under your test folder, something similar to this:

EstebanBustamante_0-1728915774242.png

This will be available in your classPath if you use context().load() https://wcm.io/testing/aem-mock/usage-content-loader-builder.html, otherwise you can check this: https://stackoverflow.com/questions/28673651/how-to-get-the-path-of-src-test-resources-directory-in-... 

 

Hope this helps



Esteban Bustamante

Avatar

Administrator

@LIKHITHASS Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni