From 9e593aaf9ca9a4c0f64e8c789df56e42af796d7e Mon Sep 17 00:00:00 2001 From: jensp Date: Fri, 9 Sep 2016 18:53:05 +0000 Subject: [PATCH] CCM NG: Fixed several bugs found by tests related to the methods of ContentItemManager git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4291 8810af33-2d31-482b-a856-94f89814c4df --- ccm-cms/pom.xml | 6 + .../librecms/contentsection/ContentItem.java | 8 + .../contentsection/ContentItemManager.java | 26 +- .../contentsection/ContentTypeRepository.java | 2 +- .../java/org/librecms/lifecycle/Phase.java | 1 + ...7_0_0_5_fix_wrong_col_lifecycle_phases.sql | 2 + ...7_0_0_5_fix_wrong_col_lifecycle_phases.sql | 2 + .../ContentItemManagerTest.java | 246 ++++++-- .../ContentItemRepositoryTest.java | 17 +- .../librecms/contentsection/DatasetsTest.java | 3 +- .../scripts/create_ccm_cms_schema.sql | 4 +- .../scripts/create_ccm_cms_schema.sql | 4 +- .../ContentItemManagerTest/log4j2.xml | 31 + .../datasets/create_ccm_cms_schema.sql | 82 ++- .../after-create-contentitem.xml | 540 ++++++++++++++++++ .../ContentItemManagerTest/data.xml | 237 +++++++- .../src/test/resources/scripts/h2-cleanup.sql | 52 +- .../test/resources/scripts/pgsql-cleanup.sql | 12 +- ccm-cms/src/test/resources/test-web.xml | 2 +- .../libreccm/workflow/WorkflowManager.java | 34 +- .../categorization/CategoryManagerTest.java | 7 + 21 files changed, 1219 insertions(+), 99 deletions(-) create mode 100644 ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/h2/V7_0_0_5_fix_wrong_col_lifecycle_phases.sql create mode 100644 ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/pgsql/V7_0_0_5_fix_wrong_col_lifecycle_phases.sql create mode 100644 ccm-cms/src/test/resources/configs/org/librecms/contentsection/ContentItemManagerTest/log4j2.xml create mode 100644 ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/after-create-contentitem.xml diff --git a/ccm-cms/pom.xml b/ccm-cms/pom.xml index 436527e6e..57a77f9bd 100644 --- a/ccm-cms/pom.xml +++ b/ccm-cms/pom.xml @@ -163,6 +163,7 @@ 2.18.1 org.libreccm.tests.categories.UnitTest + false @@ -280,6 +281,9 @@ org.apache.maven.plugins maven-surefire-report-plugin 2.18.1 + + false + org.jacoco @@ -417,6 +421,7 @@ always 999 true + false org.jboss.logmanager.LogManager + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml index 9405d8876..4f0e6c229 100644 --- a/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml +++ b/ccm-cms/src/test/resources/datasets/org/librecms/contentsection/ContentItemManagerTest/data.xml @@ -1,6 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -10,6 +89,24 @@ + + + + + + - + @@ -48,8 +145,134 @@ root_documents_folder_id="-2100" root_assets_folder_id="-2200" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + name="info_alert_recipient" /> + + + + - CcmCoreTest + CcmCmsTest ShiroFilter diff --git a/ccm-core/src/main/java/org/libreccm/workflow/WorkflowManager.java b/ccm-core/src/main/java/org/libreccm/workflow/WorkflowManager.java index cee0ee4f9..de8e7538f 100644 --- a/ccm-core/src/main/java/org/libreccm/workflow/WorkflowManager.java +++ b/ccm-core/src/main/java/org/libreccm/workflow/WorkflowManager.java @@ -19,6 +19,7 @@ package org.libreccm.workflow; import org.libreccm.core.CoreConstants; +import org.libreccm.l10n.LocalizedString; import org.libreccm.security.AuthorizationRequired; import org.libreccm.security.RequiresPrivilege; import org.libreccm.security.Role; @@ -70,13 +71,24 @@ public class WorkflowManager { @Transactional(Transactional.TxType.REQUIRED) public Workflow createWorkflow(final WorkflowTemplate template) { final Workflow workflow = new Workflow(); + + final LocalizedString name = new LocalizedString(); + template.getName().getValues().forEach( + (locale, str) -> name.addValue(locale, str)); + workflow.setName(name); + + final LocalizedString description = new LocalizedString(); + template.getDescription().getValues().forEach( + (locale, str) -> description.addValue(locale, str)); + workflow.setDescription(description); + final Map tasks = new HashMap<>(); template.getTasks().forEach(taskTemplate -> createTask(taskTemplate, tasks)); template.getTasks().forEach(taskTemplate -> fixTaskDependencies( taskTemplate, tasks.get(taskTemplate.getTaskId()), tasks)); - + tasks.values().forEach(task -> taskRepo.save(task)); workflowRepo.save(workflow); @@ -105,15 +117,31 @@ public class WorkflowManager { if ("taskId".equals(propertyDesc.getName()) || "workflow".equals(propertyDesc.getName()) || "dependentTasks".equals(propertyDesc.getName()) - || "dependsOn".equals(propertyDesc.getName())) { + || "dependsOn".equals(propertyDesc.getName()) + || "assignments".equals(propertyDesc.getName()) + || "class".equals(propertyDesc.getName())) { continue; } final Method readMethod = propertyDesc.getReadMethod(); final Method writeMethod = propertyDesc.getWriteMethod(); + if (writeMethod == null) { + continue; + } + final Object value = readMethod.invoke(template); - writeMethod.invoke(task, value); + if (value instanceof LocalizedString) { + final LocalizedString localized = (LocalizedString) value; + final LocalizedString copy = new LocalizedString(); + + localized.getValues().forEach( + (locale, str) -> copy.addValue(locale, str)); + + writeMethod.invoke(task, copy); + } else { + writeMethod.invoke(task, value); + } } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { diff --git a/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java b/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java index 9093cd5ed..835ea84a6 100644 --- a/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java @@ -178,6 +178,13 @@ public class CategoryManagerTest { System.out.println("Dataset loaded successfully."); } + @Test + @InSequence(20) + public void checkShiro() { + assertThat(shiro.getSecurityManager(), is(not(nullValue()))); + assertThat(shiro.getSystemUser(), is(not(nullValue()))); + } + @Test @UsingDataSet( "datasets/org/libreccm/categorization/CategoryManagerTest/data.yml")