1 26 27 29 package de.nava.informa.impl.basic; 30 31 import java.net.MalformedURLException ; 32 import java.net.URL ; 33 import java.util.Iterator ; 34 35 import de.nava.informa.core.ChannelBuilderIF; 36 import de.nava.informa.core.ChannelIF; 37 import de.nava.informa.core.ItemIF; 38 import de.nava.informa.utils.InformaTestCase; 39 40 public class TestItemOrder extends InformaTestCase { 41 42 private static ChannelBuilderIF builder = new ChannelBuilder(); 43 44 public TestItemOrder(String testname) { 45 super("TestItemOrder", testname); 46 } 47 48 private static ChannelIF prepare() throws MalformedURLException { 49 ChannelIF chA = builder.createChannel("myChannel"); 50 builder.createItem(chA, "first item", "descr1", new URL ("http://1.net/")); 51 builder.createItem(chA, "second item", "22", new URL ("http://2.net/")); 52 builder.createItem(chA, "third item", "333", new URL ("http://3.net/")); 53 builder.createItem(chA, "fourth item", "4", new URL ("http://4.net/")); 54 builder.createItem(chA, "fifth item", "5555", new URL ("http://5.net/")); 55 builder.createItem(chA, "sixth item", "6", new URL ("http://6.net/")); 56 builder.createItem(chA, "seventh item", "7777", new URL ("http://7.net/")); 57 builder.createItem(chA, "eight item", "8", new URL ("http://8.net/")); 58 return chA; 59 } 60 61 public void testCreatedItemCount() throws MalformedURLException { 62 ChannelIF channel = prepare(); 63 assertEquals(8, channel.getItems().size()); 64 } 65 66 public void testCreatedItemInOrder() throws MalformedURLException { 67 ChannelIF channel = prepare(); 68 Iterator it = channel.getItems().iterator(); 69 int idx = 1; 70 while (it.hasNext()) { 71 ItemIF item = (ItemIF) it.next(); 72 assertEquals("http://" + idx + ".net/", item.getLink().toString()); 73 idx++; 74 } 75 } 76 77 public void testCreatedItemAddOne() throws MalformedURLException { 78 ChannelIF channel = prepare(); 79 ItemIF firstItem = (ItemIF) channel.getItems().iterator().next(); 80 channel.removeItem(firstItem); 81 assertEquals(7, channel.getItems().size()); 82 builder.createItem(channel, "another one", "9", new URL ("http://9.net/")); 83 assertEquals(8, channel.getItems().size()); 84 Iterator it = channel.getItems().iterator(); 85 int idx = 2; 86 while (it.hasNext()) { 87 ItemIF item = (ItemIF) it.next(); 88 assertEquals("http://" + idx + ".net/", item.getLink().toString()); 89 idx++; 90 } 91 } 92 93 public void testRetrieveItem() throws MalformedURLException { 94 ChannelIF channel = prepare(); 95 ItemIF firstItem = (ItemIF) channel.getItems().iterator().next(); 96 long firstId = firstItem.getId(); 97 ItemIF retrievedItem = channel.getItem(firstId); 98 assertEquals(firstItem, retrievedItem); 99 } 100 101 } 102 | Popular Tags |