Skip to content

Commit

Permalink
Fix uri generation for "/" context
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Nov 9, 2023
1 parent c833b95 commit 8487d9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.net.URI;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -26,7 +27,7 @@ public URI create(final FlexibleParameter parameter) {
".imaging",
FlexibleImageGenerator.GENERATOR_NAME,
parameter.getItemKey().asString()
),
).filter(Predicate.not(String::isBlank)),
parameter.toMap().entrySet().stream().sorted(Map.Entry.comparingByKey()).flatMap(p -> Stream.of(p.getKey(), p.getValue())),
Stream.of(parameter.getFileName())
).flatMap(Function.identity()).collect(Collectors.toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,21 @@ void create() throws URISyntaxException {
);
}
}

@Test
void createNoContext() throws URISyntaxException {
final Asset asset = mock(Asset.class);
doReturn(ItemKey.from("jcr:b3ee7444-4830-4454-abbb-20fc35387032")).when(asset).getItemKey();
doReturn("someImage.jpg").when(asset).getFileName();
final FlexibleParameter parameter = new FlexibleParameter(new DynamicImageParameter(true), "16:9", 100, asset);

try (MockedStatic<MgnlContext> mgnlContext = Mockito.mockStatic(MgnlContext.class)) {
mgnlContext.when(MgnlContext::getContextPath).thenReturn("/");

assertEquals(
new URI("/.imaging/flex/jcr:b3ee7444-4830-4454-abbb-20fc35387032/crop/true/ratio/16:9/width/100/someImage.jpg"),
new FlexibleImageUriFactory().create(parameter)
);
}
}
}

0 comments on commit 8487d9e

Please sign in to comment.