2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.authorization.importer;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.springframework.transaction.TransactionStatus;
30 import org.testng.annotations.BeforeClass;
36 public class AuthorizationSeedTest extends AbstractAuthorizationTestImpl {
38 final Logger logger = LoggerFactory.getLogger(AuthorizationSeedTest.class);
39 final static String PERMISSION_FILE = "import-permissions.xml";
40 final static String PERMISSION_ROLE_FILE = "import-permissions-roles.xml";
42 @BeforeClass(alwaysRun = true)
43 public void seedData() {
45 TransactionStatus status = null;
47 AuthorizationGen authzGen = new AuthorizationGen();
48 String tenantBindingFile = getTenantBindingFile();
49 authzGen.initialize(tenantBindingFile);
50 authzGen.createDefaultServicePermissions();
51 authzGen.createDefaultPermissionsRoles("ROLE_ADMINISTRATOR");
52 String exportDir = getExportDir();
53 authzGen.exportPermissions(exportDir + PERMISSION_FILE);
54 authzGen.exportPermissionRoles(exportDir + PERMISSION_ROLE_FILE);
55 if (logger.isDebugEnabled()) {
56 logger.debug("authroization generation completed ");
58 status = beginTransaction("seedData");
59 AuthorizationSeed authzSeed = new AuthorizationSeed();
60 String importDir = getImportDir();
61 authzSeed.seedPermissions(importDir + PERMISSION_FILE,
62 importDir + PERMISSION_ROLE_FILE);
63 if (logger.isDebugEnabled()) {
64 logger.debug("authroization seeding completed ");
66 } catch (Exception ex) {
68 rollbackTransaction(status);
70 if (logger.isDebugEnabled()) {
73 throw new RuntimeException(ex);
76 commitTransaction(status);
81 private String getTenantBindingFile() {
82 String tenantBindingFile = System.getProperty("tenantbindings");
83 if (tenantBindingFile == null || tenantBindingFile.isEmpty()) {
84 throw new IllegalStateException("tenantbindings are required."
85 + " System property tenantbindings is missing or empty");
87 return tenantBindingFile;
90 private String getImportDir() {
91 String importDir = System.getProperty("importdir");
92 if (importDir == null || importDir.isEmpty()) {
93 throw new IllegalStateException("importdir required."
94 + " System property importdir is missing or empty");
96 return importDir + File.separator;
99 private String getExportDir() {
100 String exportDir = System.getProperty("exportdir");
101 if (exportDir == null || exportDir.isEmpty()) {
102 throw new IllegalStateException("exportdir required."
103 + " System property exportdir is missing or empty");
105 return exportDir + File.separator;