Skip to content

Commit

Permalink
Add test, add line in changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Castelo committed May 5, 2021
1 parent f0c11ea commit 0f94002
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)
## Unreleased ([details][unreleased changes details])
<!-- Keep this up to date! After a release, change the tag name to the latest release -->
[unreleased changes details]: https://github.com/Adobe-Consulting-Services/acs-aem-commons/compare/acs-aem-commons-5.0.4...HEAD
### Fixed
- #2581 - Versioned ClientLibs no longer works with proxied clientlibs

### Fixed
- #2562 - Fixed cache refresh on versioned clientlibs request when enforceMd5 is false (default).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.commons.testing.sling.MockResource;
import org.apache.sling.rewriter.ProcessingContext;
import org.apache.sling.rewriter.Transformer;
import org.junit.After;
Expand Down Expand Up @@ -84,6 +85,9 @@ public class VersionedClientlibsTransformerFactoryTest {
@Mock
private HtmlLibrary proxiedHtmlLibrary;

@Mock
private HtmlLibrary resourceResolverHtmlLibrary;

@Mock
private ContentHandler handler;

Expand Down Expand Up @@ -115,6 +119,7 @@ public class VersionedClientlibsTransformerFactoryTest {
private ResourceResolver resourceResolver;

private static final String PATH = "/etc/clientlibs/test";
private static final String MAP_PATH = "/mylib/test";
private static final String FAKE_STREAM_CHECKSUM="fcadcfb01c1367e9e5b7f2e6d455ba8f"; // md5 of "I love strings"
private static final String PROXIED_FAKE_STREAM_CHECKSUM="669a712c318596cd7e7520e3e2000cfb"; // md5 of "I love strings when they are proxied"
private static final byte[] BYTES;
Expand Down Expand Up @@ -148,6 +153,9 @@ public void setUp() throws Exception {
when(proxiedHtmlLibrary.getLibraryPath()).thenReturn(PROXIED_PATH);
when(proxiedHtmlLibrary.getInputStream(false)).thenReturn(new java.io.ByteArrayInputStream("I love strings when they are proxied".getBytes()));

when(resourceResolverHtmlLibrary.getLibraryPath()).thenReturn(MAP_PATH);
when(resourceResolverHtmlLibrary.getInputStream(false)).thenReturn(new java.io.ByteArrayInputStream("I love strings when they are resolved".getBytes()));

when(processingContext.getRequest()).thenReturn(slingRequest);
when(slingRequest.getResourceResolver()).thenReturn(resourceResolver);
when(resourceResolver.getSearchPath()).thenReturn(new String[] { "/libs/", "/apps/" });
Expand All @@ -162,7 +170,7 @@ public void setUp() throws Exception {

@After
public void tearDown() throws Exception {
reset(htmlLibraryManager, htmlLibrary, handler);
reset(htmlLibraryManager, htmlLibrary, resourceResolverHtmlLibrary, handler);
transformer = null;
}

Expand Down Expand Up @@ -471,6 +479,27 @@ public void testMinifiedJavaScriptClientLibrary() throws Exception {
assertEquals(PATH + ".min."+ FAKE_STREAM_CHECKSUM +".js", attributesCaptor.getValue().getValue(0));
}

@Test
public void testClientLibFoundWithResourceResolverMapping() throws Exception {

MockResource clientlib = new MockResource(resourceResolver, PATH,"");
when(resourceResolver.resolve(slingRequest, MAP_PATH)).thenReturn(clientlib);
when(htmlLibraryManager.getLibrary(eq(LibraryType.JS), eq(PATH))).thenReturn(htmlLibrary);

final AttributesImpl in = new AttributesImpl();
in.addAttribute("", "src", "", "CDATA", MAP_PATH + ".min.js");
in.addAttribute("", "type", "", "CDATA", "text/javascript");

transformer.startElement(null, "script", null, in);

ArgumentCaptor<Attributes> attributesCaptor = ArgumentCaptor.forClass(Attributes.class);

verify(handler, only()).startElement(isNull(), eq("script"), isNull(),
attributesCaptor.capture());

assertEquals(MAP_PATH + ".min."+ FAKE_STREAM_CHECKSUM +".js", attributesCaptor.getValue().getValue(0));
}

@Test
public void testCssClientLibraryWithInvalidExtension() throws Exception {

Expand Down

0 comments on commit 0f94002

Please sign in to comment.