- modifies importFiles-method in AbstractMarshaller.java to return boolean for easier test evaluation
- reduces import tests to a single xml file for easier problem finding 
- modifies insertIntoDb method overriden by RoleMembershipMarshaller

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4554 8810af33-2d31-482b-a856-94f89814c4df
tosmers 2017-02-07 20:44:46 +00:00
parent 00d2858e0d
commit cf95e4d26f
4 changed files with 46 additions and 35 deletions

View File

@ -174,9 +174,10 @@ public abstract class AbstractMarshaller<P extends Portable> {
* of the list represents an object of the file. Then retrieves each object
* from the corresponding string in the list.
*
* @return List of imported objects.
* @return If error occurs true, otherwise false.
*/
public List<P> importFile() {
public boolean importFile() {
boolean error = false;
File file = new File(filename);
List<String> lines = null;
@ -186,6 +187,7 @@ public abstract class AbstractMarshaller<P extends Portable> {
LOGGER.error("Unable to read lines of the file with " +
"name {}.", file.getName());
LOGGER.error(e);
error = true;
}
List<P> objects = new ArrayList<>();
@ -201,6 +203,7 @@ public abstract class AbstractMarshaller<P extends Portable> {
LOGGER.error("Unable to read objects " +
"from XML line:\n \"{}\"", line);
LOGGER.error(e);
error = true;
}
break;
@ -214,10 +217,11 @@ public abstract class AbstractMarshaller<P extends Portable> {
} else {
emptyObjects+=1;
LOGGER.info("Count of empty objects: {}", emptyObjects);
error = true;
}
}
}
return objects;
return error;
}
/**

View File

@ -45,10 +45,10 @@ public class RoleMembershipMarshaller extends AbstractMarshaller<RoleMembership>
@Override
@Transactional(Transactional.TxType.REQUIRED)
protected void insertIntoDb(RoleMembership portableObject) {
if (portableObject.getMembershipId() == 0) {
// if (portableObject.getMembershipId() == 0) {
entityManager.persist(portableObject);
} else {
entityManager.merge(portableObject);
}
// } else {
// entityManager.merge(portableObject);
// }
}
}

View File

@ -31,6 +31,7 @@ import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@ -107,6 +108,8 @@ public class CoreDataImportTest {
.class.getPackage())
.addPackage(org.libreccm.jpa.EntityManagerProducer
.class.getPackage())
.addClass(com.arsdigita.util.UncheckedWrapperException
.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
@ -127,70 +130,73 @@ public class CoreDataImportTest {
@Test
@InSequence(105)
public void categoriesShouldBeImported() {
importHelper.importRoleMemberships();
Assert.assertFalse(importHelper.importRoleMemberships());
}
@Test
//@Test
@InSequence(110)
public void categorizationsShouldBeImported() {
importHelper.importGroupMemberships();
}
@Test
//@Test
@InSequence(115)
public void usersShouldBeImported() {
importHelper.importGroups();
}
@Test
//@Test
@InSequence(120)
public void groupsShouldBeImported() {
importHelper.importUsers();
}
@Test
//@Test
@InSequence(125)
public void groupMembershipsShouldBeImported() {
importHelper.importTaskAssignments();
}
@Test
//@Test
@InSequence(130)
public void rolesShouldBeImported() {
importHelper.importAssignableTasks();
}
@Test
//@Test
@InSequence(135)
public void roleMembershipsShouldBeImported() {
importHelper.importWorkflowTemplates();
}
@Test
//@Test
@InSequence(140)
public void workflowTemplatesShouldBeImported() {
importHelper.importWorkflows();
}
@Test
//@Test
@InSequence(145)
public void workflowsShouldBeImported() {
importHelper.importCategorizations();
}
@Test
//@Test
@InSequence(150)
public void assignableTasksShouldBeImported() {
importHelper.importPermissions();
}
@Test
//@Test
@InSequence(155)
public void taskAssignmentsShouldBeImported() {
importHelper.importCategories();
}
@Test
//@Test
@InSequence(160)
public void permissionsShouldBeImported() {
importHelper.importRoles();

View File

@ -55,8 +55,9 @@ import javax.inject.Inject;
*/
@RequestScoped
class ImportHelper {
private String pathName =
"/home/jensp/pwi/libreccm/ccm/ccm_ng/ccm-core/src/test/resources/" +
private String repoPath = "/home/tosmers/Svn/libreccm/";
//private String repoPath = "";
private String projectPath = "ccm_ng/ccm-core/src/test/resources/" +
"portation/trunk-iaw-exports";
private boolean indentation = false;
@ -99,73 +100,73 @@ class ImportHelper {
void importCategories() {
categoryMarshaller.prepare(Format.XML, pathName,
categoryMarshaller.prepare(Format.XML, repoPath + projectPath,
"categories.xml", indentation);
categoryMarshaller.importFile();
}
void importCategorizations() {
categorizationMarshaller.prepare(Format.XML, pathName,
categorizationMarshaller.prepare(Format.XML, repoPath + projectPath,
"categorizations.xml", indentation);
categorizationMarshaller.importFile();
}
void importUsers() {
userMarshaller.prepare(Format.XML, pathName,
userMarshaller.prepare(Format.XML, repoPath + projectPath,
"users.xml", indentation);
userMarshaller.importFile();
}
void importGroups() {
groupMarshaller.prepare(Format.XML, pathName,
groupMarshaller.prepare(Format.XML, repoPath + projectPath,
"groups.xml", indentation);
groupMarshaller.importFile();
}
void importGroupMemberships() {
groupMembershipMarshaller.prepare(Format.XML, pathName,
groupMembershipMarshaller.prepare(Format.XML, repoPath + projectPath,
"groupMemberships.xml", indentation);
groupMembershipMarshaller.importFile();
}
void importRoles() {
roleMarshaller.prepare(Format.XML, pathName,
roleMarshaller.prepare(Format.XML, repoPath + projectPath,
"roles.xml", indentation);
roleMarshaller.importFile();
}
void importRoleMemberships() {
roleMembershipMarshaller.prepare(Format.XML, pathName,
boolean importRoleMemberships() {
roleMembershipMarshaller.prepare(Format.XML, repoPath + projectPath,
"roleMemberships.xml", indentation);
roleMembershipMarshaller.importFile();
return roleMembershipMarshaller.importFile();
}
void importWorkflowTemplates() {
workflowTemplateMarshaller.prepare(Format.XML, pathName,
workflowTemplateMarshaller.prepare(Format.XML, repoPath + projectPath,
"workflowTemplates.xml", indentation);
workflowTemplateMarshaller.importFile();
}
void importWorkflows() {
workflowMarshaller.prepare(Format.XML, pathName,
workflowMarshaller.prepare(Format.XML, repoPath + projectPath,
"workflows.xml", indentation);
workflowMarshaller.importFile();
}
void importAssignableTasks() {
assignableTaskMarshaller.prepare(Format.XML, pathName,
assignableTaskMarshaller.prepare(Format.XML, repoPath + projectPath,
"assignableTasks.xml", indentation);
assignableTaskMarshaller.importFile();
}
void importTaskAssignments() {
taskAssignmentMarshaller.prepare(Format.XML, pathName,
taskAssignmentMarshaller.prepare(Format.XML, repoPath + projectPath,
"taskAssignments.xml", indentation);
taskAssignmentMarshaller.importFile();
}
void importPermissions() {
permissionMarshaller.prepare(Format.XML, pathName,
permissionMarshaller.prepare(Format.XML, repoPath + projectPath,
"permissions.xml", indentation);
permissionMarshaller.importFile();
}