Package org.olat.modules.ims.cp

Source Code of org.olat.modules.ims.cp.CPManagerTest

/**
* 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.modules.ims.cp;

import org.apache.log4j.Logger;
import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.id.OLATResourceable;
import org.olat.core.test.OlatTestCase;
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;

/**
* The test class for the CPManager and its implementation.
*
* <P>
* Initial Date: Jun 11, 2009 <br>
*
* @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(CPManagerTest.class.getName());
  private final CPManager mgr;
  private ContentPackage cp;

  public CPManagerTest() {
    super("CPManagerTest");
    mgr = CPManager.getInstance();
  }

  /**
   * SetUp is called before each test
   */
  public void setUp() {
    // create some users with user manager
    try {
      log.info("setUp start ------------------------");
      DBFactory.getJunitInstance().clearDatabase();

      OLATResourceable ores = OresHelper.createOLATResourceableInstance(this.getClass(), System.currentTimeMillis());
      cp = mgr.createNewCP(ores, PAGE_TITLE);

      if (cp==null) {
        throw new IllegalStateException("Could not create cp for PAGE_TITLE="+PAGE_TITLE+", ores="+ores+" with mgr="+mgr);
      }
     
    } catch(RuntimeException re) {
      re.printStackTrace(System.out);
      log.error("RuntimeException in setUp(): " + re);
      throw re;
    } catch (Exception e) {
      e.printStackTrace(System.out);
      log.error("Exception in setUp(): " + e);
      throw new RuntimeException("Exception encountered in setUp: "+e.getMessage(), e);
    }
  }

  /**
   * TearDown is called after each test
   */
  public void tearDown() {
    cp.getRootDir().delete();
    try {
      DBFactory.getInstance().closeSession();
    } catch (Exception e) {
      log.error("Exception in tearDown(): " + e);
    }
  }

  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());
  }

  public void testCreateNewCP() {
  // Tested through setup. Foundation for the other tests.
  }

  public void testIsSingleUsedResource() {
  // mgr.isSingleUsedResource(res, cp);
  }

  public void testAddBlankPage() {
    final String pageTitle = "the blank page";
    String ident = mgr.addBlankPage(cp, pageTitle);
    assertNotNull(ident);
   
  }

  public void testUpdatePage() {
  // TODO:GW impl
  }

  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);
  }

  public void testRemoveElement() {
  // TODO:GW impl
  }

  public void testMoveElement() {
  // TODO:GW impl
  }

  public void testCopyElement() {
  // TODO:GW impl
  }

  public void testGetDocument() {
  // TODO:GW impl
  }

  public void testGetItemTitle() {
    String title = mgr.getItemTitle(cp, ITEM_ID);
    assertNotNull(title);
    assertEquals(PAGE_TITLE, title);
  }

  public void testGetTreeDataModel() {
  // TODO:GW impl
  }

  public void testGetFirstOrganizationInManifest() {
  // TODO:GW impl
  }

  public void testGetFirstPageToDisplay() {
  // this method basically just returns the first element in the cp
  }

  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);
  }

  public void testWriteToFile() {
    mgr.writeToFile(cp); // Throws exception on failure
  }

  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);
  }

  public void testGetElementByIdentifier() {
  // TODO:GW impl
  }

}
TOP

Related Classes of org.olat.modules.ims.cp.CPManagerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.