From 4ddac214183000cf4bfb22f70f44048d4548e62c Mon Sep 17 00:00:00 2001 From: Silviu Dinuta Date: Mon, 7 Nov 2016 10:47:10 +0200 Subject: [PATCH] RM-4312: added comments to unit tests --- .../model/BaseBehaviourBean.java | 22 ++++--------------- .../model/rma/type/FilePlanType.java | 4 ++-- .../rma/type/HoldContainerTypeUnitTest.java | 8 +++++++ .../type/TransferContainerTypeUnitTest.java | 8 +++++++ .../UnfiledRecordContainerTypeUnitTest.java | 16 ++++++++++++++ 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/BaseBehaviourBean.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/BaseBehaviourBean.java index 8a48fdf58c..734b7d34e9 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/BaseBehaviourBean.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/BaseBehaviourBean.java @@ -127,28 +127,14 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl protected void validateNewChildAssociationSubTypesIncluded(NodeRef child, List acceptedMultipleChildType) throws InvalidParameterException { QName childType = getInternalNodeService().getType(child); - if(!validateNodeRef(acceptedMultipleChildType, childType)) - { - throw new InvalidParameterException("Operation failed. Children of type " + childType + " are not allowed"); - } - } - - /** - * Checks if the type of the provided nodeRef it is between the sub-types of accepted types - * - * @param acceptedMultipleChildType - * @param nodeType - * @return true if the type of the nodeRef is between the sub-types of accepted types, or false otherwise - */ - protected boolean validateNodeRef(List acceptedMultipleChildType, QName nodeType) - { for(QName type : acceptedMultipleChildType) { - if(instanceOf(nodeType, type)) + if(instanceOf(childType, type)) { - return true; + return; } } - return false; + //no match was found in sub-types of permitted types list + throw new InvalidParameterException("Operation failed. Children of type " + childType + " are not allowed"); } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java index 3f670044fc..3cc8cba850 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/FilePlanType.java @@ -63,8 +63,8 @@ public class FilePlanType extends BaseBehaviourBean NodeServicePolicies.OnCreateNodePolicy, NodeServicePolicies.OnDeleteNodePolicy { - private static List ACCEPTED_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_HOLD_CONTAINER, TYPE_TRANSFER_CONTAINER, TYPE_UNFILED_RECORD_CONTAINER); - private static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY); + private final static List ACCEPTED_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_HOLD_CONTAINER, TYPE_TRANSFER_CONTAINER, TYPE_UNFILED_RECORD_CONTAINER); + private final static List ACCEPTED_NON_UNIQUE_CHILD_TYPES = Arrays.asList(TYPE_RECORD_CATEGORY); /** file plan service */ private FilePlanService filePlanService; diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/HoldContainerTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/HoldContainerTypeUnitTest.java index 4e946da234..1a614fc075 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/HoldContainerTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/HoldContainerTypeUnitTest.java @@ -50,6 +50,10 @@ public class HoldContainerTypeUnitTest extends BaseUnitTest /** test object */ private @InjectMocks HoldContainerType holdContainerType; + /** + * Given that we try to add a non "rma:hold" type to hold container, + * Then InvalidParameterException is thrown. + */ @Test (expected = InvalidParameterException.class) public void testAddNonHoldTypeToHoldContainer() { @@ -64,6 +68,10 @@ public class HoldContainerTypeUnitTest extends BaseUnitTest holdContainerType.onCreateChildAssociation(mockedChildAssoc, true); } + /** + * Given that we try to add "rma:hold" type to hold container, + * Then the operation is successful. + */ @Test public void testAddHoldTypeToHoldContainer() { diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/TransferContainerTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/TransferContainerTypeUnitTest.java index 058e13b13b..2e3a3135b1 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/TransferContainerTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/TransferContainerTypeUnitTest.java @@ -50,6 +50,10 @@ public class TransferContainerTypeUnitTest extends BaseUnitTest /** test object */ private @InjectMocks TransferContainerType transferContainerType; + /** + * Given that we try to add a non "rma:transfer" type to transfer container, + * Then InvalidParameterException is thrown. + */ @Test(expected = InvalidParameterException.class) public void testAddNonTransferTypeToTransferContainerTest() { @@ -65,6 +69,10 @@ public class TransferContainerTypeUnitTest extends BaseUnitTest transferContainerType.onCreateChildAssociation(mockedChildAssoc, true); } + /** + * Given that we try to add "rma:transfer" type to transfer container, + * Then the operation is successful. + */ @Test public void testAddTransferFolderToTransferContainer() { diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordContainerTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordContainerTypeUnitTest.java index 57202bbeea..5ed5fc662e 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordContainerTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/UnfiledRecordContainerTypeUnitTest.java @@ -52,6 +52,10 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest @InjectMocks private UnfiledRecordContainerType unfiledRecordContainerType; + /** + * Given that we try to add a type that is not one of "rma:unfiledRecordFolder", "cm:content" or "rma:nonElectronicDocument" types to unfiled record container, + * Then InvalidParameterException is thrown. + */ @Test(expected = InvalidParameterException.class) public void testAddNonAcceptedTypeToUnfiledRecordContainer() { @@ -69,6 +73,10 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest unfiledRecordContainerType.onCreateChildAssociation(mockedChildAssoc, true); } + /** + * Given that we try to add "rma:unfiledRecordFolder" sub-type to unfiled record container, + * Then the operation is successful. + */ @Test public void testAddUnfiledRecordFolderTypeToUnfiledRecordContainer() { @@ -86,6 +94,10 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest unfiledRecordContainerType.onCreateChildAssociation(mockedChildAssoc, true); } + /** + * Given that we try to add "cm:content" sub-type to unfiled record container, + * Then the operation is successful. + */ @Test public void testAddContentTypeToUnfiledRecordContainer() { @@ -103,6 +115,10 @@ public class UnfiledRecordContainerTypeUnitTest extends BaseUnitTest unfiledRecordContainerType.onCreateChildAssociation(mockedChildAssoc, true); } + /** + * Given that we try to add "rma:nonElectronicDocument" sub-type to unfiled record container, + * Then the operation is successful. + */ @Test public void testNonElectronicDocumentTypeToUnfiledRecordContainer() {