KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > impl > basic > TestItemOrder


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002, 2003 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: TestItemOrder.java,v 1.2 2003/09/17 20:22:08 niko_schmuck Exp $
28

29 package de.nava.informa.impl.basic;
30
31 import java.net.MalformedURLException JavaDoc;
32 import java.net.URL JavaDoc;
33 import java.util.Iterator JavaDoc;
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 JavaDoc testname) {
45     super("TestItemOrder", testname);
46   }
47
48   private static ChannelIF prepare() throws MalformedURLException JavaDoc {
49     ChannelIF chA = builder.createChannel("myChannel");
50     builder.createItem(chA, "first item", "descr1", new URL JavaDoc("http://1.net/"));
51     builder.createItem(chA, "second item", "22", new URL JavaDoc("http://2.net/"));
52     builder.createItem(chA, "third item", "333", new URL JavaDoc("http://3.net/"));
53     builder.createItem(chA, "fourth item", "4", new URL JavaDoc("http://4.net/"));
54     builder.createItem(chA, "fifth item", "5555", new URL JavaDoc("http://5.net/"));
55     builder.createItem(chA, "sixth item", "6", new URL JavaDoc("http://6.net/"));
56     builder.createItem(chA, "seventh item", "7777", new URL JavaDoc("http://7.net/"));
57     builder.createItem(chA, "eight item", "8", new URL JavaDoc("http://8.net/"));
58     return chA;
59   }
60
61   public void testCreatedItemCount() throws MalformedURLException JavaDoc {
62     ChannelIF channel = prepare();
63     assertEquals(8, channel.getItems().size());
64   }
65   
66   public void testCreatedItemInOrder() throws MalformedURLException JavaDoc {
67     ChannelIF channel = prepare();
68     Iterator JavaDoc 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 JavaDoc {
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 JavaDoc("http://9.net/"));
83     assertEquals(8, channel.getItems().size());
84     Iterator JavaDoc 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 JavaDoc {
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