use of org.craftercms.core.exception.PathNotFoundException in project core by craftercms.
the class ContentStoreRestControllerTest method testHandlePathNotFoundException.
@Test
public void testHandlePathNotFoundException() throws Exception {
PathNotFoundException ex = new PathNotFoundException("This is a test");
Map<String, Object> model = storeRestController.handlePathNotFoundException(request, ex);
assertEquals(ex.getMessage(), model.get(MESSAGE_MODEL_ATTRIBUTE_NAME));
}
use of org.craftercms.core.exception.PathNotFoundException 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) {
}
}
use of org.craftercms.core.exception.PathNotFoundException in project engine by craftercms.
the class ContentStoreServiceMockUtils method setUpGetContentFromClassPath.
public static ContentStoreService setUpGetContentFromClassPath(ContentStoreService mock) {
Answer<Content> getContentAnswer = new Answer<Content>() {
@Override
public Content answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
String url;
if (args.length == 2) {
url = (String) args[1];
} else {
url = (String) args[2];
}
Content content = getContentFromClassPath(url);
if (content == null) {
throw new PathNotFoundException();
}
return content;
}
};
Answer<Boolean> existsAnswer = new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
String url = (String) args[1];
return new ClassPathResource(url).exists();
}
};
when(mock.getContent(any(Context.class), anyString())).then(getContentAnswer);
when(mock.getContent(any(Context.class), any(CachingOptions.class), anyString())).then(getContentAnswer);
when(mock.exists(any(Context.class), anyString())).then(existsAnswer);
when(mock.findChildren(any(Context.class), anyString())).then(new Answer<List<Item>>() {
@Override
public List<Item> answer(InvocationOnMock invocation) throws Throwable {
String folderUrl = (String) invocation.getArguments()[1];
Resource folderRes = new ClassPathResource(folderUrl);
File folder = folderRes.getFile();
String[] childNames = folder.list();
List<Item> children = new ArrayList<>(childNames.length);
for (String childName : childNames) {
Item child = new Item();
child.setUrl(folderUrl + "/" + childName);
children.add(child);
}
return children;
}
});
return mock;
}
use of org.craftercms.core.exception.PathNotFoundException 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) {
}
}
use of org.craftercms.core.exception.PathNotFoundException 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) {
}
}
Aggregations