From 39a78c7976375f89fa0d35bb010983d8df33651a Mon Sep 17 00:00:00 2001 From: cagache Date: Thu, 7 Jun 2018 10:43:37 +0300 Subject: [PATCH] RM-6364 Convert search integration tests to end to end tests done through api --- .../AutomaticDispositionTest.java | 97 +++++++++++++ .../job/AutomaticDispositionTest.java | 137 ------------------ ...ecordsManagementSearchServiceImplTest.java | 24 --- 3 files changed, 97 insertions(+), 161 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/AutomaticDispositionTest.java delete mode 100644 rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/AutomaticDispositionTest.java diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/AutomaticDispositionTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/AutomaticDispositionTest.java new file mode 100644 index 0000000000..e148f783f7 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/recordcategories/AutomaticDispositionTest.java @@ -0,0 +1,97 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2018 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.rest.rm.community.recordcategories; + +import static org.alfresco.utility.data.RandomData.getRandomName; +import static org.alfresco.utility.report.log.Step.STEP; +import static org.testng.Assert.assertTrue; + +import java.util.List; + +import org.alfresco.rest.rm.community.base.BaseRMRestTest; +import org.alfresco.rest.rm.community.model.record.Record; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild; + +import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI; +import org.alfresco.rest.v0.service.DispositionScheduleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +public class AutomaticDispositionTest extends BaseRMRestTest +{ + private static final String CUT_OFF_ASPECT = "rma:cutOff"; + + @Autowired + private DispositionScheduleService dispositionScheduleService; + + private RecordCategory categoryWithRSOnRecords; + + /** + * Given there is a complete record eligible for cut off + * When the correct frequency of time passes + * Then the record will be automatically cut off + */ + @Test + public void testAutomaticCutOff() throws Exception + { + STEP("Create record category with retention schedule and apply it to records."); + categoryWithRSOnRecords = createRootCategory(getRandomName("categoryWithRSOnRecords")); + dispositionScheduleService.createCategoryRetentionSchedule(categoryWithRSOnRecords.getName(), true); + + STEP("Add retention schedule cut off step with immediate period."); + dispositionScheduleService.addCutOffAfterPeriodStep(categoryWithRSOnRecords.getName(), "immediately"); + + STEP("Create a record folder with a record"); + RecordCategoryChild recordFolder = createRecordFolder(categoryWithRSOnRecords.getId(), getRandomName + ("recordFolder")); + + STEP("Complete the record and wait upon to 5 minutes for automatic job to execute"); + Record record = createElectronicRecord(recordFolder.getId(), getRandomName("elRecord")); + completeRecord(record.getId()); + + RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI(); + List aspects = recordsAPI.getRecord(record.getId()).getAspectNames(); + int count = 0; + while (!aspects.contains(CUT_OFF_ASPECT) && count < 30) + { + // sleep .. allowing the job time to execute + Thread.sleep(10000); + count++; + aspects = recordsAPI.getRecord(record.getId()).getAspectNames(); + } + aspects = recordsAPI.getRecord(record.getId()).getAspectNames(); + assertTrue(aspects.contains(CUT_OFF_ASPECT), "Record should now be cut off"); + } + + @AfterClass (alwaysRun = true) + public void deleteCategory() + { + deleteRecordCategory(categoryWithRSOnRecords.getId()); + } +} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/AutomaticDispositionTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/AutomaticDispositionTest.java deleted file mode 100644 index 6230fc6a4b..0000000000 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/job/AutomaticDispositionTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2018 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.test.integration.job; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.module.org_alfresco_module_rm.action.impl.CutOffAction; -import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditService; -import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction; -import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.namespace.QName; -import org.alfresco.util.GUID; -import org.apache.commons.lang3.ArrayUtils; - -/** - * Test automatic disposition via scheduled job. - * - * @author Roy Wetherall - * @since 2.2 - */ -public class AutomaticDispositionTest extends BaseRMTestCase -{ - @SuppressWarnings("unused") - private RecordsManagementAuditService auditService; - - /** additional job context to override job frequency */ - protected String[] getConfigLocations() - { - return ArrayUtils.add(super.getConfigLocations(), "classpath:test-job-context.xml"); - } - - /** - * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices() - */ - @Override - protected void initServices() - { - super.initServices(); - auditService = (RecordsManagementAuditService)applicationContext.getBean("recordsManagementAuditService"); - } - - /** - * Given there is a complete record eligible for cut off, when the correct frequency of time passes, then - * the record will be automatically cut off - */ - public void testAutomaticCutOff() - { - doBehaviourDrivenTest(new BehaviourDrivenTest() - { - NodeRef sourceCategory; - NodeRef sourceRecordFolder; - NodeRef record; - - public void given() - { - // create test data - sourceCategory = filePlanService.createRecordCategory(filePlan, GUID.generate()); - DispositionSchedule dis = utils.createBasicDispositionSchedule(sourceCategory, GUID.generate(), GUID.generate(), true, false); - Map adParams = new HashMap(3); - adParams.put(PROP_DISPOSITION_ACTION_NAME, CutOffAction.NAME); - adParams.put(PROP_DISPOSITION_DESCRIPTION, GUID.generate()); - adParams.put(PROP_DISPOSITION_PERIOD, CommonRMTestUtils.PERIOD_IMMEDIATELY); - dispositionService.addDispositionActionDefinition(dis, adParams); - sourceRecordFolder = recordFolderService.createRecordFolder(sourceCategory, GUID.generate()); - - // create and complete record - record = utils.createRecord(sourceRecordFolder, GUID.generate()); - utils.completeRecord(record); - - // check the disposition action details - DispositionAction dispositionAction = dispositionService.getNextDispositionAction(record); - assertNotNull(dispositionAction); - assertNotNull(CutOffAction.NAME, dispositionAction.getName()); - assertTrue(dispositionService.isNextDispositionActionEligible(record)); - } - - public void when() throws Exception - { - // sleep .. allowing the job time to execute - Thread.sleep(30000); - } - - public void then() - { - // record should now be cut off - assertTrue(dispositionService.isDisposableItemCutoff(record)); - - // TODO .. automatic dispoistion does not log entry in audit - // .. the following test checks for this, but is currently commented out - // .. because it doesn't work! -// RecordsManagementAuditQueryParameters params = new RecordsManagementAuditQueryParameters(); -// params.setEvent(CutOffAction.NAME); -// params.setMaxEntries(1); -// List entries = auditService.getAuditTrail(params); -// assertNotNull(entries); -// assertEquals(1, entries.size()); -// -// RecordsManagementAuditEntry entry = entries.get(0); -// assertEquals(record, entry.getNodeRef()); - } - }); - } - - // TODO automatic retain - - // TODO automatic destroy -} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementSearchServiceImplTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementSearchServiceImplTest.java index 42e2005b0b..e78181a982 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementSearchServiceImplTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/service/RecordsManagementSearchServiceImplTest.java @@ -117,30 +117,6 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase }, AuthenticationUtil.getSystemUserName()); } - public void testSearch() - { - // Full text search - doTestInTransaction(new Test() - { - @Override - public Void run() - { - String query = "keywords:\"elephant\""; - RecordsManagementSearchParameters params = new RecordsManagementSearchParameters(); - params.setIncludeUndeclaredRecords(true); - List> results = rmSearchService.search(siteId, query, params); - assertNotNull(results); - assertEquals(2, results.size()); - - return null; - } - }, AuthenticationUtil.getSystemUserName()); - - // Property search - - // - } - public void testSaveSearch() { // Add some saved searches (as admin user)