From a1dbd98b02fb2cbba727cb0d2cd5c92ddbb70600 Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Mon, 30 Nov 2015 21:22:59 +0100
Subject: [PATCH] no-jira: tweak events in business group controllers to make
 the selenium tests more reliable

---
 .../org/olat/collaboration/CollaborationTools.java   |  4 ----
 .../CollaborationToolsSettingsController.java        |  4 +---
 .../group/ui/edit/BusinessGroupEditController.java   | 12 +++++++++---
 .../ui/edit/BusinessGroupMembersController.java      |  7 +++++--
 .../group/ui/edit/BusinessGroupToolsController.java  |  5 +----
 .../group/ui/run/BusinessGroupMainRunController.java |  8 ++++++--
 .../java/org/olat/selenium/page/group/GroupPage.java |  2 --
 .../org/olat/selenium/page/group/GroupsPage.java     |  2 ++
 8 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/src/main/java/org/olat/collaboration/CollaborationTools.java b/src/main/java/org/olat/collaboration/CollaborationTools.java
index 14b9d596574..8d9decbf069 100644
--- a/src/main/java/org/olat/collaboration/CollaborationTools.java
+++ b/src/main/java/org/olat/collaboration/CollaborationTools.java
@@ -372,7 +372,6 @@ public class CollaborationTools implements Serializable {
 			return null;
 		}
 
-		//fxdiff VCRP-8: collaboration tools folder access control
 		boolean writeAccess;
 		boolean isOwner = CoreSpringFactory.getImpl(BusinessGroupService.class).hasRoles(identity, businessGroup, GroupRoles.coach.name());
 		if (!(isAdmin || isOwner)) {
@@ -773,7 +772,6 @@ public class CollaborationTools implements Serializable {
 		}
 	}
 	
-	//fxdiff VCRP-8: collaboration tools folder access control
 	public Long lookupFolderAccess() {
 		NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
 		Property property = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FOLDER_ACCESS);
@@ -784,7 +782,6 @@ public class CollaborationTools implements Serializable {
 		return property.getLongValue();
 	}
 	
-	//fxdiff VCRP-8: collaboration tools folder access control
 	public void saveFolderAccess(Long folderrAccess) {
 		NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(ores);
 		Property property = npm.findProperty(null, null, PROP_CAT_BG_COLLABTOOLS, KEY_FOLDER_ACCESS);
@@ -799,7 +796,6 @@ public class CollaborationTools implements Serializable {
 	
 	public class CollabSecCallback implements VFSSecurityCallback {
 		
-		//fxdiff VCRP-8: collaboration tools folder access control
 		private final boolean write;
 		private Quota folderQuota = null;
 		private SubscriptionContext subsContext;
diff --git a/src/main/java/org/olat/collaboration/CollaborationToolsSettingsController.java b/src/main/java/org/olat/collaboration/CollaborationToolsSettingsController.java
index fe13e0eefbb..bfb17ccd5b2 100644
--- a/src/main/java/org/olat/collaboration/CollaborationToolsSettingsController.java
+++ b/src/main/java/org/olat/collaboration/CollaborationToolsSettingsController.java
@@ -135,7 +135,6 @@ public class CollaborationToolsSettingsController extends BasicController {
 		// update quota form: only show when enabled
 		if (collabTools.isToolEnabled(CollaborationTools.TOOL_FOLDER)) {
 			vc_collabtools.contextPut("folderToolEnabled", Boolean.TRUE);
-			//fxdiff VCRP-8: collaboration tools folder access control
 			if(ureq.getUserSession().getRoles().isOLATAdmin()) {
 				vc_collabtools.put("quota", quotaCtr.getInitialComponent());
 			}
@@ -255,7 +254,6 @@ public class CollaborationToolsSettingsController extends BasicController {
 			CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(
 					new CalendarGUIModifiedEvent(), OresHelper.lookupType(CalendarManager.class)
 			);
-		//fxdiff VCRP-8: collaboration tools folder access control
 		} else if (source == folderForm) {
 			collabTools.saveFolderAccess(new Long(folderForm.getFolderAccess()));
 		}
@@ -300,7 +298,7 @@ class ChoiceOfToolsForm extends FormBasicController {
 			}
 			theKeys.add(""+i);
 			theValues.add(translate("collabtools.named." + availableTools[i]));
-			theClasses.add(translate("o_sel_" + availableTools[i]));
+			theClasses.add("o_sel_" + availableTools[i]);
 		}
 		
 		toolsKeys = theKeys.toArray(new String[theKeys.size()]);
diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java
index 0407035799f..83b1eab137b 100644
--- a/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java
+++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupEditController.java
@@ -131,7 +131,7 @@ public class BusinessGroupEditController extends BasicController implements Cont
 				putInitialPanel(vc);
 			} else {
 				// add as listener to BusinessGroup so we are being notified about changes.
-				CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, ureq.getIdentity(), currBusinessGroup);
+				CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, getIdentity(), currBusinessGroup);
 	
 				//create some controllers
 				editDetailsController = new BusinessGroupEditDetailsController(ureq, getWindowControl(), businessGroup);
@@ -143,7 +143,6 @@ public class BusinessGroupEditController extends BasicController implements Cont
 				membersController = new BusinessGroupMembersController(ureq, getWindowControl(), toolbarPanel, businessGroup);
 				listenTo(membersController);
 				
-				//fxdiff VCRP-1,2: access control of resources
 				tabbedPane = new TabbedPane("bgTabbs", ureq.getLocale());
 				tabbedPane.addListener(this);
 				setAllTabs(ureq);
@@ -162,6 +161,10 @@ public class BusinessGroupEditController extends BasicController implements Cont
 		}
 	}
 	
