001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * --------------------------------
028: * TimeSeriesURLGeneratorTests.java
029: * --------------------------------
030: * (C) Copyright 2007, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: TimeSeriesURLGeneratorTests.java,v 1.1.2.2 2007/04/17 16:05:27 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 17-Apr-2007 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.chart.urls.junit;
044:
045: import java.io.ByteArrayInputStream;
046: import java.io.ByteArrayOutputStream;
047: import java.io.ObjectInput;
048: import java.io.ObjectInputStream;
049: import java.io.ObjectOutput;
050: import java.io.ObjectOutputStream;
051: import java.text.SimpleDateFormat;
052:
053: import junit.framework.Test;
054: import junit.framework.TestCase;
055: import junit.framework.TestSuite;
056:
057: import org.jfree.chart.urls.TimeSeriesURLGenerator;
058: import org.jfree.data.xy.DefaultXYDataset;
059:
060: /**
061: * Tests for the {@link TimeSeriesURLGenerator} class.
062: */
063: public class TimeSeriesURLGeneratorTests extends TestCase {
064:
065: /**
066: * Returns the tests as a test suite.
067: *
068: * @return The test suite.
069: */
070: public static Test suite() {
071: return new TestSuite(TimeSeriesURLGeneratorTests.class);
072: }
073:
074: /**
075: * Constructs a new set of tests.
076: *
077: * @param name the name of the tests.
078: */
079: public TimeSeriesURLGeneratorTests(String name) {
080: super (name);
081: }
082:
083: /**
084: * A basic check for the generateURL() method.
085: */
086: public void testGenerateURL() {
087: TimeSeriesURLGenerator g = new TimeSeriesURLGenerator();
088: DefaultXYDataset dataset = new DefaultXYDataset();
089: dataset.addSeries("Series '1'", new double[][] { { 1.0, 2.0 },
090: { 3.0, 4.0 } });
091: String s = g.generateURL(dataset, 0, 0);
092: assertTrue(s
093: .startsWith("index.html?series=Series+%271%27&item="));
094: }
095:
096: /**
097: * Check that the equals() method can distinguish all fields.
098: */
099: public void testEquals() {
100: TimeSeriesURLGenerator g1 = new TimeSeriesURLGenerator();
101: TimeSeriesURLGenerator g2 = new TimeSeriesURLGenerator();
102: assertTrue(g1.equals(g2));
103:
104: g1 = new TimeSeriesURLGenerator(new SimpleDateFormat("yyyy"),
105: "prefix", "series", "item");
106: assertFalse(g1.equals(g2));
107: g2 = new TimeSeriesURLGenerator(new SimpleDateFormat("yyyy"),
108: "prefix", "series", "item");
109: assertTrue(g1.equals(g2));
110:
111: g1 = new TimeSeriesURLGenerator(new SimpleDateFormat("yy"),
112: "prefix", "series", "item");
113: assertFalse(g1.equals(g2));
114: g2 = new TimeSeriesURLGenerator(new SimpleDateFormat("yy"),
115: "prefix", "series", "item");
116: assertTrue(g1.equals(g2));
117:
118: g1 = new TimeSeriesURLGenerator(new SimpleDateFormat("yy"),
119: "prefix1", "series", "item");
120: assertFalse(g1.equals(g2));
121: g2 = new TimeSeriesURLGenerator(new SimpleDateFormat("yy"),
122: "prefix1", "series", "item");
123: assertTrue(g1.equals(g2));
124:
125: g1 = new TimeSeriesURLGenerator(new SimpleDateFormat("yy"),
126: "prefix1", "series1", "item");
127: assertFalse(g1.equals(g2));
128: g2 = new TimeSeriesURLGenerator(new SimpleDateFormat("yy"),
129: "prefix1", "series1", "item");
130: assertTrue(g1.equals(g2));
131:
132: g1 = new TimeSeriesURLGenerator(new SimpleDateFormat("yy"),
133: "prefix1", "series1", "item1");
134: assertFalse(g1.equals(g2));
135: g2 = new TimeSeriesURLGenerator(new SimpleDateFormat("yy"),
136: "prefix1", "series1", "item1");
137: assertTrue(g1.equals(g2));
138: }
139:
140: /**
141: * Serialize an instance, restore it, and check for equality.
142: */
143: public void testSerialization() {
144:
145: TimeSeriesURLGenerator g1 = new TimeSeriesURLGenerator();
146: TimeSeriesURLGenerator g2 = null;
147:
148: try {
149: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
150: ObjectOutput out = new ObjectOutputStream(buffer);
151: out.writeObject(g1);
152: out.close();
153:
154: ObjectInput in = new ObjectInputStream(
155: new ByteArrayInputStream(buffer.toByteArray()));
156: g2 = (TimeSeriesURLGenerator) in.readObject();
157: in.close();
158: } catch (Exception e) {
159: e.printStackTrace();
160: }
161: assertEquals(g1, g2);
162:
163: }
164:
165: }
|