From c0417eb55d415d4957ce0eb4ca6c500d9a5882d6 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Thu, 15 Aug 2013 10:39:20 +0200 Subject: [PATCH] OO-531: fix add to catalog in publish wizard, fix catalog / blog clear cache selenium tests, upgrade arquillian to the last final --- pom.xml | 6 +- .../catalog/ui/CatalogEntryAddController.java | 9 +- .../editor/MoveCopySubtreeController.java | 3 - .../olat/course/editor/PublishStep00a.java | 8 +- .../olat/course/editor/PublishStep00b.java | 12 +- .../course/editor/PublishStepCatalog.java | 81 ++++++------- .../org/olat/util/CatalogTreeEntryPosition.vm | 32 ------ .../FunctionalAdministrationSiteUtil.java | 7 +- .../org/olat/util/FunctionalCourseUtil.java | 106 +++++------------- .../org/olat/util/FunctionalHtmlUtil.java | 3 - .../util/FunctionalRepositorySiteUtil.java | 7 +- 11 files changed, 83 insertions(+), 191 deletions(-) delete mode 100644 src/test/java/org/olat/util/CatalogTreeEntryPosition.vm diff --git a/pom.xml b/pom.xml index 2bad12daf67..531d159c7c6 100644 --- a/pom.xml +++ b/pom.xml @@ -2149,7 +2149,7 @@ <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-tomcat-managed-7</artifactId> - <version>1.0.0.CR3</version> + <version>1.0.0.CR5</version> <scope>test</scope> </dependency> <dependency> @@ -2197,14 +2197,14 @@ <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> - <version>1.0.1.Final</version> + <version>1.1.1.Final</version> <scope>import</scope> <type>pom</type> </dependency> <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-drone-bom</artifactId> - <version>1.0.0.Final</version> + <version>1.1.1.Final</version> <type>pom</type> <scope>import</scope> </dependency> diff --git a/src/main/java/org/olat/catalog/ui/CatalogEntryAddController.java b/src/main/java/org/olat/catalog/ui/CatalogEntryAddController.java index e43dda51c06..6f567147d4f 100644 --- a/src/main/java/org/olat/catalog/ui/CatalogEntryAddController.java +++ b/src/main/java/org/olat/catalog/ui/CatalogEntryAddController.java @@ -102,14 +102,13 @@ public class CatalogEntryAddController extends BasicController { if(source == okButton) { GenericTreeNode node = (GenericTreeNode) selectionTree.getSelectedNode(); Long newParentId = Long.parseLong(node.getIdent()); - insertNode(newParentId); - fireEvent(ureq, Event.DONE_EVENT); + insertNode(ureq, newParentId); } else if(source == cancelButton) { fireEvent(ureq, Event.CANCELLED_EVENT); } } - protected boolean insertNode(Long newParentId) { + protected void insertNode(UserRequest ureq, Long newParentId) { CatalogEntry newParent = catalogManager.loadCatalogEntry(newParentId); // check first if this repo entry is already attached to this new parent List<CatalogEntry> existingChildren = catalogManager.getChildrenOf(newParent); @@ -117,7 +116,7 @@ public class CatalogEntryAddController extends BasicController { RepositoryEntry existingRepoEntry = existingChild.getRepositoryEntry(); if (existingRepoEntry != null && existingRepoEntry.equalsByPersistableKey(toBeAddedEntry)) { showError("catalog.tree.add.already.exists", toBeAddedEntry.getDisplayname()); - return false; + return; } } CatalogEntry newEntry = catalogManager.createCatalogEntry(); @@ -128,6 +127,6 @@ public class CatalogEntryAddController extends BasicController { newEntry.setOwnerGroup(BaseSecurityManager.getInstance().createAndPersistSecurityGroup()); // save entry catalogManager.addCatalogEntry(newParent, newEntry); - return true; + fireEvent(ureq, Event.DONE_EVENT); } } diff --git a/src/main/java/org/olat/course/editor/MoveCopySubtreeController.java b/src/main/java/org/olat/course/editor/MoveCopySubtreeController.java index 0c761108ece..15bcc6ac48c 100644 --- a/src/main/java/org/olat/course/editor/MoveCopySubtreeController.java +++ b/src/main/java/org/olat/course/editor/MoveCopySubtreeController.java @@ -57,9 +57,6 @@ import org.olat.util.logging.activity.LoggingResourceable; */ public class MoveCopySubtreeController extends BasicController { - private static final String LOG_COURSENODE_COPIED = "COURSENODE_COPIED"; - private static final String LOG_COURSENODE_MOVED = "COURSENODE_MOVED"; - private CourseEditorTreeNode moveCopyFrom; private boolean copy; diff --git a/src/main/java/org/olat/course/editor/PublishStep00a.java b/src/main/java/org/olat/course/editor/PublishStep00a.java index dd66017ed5b..86c08399c16 100644 --- a/src/main/java/org/olat/course/editor/PublishStep00a.java +++ b/src/main/java/org/olat/course/editor/PublishStep00a.java @@ -78,8 +78,7 @@ class PublishStep00a extends BasicStep implements Step { @Override protected void doDispose() { - // TODO Auto-generated method stub - + // } @Override @@ -88,7 +87,6 @@ class PublishStep00a extends BasicStep implements Step { } @Override - @SuppressWarnings("unused") protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { // if(containsRunContextKey("STEP00.warningMessage")){ @@ -99,6 +97,4 @@ class PublishStep00a extends BasicStep implements Step { } } - - -} +} \ No newline at end of file diff --git a/src/main/java/org/olat/course/editor/PublishStep00b.java b/src/main/java/org/olat/course/editor/PublishStep00b.java index 390b498f66e..7824011ae65 100644 --- a/src/main/java/org/olat/course/editor/PublishStep00b.java +++ b/src/main/java/org/olat/course/editor/PublishStep00b.java @@ -39,7 +39,7 @@ import org.olat.core.gui.control.generic.wizard.StepsRunContext; /** * Description:<br> - * TODO: patrickb Class Description for PublishStep00b + * Step which shows the confirmation with all changes informations * * <P> * Initial Date: 24.01.2008 <br> @@ -92,8 +92,7 @@ class PublishStep00b extends BasicStep implements Step { @Override protected void doDispose() { - // TODO Auto-generated method stub - + //nothing to do } @Override @@ -102,16 +101,11 @@ class PublishStep00b extends BasicStep implements Step { } @Override - @SuppressWarnings("unused") protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { PublishProcess pp = (PublishProcess)getFromRunContext("publishProcess"); String confirmMsg= pp.assemblePublishConfirmation(); uifactory.addStaticTextElement("message", null, confirmMsg, formLayout);//null > no label } - } - - - - + } diff --git a/src/main/java/org/olat/course/editor/PublishStepCatalog.java b/src/main/java/org/olat/course/editor/PublishStepCatalog.java index 410873040be..c6691d81bd1 100644 --- a/src/main/java/org/olat/course/editor/PublishStepCatalog.java +++ b/src/main/java/org/olat/course/editor/PublishStepCatalog.java @@ -32,7 +32,6 @@ import org.olat.catalog.CatalogEntry; import org.olat.catalog.CatalogManager; import org.olat.catalog.ui.CatalogEntryAddController; import org.olat.core.gui.UserRequest; -import org.olat.core.gui.components.Component; import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; import org.olat.core.gui.components.form.flexible.elements.FormLink; @@ -41,8 +40,6 @@ import org.olat.core.gui.components.form.flexible.impl.Form; import org.olat.core.gui.components.form.flexible.impl.FormEvent; import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; import org.olat.core.gui.components.link.Link; -import org.olat.core.gui.components.tree.SelectionTree; -import org.olat.core.gui.components.tree.TreeEvent; import org.olat.core.gui.components.velocity.VelocityContainer; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; @@ -262,6 +259,7 @@ class PublishStepCatalog extends BasicStep { link.setUserObject(label); deleteLinks.add(link); catalogBox.clearError(); + closeAddCatalog(); } else if (event instanceof UndoCategoryEvent) { UndoCategoryEvent e = (UndoCategoryEvent)event; CategoryLabel undelete = e.getUndelete(); @@ -273,16 +271,21 @@ class PublishStepCatalog extends BasicStep { break; } } + closeAddCatalog(); } - cmc.deactivate(); - removeAsListenerAndDispose(catalogAddController); - removeAsListenerAndDispose(cmc); - catalogAddController = null; - cmc = null; + } else { super.event(ureq, source, event); } } + + private void closeAddCatalog() { + if(cmc != null) cmc.deactivate(); + removeAsListenerAndDispose(catalogAddController); + removeAsListenerAndDispose(cmc); + catalogAddController = null; + cmc = null; + } @Override protected void formOK(UserRequest ureq) { @@ -328,7 +331,7 @@ class PublishStepCatalog extends BasicStep { } } - public class SpecialCatalogEntryAddController extends CatalogEntryAddController { + public static class SpecialCatalogEntryAddController extends CatalogEntryAddController { private final RepositoryEntry toBeAddedEntry; private final List<CategoryLabel> categories; @@ -347,45 +350,35 @@ class PublishStepCatalog extends BasicStep { velocity_root = Util.getPackageVelocityRoot(CatalogEntryAddController.class); return super.createVelocityContainer(page); } - + @Override - public void event(UserRequest ureq, Component source, Event event) { - if (source instanceof SelectionTree) { - TreeEvent te = (TreeEvent) event; - if (te.getCommand().equals(TreeEvent.COMMAND_TREENODE_CLICKED)) { - CatalogManager cm = CatalogManager.getInstance(); - Long newParentId = Long.parseLong(te.getNodeId()); - CatalogEntry newParent = cm.loadCatalogEntry(newParentId); - // check first if this repo entry is already attached to this new parent - for (CategoryLabel label:categories) { - CatalogEntry category = label.getCategory(); - if(category.getKey() == null) { - category = label.getParentCategory(); - } - - if(category.equalsByPersistableKey(newParent)) { - if(label.isDeleted()) { - fireEvent(ureq, new UndoCategoryEvent(label)); - } else { - showError("catalog.tree.add.already.exists", toBeAddedEntry.getDisplayname()); - } - return; - } + protected void insertNode(UserRequest ureq, Long newParentId) { + CatalogManager cm = CatalogManager.getInstance(); + CatalogEntry newParent = cm.loadCatalogEntry(newParentId); + // check first if this repo entry is already attached to this new parent + for (CategoryLabel label:categories) { + CatalogEntry category = label.getCategory(); + if(category.getKey() == null) { + category = label.getParentCategory(); + } + + if(category.equalsByPersistableKey(newParent)) { + if(label.isDeleted()) { + fireEvent(ureq, new UndoCategoryEvent(label)); + } else { + showError("catalog.tree.add.already.exists", toBeAddedEntry.getDisplayname()); } - - CatalogEntry newEntry = cm.createCatalogEntry(); - newEntry.setRepositoryEntry(toBeAddedEntry); - newEntry.setName(toBeAddedEntry.getDisplayname()); - newEntry.setDescription(toBeAddedEntry.getDescription()); - newEntry.setType(CatalogEntry.TYPE_LEAF); - newEntry.setParent(newParent); - fireEvent(ureq, new AddToCategoryEvent(newEntry, newParent)); - - } else if (te.getCommand().equals(TreeEvent.COMMAND_CANCELLED)) { - fireEvent(ureq, Event.CANCELLED_EVENT); + return; } } - + + CatalogEntry newEntry = cm.createCatalogEntry(); + newEntry.setRepositoryEntry(toBeAddedEntry); + newEntry.setName(toBeAddedEntry.getDisplayname()); + newEntry.setDescription(toBeAddedEntry.getDescription()); + newEntry.setType(CatalogEntry.TYPE_LEAF); + newEntry.setParent(newParent); + fireEvent(ureq, new AddToCategoryEvent(newEntry, newParent)); } } diff --git a/src/test/java/org/olat/util/CatalogTreeEntryPosition.vm b/src/test/java/org/olat/util/CatalogTreeEntryPosition.vm deleted file mode 100644 index 4272becf067..00000000000 --- a/src/test/java/org/olat/util/CatalogTreeEntryPosition.vm +++ /dev/null @@ -1,32 +0,0 @@ -offset = -1; - -if(document.querySelector){ - var selector = "${treeSelector}"; - var path = "${treePath}"; - - /* make array out of path */ - path = path.substring(1); - var item = path.split("/"); - - /* count items till path fits */ - var selection = window.document.evaluate(selector, window.document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); - var i = 0; - var j = 0; - - for(; i < selection.snapshotLength && j < item.length; i++){ - var current = selection.snapshotItem(i); - - if(current != null){ - var itemSelector = "(" + selector + ")[" + (i + 1) + "]//div[contains(@class, 'b_selectiontree_content') and text()='" + item[j] + "']"; - var itemSelection = window.document.evaluate(itemSelector, window.document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); - - if(itemSelection != null && itemSelection.snapshotLength > 0){ - j++; - } - } - } - - offset = (i + 1) / 2 - (item.length - 1) - 1; -} - -offset; diff --git a/src/test/java/org/olat/util/FunctionalAdministrationSiteUtil.java b/src/test/java/org/olat/util/FunctionalAdministrationSiteUtil.java index dac7204905b..d744d79cfce 100644 --- a/src/test/java/org/olat/util/FunctionalAdministrationSiteUtil.java +++ b/src/test/java/org/olat/util/FunctionalAdministrationSiteUtil.java @@ -19,8 +19,6 @@ */ package org.olat.util; -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; import org.olat.util.FunctionalUtil.OlatSite; import org.olat.util.xss.XssUtil; @@ -32,7 +30,6 @@ import com.thoughtworks.selenium.Selenium; */ @XssUtil public class FunctionalAdministrationSiteUtil { - private final static OLog log = Tracing.createLoggerFor(FunctionalAdministrationSiteUtil.class); public enum AdministrationSiteAction { SYSTEM("o_sel_system"), @@ -211,7 +208,7 @@ public class FunctionalAdministrationSiteUtil { selectorBuffer.append("xpath=//li[contains(@class, '") .append(((AdministrationSiteAction) action).getActionCss()) .append("')]//a[contains(@class, '") - .append(functionalUtil.getTreeLevel1Css()) + .append(functionalUtil.getTreeLevel0Css()) .append("')]"); }else{ String actionL1Css = null; @@ -256,7 +253,7 @@ public class FunctionalAdministrationSiteUtil { selectorBuffer.append("xpath=//li[contains(@class, '") .append(actionL2Css) .append("')]//a[contains(@class, '") - .append(functionalUtil.getTreeLevel2Css()) + .append(functionalUtil.getTreeLevel1Css()) .append("')]"); } diff --git a/src/test/java/org/olat/util/FunctionalCourseUtil.java b/src/test/java/org/olat/util/FunctionalCourseUtil.java index 25fba1fdf84..41e2685bb57 100644 --- a/src/test/java/org/olat/util/FunctionalCourseUtil.java +++ b/src/test/java/org/olat/util/FunctionalCourseUtil.java @@ -23,8 +23,7 @@ import java.io.IOException; import java.io.StringWriter; import java.net.MalformedURLException; import java.net.URI; -import java.util.ArrayList; -import java.util.List; +import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -34,8 +33,6 @@ import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; import org.olat.util.xss.NotImplemented; import org.olat.util.xss.XssInjection; import org.olat.util.xss.XssInjectionDependencies; @@ -57,9 +54,6 @@ import com.thoughtworks.selenium.Selenium; */ @XssUtil public class FunctionalCourseUtil { - private final static OLog log = Tracing.createLoggerFor(FunctionalCourseUtil.class); - - private final static Pattern categoryPattern = Pattern.compile("/([^/]+)"); public final static String COURSE_RUN_CSS = "o_course_run"; public final static String COURSE_OPEN_EDITOR_CSS = "o_sel_course_open_editor"; @@ -893,10 +887,10 @@ public class FunctionalCourseUtil { * @param path * @return */ - public String createCatalogSelectors(Selenium browser, String path){ - if(path == null || - !path.startsWith("/")){ - return(null); + + public String selectCatalogPath(Selenium browser, String path){ + if(path == null || !path.startsWith("/")){ + return null; } functionalUtil.idle(browser); @@ -904,60 +898,24 @@ public class FunctionalCourseUtil { /* * Determine best matching item by using regular expressions */ - StringBuffer itemLocator = new StringBuffer(); - itemLocator.append("//div[contains(@class, 'b_selectiontree_item')]"); - - VelocityContext context = new VelocityContext(); - - context.put("treeSelector", itemLocator.toString()); - context.put("treePath", path); - - VelocityEngine engine = null; - - engine = new VelocityEngine(); - - StringWriter sw = new StringWriter(); - Integer offset = null; - - StringBuffer locatorBuffer = new StringBuffer(); - - locatorBuffer.append("xpath=") - .append(itemLocator.toString()); - functionalUtil.waitForPageToLoadElement(browser, locatorBuffer.toString()); - - try { - engine.evaluate(context, sw, "catalogTreeEntryPosition", FunctionalEPortfolioUtil.class.getResourceAsStream("CatalogTreeEntryPosition.vm")); - - offset = new Integer(browser.getEval(sw.toString())); - - if(offset.intValue() == -1){ - return(null); + String locator = null; + String parentPath = null; + String currentPath = null; + for(StringTokenizer tokenizer=new StringTokenizer(path, "/"); tokenizer.hasMoreTokens(); ) { + parentPath = currentPath; + currentPath = tokenizer.nextToken(); + + StringBuilder sl = new StringBuilder(); + sl.append("//a[span[text() = '").append(currentPath).append("']]"); + if(parentPath != null) { + sl.append("[ancestor::li[div//span[text() = '").append(parentPath).append("']]]"); } - - } catch (ParseErrorException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (MethodInvocationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ResourceNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + + locator = sl.toString(); + functionalUtil.waitForPageToLoadElement(browser, "xpath=" + locator); + browser.click("xpath=" + locator); } - - /* create selector */ - StringBuffer selectorBuffer = new StringBuffer(); - - selectorBuffer.append("xpath=(//div[contains(@class, '") - .append("b_selectiontree_item") - .append("')]//input[@type='radio'])[position()='") - .append(offset.intValue() + 1) - .append("']"); - - return(selectorBuffer.toString()); + return locator; } /** @@ -1018,26 +976,22 @@ public class FunctionalCourseUtil { browser.click(selectorBuffer.toString()); - String catalogSelector = createCatalogSelectors(browser, catalog); + String catalogSelector = selectCatalogPath(browser, catalog); functionalUtil.idle(browser); functionalUtil.waitForPageToLoadElement(browser, catalogSelector); - browser.click(catalogSelector); + //browser.click("xpath=" + catalogSelector); /* click choose */ - selectorBuffer = new StringBuffer(); - - selectorBuffer.append("xpath=//div[contains(@class, '") - .append(getCatalogCss()) - .append("')]//button[contains(@class, '") - .append(functionalUtil.getButtonDirtyCss()) - .append("')]"); + StringBuilder selectOk = new StringBuilder(); + selectOk.append("xpath=//div[contains(@class,'").append(getCatalogCss()).append("')]") + .append("//a[contains(@class,'").append(functionalUtil.getButtonCss()).append("')][contains(@href,'cid%3Aok/')]"); - functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString()); + functionalUtil.waitForPageToLoadElement(browser, selectOk.toString()); - browser.focus(selectorBuffer.toString()); - browser.click(selectorBuffer.toString()); + browser.focus(selectOk.toString()); + browser.click(selectOk.toString()); - functionalUtil.waitForPageToUnloadElement(browser, selectorBuffer.toString()); + functionalUtil.waitForPageToUnloadElement(browser, selectOk.toString()); }else{ functionalUtil.selectOption(browser, getCourseEditorPublishWizardCatalogId(), ADD_TO_CATALOG_NO_VALUE); } diff --git a/src/test/java/org/olat/util/FunctionalHtmlUtil.java b/src/test/java/org/olat/util/FunctionalHtmlUtil.java index fe08d3d9572..12168cb2eb0 100644 --- a/src/test/java/org/olat/util/FunctionalHtmlUtil.java +++ b/src/test/java/org/olat/util/FunctionalHtmlUtil.java @@ -19,8 +19,6 @@ */ package org.olat.util; -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; import org.olat.core.util.filter.FilterFactory; /** @@ -28,7 +26,6 @@ import org.olat.core.util.filter.FilterFactory; * @author jkraehemann, joel.kraehemann@frentix.com, frentix.com */ public class FunctionalHtmlUtil { - private final static OLog log = Tracing.createLoggerFor(FunctionalHtmlUtil.class); /** * Strips all markup of specified string. diff --git a/src/test/java/org/olat/util/FunctionalRepositorySiteUtil.java b/src/test/java/org/olat/util/FunctionalRepositorySiteUtil.java index 195141fc2ab..dcba8b29928 100644 --- a/src/test/java/org/olat/util/FunctionalRepositorySiteUtil.java +++ b/src/test/java/org/olat/util/FunctionalRepositorySiteUtil.java @@ -25,8 +25,6 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; import org.olat.util.FunctionalUtil.OlatSite; import org.olat.util.xss.XssUtil; @@ -39,7 +37,6 @@ import com.thoughtworks.selenium.Selenium; */ @XssUtil public class FunctionalRepositorySiteUtil { - private final static OLog log = Tracing.createLoggerFor(FunctionalRepositorySiteUtil.class); private final static Pattern categoryPattern = Pattern.compile("/([^/]+)"); @@ -1256,11 +1253,11 @@ public class FunctionalRepositorySiteUtil { /* catalog */ if(catalog != null){ - String catalogSelectors = functionalCourseUtil.createCatalogSelectors(browser, catalog); + String catalogSelectors = functionalCourseUtil.selectCatalogPath(browser, catalog); functionalUtil.idle(browser); functionalUtil.waitForPageToLoadElement(browser, catalogSelectors); - browser.click(catalogSelectors); + //browser.click(catalogSelectors); } functionalUtil.clickWizardNext(browser); -- GitLab