Skip to content
Snippets Groups Projects
Commit 9de7e854 authored by srosse's avatar srosse
Browse files

OO-1068: clean up test package after oo10 refactoring

parent 49cf01ad
No related branches found
No related tags found
No related merge requests found
Showing
with 31 additions and 1868 deletions
......@@ -34,18 +34,11 @@ public void testPlainText() {...
2: You like to test code which includes managers/modules that are spring beans you can use this setup:
-----------------------------------
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"/org/olat/core/test/_spring/yourSpringContext.xml"})
public class YourTestClass {...
public class YourTestClass extends OlatTestCase {...
-------------------------------------
The Springcontext gets loaded and you can use @Autowire or access directly the "applicationContext" var and do you testing
3: If you need more stuff from the framework like Coordinator or database access in your code you can use the OlatcoreTestCaseWithMocking which
already has some mocked stuff inside (Coordinator.getEventBus() calls) or create your own mocks based on the example. The library we use for mocking is
Mockito (http://mockito.org/)
When you run all tests in a suite, the spring context gets cached and only loaded once for better performance. But if you load the same spring beans twice,
3: When you run all tests in a suite, the spring context gets cached and only loaded once for better performance. But if you load the same spring beans twice,
the beans will not get overwritten and instead they get created again and a new instance gets assigned for e.g. a singleton.
\ No newline at end of file
File deleted
File deleted
File deleted
/**
* <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.course.nodes.feed;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Arrays;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.lang.ArrayUtils;
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.Test;
import org.junit.runner.RunWith;
import org.olat.restapi.support.vo.CourseVO;
import org.olat.restapi.support.vo.RepositoryEntryVO;
import org.olat.test.ArquillianDeployments;
import org.olat.user.restapi.UserVO;
import org.olat.util.FunctionalAdministrationSiteUtil;
import org.olat.util.FunctionalCourseUtil;
import org.olat.util.FunctionalCourseUtil.BlogEdit;
import org.olat.util.FunctionalCourseUtil.CourseNodeAlias;
import org.olat.util.FunctionalRepositorySiteUtil;
import org.olat.util.FunctionalUtil;
import org.olat.util.FunctionalUtil.WaitLimitAttribute;
import org.olat.util.FunctionalVOUtil;
import org.olat.util.browser.Student1;
import org.olat.util.browser.Student2;
import org.olat.util.browser.Tutor1;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
/**
*
* @author jkraehemann, joel.kraehemann@frentix.com, frentix.com
*/
@RunWith(Arquillian.class)
public class FunctionalBlogTest {
public final static String BLOG_SHORT_TITLE = "blog";
public final static String BLOG_LONG_TITLE = "test blog";
public final static String BLOG_DESCRIPTION = "blog";
public final static String BLOG_FEED = "http://blogs.frentix.com/blogs/frentix/rss.xml";
public final static String DELETE_BLOG_SHORT_TITLE = "blog";
public final static String DELETE_BLOG_LONG_TITLE = "blog for removal";
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_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";
public final static String CONCURRENT_CLEAR_CACHE_BLOG_POST1_TITLE = "Conditional locks with Java";
public final static String CONCURRENT_CLEAR_CACHE_BLOG_POST1_DESCRIPTION = "Advanced thread safety in Java.";
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>\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";
public final static String CONCURRENT_RW_BLOG_DESCRIPTION = "During open blog cache will be cleared";
public final static String CONCURRENT_RW_BLOG_CONTENT = "New openolat release is outstanding.";
public final static String CONCURRENT_RW_BLOG_NEW_CONTENT = "New openolat release is outstanding and is comming soon.";
public final static String CONCURRENT_TUTORS_BLOG_SHORT_TITLE = "blog";
public final static String CONCURRENT_TUTORS_BLOG_LONG_TITLE = "test blog";
public final static String CONCURRENT_TUTORS_BLOG_DESCRIPTION = "The blog will be opened and saved while cache is clearing";
public final static String CONCURRENT_TUTORS_BLOG_CONTENT = "Race conditions may end up in a dead lock";
public final static String CONCURRENT_TUTORS_BLOG_POST1_TITLE = "race conditions";
public final static String CONCURRENT_TUTORS_BLOG_POST1_DESCRIPTION = "the causes of race conditions";
public final static String CONCURRENT_TUTORS_BLOG_POST1_CONTENT = "In multi-threaded environments you may want perform some kind of syncing. Inproper syncing ends up in a race condition eg. you read a value of a field before it was written.";
public final static String CONCURRENT_TUTORS_BLOG_POST2_TITLE = "dead locks";
public final static String CONCURRENT_TUTORS_BLOG_POST2_DESCRIPTION = "the causes of dead locks";
public final static String CONCURRENT_TUTORS_BLOG_POST2_CONTENT = "Assumed you have more than one thread you probably want to lock some resources, other threads or even the entire process. Therefore exist mutices or in java you have additionally the keyword synchronized. Dead locks occure during inproper syncing or during a race condition. The system remains in a unusable state.";
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ArquillianDeployments.createDeployment();
}
@Drone
DefaultSelenium browser;
@ArquillianResource
URL deploymentUrl;
static FunctionalUtil functionalUtil;
static FunctionalRepositorySiteUtil functionalRepositorySiteUtil;
static FunctionalCourseUtil functionalCourseUtil;
static FunctionalAdministrationSiteUtil functionalAdministrationSiteUtil;
static FunctionalVOUtil functionalVOUtil;
static boolean initialized = false;
@Before
public void setup() throws IOException, URISyntaxException{
if(!initialized){
functionalUtil = new FunctionalUtil();
functionalUtil.setDeploymentUrl(deploymentUrl.toString());
functionalRepositorySiteUtil = functionalUtil.getFunctionalRepositorySiteUtil();
functionalCourseUtil = functionalRepositorySiteUtil.getFunctionalCourseUtil();
functionalAdministrationSiteUtil = functionalUtil.getFunctionalAdministrationSiteUtil();
functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword());
initialized = true;
}
}
@Test
@RunAsClient
public void checkConcurrentClearCache(@Drone @Tutor1 DefaultSelenium tutor0, @Drone @Student1 DefaultSelenium student0) throws IOException, URISyntaxException{
/*
* Setup
*/
/* create author */
int tutorCount = 1;
final UserVO[] tutors = new UserVO[tutorCount];
functionalVOUtil.createTestAuthors(deploymentUrl, tutorCount).toArray(tutors);
/* create user */
int userCount = 1;
final UserVO[] students = new UserVO[userCount];
functionalVOUtil.createTestUsers(deploymentUrl, userCount).toArray(students);
/* create blog and set tutor as owner */
RepositoryEntryVO repoEntry = functionalVOUtil.importBlog(deploymentUrl,
CONCURRENT_CLEAR_CACHE_BLOG_PATH,
CONCURRENT_CLEAR_CACHE_BLOG_FILE_NAME, CONCURRENT_CLEAR_CACHE_BLOG_RESOURCE_NAME, CONCURRENT_CLEAR_CACHE_BLOG_DISPLAY_NAME);
functionalVOUtil.addOwnerToRepositoryEntry(deploymentUrl, repoEntry, tutors[0]);
/*
* Create content and visit it.
*/
/* tutor creates a new post */
Assert.assertTrue(functionalUtil.login(tutor0, tutors[0].getLogin(), tutors[0].getPassword(), true));
Assert.assertTrue(functionalCourseUtil.openBlog(tutor0, repoEntry.getKey()));
Assert.assertTrue(functionalCourseUtil.editBlogEntry(tutor0,
CONCURRENT_CLEAR_CACHE_BLOG_POST1_TITLE, CONCURRENT_CLEAR_CACHE_BLOG_POST1_DESCRIPTION, CONCURRENT_CLEAR_CACHE_BLOG_POST1_CONTENT,
-1, null));
/* student visits content */
Assert.assertTrue(functionalUtil.login(student0, students[0].getLogin(), students[0].getPassword(), true));
Assert.assertTrue(functionalCourseUtil.openBlog(student0, repoEntry.getKey()));
/*
* Clear cache and verify content.
*/
/* admin clears cache */
Assert.assertTrue(functionalUtil.login(browser, functionalUtil.getUsername(), functionalUtil.getPassword(), true));
Assert.assertTrue(functionalAdministrationSiteUtil.clearCache(browser,
new String[]{
"FeedManager@feed",
"Path@feed"
}
));
Assert.assertTrue(functionalUtil.logout(browser));
/* tutor adds a new post */
//Assert.assertTrue(functionalCourseUtil.backBlogEntry(tutor0));
Assert.assertTrue(functionalCourseUtil.editBlogEntry(tutor0,
CONCURRENT_CLEAR_CACHE_BLOG_POST2_TITLE, CONCURRENT_CLEAR_CACHE_BLOG_POST2_DESCRIPTION, CONCURRENT_CLEAR_CACHE_BLOG_POST2_CONTENT,
-1, null));
/* 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("//ul[contains(@class, '")
.append(functionalCourseUtil.getBlogMonthCss())
.append("')]//li//a");
int iStop = student0.getXpathCount(selectorBuffer.toString()).intValue();
boolean[] foundTitlesInMonth = new boolean[titles.length];
Arrays.fill(foundTitlesInMonth, false);
for(int i = 0; i < iStop; i++){
functionalUtil.idle(student0);
/* click month */
StringBuffer currentBuffer = new StringBuffer();
currentBuffer.append("xpath=(")
.append(selectorBuffer)
.append(")[")
.append(i + 1)
.append(']');
functionalUtil.waitForPageToLoadElement(student0, currentBuffer.toString());
student0.click(currentBuffer.toString());
functionalUtil.idle(student0);
/* it should be visible somewhere */
int j = 0;
for(String currentTitle: titles){
if(student0.isTextPresent(currentTitle)){
foundTitlesInMonth[j] = true;
}
j++;
}
}
Assert.assertFalse(ArrayUtils.contains(foundTitlesInMonth, false));
/* student verifies title - year */
functionalUtil.idle(student0);
selectorBuffer = new StringBuffer();
selectorBuffer.append("//div//a[contains(@class, '")
.append(functionalCourseUtil.getBlogYearCss())
.append("')]");
iStop = student0.getXpathCount(selectorBuffer.toString()).intValue();
boolean[] foundTitlesInYear = new boolean[titles.length];
Arrays.fill(foundTitlesInYear, false);
for(int i = 0; i < iStop; i++){
functionalUtil.idle(student0);
/* click year */
StringBuffer currentBuffer = new StringBuffer();
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;
for(String currentTitle: titles){
if(student0.isTextPresent(currentTitle)){
foundTitlesInYear[j] = true;
}
j++;
}
}
Assert.assertFalse(ArrayUtils.contains(foundTitlesInYear, false));
/* logout */
Assert.assertTrue(functionalUtil.logout(tutor0));
Assert.assertTrue(functionalUtil.logout(student0));
}
@Test
@RunAsClient
public void checkConcurrentRW(@Drone @Student1 DefaultSelenium student0, @Drone @Student2 DefaultSelenium student1) throws IOException, URISyntaxException, InterruptedException{
/*
* Setup
*/
int userCount = 2;
final UserVO[] users = new UserVO[userCount];
functionalVOUtil.createTestUsers(deploymentUrl, userCount).toArray(users);
final CourseVO course = functionalVOUtil.importEmptyCourse(deploymentUrl);
/* create blog */
Assert.assertTrue(functionalUtil.login(browser, functionalUtil.getUsername(), functionalUtil.getPassword(), true));
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));
Assert.assertTrue(functionalCourseUtil.publishEntireCourse(browser, null, null));
/* create content */
Assert.assertNotNull(functionalCourseUtil.open(browser, course.getRepoEntryKey(), 0));
Assert.assertTrue(functionalCourseUtil.createBlogEntry(browser, course.getRepoEntryKey(), 0,
CONCURRENT_RW_BLOG_SHORT_TITLE, CONCURRENT_RW_BLOG_DESCRIPTION, CONCURRENT_RW_BLOG_CONTENT));
/*
* do concurrent access read
*/
final Selenium[] student = new Selenium[userCount];
student[0] = student0;
student[1] = student1;
final boolean[] success = new boolean[userCount];
Arrays.fill(success, true);
/* for syncing threads */
final ReentrantLock lock = new ReentrantLock();
final Condition cond = lock.newCondition();
final boolean[] doSignal = new boolean[1];
doSignal[0] = false;
final boolean[] finished = new boolean[userCount];
Arrays.fill(finished, false);
/* students log in an visit blog */
for(int i = 0; i < userCount; i++){
final int index = i;
Thread thread = new Thread(new Runnable(){
int i;
{
i = index;
}
@Override
public void run() {
try{
functionalUtil.login(student[i], users[i].getLogin(), users[i].getPassword(), true);
functionalCourseUtil.openBlogWithoutBusinessPath(student[i], course.getRepoEntryKey(), 0);
functionalCourseUtil.openBlogEntry(student[i], 0);
}catch(Exception e){
success[i] = false;
}finally{
finished[i] = true;
lock.lock();
if(doSignal[0]){
cond.signal();
}
lock.unlock();
}
}
});
thread.start();
}
/* wait for browsers to be ready */
lock.lock();
doSignal[0] = true;
try{
while(ArrayUtils.contains(finished, false)){
cond.await();
}
}finally{
lock.unlock();
}
/* edit blog as author */
Assert.assertTrue(functionalCourseUtil.editBlogEntry(browser, course.getRepoEntryKey(), 0,
null, null, CONCURRENT_RW_BLOG_NEW_CONTENT, 0, new BlogEdit[]{BlogEdit.CONTENT}));
/* open entry by users */
Arrays.fill(finished, false);
doSignal[0] = false;
for(int i = 0; i < userCount; i++){
final int index = i;
Thread thread = new Thread(new Runnable(){
int i;
{
i = index;
}
@Override
public void run() {
try{
functionalCourseUtil.backBlogEntry(student[i]);
functionalCourseUtil.openBlogEntry(student[i], 0);
functionalUtil.waitForPageToLoadContent(student[i], null, CONCURRENT_RW_BLOG_NEW_CONTENT, WaitLimitAttribute.VERY_SAVE, null, true);
functionalUtil.logout(student[i]);
}catch(Exception e){
success[i] = false;
}finally{
finished[i] = true;
lock.lock();
if(doSignal[0]){
cond.signal();
}
lock.unlock();
}
}
});
thread.start();
}
/* wait for browsers to be logged out */
lock.lock();
doSignal[0] = true;
try{
while(ArrayUtils.contains(finished, false)){
cond.await();
}
}finally{
lock.unlock();
}
Assert.assertFalse(ArrayUtils.contains(success, false));
Assert.assertTrue(functionalUtil.logout(browser));
}
}
File deleted
<html>
<head>
<title>A comprehensive guide to free software development with free tools</title>
</head>
<body>
<h1>Welcome to free software development course</h1>
<p>This course is intended to give you a quick overview to free software development using free tools. Currently only C Programming language is covered and may be extended in future versions of this course.</p>
<h2>Prerequisites</h2>
<p>In addition to start programming you may want to download and install common tools for c development. We will take extensive use of `gcc`. To ease programming I recommend you `make` and `gdb`, too. Use your editor of choice, preferably with syntax highlighting for the C language. Personally I prefer `emacs`.</p>
<p>Be part of the fun!</p>
</body>
</html>
TODO:
Write proper unit/integration tests for these statistics tests, see
http://static.springsource.org/spring/docs/3.0.x/reference/testing.html
\ No newline at end of file
/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <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>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <hr>
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* This file has been modified by the OpenOLAT community. Changes are licensed
* under the Apache 2.0 license as the original file.
*/
package org.olat.course.statistic.weekly;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class TestWeeklyStatisticManager_fillGaps {
private WeeklyStatisticManager manager_;
@Before
public void setUp() throws Exception {
manager_ = new WeeklyStatisticManager();
}
private void runTest(List<String> input, List<String> expectedOutput) throws Exception {
List<String> resultingTestset = manager_.fillGapsInColumnHeaders(input);
assertListEquals(expectedOutput, resultingTestset);
}
@Test
public void testNull() throws Exception {
Assert.assertNull(manager_.fillGapsInColumnHeaders(null));
}
@Test
public void testOne() throws Exception {
for(int i=0; i<50; i++) {
String s;
if (i<10) {
s = "2010-0"+i;
} else {
s = "2010-"+i;
}
List<String> resultingTestset = manager_.fillGapsInColumnHeaders(createList(s));
Assert.assertNull(resultingTestset);
}
}
@Test
public void testSimple() throws Exception {
runTest(
createList("2010-01", "2010-02", "2010-03"),
createList("2010-01", "2010-02", "2010-03"));
}
@Test
public void testYearChange() throws Exception {
runTest(
createList("2009-50", "2010-01", "2010-02", "2010-03"),
createList("2009-50", "2009-51", "2009-52", "2009-53", "2010-01", "2010-02", "2010-03"));
}
@Test
public void testAllYearChanges() throws Exception {
for(int i=2000; i<2200; i++) {
List<String> input = createList(i+"-50", (i+1)+"-03");
List<String> output = manager_.fillGapsInColumnHeaders(input);
Assert.assertNotNull(output);
List<String> outputVariant1 = createList(i+"-50", i+"-51", i+"-52", (i+1)+"-01", (i+1)+"-02", (i+1)+"-03");
List<String> outputVariant2 = createList(i+"-50", i+"-51", i+"-52", i+"-53", (i+1)+"-01", (i+1)+"-02", (i+1)+"-03");
List<String> outputVariant3 = createList(i+"-50", i+"-51", i+"-52", i+"-53", /*WeeklyStatisticManager left out week 01... */ (i+1)+"-02", (i+1)+"-03");
boolean matchesVariant1 = matches(input, outputVariant1);
boolean matchesVariant2 = matches(input, outputVariant2);
boolean matchesVariant3 = matches(input, outputVariant3);
if (matchesVariant1 && !matchesVariant2 && !matchesVariant3) {
// perfecto
} else if (!matchesVariant1 && matchesVariant2 && !matchesVariant3) {
// perfecto
} else if (!matchesVariant1 && !matchesVariant2 && matchesVariant3) {
// perfecto
} else {
Assert.fail("failed with input "+input);
}
}
}
@Test
public void testWronglyFormatted() throws Exception {
runTest(
createList("2010-1", "2010-2", "2010-4"),
createList("2010-1", "2010-02", "2010-2", "2010-03", "2010-04", "2010-4"));
}
@Test
public void testGapsA() throws Exception {
runTest(
createList("2010-01", "2010-02", "2010-04"),
createList("2010-01", "2010-02", "2010-03", "2010-04"));
}
@Test
public void testGapsB() throws Exception {
runTest(
createList("2010-01", "2010-02", "2010-04", "2010-07"),
createList("2010-01", "2010-02", "2010-03", "2010-04", "2010-05", "2010-06", "2010-07"));
}
@Test
public void testBigGap() throws Exception {
runTest(
createList("2009-50", "2010-12"),
createList("2009-50", "2009-51", "2009-52", "2009-53", "2010-01", "2010-02", "2010-03", "2010-04", "2010-05", "2010-06", "2010-07", "2010-08", "2010-09", "2010-10", "2010-11", "2010-12"));
}
@Test
public void testWrongInputParams() throws Exception {
List<String> resultingTestset = manager_.fillGapsInColumnHeaders(createList("2010-50", "2010-12"));
Assert.assertNull(resultingTestset);
}
private void assertListEquals(List<String> testset, List<String> resultingTestset) {
if (testset==null || resultingTestset==null) {
throw new IllegalArgumentException("testset and resultingtestset must not be empty");
}
Assert.assertEquals("size mismatch", testset.size(), resultingTestset.size());
for(int i=0; i<testset.size(); i++) {
String expectedStr = testset.get(i);
String actualStr = resultingTestset.get(i);
Assert.assertEquals("string at position "+i+" mismatch", expectedStr, actualStr);
}
}
private boolean matches(List<String> input, List<String> output) {
if (input.size()!=output.size()) {
return false;
}
for(int i=0; i<input.size(); i++) {
String expectedStr = input.get(i);
String actualStr = output.get(i);
if (!expectedStr.equals(actualStr)) {
return false;
}
}
return true;
}
private List<String> createList(String... strings) {
if (strings==null || strings.length==0) {
throw new IllegalArgumentException("strings must not be empty");
}
List<String> result = new ArrayList<String>(strings.length);
for (int i = 0; i < strings.length; i++) {
String aStr = strings[i];
result.add(aStr);
}
return result;
}
}
/**
* <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.instantMessaging;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.apache.commons.lang.ArrayUtils;
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.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.olat.collaboration.CollaborationTools;
import org.olat.restapi.support.vo.GroupVO;
import org.olat.test.ArquillianDeployments;
import org.olat.user.restapi.UserVO;
import org.olat.util.FunctionalGroupsSiteUtil;
import org.olat.util.FunctionalGroupsSiteUtil.MembersConfiguration;
import org.olat.util.FunctionalInstantMessagingUtil;
import org.olat.util.FunctionalUtil;
import org.olat.util.FunctionalVOUtil;
import org.olat.util.browser.Student1;
import org.olat.util.browser.Student2;
import org.olat.util.browser.Student3;
import org.olat.util.browser.Tutor1;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
/**
*
* @author jkraehemann, joel.kraehemann@frentix.com, frentix.com
*/
@RunWith(Arquillian.class)
public class FunctionalInstantMessagingTest {
public final static List<Dialog> GROUP_CHAT_DIALOG = new ArrayList<Dialog>();
public final static String[] GROUP_CHAT_MESSAGE = new String[]{
null,
null,
null,
"Hello world!",
"Clear sky.",
null,
};
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ArquillianDeployments.createDeployment();
}
@Drone
DefaultSelenium browser;
@ArquillianResource
URL deploymentUrl;
static FunctionalUtil functionalUtil;
static FunctionalGroupsSiteUtil functionalGroupsSiteUtil;
static FunctionalInstantMessagingUtil functionalInstantMessagingUtil;
static FunctionalVOUtil functionalVOUtil;
static boolean initialized = false;
@Before
public void setup() throws IOException, URISyntaxException{
if(!initialized){
functionalUtil = new FunctionalUtil();
functionalUtil.setDeploymentUrl(deploymentUrl.toString());
functionalGroupsSiteUtil = new FunctionalGroupsSiteUtil(functionalUtil);
functionalInstantMessagingUtil = new FunctionalInstantMessagingUtil(functionalUtil);
functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword());
initialized = true;
}
}
@Test
@RunAsClient
public void checkGroupChat(@Drone @Tutor1 DefaultSelenium tutor0,
@Drone @Student1 DefaultSelenium student0, @Drone @Student2 DefaultSelenium student1, @Drone @Student3 DefaultSelenium student2)
throws IOException, URISyntaxException
{
/*
* Prerequisites
*/
/* create users and group */
List<UserVO> tutor = functionalVOUtil.createTestAuthors(deploymentUrl, 1);
List<UserVO> user = functionalVOUtil.createTestUsers(deploymentUrl, 3);
List<GroupVO> group = functionalVOUtil.createTestCourseGroups(deploymentUrl, 1);
/* set visibility */
functionalVOUtil.setGroupConfiguration(deploymentUrl, group.get(0),
new String[]{CollaborationTools.TOOL_CHAT},
false, false,
false, false,
false, false);
/* add users to group */
functionalVOUtil.addOwnerToGroup(deploymentUrl, group.get(0), tutor.get(0));
for(int i = 0; i < 2; i++){
functionalVOUtil.addParticipantToGroup(deploymentUrl, group.get(0), user.get(i));
}
/*
* Content
*/
functionalUtil.login(tutor0, tutor.get(0).getLogin(), tutor.get(0).getPassword(), true);
/* message #0 */
Dialog dialog = new Dialog(student0, group.get(0), GROUP_CHAT_MESSAGE[0]);
Dialog.Action action = dialog.new LoginAction(user.get(0));
dialog.getPreProcessor().add(action);
action = dialog.new OnlineContactsAction(0);
dialog.getPreProcessor().add(action);
action = dialog.new OfflineContactsAction(0);
dialog.getPreProcessor().add(action);
//FIXME:JK: really ugly, probably rest connection remains open
action = dialog.new UsersAction(3);
dialog.getPreProcessor().add(action);
action = dialog.new LogoutAction();
dialog.getPreProcessor().add(action);
GROUP_CHAT_DIALOG.add(dialog);
/* message #1 */
dialog = new Dialog(student0, group.get(0), GROUP_CHAT_MESSAGE[1]);
action = dialog.new ModifySettingsAction(tutor0, new FunctionalGroupsSiteUtil.MembersConfiguration[]{
MembersConfiguration.CAN_SEE_COACHES,
}, group.get(0).getName());
dialog.getPreProcessor().add(action);
action = dialog.new LoginAction(user.get(0));
dialog.getPreProcessor().add(action);
action = dialog.new OnlineContactsAction(2);
dialog.getPreProcessor().add(action);
action = dialog.new CheckUserAction(tutor.get(0).getFirstName(), tutor.get(0).getLastName(), true, false);
dialog.getPreProcessor().add(action);
action = dialog.new OfflineContactsAction(0);
dialog.getPreProcessor().add(action);
action = dialog.new LogoutAction();
dialog.getPreProcessor().add(action);
GROUP_CHAT_DIALOG.add(dialog);
/* message #2 */
dialog = new Dialog(student0, group.get(0), GROUP_CHAT_MESSAGE[2]);
action = dialog.new ModifySettingsAction(tutor0, new FunctionalGroupsSiteUtil.MembersConfiguration[]{
//MembersConfiguration.CAN_SEE_COACHES,
MembersConfiguration.CAN_SEE_PARTICIPANTS,
}, group.get(0).getName());
dialog.getPreProcessor().add(action);
action = dialog.new LoginAction(user.get(0));
dialog.getPreProcessor().add(action);
action = dialog.new OnlineContactsAction(2);
dialog.getPreProcessor().add(action);
action = dialog.new CheckUserAction(tutor.get(0).getFirstName(), tutor.get(0).getLastName(), true, false);
dialog.getPreProcessor().add(action);
// action = dialog.new CheckUserAction(user.get(1).getFirstName(), user.get(1).getLastName(), false, true);
// dialog.getPreProcessor().add(action);
GROUP_CHAT_DIALOG.add(dialog);
/* message #3 */
dialog = new Dialog(student1, group.get(0), GROUP_CHAT_MESSAGE[3]);
action = dialog.new LoginAction(user.get(1));
dialog.getPreProcessor().add(action);
action = dialog.new OnlineContactsAction(3);
dialog.getPreProcessor().add(action);
action = dialog.new CheckUserAction(tutor.get(0).getFirstName(), tutor.get(0).getLastName(), true, false);
dialog.getPreProcessor().add(action);
action = dialog.new CheckUserAction(user.get(0).getFirstName(), user.get(0).getLastName(), true, false);
dialog.getPreProcessor().add(action);
action = dialog.new VerifyMessageAction(new String[]{
GROUP_CHAT_MESSAGE[3],
}, 0);
dialog.getPostProcessor().add(action);
GROUP_CHAT_DIALOG.add(dialog);
/* message #4 */
dialog = new Dialog(student0, group.get(0), GROUP_CHAT_MESSAGE[4]);
action = dialog.new VerifyMessageAction(new String[]{
GROUP_CHAT_MESSAGE[4],
}, 1);
dialog.getPostProcessor().add(action);
GROUP_CHAT_DIALOG.add(dialog);
/* message #5 */
dialog = new Dialog(student2, group.get(0), GROUP_CHAT_MESSAGE[5]);
action = dialog.new LoginAction(user.get(2));
dialog.getPreProcessor().add(action);
GROUP_CHAT_DIALOG.add(dialog);
/*
* chat - run the dialogs with its pre and post processors
*/
for(Dialog current: GROUP_CHAT_DIALOG){
current.chat();
}
}
public class Dialog{
private Selenium browser;
private Object conversationPartner;
private String message;
private List<Action> preProcessor = new ArrayList<Action>();
private List<Action> postProcessor = new ArrayList<Action>();
public Dialog(Selenium browser, Object conversationPartner, String message){
this.browser = browser;
this.conversationPartner = conversationPartner;
this.message = message;
}
public boolean performPreProcessing(){
for(Action current: preProcessor){
if(!current.process(this)){
Assert.fail(current.getClass().getName());
}
}
return(true);
}
public boolean performPostProcessing(){
for(Action current: postProcessor){
if(!current.process(this)){
Assert.fail(current.getClass().getName());
}
}
return(true);
}
public boolean chat(){
performPreProcessing();
if(message != null){
if(conversationPartner instanceof UserVO){
if(!functionalInstantMessagingUtil.sendMessageToUser(browser,
((UserVO) conversationPartner).getFirstName(), ((UserVO) conversationPartner).getLastName(),
message)){
Assert.fail();
}
}else if(conversationPartner instanceof GroupVO){
if(!functionalGroupsSiteUtil.sendMessageToGroup(browser,
((GroupVO) conversationPartner).getName(),
message)){
Assert.fail();
}
}
}
performPostProcessing();
return(true);
}
public Selenium getBrowser() {
return browser;
}
public void setBrowser(Selenium browser) {
this.browser = browser;
}
public Object getConversationPartner() {
return conversationPartner;
}
public void setConversationPartner(Object conversationPartner) {
this.conversationPartner = conversationPartner;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public List<Action> getPreProcessor() {
return preProcessor;
}
public void setPreProcessor(List<Action> preProcessor) {
this.preProcessor = preProcessor;
}
public List<Action> getPostProcessor() {
return postProcessor;
}
public void setPostProcessor(List<Action> postProcessor) {
this.postProcessor = postProcessor;
}
public abstract class Action{
public abstract boolean process(Dialog dialog);
}
public class UsersAction extends Action{
private int count;
public UsersAction(int count){
this.count = count;
}
@Override
public boolean process(Dialog dialog) {
int users = functionalUtil.retrieveUserCount(getBrowser());
if(users == count){
return(true);
}else{
return(false);
}
}
}
public class LoginAction extends Action {
private UserVO user;
public LoginAction(UserVO user){
this.user = user;
}
@Override
public boolean process(Dialog dialog) {
if(functionalUtil.login(browser, user.getLogin(), user.getPassword(), true)){
return(true);
}else{
return(false);
}
}
}
public class LogoutAction extends Action {
public LogoutAction(){
}
@Override
public boolean process(Dialog dialog) {
if(functionalUtil.logout(browser)){
return(true);
}else{
return(false);
}
}
}
public class OnlineContactsAction extends Action{
private int count;
public OnlineContactsAction(int count){
this.count = count;
}
@Override
public boolean process(Dialog dialog) {
List<String> contacts = functionalInstantMessagingUtil.findOnlineContacts(browser);
if(contacts.size() == count){
return(true);
}else{
return(false);
}
}
}
public class OfflineContactsAction extends Action{
private int count;
public OfflineContactsAction(int count){
this.count = count;
}
@Override
public boolean process(Dialog dialog) {
List<String> contacts = functionalInstantMessagingUtil.findOfflineContacts(browser);
if(contacts.size() == count){
return(true);
}else{
return(false);
}
}
}
public class VerifyMessageAction extends Action {
String message[];
int index;
public VerifyMessageAction(String message[], int index){
this.message = message;
this.index = index;
}
@Override
public boolean process(Dialog dialog) {
for(String current: message){
if(conversationPartner instanceof UserVO){
if(!functionalInstantMessagingUtil.waitForPageToLoadMessage(browser, current)){
return(false);
}
}else if(conversationPartner instanceof GroupVO){
if(!functionalGroupsSiteUtil.waitForPageToLoadMessage(browser, ((GroupVO) conversationPartner).getName(), current, index)){
return(false);
}
}
}
return(true);
}
}
public class ModifySettingsAction extends Action {
private Selenium tutor;
private String groupName;
private FunctionalGroupsSiteUtil.MembersConfiguration[] config;
public ModifySettingsAction(Selenium tutor, FunctionalGroupsSiteUtil.MembersConfiguration[] config, String groupName){
this.tutor = tutor;
this.groupName = groupName;
this.config = config;
}
@Override
public boolean process(Dialog dialog) {
functionalGroupsSiteUtil.openMyGroup(tutor, groupName);
functionalGroupsSiteUtil.applyMembersConfiguration(tutor, config);
return(true);
}
}
public class CheckUserAction extends Action {
private String firstname;
private String surname;
private boolean onlineContacts;
private boolean offlineContacts;
public CheckUserAction(String firstname, String surname, boolean onlineContacts, boolean offlineContacts){
this.firstname = firstname;
this.surname = surname;
this.onlineContacts = onlineContacts;
this.offlineContacts = offlineContacts;
}
@Override
public boolean process(Dialog dialog) {
String name = surname + ", " + firstname;
boolean isOnline = ArrayUtils.contains(functionalInstantMessagingUtil.findOnlineContacts(browser).toArray(), name);
boolean isOffline = ArrayUtils.contains(functionalInstantMessagingUtil.findOfflineContacts(browser).toArray(), name);
if((onlineContacts && isOnline) ||
(offlineContacts && isOffline)){
return(true);
}else{
return(false);
}
}
}
}
}
......@@ -35,6 +35,7 @@ import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.ldap.LdapContext;
import org.junit.Assume;
import org.junit.Test;
import org.olat.admin.user.delete.service.UserDeletionManager;
import org.olat.basesecurity.BaseSecurity;
......@@ -61,18 +62,19 @@ import org.olat.user.UserManager;
public class LDAPLoginTest extends OlatTestCase {
@Test public void testSystemBind() {
if (!LDAPLoginModule.isLDAPEnabled()) return;
@Test
public void testSystemBind() {
Assume.assumeTrue(LDAPLoginModule.isLDAPEnabled());
//edit olatextconfig.xml for testing
LDAPLoginManager ldapManager = (LDAPLoginManager) CoreSpringFactory.getBean(LDAPLoginManager.class);
LdapContext ctx = ldapManager.bindSystem();
assertEquals(true, (ctx != null));
}
@Test public void testCreateUser() {
if (!LDAPLoginModule.isLDAPEnabled()) return;
@Test
public void testCreateUser() {
Assume.assumeTrue(LDAPLoginModule.isLDAPEnabled());
LDAPLoginManager ldapManager = (LDAPLoginManager) CoreSpringFactory.getBean(LDAPLoginManager.class);
BaseSecurity securityManager = BaseSecurityManager.getInstance();
......@@ -94,10 +96,10 @@ public class LDAPLoginTest extends OlatTestCase {
ldapManager.createAndPersistUser(attrs);
assertEquals(true, (securityManager.findIdentityByName(uid) != null));
}
@Test public void testUserBind() throws NamingException {
if (!LDAPLoginModule.isLDAPEnabled()) return;
@Test
public void testUserBind() throws NamingException {
Assume.assumeTrue(LDAPLoginModule.isLDAPEnabled());
LDAPLoginManager ldapManager = (LDAPLoginManager) CoreSpringFactory.getBean(LDAPLoginManager.class);
LDAPError errors = new LDAPError();
......@@ -127,8 +129,9 @@ public class LDAPLoginTest extends OlatTestCase {
}
@Test public void testCheckUser() {
if (!LDAPLoginModule.isLDAPEnabled()) return;
@Test
public void testCheckUser() {
Assume.assumeTrue(LDAPLoginModule.isLDAPEnabled());
LDAPLoginManager ldapManager = (LDAPLoginManager) CoreSpringFactory.getBean(LDAPLoginManager.class);
LDAPError errors = new LDAPError();
......@@ -151,9 +154,9 @@ public class LDAPLoginTest extends OlatTestCase {
assertEquals(true, errors.isEmpty());
}
@Test public void testCreateChangedAttrMap() {
if (!LDAPLoginModule.isLDAPEnabled()) return;
@Test
public void testCreateChangedAttrMap() {
Assume.assumeTrue(LDAPLoginModule.isLDAPEnabled());
// simulate closed session (user adding from startup job)
DBFactory.getInstance().intermediateCommit();
......@@ -210,8 +213,9 @@ public class LDAPLoginTest extends OlatTestCase {
assertEquals(true, (changedAttrMap==null));
}
@Test public void testSyncUser(){
if (!LDAPLoginModule.isLDAPEnabled()) return;
@Test
public void testSyncUser(){
Assume.assumeTrue(LDAPLoginModule.isLDAPEnabled());
LDAPLoginManager ldapManager = (LDAPLoginManager) CoreSpringFactory.getBean(LDAPLoginManager.class);
BaseSecurity securityManager = BaseSecurityManager.getInstance();
......@@ -233,8 +237,9 @@ public class LDAPLoginTest extends OlatTestCase {
assertEquals(true, (changedMap==null));
}
@Test public void testIdentityDeletedInLDAP(){
if (!LDAPLoginModule.isLDAPEnabled()) return;
@Test
public void testIdentityDeletedInLDAP(){
Assume.assumeTrue(LDAPLoginModule.isLDAPEnabled());
LDAPLoginManager ldapManager = (LDAPLoginManager) CoreSpringFactory.getBean(LDAPLoginManager.class);
BaseSecurity securityManager = BaseSecurityManager.getInstance();
......@@ -279,10 +284,9 @@ public class LDAPLoginTest extends OlatTestCase {
assertEquals(2, (deletList.size()));
}
@Test public void testCronSync() throws Exception {
if (!LDAPLoginModule.isLDAPEnabled()) return;
@Test
public void testCronSync() throws Exception {
Assume.assumeTrue(LDAPLoginModule.isLDAPEnabled());
LdapContext ctx;
List<Attributes> ldapUserList;
......
/**
* <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.portal;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
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.Test;
import org.junit.runner.RunWith;
import org.olat.test.ArquillianDeployments;
import org.olat.user.restapi.UserVO;
import org.olat.util.FunctionalHomeSiteUtil;
import org.olat.util.FunctionalHomeSiteUtil.SettingsTab;
import org.olat.util.FunctionalLocatorPairsFactory;
import org.olat.util.FunctionalUtil;
import org.olat.util.FunctionalVOUtil;
import com.thoughtworks.selenium.DefaultSelenium;
/**
*
* @author jkraehemann, joel.kraehemann@frentix.com, frentix.com
*/
@RunWith(Arquillian.class)
public class FunctionalSettingsTest {
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ArquillianDeployments.createDeployment();
}
@Drone
DefaultSelenium browser;
@ArquillianResource
URL deploymentUrl;
FunctionalUtil functionalUtil;
FunctionalVOUtil functionalVOUtil;
FunctionalHomeSiteUtil functionalHomeSiteUtil;
int portalColumnCount;
@Before
public void setup(){
functionalUtil = new FunctionalUtil();
functionalUtil.setDeploymentUrl(deploymentUrl.toString());
functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword());
functionalHomeSiteUtil = functionalUtil.getFunctionalHomeSiteUtil();
portalColumnCount = 2;
}
@Test
@RunAsClient
public void checkActivatePortlet(){
/* login for test setup */
Assert.assertTrue(functionalUtil.login(browser));
/* click configure */
functionalHomeSiteUtil.beginEditingPortal(browser);
/* de-/activate portlets */
if(functionalHomeSiteUtil.deactivatePortlet(browser, functionalHomeSiteUtil.getPortletEffCss())){
Assert.assertFalse(functionalHomeSiteUtil.checkPortletActive(browser, functionalHomeSiteUtil.getPortletEffCss()));
}
if(functionalHomeSiteUtil.activatePortlet(browser, functionalHomeSiteUtil.getPortletNotesCss())){
Assert.assertTrue(functionalHomeSiteUtil.checkPortletActive(browser, functionalHomeSiteUtil.getPortletNotesCss()));
}
/* end editing portal */
functionalHomeSiteUtil.endEditingPortal(browser);
}
@Test
@RunAsClient
public void checkMovePortlet(){
/* login for test setup */
Assert.assertTrue(functionalUtil.login(browser));
/* click configure */
functionalHomeSiteUtil.beginEditingPortal(browser);
/* move portlets */
int oldPositionDyk[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletDykCss(), portalColumnCount);
if(oldPositionDyk[1] != 0){
if(functionalHomeSiteUtil.movePortlet(browser, functionalHomeSiteUtil.getPortletDykCss(), FunctionalHomeSiteUtil.Direction.UP)){
functionalUtil.idle(browser);
int newPosition[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletDykCss(), portalColumnCount);
Assert.assertEquals(oldPositionDyk[1], newPosition[1] + 1);
}
}else{
if(functionalHomeSiteUtil.movePortlet(browser, functionalHomeSiteUtil.getPortletDykCss(), FunctionalHomeSiteUtil.Direction.DOWN)){
functionalUtil.idle(browser);
int newPosition[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletDykCss(), portalColumnCount);
Assert.assertEquals(oldPositionDyk[1], newPosition[1] - 1);
}
}
int oldPositionNoti[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletNotiCss(), portalColumnCount);
if(oldPositionNoti[0] != 0){
if(functionalHomeSiteUtil.movePortlet(browser, functionalHomeSiteUtil.getPortletNotiCss(), FunctionalHomeSiteUtil.Direction.LEFT)){
functionalUtil.idle(browser);
int newPosition[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletNotiCss(), portalColumnCount);
Assert.assertEquals(oldPositionNoti[0] - 1, newPosition[0]);
}
}else{
if(functionalHomeSiteUtil.movePortlet(browser, functionalHomeSiteUtil.getPortletNotiCss(), FunctionalHomeSiteUtil.Direction.RIGHT)){
functionalUtil.idle(browser);
int newPosition[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletNotiCss(), portalColumnCount);
Assert.assertEquals(oldPositionNoti[0] + 1, newPosition[0]);
}
}
/* end editing portal */
functionalHomeSiteUtil.endEditingPortal(browser);
}
@Test
@RunAsClient
public void checkBrowserBack(){
/* login for test setup */
Assert.assertTrue(functionalUtil.login(browser));
functionalHomeSiteUtil.enableBack(browser);
/* check if settings were applied */
Assert.assertTrue(functionalUtil.logout(browser));
Assert.assertTrue(functionalUtil.login(browser));
LinkedHashMap<String,String> pages = new LinkedHashMap<String,String>();
/* locators as key to click and as value to test for */
FunctionalLocatorPairsFactory pairsFactory = new FunctionalLocatorPairsFactory(functionalUtil);
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteHomeCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteHomeCss()));
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteAdministrationCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteAdministrationCss()));
//pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteGroupAdministrationCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteGroupAdministrationCss()));
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteGroupsCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteGroupsCss()));
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteLearningResourcesCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteLearningResourcesCss()));
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteUserManagementCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteUserManagementCss()));
/* visit specified pages */
String[] keys = pages.keySet().toArray(new String[0]);
String[] values = pages.values().toArray(new String[0]);
int i;
for(i = 0; i < pages.size(); i++){
functionalUtil.idle(browser);
browser.click(keys[i]);
functionalUtil.waitForPageToLoad(browser);
functionalUtil.waitForPageToLoadElement(browser, values[i]);
}
/* test for the appropriate pages */
i = pages.size() -1;
Assert.assertTrue(browser.isElementPresent(values[i]));
i--;
for(; i >= 0; i--){
functionalUtil.idle(browser);
browser.goBack();
functionalUtil.waitForPageToLoad(browser);
functionalUtil.waitForPageToLoadElement(browser, values[i]);
Assert.assertTrue(browser.isElementPresent(values[i]));
}
}
@Test
@RunAsClient
public void checkSettings() throws IOException, URISyntaxException, InterruptedException{
/* create test user via REST */
List<UserVO> userVO = functionalVOUtil.createTestUsers(deploymentUrl, 1);
/* login for test setup */
Assert.assertTrue(functionalUtil.login(browser));
/* reset settings */
Assert.assertTrue(functionalHomeSiteUtil.resetSettings(browser));
Assert.assertTrue(functionalUtil.login(browser));
/* set language */
functionalHomeSiteUtil.selectLanguage(browser, FunctionalHomeSiteUtil.GERMAN_LANGUAGE_VALUE);
/* resume off */
functionalHomeSiteUtil.disableResume(browser);
/* logout */
Assert.assertTrue(functionalUtil.logout(browser));
/* login for test case */
Assert.assertTrue(functionalUtil.login(browser));
/* click configure */
functionalHomeSiteUtil.beginEditingPortal(browser);
/* de-/activate portlets */
if(functionalHomeSiteUtil.deactivatePortlet(browser, functionalHomeSiteUtil.getPortletEffCss())){
Assert.assertFalse(functionalHomeSiteUtil.checkPortletActive(browser, functionalHomeSiteUtil.getPortletEffCss()));
}
if(functionalHomeSiteUtil.activatePortlet(browser, functionalHomeSiteUtil.getPortletNotesCss())){
Assert.assertTrue(functionalHomeSiteUtil.checkPortletActive(browser, functionalHomeSiteUtil.getPortletNotesCss()));
}
/* move portlets */
/* move portlets */
int oldPositionDyk[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletDykCss(), portalColumnCount);
if(oldPositionDyk[1] != 0){
if(functionalHomeSiteUtil.movePortlet(browser, functionalHomeSiteUtil.getPortletDykCss(), FunctionalHomeSiteUtil.Direction.UP)){
functionalUtil.idle(browser);
int newPosition[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletDykCss(), portalColumnCount);
Assert.assertEquals(oldPositionDyk[1], newPosition[1] + 1);
}
}else{
if(functionalHomeSiteUtil.movePortlet(browser, functionalHomeSiteUtil.getPortletDykCss(), FunctionalHomeSiteUtil.Direction.DOWN)){
functionalUtil.idle(browser);
int newPosition[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletDykCss(), portalColumnCount);
Assert.assertEquals(oldPositionDyk[1], newPosition[1] - 1);
}
}
int oldPositionNoti[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletNotiCss(), portalColumnCount);
if(oldPositionNoti[0] != 0){
if(functionalHomeSiteUtil.movePortlet(browser, functionalHomeSiteUtil.getPortletNotiCss(), FunctionalHomeSiteUtil.Direction.LEFT)){
functionalUtil.idle(browser);
int newPosition[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletNotiCss(), portalColumnCount);
Assert.assertEquals(oldPositionNoti[0] - 1, newPosition[0]);
}
}else{
if(functionalHomeSiteUtil.movePortlet(browser, functionalHomeSiteUtil.getPortletNotiCss(), FunctionalHomeSiteUtil.Direction.RIGHT)){
functionalUtil.idle(browser);
int newPosition[] = functionalHomeSiteUtil.findPortletPosition(browser, functionalHomeSiteUtil.getPortletNotiCss(), portalColumnCount);
Assert.assertEquals(oldPositionNoti[0] + 1, newPosition[0]);
}
}
/* end editing portal */
functionalHomeSiteUtil.endEditingPortal(browser);
/* edit settings */
functionalHomeSiteUtil.openActionByMenuTree(browser, FunctionalHomeSiteUtil.HomeSiteAction.SETTINGS);
functionalUtil.openContentTab(browser, SettingsTab.SYSTEM.ordinal());
functionalHomeSiteUtil.selectLanguage(browser, FunctionalHomeSiteUtil.ENGLISH_LANGUAGE_VALUE);
functionalHomeSiteUtil.enableBack(browser);
/* check if settings were applied */
Assert.assertTrue(functionalUtil.logout(browser));
Assert.assertTrue(functionalUtil.login(browser));
LinkedHashMap<String,String> pages = new LinkedHashMap<String,String>();
/* locators as key to click and as value to test for */
FunctionalLocatorPairsFactory pairsFactory = new FunctionalLocatorPairsFactory(functionalUtil);
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteHomeCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteHomeCss()));
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteAdministrationCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteAdministrationCss()));
//pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteGroupAdministrationCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteGroupAdministrationCss()));
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteGroupsCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteGroupsCss()));
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteLearningResourcesCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteLearningResourcesCss()));
pages.put(pairsFactory.getLocatorOfSite(functionalUtil.getOlatSiteUserManagementCss()), pairsFactory.getApprovalOfSite(functionalUtil.getOlatSiteUserManagementCss()));
/* visit specified pages */
String[] keys = pages.keySet().toArray(new String[0]);
String[] values = pages.values().toArray(new String[0]);
int i;
for(i = 0; i < pages.size(); i++){
functionalUtil.idle(browser);
browser.click(keys[i]);
functionalUtil.waitForPageToLoad(browser);
functionalUtil.waitForPageToLoadElement(browser, values[i]);
}
/* test for the appropriate pages */
i = pages.size() -1;
Assert.assertTrue(browser.isElementPresent(values[i]));
i--;
for(; i >= 0; i--){
browser.goBack();
functionalUtil.waitForPageToLoad(browser);
functionalUtil.waitForPageToLoadElement(browser, values[i]);
Assert.assertTrue(browser.isElementPresent(values[i]));
}
/* password test */
UserVO current = userVO.get(0);
Assert.assertTrue(functionalUtil.logout(browser));
Assert.assertTrue(functionalUtil.login(browser, current.getLogin(), current.getPassword(), true));
functionalUtil.openSite(browser, FunctionalUtil.OlatSite.HOME);
functionalHomeSiteUtil.openActionByMenuTree(browser, FunctionalHomeSiteUtil.HomeSiteAction.SETTINGS);
String newPassword = ("passwd_" + 0 + "_" + UUID.randomUUID().toString()).substring(0, 24);
functionalUtil.openContentTab(browser, SettingsTab.PASSWORD.ordinal());
functionalUtil.typePassword(browser, functionalHomeSiteUtil.getOldPasswordCss(), current.getPassword());
functionalUtil.typePassword(browser, functionalHomeSiteUtil.getNewPasswordCss(), newPassword);
functionalUtil.typePassword(browser, functionalHomeSiteUtil.getConfirmPasswordCss(), newPassword);
functionalUtil.saveForm(browser, 0);
Assert.assertTrue(functionalUtil.logout(browser));
Assert.assertTrue(functionalUtil.login(browser, current.getLogin(), newPassword, true));
}
}
/**
* <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.repository;
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.Test;
import org.junit.runner.RunWith;
import org.olat.restapi.support.vo.CourseVO;
import org.olat.restapi.support.vo.RepositoryEntryVO;
import org.olat.test.ArquillianDeployments;
import org.olat.util.FunctionalCourseUtil;
import org.olat.util.FunctionalCourseUtil.CourseNodeAlias;
import org.olat.util.FunctionalRepositorySiteUtil;
import org.olat.util.FunctionalUtil;
import org.olat.util.FunctionalVOUtil;
import org.olat.util.FunctionalRepositorySiteUtil.RepositorySiteAction;
import com.thoughtworks.selenium.DefaultSelenium;
/**
*
* @author jkraehemann, joel.kraehemann@frentix.com, frentix.com
*/
@RunWith(Arquillian.class)
public class FunctionalCatalogTest {
public final static String[] SUBCATEGORY_PATHS = {
"/programming",
"/programming/c",
"/programming/java"
};
public final static String[] SUBCATEGORY_DESCRIPTIONS = {
"here you may find courses and resources related to programming",
"about the C programming language",
"about the Java programming language"
};
public final static String[] SUBCATEGORY_PATHS_INCLUDING_RESOURCE = {
SUBCATEGORY_PATHS[1],
SUBCATEGORY_PATHS[2]
};
@Deployment(testable = false)
public static WebArchive createDeployment() {
return ArquillianDeployments.createDeployment();
}
@Drone
DefaultSelenium browser;
@ArquillianResource
URL deploymentUrl;
static FunctionalUtil functionalUtil;
static FunctionalRepositorySiteUtil functionalRepositorySiteUtil;
static FunctionalCourseUtil functionalCourseUtil;
static FunctionalVOUtil functionalVOUtil;
static boolean initialized = false;
@Before
public void setup() throws IOException, URISyntaxException{
if(!initialized){
functionalUtil = new FunctionalUtil();
functionalUtil.setDeploymentUrl(deploymentUrl.toString());
functionalRepositorySiteUtil = functionalUtil.getFunctionalRepositorySiteUtil();
functionalCourseUtil = functionalRepositorySiteUtil.getFunctionalCourseUtil();
functionalVOUtil = new FunctionalVOUtil(functionalUtil.getUsername(), functionalUtil.getPassword());
initialized = true;
}
}
@Test
@RunAsClient
public void checkCreateSubcategory() throws URISyntaxException, IOException{
int courses = SUBCATEGORY_PATHS_INCLUDING_RESOURCE.length;
/*
* prerequisites for test created via REST
*/
/* import wiki */
RepositoryEntryVO[] wikiVO = new RepositoryEntryVO[courses];
for(int i = 0; i < courses; i++){
wikiVO[i] = functionalVOUtil.importWiki(deploymentUrl);
}
/* import course */
CourseVO[] courseVO = new CourseVO[courses];
for(int i = 0; i < courses; i++){
courseVO[i] = functionalVOUtil.importEmptyCourse(deploymentUrl);
}
/*
* create or configure content
*/
functionalUtil.login(browser);
/* create categories */
for(int i = 0; i < SUBCATEGORY_PATHS.length; i++){
String currentPath = SUBCATEGORY_PATHS[i];
String currentName = currentPath.substring(currentPath.lastIndexOf('/') + 1);
String currentDescription = SUBCATEGORY_DESCRIPTIONS[i];
Assert.assertTrue(functionalRepositorySiteUtil.createCatalogSubcategory(browser, currentPath.substring(0, currentPath.lastIndexOf('/')), currentName, currentDescription));
}
/* edit course and publish thereby adding it to catalog */
for(int i = 0; i < courses; i++){
/* open course in edit mode */
Assert.assertTrue(functionalRepositorySiteUtil.openCourse(browser, courseVO[i].getRepoEntryKey()));
Assert.assertTrue(functionalCourseUtil.openCourseEditor(browser));
/* choose wiki */
String currentPath = SUBCATEGORY_PATHS_INCLUDING_RESOURCE[i];
String currentName = currentPath.substring(currentPath.lastIndexOf('/') + 1);
Assert.assertTrue(functionalCourseUtil.createCourseNode(browser, CourseNodeAlias.WIKI, "wiki", currentName + " wiki", "colaborative " + currentName + " wiki", 0));
Assert.assertTrue(functionalCourseUtil.chooseWiki(browser, wikiVO[i].getKey()));
/* publish course */
Assert.assertTrue(functionalCourseUtil.publishEntireCourse(browser, null, currentPath));
/* close course */
Assert.assertTrue(functionalCourseUtil.closeActiveTab(browser));
}
/*
* verify content
*/
/* open catalog */
Assert.assertTrue(functionalUtil.openSite(browser, FunctionalUtil.OlatSite.LEARNING_RESOURCES));
Assert.assertTrue(functionalRepositorySiteUtil.openActionByMenuTree(browser, RepositorySiteAction.CATALOG));
/* verify resources */
for(int i = 0; i < courses; i++){
functionalUtil.idle(browser);
/* click on catalog root */
StringBuffer selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=//div[contains(@class, '")
.append(functionalRepositorySiteUtil.getCatalogNavigationCss())
.append("')]//a");
if(browser.isElementPresent(selectorBuffer.toString())){
browser.click(selectorBuffer.toString());
}
/* navigate tree */
String[] selectors = functionalRepositorySiteUtil.createCatalogSelectors(SUBCATEGORY_PATHS_INCLUDING_RESOURCE[i]);
for(String currentSelector: selectors){
functionalUtil.idle(browser);
functionalUtil.waitForPageToLoadElement(browser, currentSelector.toString());
browser.click(currentSelector);
}
functionalUtil.idle(browser);
/* click first course and retrieve business path */
selectorBuffer = new StringBuffer();
selectorBuffer.append("xpath=(//a[contains(@class, '")
.append(functionalRepositorySiteUtil.getCourseModuleIconCss())
.append("')])");
/* create business path and try to find it */
String businessPath0 = functionalUtil.getDeploymentUrl() + "/url/RepositoryEntry/" + courseVO[i].getRepoEntryKey();
boolean found = false;
/* click show all */
//FIXME:JK: implement me
for(int j = 0; j < browser.getXpathCount(selectorBuffer.toString().substring(6)).intValue(); j++){
functionalUtil.idle(browser);
functionalUtil.waitForPageToLoadElement(browser, selectorBuffer.toString() + "[" + (j + 1) + "]");
browser.click(selectorBuffer.toString() + "[" + (j + 1) + "]");
functionalUtil.idle(browser);
String businessPath1 = functionalUtil.currentBusinessPath(browser);
functionalCourseUtil.closeActiveTab(browser);
if(businessPath1.contains(businessPath0)){
found = true;
break;
}
}
/* assert collected business paths to be equal */
Assert.assertTrue(found);
}
}
}
......@@ -137,6 +137,7 @@ public class GroupMgmtTest extends OlatJerseyTestCase {
RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = rs.create("administrator", "-", "rest-re", null, course);
DBFactory.getInstance().commit();
assertNotNull(re);
//create learn group
// 1) context one: learning groups
......
......@@ -174,6 +174,7 @@ public class ArquillianDeployments {
|| path.endsWith(".pxml")
|| path.endsWith(".sh")
|| path.endsWith(".scss")
|| path.endsWith(".zip")
|| path.endsWith(".pxm"));
return !exclude;
}
......@@ -192,11 +193,8 @@ public class ArquillianDeployments {
String pathStr = path.toString();
boolean exclude = (pathStr.contains("/org/olat/core/test")
|| pathStr.contains("/org/olat/selenium")
|| pathStr.contains("/org/olat/test/_spring")
|| pathStr.contains("/org/olat/test/file_resources")
|| pathStr.endsWith("Test.class]")
|| pathStr.endsWith("TestWithMocking.class]")
|| pathStr.endsWith("Junit4.class]"));
|| pathStr.contains("/org/olat/test/")
|| pathStr.endsWith("Test.class]"));
return !exclude;
}
}
......
/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <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>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <hr>
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* This file has been modified by the OpenOLAT community. Changes are licensed
* under the Apache 2.0 license as the original file.
*/
package org.olat.test;
import org.springframework.beans.factory.FactoryBean;
/**
*
* Description:<br>
* use this bean if you want to reference an null value as a bean class value.
* If you like to set null as value try the <null/> bean.
*
* <P>
* Initial Date: 03.05.2010 <br>
* @author guido
*/
public class NullFactoryBean implements FactoryBean<Void> {
public Void getObject() throws Exception {
return null;
}
public Class<? extends Void> getObjectType() {
return null;
}
public boolean isSingleton() {
return true;
}
}
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment