does anyone know how to adopt json resource as asset while writing junit? | Community
Skip to main content
Level 4
November 15, 2022
Solved

does anyone know how to adopt json resource as asset while writing junit?

  • November 15, 2022
  • 1 reply
  • 1868 views

context.load().json("/my/folder/co/aem/core/workflow/dam/xyz.json", "/content/dam/test/abc.zip");

Resource resource = context.resourceResolver().getResource("/content/dam/test/abc.zip");

Asset asset = resource.adaptTo(Asset.class); //here asset is null

 

 

 

 

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

1 reply

arunpatidar
Community Advisor
Community Advisor
November 15, 2022

Please check example

https://github.com/arunpatidar02/com.aemlab.junitapp/tree/master/core/src/test 

jsons are inside resources folder

Arun Patidar
Level 4
November 15, 2022

Hi Arun,

 

Thanks for your reply. i didnot get any reference.

i'm trying to adapt "resource.adaptTo(Asset.class)" resource as Asset but i'm getting null not sure why this is happening.

Here i'm getting resource.

arunpatidar
Community Advisor
Community Advisor
November 16, 2022

Hi Arun,  here its

{
"jcr:primaryType":"sling:Folder",
"jcr:createdBy":"admin",
"jcr:created":"Tue Nov 15 2022 12:24:07 GMT+0530",
"abc.zip":{
"jcr:primaryType":"dam:Asset",
"jcr:mixinTypes":[
"mix:referenceable"
],
"jcr:createdBy":"admin",
"jcr:created":"Tue Nov 15 2022 13:17:18 GMT+0530",
"jcr:uuid":"5335343gfdsfgafdaafdf",
"jcr:content":{
"jcr:primaryType":"dam:AssetContent",
"dam:assetState":"processing",
"renditions":{
"jcr:primaryType":"nt:folder",
"jcr:createdBy":"admin",
"jcr:created":"Tue Nov 15 2022 13:17:18 GMT+0530",
"original":{
"jcr:primaryType":"nt:file",
"jcr:createdBy":"admin",
"jcr:created":"Tue Nov 15 2022 13:17:18 GMT+0530",
"jcr:content":{
"jcr:primaryType":"oak:Resource",
"jcr:lastModifiedBy":"admin",
"jcr:mimeType":"application/zip",
"jcr:lastModified":"Tue Nov 15 2022 13:17:18 GMT+0530",
":jcr:data":13721771
}
}
},
"related":{
"jcr:primaryType":"nt:unstructured"
},
"metadata":{
"jcr:primaryType":"nt:unstructured",
"jcr:mixinTypes":[
"cq:Taggable"
]
}
}
},
"jcr:content":{
"jcr:primaryType":"nt:unstructured",
"jcr:title":"testing",
"dam:noThumbnail":true,
"sourcing":"false",
"folderThumbnail":{
"jcr:primaryType":"nt:file",
"jcr:createdBy":"abc-service",
"jcr:created":"Tue Nov 15 2022 13:01:03 GMT+0530",
"jcr:content":{
"jcr:primaryType":"nt:unstructured",
"dam:folderThumbnailPaths":[

],
"height":140,
"bgcolor":-1,
"width":240,
"jcr:lastModified":"Tue Nov 15 2022 13:17:10 GMT+0530",
"jcr:data":631
}
}
}
}


Your json is incorrect?

Try to check the primary type of Resource, it should be dam:Asset ?

 

you can remove the first nesting e.g. your json should look like below

{
    "jcr:primaryType": "dam:Asset",
    "jcr:mixinTypes": [
        "mix:referenceable"
    ],
    "jcr:content":
    {
        "jcr:primaryType": "dam:AssetContent",
        "dam:assetState": "processing",
        "renditions":
        {
            "jcr:primaryType": "nt:folder",
            "original":
            {
                "jcr:primaryType": "nt:file",
                "jcr:content":
                {
                    "jcr:primaryType": "oak:Resource",
                    "jcr:mimeType": "application/zip",
                    ":jcr:data": 13721771
                }
            }
        },
        "related":
        {
            "jcr:primaryType": "nt:unstructured"
        },
        "metadata":
        {
            "jcr:primaryType": "nt:unstructured",
            "jcr:mixinTypes": [
                "cq:Taggable"
            ]
        }
    }
}
Arun Patidar