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 //create default role(s) for the tenant and assign permissions
52 authzGen.createDefaultPermissionsRoles();
53 String exportDir = getExportDir();
54 authzGen.exportPermissions(exportDir + PERMISSION_FILE);
55 authzGen.exportPermissionRoles(exportDir + PERMISSION_ROLE_FILE);
56 if (logger.isDebugEnabled()) {
57 logger.debug("authroization generation completed ");
59 status = beginTransaction("seedData");
60 AuthorizationSeed authzSeed = new AuthorizationSeed();
61 String importDir = getImportDir();
62 authzSeed.seedPermissions(importDir + PERMISSION_FILE,
63 importDir + PERMISSION_ROLE_FILE);
64 if (logger.isDebugEnabled()) {
65 logger.debug("authroization seeding completed ");
67 } catch (Exception ex) {
69 rollbackTransaction(status);
71 if (logger.isDebugEnabled()) {
74 throw new RuntimeException(ex);
77 commitTransaction(status);
82 private String getTenantBindingFile() {
83 String tenantBindingFile = System.getProperty("tenantbindings");
84 if (tenantBindingFile == null || tenantBindingFile.isEmpty()) {
85 throw new IllegalStateException("tenantbindings are required."
86 + " System property tenantbindings is missing or empty");
88 return tenantBindingFile;
91 private String getImportDir() {
92 String importDir = System.getProperty("importdir");
93 if (importDir == null || importDir.isEmpty()) {
94 throw new IllegalStateException("importdir required."
95 + " System property importdir is missing or empty");
97 return importDir + File.separator;
100 private String getExportDir() {
101 String exportDir = System.getProperty("exportdir");
102 if (exportDir == null || exportDir.isEmpty()) {
103 throw new IllegalStateException("exportdir required."
104 + " System property exportdir is missing or empty");
106 return exportDir + File.separator;