Skip to main content
New Participant
April 27, 2022

AEM Assets JUnit Java Sample

  • April 27, 2022
  • 2 replies
  • 2054 views

Hi ! I'm trying to create a test case JUnit which involves getting the title metadata from image. But so far I can't find any materials or samples of Assets DAM JUnit test cases. Any suggestions will be helpful. Thank you 

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

2 replies

New Participant
April 24, 2023

You can create a new asset at "/content/dam/test-image.jpg" with width, height, mime type "image/jpeg" and image title

Example: 

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

Do not need to load a binary and additional json.

VeenaVikraman
New Participant
April 27, 2022

Could you give the sample code you are trying to test ? Basically the logic of unit testing is mocking everything you want to test. If you have the correct mocks created , your test should basically pass. 

New Participant
April 27, 2022

@veenavikraman please see below

 

public String getImageTitle() {
Resource resource = resolver.getResource(imagePath);
Asset asset = resource.adaptTo(Asset.class);
return asset.getMetadataValue("dc:Title");