[CCM][UPDATE]
- improves the file handling for the import tests using systems temp folder
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5215 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: 374fbff673
pull/2/head
parent
eab4cd95d3
commit
ab46daa72d
|
|
@ -96,7 +96,7 @@ public abstract class AbstractMarshaller<P extends Portable> {
|
||||||
* from
|
* from
|
||||||
* @param filename The filename of the file exported to or imported from
|
* @param filename The filename of the file exported to or imported from
|
||||||
* @param indentation whether or not indentation
|
* @param indentation whether or not indentation
|
||||||
*/
|
*
|
||||||
public void prepare(final Format format,
|
public void prepare(final Format format,
|
||||||
String folderPath, String filename,
|
String folderPath, String filename,
|
||||||
boolean indentation) {
|
boolean indentation) {
|
||||||
|
|
@ -104,7 +104,7 @@ public abstract class AbstractMarshaller<P extends Portable> {
|
||||||
if (file.exists() || file.mkdirs()) {
|
if (file.exists() || file.mkdirs()) {
|
||||||
prepare(format, folderPath + "/" + filename, indentation);
|
prepare(format, folderPath + "/" + filename, indentation);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export routine for lists with the same object type {@code P}. Creates a
|
* Export routine for lists with the same object type {@code P}. Creates a
|
||||||
|
|
|
||||||
|
|
@ -30,22 +30,30 @@ import org.jboss.arquillian.transaction.api.annotation.Transactional;
|
||||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||||
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
|
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
|
||||||
import org.jboss.shrinkwrap.api.spec.WebArchive;
|
import org.jboss.shrinkwrap.api.spec.WebArchive;
|
||||||
|
|
||||||
import org.junit.experimental.categories.Category;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.libreccm.security.GroupRepository;
|
|
||||||
import org.libreccm.tests.categories.IntegrationTest;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import static org.libreccm.testutils.DependenciesHelpers.getModuleDependencies;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.libreccm.tests.categories.IntegrationTest;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.FileAlreadyExistsException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.libreccm.testutils.DependenciesHelpers.getModuleDependencies;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,23 +74,75 @@ public class CoreDataImportTest {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ImportHelper importHelper;
|
private ImportHelper importHelper;
|
||||||
@Inject
|
|
||||||
private GroupRepository groupRepository;
|
private enum Types {
|
||||||
|
user, group, groupMem, role, roleMem,
|
||||||
|
category, categorization, resourceType,
|
||||||
|
ccmAppl, domain, domainOwn,
|
||||||
|
permission, workflow, taskComment,
|
||||||
|
assignableTask, taskDep, taskAssign
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<Types, String> fileNames;
|
||||||
|
static {
|
||||||
|
fileNames = new HashMap<>();
|
||||||
|
fileNames.put(Types.user, "users.xml");
|
||||||
|
fileNames.put(Types.group, "groups.xml");
|
||||||
|
fileNames.put(Types.groupMem, "groupMemberships.xml");
|
||||||
|
fileNames.put(Types.role, "roles.xml");
|
||||||
|
fileNames.put(Types.roleMem, "roleMemberships.xml");
|
||||||
|
fileNames.put(Types.category, "categories.xml");
|
||||||
|
fileNames.put(Types.categorization, "categorizations.xml");
|
||||||
|
fileNames.put(Types.resourceType, "resourceTypes.xml");
|
||||||
|
fileNames.put(Types.ccmAppl, "ccmApplications.xml");
|
||||||
|
fileNames.put(Types.domain, "domains.xml");
|
||||||
|
fileNames.put(Types.domainOwn, "domainOwnerships.xml");
|
||||||
|
fileNames.put(Types.permission, "permissions.xml");
|
||||||
|
fileNames.put(Types.workflow, "workflows.xml");
|
||||||
|
fileNames.put(Types.taskComment, "taskComments.xml");
|
||||||
|
fileNames.put(Types.assignableTask, "assignableTasks.xml");
|
||||||
|
fileNames.put(Types.taskDep, "taskDependencies.xml");
|
||||||
|
fileNames.put(Types.taskAssign, "taskAssignments.xml");
|
||||||
|
}
|
||||||
|
|
||||||
public CoreDataImportTest() {
|
public CoreDataImportTest() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass() {
|
public static void setUpClass() throws IOException {
|
||||||
}
|
final String tmpDirPath = System.getProperty("java.io.tmpdir");
|
||||||
|
final Path filesPath = Paths
|
||||||
|
.get(tmpDirPath, "libreccm-test", "CoreDataImportTest");
|
||||||
|
Files.createDirectories(filesPath);
|
||||||
|
|
||||||
@BeforeClass
|
for (String fileName : fileNames.values()) {
|
||||||
public static void createResource() {
|
final InputStream inputStream = CoreDataImportTest
|
||||||
|
.class
|
||||||
|
.getResourceAsStream(String
|
||||||
|
.format("/portation/trunk-iaw-exports/%s",
|
||||||
|
fileName));
|
||||||
|
try {
|
||||||
|
Files.copy(inputStream, filesPath.resolve(fileName));
|
||||||
|
} catch(FileAlreadyExistsException e) {
|
||||||
|
//destination file already exists
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDownClass() {
|
public static void tearDownClass() throws IOException {
|
||||||
|
final String tmpDirPath = System.getProperty("java.io.tmpdir");
|
||||||
|
final Path filesPath = Paths
|
||||||
|
.get(tmpDirPath,"libreccm-test", "CoreDataImportTest");
|
||||||
|
Files.walkFileTree(filesPath, new SimpleFileVisitor<Path>(){
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes
|
||||||
|
attrs) throws IOException {
|
||||||
|
Files.delete(file);
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deployment
|
@Deployment
|
||||||
|
|
@ -134,28 +194,50 @@ public class CoreDataImportTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@InSequence(100)
|
@InSequence(100)
|
||||||
public void objectsShouldBeImported() {
|
public void objectsShouldBeImported() throws IOException {
|
||||||
|
final String tmpDirPath = System.getProperty("java.io.tmpdir");
|
||||||
|
final Path filesPath = Paths
|
||||||
|
.get(tmpDirPath, "libreccm-test", "CoreDataImportTest");
|
||||||
|
Files.createDirectories(filesPath);
|
||||||
|
|
||||||
// assert for no errors
|
// assert for no errors
|
||||||
Assert.assertFalse(importHelper.importUsers());
|
Assert.assertFalse(importHelper.importUsers(
|
||||||
Assert.assertFalse(importHelper.importGroups());
|
filesPath.resolve(fileNames.get(Types.user))));
|
||||||
Assert.assertFalse(importHelper.importGroupMemberships());
|
Assert.assertFalse(importHelper.importGroups(
|
||||||
Assert.assertFalse(importHelper.importRoles());
|
filesPath.resolve(fileNames.get(Types.group))));
|
||||||
Assert.assertFalse(importHelper.importRoleMemberships());
|
Assert.assertFalse(importHelper.importGroupMemberships(
|
||||||
|
filesPath.resolve(fileNames.get(Types.groupMem))));
|
||||||
|
Assert.assertFalse(importHelper.importRoles(
|
||||||
|
filesPath.resolve(fileNames.get(Types.role))));
|
||||||
|
Assert.assertFalse(importHelper.importRoleMemberships(
|
||||||
|
filesPath.resolve(fileNames.get(Types.roleMem))));
|
||||||
|
|
||||||
Assert.assertFalse(importHelper.importCategories());
|
Assert.assertFalse(importHelper.importCategories(
|
||||||
Assert.assertFalse(importHelper.importCategorizations());
|
filesPath.resolve(fileNames.get(Types.category))));
|
||||||
Assert.assertFalse(importHelper.importResourceTypes());
|
Assert.assertFalse(importHelper.importCategorizations(
|
||||||
Assert.assertFalse(importHelper.importCcmApplications());
|
filesPath.resolve(fileNames.get(Types.categorization))));
|
||||||
Assert.assertFalse(importHelper.importDomains());
|
Assert.assertFalse(importHelper.importResourceTypes(
|
||||||
Assert.assertFalse(importHelper.importDomainOwnerships());
|
filesPath.resolve(fileNames.get(Types.resourceType))));
|
||||||
|
Assert.assertFalse(importHelper.importCcmApplications(
|
||||||
|
filesPath.resolve(fileNames.get(Types.ccmAppl))));
|
||||||
|
Assert.assertFalse(importHelper.importDomains(
|
||||||
|
filesPath.resolve(fileNames.get(Types.domain))));
|
||||||
|
Assert.assertFalse(importHelper.importDomainOwnerships(
|
||||||
|
filesPath.resolve(fileNames.get(Types.domainOwn))));
|
||||||
|
|
||||||
Assert.assertFalse(importHelper.importPermissions());
|
Assert.assertFalse(importHelper.importPermissions(
|
||||||
|
filesPath.resolve(fileNames.get(Types.permission))));
|
||||||
|
|
||||||
Assert.assertFalse(importHelper.importWorkflows());
|
Assert.assertFalse(importHelper.importWorkflows(
|
||||||
Assert.assertFalse(importHelper.importTaskComments());
|
filesPath.resolve(fileNames.get(Types.workflow))));
|
||||||
Assert.assertFalse(importHelper.importAssignableTasks());
|
Assert.assertFalse(importHelper.importTaskComments(
|
||||||
Assert.assertFalse(importHelper.importTaskDependencies());
|
filesPath.resolve(fileNames.get(Types.taskComment))));
|
||||||
Assert.assertFalse(importHelper.importTaskAssignments());
|
Assert.assertFalse(importHelper.importAssignableTasks(
|
||||||
|
filesPath.resolve(fileNames.get(Types.assignableTask))));
|
||||||
|
Assert.assertFalse(importHelper.importTaskDependencies(
|
||||||
|
filesPath.resolve(fileNames.get(Types.taskDep))));
|
||||||
|
Assert.assertFalse(importHelper.importTaskAssignments(
|
||||||
|
filesPath.resolve(fileNames.get(Types.taskAssign))));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ import org.libreccm.workflow.WorkflowMarshaller;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to implement the specifics for the importations. Makes source code
|
* Helper to implement the specifics for the importations. Makes source code
|
||||||
|
|
@ -67,10 +68,7 @@ import javax.inject.Inject;
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
class ImportHelper {
|
class ImportHelper {
|
||||||
|
|
||||||
private final String repoPath = "/home/jensp/pwi/libreccm/ccm/";
|
private final Format format = Format.XML;
|
||||||
// private final String repoPath = "/home/tosmers/Svn/libreccm/";
|
|
||||||
private final String projectPath = "ccm_ng/ccm-core/src/test/resources/" +
|
|
||||||
"portation/trunk-iaw-exports";
|
|
||||||
private final boolean indentation = false;
|
private final boolean indentation = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -143,156 +141,139 @@ class ImportHelper {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
boolean importUsers() {
|
boolean importUsers(final Path filePath) {
|
||||||
userMarshaller.prepare(
|
userMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"users.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return userMarshaller.importFile();
|
return userMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importGroups() {
|
boolean importGroups(final Path filePath) {
|
||||||
groupMarshaller.prepare(
|
groupMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"groups.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return groupMarshaller.importFile();
|
return groupMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importGroupMemberships() {
|
boolean importGroupMemberships(final Path filePath) {
|
||||||
groupMembershipMarshaller.prepare(
|
groupMembershipMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"groupMemberships.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return groupMembershipMarshaller.importFile();
|
return groupMembershipMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importRoles() {
|
boolean importRoles(final Path filePath) {
|
||||||
roleMarshaller.prepare(
|
roleMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"roles.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return roleMarshaller.importFile();
|
return roleMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importRoleMemberships() {
|
boolean importRoleMemberships(final Path filePath) {
|
||||||
roleMembershipMarshaller.prepare(
|
roleMembershipMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"roleMemberships.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return roleMembershipMarshaller.importFile();
|
return roleMembershipMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importCategories() {
|
boolean importCategories(final Path filePath) {
|
||||||
categoryMarshaller.prepare(
|
categoryMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"categories.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return categoryMarshaller.importFile();
|
return categoryMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importCategorizations() {
|
boolean importCategorizations(final Path filePath) {
|
||||||
categorizationMarshaller.prepare(
|
categorizationMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"categorizations.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return categorizationMarshaller.importFile();
|
return categorizationMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importResourceTypes() {
|
boolean importResourceTypes(final Path filePath) {
|
||||||
resourceTypeMarshaller.prepare(
|
resourceTypeMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"resourceTypes.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return resourceTypeMarshaller.importFile();
|
return resourceTypeMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importCcmApplications() {
|
boolean importCcmApplications(final Path filePath) {
|
||||||
applicationMarshaller.prepare(
|
applicationMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"ccmApplications.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return applicationMarshaller.importFile();
|
return applicationMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importDomains() {
|
boolean importDomains(final Path filePath) {
|
||||||
domainMarshaller.prepare(
|
domainMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"domains.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return domainMarshaller.importFile();
|
return domainMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importDomainOwnerships() {
|
boolean importDomainOwnerships(final Path filePath) {
|
||||||
domainOwnershipMarshaller.prepare(
|
domainOwnershipMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"domainOwnerships.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return domainOwnershipMarshaller.importFile();
|
return domainOwnershipMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importPermissions() {
|
boolean importPermissions(final Path filePath) {
|
||||||
permissionMarshaller.prepare(
|
permissionMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"permissions.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return permissionMarshaller.importFile();
|
return permissionMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean importWorkflows() {
|
boolean importWorkflows(final Path filePath) {
|
||||||
workflowMarshaller.prepare(
|
workflowMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"workflows.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return workflowMarshaller.importFile();
|
return workflowMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importTaskComments() {
|
boolean importTaskComments(final Path filePath) {
|
||||||
taskCommentMarshaller.prepare(
|
taskCommentMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"taskComments.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return taskCommentMarshaller.importFile();
|
return taskCommentMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importAssignableTasks() {
|
boolean importAssignableTasks(final Path filePath) {
|
||||||
assignableTaskMarshaller.prepare(
|
assignableTaskMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"assignableTasks.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return assignableTaskMarshaller.importFile();
|
return assignableTaskMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importTaskDependencies() {
|
boolean importTaskDependencies(final Path filePath) {
|
||||||
taskDependencyMarshaller.prepare(
|
taskDependencyMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"taskDependencies.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return taskDependencyMarshaller.importFile();
|
return taskDependencyMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean importTaskAssignments() {
|
boolean importTaskAssignments(final Path filePath) {
|
||||||
taskAssignmentMarshaller.prepare(
|
taskAssignmentMarshaller.prepare(
|
||||||
Format.XML,
|
format,
|
||||||
repoPath + projectPath,
|
filePath.toString(),
|
||||||
"taskAssignments.xml",
|
|
||||||
indentation);
|
indentation);
|
||||||
return taskAssignmentMarshaller.importFile();
|
return taskAssignmentMarshaller.importFile();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue