From 0007fc3013bc4fe133bfaf2d5b04c16cf3acd805 Mon Sep 17 00:00:00 2001 From: Silviu Dinuta Date: Thu, 14 Apr 2016 12:06:39 +0300 Subject: [PATCH 1/5] Added NonElectronicRecordType class to make sure that Record aspect is added before entering in UpdatePropertiesPolicy for nonElectronic documents --- .../rm-model-context.xml | 3 + .../rma/type/NonElectronicRecordType.java | 96 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index 18fe9ee15f..deebceb06e 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -66,6 +66,9 @@ + + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java new file mode 100644 index 0000000000..2322a1cff7 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java @@ -0,0 +1,96 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.model.rma.type; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.record.RecordService; +import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; +import org.alfresco.repo.policy.annotation.Behaviour; +import org.alfresco.repo.policy.annotation.BehaviourBean; +import org.alfresco.repo.policy.annotation.BehaviourKind; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; + +@BehaviourBean(defaultType = "rma:nonElectronicDocument") +public class NonElectronicRecordType extends BaseBehaviourBean implements NodeServicePolicies.OnUpdateNodePolicy +{ + + /** record service */ + protected RecordService recordService; + + /** + * @param recordService record service + */ + public void setRecordService(RecordService recordService) + { + this.recordService = recordService; + } + + @Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.FIRST_EVENT) + @Override + public void onUpdateNode(final NodeRef nodeRef) + { + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @Override + public Void doWork() + { + final NodeRef child = nodeRef; + if (nodeService.exists(child)) + { + QName childType = nodeService.getType(child); + NodeRef parentRef = nodeService.getPrimaryParent(child).getParentRef(); + QName parentType = nodeService.getType(parentRef); + boolean isContentSubType = dictionaryService.isSubClass(childType, ContentModel.TYPE_CONTENT); + boolean isUnfiledRecordContainer = parentType + .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER); + boolean isUnfiledRecordFolder = parentType + .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER); + if (isContentSubType && (isUnfiledRecordContainer || isUnfiledRecordFolder)) + { + if (!nodeService.hasAspect(child, ASPECT_FILE_PLAN_COMPONENT)) + { + nodeService.addAspect(child, ASPECT_FILE_PLAN_COMPONENT, null); + } + if (!nodeService.hasAspect(child, ASPECT_RECORD)) + { + recordService.makeRecord(child); + } + } + } + return null; + } + }); + } + +} From 0d52abc77ea3e9c6514bf10d9adcfd0d136fb7ff Mon Sep 17 00:00:00 2001 From: Silviu Dinuta Date: Thu, 14 Apr 2016 15:24:30 +0300 Subject: [PATCH 2/5] Added @author and @since for the class --- .../rma/type/NonElectronicRecordType.java | 180 +++++++++--------- 1 file changed, 93 insertions(+), 87 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java index 2322a1cff7..6a28c62f0d 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java @@ -4,93 +4,99 @@ * %% * Copyright (C) 2005 - 2016 Alfresco Software Limited * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License * along with Alfresco. If not, see . * #L% */ - -package org.alfresco.module.org_alfresco_module_rm.model.rma.type; - -import org.alfresco.model.ContentModel; -import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; -import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; -import org.alfresco.module.org_alfresco_module_rm.record.RecordService; -import org.alfresco.repo.node.NodeServicePolicies; -import org.alfresco.repo.policy.Behaviour.NotificationFrequency; -import org.alfresco.repo.policy.annotation.Behaviour; -import org.alfresco.repo.policy.annotation.BehaviourBean; -import org.alfresco.repo.policy.annotation.BehaviourKind; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.QName; - -@BehaviourBean(defaultType = "rma:nonElectronicDocument") -public class NonElectronicRecordType extends BaseBehaviourBean implements NodeServicePolicies.OnUpdateNodePolicy -{ - - /** record service */ - protected RecordService recordService; - - /** - * @param recordService record service - */ - public void setRecordService(RecordService recordService) - { - this.recordService = recordService; - } - - @Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.FIRST_EVENT) - @Override - public void onUpdateNode(final NodeRef nodeRef) - { - AuthenticationUtil.runAsSystem(new RunAsWork() - { - @Override - public Void doWork() - { - final NodeRef child = nodeRef; - if (nodeService.exists(child)) - { - QName childType = nodeService.getType(child); - NodeRef parentRef = nodeService.getPrimaryParent(child).getParentRef(); - QName parentType = nodeService.getType(parentRef); - boolean isContentSubType = dictionaryService.isSubClass(childType, ContentModel.TYPE_CONTENT); - boolean isUnfiledRecordContainer = parentType - .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER); - boolean isUnfiledRecordFolder = parentType - .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER); - if (isContentSubType && (isUnfiledRecordContainer || isUnfiledRecordFolder)) - { - if (!nodeService.hasAspect(child, ASPECT_FILE_PLAN_COMPONENT)) - { - nodeService.addAspect(child, ASPECT_FILE_PLAN_COMPONENT, null); - } - if (!nodeService.hasAspect(child, ASPECT_RECORD)) - { - recordService.makeRecord(child); - } - } - } - return null; - } - }); - } - -} + +package org.alfresco.module.org_alfresco_module_rm.model.rma.type; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.record.RecordService; +import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; +import org.alfresco.repo.policy.annotation.Behaviour; +import org.alfresco.repo.policy.annotation.BehaviourBean; +import org.alfresco.repo.policy.annotation.BehaviourKind; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; + +/** + * rma:nonElectronicDocument behaviour bean. + * + * @author silviudinuta + * @since 2.4 + */ +@BehaviourBean(defaultType = "rma:nonElectronicDocument") +public class NonElectronicRecordType extends BaseBehaviourBean implements NodeServicePolicies.OnUpdateNodePolicy +{ + + /** record service */ + protected RecordService recordService; + + /** + * @param recordService record service + */ + public void setRecordService(RecordService recordService) + { + this.recordService = recordService; + } + + @Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.FIRST_EVENT) + @Override + public void onUpdateNode(final NodeRef nodeRef) + { + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @Override + public Void doWork() + { + final NodeRef child = nodeRef; + if (nodeService.exists(child)) + { + QName childType = nodeService.getType(child); + NodeRef parentRef = nodeService.getPrimaryParent(child).getParentRef(); + QName parentType = nodeService.getType(parentRef); + boolean isContentSubType = dictionaryService.isSubClass(childType, ContentModel.TYPE_CONTENT); + boolean isUnfiledRecordContainer = parentType + .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER); + boolean isUnfiledRecordFolder = parentType + .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER); + if (isContentSubType && (isUnfiledRecordContainer || isUnfiledRecordFolder)) + { + if (!nodeService.hasAspect(child, ASPECT_FILE_PLAN_COMPONENT)) + { + nodeService.addAspect(child, ASPECT_FILE_PLAN_COMPONENT, null); + } + if (!nodeService.hasAspect(child, ASPECT_RECORD)) + { + recordService.makeRecord(child); + } + } + } + return null; + } + }); + } + +} From f8332dccae46c1c5cbb56bfb7bf9f41f88c22460 Mon Sep 17 00:00:00 2001 From: Silviu Dinuta Date: Thu, 14 Apr 2016 18:54:41 +0300 Subject: [PATCH 3/5] Added unit tests for NonElectronicRecordType and fixed typo --- .../rm-model-context.xml | 3 +- .../rma/type/NonElectronicRecordType.java | 5 +- .../type/NonElectronicRecordTypeUnitTest.java | 103 ++++++++++++++++++ 3 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index deebceb06e..96130f9e01 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -66,7 +66,8 @@ - + + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java index 6a28c62f0d..b9f608e612 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java @@ -27,7 +27,6 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; -import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; @@ -74,15 +73,13 @@ public class NonElectronicRecordType extends BaseBehaviourBean implements NodeSe final NodeRef child = nodeRef; if (nodeService.exists(child)) { - QName childType = nodeService.getType(child); NodeRef parentRef = nodeService.getPrimaryParent(child).getParentRef(); QName parentType = nodeService.getType(parentRef); - boolean isContentSubType = dictionaryService.isSubClass(childType, ContentModel.TYPE_CONTENT); boolean isUnfiledRecordContainer = parentType .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER); boolean isUnfiledRecordFolder = parentType .equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER); - if (isContentSubType && (isUnfiledRecordContainer || isUnfiledRecordFolder)) + if (isUnfiledRecordContainer || isUnfiledRecordFolder) { if (!nodeService.hasAspect(child, ASPECT_FILE_PLAN_COMPONENT)) { diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java new file mode 100644 index 0000000000..cc417a7349 --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java @@ -0,0 +1,103 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.model.rma.type; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper; +import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * @author silviudinuta + */ +public class NonElectronicRecordTypeUnitTest extends BaseUnitTest +{ + + @InjectMocks + NonElectronicRecordType nonElectronicRecordType; + @Mock + AuthenticationUtil mockAuthenticationUtil; + + @Before + public void setUp() + { + MockitoAnnotations.initMocks(this); + MockAuthenticationUtilHelper.setup(mockAuthenticationUtil); + } + + @SuppressWarnings("unchecked") + @Test + public void testOnUpdateWithAspectsAlreadyPresent() + { + NodeRef nodeRef = generateNodeRef(); + NodeRef parentNodeRef=generateNodeRef(); + ChildAssociationRef generateChildAssociationRef = generateChildAssociationRef(parentNodeRef, nodeRef); + when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(generateChildAssociationRef); + when(mockedNodeService.getType(parentNodeRef)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); + when(mockedNodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(true); + when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true); + + nonElectronicRecordType.onUpdateNode(nodeRef); + + verify(mockedNodeService, never()).addAspect(eq(nodeRef), eq(ASPECT_FILE_PLAN_COMPONENT), any(Map.class)); + verify(mockedRecordService, never()).makeRecord(eq(nodeRef)); + } + + @SuppressWarnings("unchecked") + @Test + public void testOnUpdateWithoutTheAspects() + { + NodeRef nodeRef = generateNodeRef(); + NodeRef parentNodeRef=generateNodeRef(); + ChildAssociationRef generateChildAssociationRef = generateChildAssociationRef(parentNodeRef, nodeRef); + when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(generateChildAssociationRef); + when(mockedNodeService.getType(parentNodeRef)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); + when(mockedNodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); + when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false); + + nonElectronicRecordType.onUpdateNode(nodeRef); + + verify(mockedNodeService, times(1)).addAspect(eq(nodeRef), eq(ASPECT_FILE_PLAN_COMPONENT), any(Map.class)); + verify(mockedRecordService, times(1)).makeRecord(eq(nodeRef)); + } +} From eca36c48b2e785d1f830319dbb736856ac69c177 Mon Sep 17 00:00:00 2001 From: Silviu Dinuta Date: Fri, 15 Apr 2016 10:41:53 +0300 Subject: [PATCH 4/5] Changed NonElectronicRecordTypeUnitTest --- .../type/NonElectronicRecordTypeUnitTest.java | 57 +++++++++++++------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java index cc417a7349..8f3f8dcb0a 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java @@ -27,20 +27,24 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.util.Map; - -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.test.util.MockAuthenticationUtilHelper; import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.util.GUID; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -50,14 +54,21 @@ import org.mockito.MockitoAnnotations; /** * @author silviudinuta */ -public class NonElectronicRecordTypeUnitTest extends BaseUnitTest +public class NonElectronicRecordTypeUnitTest implements RecordsManagementModel, ContentModel { @InjectMocks NonElectronicRecordType nonElectronicRecordType; + @Mock AuthenticationUtil mockAuthenticationUtil; + @Mock + RecordService mockedRecordService; + + @Mock + NodeService mockedNodeService; + @Before public void setUp() { @@ -65,13 +76,19 @@ public class NonElectronicRecordTypeUnitTest extends BaseUnitTest MockAuthenticationUtilHelper.setup(mockAuthenticationUtil); } - @SuppressWarnings("unchecked") @Test public void testOnUpdateWithAspectsAlreadyPresent() { - NodeRef nodeRef = generateNodeRef(); - NodeRef parentNodeRef=generateNodeRef(); - ChildAssociationRef generateChildAssociationRef = generateChildAssociationRef(parentNodeRef, nodeRef); + NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); + when(mockedNodeService.exists(eq(nodeRef))).thenReturn(true); + + NodeRef parentNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); + when(mockedNodeService.exists(eq(parentNodeRef))).thenReturn(true); + + ChildAssociationRef generateChildAssociationRef = mock(ChildAssociationRef.class); + doReturn(parentNodeRef).when(generateChildAssociationRef).getParentRef(); + doReturn(nodeRef).when(generateChildAssociationRef).getChildRef(); + when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(generateChildAssociationRef); when(mockedNodeService.getType(parentNodeRef)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); when(mockedNodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(true); @@ -79,17 +96,23 @@ public class NonElectronicRecordTypeUnitTest extends BaseUnitTest nonElectronicRecordType.onUpdateNode(nodeRef); - verify(mockedNodeService, never()).addAspect(eq(nodeRef), eq(ASPECT_FILE_PLAN_COMPONENT), any(Map.class)); - verify(mockedRecordService, never()).makeRecord(eq(nodeRef)); + verify(mockedNodeService, never()).addAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT, null); + verify(mockedRecordService, never()).makeRecord(nodeRef); } - @SuppressWarnings("unchecked") @Test public void testOnUpdateWithoutTheAspects() { - NodeRef nodeRef = generateNodeRef(); - NodeRef parentNodeRef=generateNodeRef(); - ChildAssociationRef generateChildAssociationRef = generateChildAssociationRef(parentNodeRef, nodeRef); + NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); + when(mockedNodeService.exists(eq(nodeRef))).thenReturn(true); + + NodeRef parentNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); + when(mockedNodeService.exists(eq(parentNodeRef))).thenReturn(true); + + ChildAssociationRef generateChildAssociationRef = mock(ChildAssociationRef.class); + doReturn(parentNodeRef).when(generateChildAssociationRef).getParentRef(); + doReturn(nodeRef).when(generateChildAssociationRef).getChildRef(); + when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(generateChildAssociationRef); when(mockedNodeService.getType(parentNodeRef)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); when(mockedNodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); @@ -97,7 +120,7 @@ public class NonElectronicRecordTypeUnitTest extends BaseUnitTest nonElectronicRecordType.onUpdateNode(nodeRef); - verify(mockedNodeService, times(1)).addAspect(eq(nodeRef), eq(ASPECT_FILE_PLAN_COMPONENT), any(Map.class)); - verify(mockedRecordService, times(1)).makeRecord(eq(nodeRef)); + verify(mockedNodeService, times(1)).addAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT, null); + verify(mockedRecordService, times(1)).makeRecord(nodeRef); } } From 5eaf78dc8e1411bcd25d77e0e475add245a3e473 Mon Sep 17 00:00:00 2001 From: Silviu Dinuta Date: Fri, 15 Apr 2016 11:09:32 +0300 Subject: [PATCH 5/5] Changed NonElectronicRecortTypeUnitTest --- .../type/NonElectronicRecordTypeUnitTest.java | 59 ++++++++----------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java index 8f3f8dcb0a..eb4fad6ae7 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordTypeUnitTest.java @@ -27,8 +27,6 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -56,6 +54,10 @@ import org.mockito.MockitoAnnotations; */ public class NonElectronicRecordTypeUnitTest implements RecordsManagementModel, ContentModel { + private final static NodeRef CHILD_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, + GUID.generate()); + private final static NodeRef PARENT_NODE_REF = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, + GUID.generate()); @InjectMocks NonElectronicRecordType nonElectronicRecordType; @@ -74,53 +76,38 @@ public class NonElectronicRecordTypeUnitTest implements RecordsManagementModel, { MockitoAnnotations.initMocks(this); MockAuthenticationUtilHelper.setup(mockAuthenticationUtil); + when(mockedNodeService.exists(CHILD_NODE_REF)).thenReturn(true); + when(mockedNodeService.exists(PARENT_NODE_REF)).thenReturn(true); + + ChildAssociationRef generateChildAssociationRef = mock(ChildAssociationRef.class); + when(generateChildAssociationRef.getParentRef()).thenReturn(PARENT_NODE_REF); + when(generateChildAssociationRef.getChildRef()).thenReturn(CHILD_NODE_REF); + + when(mockedNodeService.getPrimaryParent(CHILD_NODE_REF)).thenReturn(generateChildAssociationRef); + when(mockedNodeService.getType(PARENT_NODE_REF)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); } @Test public void testOnUpdateWithAspectsAlreadyPresent() { - NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); - when(mockedNodeService.exists(eq(nodeRef))).thenReturn(true); + when(mockedNodeService.hasAspect(CHILD_NODE_REF, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(true); + when(mockedNodeService.hasAspect(CHILD_NODE_REF, ASPECT_RECORD)).thenReturn(true); - NodeRef parentNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); - when(mockedNodeService.exists(eq(parentNodeRef))).thenReturn(true); + nonElectronicRecordType.onUpdateNode(CHILD_NODE_REF); - ChildAssociationRef generateChildAssociationRef = mock(ChildAssociationRef.class); - doReturn(parentNodeRef).when(generateChildAssociationRef).getParentRef(); - doReturn(nodeRef).when(generateChildAssociationRef).getChildRef(); - - when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(generateChildAssociationRef); - when(mockedNodeService.getType(parentNodeRef)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); - when(mockedNodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(true); - when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true); - - nonElectronicRecordType.onUpdateNode(nodeRef); - - verify(mockedNodeService, never()).addAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT, null); - verify(mockedRecordService, never()).makeRecord(nodeRef); + verify(mockedNodeService, never()).addAspect(CHILD_NODE_REF, ASPECT_FILE_PLAN_COMPONENT, null); + verify(mockedRecordService, never()).makeRecord(CHILD_NODE_REF); } @Test public void testOnUpdateWithoutTheAspects() { - NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); - when(mockedNodeService.exists(eq(nodeRef))).thenReturn(true); + when(mockedNodeService.hasAspect(CHILD_NODE_REF, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); + when(mockedNodeService.hasAspect(CHILD_NODE_REF, ASPECT_RECORD)).thenReturn(false); - NodeRef parentNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, GUID.generate()); - when(mockedNodeService.exists(eq(parentNodeRef))).thenReturn(true); + nonElectronicRecordType.onUpdateNode(CHILD_NODE_REF); - ChildAssociationRef generateChildAssociationRef = mock(ChildAssociationRef.class); - doReturn(parentNodeRef).when(generateChildAssociationRef).getParentRef(); - doReturn(nodeRef).when(generateChildAssociationRef).getChildRef(); - - when(mockedNodeService.getPrimaryParent(nodeRef)).thenReturn(generateChildAssociationRef); - when(mockedNodeService.getType(parentNodeRef)).thenReturn(TYPE_UNFILED_RECORD_FOLDER); - when(mockedNodeService.hasAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT)).thenReturn(false); - when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false); - - nonElectronicRecordType.onUpdateNode(nodeRef); - - verify(mockedNodeService, times(1)).addAspect(nodeRef, ASPECT_FILE_PLAN_COMPONENT, null); - verify(mockedRecordService, times(1)).makeRecord(nodeRef); + verify(mockedNodeService, times(1)).addAspect(CHILD_NODE_REF, ASPECT_FILE_PLAN_COMPONENT, null); + verify(mockedRecordService, times(1)).makeRecord(CHILD_NODE_REF); } }