mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-4247 Merge master into RM-4247_UpdateDispositionProperty.
This commit is contained in:
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
|
||||
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.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Unit test for RmSiteType
|
||||
*
|
||||
* @author Silviu Dinuta
|
||||
* @since 2.6
|
||||
*
|
||||
*/
|
||||
public class RmSiteTypeUnitTest extends BaseUnitTest implements DOD5015Model
|
||||
{
|
||||
@Mock
|
||||
private AuthenticationUtil mockAuthenticationUtil;
|
||||
|
||||
@Mock
|
||||
private SiteService mockedSiteService;
|
||||
|
||||
private @InjectMocks RmSiteType rmSiteType;
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
MockitoAnnotations.initMocks(this);
|
||||
MockAuthenticationUtilHelper.setup(mockAuthenticationUtil);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add non allowed type to rm site,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddNonAcceptedTypeToRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
|
||||
|
||||
QName type = AlfMock.generateQName();
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type);
|
||||
|
||||
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
|
||||
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
|
||||
when(mockedChildAssoc.getParentRef()).thenReturn(rmSiteNodeRef);
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add one cm:folder to rm site,
|
||||
* Then operation is successful.
|
||||
*/
|
||||
@Test
|
||||
public void testAddOneFolderTypeToRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
|
||||
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
|
||||
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
|
||||
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add two cm:folder to rm site,
|
||||
* Then operation is successful.
|
||||
*/
|
||||
@Test
|
||||
public void testAddTwoFolderTypeToRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
|
||||
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
|
||||
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
|
||||
//create first folder
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
|
||||
//create second cm:folder
|
||||
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
|
||||
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add more than two cm:folder to rm site,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddMoreThanTwhoFolderTypeToRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
|
||||
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
|
||||
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(new ArrayList<ChildAssociationRef>());
|
||||
|
||||
//create first folder
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
|
||||
|
||||
//create second cm:folder
|
||||
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
|
||||
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
|
||||
//create third cm:folder
|
||||
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FOLDER);
|
||||
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FOLDER))).thenReturn(assocs);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add one rma:filePlan to rm site,
|
||||
* Then operation is successful.
|
||||
*/
|
||||
@Test
|
||||
public void testAddOneFilePlanTypeToRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
|
||||
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
|
||||
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FILE_PLAN);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FILE_PLAN))).thenReturn(assocs);
|
||||
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add one dod:filePlan to standard rm site,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddDODFilePlanTypeToStandardRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_DOD_5015_FILE_PLAN);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add more than one rma:filePlan to rm site,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddMoreThanOneFilePlanTypeToRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_RM_SITE, true);
|
||||
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
|
||||
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
|
||||
//first file plan creation
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FILE_PLAN);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FILE_PLAN))).thenReturn(assocs);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
|
||||
//second filePlan creation
|
||||
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FILE_PLAN);
|
||||
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_FILE_PLAN))).thenReturn(assocs);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add one dod:filePlan to rm site,
|
||||
* Then operation is successful.
|
||||
*/
|
||||
@Test
|
||||
public void testAddOneDODFilePlanTypeToRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_DOD_5015_SITE, true);
|
||||
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
|
||||
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteInfo.getNodeRef()).thenReturn(rmSiteNodeRef);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
|
||||
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_SITE, TYPE_RM_SITE)).thenReturn(true);
|
||||
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_FILE_PLAN, TYPE_FILE_PLAN)).thenReturn(true);
|
||||
rmSiteType.registerFilePlanType(TYPE_DOD_5015_SITE, TYPE_DOD_5015_FILE_PLAN);
|
||||
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_DOD_5015_FILE_PLAN);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_DOD_5015_FILE_PLAN))).thenReturn(assocs);
|
||||
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add more than one dod:filePlan to rm site,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddMoreThanOneDODFilePlanTypeToRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_DOD_5015_SITE, true);
|
||||
ArrayList<ChildAssociationRef> assocs = new ArrayList<ChildAssociationRef>();
|
||||
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteInfo.getNodeRef()).thenReturn(rmSiteNodeRef);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
|
||||
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_SITE, TYPE_RM_SITE)).thenReturn(true);
|
||||
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_FILE_PLAN, TYPE_FILE_PLAN)).thenReturn(true);
|
||||
rmSiteType.registerFilePlanType(TYPE_DOD_5015_SITE, TYPE_DOD_5015_FILE_PLAN);
|
||||
|
||||
//first dod:filePlan creation
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_DOD_5015_FILE_PLAN);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_DOD_5015_FILE_PLAN))).thenReturn(assocs);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
|
||||
//second dod:filePlan creation
|
||||
nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_DOD_5015_FILE_PLAN);
|
||||
mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
assocs.add(mockedChildAssoc);
|
||||
when(mockedNodeService.getChildAssocs(rmSiteNodeRef, Sets.newHashSet(TYPE_DOD_5015_FILE_PLAN))).thenReturn(assocs);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add one rma:filePlan to DOD rm site,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddStandardFilePlanTypeToDODRmSite()
|
||||
{
|
||||
NodeRef rmSiteNodeRef = generateNodeRef(TYPE_DOD_5015_SITE, true);
|
||||
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteInfo.getNodeRef()).thenReturn(rmSiteNodeRef);
|
||||
when(mockedSiteService.getSite(rmSiteNodeRef)).thenReturn(mockedSiteInfo);
|
||||
when(mockedApplicationContext.getBean("dbNodeService")).thenReturn(mockedNodeService);
|
||||
|
||||
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_SITE, TYPE_RM_SITE)).thenReturn(true);
|
||||
when(mockedDictionaryService.isSubClass(TYPE_DOD_5015_FILE_PLAN, TYPE_FILE_PLAN)).thenReturn(true);
|
||||
rmSiteType.registerFilePlanType(TYPE_DOD_5015_SITE, TYPE_DOD_5015_FILE_PLAN);
|
||||
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, TYPE_FILE_PLAN);
|
||||
ChildAssociationRef mockedChildAssoc = generateChildAssociationRef(rmSiteNodeRef, nodeRef);
|
||||
rmSiteType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
}
|
@@ -51,16 +51,15 @@ public class TransferContainerTypeUnitTest extends BaseUnitTest
|
||||
private @InjectMocks TransferContainerType transferContainerType;
|
||||
|
||||
/**
|
||||
* Given that we try to add a non "rma:transfer" type to transfer container,
|
||||
* Given that we try to add to transfer container,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddNonTransferTypeToTransferContainerTest()
|
||||
public void testAddToTransferContainerTest()
|
||||
{
|
||||
NodeRef transferContainer = generateNodeRef(TYPE_TRANSFER_CONTAINER, true);
|
||||
|
||||
QName type = AlfMock.generateQName();
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_TRANSFER)).thenReturn(false);
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type);
|
||||
|
||||
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
|
||||
@@ -68,22 +67,4 @@ public class TransferContainerTypeUnitTest extends BaseUnitTest
|
||||
when(mockedChildAssoc.getParentRef()).thenReturn(transferContainer);
|
||||
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()
|
||||
{
|
||||
QName type = AlfMock.generateQName();
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_TRANSFER)).thenReturn(true);
|
||||
NodeRef transferFolder= AlfMock.generateNodeRef(mockedNodeService, type);
|
||||
|
||||
NodeRef transferContainer = generateNodeRef(TYPE_TRANSFER_CONTAINER, true);
|
||||
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
|
||||
when(mockedChildAssoc.getChildRef()).thenReturn(transferFolder);
|
||||
when(mockedChildAssoc.getParentRef()).thenReturn(transferContainer);
|
||||
transferContainerType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
/**
|
||||
* Unit test for TransferType
|
||||
*
|
||||
* @author Silviu Dinuta
|
||||
* @since 2.6
|
||||
*/
|
||||
public class TransferTypeUnitTest extends BaseUnitTest
|
||||
{
|
||||
/** test object */
|
||||
private @InjectMocks TransferType transferType;
|
||||
|
||||
/**
|
||||
* Given that we try to add to transfer type folder,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddToTransferFolderTest()
|
||||
{
|
||||
NodeRef transferFolder = generateNodeRef(TYPE_TRANSFER, true);
|
||||
|
||||
QName type = AlfMock.generateQName();
|
||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService, type);
|
||||
|
||||
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
|
||||
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
|
||||
when(mockedChildAssoc.getParentRef()).thenReturn(transferFolder);
|
||||
transferType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
}
|
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.type;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
||||
/**
|
||||
* Unit test for UnfiledRecordFolderType
|
||||
*
|
||||
* @author Silviu Dinuta
|
||||
* @since 2.6
|
||||
*/
|
||||
public class UnfiledRecordFolderTypeUnitTest extends BaseUnitTest
|
||||
{
|
||||
@InjectMocks
|
||||
private UnfiledRecordFolderType unfiledRecordFolderType;
|
||||
|
||||
/**
|
||||
* Given that we try to add a type that is not one of "rma:unfiledRecordFolder", "cm:content" or "rma:nonElectronicDocument" types to unfiled record folder,
|
||||
* Then InvalidParameterException is thrown.
|
||||
*/
|
||||
@Test(expected = InvalidParameterException.class)
|
||||
public void testAddNonAcceptedTypeToUnfiledRecordFolder()
|
||||
{
|
||||
QName type = AlfMock.generateQName();
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
|
||||
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
|
||||
|
||||
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
|
||||
|
||||
NodeRef unfiledRecordFolder = generateNodeRef(TYPE_UNFILED_RECORD_FOLDER, true);
|
||||
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
|
||||
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
|
||||
when(mockedChildAssoc.getParentRef()).thenReturn(unfiledRecordFolder);
|
||||
unfiledRecordFolderType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add "rma:unfiledRecordFolder" sub-type to unfiled record folder,
|
||||
* Then the operation is successful.
|
||||
*/
|
||||
@Test
|
||||
public void testAddUnfiledRecordFolderTypeToUnfiledRecordFolder()
|
||||
{
|
||||
QName type = AlfMock.generateQName();
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(true);
|
||||
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
|
||||
|
||||
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
|
||||
|
||||
NodeRef unfiledRecordFolder = generateNodeRef(TYPE_UNFILED_RECORD_FOLDER, true);
|
||||
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
|
||||
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
|
||||
when(mockedChildAssoc.getParentRef()).thenReturn(unfiledRecordFolder);
|
||||
unfiledRecordFolderType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add "cm:content" sub-type to unfiled record folder,
|
||||
* Then the operation is successful.
|
||||
*/
|
||||
@Test
|
||||
public void testAddContentTypeToUnfiledRecordFolder()
|
||||
{
|
||||
QName type = AlfMock.generateQName();
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
|
||||
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(true);
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(false);
|
||||
|
||||
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
|
||||
|
||||
NodeRef unfiledRecordFolder = generateNodeRef(TYPE_UNFILED_RECORD_FOLDER, true);
|
||||
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
|
||||
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
|
||||
when(mockedChildAssoc.getParentRef()).thenReturn(unfiledRecordFolder);
|
||||
unfiledRecordFolderType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given that we try to add "rma:nonElectronicDocument" sub-type to unfiled record folder,
|
||||
* Then the operation is successful.
|
||||
*/
|
||||
@Test
|
||||
public void testNonElectronicDocumentTypeToUnfiledRecordFolder()
|
||||
{
|
||||
QName type = AlfMock.generateQName();
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_UNFILED_RECORD_FOLDER)).thenReturn(false);
|
||||
when(mockedDictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT)).thenReturn(false);
|
||||
when(mockedDictionaryService.isSubClass(type, TYPE_NON_ELECTRONIC_DOCUMENT)).thenReturn(true);
|
||||
|
||||
NodeRef nodeRef= AlfMock.generateNodeRef(mockedNodeService, type);
|
||||
|
||||
NodeRef unfiledRecordFolder = generateNodeRef(TYPE_UNFILED_RECORD_FOLDER, true);
|
||||
ChildAssociationRef mockedChildAssoc = mock(ChildAssociationRef.class);
|
||||
when(mockedChildAssoc.getChildRef()).thenReturn(nodeRef);
|
||||
when(mockedChildAssoc.getParentRef()).thenReturn(unfiledRecordFolder);
|
||||
unfiledRecordFolderType.onCreateChildAssociation(mockedChildAssoc, true);
|
||||
}
|
||||
}
|
@@ -65,7 +65,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -725,32 +724,6 @@ public class RMNodesImplUnitTest extends BaseUnitTest
|
||||
verify(mockedFileFolderService, never()).delete(nodeRef);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsRMSite() throws Exception
|
||||
{
|
||||
//test when rm site exists and we do not check the rm site
|
||||
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
|
||||
NodeRef rmSiteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
|
||||
when(mockedSiteInfo.getNodeRef()).thenReturn(rmSiteNodeRef);
|
||||
when(mockedSiteService.getSite(RM_SITE_ID)).thenReturn(mockedSiteInfo);
|
||||
|
||||
boolean isRMSite = rmNodesImpl.isRMSite(parentNodeRef.getId());
|
||||
assertEquals("Should return false.", false, isRMSite);
|
||||
|
||||
//check when rm site does not exist
|
||||
when(mockedSiteService.getSite(RM_SITE_ID)).thenReturn(null);
|
||||
isRMSite = rmNodesImpl.isRMSite(parentNodeRef.getId());
|
||||
assertEquals("Should return false.", false, isRMSite);
|
||||
|
||||
//check when rm site exists and we check with rm site node ref id
|
||||
when(mockedSiteInfo.getNodeRef()).thenReturn(parentNodeRef);
|
||||
when(mockedSiteService.getSite(RM_SITE_ID)).thenReturn(mockedSiteInfo);
|
||||
isRMSite = rmNodesImpl.isRMSite(parentNodeRef.getId());
|
||||
assertEquals("Should return true.", true, isRMSite);
|
||||
}
|
||||
|
||||
private void setupCompanyHomeAndPrimaryParent(NodeRef nodeRef)
|
||||
{
|
||||
NodeRef companyHomeNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
|
@@ -28,13 +28,9 @@
|
||||
package org.alfresco.rm.rest.api.nodes;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -42,7 +38,6 @@ import java.util.List;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.rest.framework.webscripts.WithResponse;
|
||||
import org.alfresco.rm.rest.api.impl.RMNodesImpl;
|
||||
@@ -100,28 +95,6 @@ public class FileplanComponentChildrenRelationUnitTest extends BaseUnitTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateOnRMSite() throws Exception
|
||||
{
|
||||
Parameters mockedParameters = mock(Parameters.class);
|
||||
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
|
||||
List<Node> nodeInfos = new ArrayList<Node>();
|
||||
Node mokedNodeInfo = mock(Node.class);
|
||||
nodeInfos.add(mokedNodeInfo);
|
||||
|
||||
when(mockedRMNodes.isRMSite(parentNodeRef.getId())).thenReturn(true);
|
||||
try
|
||||
{
|
||||
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), nodeInfos, mockedParameters);
|
||||
fail("Expected ecxeption as POST request is not allowed in RM site.");
|
||||
}
|
||||
catch(PermissionDeniedException ex)
|
||||
{
|
||||
assertEquals("POST request not allowed in RM site.", ex.getMsgId());
|
||||
}
|
||||
verify(mockedRMNodes, never()).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters);
|
||||
}
|
||||
|
||||
public void testUpload() throws Exception
|
||||
{
|
||||
Parameters mockedParameters = mock(Parameters.class);
|
||||
@@ -131,24 +104,4 @@ public class FileplanComponentChildrenRelationUnitTest extends BaseUnitTest
|
||||
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse);
|
||||
verify(mockedRMNodes, times(1)).upload(parentNodeRef.getId(), mockedFormData, mockedParameters);
|
||||
}
|
||||
|
||||
public void testUploadOnRMSite() throws Exception
|
||||
{
|
||||
Parameters mockedParameters = mock(Parameters.class);
|
||||
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
FormData mockedFormData = mock(FormData.class);
|
||||
WithResponse mockedWithResponse = mock(WithResponse.class);
|
||||
|
||||
when(mockedRMNodes.isRMSite(parentNodeRef.getId())).thenReturn(true);
|
||||
try
|
||||
{
|
||||
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse);
|
||||
fail("Expected ecxeption as POST request is not allowed in RM site.");
|
||||
}
|
||||
catch(PermissionDeniedException ex)
|
||||
{
|
||||
assertEquals("POST request not allowed in RM site.", ex.getMsgId());
|
||||
}
|
||||
verify(mockedRMNodes, never()).upload(parentNodeRef.getId(), mockedFormData, mockedParameters);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user