-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1159 from davidjgonzalez/oft
Fixed issue with thumbnails not showing for assets missing dc:format
- Loading branch information
Showing
11 changed files
with
226 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...etshare/content/renditions/impl/dispatchers/AssetDeliveryRenditionDispatcherImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.adobe.aem.commons.assetshare.content.renditions.impl.dispatchers; | ||
|
||
import com.adobe.aem.commons.assetshare.content.AssetModel; | ||
import com.adobe.aem.commons.assetshare.content.impl.AssetModelImpl; | ||
import com.adobe.aem.commons.assetshare.content.renditions.AssetRenditionDispatcher; | ||
import com.adobe.aem.commons.assetshare.content.renditions.impl.AssetRenditionsImpl; | ||
import com.adobe.aem.commons.assetshare.testing.MockAssetModels; | ||
import com.adobe.aem.commons.assetshare.testing.RequireAemMock; | ||
import com.adobe.aem.commons.assetshare.util.ExpressionEvaluator; | ||
import com.adobe.aem.commons.assetshare.util.RequireAem; | ||
import com.adobe.aem.commons.assetshare.util.impl.ExpressionEvaluatorImpl; | ||
import com.adobe.cq.dam.download.api.DownloadTarget; | ||
import com.adobe.cq.wcm.spi.AssetDelivery; | ||
import io.wcm.testing.mock.aem.junit.AemContext; | ||
import org.apache.sling.commons.mime.MimeTypeService; | ||
import org.apache.sling.models.factory.ModelFactory; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class AssetDeliveryRenditionDispatcherImplTest { | ||
@Rule | ||
public AemContext ctx = new AemContext(); | ||
|
||
@Mock | ||
MimeTypeService mimeTypeService; | ||
|
||
@Mock | ||
DownloadTarget downloadTarget; | ||
|
||
@Mock | ||
ModelFactory modelFactory; | ||
|
||
@Mock | ||
AssetDelivery assetDelivery; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
ctx.load().json(getClass().getResourceAsStream("AssetDeliveryRenditionDispatcherImplTest.json"), "/content"); | ||
|
||
RequireAemMock.setAem(ctx, | ||
RequireAem.Distribution.CLOUD_READY, | ||
RequireAem.ServiceType.AUTHOR); | ||
|
||
ctx.addModelsForClasses(AssetModelImpl.class); | ||
|
||
MockAssetModels.mockModelFactory(ctx, modelFactory, "/content/dam/test.png"); | ||
MockAssetModels.mockModelFactory(ctx, modelFactory, "/content/dam/test.oft"); | ||
|
||
ctx.registerService(ModelFactory.class, modelFactory, org.osgi.framework.Constants.SERVICE_RANKING, | ||
Integer.MAX_VALUE); | ||
|
||
|
||
ctx.registerService(AssetDelivery.class, assetDelivery); | ||
ctx.registerService(MimeTypeService.class, mimeTypeService); | ||
ctx.registerService(ExpressionEvaluator.class, new ExpressionEvaluatorImpl()); | ||
|
||
ctx.registerInjectActivateService(new AssetRenditionsImpl()); | ||
|
||
ctx.registerInjectActivateService(new AssetDeliveryRenditionDispatcherImpl(), "rendition.mappings", new String[]{"test=foo"}); | ||
} | ||
|
||
@Test | ||
public void testAccepts_True() throws Exception { | ||
ctx.currentResource("/content/dam/test.png"); | ||
AssetModel assetModel = ctx.request().adaptTo(AssetModel.class); | ||
|
||
AssetRenditionDispatcher dispatcher = ctx.getService(AssetRenditionDispatcher.class); | ||
|
||
assertTrue("PNG should be accepted", dispatcher.accepts(assetModel, "test")); | ||
} | ||
|
||
@Test | ||
public void testAccepts_False() throws Exception { | ||
ctx.currentResource("/content/dam/test.oft"); | ||
AssetModel assetModel = ctx.request().adaptTo(AssetModel.class); | ||
|
||
AssetRenditionDispatcher dispatcher = ctx.getService(AssetRenditionDispatcher.class); | ||
|
||
assertFalse("OFT should not be accepted", dispatcher.accepts(assetModel, "test")); | ||
} | ||
|
||
|
||
@Test | ||
public void testAccepts_NoDcFormat_False() { | ||
ctx.currentResource("/content/dam/test.no-dc-format"); | ||
AssetModel assetModel = ctx.request().adaptTo(AssetModel.class); | ||
|
||
AssetRenditionDispatcher dispatcher = ctx.getService(AssetRenditionDispatcher.class); | ||
|
||
assertFalse("Missing dc:format should not be accepted", dispatcher.accepts(assetModel, "test")); | ||
} | ||
|
||
|
||
@Test | ||
public void testAccepts_BlankDcFormat_False() { | ||
ctx.currentResource("/content/dam/test.blank-dc-format"); | ||
AssetModel assetModel = ctx.request().adaptTo(AssetModel.class); | ||
|
||
AssetRenditionDispatcher dispatcher = ctx.getService(AssetRenditionDispatcher.class); | ||
|
||
assertFalse("Blank dc:format should not be accepted", dispatcher.accepts(assetModel, "test")); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...etshare/content/renditions/impl/dispatchers/AssetDeliveryRenditionDispatcherImplTest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{ | ||
"dam": { | ||
"test.png": { | ||
"jcr:primaryType": "dam:Asset", | ||
"jcr:content": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"metadata": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"dc:format": "image/png" | ||
}, | ||
"renditions": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"cq5dam.web.1280.1280.png": { | ||
"jcr:primaryType": "nt:file", | ||
"jcr:content": { | ||
"jcr:primaryType": "oak:Resource", | ||
"jcr:mimeType": "image/png" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"test.oft": { | ||
"jcr:primaryType": "dam:Asset", | ||
"jcr:content": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"metadata": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"dc:format": "application/vnd.oasis.opendocument.text" | ||
}, | ||
"renditions": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"cq5dam.web.1280.1280.png": { | ||
"jcr:primaryType": "nt:file", | ||
"jcr:content": { | ||
"jcr:primaryType": "oak:Resource", | ||
"jcr:mimeType": "image/png" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"test.no-dc-format": { | ||
"jcr:primaryType": "dam:Asset", | ||
"jcr:content": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"metadata": { | ||
"jcr:primaryType": "nt:unstructured" | ||
}, | ||
"renditions": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"cq5dam.web.1280.1280.png": { | ||
"jcr:primaryType": "nt:file", | ||
"jcr:content": { | ||
"jcr:primaryType": "oak:Resource", | ||
"jcr:mimeType": "image/png" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"test.blank-dc-format": { | ||
"jcr:primaryType": "dam:Asset", | ||
"jcr:content": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"metadata": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"dc:format": " " | ||
}, | ||
"renditions": { | ||
"jcr:primaryType": "nt:unstructured", | ||
"cq5dam.web.1280.1280.png": { | ||
"jcr:primaryType": "nt:file", | ||
"jcr:content": { | ||
"jcr:primaryType": "oak:Resource", | ||
"jcr:mimeType": "image/png" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ontent/jcr_root/apps/asset-share-commons/components/search/results/clientlibs/site/js.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#base=js | ||
|
||
scripts.js |
8 changes: 8 additions & 0 deletions
8
...jcr_root/apps/asset-share-commons/components/search/results/clientlibs/site/js/scripts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const images = document.querySelectorAll('img[data-asset-share-missing-image]'); | ||
images.forEach(img => { | ||
img.onerror = function() { | ||
this.src = this.getAttribute('data-asset-share-missing-image'); | ||
}; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters