RM-1679 (Write unit tests for inplace record methods)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@84079 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2014-09-13 21:25:26 +00:00
parent 1a7aa49248
commit 7cd0105e7b
4 changed files with 214 additions and 5 deletions

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.module.org_alfresco_module_rm.test.integration.record;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
/**
* Hide Inplace Record Test
*
* @author Tuna Aksoy
* @since 2.3
*/
public class HideInplaceRecordTest extends BaseRMTestCase
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#isCollaborationSiteTest()
*/
@Override
protected boolean isCollaborationSiteTest()
{
return true;
}
/**
* Tests hiding inplace records
*/
public void testHideInplaceRecord()
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
public void given()
{
// Check that the document is not a record
assertFalse(recordService.isRecord(dmDocument));
// Check that the record has one parent association
assertEquals(1, nodeService.getParentAssocs(dmDocument).size());
// Declare the document as a record
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
public Void doWork() throws Exception
{
// Declare record
recordService.createRecord(filePlan, dmDocument);
return null;
}
}, dmCollaborator);
// Check that the document is a record
assertTrue(recordService.isRecord(dmDocument));
// Check that the record has two parent associations
assertEquals(2, nodeService.getParentAssocs(dmDocument).size());
}
public void when()
{
// Hide the document
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
public Void doWork() throws Exception
{
// Hide record
inplaceRecordService.hideRecord(dmDocument);
return null;
}
}, dmCollaborator);
}
public void then()
{
// Check that the record has one parent association
assertEquals(1, nodeService.getParentAssocs(dmDocument).size());
}
});
}
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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/>.
*/
package org.alfresco.module.org_alfresco_module_rm.test.integration.record;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Move Inplace Record Test
*
* @author Tuna Aksoy
* @since 2.3
*/
public class MoveInplaceRecordTest extends BaseRMTestCase
{
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#isCollaborationSiteTest()
*/
@Override
protected boolean isCollaborationSiteTest()
{
return true;
}
/**
* Tests moving inplace records
*/
public void testMoveInplaceRecord()
{
doBehaviourDrivenTest(new BehaviourDrivenTest()
{
// The destination folder in collaboration site
private NodeRef destinationDmFolder;
public void given()
{
// Create the destination folder
destinationDmFolder = fileFolderService.create(documentLibrary, "destinationCollabFolder", ContentModel.TYPE_FOLDER).getNodeRef();
// Check that the document is not a record
assertFalse(recordService.isRecord(dmDocument));
// Declare the document as a record
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
public Void doWork() throws Exception
{
// Declare record
recordService.createRecord(filePlan, dmDocument);
return null;
}
}, dmCollaborator);
// Check that the document is a record now
assertTrue(recordService.isRecord(dmDocument));
}
public void when()
{
// Move the document
AuthenticationUtil.runAs(new RunAsWork<Void>()
{
public Void doWork() throws Exception
{
// Move record
inplaceRecordService.moveRecord(dmDocument, destinationDmFolder);
return null;
}
}, dmCollaborator);
}
public void then()
{
// Check that the source folder is empty now and the destination folder has the document
assertEquals(0, nodeService.getChildAssocs(dmFolder).size());
List<ChildAssociationRef> destinationFolderChildAssocs = nodeService.getChildAssocs(destinationDmFolder);
assertEquals(1, destinationFolderChildAssocs.size());
assertEquals(dmDocument, destinationFolderChildAssocs.get(0).getChildRef());
}
});
}
}

View File

@@ -33,7 +33,9 @@ import org.junit.runners.Suite.SuiteClasses;
{ {
RejectRecordTest.class, RejectRecordTest.class,
CreateRecordTest.class, CreateRecordTest.class,
MoveRecordTest.class MoveRecordTest.class,
HideInplaceRecordTest.class,
MoveInplaceRecordTest.class
}) })
public class RecordTestSuite public class RecordTestSuite
{ {

View File

@@ -39,6 +39,7 @@ import org.alfresco.module.org_alfresco_module_rm.hold.HoldService;
import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.model.rma.type.RmSiteType; import org.alfresco.module.org_alfresco_module_rm.model.rma.type.RmSiteType;
import org.alfresco.module.org_alfresco_module_rm.record.InplaceRecordService;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService; import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService;
import org.alfresco.module.org_alfresco_module_rm.report.ReportService; import org.alfresco.module.org_alfresco_module_rm.report.ReportService;
@@ -156,6 +157,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
protected RecordsManagementAuditService rmAuditService; protected RecordsManagementAuditService rmAuditService;
protected IdentifierService identifierService; protected IdentifierService identifierService;
protected HoldService holdService; protected HoldService holdService;
protected InplaceRecordService inplaceRecordService;
/** test data */ /** test data */
protected String siteId; protected String siteId;
@@ -391,6 +393,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
rmAuditService = (RecordsManagementAuditService) applicationContext.getBean("RecordsManagementAuditService"); rmAuditService = (RecordsManagementAuditService) applicationContext.getBean("RecordsManagementAuditService");
identifierService = (IdentifierService) applicationContext.getBean("recordsManagementIdentifierService"); identifierService = (IdentifierService) applicationContext.getBean("recordsManagementIdentifierService");
holdService = (HoldService) applicationContext.getBean("HoldService"); holdService = (HoldService) applicationContext.getBean("HoldService");
inplaceRecordService = (InplaceRecordService) applicationContext.getBean("InplaceRecordService");
} }
/** /**