Search in sources :

Example 1 with DescriptorMergeStrategyResolver

use of org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver 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)

Example 2 with DescriptorMergeStrategyResolver

use of org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver in project core by craftercms.

the class DescriptorMergeStrategyResolverChainTest method setUpTestResolverChain.

private void setUpTestResolverChain() {
    DescriptorMergeStrategyResolver resolver1 = mock(DescriptorMergeStrategyResolver.class);
    when(resolver1.getStrategy(eq(DESCRIPTOR_URL1), Matchers.<Document>anyObject())).thenReturn(strategy1);
    DescriptorMergeStrategyResolver resolver2 = mock(DescriptorMergeStrategyResolver.class);
    when(resolver2.getStrategy(eq(DESCRIPTOR_URL2), Matchers.<Document>anyObject())).thenReturn(strategy2);
    resolverChain = new DescriptorMergeStrategyResolverChain();
    resolverChain.setResolvers(Arrays.asList(resolver1, resolver2));
    resolverChain.setDefaultStrategy(defaultStrategy);
}
Also used : DescriptorMergeStrategyResolver(org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver) DescriptorMergeStrategyResolverChain(org.craftercms.core.xml.mergers.impl.resolvers.DescriptorMergeStrategyResolverChain)

Example 3 with DescriptorMergeStrategyResolver

use of org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver in project core by craftercms.

the class ExplicitParentMergeStrategyTest method setUpTestStrategy.

private void setUpTestStrategy() {
    DescriptorMergeStrategy parentStrategy = mock(DescriptorMergeStrategy.class);
    when(parentStrategy.getDescriptors(any(Context.class), eq(DEFAULT_CACHING_OPTIONS), eq(PARENT_DESCRIPTOR_URL), any(Document.class), eq(true))).thenReturn(Arrays.asList(new MergeableDescriptor(LEVEL_DESCRIPTOR_URL, true), new MergeableDescriptor(PARENT_DESCRIPTOR_URL, true)));
    DescriptorMergeStrategyResolver mergeStrategyResolver = mock(DescriptorMergeStrategyResolver.class);
    when(mergeStrategyResolver.getStrategy(eq(PARENT_DESCRIPTOR_URL), any(Document.class))).thenReturn(parentStrategy);
    strategy = new ExplicitParentMergeStrategy();
    strategy.setMergeStrategyResolver(mergeStrategyResolver);
    strategy.setParentDescriptorElementXPathQuery(PARENT_DESCRIPTOR_ELEM_XPATH_QUERY);
}
Also used : Context(org.craftercms.core.service.Context) DescriptorMergeStrategyResolver(org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver) DescriptorMergeStrategy(org.craftercms.core.xml.mergers.DescriptorMergeStrategy) MergeableDescriptor(org.craftercms.core.xml.mergers.MergeableDescriptor) Document(org.dom4j.Document)

Aggregations

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