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());
}
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());
}
Aggregations