+	public BusinessGroup getBusinessGroup() {
+		return currBusinessGroup;
+	}
+	
 	/**
 	 * Learning areas and and course rights should only appear when at least one course is associated.</br>
 	 * <ul><li>
@@ -267,10 +270,10 @@ public class BusinessGroupEditController extends BasicController implements Cont
 	public void event(UserRequest ureq, Controller source, Event event) {
 		if (source == collaborationToolsController) {
 			if (event == Event.CHANGED_EVENT) {
+				fireEvent(ureq, event);
 				// notify current active users of this business group
 				BusinessGroupModifiedEvent
 						.fireModifiedGroupEvents(BusinessGroupModifiedEvent.CONFIGURATION_MODIFIED_EVENT, currBusinessGroup, null);
-				fireEvent(ureq, event);
 			}
 		} else if (source == alreadyLockedDialogController) {
 			//closed dialog box either by clicking ok, or closing the box
@@ -281,6 +284,8 @@ public class BusinessGroupEditController extends BasicController implements Cont
 			if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
 				//reload the business group
 				currBusinessGroup = editDetailsController.getGroup();
+				fireEvent(ureq, event);
+				
 				// inform index about change
 				setAllTabs(ureq);
 				// notify current active users of this business group
@@ -307,6 +312,7 @@ public class BusinessGroupEditController extends BasicController implements Cont
 	/**
 	 * @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event)
 	 */
