Package org.olat.modules.webFeed

Source Code of org.olat.modules.webFeed.FeedManagerImplTest

/**
* 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.webFeed;

import org.olat.core.id.OLATResourceable;
import org.olat.core.test.OlatTestCase;
import org.olat.core.util.CodeHelper;
import org.olat.core.util.vfs.VFSContainer;
import org.olat.modules.webFeed.managers.FeedManagerImpl;
import org.olat.modules.webFeed.models.Feed;
import org.olat.modules.webFeed.models.Item;

/**
* JUnit tests for <code>FeedManager</code> methods.
*
* <P>
* Initial Date: Feb 16, 2009 <br>
*
* @author Gregor Wassmann
*/
public class FeedManagerImplTest extends OlatTestCase {
  // private static final OLog log = Tracing.createLoggerFor(I18nTest.class);
  private FeedManagerImpl feedManager;
  private Feed feed;
  private static final String PODCAST_TITLE = "My Test Feed";

  /**
   * Test Constructor
   */
  public FeedManagerImplTest() {
    super("FeedManagerImplTest");
    // Test the feed manager implementation.
    feedManager = new FeedManagerImpl();
  }

  /**
   * @see junit.framework.TestCase#setUp()
   */
  public void setUp() {
    // Create a feed that can be read, updated or deleted.
    OLATResourceable podcastResource = feedManager.createPodcastResource();
    feed = feedManager.readFeed(podcastResource);
    feed.setTitle(PODCAST_TITLE);
    feedManager.updateFeedMetadata(feed);

    // Add an episode
    // A feed can only be edited when it is an internal feed (meaning that
    // it is made within OLAT). Obviously, external feeds cannot be changed.
    Item item = new Item();
    item.setTitle("My Test Item");
    feed = feedManager.updateFeedMode(Boolean.FALSE, feed);
    feedManager.addItem(item, null, feed);
  }

  /**
   * @see junit.framework.TestCase#tearDown()
   */
  public void tearDown() {
    feedManager.delete(feed);
  }

  /**
   * Test method create
   */
  public void testCreatePodcast() {
    OLATResourceable podcastResource = feedManager.createPodcastResource();
    Feed newPodcast = feedManager.readFeed(podcastResource);
    assertNotNull(newPodcast);
    assertNotNull(newPodcast.getId());

    // Has a feed folder been created?
    VFSContainer podcastContainer = feedManager.getFeedContainer(newPodcast);
    assertNotNull(podcastContainer);
    feedManager.delete(newPodcast);
  }

  /**
   * Test method read
   */
  public void testReadPodcast() {
    Feed readPodcast = feedManager.readFeed(feed);
    assertNotNull(readPodcast);
    assertNotNull(readPodcast.getId());
    assertEquals(PODCAST_TITLE, readPodcast.getTitle());
  }

  /**
   * Test method update
   */
  public void testUpdate() {
    feed.setTitle("The title changed");
    feedManager.updateFeedMetadata(feed);
    // re-read for assertion
    Feed readPodcast = feedManager.readFeed(feed);
    assertEquals(feed.getTitle(), readPodcast.getTitle());
  }

  /**
   * Test method delete
   */
  public void testDelete() {
    // int initialCount = feedManager.podcastCount();
    feedManager.delete(feed);
    // int newCount = feedManager.podcastCount();
    // assertEquals(initialCount - 1, newCount);
    // assertNull(feed);
  }

  /**
   * Test method add
   */
  public void testAdd() {
    Item newEpisode = new Item();
    newEpisode.setGuid(CodeHelper.getGlobalForeverUniqueID());
    newEpisode.setTitle("This is my new Item");
    // Count episodes before
    int initialCount = feed.getItems().size();
    feedManager.addItem(newEpisode, null, feed);
    // re-read feed and count episodes
    feed = feedManager.readFeed(feed);
    int newCount = feed.getItems().size();
    // Compare
    assertEquals(initialCount + 1, newCount);
  }

  /**
   * Test method remove
   */
  public void testRemove() {
    Item item = feed.getItems().get(0);
    // Count episodes before
    int initialCount = feed.getItems().size();
    feedManager.remove(item, feed);
    // re-read feed and count episodes after adding a new one
    feed = feedManager.readFeed(feed);
    int newCount = feed.getItems().size();
    // Compare
    assertEquals(initialCount - 1, newCount);
  }
}
TOP

Related Classes of org.olat.modules.webFeed.FeedManagerImplTest

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.