RM-2477 Treat the empty string in the same way as null.

Fix an issue in the behaviour checking where the empty string was being
passed as the instructions when nothing was set.

+review RM

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@109843 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tom Page
2015-08-10 10:24:57 +00:00
parent 055eabac78
commit 43ea2e5bc4
2 changed files with 26 additions and 1 deletions

View File

@@ -144,10 +144,23 @@ public class ClassifiedAspect extends BaseBehaviourBean implements NodeServicePo
Serializable downgradeDate = nodeService.getProperty(nodeRef, PROP_DOWNGRADE_DATE);
Serializable downgradeEvent = nodeService.getProperty(nodeRef, PROP_DOWNGRADE_EVENT);
Serializable downgradeInstructions = nodeService.getProperty(nodeRef, PROP_DOWNGRADE_INSTRUCTIONS);
if (downgradeInstructions == null && (downgradeDate != null || downgradeEvent != null))
if (isEmpty(downgradeInstructions) && !(isEmpty(downgradeDate) && isEmpty(downgradeEvent)))
{
throw new MissingDowngradeInstructions(nodeRef);
}
}
}
/**
* Check if a property is null or the empty string. Note that this is the same as
* {@link org.apache.commons.lang.StringUtils#isEmpty(String)}, except that it takes a Serializable rather than a
* String. This avoids awkward casting exceptions when working with properties.
*
* @param value The (probably String) value to check.
* @return true if the supplied value is null or the empty string.
*/
private boolean isEmpty(Serializable value)
{
return (value == null || value.equals(""));
}
}

View File

@@ -98,4 +98,16 @@ public class ClassifiedAspectUnitTest implements ClassifiedContentModel
classifiedAspect.checkConsistencyOfProperties(NODE_REF);
}
/** Check that blank instructions are treated in the same way as null instructions. */
@Test(expected = MissingDowngradeInstructions.class)
public void testCheckConsistencyOfProperties_emptyStringsSupplied()
{
when(mockNodeService.hasAspect(NODE_REF, ASPECT_CLASSIFIED)).thenReturn(true);
when(mockNodeService.getProperty(NODE_REF, PROP_DOWNGRADE_DATE)).thenReturn("");
when(mockNodeService.getProperty(NODE_REF, PROP_DOWNGRADE_EVENT)).thenReturn("Event");
when(mockNodeService.getProperty(NODE_REF, PROP_DOWNGRADE_INSTRUCTIONS)).thenReturn("");
classifiedAspect.checkConsistencyOfProperties(NODE_REF);
}
}