Search in sources :

Example 1 with ContentStoreAdapter

use of org.craftercms.core.store.ContentStoreAdapter in project engine by craftercms.

the class TargetedContentDescriptorMergeStrategyTest method testGetDescriptors.

@Test
public void testGetDescriptors() throws Exception {
    Item item = mock(Item.class);
    when(item.getDescriptorDom()).thenReturn(mock(Document.class));
    ContentStoreAdapter storeAdapter = mock(ContentStoreAdapter.class);
    when(storeAdapter.findItem(any(Context.class), any(CachingOptions.class), anyString(), anyBoolean())).thenReturn(item);
    Context context = mock(Context.class);
    when(context.getStoreAdapter()).thenReturn(storeAdapter);
    List<MergeableDescriptor> descriptors = mergeStrategy.getDescriptors(context, CachingOptions.DEFAULT_CACHING_OPTIONS, "/site/website/es_CR/products/index.xml", mock(Document.class), false);
    assertNotNull(descriptors);
    assertEquals(12, descriptors.size());
    assertEquals("/crafter-level-descriptor.level.xml", descriptors.get(0).getUrl());
    assertEquals("/site/crafter-level-descriptor.level.xml", descriptors.get(1).getUrl());
    assertEquals("/site/website/crafter-level-descriptor.level.xml", descriptors.get(2).getUrl());
    assertEquals("/site/website/en/crafter-level-descriptor.level.xml", descriptors.get(3).getUrl());
    assertEquals("/site/website/en/products/crafter-level-descriptor.level.xml", descriptors.get(4).getUrl());
    assertEquals("/site/website/en/products/index.xml", descriptors.get(5).getUrl());
    assertEquals("/site/website/es/crafter-level-descriptor.level.xml", descriptors.get(6).getUrl());
    assertEquals("/site/website/es/products/crafter-level-descriptor.level.xml", descriptors.get(7).getUrl());
    assertEquals("/site/website/es/products/index.xml", descriptors.get(8).getUrl());
    assertEquals("/site/website/es_CR/crafter-level-descriptor.level.xml", descriptors.get(9).getUrl());
    assertEquals("/site/website/es_CR/products/crafter-level-descriptor.level.xml", descriptors.get(10).getUrl());
    assertEquals("/site/website/es_CR/products/index.xml", descriptors.get(11).getUrl());
}
Also used : SiteContext(org.craftercms.engine.service.context.SiteContext) Context(org.craftercms.core.service.Context) Item(org.craftercms.core.service.Item) CachingOptions(org.craftercms.core.service.CachingOptions) ContentStoreAdapter(org.craftercms.core.store.ContentStoreAdapter) MergeableDescriptor(org.craftercms.core.xml.mergers.MergeableDescriptor) Document(org.dom4j.Document) Test(org.junit.Test)

Example 2 with ContentStoreAdapter

use of org.craftercms.core.store.ContentStoreAdapter in project engine by craftercms.

the class TargetedContentStoreAdapterTest method createActualAdapter.

private ContentStoreAdapter createActualAdapter() {
    ContentStoreAdapter adapter = mock(ContentStoreAdapter.class);
    Item idx = new Item();
    idx.setName("index.xml");
    idx.setUrl("/site/website/index.xml");
    Item en = new Item();
    en.setName("en");
    en.setUrl("/site/website/en");
    Item enIdx = new Item();
    enIdx.setName("index.xml");
    enIdx.setUrl("/site/website/en/index.xml");
    Item enAboutUs = new Item();
    enAboutUs.setName("about-us");
    enAboutUs.setUrl("/site/website/en/about-us");
    Item mainCss = new Item();
    mainCss.setName("main.css");
    mainCss.setUrl("/static-assets/css/main.css");
    Item frIdx = new Item();
    frIdx.setName("index.xml");
    frIdx.setUrl("/site/website/ja/index.xml");
    when(adapter.exists(any(Context.class), eq("/site/website/index.xml"))).thenReturn(true);
    when(adapter.exists(any(Context.class), eq("/site/website/en"))).thenReturn(true);
    when(adapter.exists(any(Context.class), eq("/site/website/en/index.xml"))).thenReturn(true);
    when(adapter.exists(any(Context.class), eq("/static-assets/css/main.css"))).thenReturn(true);
    when(adapter.findContent(any(Context.class), any(CachingOptions.class), eq("/site/website/index.xml"))).thenReturn(mock(Content.class));
    when(adapter.findContent(any(Context.class), any(CachingOptions.class), eq("/site/website/en/index.xml"))).thenReturn(mock(Content.class));
    when(adapter.findContent(any(Context.class), any(CachingOptions.class), eq("/static-assets/css/main.css"))).thenReturn(mock(Content.class));
    when(adapter.findItem(any(Context.class), any(CachingOptions.class), eq("/site/website/index.xml"), anyBoolean())).thenReturn(idx);
    when(adapter.findItem(any(Context.class), any(CachingOptions.class), eq("/site/website/en"), anyBoolean())).thenReturn(en);
    when(adapter.findItem(any(Context.class), any(CachingOptions.class), eq("/site/website/en/index.xml"), anyBoolean())).thenReturn(enIdx);
    when(adapter.findItem(any(Context.class), any(CachingOptions.class), eq("/static-assets/css/main.css"), anyBoolean())).thenReturn(mainCss);
    when(adapter.findItems(any(Context.class), any(CachingOptions.class), eq("/site/website/en"), anyBoolean())).thenReturn(Arrays.asList(enIdx, enAboutUs));
    when(adapter.findItems(any(Context.class), any(CachingOptions.class), eq("/site/website/ja"), anyBoolean())).thenReturn(Collections.singletonList(frIdx));
    return adapter;
}
Also used : Context(org.craftercms.core.service.Context) Item(org.craftercms.core.service.Item) CachingOptions(org.craftercms.core.service.CachingOptions) ContentStoreAdapter(org.craftercms.core.store.ContentStoreAdapter) Content(org.craftercms.core.service.Content)

Aggregations

CachingOptions (org.craftercms.core.service.CachingOptions)2 Context (org.craftercms.core.service.Context)2 Item (org.craftercms.core.service.Item)2 ContentStoreAdapter (org.craftercms.core.store.ContentStoreAdapter)2 Content (org.craftercms.core.service.Content)1 MergeableDescriptor (org.craftercms.core.xml.mergers.MergeableDescriptor)1 SiteContext (org.craftercms.engine.service.context.SiteContext)1 Document (org.dom4j.Document)1 Test (org.junit.Test)1