1 /**
2 * JSpiff
3 * -----------------
4 * Copyright 2005-2006 Emil A. Lefkof III
5 *
6 * I always give it my best shot to make a program useful and solid, but
7 * remeber that there is absolutely no warranty for using this program as
8 * stated in the following terms:
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23 package com.melloware.jspiff.jaxp;
24
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.sql.Timestamp;
28
29 import javax.xml.parsers.ParserConfigurationException;
30
31 import org.xml.sax.SAXException;
32
33 import junit.framework.TestCase;
34
35 /**
36 * Test case to verify creating of XspfPlaylists and adding Tracks to those
37 * playlists. This test if for the JAXP code.
38 * <p>
39 * Copyright (c) 2006
40 * Melloware, Inc. <http://www.melloware.com>
41 * @author Emil A. Lefkof III <info@melloware.com>
42 * @version 4.0
43 */
44 public class XspfJAXPTest
45 extends TestCase {
46
47 /**
48 * Constructor for XspfJAXPTest.
49 * @param arg0
50 */
51 public XspfJAXPTest(String arg0) {
52 super(arg0);
53 }
54
55 /**
56 * Tests an invalid playlist file.
57 */
58 public void testInvalidPlaylistFile() {
59
60 try {
61 final InputStream stream = getClass().getResourceAsStream("/playlist-invalid.xml");
62 final XspfPlaylist playlist = new XspfPlaylist(stream);
63 final String xml = playlist.makeTextDocument();
64 System.out.println(xml);
65 assertNotNull(xml);
66 assertNotSame(playlist.getTitle(), "XSPlF it up!");
67 assertNull(playlist.getPlaylistTrackList());
68 } catch (IOException ex) {
69 fail(ex.getMessage());
70 } catch (SAXException ex) {
71 fail(ex.getMessage());
72 } catch (ParserConfigurationException ex) {
73 fail(ex.getMessage());
74 }
75 }
76
77 /**
78 * Tests the creation of an XspfPlaylist object.
79 */
80 public void testPlaylist() {
81 final XspfPlaylist playlist = new XspfPlaylist();
82 playlist.setTitle("Melloware XSPF Playlist");
83 playlist.setCreator("Melloware User");
84 playlist.setDate(new Timestamp(System.currentTimeMillis()));
85 playlist.setInfo("http://melloware.com/");
86 playlist.setVersion("1");
87 playlist.setImage("http://melloware.com/images/header.jpg");
88 playlist.setIdentifier(Integer.toString(super.hashCode()));
89 playlist.setLicense("http://www.apache.org/licenses/LICENSE-2.0.txt");
90
91
92 final String xml = playlist.makeTextDocument();
93 System.out.println(xml);
94 assertNotNull(xml);
95
96 }
97
98 /**
99 * Tests the creation of an XspfTrack objects and appending them to a
100 * playlist.
101 */
102 public void testTracks() {
103 final XspfPlaylist playlist = new XspfPlaylist();
104 playlist.setTitle("Track Test Playlist");
105 playlist.setCreator("Melloware User");
106 playlist.setDate(new Timestamp(System.currentTimeMillis()));
107 playlist.setInfo("http://melloware.com/");
108 playlist.setVersion("1");
109 playlist.setImage("http://melloware.com/images/header.jpg");
110 playlist.setIdentifier(Integer.toString(super.hashCode()));
111 playlist.setLicense("http://www.apache.org/licenses/LICENSE-2.0.txt");
112
113
114 final XspfPlaylistTrackList tracks = new XspfPlaylistTrackList();
115
116
117 XspfTrack track = new XspfTrack();
118 track.setIdentifier("135c3af5-526f-4d87-9757-1b404b51e31d");
119 track.setLocation("C:\\music\\01 - She Talks To Angels.mp3");
120 track.setCreator("Black Crowes");
121 track.setAlbum("Shake Your Moneymaker");
122 track.setTitle("She Talks To Angels");
123 track.setAnnotation("This is a classic song");
124 track.setTrackNumByString("01");
125 track.setDurationByString("314");
126 tracks.addTrack(track);
127
128
129 track = new XspfTrack();
130 track.setIdentifier("e113c56f-c4d4-4bfb-b9f0-6f90a172b5a9");
131 track.setLocation("C:\\music\\02 - Come Together.mp3");
132 track.setCreator("Beatles");
133 track.setAlbum("Abbey Road");
134 track.setTitle("Come Together");
135 track.setAnnotation("Love the Beatles");
136 track.setTrackNumByString("02");
137 track.setDurationByString("226");
138 tracks.addTrack(track);
139
140
141 playlist.setPlaylistTrackList(tracks);
142
143
144 final String xml = playlist.makeTextDocument();
145 System.out.println(xml);
146 assertNotNull(xml);
147 }
148
149 /**
150 * Tests a valid playlist file.
151 */
152 public void testValidPlaylistFileVersion0() {
153
154 try {
155 final InputStream stream = getClass().getResourceAsStream("/playlist-valid-ver0.xml");
156
157 final XspfPlaylist playlist = new XspfPlaylist(stream);
158 assertEquals(playlist.getTitle(), "XSPlF it up!");
159
160 final XspfTrack[] array = playlist.getPlaylistTrackList().getTrack();
161 for (int i = 0; i < array.length; i++) {
162 XspfTrack element = (XspfTrack)array[i];
163 assertNotNull(element.makeTextDocument());
164
165 assertEquals(element.sizeMeta(), 1);
166 }
167 assertEquals(playlist.getAttribution_Location().length, 1);
168 assertEquals(playlist.getPlaylistTrackList().sizeTrack(), 3);
169
170
171 final String xml = playlist.makeTextDocument();
172 System.out.println(xml);
173 assertNotNull(xml);
174 } catch (IOException ex) {
175 fail(ex.getMessage());
176 } catch (SAXException ex) {
177 fail(ex.getMessage());
178 } catch (ParserConfigurationException ex) {
179 fail(ex.getMessage());
180 }
181 }
182
183 /**
184 * Tests a valid playlist file.
185 */
186 public void testValidPlaylistFileVersion1() {
187
188 try {
189 final InputStream stream = getClass().getResourceAsStream("/playlist-valid-ver1.xml");
190
191 final XspfPlaylist playlist = new XspfPlaylist(stream);
192 assertEquals(playlist.getTitle(), "Track Test Playlist");
193
194 final XspfTrack[] array = playlist.getPlaylistTrackList().getTrack();
195 for (int i = 0; i < array.length; i++) {
196 XspfTrack element = (XspfTrack)array[i];
197 assertNotNull(element.makeTextDocument());
198
199 }
200 assertEquals(playlist.getPlaylistTrackList().sizeTrack(), 2);
201
202
203 final String xml = playlist.makeTextDocument();
204 System.out.println(xml);
205 assertNotNull(xml);
206 } catch (IOException ex) {
207 fail(ex.getMessage());
208 } catch (SAXException ex) {
209 fail(ex.getMessage());
210 } catch (ParserConfigurationException ex) {
211 fail(ex.getMessage());
212 }
213 }
214
215
216
217
218 protected void setUp()
219 throws Exception {
220 super.setUp();
221 }
222
223
224
225
226 protected void tearDown()
227 throws Exception {
228 super.tearDown();
229 }
230
231 }