Search in sources :

Example 1 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class FieldRenamingProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    Item item = new Item();
    item.setDescriptorDom(readInputXml());
    item = processor.process(mock(Context.class), CachingOptions.DEFAULT_CACHING_OPTIONS, item);
    assertNotNull(item.getDescriptorDom());
    assertEquals(EXPECTED_XML, item.getDescriptorDom().asXML().replace("\n", ""));
}
Also used : Item(org.craftercms.core.service.Item) Test(org.junit.Test)

Example 2 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class TextMetaDataExtractingProcessorTest method setUpTestItem.

private void setUpTestItem() {
    Node cssNode = mock(Node.class);
    when(cssNode.getText()).thenReturn(CSS);
    Node jsNode = mock(Node.class);
    when(jsNode.getText()).thenReturn(JS);
    Document descriptorDom = mock(Document.class);
    when(descriptorDom.selectSingleNode(testMetaDataNodesXPathQueries[0])).thenReturn(cssNode);
    when(descriptorDom.selectSingleNode(testMetaDataNodesXPathQueries[1])).thenReturn(jsNode);
    item = new Item();
    item.setDescriptorDom(descriptorDom);
}
Also used : Item(org.craftercms.core.service.Item) Node(org.dom4j.Node) Document(org.dom4j.Document)

Example 3 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class UrlPatternProcessorResolverTest method testGetProcessor.

@Test
public void testGetProcessor() throws Exception {
    Item item = new Item();
    item.setUrl(DESCRIPTOR_URL);
    ItemProcessor processor = resolver.getProcessor(item);
    assertSame(processor, pagesProcessor);
    item = new Item();
    item.setUrl(IMAGE_URL);
    processor = resolver.getProcessor(item);
    assertSame(processor, staticAssetsProcessor);
}
Also used : Item(org.craftercms.core.service.Item) ItemProcessor(org.craftercms.core.processors.ItemProcessor) Test(org.junit.Test)

Example 4 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class ContentStoreServiceImplTest method testGetDescriptorItem.

@Test
public void testGetDescriptorItem() throws Exception {
    Item item = contentStoreService.findItem(context, CONTENT_FR_ES_DESCRIPTOR_PATH);
    assertContentFrEsDescriptorItem(item, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    Item cachedItem = contentStoreService.getItem(context, CONTENT_FR_ES_DESCRIPTOR_PATH);
    assertEquals(item, cachedItem);
    assertCaching(item, cachedItem);
    item = contentStoreService.findItem(context, INVALID_PATH);
    assertNull(item);
    try {
        contentStoreService.getItem(context, INVALID_PATH);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
    TextMetaDataExtractingProcessor extractor = new TextMetaDataExtractingProcessor("//first-quote", "//second-quote", "//third-quote");
    item = contentStoreService.findItem(context, DEFAULT_CACHING_OPTIONS, CONTENT_FR_ES_DESCRIPTOR_PATH, extractor);
    assertContentFrEsDescriptorItem(item, true);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedItem = contentStoreService.getItem(context, DEFAULT_CACHING_OPTIONS, CONTENT_FR_ES_DESCRIPTOR_PATH, extractor);
    assertEquals(item, cachedItem);
    assertCaching(item, cachedItem);
    item = contentStoreService.findItem(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, extractor);
    assertNull(item);
    try {
        contentStoreService.getItem(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, extractor);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
}
Also used : Item(org.craftercms.core.service.Item) TextMetaDataExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor) PathNotFoundException(org.craftercms.core.exception.PathNotFoundException) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Example 5 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class ContentStoreServiceImplTest method testGetFolderItem.

@Test
public void testGetFolderItem() throws Exception {
    Item item = contentStoreService.findItem(context, BUNDLE_FOLDER_PATH);
    assertBundleFolderItem(item, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    Item cachedItem = contentStoreService.getItem(context, BUNDLE_FOLDER_PATH);
    assertEquals(item, cachedItem);
    assertCaching(item, cachedItem);
    TextMetaDataCollectionExtractingProcessor extractor = new TextMetaDataCollectionExtractingProcessor("//extension");
    item = contentStoreService.findItem(context, DEFAULT_CACHING_OPTIONS, BUNDLE_FOLDER_PATH, extractor);
    assertBundleFolderItem(item, true);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedItem = contentStoreService.getItem(context, DEFAULT_CACHING_OPTIONS, BUNDLE_FOLDER_PATH, extractor);
    assertEquals(item, cachedItem);
    assertCaching(item, cachedItem);
}
Also used : Item(org.craftercms.core.service.Item) TextMetaDataCollectionExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Aggregations

Item (org.craftercms.core.service.Item)55 Test (org.junit.Test)21 Context (org.craftercms.core.service.Context)19 CachingOptions (org.craftercms.core.service.CachingOptions)8 Document (org.dom4j.Document)8 ArrayList (java.util.ArrayList)7 ContentStoreAdapter (org.craftercms.core.store.ContentStoreAdapter)7 CachingAwareList (org.craftercms.core.util.cache.impl.CachingAwareList)5 InheritLevelsMergeStrategyTest (org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)4 DecoratedStoreAdapterContext (org.craftercms.engine.util.store.decorators.DecoratedStoreAdapterContext)4 PathNotFoundException (org.craftercms.core.exception.PathNotFoundException)3 TextMetaDataExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor)3 Content (org.craftercms.core.service.Content)3 ContentStoreService (org.craftercms.core.service.ContentStoreService)3 Tree (org.craftercms.core.service.Tree)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 StoreException (org.craftercms.core.exception.StoreException)2 ItemProcessor (org.craftercms.core.processors.ItemProcessor)2 ItemProcessorPipeline (org.craftercms.core.processors.impl.ItemProcessorPipeline)2 TextMetaDataCollectionExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor)2