Examples of ItemIF


Examples of de.nava.informa.core.ItemIF

  /**
   * Tests add,delete,add item sequence.
   */
  public void testAddDeleteAddItem() {
    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);

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

      item2 = manager.createItem(channel, tuids2);

      // 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) {
      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

Examples of de.nava.informa.core.ItemIF

    */
  }

  private void compareDates(Calendar expectedCal, Object[] actualItems,
                            int index) {
    ItemIF item = (ItemIF) actualItems[index];
    // ignore milliseconds
    long milliExp = expectedCal.getTime().getTime();
    long milliAct = item.getDate().getTime();

    assertEquals("Wrong date for item " + (index+1),
                 milliExp / 1000, milliAct / 1000);
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

      tx = session.beginTransaction();
      String chanName = "Foo Test Channel";
      ChannelIF channel = builder.createChannel(chanName, "http://www.nava.de/channelTest");
      channel.setDescription("Test Channel: " + chanName);
      session.saveOrUpdate(channel);
      ItemIF item1 = builder.createItem(channel, "Item 1 for " + chanName,
                                        "First in line", new URL("http://www.sf1.net"));
      session.saveOrUpdate(item1);
      ItemIF item2 = builder.createItem(channel, "Item 2 for " + chanName,
                                        "Second in line", new URL("http://www.sf1.net"));
      session.saveOrUpdate(item2);
      session.saveOrUpdate(channel);
      tx.commit();
      chId = (int) channel.getId();
    }
    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 children
    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);
      assertEquals(1, c.getItems().size()); // The itens links where the same and it's unique
      Iterator it_items = c.getItems().iterator();
      while (it_items.hasNext()) {
        ItemIF item = (ItemIF) it_items.next();
        logger.info("  * " + item);
        assertEquals(c, item.getChannel());
      }
    }
    catch (HibernateException he) {
      logger.warn("Error while querying for channel");
      throw he;
View Full Code Here

Examples of de.nava.informa.core.ItemIF

      tx = session.beginTransaction();
      ChannelIF chA = builder.createChannel("Channel A", "http://test.org/A");
      long chA_id = chA.getId();
      chA.setDescription("test channel for hibernate backend");
      logger.info("created chA: " + chA);
      ItemIF itA = builder.createItem(chA, "Simple item", "oh what a desc",
                                      new URL("http://www.sf.net/"));
      logger.info("created itA: " + itA);
      session.save(chA);
      logger.info("saved chA");
      tx.commit();
View Full Code Here

Examples of de.nava.informa.core.ItemIF

   
    // create dummy channel
    ChannelIF channel = new Channel(ch_title);
    channel.setDescription(ch_desc);
    channel.setSite(new URL("http://nava.de"));
    ItemIF itemA = new Item("Bugo", "All about it!",
                            new URL("http://nava.de/huhu2002"));
    itemA.setFound(new Date());
    channel.addItem(itemA);
    // TODO: what about markup here ???
    ItemIF itemB = new Item("SoCool",
                            "????**$12 @??? # <strong>should</strong> work",
                            new URL("http://nava.de/very/nested/98"));
    itemB.setFound(new Date());
    channel.addItem(itemB);
    assertEquals(2, channel.getItems().size());
    // export this channel to file (encoding: utf-8)
    String basename = "export-rss091.xml";
    String exp_file = getOutputDir() + FS + basename;
    ChannelExporterIF exporter = new RSS_0_91_Exporter(exp_file);
    exporter.write(channel);

    // clean channel object
    channel = null;
   
    // read in again
    File inpFile = new File(exp_file);
    channel = FeedParser.parse(new ChannelBuilder(), inpFile);

    assertEquals(ch_title, channel.getTitle());
    assertEquals(ch_desc, channel.getDescription());
   
    Collection items = channel.getItems();
    assertEquals(2, items.size());
    Iterator it = items.iterator();
    ItemIF item = (ItemIF) it.next();
    if (item.equals(itemA)) {
      assertEquals(item, itemA);
      item = (ItemIF) it.next();
      assertEquals(item, itemB);
    } else {
      assertEquals(item, itemB);
View Full Code Here

Examples of de.nava.informa.core.ItemIF

    // create dummy channel
    ChannelIF channel = new Channel(ch_title);
    channel.setDescription(ch_desc);
    channel.setSite(new URL("http://nava.de"));
    channel.setLocation(new URL("http://nava.de/news.rdf"));
    ItemIF itemA = new Item("Bugo", "All about it!",
                            new URL("http://nava.de/huhu2002"));
    itemA.setFound(new Date());
    channel.addItem(itemA);
    // TODO: what about markup here ???
    ItemIF itemB = new Item("SoCool",
                            "????**$12 @??? # <strong>should</strong> work",
                            new URL("http://nava.de/very/nested/98"));
    itemB.setFound(new Date());
    channel.addItem(itemB);
    assertEquals(2, channel.getItems().size());
    // export this channel to file (encoding: utf-8)
    String basename = "export-rss10.xml";
    String exp_file = getOutputDir() + FS + basename;
    ChannelExporterIF exporter = new RSS_1_0_Exporter(exp_file);
    exporter.write(channel);

    // clean channel object
    channel = null;
   
    // read in again
    File inpFile = new File(exp_file);
    channel = FeedParser.parse(new ChannelBuilder(), inpFile);

    assertEquals(ch_title, channel.getTitle());
    assertEquals(ch_desc, channel.getDescription());
   
    Collection items = channel.getItems();
    assertEquals(2, items.size());
    Iterator it = items.iterator();
    ItemIF item = (ItemIF) it.next();
    if (item.equals(itemA)) {
      assertEquals(item, itemA);
      item = (ItemIF) it.next();
      assertEquals(item, itemB);
    } else {
      assertEquals(item, itemB);
View Full Code Here

Examples of de.nava.informa.core.ItemIF

  public void testCreatedItemInOrder() throws MalformedURLException {
    ChannelIF channel = prepare();
    Iterator it = channel.getItems().iterator();
    int idx = 1;
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      assertEquals("http://" + idx + ".net/", item.getLink().toString());
      idx++;
    }
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

    }
  }

  public void testCreatedItemAddOne() throws MalformedURLException {
    ChannelIF channel = prepare();
    ItemIF firstItem = (ItemIF) channel.getItems().iterator().next();
    channel.removeItem(firstItem);
    assertEquals(7, channel.getItems().size());
    builder.createItem(channel, "another one", "9", new URL("http://9.net/"));
    assertEquals(8, channel.getItems().size());
    Iterator it = channel.getItems().iterator();
    int idx = 2;
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      assertEquals("http://" + idx + ".net/", item.getLink().toString());
      idx++;
    }
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

    }
  }

  public void testRetrieveItem() throws MalformedURLException {
    ChannelIF channel = prepare();
    ItemIF firstItem = (ItemIF) channel.getItems().iterator().next();
    long firstId = firstItem.getId();   
    ItemIF retrievedItem = channel.getItem(firstId);
    assertEquals(firstItem, retrievedItem);
  }
View Full Code Here

Examples of de.nava.informa.core.ItemIF

    super("TestChannelIndexer", name);
  }

  public void testIndexItems() throws MalformedURLException, IOException {
    Collection<ItemIF> items = new ArrayList<ItemIF>();
    ItemIF itemA = new Item("Java 1.5 out", "Long awaited...",
                            new URL("http://example.org/1234"));
    items.add(itemA);
    ItemIF itemB = new Item("XML virus found", "All about it here.",
                            new URL("http://example.org/2345"));
    items.add(itemB);
    assertEquals(2, items.size());
    ChannelIndexer indexer = new ChannelIndexer(getIndexDir());
    indexer.indexItems(true, items);
View Full Code Here
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.