From 878297316b96044ffd879c82be2ba7a54a57804c Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 14 Sep 2011 15:34:19 +0000 Subject: [PATCH] ALF-9981 Add unit tests for the selectSingleNode freemarker function used in the example scheduled action git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30512 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../FreeMarkerModelLuceneFunctionTest.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/source/java/org/alfresco/repo/action/scheduled/FreeMarkerModelLuceneFunctionTest.java b/source/java/org/alfresco/repo/action/scheduled/FreeMarkerModelLuceneFunctionTest.java index d10fad0dd7..0599c32405 100644 --- a/source/java/org/alfresco/repo/action/scheduled/FreeMarkerModelLuceneFunctionTest.java +++ b/source/java/org/alfresco/repo/action/scheduled/FreeMarkerModelLuceneFunctionTest.java @@ -29,10 +29,11 @@ import junit.framework.TestCase; import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.repository.TemplateException; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ApplicationContextHelper; -import org.springframework.extensions.surf.util.ISO8601DateFormat; import org.springframework.context.ApplicationContext; +import org.springframework.extensions.surf.util.ISO8601DateFormat; /** * Test that the correct date ranges are generated for lucene @@ -209,4 +210,40 @@ public class FreeMarkerModelLuceneFunctionTest extends TestCase String result = serviceRegistry.getTemplateService().processTemplateString("freemarker", template, mf.getModel()); assertEquals(result, "["+isoStartDate+" TO "+isoStartDate+"]"); } + + /** + * Tests finding single nodes by a lucene query. + * Uses a node with a special, known noderef + */ + public void testSelectSingleNode() + { + String renderingSpaceNodeRef = "workspace://SpacesStore/rendering_actions_space"; + + // Build a selectSingleNode to get the rendering actions space by path + String rendering_space = "rendering_actions"; + String path = "'PATH:\"/app:company_home/app:dictionary/app:" + rendering_space + "\"'"; + String template = "${selectSingleNode('workspace://SpacesStore', 'lucene', "+path+" )}"; + + // Evaluate the script + FreeMarkerWithLuceneExtensionsModelFactory mf = new FreeMarkerWithLuceneExtensionsModelFactory(); + mf.setServiceRegistry(serviceRegistry); + String result = serviceRegistry.getTemplateService().processTemplateString("freemarker", template, mf.getModel()); + + // Check we got the magic, known noderef back + assertEquals(result, renderingSpaceNodeRef); + + + // Now check for a node that doesn't exist + String invalidSpace = "DOESnotEXISTspace"; + path = "'PATH:\"/app:company_home/app:dictionary/app:" + invalidSpace + "\"'"; + template = "${selectSingleNode('workspace://SpacesStore', 'lucene', "+path+" )}"; + + // Will fail with "No Nodes Selected" + try + { + result = serviceRegistry.getTemplateService().processTemplateString("freemarker", template, mf.getModel()); + fail("Shouldn't find anything, but got" + result); + } + catch(TemplateException e) {} + } } \ No newline at end of file