Search in sources :

Example 1 with TextMetaDataExtractingProcessor

use of org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor 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 2 with TextMetaDataExtractingProcessor

use of org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor in project core by craftercms.

the class ContentStoreServiceImplTest method testGetChildren.

@Test
public void testGetChildren() throws Exception {
    CachingAwareList<Item> children = (CachingAwareList<Item>) contentStoreService.findChildren(context, ROOT_FOLDER_PATH);
    assertRootFolderChildren(children, false, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    CachingAwareList<Item> cachedChildren = (CachingAwareList<Item>) contentStoreService.getChildren(context, ROOT_FOLDER_PATH);
    assertEquals(children, cachedChildren);
    assertListCaching(children, cachedChildren);
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, INVALID_PATH);
    assertNull(children);
    try {
        contentStoreService.getChildren(context, INVALID_PATH);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
    ItemProcessorPipeline extractorPipeline = new ItemProcessorPipeline();
    extractorPipeline.addProcessor(new TextMetaDataCollectionExtractingProcessor("//extension"));
    extractorPipeline.addProcessor(new TextMetaDataExtractingProcessor("//size"));
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertRootFolderChildren(children, true, true);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedChildren = (CachingAwareList<Item>) contentStoreService.getChildren(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertEquals(children, cachedChildren);
    assertListCaching(children, cachedChildren);
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertNull(children);
    try {
        contentStoreService.getChildren(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
        assertNull(children);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
}
Also used : Item(org.craftercms.core.service.Item) ItemProcessorPipeline(org.craftercms.core.processors.impl.ItemProcessorPipeline) TextMetaDataCollectionExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor) TextMetaDataExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor) PathNotFoundException(org.craftercms.core.exception.PathNotFoundException) CachingAwareList(org.craftercms.core.util.cache.impl.CachingAwareList) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Example 3 with TextMetaDataExtractingProcessor

use of org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor in project core by craftercms.

the class ContentStoreServiceImplTest method testGetStaticAssetItem.

@Test
public void testGetStaticAssetItem() throws Exception {
    Item item = contentStoreService.findItem(context, CRAFTER_CMS_LOGO_PATH);
    assertCrafterCMSLogoItem(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, CRAFTER_CMS_LOGO_PATH);
    assertEquals(item, cachedItem);
    assertCaching(item, cachedItem);
    TextMetaDataExtractingProcessor extractor = new TextMetaDataExtractingProcessor("//size");
    item = contentStoreService.findItem(context, DEFAULT_CACHING_OPTIONS, CRAFTER_CMS_LOGO_PATH, extractor);
    assertCrafterCMSLogoItem(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, CRAFTER_CMS_LOGO_PATH, extractor);
    assertEquals(item, cachedItem);
    assertCaching(item, cachedItem);
}
Also used : Item(org.craftercms.core.service.Item) TextMetaDataExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Example 4 with TextMetaDataExtractingProcessor

use of org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor in project core by craftercms.

the class ContentStoreServiceImplTest method testGetTree.

@Test
public void testGetTree() throws Exception {
    Tree tree = contentStoreService.findTree(context, ROOT_FOLDER_PATH);
    assertRootFolderTree(tree, UNLIMITED_TREE_DEPTH, false, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    Tree cachedTree = contentStoreService.getTree(context, ROOT_FOLDER_PATH);
    assertEquals(tree, cachedTree);
    assertTreeCaching(tree, cachedTree);
    tree = contentStoreService.findTree(context, INVALID_PATH);
    assertNull(tree);
    try {
        contentStoreService.getTree(context, INVALID_PATH);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
    tree = contentStoreService.findTree(context, ROOT_FOLDER_PATH, 1);
    assertRootFolderTree(tree, 1, false, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedTree = contentStoreService.getTree(context, ROOT_FOLDER_PATH, 1);
    assertEquals(tree, cachedTree);
    assertTreeCaching(tree, cachedTree);
    tree = contentStoreService.findTree(context, INVALID_PATH, 1);
    assertNull(tree);
    try {
        contentStoreService.getTree(context, INVALID_PATH, 1);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
    ItemProcessorPipeline extractorPipeline = new ItemProcessorPipeline();
    extractorPipeline.addProcessor(new TextMetaDataCollectionExtractingProcessor("//extension"));
    extractorPipeline.addProcessor(new TextMetaDataExtractingProcessor("//first-quote", "//second-quote", "//third-quote", "//size"));
    tree = contentStoreService.findTree(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, 1, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertRootFolderTree(tree, 1, true, true);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedTree = contentStoreService.getTree(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, 1, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertEquals(tree, cachedTree);
    assertTreeCaching(tree, cachedTree);
    tree = contentStoreService.findTree(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, 1, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertNull(tree);
    try {
        contentStoreService.getTree(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, 1, OnlyNonDescriptorsFilter.instance, extractorPipeline);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
}
Also used : ItemProcessorPipeline(org.craftercms.core.processors.impl.ItemProcessorPipeline) TextMetaDataCollectionExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor) TextMetaDataExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor) Tree(org.craftercms.core.service.Tree) PathNotFoundException(org.craftercms.core.exception.PathNotFoundException) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Aggregations

TextMetaDataExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor)4 InheritLevelsMergeStrategyTest (org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)4 Test (org.junit.Test)4 PathNotFoundException (org.craftercms.core.exception.PathNotFoundException)3 Item (org.craftercms.core.service.Item)3 ItemProcessorPipeline (org.craftercms.core.processors.impl.ItemProcessorPipeline)2 TextMetaDataCollectionExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor)2 Tree (org.craftercms.core.service.Tree)1 CachingAwareList (org.craftercms.core.util.cache.impl.CachingAwareList)1