Package de.nava.informa.core

Examples of de.nava.informa.core.ChannelIF


   * Tests deletion of items.
   *
   * @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


  /**
   * 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

  public void testConcItemCreation()
  {
    final int itemsCount = 100;

    // Create empty channel
    ChannelIF chan = null;
    try {
      chan = manager.createChannel(tuids1, url1);
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      fail("Failed to create test channel.");
    }

    final ChannelIF channel = chan;

    // Create new thread which will be waiting for notification to start
    // creation of 10 items
    final RacingThread thread = new RacingThread(new ExRunnable() {

      /**
       * Runs the task and throws our any exceptions.
       *
       * @throws Exception in any case.
       */
      public void run() throws Exception {
        for (int i = 0; i < itemsCount; i++)
        {
          manager.createItem(channel, "i_tread_" + i);
        }
      }
    });

    // Start race
    boolean failed = false;
    thread.start();
    try {
      for (int i = 0; i < itemsCount; i++)
      {
        manager.createItem(channel, "i_" + i);
      }
    } catch (PersistenceManagerException e) {
      e.printStackTrace();
      failed = true;
    } finally {
      thread.waitForFinish();
    }

    // Check the results
    assertFalse("Main thread failed.", failed);
    if (thread.hasFailed()) {
      thread.getException().printStackTrace();
      fail("Racer thread failed.");
    }

    assertEquals("Incorrect number of items in channel.",
      itemsCount * 2, channel.getItems().size());
  }
View Full Code Here

  }

  public void testSort() throws Exception {

    File inpFile = new File(getDataDir(), "snipsnap-org.rss");
    ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

    // convert from List to Array
    Set<ItemIF> itemsSet = channel.getItems();
    ItemIF[] items = itemsSet.toArray(new ItemIF[itemsSet.size()]);
    // sort news items
    Arrays.sort(items, new ItemComparator(true));

    // compare dates
View Full Code Here

    CacheSettings cs = new CacheSettings();
    cs.setDefaultTtl(2000);

    File inpFile = new File(getDataDir(), "xmlhack-0.91.xml");
    try {
      ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

      //test RSS0.91 behavior
      assertEquals(2000, cs.getTtl(channel, -1L));

      String url = new Feed(channel).getLocation().toString();
View Full Code Here

    CacheSettings cs = new CacheSettings();
    cs.setDefaultTtl(2000);

    File inpFile = new File(getDataDir(), "xmlhack-0.91.xml");
    try {
      ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

      //test RSS0.91 behavior
      assertEquals(2000L, cs.getTtl(channel, 10000L)); // ttl < MINIMAL_TTL
      assertEquals(360000L, cs.getTtl(channel, 360000L)); // ttl > MINIMAL_TTL
View Full Code Here

    CacheSettings cs = new CacheSettings();
    cs.setDefaultTtl(2000);

    File inpFile = new File(getDataDir(), "bloggy.rdf");
    try {
      ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

      //test RSS1.00 behavior
      assertEquals(2000, cs.getTtl(channel, -1L));
      assertEquals(2000L, cs.getTtl(channel, 10000L)); // ttl < MINIMAL_TTL
      assertEquals(360000L, cs.getTtl(channel, 360000L)); // ttl > MINIMAL_TTL
View Full Code Here

    CacheSettings cs = new CacheSettings();
    cs.setDefaultTtl(2000);

    File inpFile = new File(getDataDir(), "slashdot-010604.rdf");
    try {
      ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

      //UpdatePeriod/UpdateFrequency = hourly/1 in feed
      assertEquals(3600000, cs.getTtl(channel, -1L));
      assertEquals(3600000, cs.getTtl(channel, 10000L));
      assertEquals(3600005, cs.getTtl(channel, 3600005)); // > ttl of the feed
View Full Code Here

    CacheSettings cs = new CacheSettings();
    cs.setDefaultTtl(2000);

    File inpFile = new File(getDataDir(), "mobitopia.xml");
    try {
      ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

      //test RSS2.00 behavior
      assertEquals((60*60*1000), cs.getTtl(channel, -1L));
      assertEquals((60*60*1000), cs.getTtl(channel, 10000L));
      // < ttl of feed && > MINIMAL_TTL
View Full Code Here

    CacheSettings cs = new CacheSettings();
    cs.setDefaultTtl(3000);

    File inpFile = new File(getDataDir(), "xmlhack-0.91.xml");
    try {
      ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile);

      //test RSS0.91 behavior
      // default ttl used
      assertEquals(3000, cs.getTtl(channel, -1L));
View Full Code Here

TOP

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

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.