Package de.nava.informa.core

Examples of de.nava.informa.core.ItemIF


  public void testCreatedItems() {
    assertEquals(6, channel.getItems().size());
    Iterator it = channel.getItems().iterator();
    assertNotNull("Could not get items iterator", it);
    ItemIF item = searchForItem(channel, "Revised");
    assertNotNull("Item not found", item);
    assertEquals("Revised DOM Level 3 drafts", item.getTitle());
    assertEquals("http://www.xmlhack.com/read.php?item=1612",
                 item.getLink().toString());
    assertEquals(196, item.getDescription().length());
    assertNotNull(item.getFound());
    Date now = new Date();
    assertTrue(now.after(item.getFound()));
  }
View Full Code Here


  public void testObserve() {
    ChannelIF channel = new Channel("Niko's log");
    SimpleChannelObserver observer = new SimpleChannelObserver();
    ((ChannelObservableIF) channel).addObserver(observer);
    assertEquals(0, channel.getItems().size());
    ItemIF item = new Item("Bongo", "Rongoo", null);
    channel.addItem(item);
    assertEquals(1, channel.getItems().size());
    assertTrue(channel.getItems().contains(item));
    assertEquals(item, observer.getMyAddedItem());
   
View Full Code Here

  // =====================================================================
  // internal helper methods
  // =====================================================================
 
  protected ItemIF searchForItem(ChannelIF chn, String itmTitle) {
    ItemIF lookup_item = null;
    Iterator it = chn.getItems().iterator();
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      assertNotNull("Item has no title", item.getTitle());
      assertNotNull("Item has no link", item.getLink());
      // logger.debug("title: <" + item.getTitle() + ">");
      if (item.getTitle().startsWith(itmTitle)) {
        lookup_item = item;
        break;
      }
    }
    return lookup_item;
View Full Code Here

      int items;
      for (items = 0; items < 20; items++) {
        boolean unreadflag = ((items > 0 && items < 5))
          || (items > 10 && items < 15);
        String desc = unreadflag ? "UnreadItem" : "ReadItem";
        ItemIF anItem = builder.createItem(channel, "Item: " + items, desc, new URL("http://www.sf.net"));
        anItem.setUnRead(unreadflag);
      }
      session.save(channel);
      chId = (int) channel.getId();
      tx.commit();
    }
    catch (HibernateException he) {
      logger.warn("trying to rollback the transaction");
      if (tx != null) tx.rollback();
      throw he;
    }
    assertTrue("No valid channel created.", chId >= 0);

    // -- try to retrieve channel and check the unread statuses
    try {
      logger.info("Searching for channel " + chId);
      Object result = session.get(Channel.class, new Long(chId));
      assertNotNull(result);
      ChannelIF c = (ChannelIF) result;
      logger.info("retrieved channel --> " + c);

      // now check unread settings
      Iterator itemsIter = c.getItems().iterator();
      while (itemsIter.hasNext()) {
        ItemIF anItem = (ItemIF) itemsIter.next();
        if (anItem.getUnRead())
            assertTrue("Item marked as Unread isn't supposed to be Unread",
                anItem.getDescription().compareTo("UnreadItem") == 0);
        if (!anItem.getUnRead())
            assertTrue("Item marked as Read isn't supposed to be Read", anItem
                .getDescription().compareTo("ReadItem") == 0);
      }
    } catch (HibernateException he) {
      logger.warn("Error while querying for channel");
      throw he;
View Full Code Here

    assertEquals("http://www.movabletype.org/?v=2.51", attribute);
  }

  public void testCreatedItems() {
    assertEquals(15, channel.getItems().size());
    ItemIF item = searchForItem(channel, "We know what culture is");
    assertNotNull("Item not found", item);
    assertEquals("We know what culture is, right?", item.getTitle());
    assertEquals("http://bloggy.com/mt/archives/000842.html",
                 item.getLink().toString());
    assertEquals(100, item.getDescription().length());
    assertEquals("War", item.getSubject());
    assertEquals("barry", item.getCreator());
    Calendar expDate = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    expDate.set(2003, Calendar.APRIL, 1, 18, 43, 21);
    expDate.set(Calendar.MILLISECOND, 0);
    assertEquals(expDate.getTime(), item.getDate());
  }
