diff --git a/src/test/java/org/olat/course/nodes/feed/FunctionalBlogTest.java b/src/test/java/org/olat/course/nodes/feed/FunctionalBlogTest.java index 7f0a7c7292abfad3267ebc1d640cc02206dd7828..d69c055e3f110b20cce15498a5050b7db73c1752 100644 --- a/src/test/java/org/olat/course/nodes/feed/FunctionalBlogTest.java +++ b/src/test/java/org/olat/course/nodes/feed/FunctionalBlogTest.java @@ -79,7 +79,7 @@ public class FunctionalBlogTest { public final static String DELETE_BLOG_DESCRIPTION = "The first blog entry will be deleted"; public final static String DELETE_BLOG_CONTENT = "You should be able to choose to create or feed from existing blog."; - public final static String CONCURRENT_CLEAR_CACHE_BLOG = "/org/olat/course/nodes/feed/blog.zip"; + public final static String CONCURRENT_CLEAR_CACHE_BLOG_PATH = "/org/olat/course/nodes/feed/blog.zip"; public final static String CONCURRENT_CLEAR_CACHE_BLOG_FILE_NAME = "blog.zip"; public final static String CONCURRENT_CLEAR_CACHE_BLOG_RESOURCE_NAME = "Blog"; public final static String CONCURRENT_CLEAR_CACHE_BLOG_DISPLAY_NAME = "Parallel Computing Blog"; @@ -88,7 +88,7 @@ public class FunctionalBlogTest { public final static String CONCURRENT_CLEAR_CACHE_BLOG_POST1_CONTENT = "Please take a look at ReentrantLock class in JavaSE package java.util.concurrent.locks for further information."; public final static String CONCURRENT_CLEAR_CACHE_BLOG_POST2_TITLE = "Creating conditions"; public final static String CONCURRENT_CLEAR_CACHE_BLOG_POST2_DESCRIPTION = "Wait until condition is fulfilled."; - public final static String CONCURRENT_CLEAR_CACHE_BLOG_POST2_CONTENT = "With the ReentrantLock class you may create new conditions like following:<br><code>final Lock lock = new ReentrantLock();<br>final Condition cond = lock.newCondition()<br></code>"; + public final static String CONCURRENT_CLEAR_CACHE_BLOG_POST2_CONTENT = "With the ReentrantLock class you may create new conditions like following:<br>\n<code>\nfinal Lock lock = new ReentrantLock();<br>\nfinal Condition cond = lock.newCondition()<br>\n</code>\n"; public final static String CONCURRENT_RW_BLOG_SHORT_TITLE = "blog"; public final static String CONCURRENT_RW_BLOG_LONG_TITLE = "blog cleared cache"; @@ -140,18 +140,21 @@ public class FunctionalBlogTest { /* login for test setup */ Assert.assertTrue(functionalUtil.login(browser, functionalUtil.getUsername(), functionalUtil.getPassword(), true)); - /* */ + /* create a empty blog */ Assert.assertTrue(functionalRepositorySiteUtil.openCourse(browser, course.getRepoEntryKey())); Assert.assertTrue(functionalCourseUtil.openCourseEditor(browser)); Assert.assertTrue(functionalCourseUtil.createCourseNode(browser, CourseNodeAlias.BLOG, BLOG_SHORT_TITLE, BLOG_LONG_TITLE, BLOG_DESCRIPTION, 0)); Assert.assertTrue(functionalCourseUtil.createBlog(browser, BLOG_SHORT_TITLE, BLOG_DESCRIPTION)); + /* publish */ Assert.assertTrue(functionalCourseUtil.publishEntireCourse(browser, null, null)); + /* import empty feed */ Assert.assertTrue(functionalCourseUtil.open(browser, course.getRepoEntryKey(), 0)); Assert.assertTrue(functionalCourseUtil.importBlogFeed(browser, BLOG_FEED)); + /* blog should be accessible */ Assert.assertTrue(functionalCourseUtil.open(browser, course.getRepoEntryKey(), 0)); @@ -165,7 +168,6 @@ public class FunctionalBlogTest { //TODO:JK: implement me } - @Ignore @Test @RunAsClient public void checkConcurrentClearCache(@Drone @Tutor1 DefaultSelenium tutor0, @Drone @Student1 DefaultSelenium student0) throws IOException, URISyntaxException{ @@ -176,7 +178,7 @@ public class FunctionalBlogTest { int tutorCount = 1; final UserVO[] tutors = new UserVO[tutorCount]; - functionalVOUtil.createTestUsers(deploymentUrl, tutorCount).toArray(tutors); + functionalVOUtil.createTestAuthors(deploymentUrl, tutorCount).toArray(tutors); /* create user */ int userCount = 1; @@ -184,11 +186,12 @@ public class FunctionalBlogTest { final UserVO[] students = new UserVO[userCount]; functionalVOUtil.createTestUsers(deploymentUrl, userCount).toArray(students); - /* create blog and set rights for tutor */ + /* create blog and set tutor as owner */ RepositoryEntryVO repoEntry = functionalVOUtil.importBlog(deploymentUrl, - CONCURRENT_CLEAR_CACHE_BLOG, + CONCURRENT_CLEAR_CACHE_BLOG_PATH, CONCURRENT_CLEAR_CACHE_BLOG_FILE_NAME, CONCURRENT_CLEAR_CACHE_BLOG_RESOURCE_NAME, CONCURRENT_CLEAR_CACHE_BLOG_DISPLAY_NAME); - //FIXME:JK: set rights + + functionalVOUtil.addOwnerToRepositoryEntry(deploymentUrl, repoEntry, tutors[0]); /* * Create content and visit it. @@ -228,68 +231,99 @@ public class FunctionalBlogTest { /* student verifies title - month */ functionalUtil.idle(student0); + String[] titles = { + CONCURRENT_CLEAR_CACHE_BLOG_POST1_TITLE, + CONCURRENT_CLEAR_CACHE_BLOG_POST2_TITLE + }; + StringBuffer selectorBuffer = new StringBuffer(); - selectorBuffer.append("xpath=(//ul[contains(@class, '") + selectorBuffer.append("//ul[contains(@class, '") .append(functionalCourseUtil.getBlogMonthCss()) - .append("')]//li//a)"); + .append("')]//li//a"); int iStop = student0.getXpathCount(selectorBuffer.toString()).intValue(); - boolean foundTitleInMonth = false; + + boolean[] foundTitlesInMonth = new boolean[titles.length]; + Arrays.fill(foundTitlesInMonth, false); + for(int i = 0; i < iStop; i++){ functionalUtil.idle(student0); - StringBuffer currentBuffer = new StringBuffer(selectorBuffer); + /* click month */ + StringBuffer currentBuffer = new StringBuffer(); - currentBuffer.append('[') + currentBuffer.append("xpath=(") + .append(selectorBuffer) + .append(")[") .append(i + 1) .append(']'); + functionalUtil.waitForPageToLoadElement(student0, currentBuffer.toString()); student0.click(currentBuffer.toString()); functionalUtil.idle(student0); - if(student0.isTextPresent(CONCURRENT_CLEAR_CACHE_BLOG_POST2_TITLE)){ - foundTitleInMonth = true; - break; + /* it should be visible somewhere */ + int j = 0; + + for(String currentTitle: titles){ + if(student0.isTextPresent(currentTitle)){ + foundTitlesInMonth[j] = true; + break; + } + + j++; } } - Assert.assertTrue(foundTitleInMonth); + Assert.assertFalse(ArrayUtils.contains(foundTitlesInMonth, false)); /* student verifies title - year */ functionalUtil.idle(student0); selectorBuffer = new StringBuffer(); - selectorBuffer.append("xpath=(//div//a[contains(@class, '") + selectorBuffer.append("//div//a[contains(@class, '") .append(functionalCourseUtil.getBlogYearCss()) - .append("')])"); + .append("')]"); iStop = student0.getXpathCount(selectorBuffer.toString()).intValue(); - boolean foundTitleInYear = false; + + boolean[] foundTitlesInYear = new boolean[titles.length]; + Arrays.fill(foundTitlesInYear, false); for(int i = 0; i < iStop; i++){ functionalUtil.idle(student0); - StringBuffer currentBuffer = new StringBuffer(selectorBuffer); + /* click year */ + StringBuffer currentBuffer = new StringBuffer(); - currentBuffer.append('[') + currentBuffer.append("xpath=(") + .append(selectorBuffer) + .append(")[") .append(i + 1) .append(']'); student0.click(currentBuffer.toString()); functionalUtil.idle(student0); + + /* it should be visible somewhere */ + int j = 0; - if(student0.isTextPresent(CONCURRENT_CLEAR_CACHE_BLOG_POST2_TITLE)){ - foundTitleInYear = true; - break; + for(String currentTitle: titles){ + if(student0.isTextPresent(currentTitle)){ + foundTitlesInMonth[j] = true; + break; + } + + j++; } } - Assert.assertTrue(foundTitleInYear); + Assert.assertFalse(ArrayUtils.contains(foundTitlesInYear, false)); /* logout */ Assert.assertTrue(functionalUtil.logout(tutor0)); @@ -338,7 +372,6 @@ public class FunctionalBlogTest { /* for syncing threads */ final ReentrantLock lock = new ReentrantLock(); - final ReentrantLock subroutineLock = new ReentrantLock(); final Condition cond = lock.newCondition(); final boolean[] doSignal = new boolean[1]; doSignal[0] = false; diff --git a/src/test/java/org/olat/group/FunctionalGroupTest.java b/src/test/java/org/olat/group/FunctionalGroupTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5ef63f91feb56281a27992beb65b8da5f597f6b8 --- /dev/null +++ b/src/test/java/org/olat/group/FunctionalGroupTest.java @@ -0,0 +1,148 @@ +/** + * <a href="http://www.openolat.org"> + * OpenOLAT - Online Learning and Training</a><br> + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); <br> + * you may not use this file except in compliance with the License.<br> + * You may obtain a copy of the License at the + * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a> + * <p> + * Unless required by applicable law or agreed to in writing,<br> + * software distributed under the License is distributed on an "AS IS" BASIS, <br> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> + * See the License for the specific language governing permissions and <br> + * limitations under the License. + * <p> + * Initial code contributed and copyrighted by<br> + * frentix GmbH, http://www.frentix.com + * <p> + */ +package org.olat.group; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.drone.api.annotation.Drone; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.olat.test.ArquillianDeployments; +import org.olat.user.restapi.UserVO; +import org.olat.util.FunctionalGroupsSiteUtil; +import org.olat.util.FunctionalGroupsSiteUtil.GroupOptions; +import org.olat.util.FunctionalUtil; +import org.olat.util.FunctionalVOUtil; +import org.olat.util.browser.Student1; +import org.olat.util.browser.Tutor1; + +import com.thoughtworks.selenium.DefaultSelenium; + +/** + * + * @author jkraehemann, joel.kraehemann@frentix.com, frentix.com + */ +@Ignore +@RunWith(Arquillian.class) +public class FunctionalGroupTest { + + public final static String CREATE_GROUP_NAME = "club of dead poets"; + public final static String CREATE_GROUP_DESCRIPTION = "If you feel disappointed by the attitude and stance on free software of certain companies you're welcome."; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return ArquillianDeployments.createDeployment(); + } + + @Drone + DefaultSelenium browser; + + @ArquillianResource + URL deploymentUrl; + + static FunctionalUtil functionalUtil; + static FunctionalGroupsSiteUtil functionalGroupsSiteUtil; + static FunctionalVOUtil functionalVOUtil; + + static boolean initialized = false; + + @Before + public void setup() throws IOException, URISyntaxException{ + if(!initialized){ + functionalUtil = new FunctionalUtil(); + functionalUtil.setDeploymentUrl(deploymentUrl.toString()); + + functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword()); + + initialized = true; + } + } + + @Test + @RunAsClient + public void checkCreate(@Drone @Tutor1 DefaultSelenium tutor0) throws IOException, URISyntaxException{ + /* + * Setup + */ + /* create author */ + int tutorCount = 1; + + final UserVO[] tutors = new UserVO[tutorCount]; + functionalVOUtil.createTestUsers(deploymentUrl, tutorCount).toArray(tutors); + + /* + * create content + */ + Assert.assertTrue(functionalUtil.login(tutor0, tutors[0].getLogin(), tutors[0].getPassword(), true)); + + /* create group */ + Assert.assertTrue(functionalGroupsSiteUtil.createGroup(tutor0, + CREATE_GROUP_NAME, CREATE_GROUP_DESCRIPTION, + 3, + new GroupOptions[]{ + GroupOptions.WAITING_LIST + } + )); + + /* + * verify + */ + } + + @Test + @RunAsClient + public void checkConfigureTools(){ + + } + + @Test + @RunAsClient + public void checkConfigureMembers(){ + + } + + @Test + @RunAsClient + public void checkConfigureAccessControl(){ + + } + + @Test + @RunAsClient + public void checkBookGroup(){ + + } + + @Test + @RunAsClient + public void checkAddUser(){ + + } +} diff --git a/src/test/java/org/olat/util/FunctionalAdministrationSiteUtil.java b/src/test/java/org/olat/util/FunctionalAdministrationSiteUtil.java index 59cd38099aedb00f73e8a99d3a8b227390ee7ae9..fcc0e1cd3dfe291fc3a1a6ea93205fedfcd165d1 100644 --- a/src/test/java/org/olat/util/FunctionalAdministrationSiteUtil.java +++ b/src/test/java/org/olat/util/FunctionalAdministrationSiteUtil.java @@ -19,7 +19,6 @@ */ package org.olat.util; -import org.junit.Assert; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.util.FunctionalUtil.OlatSite; @@ -168,7 +167,7 @@ public class FunctionalAdministrationSiteUtil { .append(functionalUtil.getTreeLevel1Css()) .append("')]"); }else if(action instanceof SystemConfigurationAction){ - /* check if collapsed */ + /* check if not collapsed */ selectorBuffer = new StringBuffer(); selectorBuffer.append("xpath=//li[contains(@class, '") @@ -191,7 +190,7 @@ public class FunctionalAdministrationSiteUtil { .append(functionalUtil.getTreeLevel2Css()) .append("')]"); }else if(action instanceof SystemMaintenanceAction){ - /* check if collapsed */ + /* check if not collapsed */ selectorBuffer = new StringBuffer(); selectorBuffer.append("xpath=//li[contains(@class, '") @@ -212,7 +211,7 @@ public class FunctionalAdministrationSiteUtil { .append(functionalUtil.getTreeLevel2Css()) .append("')]"); }else if(action instanceof CustomizingAction){ - /* check if collapsed */ + /* check if not collapsed */ selectorBuffer = new StringBuffer(); selectorBuffer.append("xpath=//li[contains(@class, '") @@ -267,37 +266,44 @@ public class FunctionalAdministrationSiteUtil { /* click show all*/ StringBuffer selectorBuffer = new StringBuffer(); - selectorBuffer.append("xpath=//a[contains(@class, '") + selectorBuffer.append("xpath=//div[contains(@class, '") .append(functionalUtil.getTableAllCss()) - .append("')]"); + .append("')]//a"); if(browser.isElementPresent(selectorBuffer.toString())){ browser.click(selectorBuffer.toString()); } - boolean success = true; - /* clear appropriate cache */ for(String currentKey: keys){ functionalUtil.idle(browser); + /* click clear */ selectorBuffer = new StringBuffer(); - selectorBuffer.append("xpath=//table//tr//td[contains(@text, '") + selectorBuffer.append("//table//tr//td[text()='") .append(currentKey) - .append("\\n") - .append("')]"); + .append("']"); - if(browser.isElementPresent(selectorBuffer.toString())){ - selectorBuffer.append("/../td[last()]//a"); + functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString()); + selectorBuffer.append("/../td[last()]//a"); - browser.click(selectorBuffer.toString()); - }else{ - success = false; - } + browser.click(selectorBuffer.toString()); + + /* confirm */ + selectorBuffer = new StringBuffer(); + + selectorBuffer.append("xpath=(//div[contains(@class, '") + .append(functionalUtil.getWindowCss()) + .append("')]//a[contains(@class, '") + .append(functionalUtil.getButtonCss()) + .append("')])[last()]"); + + functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString()); + browser.click(selectorBuffer.toString()); } - return(success); + return(true); } public FunctionalUtil getFunctionalUtil() { diff --git a/src/test/java/org/olat/util/FunctionalCourseUtil.java b/src/test/java/org/olat/util/FunctionalCourseUtil.java index d7131575f8b65a15be97ad0ed7c71296908fbdab..9eadeeabf23c1ebc11a7b8895fd57126fb70a4e5 100644 --- a/src/test/java/org/olat/util/FunctionalCourseUtil.java +++ b/src/test/java/org/olat/util/FunctionalCourseUtil.java @@ -1659,8 +1659,7 @@ public class FunctionalCourseUtil { browser.click(selectorBuffer.toString()); functionalUtil.waitForPageToLoad(browser); - - functionalUtil.idle(browser); + /* */ return(functionalRepositorySiteUtil.fillInRepositoryEntryPopup(browser, title, description)); } diff --git a/src/test/java/org/olat/util/FunctionalGroupsSiteUtil.java b/src/test/java/org/olat/util/FunctionalGroupsSiteUtil.java index 8aa0cfc676516c522b0867f5992825ad44e9d92e..ce5f53e1ad5de31d6b078cf141d3ed883027adaf 100644 --- a/src/test/java/org/olat/util/FunctionalGroupsSiteUtil.java +++ b/src/test/java/org/olat/util/FunctionalGroupsSiteUtil.java @@ -21,6 +21,8 @@ package org.olat.util; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; +import org.olat.util.FunctionalAdministrationSiteUtil.AdministrationSiteAction; +import org.olat.util.FunctionalUtil.OlatSite; import com.thoughtworks.selenium.Selenium; @@ -32,9 +34,35 @@ public class FunctionalGroupsSiteUtil { private final static OLog log = Tracing.createLoggerFor(FunctionalGroupsSiteUtil.class); public enum GroupsSiteAction { - MY_GROUPS, - PUBLISHED_GROUPS, - GROUPS_ADMINISTRATION + MY_GROUPS("o_sel_MyGroups"), + PUBLISHED_GROUPS("o_sel_OpenGroups"), + GROUPS_ADMINISTRATION("o_sel_AdminGroups"); + + private String actionCss; + + GroupsSiteAction(String actionCss){ + setActionCss(actionCss); + } + + public String getActionCss() { + return actionCss; + } + + public void setActionCss(String actionCss) { + this.actionCss = actionCss; + } + } + + public enum MyGroupsTabs { + BOOKMARK, + ALL_GROUPS, + COACH, + SEARCH, + } + + public enum GroupOptions { + WAITING_LIST, + AUTO_MOVING_UP, } private FunctionalUtil functionalUtil; @@ -51,11 +79,64 @@ public class FunctionalGroupsSiteUtil { * @return true on success otherwise false */ public boolean openActionByMenuTree(Selenium browser, Object action){ - //TODO:JK: implement me + functionalUtil.idle(browser); - return(false); + StringBuffer selectorBuffer; + + if(action instanceof GroupsSiteAction){ + selectorBuffer = new StringBuffer(); + + selectorBuffer.append("xpath=//li[contains(@class, '") + .append(((GroupsSiteAction) action).getActionCss()) + .append("')]//a[contains(@class, '") + .append(functionalUtil.getTreeLevel1Css()) + .append("')]");; + }else{ + return(false); + } + + functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString()); + browser.click(selectorBuffer.toString()); + + return(true); } + public boolean createGroup(Selenium browser, String groupName, String groupDescription, int maxParticipants, GroupOptions[] options){ + if(!functionalUtil.openSite(browser, OlatSite.GROUPS)){ + return(false); + } + + if(!openActionByMenuTree(browser, GroupsSiteAction.MY_GROUPS)){ + return(false); + } + + if(!functionalUtil.openContentSegment(browser, MyGroupsTabs.ALL_GROUPS.ordinal())){ + return(false); + } + + functionalUtil.idle(browser); + + /* click create */ + + + /* fill in group name */ + + + /* fill in group description */ + + + /* fill in max participants */ + + + /* set options */ + + + /* click finish */ + + + return(true); + } + public FunctionalUtil getFunctionalUtil() { return functionalUtil; } diff --git a/src/test/java/org/olat/util/FunctionalHtmlUtil.java b/src/test/java/org/olat/util/FunctionalHtmlUtil.java index b5b99a93509149fbc4bd49300140d5be60cc1b55..fe08d3d957213b8da926e05e7b6c2fd60fffd25e 100644 --- a/src/test/java/org/olat/util/FunctionalHtmlUtil.java +++ b/src/test/java/org/olat/util/FunctionalHtmlUtil.java @@ -21,6 +21,7 @@ package org.olat.util; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; +import org.olat.core.util.filter.FilterFactory; /** * @@ -31,11 +32,14 @@ public class FunctionalHtmlUtil { /** * Strips all markup of specified string. + * This method is depracted and shouldn't be used in newly written code. + * Use removeMarkup instead. * * @param html * @param insertNewlines * @return */ + @Deprecated public String stripTags(String html, boolean insertNewlines){ if(html.indexOf("<body") != -1){ html = html.substring(html.indexOf('>', html.indexOf("<body")) + 1, html.indexOf("</body")); @@ -63,17 +67,26 @@ public class FunctionalHtmlUtil { } } - prevLineLastChar = currentText.charAt(currentText.length() - 1); + if(!currentText.isEmpty()){ + prevLineLastChar = currentText.charAt(currentText.length() - 1); + } } - offset = html.indexOf('>', nextOffset) + 1; + offset = html.indexOf('>', nextOffset); + + if(offset != -1){ + offset += 1; + } } String currentText = html.substring(offset); if(!currentText.matches("^[\\s]+$")){ textBuffer.append(currentText); - prevLineLastChar = currentText.charAt(currentText.length() - 1); + + if(!currentText.isEmpty()){ + prevLineLastChar = currentText.charAt(currentText.length() - 1); + } } if(prevLineLastChar != '\n'){ @@ -82,4 +95,8 @@ public class FunctionalHtmlUtil { return(textBuffer.toString()); } + + public String removeMarkup(String html){ + return(FilterFactory.getHtmlTagsFilter().filter(html)); + } } diff --git a/src/test/java/org/olat/util/FunctionalUtil.java b/src/test/java/org/olat/util/FunctionalUtil.java index 5aeb1193f0712c680832fa25921b8c08f20e75a8..e61281012929cf9f8dee6a9d9fd1c590734ce16d 100644 --- a/src/test/java/org/olat/util/FunctionalUtil.java +++ b/src/test/java/org/olat/util/FunctionalUtil.java @@ -95,7 +95,6 @@ public class FunctionalUtil { HOME, GROUPS, LEARNING_RESOURCES, - GROUP_ADMINISTRATION, USER_MANAGEMENT, ADMINISTRATION, } @@ -116,6 +115,10 @@ public class FunctionalUtil { public final static String CONTENT_CSS = "b_main"; public final static String CONTENT_TAB_CSS = "b_item_"; public final static String ACTIVE_CONTENT_TAB_CSS = "b_active"; + public final static String CONTENT_SEGMENT_CONTAINER_CSS = "b_segments_container"; + public final static String CONTENT_SEGMENT_CSS = "b_segment"; + + public final static String WINDOW_CSS = "b_window"; public final static String WIZARD_CSS = "b_wizard"; public final static String WIZARD_NEXT_CSS = "b_wizard_button_next"; @@ -172,9 +175,13 @@ public class FunctionalUtil { private String contentCss; private String contentTabCss; private String activeContentTabCss; + private String contentSegmentContainerCss; + private String contentSegmentCss; private String formSaveXPath; + private String windowCss; + private String wizardCss; private String wizardNextCss; private String wizardFinishCss; @@ -249,9 +256,13 @@ public class FunctionalUtil { contentCss = CONTENT_CSS; contentTabCss = CONTENT_TAB_CSS; activeContentTabCss = ACTIVE_CONTENT_TAB_CSS; + contentSegmentContainerCss = CONTENT_SEGMENT_CONTAINER_CSS; + contentSegmentCss = CONTENT_SEGMENT_CSS; formSaveXPath = FORM_SAVE_XPATH; + windowCss = WINDOW_CSS; + wizardCss = WIZARD_CSS; wizardNextCss = WIZARD_NEXT_CSS; wizardFinishCss = WIZARD_FINISH_CSS; @@ -644,11 +655,6 @@ public class FunctionalUtil { selectedCss = getOlatSiteLearningResourcesCss(); break; } - case GROUP_ADMINISTRATION: - { - selectedCss = getOlatSiteAdministrationCss(); - break; - } case USER_MANAGEMENT: { selectedCss = getOlatSiteUserManagementCss(); @@ -756,11 +762,6 @@ public class FunctionalUtil { retval = functionalUserManagementSiteUtil.openActionByMenuTree(browser, UserManagementSiteAction.USER_SEARCH); } break; - case GROUP_ADMINISTRATION: - { - //FIXME:JK: need to be implemented - } - break; case ADMINISTRATION: { retval = functionalAdministrationSiteUtil.openActionByMenuTree(browser, AdministrationSiteAction.INFORMATION); @@ -943,6 +944,32 @@ public class FunctionalUtil { return(true); } + /** + * Opens a segment at the specified segmentIndex. + * + * @param browser + * @param segmentIndex + * @return + */ + public boolean openContentSegment(Selenium browser, int segmentIndex){ + idle(browser); + + StringBuffer selectorBuffer = new StringBuffer(); + + selectorBuffer.append("xpath=//div[contains(@class, '") + .append(getContentSegmentContainerCss()) + .append("')]//ul//(li[contains(@class, '") + .append(getContentSegmentCss()) + .append("')])[") + .append(segmentIndex) + .append("]"); + + waitForPageToLoadElement(browser, selectorBuffer.toString()); + browser.click(selectorBuffer.toString()); + + return(true); + } + /** * Save the form at the position formIndex within content element. * @@ -1484,6 +1511,22 @@ public class FunctionalUtil { this.activeContentTabCss = activeContentTabCss; } + public String getContentSegmentContainerCss() { + return contentSegmentContainerCss; + } + + public void setContentSegmentContainerCss(String contentSegmentContainerCss) { + this.contentSegmentContainerCss = contentSegmentContainerCss; + } + + public String getContentSegmentCss() { + return contentSegmentCss; + } + + public void setContentSegmentCss(String contentSegmentCss) { + this.contentSegmentCss = contentSegmentCss; + } + public String getFormSaveXPath() { return formSaveXPath; } @@ -1492,6 +1535,14 @@ public class FunctionalUtil { this.formSaveXPath = formSaveXPath; } + public String getWindowCss() { + return windowCss; + } + + public void setWindowCss(String windowCss) { + this.windowCss = windowCss; + } + public String getWizardCss() { return wizardCss; } diff --git a/src/test/java/org/olat/util/FunctionalVOUtil.java b/src/test/java/org/olat/util/FunctionalVOUtil.java index b142e409eeceeff6a83d1c25e0a1488c46a6da51..5546bbf94b63bb192e55a4f4f78f5bffbc198a06 100644 --- a/src/test/java/org/olat/util/FunctionalVOUtil.java +++ b/src/test/java/org/olat/util/FunctionalVOUtil.java @@ -45,6 +45,7 @@ import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.util.EntityUtils; import org.junit.Assert; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; @@ -135,7 +136,9 @@ public class FunctionalVOUtil { UserVO current = restConnection.parse(body, UserVO.class); Assert.assertNotNull(current); - user.add(vo); + current.setPassword(vo.getPassword()); + + user.add(current); } restConnection.shutdown(); @@ -150,27 +153,32 @@ public class FunctionalVOUtil { /* make a tutor */ RestConnection restConnection = new RestConnection(deploymentUrl); - restConnection.login(getUsername(), getPassword()); + Assert.assertTrue(restConnection.login(getUsername(), getPassword())); for(UserVO currentUser: user){ /* retrieve roles */ - URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("/users/" + currentUser.getKey() + "/roles").build(); - HttpGet getMethod = restConnection.createGet(request, MediaType.APPLICATION_JSON, true); - HttpResponse response = restConnection.execute(getMethod); + URI request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("users/" + currentUser.getKey() + "/roles").build(); + HttpGet method = restConnection.createGet(request, MediaType.APPLICATION_JSON, true); + HttpResponse response = restConnection.execute(method); assertEquals(200, response.getStatusLine().getStatusCode()); - RolesVO roles = restConnection.parse(response, RolesVO.class); + InputStream body = response.getEntity().getContent(); + RolesVO roles = restConnection.parse(body, RolesVO.class); /* send appropriate role */ roles.setAuthor(true); roles.setUserManager(true); - request = UriBuilder.fromUri(deploymentUrl.toURI()).path("/users/" + currentUser.getKey() + "/roles").build(); + request = UriBuilder.fromUri(deploymentUrl.toURI()).path("restapi").path("users/" + currentUser.getKey() + "/roles").build(); HttpPost postMethod = restConnection.createPost(request, MediaType.APPLICATION_JSON, true); restConnection.addJsonEntity(postMethod, roles); response = restConnection.execute(postMethod); assertEquals(200, response.getStatusLine().getStatusCode()); + + EntityUtils.consume(response.getEntity()); } + restConnection.shutdown(); + return(user); } @@ -187,7 +195,6 @@ public class FunctionalVOUtil { * @throws IOException */ public CourseVO importCourse(URL deploymentUrl, String path, String filename, String resourcename, String displayname) throws URISyntaxException, IOException{ - //TODO:JK: may be replace this code because the course will just be deployed and not imported URL cpUrl = FunctionalVOUtil.class.getResource(path); assertNotNull(cpUrl); File cp = new File(cpUrl.toURI()); @@ -345,6 +352,34 @@ public class FunctionalVOUtil { return(vo); } + /** + * Adds owner as owner to repoEntry. + * + * @param deploymentUrl + * @param repoEntry + * @param owner + * @throws URISyntaxException + * @throws IOException + */ + public void addOwnerToRepositoryEntry(URL deploymentUrl, RepositoryEntryVO repoEntry, UserVO owner) throws IOException, URISyntaxException{ + //add an owner + RestConnection restConnection = new RestConnection(deploymentUrl); + assertTrue(restConnection.login(getUsername(), getPassword())); + + URI request = UriBuilder.fromUri(deploymentUrl.toURI()) + .path("restapi") + .path("repo/entries").path(repoEntry.getKey().toString()) + .path("owners").path(owner.getKey().toString()) + .build(); + + HttpPut method = restConnection.createPut(request, MediaType.APPLICATION_JSON, true); + HttpResponse response = restConnection.execute(method); + assertEquals(200, response.getStatusLine().getStatusCode()); + EntityUtils.consume(response.getEntity()); + + restConnection.shutdown(); + } + public String getUsername() { return username; }