mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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
This commit is contained in:
@@ -29,10 +29,11 @@ import junit.framework.TestCase;
|
|||||||
|
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
import org.alfresco.service.ServiceRegistry;
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.repository.TemplateException;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.alfresco.util.ApplicationContextHelper;
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
import org.springframework.extensions.surf.util.ISO8601DateFormat;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.extensions.surf.util.ISO8601DateFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the correct date ranges are generated for lucene
|
* 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());
|
String result = serviceRegistry.getTemplateService().processTemplateString("freemarker", template, mf.getModel());
|
||||||
assertEquals(result, "["+isoStartDate+" TO "+isoStartDate+"]");
|
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) {}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user