Search in sources :

Example 1 with ContentBundleUrlParser

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);
}
Also used : DescriptorMergeStrategyResolver(org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver) Context(org.craftercms.core.service.Context) MergeableDescriptor(org.craftercms.core.xml.mergers.MergeableDescriptor) ContentBundleUrlParser(org.craftercms.core.util.url.ContentBundleUrlParser) ContentBundleUrl(org.craftercms.core.util.url.ContentBundleUrl) Document(org.dom4j.Document) DescriptorMergeStrategy(org.craftercms.core.xml.mergers.DescriptorMergeStrategy) CachingOptions(org.craftercms.core.service.CachingOptions) InvocationOnMock(org.mockito.invocation.InvocationOnMock) List(java.util.List)

Aggregations

List (java.util.List)1 CachingOptions (org.craftercms.core.service.CachingOptions)1 Context (org.craftercms.core.service.Context)1 ContentBundleUrl (org.craftercms.core.util.url.ContentBundleUrl)1 ContentBundleUrlParser (org.craftercms.core.util.url.ContentBundleUrlParser)1 DescriptorMergeStrategy (org.craftercms.core.xml.mergers.DescriptorMergeStrategy)1 DescriptorMergeStrategyResolver (org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver)1 MergeableDescriptor (org.craftercms.core.xml.mergers.MergeableDescriptor)1 Document (org.dom4j.Document)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1