View Full Code Here

   * @see de.nava.informa.core.ItemIF#equals
   *
   * @throws Exception in case of any exceptions
   */
  public void testHowDifferentImplementationsMatching() throws Exception {
    ItemIF item1, item2;

    item1 = new Item("a", "b", new URL("file://a"));
    item2 = new SimpleItem("a", "b", new URL("file://a"));
    assertTrue(item1.equals(item2));

    item1 = new Item("a", "b", new URL("file://a"));
    item2 = new SimpleItem("a", "b", new URL("file://b"));
    assertFalse(item1.equals(item2));

    item1 = new Item("a", "b", new URL("file://a"));
    item2 = new SimpleItem("a", "b", new URL("file://A"));
    assertTrue(item1.equals(item2));
  }
View Full Code Here

   * @see PersistenceManagerIF#deleteChannel
   */
  public void testDeleteChannelCascade() {
    ChannelGroupIF group = null;
    ChannelIF channel = null;
    ItemIF item1 = null;
    ItemIF item2 = null;

    try {
      // Create group and channel with two items
      group = manager.createGroup(tuids1);
      channel = manager.createChannel(tuids1, url1);
      item1 = manager.createItem(channel, tuids1);
      item2 = manager.createItem(channel, tuids2);

      // Put channel in group
      manager.addChannelToGroup(channel, group);

      // Delete channel
      manager.deleteChannel(channel);

      // Check that it was removed from parent group and all of its items gone too
      assertEquals("Group still has channels.", 0, group.getAll().size());
      assertEquals("Channel still has items.", 0, channel.getItems().size());
      assertEquals("Item still has initialized ID.", -1, item1.getId());
      assertEquals("Item still has initialized ID.", -1, item2.getId());
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail();
    } finally {
      // Delete channel, group and items
      try {
        if (item1 != null && item1.getId() != -1) manager.deleteItem(item1);
        if (item2 != null && item2.getId() != -1) manager.deleteItem(item2);
        if (channel != null && channel.getId() != -1) manager.deleteChannel(channel);
        if (group != null && group.getId() != -1) manager.deleteGroup(group);
      } catch (PersistenceManagerException e) {
        // We can do nothing here
      }
View Full Code Here

   *
   * @see PersistenceManagerIF#createItem
   */
  public void testCreateItem() {
    ChannelIF channel = null;
    ItemIF item = null;

    try {
      // Create channel and item
      channel = manager.createChannel(tuids1, url1);
      item = manager.createItem(channel, tuids2);

      // Check item
      assertNotNull(item);
      assertEquals("Title isn't properly initialized.", tuids2, item.getTitle());

      // Check channel
      final Collection items = channel.getItems();
      assertNotNull(items);
      assertEquals("Item was not correclty added to the channel.", 1, items.size());
View Full Code Here

   * @see PersistenceManagerIF#createItem
   */
  public void testCreateItemFromItem() {
    ChannelIF channel1 = null;
    ChannelIF channel2 = null;
    ItemIF item1 = null;
    ItemIF item2 = null;

    try {
      // Create two channels and item
      channel1 = manager.createChannel(tuids1, url1);
      channel2 = manager.createChannel(tuids2, url1);
View Full Code Here

   *
   * @see PersistenceManagerIF#deleteItem
   */
  public void testDeleteItem() {
    ChannelIF channel = null;
    ItemIF item1 = null;
    ItemIF item2 = null;

    try {
      // Create channel with two items
      channel = manager.createChannel(tuids1, url1);
      item1 = manager.createItem(channel, tuids1);
      item2 = manager.createItem(channel, tuids2);

      // Delete first item
      manager.deleteItem(item1);

      // Check item and channel
      assertEquals("Item ID should be in uninitialized state (-1).", -1, item1.getId());

      final Collection items = channel.getItems();
      assertNotNull(items);
      assertEquals("Number of items in list is incorrect.", 1, items.size());
      assertTrue("Wrong item was removed.", item2 == items.iterator().next());
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail();
    } finally {
      // Delete items and channel
      try {
        if (item1 != null && item1.getId() != -1) manager.deleteItem(item1);
        if (item2 != null && item2.getId() != -1) manager.deleteItem(item2);
        if (channel != null && channel.getId() != -1) manager.deleteChannel(channel);
      } catch (PersistenceManagerException e) {
        // We can do nothing here.
      }
    }
View Full Code Here

TOP

Related Classes of de.nava.informa.core.ItemIF

Copyright © 2018 www.massapicom. 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.