+	@Override
 	public void event(Event event) {
 		if (event instanceof OLATResourceableJustBeforeDeletedEvent) {
 			OLATResourceableJustBeforeDeletedEvent delEvent = (OLATResourceableJustBeforeDeletedEvent) event;
diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupMembersController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupMembersController.java
index 9a7674b3e8c..c9fc9ab13b3 100644
--- a/src/main/java/org/olat/group/ui/edit/BusinessGroupMembersController.java
+++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupMembersController.java
@@ -160,25 +160,28 @@ public class BusinessGroupMembersController extends BasicController {
 				boolean waitingPublic = dmsForm.isDisplayWaitingListPublic();
 				boolean download = dmsForm.isDownloadList();
 				
+				//changes are committed by the service
 				businessGroup = businessGroupService.updateDisplayMembers(businessGroup,
 						ownersIntern, participantsIntern, waitingIntern,
 						ownersPublic, participantsPublic, waitingPublic,
 						download);
+				fireEvent(ureq, event);
+				
 				// notify current active users of this business group
 				BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.CONFIGURATION_MODIFIED_EVENT, businessGroup, null);
 				// do loggin
 				ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_CONFIGURATION_CHANGED, getClass());
-				fireEvent(ureq, event);
 			}
 		} else if (source == configForm) {
 			if(event == Event.CHANGED_EVENT) {
 				boolean allow = configForm.isAllowToLeaveBusinessGroup();
 				businessGroup = businessGroupService.updateAllowToLeaveBusinessGroup(businessGroup, allow);
+				fireEvent(ureq, event);
+				
 				// notify current active users of this business group
 				BusinessGroupModifiedEvent.fireModifiedGroupEvents(BusinessGroupModifiedEvent.CONFIGURATION_MODIFIED_EVENT, businessGroup, null);
 				// do loggin
 				ThreadLocalUserActivityLogger.log(GroupLoggingAction.GROUP_CONFIGURATION_CHANGED, getClass());
-				fireEvent(ureq, event);
 			}
 		} else if(source == importMembersWizard) {
 			if(event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
diff --git a/src/main/java/org/olat/group/ui/edit/BusinessGroupToolsController.java b/src/main/java/org/olat/group/ui/edit/BusinessGroupToolsController.java
index cad62d546ee..c7834a63b0e 100644
--- a/src/main/java/org/olat/group/ui/edit/BusinessGroupToolsController.java
+++ b/src/main/java/org/olat/group/ui/edit/BusinessGroupToolsController.java
@@ -19,8 +19,6 @@
  */
 package org.olat.group.ui.edit;
 
-import org.olat.collaboration.CollaborationTools;
-import org.olat.collaboration.CollaborationToolsFactory;
 import org.olat.collaboration.CollaborationToolsSettingsController;
 import org.olat.core.gui.UserRequest;
 import org.olat.core.gui.components.Component;
@@ -44,8 +42,7 @@ public class BusinessGroupToolsController extends BasicController {
 		super(ureq, wControl);
 		
 		mainVC = createVelocityContainer("tab_bgCollabTools");
-		CollaborationTools ctsm = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup);
-		toolsController = ctsm.createCollaborationToolsSettingsController(ureq, getWindowControl());
+		toolsController = new CollaborationToolsSettingsController(ureq, getWindowControl(), businessGroup);
 		// we are listening on CollaborationToolsSettingsController events
 		// which are just propagated to our attached controllerlistener...
 		// e.g. the BusinessGroupMainRunController, updating the MenuTree
diff --git a/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java b/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java
index 9bf3a984bd1..f55a30a2937 100644
--- a/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java
+++ b/src/main/java/org/olat/group/ui/run/BusinessGroupMainRunController.java
@@ -224,6 +224,8 @@ public class BusinessGroupMainRunController extends MainLayoutBasicController im
 	@Autowired
 	private CalendarModule calendarModule;
 	@Autowired
+	private InstantMessagingModule imModule;
+	@Autowired
 	private BusinessGroupService businessGroupService;
 
 	/**
@@ -372,8 +374,7 @@ public class BusinessGroupMainRunController extends MainLayoutBasicController im
 	}
 	
 	private boolean isChatAvailable() {
-		return CoreSpringFactory.getImpl(InstantMessagingModule.class).isEnabled() &&
-				CoreSpringFactory.getImpl(InstantMessagingModule.class).isGroupEnabled() && 
+		return imModule.isEnabled() && imModule.isGroupEnabled() && 
 				CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(businessGroup).isToolEnabled(CollaborationTools.TOOL_CHAT);
 	}
 	
@@ -443,6 +444,9 @@ public class BusinessGroupMainRunController extends MainLayoutBasicController im
 		if (source == bgEditCntrllr) {
 			// changes from the admin controller
 			if (event == Event.CHANGED_EVENT) {
+				businessGroup = bgEditCntrllr.getBusinessGroup();
+				chatAvailable = isChatAvailable();
+				
 				TreeModel trMdl = buildTreeModel();
 				bgTree.setTreeModel(trMdl);
 				bgTree.setSelectedNode(nodeAdmin);
diff --git a/src/test/java/org/olat/selenium/page/group/GroupPage.java b/src/test/java/org/olat/selenium/page/group/GroupPage.java
index ac12929975f..8416c84687b 100644
--- a/src/test/java/org/olat/selenium/page/group/GroupPage.java
+++ b/src/test/java/org/olat/selenium/page/group/GroupPage.java
@@ -197,8 +197,6 @@ public class GroupPage {
 			OOGraphene.waitBusy(browser);
 			OOGraphene.waitElement(memberMenuItem, 2, browser);
 		}
-		
-		OOGraphene.waitBusy(browser);
 		return this;
 	}
 	
diff --git a/src/test/java/org/olat/selenium/page/group/GroupsPage.java b/src/test/java/org/olat/selenium/page/group/GroupsPage.java
index 6463c8e4d46..5e957027a67 100644
--- a/src/test/java/org/olat/selenium/page/group/GroupsPage.java
+++ b/src/test/java/org/olat/selenium/page/group/GroupsPage.java
@@ -73,6 +73,8 @@ public class GroupsPage {
 		WebElement submitButton = browser.findElement(submitBy);
 		submitButton.click();
 		OOGraphene.waitBusy(browser);
+		By groupNameBy = By.xpath("//div[@id='o_main_center_content_inner']//p[contains(text(),'" + name+ "')]");
+		OOGraphene.waitElement(groupNameBy, 2, browser);
 		
 		return new GroupPage(browser);
 	}
-- 
GitLab