I try to test some DAM Assets with a JUnit test in AEM.
At first I copied an existing asset as JSON in a resource file. Next, I use the ContentLoader to write the JSON file into the simulated repository.
final ContentLoader contentLoader = new ContentLoader(this.getResourceResolver());
contentLoader.json("content/assets/testAsset.json", "/content/assets/testAsset");
Then, I use the ResourceResolver to resolve the Resource in the destinationPath.
Resource assetRecource = resourceResolver.resolve("/content/assets/testAsset");
So far so good. When I try to adapt the assetRecource to an Asset.class is the result null.
Asset asset = assetRecource.adaptTo(Asset.class); // is null
In my opinion it's because the missing renditions.
Do someone have an idea how to fix this? Maybe with the ContentLoader#binaryResource()?
testAsset
json has primaryType ofdam:Asset
. You can also try to check the resource that gets resolved has the same resource type. – Abhishek