Search in sources :

Example 16 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class HasAspectEvaluatorTest method testMandatoryParamsMissing.

@Test
public void testMandatoryParamsMissing() {
    ActionCondition condition = new ActionConditionImpl(ID, HasAspectEvaluator.NAME, null);
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("The fact that a mandatory parameter has not been set should have been detected.");
    } catch (Throwable exception) {
    // Do nothing since this is correct
    }
}
Also used : ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 17 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class ComparePropertyValueEvaluatorTest method testNumericComparison.

/**
 * Test numeric comparisions
 */
@Test
public void testNumericComparison() {
    ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_INT);
    // Test the default operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, INT_VALUE);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, INT_VALUE);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals greater than operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 99);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals greater than operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 99);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 100);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals less than operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 99);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals less than equals operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 101);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 100);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 99);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Ensure other operators are invalid
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
        exception.printStackTrace();
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
}
Also used : ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 18 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class ComparePropertyValueEvaluatorTest method testMultiValuedPropertyComparisons.

@Test
public void testMultiValuedPropertyComparisons() {
    ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_MULTI_VALUE);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "Document");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
}
Also used : ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 19 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class ComparePropertyValueEvaluatorTest method testContentPropertyComparisons.

@Test
public void testContentPropertyComparisons() {
    ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, ContentModel.PROP_CONTENT);
    // What happens if you do this and the node has no content set yet !!
    // Add some content to the node reference
    ContentWriter contentWriter = this.contentService.getWriter(this.nodeRef, ContentModel.PROP_CONTENT, true);
    contentWriter.setEncoding("UTF-8");
    contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
    contentWriter.putContent("This is some test content.");
    // Test matching the mimetype
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.MIME_TYPE.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, MimetypeMap.MIMETYPE_TEXT_PLAIN);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, MimetypeMap.MIMETYPE_HTML);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test matching the encoding
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.ENCODING.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "UTF-8");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "UTF-16");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test comparision to the size of the content
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_CONTENT_PROPERTY, ContentPropertyName.SIZE.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 50);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, 2);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 20 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class IsSubTypeEvaluatorTest method testFail.

@Test
public void testFail() {
    ActionCondition condition = new ActionConditionImpl(ID, IsSubTypeEvaluator.NAME, null);
    condition.setParameterValue(IsSubTypeEvaluator.PARAM_TYPE, ContentModel.TYPE_FOLDER);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
}
Also used : ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Aggregations

ActionConditionImpl (org.alfresco.repo.action.ActionConditionImpl)22 BaseSpringTest (org.alfresco.util.BaseSpringTest)16 Test (org.junit.Test)16 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)12 ActionServiceException (org.alfresco.service.cmr.action.ActionServiceException)4 Date (java.util.Date)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 JSONObject (org.json.JSONObject)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 FailedThumbnailInfo (org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo)1