Search in sources :

Example 1 with TextMetaDataCollectionExtractingProcessor

use of org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor 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)

Example 2 with TextMetaDataCollectionExtractingProcessor

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

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

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