Hello,
I have a test workflow written in aem where i need to get the Asset
where the java test case is written as:
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
//import com.day.cq.dam.api.Asset; //if i am using this import then its working fine
import com.adobe.granite.asset.api.Asset; //but i want for this import
import com.adobe.granite.workflow.WorkflowException;
import io.wcm.testing.mock.aem.junit5.*;
@ExtendWith({ AemContextExtension.class, MockitoExtension.class })
class ExampleTest
{
AemContext aemContext = new AemContext();
@Mock
Resource resource;
@BeforeEach
void setup() throws Exception
{
aemContext.load().json("com/example/test.json", "/content/dam");
}
@Test
void testExecute() throws WorkflowException, RepositoryException {
String resourcePath = "/content/dam/test";
resource = aemContext.resourceResolver().getResource(resourcePath);
System.out.println(resource.getPath()); // Output: resource path: /content/dam/test
Asset asset = resource.adaptTo(Asset.class);
System.out.println(asset.getPath()); // Output: asset path: null
}
}
JsonFile
{
"test":
{
"jcr:primaryType":"dam:Asset",
"jcr:createdBy":"admin"
}
}
please help me solve from above code on how to get the asset path/object so that i can retrive asset.getPath(), asset.getName() asset.getAssetMetadata() if required
for now its giving the value as null
request to share the sample code
Thanks & Regards.