use of org.alfresco.service.cmr.rule.RuleServiceException in project alfresco-repository by Alfresco.
the class RuleServiceCoverageTest method testContainsTextCondition.
/**
* Test:
* rule type: inbound
* condition: match-text(
* text = .doc,
* operation = CONTAINS)
* action: add-features(
* aspect-name = versionable)
*/
public void testContainsTextCondition() {
Map<String, Serializable> actionParams = new HashMap<String, Serializable>(1);
actionParams.put("aspect-name", ContentModel.ASPECT_VERSIONABLE);
// ActionCondition parameter's
Map<String, Serializable> condParams = new HashMap<String, Serializable>(1);
condParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, ".doc");
Rule rule = createRule(RuleType.INBOUND, AddFeaturesActionExecuter.NAME, actionParams, ComparePropertyValueEvaluator.NAME, condParams);
this.ruleService.saveRule(this.nodeRef, rule);
// Test condition failure
Map<QName, Serializable> props1 = new HashMap<QName, Serializable>();
props1.put(ContentModel.PROP_NAME, "bobbins.txt");
// props1.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
NodeRef newNodeRef = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, props1).getChildRef();
addContentToNode(newNodeRef);
// Map<QName, Serializable> map = this.nodeService.getProperties(newNodeRef);
// String value = (String)this.nodeService.getProperty(newNodeRef, ContentModel.PROP_NAME);
assertFalse(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE));
// Test condition success
Map<QName, Serializable> props2 = new HashMap<QName, Serializable>();
props2.put(ContentModel.PROP_NAME, "bobbins.doc");
// props2.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
NodeRef newNodeRef2 = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, props2).getChildRef();
addContentToNode(newNodeRef2);
assertTrue(this.nodeService.hasAspect(newNodeRef2, ContentModel.ASPECT_VERSIONABLE));
try {
// Test name not set
NodeRef newNodeRef3 = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, getContentProperties()).getChildRef();
addContentToNode(newNodeRef3);
} catch (RuleServiceException exception) {
// Correct since text-match is a mandatory property
}
// Test begins with
Map<String, Serializable> condParamsBegins = new HashMap<String, Serializable>(1);
condParamsBegins.put(ComparePropertyValueEvaluator.PARAM_VALUE, "bob*");
rule.getAction().removeAllActionConditions();
ActionCondition condition1 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME, condParamsBegins);
rule.getAction().addActionCondition(condition1);
this.ruleService.saveRule(this.nodeRef, rule);
Map<QName, Serializable> propsx = new HashMap<QName, Serializable>();
propsx.put(ContentModel.PROP_NAME, "mybobbins.doc");
// propsx.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
NodeRef newNodeRefx = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, propsx).getChildRef();
addContentToNode(newNodeRefx);
assertFalse(this.nodeService.hasAspect(newNodeRefx, ContentModel.ASPECT_VERSIONABLE));
Map<QName, Serializable> propsy = new HashMap<QName, Serializable>();
propsy.put(ContentModel.PROP_NAME, "bobbins.doc");
// propsy.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
NodeRef newNodeRefy = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, propsy).getChildRef();
addContentToNode(newNodeRefy);
assertTrue(this.nodeService.hasAspect(newNodeRefy, ContentModel.ASPECT_VERSIONABLE));
// Test ends with
Map<String, Serializable> condParamsEnds = new HashMap<String, Serializable>(1);
condParamsEnds.put(ComparePropertyValueEvaluator.PARAM_VALUE, "*s.doc");
rule.getAction().removeAllActionConditions();
ActionCondition condition2 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME, condParamsEnds);
rule.getAction().addActionCondition(condition2);
this.ruleService.saveRule(this.nodeRef, rule);
Map<QName, Serializable> propsa = new HashMap<QName, Serializable>();
propsa.put(ContentModel.PROP_NAME, "bobbins.document");
// propsa.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
NodeRef newNodeRefa = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, propsa).getChildRef();
addContentToNode(newNodeRefa);
assertFalse(this.nodeService.hasAspect(newNodeRefa, ContentModel.ASPECT_VERSIONABLE));
Map<QName, Serializable> propsb = new HashMap<QName, Serializable>();
propsb.put(ContentModel.PROP_NAME, "bobbins.doc");
// propsb.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
NodeRef newNodeRefb = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, propsb).getChildRef();
addContentToNode(newNodeRefb);
assertTrue(this.nodeService.hasAspect(newNodeRefb, ContentModel.ASPECT_VERSIONABLE));
}
Aggregations