Hi All
I'm using aem mocks in my project
Aem mocks version: 5.0.0
Aem mock core version:5.0.0
And i have written a junit test class like below
Private AemContext aemContext = new AemContext
@Before
Public void setup() {
Assest asset = aemContext.create().asset("/content/dam/simple.jpg", 240, 280, "image/jpeg")
}
When I execute the test class.
I get the error
Java.lang.RuntimeExcsption: No asset manager
at io.wcm.tetsing.mock.builder.contentBuilder.asset()
Can some one please help tell me what is the issue??
@Jörg Hoh
Solved! Go to Solution.
Views
Replies
Total Likes
For some reason I don't know why AemContext class is not working with below dependency in AEM6.5.12
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<scope>test</test>
</dependency>
I added junit4 version and I was able to use AemContext class and mock assets in Junits
Below dependency worked for me
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit4</artifactId>
<version>4.1.8</version>
</dependency>
Views
Replies
Total Likes
As the error says, you need to mock the asset manager like this:
@Mock | |
private AssetManager assetManager; |
Reference link: https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle/src/test/java/com/ad...
Hope this helps!
Thanks,
Kiran Vedantam
Check this sample code for creating asset and testing it.
You seem to be using the generic AemContext() instead use the `AemContext(ResourceResolverType.JCR_MOCK)`, which sets the ResourceResolver and be able to adaptTo AssetManager object, which is then used when creating the Asset.
I have an example here that you can refer to
@ExtendWith(AemContextExtension.class) public class AssetTest { AemContext aemContext = new AemContext(ResourceResolverType.JCR_MOCK); @BeforeEach void setup() { asset = aemContext.create().asset("/content/dam/simple.jpg", 240, 280, "image/jpeg"); } private Asset asset; @Test void testAssetPath() { assertEquals(asset.getPath(), "/content/dam/simple.jpg"); } }
Can you help with the dependencies you have added??
The two main dependencies you needed are
<dependency> <groupId>io.wcm</groupId> <artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
</dependency>
<dependency>
<groupId>junit-addons</groupId> <artifactId>junit-addons</artifactId> </dependency>
You may need other dependencies based on your project setup.
What is the uber-jar version you are using?
I'm using a cloud service setup with sdk api, not uber-jar.
For some reason I don't know why AemContext class is not working with below dependency in AEM6.5.12
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<scope>test</test>
</dependency>
I added junit4 version and I was able to use AemContext class and mock assets in Junits
Below dependency worked for me
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit4</artifactId>
<version>4.1.8</version>
</dependency>
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies