KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > urls > junit > StandardPieURLGeneratorTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ---------------------------------
27  * StandardPieURLGeneratorTests.java
28  * ---------------------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: StandardPieURLGeneratorTests.java,v 1.4 2005/03/09 13:44:45 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 21-Mar-2003 : Version 1 (DG);
39  * 06-Jan-2003 : Added a test for URL generation (DG);
40  *
41  */

42
43 package org.jfree.chart.urls.junit;
44
45 import java.io.ByteArrayInputStream JavaDoc;
46 import java.io.ByteArrayOutputStream JavaDoc;
47 import java.io.ObjectInput JavaDoc;
48 import java.io.ObjectInputStream JavaDoc;
49 import java.io.ObjectOutput JavaDoc;
50 import java.io.ObjectOutputStream JavaDoc;
51
52 import junit.framework.Test;
53 import junit.framework.TestCase;
54 import junit.framework.TestSuite;
55
56 import org.jfree.chart.urls.StandardPieURLGenerator;
57 import org.jfree.data.general.DefaultPieDataset;
58
59 /**
60  * Tests for the {@link StandardPieURLGenerator} class.
61  */

62 public class StandardPieURLGeneratorTests extends TestCase {
63
64     /**
65      * Returns the tests as a test suite.
66      *
67      * @return The test suite.
68      */

69     public static Test suite() {
70         return new TestSuite(StandardPieURLGeneratorTests.class);
71     }
72
73     /**
74      * Constructs a new set of tests.
75      *
76      * @param name the name of the tests.
77      */

78     public StandardPieURLGeneratorTests(String JavaDoc name) {
79         super(name);
80     }
81
82     /**
83      * Serialize an instance, restore it, and check for equality.
84      */

85     public void testSerialization() {
86
87         StandardPieURLGenerator g1 = new StandardPieURLGenerator(
88             "index.html?", "cat"
89         );
90         StandardPieURLGenerator g2 = null;
91
92         try {
93             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
94             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
95             out.writeObject(g1);
96             out.close();
97
98             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
99                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
100             );
101             g2 = (StandardPieURLGenerator) in.readObject();
102             in.close();
103         }
104         catch (Exception JavaDoc e) {
105             System.out.println(e.toString());
106         }
107         assertEquals(g1, g2);
108
109     }
110
111     /**
112      * Test that the generated URL is as expected.
113      */

114     public void testURL() {
115         DefaultPieDataset dataset = new DefaultPieDataset();
116         dataset.setValue("Alpha", new Double JavaDoc(5.0));
117         dataset.setValue("Beta", new Double JavaDoc(5.5));
118         StandardPieURLGenerator g1 = new StandardPieURLGenerator(
119             "chart.jsp", "category"
120         );
121         String JavaDoc url = g1.generateURL(dataset, "Beta", 0);
122         assertEquals("chart.jsp?category=Beta&pieIndex=0", url);
123     }
124     
125 }
126
Popular Tags