[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
tosmers 2018-01-24 17:28:41 +00:00
parent eab4cd95d3
commit ab46daa72d
3 changed files with 173 additions and 110 deletions

View File

@ -96,7 +96,7 @@ public abstract class AbstractMarshaller<P extends Portable> {
* from
* @param filename The filename of the file exported to or imported from
* @param indentation whether or not indentation
*/
*
public void prepare(final Format format,
String folderPath, String filename,
boolean indentation) {
@ -104,7 +104,7 @@ public abstract class AbstractMarshaller<P extends Portable> {
if (file.exists() || file.mkdirs()) {
prepare(format, folderPath + "/" + filename, indentation);
}
}
}*/
/**
* Export routine for lists with the same object type {@code P}. Creates a

View File

@ -30,22 +30,30 @@ import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
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.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
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
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() {
}
@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
public static void createResource() {
for (String fileName : fileNames.values()) {
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
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
@ -134,28 +194,50 @@ public class CoreDataImportTest {
@Test
@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.assertFalse(importHelper.importUsers());
Assert.assertFalse(importHelper.importGroups());
Assert.assertFalse(importHelper.importGroupMemberships());
Assert.assertFalse(importHelper.importRoles());
Assert.assertFalse(importHelper.importRoleMemberships());
Assert.assertFalse(importHelper.importUsers(
filesPath.resolve(fileNames.get(Types.user))));
Assert.assertFalse(importHelper.importGroups(
filesPath.resolve(fileNames.get(Types.group))));
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.importCategorizations());
Assert.assertFalse(importHelper.importResourceTypes());
Assert.assertFalse(importHelper.importCcmApplications());
Assert.assertFalse(importHelper.importDomains());
Assert.assertFalse(importHelper.importDomainOwnerships());
Assert.assertFalse(importHelper.importCategories(
filesPath.resolve(fileNames.get(Types.category))));
Assert.assertFalse(importHelper.importCategorizations(
filesPath.resolve(fileNames.get(Types.categorization))));
Assert.assertFalse(importHelper.importResourceTypes(
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.importTaskComments());
Assert.assertFalse(importHelper.importAssignableTasks());
Assert.assertFalse(importHelper.importTaskDependencies());
Assert.assertFalse(importHelper.importTaskAssignments());
Assert.assertFalse(importHelper.importWorkflows(
filesPath.resolve(fileNames.get(Types.workflow))));
Assert.assertFalse(importHelper.importTaskComments(
filesPath.resolve(fileNames.get(Types.taskComment))));
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))));
}
}

View File

@ -56,6 +56,7 @@ import org.libreccm.workflow.WorkflowMarshaller;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import java.nio.file.Path;
/**
* Helper to implement the specifics for the importations. Makes source code
@ -67,10 +68,7 @@ import javax.inject.Inject;
@RequestScoped
class ImportHelper {
private final String repoPath = "/home/jensp/pwi/libreccm/ccm/";
// 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 Format format = Format.XML;
private final boolean indentation = false;
@Inject
@ -143,156 +141,139 @@ class ImportHelper {
boolean importUsers() {
boolean importUsers(final Path filePath) {
userMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"users.xml",
format,
filePath.toString(),
indentation);
return userMarshaller.importFile();
}
boolean importGroups() {
boolean importGroups(final Path filePath) {
groupMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"groups.xml",
format,
filePath.toString(),
indentation);
return groupMarshaller.importFile();
}
boolean importGroupMemberships() {
boolean importGroupMemberships(final Path filePath) {
groupMembershipMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"groupMemberships.xml",
format,
filePath.toString(),
indentation);
return groupMembershipMarshaller.importFile();
}
boolean importRoles() {
boolean importRoles(final Path filePath) {
roleMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"roles.xml",
format,
filePath.toString(),
indentation);
return roleMarshaller.importFile();
}
boolean importRoleMemberships() {
boolean importRoleMemberships(final Path filePath) {
roleMembershipMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"roleMemberships.xml",
format,
filePath.toString(),
indentation);
return roleMembershipMarshaller.importFile();
}
boolean importCategories() {
boolean importCategories(final Path filePath) {
categoryMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"categories.xml",
format,
filePath.toString(),
indentation);
return categoryMarshaller.importFile();
}
boolean importCategorizations() {
boolean importCategorizations(final Path filePath) {
categorizationMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"categorizations.xml",
format,
filePath.toString(),
indentation);
return categorizationMarshaller.importFile();
}
boolean importResourceTypes() {
boolean importResourceTypes(final Path filePath) {
resourceTypeMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"resourceTypes.xml",
format,
filePath.toString(),
indentation);
return resourceTypeMarshaller.importFile();
}
boolean importCcmApplications() {
boolean importCcmApplications(final Path filePath) {
applicationMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"ccmApplications.xml",
format,
filePath.toString(),
indentation);
return applicationMarshaller.importFile();
}
boolean importDomains() {
boolean importDomains(final Path filePath) {
domainMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"domains.xml",
format,
filePath.toString(),
indentation);
return domainMarshaller.importFile();
}
boolean importDomainOwnerships() {
boolean importDomainOwnerships(final Path filePath) {
domainOwnershipMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"domainOwnerships.xml",
format,
filePath.toString(),
indentation);
return domainOwnershipMarshaller.importFile();
}
boolean importPermissions() {
boolean importPermissions(final Path filePath) {
permissionMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"permissions.xml",
format,
filePath.toString(),
indentation);
return permissionMarshaller.importFile();
}
boolean importWorkflows() {
boolean importWorkflows(final Path filePath) {
workflowMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"workflows.xml",
format,
filePath.toString(),
indentation);
return workflowMarshaller.importFile();
}
boolean importTaskComments() {
boolean importTaskComments(final Path filePath) {
taskCommentMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"taskComments.xml",
format,
filePath.toString(),
indentation);
return taskCommentMarshaller.importFile();
}
boolean importAssignableTasks() {
boolean importAssignableTasks(final Path filePath) {
assignableTaskMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"assignableTasks.xml",
format,
filePath.toString(),
indentation);
return assignableTaskMarshaller.importFile();
}
boolean importTaskDependencies() {
boolean importTaskDependencies(final Path filePath) {
taskDependencyMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"taskDependencies.xml",
format,
filePath.toString(),
indentation);
return taskDependencyMarshaller.importFile();
}
boolean importTaskAssignments() {
boolean importTaskAssignments(final Path filePath) {
taskAssignmentMarshaller.prepare(
Format.XML,
repoPath + projectPath,
"taskAssignments.xml",
format,
filePath.toString(),
indentation);
return taskAssignmentMarshaller.importFile();
}