/**
* 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.
* <p>
*/
package org.olat.course.config;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.log4j.Logger;
import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.id.OLATResourceable;
import org.olat.core.logging.activity.IUserActivityLogger;
import org.olat.core.test.OlatTestCase;
import org.olat.core.util.resource.OresHelper;
import org.olat.core.util.vfs.VFSItem;
import org.olat.course.CourseFactory;
import org.olat.course.ICourse;
/**
* Description: <br>
* TODO: patrick Class Description for CourseConfigManagerImplTest
* <P>
* Initial Date: Jun 3, 2005 <br>
*
* @author patrick
*/
public class CourseConfigManagerImplTest extends OlatTestCase {
private static Logger log = Logger.getLogger(CourseConfigManagerImplTest.class.getName());
private static ICourse course1;
private static boolean isSetup = false;
private static boolean isTearDown = false;
/**
* @param name
*/
public CourseConfigManagerImplTest(String name) {
super(name);
}
/**
* SetUp is called before each test.
*/
public void setUp() {
if (isSetup) return;
try {
super.setUp();
DBFactory.getJunitInstance().clearDatabase();
// create course and persist as OLATResourceImpl
OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitConfigCourse", new Long(System.currentTimeMillis()));
course1 = CourseFactory.createEmptyCourse(resourceable, "JUnitCourseConfig", "JUnitCourseConfig Long Title",
"objective 1 objective 2 objective 3");
DBFactory.getInstance().closeSession();
isSetup = true;
} catch (Exception e) {
log.error("Exception in setUp(): " + e);
e.printStackTrace();
}
}
/**
* @return the test suite
* @throws Exception
*/
public static Test suite() throws Exception {
try {
return new TestSuite(CourseConfigManagerImplTest.class);
} catch (Exception e) {
log.error("Exception in suite(): " + e);
e.printStackTrace();
throw e;
}
}
/**
*
*
*/
public void testConfigFileCRUD() {
/*
* a new created course gets its configuration upon the first load with
* default values
*/
CourseConfigManager ccm = CourseConfigManagerImpl.getInstance();
CourseConfig cc1 = ccm.loadConfigFor(course1);
assertNotNull("CourseConfiguration is not null", cc1);
/*
* update values
*/
ccm.saveConfigTo(course1, cc1);
cc1 = null;
// check the saved values
cc1 = ccm.loadConfigFor(course1);
assertNotNull("CourseConfiguration is not null", cc1);
/*
* delete configuration
*/
ccm.deleteConfigOf(course1);
VFSItem cc1File = CourseConfigManagerImpl.getConfigFile(course1);
assertFalse("CourseConfig file no longer exists.", cc1File != null);
}
/**
* TearDown is called after each test.
*
* @throws Exception
*/
public void tearDown() throws Exception {
if (isTearDown) return;
try {
super.tearDown();
DBFactory.getInstance().closeSession();
isTearDown = true;
} catch (Exception e) {
log.error("Exception in tearDown(): " + e);
e.printStackTrace();
throw e;
}
}
}