Search in sources :

Example 1 with AssetData

use of com.adobe.cq.wcm.core.components.models.datalayer.AssetData in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AssetDataImplTest method testGetSmartTags.

@Test
void testGetSmartTags() {
    Asset asset = mock(Asset.class);
    Resource assetResource = mock(Resource.class);
    when(asset.adaptTo(Resource.class)).thenReturn(assetResource);
    // mock smart tags
    Resource predictedTagsResource = mock(Resource.class);
    List<Resource> children = new ArrayList<>();
    for (int i = 2; i > 0; --i) {
        Resource tagResource = mock(Resource.class);
        ValueMap valueMap = mock(ValueMap.class);
        when(valueMap.get("name")).thenReturn("tag" + i);
        when(valueMap.get("confidence")).thenReturn(0.78);
        when(tagResource.adaptTo(ValueMap.class)).thenReturn(valueMap);
        children.add(tagResource);
    }
    when(assetResource.getChild(DamConstants.PREDICTED_TAGS)).thenReturn(predictedTagsResource);
    when(predictedTagsResource.getChildren()).thenReturn(children);
    Map<String, Double> expectedSmartTags = new HashMap<String, Double>() {

        {
            put("tag1", 0.78);
            put("tag2", 0.78);
        }
    };
    AssetData assetData = DataLayerBuilder.forAsset(asset).build();
    assertEquals(expectedSmartTags, assetData.getSmartTags());
}
Also used : HashMap(java.util.HashMap) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) Asset(com.day.cq.dam.api.Asset) AssetData(com.adobe.cq.wcm.core.components.models.datalayer.AssetData) Test(org.junit.jupiter.api.Test)

Example 2 with AssetData

use of com.adobe.cq.wcm.core.components.models.datalayer.AssetData in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AssetDataImplTest method testGetLastModifiedDate.

@Test
void testGetLastModifiedDate() {
    Asset asset = mock(Asset.class);
    when(asset.getLastModified()).thenReturn(0L);
    ValueMap valueMap = mock(ValueMap.class);
    when(asset.adaptTo(ValueMap.class)).thenReturn(valueMap);
    Calendar now = Calendar.getInstance();
    when(valueMap.get(JcrConstants.JCR_CREATED, Calendar.class)).thenReturn(now);
    AssetData assetData = DataLayerBuilder.forAsset(asset).build();
    assertEquals(now.getTime(), assetData.getLastModifiedDate());
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Calendar(java.util.Calendar) Asset(com.day.cq.dam.api.Asset) AssetData(com.adobe.cq.wcm.core.components.models.datalayer.AssetData) Test(org.junit.jupiter.api.Test)

Aggregations

AssetData (com.adobe.cq.wcm.core.components.models.datalayer.AssetData)2 Asset (com.day.cq.dam.api.Asset)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Resource (org.apache.sling.api.resource.Resource)1