use of org.craftercms.core.util.url.ContentBundleUrlParser in project core by craftercms.
the class ContentBundleMergeStrategyTest method setUpTestStrategy.
private void setUpTestStrategy() {
ContentBundleUrl contentBundleUrl = mock(ContentBundleUrl.class);
when(contentBundleUrl.getPrefix()).thenReturn(MAIN_DESCRIPTOR_URL_PREFIX);
when(contentBundleUrl.getBaseNameAndExtensionToken()).thenReturn(MAIN_DESCRIPTOR_URL_BASE_NAME_AND_EXT_TOKEN);
when(contentBundleUrl.getSuffix()).thenReturn(MAIN_DESCRIPTOR_URL_SUFFIX);
ContentBundleUrlParser contentBundleUrlParser = mock(ContentBundleUrlParser.class);
when(contentBundleUrlParser.getContentBundleUrl(MAIN_DESCRIPTOR_URL)).thenReturn(contentBundleUrl);
DescriptorMergeStrategy baseStrategy = mock(DescriptorMergeStrategy.class);
when(baseStrategy.getDescriptors(eq(context), eq(DEFAULT_CACHING_OPTIONS), eq(BASE_DESCRIPTOR_URL), any(Document.class), anyBoolean())).thenAnswer(new Answer<List<MergeableDescriptor>>() {
@Override
public List<MergeableDescriptor> answer(InvocationOnMock invocation) throws Throwable {
boolean isOptionalForMerging = (Boolean) invocation.getArguments()[4];
return Arrays.asList(new MergeableDescriptor(BASE_DESCRIPTOR_URL, isOptionalForMerging));
}
});
DescriptorMergeStrategyResolver baseResolver = mock(DescriptorMergeStrategyResolver.class);
when(baseResolver.getStrategy(eq(BASE_DESCRIPTOR_URL), Matchers.<Document>anyObject())).thenReturn(baseStrategy);
DescriptorMergeStrategy regularStrategy = mock(DescriptorMergeStrategy.class);
when(regularStrategy.getDescriptors(any(Context.class), any(CachingOptions.class), eq(NO_PREFIX_DESCRIPTOR_URL), any(Document.class), anyBoolean())).thenAnswer(new Answer<List<MergeableDescriptor>>() {
@Override
public List<MergeableDescriptor> answer(InvocationOnMock invocation) throws Throwable {
boolean isOptionalForMerging = (Boolean) invocation.getArguments()[4];
return Arrays.asList(new MergeableDescriptor(NO_PREFIX_DESCRIPTOR_URL, isOptionalForMerging));
}
});
strategy = new ContentBundleMergeStrategy();
strategy.setUrlParser(contentBundleUrlParser);
strategy.setBaseDelimiter(BASE_DELIMITER);
strategy.setBaseMergeStrategyResolver(baseResolver);
strategy.setRegularMergeStrategy(regularStrategy);
}
Aggregations