From 2311e18d0a8357d207532cb43eae55e9b2d1dad0 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Fri, 21 Dec 2012 04:09:10 +0000 Subject: [PATCH] RM: Unit test fixing up git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@44898 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- rm-server/build.gradle | 46 +++++----- .../rm-service-context.xml | 2 +- .../test/JScriptTestSuite.java | 45 ---------- .../test/ServicesTestSuite.java | 1 - .../test/jscript/CapabilitiesTest.js | 18 ---- .../test/jscript/RMJScriptTest.java | 89 ------------------- .../test/util/BaseRMTestCase.java | 2 +- .../test/util/CommonRMTestUtils.java | 31 ++++--- 8 files changed, 48 insertions(+), 186 deletions(-) delete mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/JScriptTestSuite.java delete mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/CapabilitiesTest.js delete mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/RMJScriptTest.java diff --git a/rm-server/build.gradle b/rm-server/build.gradle index 21e8cf71b0..4f73ca2609 100644 --- a/rm-server/build.gradle +++ b/rm-server/build.gradle @@ -43,29 +43,33 @@ eclipse { } task resetDatabase << { - // Loading the properties in all possible locations - ant.property(file: System.properties.getProperty('DB_PROPERTIES') ) - ant.property(file: System.properties.getProperty('user.home')+'/alfresco/extension/repository.properties' ) - ant.property(resource: 'alfresco/domain/transaction.properties', classpath: configurations.compile.asPath ) - ant.property(resource: 'alfresco/version.properties', classpath: configurations.compile.asPath ) - ant.property(resource: 'alfresco/repository.properties', classpath: configurations.compile.asPath ) + + if(System.properties.getProperty('DB_PROPERTIES') != null) + { + // Loading the properties in all possible locations + ant.property(file: System.properties.getProperty('DB_PROPERTIES') ) + ant.property(file: System.properties.getProperty('user.home')+'/alfresco/extension/repository.properties' ) + ant.property(resource: 'alfresco/domain/transaction.properties', classpath: configurations.compile.asPath ) + ant.property(resource: 'alfresco/version.properties', classpath: configurations.compile.asPath ) + ant.property(resource: 'alfresco/repository.properties', classpath: configurations.compile.asPath ) - // Set default values if nothing was found (remember Ant props are 'first set wins') - ant.property(name: "db.name", value: "alfresco") - ant.property(name: "db.url", value: "jdbc:postgresql:alfresco") - ant.property(name: "db.master.url", value: "jdbc:postgresql:template1") - ant.property(name: "db.username", value: "alfresco") - ant.property(name: "db.password", value: "alfresco") + // Set default values if nothing was found (remember Ant props are 'first set wins') + ant.property(name: "db.name", value: "alfresco") + ant.property(name: "db.url", value: "jdbc:postgresql:alfresco") + ant.property(name: "db.master.url", value: "jdbc:postgresql:template1") + ant.property(name: "db.username", value: "alfresco") + ant.property(name: "db.password", value: "alfresco") - println "Recreating database " + ant.getProperty("db.name") + " as user " + ant.getProperty("db.username") - ant.sql(driver: 'org.postgresql.Driver', - url: ant.getProperty("db.master.url"), - userid: ant.getProperty("db.username"), - password: ant.getProperty("db.password"), - print: 'true', - autocommit: 'true', - classpath: configurations.compile.asPath, - 'drop database if exists ' + ant.getProperty("db.name") + '; create database ' + ant.getProperty("db.name") + ';') + println "Recreating database " + ant.getProperty("db.name") + " as user " + ant.getProperty("db.username") + ant.sql(driver: 'org.postgresql.Driver', + url: ant.getProperty("db.master.url"), + userid: ant.getProperty("db.username"), + password: ant.getProperty("db.password"), + print: 'true', + autocommit: 'true', + classpath: configurations.compile.asPath, + 'drop database if exists ' + ant.getProperty("db.name") + '; create database ' + ant.getProperty("db.name") + ';') + } } test { diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index f4d133e2c9..a5584df207 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -605,7 +605,7 @@ - + diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/JScriptTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/JScriptTestSuite.java deleted file mode 100644 index 540127ad94..0000000000 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/JScriptTestSuite.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2005-2011 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.test; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.alfresco.module.org_alfresco_module_rm.test.jscript.RMJScriptTest; - - -/** - * RM JScript test suite - * - * @author Roy Wetherall - */ -public class JScriptTestSuite extends TestSuite -{ - /** - * Creates the test suite - * - * @return the test suite - */ - public static Test suite() - { - TestSuite suite = new TestSuite(); - suite.addTestSuite(RMJScriptTest.class); - return suite; - } -} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java index 08dbfc4399..1c99a85a78 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/ServicesTestSuite.java @@ -59,7 +59,6 @@ public class ServicesTestSuite extends TestSuite suite.addTestSuite(RecordsManagementAdminServiceImplTest.class); suite.addTestSuite(RecordsManagementAuditServiceImplTest.class); //suite.addTestSuite(RecordsManagementEventServiceImplTest.class); - //suite.addTestSuite(RecordsManagementSecurityServiceImplTest.class); suite.addTestSuite(RecordsManagementSearchServiceImplTest.class); suite.addTestSuite(VitalRecordServiceImplTest.class); suite.addTestSuite(DataSetServiceImplTest.class); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/CapabilitiesTest.js b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/CapabilitiesTest.js deleted file mode 100644 index fe05c9a9d6..0000000000 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/CapabilitiesTest.js +++ /dev/null @@ -1,18 +0,0 @@ -function main() -{ - test.assertNotNull(filePlan); - test.assertNotNull(record); - - var rmNode = rmService.getRecordsManagementNode(record); - test.assertNotNull(rmNode); - - var capabilities = rmNode.capabilities; - var countCheck = capabilities.length != 0; - test.assertTrue(countCheck); - - var capability = capabilities[0]; - test.assertNotNull(capability); - test.assertNotNull(capability.name); -} - -main(); \ No newline at end of file diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/RMJScriptTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/RMJScriptTest.java deleted file mode 100644 index a1326d4680..0000000000 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/jscript/RMJScriptTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2005-2011 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.test.jscript; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.repo.jscript.ClasspathScriptLocation; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.ScriptLocation; -import org.alfresco.service.cmr.repository.ScriptService; - -/** - * @author Roy Wetherall - */ -public class RMJScriptTest extends BaseRMTestCase -{ - private static String SCRIPT_PATH = "org/alfresco/module/org_alfresco_module_rm/test/jscript/"; - private static String CAPABILITIES_TEST = "CapabilitiesTest.js"; - - private ScriptService scriptService; - - @Override - protected void initServices() - { - super.initServices(); - this.scriptService = (ScriptService)this.applicationContext.getBean("ScriptService"); - } - - private NodeRef record; - public void testCapabilities() throws Exception - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - record = utils.createRecord(rmFolder, "testRecord.txt"); - return null; - } - }); - - doTestInTransaction(new Test() - { - @Override - public NodeRef run() - { - utils.declareRecord(record); - return record; - } - - @Override - public void test(NodeRef record) throws Exception - { - - // Create a model to pass to the unit test scripts - Map model = new HashMap(1); - model.put("filePlan", filePlan); - model.put("record", record); - - executeScript(CAPABILITIES_TEST, model); - } - }); - } - - private void executeScript(String script, Map model) - { - // Execute the unit test script - ScriptLocation location = new ClasspathScriptLocation(SCRIPT_PATH + script); - this.scriptService.executeScript(location, model); - } -} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index caa5d648f1..f816bc5cb5 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -290,7 +290,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase initServices(); // Setup test data - setupTestData(); + setupTestData(); // Create multi hierarchy data if (isMultiHierarchyTest() == true) diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java index 202fed6b36..b25c7df0c3 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/CommonRMTestUtils.java @@ -16,6 +16,7 @@ import org.alfresco.module.org_alfresco_module_rm.action.impl.FreezeAction; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.model.security.ModelSecurityService; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; @@ -36,6 +37,7 @@ public class CommonRMTestUtils implements RecordsManagementModel private NodeService nodeService; private ContentService contentService; private RecordsManagementActionService actionService; + private ModelSecurityService modelSecurityService; /** test values */ public static final String DEFAULT_DISPOSITION_AUTHORITY = "disposition authority"; @@ -51,6 +53,7 @@ public class CommonRMTestUtils implements RecordsManagementModel nodeService = (NodeService)applicationContext.getBean("NodeService"); contentService = (ContentService)applicationContext.getBean("ContentService"); actionService = (RecordsManagementActionService)applicationContext.getBean("RecordsManagementActionService"); + modelSecurityService = (ModelSecurityService)applicationContext.getBean("ModelSecurityService"); } /** @@ -151,16 +154,24 @@ public class CommonRMTestUtils implements RecordsManagementModel @Override public Void doWork() throws Exception { - // Declare record - nodeService.setProperty(record, RecordsManagementModel.PROP_PUBLICATION_DATE, new Date()); - nodeService.setProperty(record, RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue"); - nodeService.setProperty(record, RecordsManagementModel.PROP_FORMAT, "formatValue"); - nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_RECEIVED, new Date()); - nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_FILED, new Date()); - nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATOR, "origValue"); - nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATING_ORGANIZATION, "origOrgValue"); - nodeService.setProperty(record, ContentModel.PROP_TITLE, "titleValue"); - actionService.executeRecordsManagementAction(record, "declareRecord"); + modelSecurityService.setEnabled(false); + try + { + // Declare record + nodeService.setProperty(record, RecordsManagementModel.PROP_PUBLICATION_DATE, new Date()); + nodeService.setProperty(record, RecordsManagementModel.PROP_MEDIA_TYPE, "mediaTypeValue"); + nodeService.setProperty(record, RecordsManagementModel.PROP_FORMAT, "formatValue"); + nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_RECEIVED, new Date()); + nodeService.setProperty(record, RecordsManagementModel.PROP_DATE_FILED, new Date()); + nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATOR, "origValue"); + nodeService.setProperty(record, RecordsManagementModel.PROP_ORIGINATING_ORGANIZATION, "origOrgValue"); + nodeService.setProperty(record, ContentModel.PROP_TITLE, "titleValue"); + actionService.executeRecordsManagementAction(record, "declareRecord"); + } + finally + { + modelSecurityService.setEnabled(true); + } return null; }