/** * OLAT - Online Learning and Training
* http://www.olat.org *

* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. *

* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),
* University of Zurich, Switzerland. *

*/ package org.olat.modules.ims.cp; import org.apache.log4j.Logger; import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.id.OLATResourceable; import org.olat.core.util.resource.OresHelper; import org.olat.core.util.vfs.VFSItem; import org.olat.core.util.vfs.VFSLeaf; import org.olat.ims.cp.CPManager; import org.olat.ims.cp.ContentPackage; import org.olat.ims.cp.objects.CPItem; import org.olat.ims.cp.objects.CPOrganization; import org.olat.modules.fo.ForumManagerTest; import org.olat.test.OlatTestCase; /** * The test class for the CPManager and its implementation. * *

* Initial Date: Jun 11, 2009
* * @author gwassmann */ public class CPManagerTest extends OlatTestCase { private static final String ITEM_ID = "this_is_a_great_inital_item_identifier"; private static final String PAGE_TITLE = "fancy page"; private static final Logger log = Logger.getLogger(ForumManagerTest.class.getName()); private CPManager mgr = null; private ContentPackage cp; @Before public void setUp() { // create some users with user manager mgr = CPManager.getInstance(); try { log.info("setUp start ------------------------"); OLATResourceable ores = OresHelper.createOLATResourceableInstance( this.getClass(), Long.valueOf((long) (Math.random()*100000))); cp = mgr.createNewCP(ores, PAGE_TITLE); assertNotNull("crated cp is null, check filesystem where the temp cp's are created.", cp); } catch (Exception e) { log.error("Exception in setUp(): " + e); } } @After public void tearDown() { cp.getRootDir().delete(); try { DBFactory.getInstance().closeSession(); } catch (Exception e) { log.error("Exception in tearDown(): " + e); } } @Test public void testLoad() { ContentPackage relodedCP = mgr.load(cp.getRootDir(), cp.getResourcable()); assertNotNull(relodedCP); CPOrganization orga = relodedCP.getFirstOrganizationInManifest(); assertNotNull(orga); CPItem item = orga.getFirstItem(); assertEquals(PAGE_TITLE, item.getTitle()); } @Test public void testCreateNewCP() { // Tested through setup. Foundation for the other tests. } @Test public void testIsSingleUsedResource() { // mgr.isSingleUsedResource(res, cp); } @Test public void testAddBlankPage() { final String pageTitle = "the blank page"; String ident = mgr.addBlankPage(cp, pageTitle); assertNotNull(ident); } @Test public void testUpdatePage() { // TODO:GW impl } @Test public void testAddElement() { // TODO:GW impl } public void testAddElementAfter() { CPItem newItem = new CPItem(); mgr.addElementAfter(cp, newItem, ITEM_ID); assertTrue("The new item wasn't inserted at the second position.", newItem.getPosition() == 1); } @Test public void testRemoveElement() { // TODO:GW impl } @Test public void testMoveElement() { // TODO:GW impl } public void testCopyElement() { // TODO:GW impl } @Test public void testGetDocument() { // TODO:GW impl } @Test public void testGetItemTitle() { String title = mgr.getItemTitle(cp, ITEM_ID); assertNotNull(title); assertEquals(PAGE_TITLE, title); } @Test public void testGetTreeDataModel() { // TODO:GW impl } @Test public void testGetFirstOrganizationInManifest() { // TODO:GW impl } public void testGetFirstPageToDisplay() { // this method basically just returns the first element in the cp } @Test public void testGetPageByItemId() { String href = mgr.getPageByItemId(cp, ITEM_ID); VFSItem file = cp.getRootDir().resolve(href); assertNotNull("The file path doesn't lead to a file.", file); } @Test public void testWriteToFile() { mgr.writeToFile(cp); // Throws exception on failure } @Test public void testWriteToZip() { // Substract 1s = 1000ms from now to make sure the time is before execution long before = System.currentTimeMillis() - 1000; VFSLeaf zip = mgr.writeToZip(cp); assertNotNull("The zip file wasn't created properly", zip); assertTrue("The last modified date of the zip file wasn't updated", zip.getLastModified() > before); } @Test public void testGetElementByIdentifier() { // TODO:GW impl } }