KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > parse > mp3 > TestMP3Parser


1 package net.nutch.parse.mp3;
2
3 import junit.framework.TestCase;
4 import net.nutch.parse.Parse;
5 import net.nutch.parse.ParseException;
6 import net.nutch.parse.Parser;
7 import net.nutch.parse.ParserFactory;
8 import net.nutch.protocol.Content;
9 import net.nutch.protocol.Protocol;
10 import net.nutch.protocol.ProtocolException;
11 import net.nutch.protocol.ProtocolFactory;
12
13 import java.util.Properties JavaDoc;
14
15 /**
16  * Unit tests for TestMP3Parser. (Adapted from John Xing msword unit tests).
17  *
18  * @author Andy Hedges
19  */

20 public class TestMP3Parser extends TestCase {
21
22   private String JavaDoc fileSeparator = System.getProperty("file.separator");
23   // This system property is defined in ./src/plugin/build-plugin.xml
24
private String JavaDoc sampleDir = System.getProperty("test.data", ".");
25   // Make sure sample files are copied to "test.data" as specified in
26
// ./src/plugin/parse-mp3/build.xml during plugin compilation.
27
// Check ./src/plugin/parse-mp3/sample/README.txt for what they are.
28
private String JavaDoc id3v1 = "postgresql-id3v1.mp3";
29   private String JavaDoc id3v2 = "postgresql-id3v2.mp3";
30   private String JavaDoc none = "postgresql-none.mp3";
31
32   public TestMP3Parser(String JavaDoc name) {
33     super(name);
34   }
35
36   protected void setUp() {
37   }
38
39   protected void tearDown() {
40   }
41
42   public void testId3v2() throws ProtocolException, ParseException {
43
44     String JavaDoc urlString;
45     Protocol protocol;
46     Content content;
47     Parser parser;
48     Parse parse;
49
50     urlString = "file:" + sampleDir + fileSeparator + id3v2;
51     protocol = ProtocolFactory.getProtocol(urlString);
52     content = protocol.getContent(urlString);
53
54     parser = ParserFactory.getParser(content.getContentType(), urlString);
55     parse = parser.getParse(content);
56     Properties JavaDoc metadata = parse.getData().getMetadata();
57     assertEquals("postgresql comment id3v2", metadata.getProperty("COMM-Text"));
58     assertEquals("postgresql composer id3v2", metadata.getProperty("TCOM-Text"));
59     assertEquals("02", metadata.getProperty("TRCK-Text"));
60     assertEquals("http://localhost/", metadata.getProperty("WCOP-URL Link"));
61     assertEquals("postgresql artist id3v2", metadata.getProperty("TPE1-Text"));
62     assertEquals("(28)", metadata.getProperty("TCON-Text"));
63     assertEquals("2004", metadata.getProperty("TYER-Text"));
64     assertEquals("postgresql title id3v2", metadata.getProperty("TIT2-Text"));
65     assertEquals("postgresql album id3v2", metadata.getProperty("TALB-Text"));
66     assertEquals("postgresql encoded by id3v2", metadata.getProperty("TENC-Text"));
67
68     assertEquals("postgresql title id3v2 - "
69         + "postgresql album id3v2 - "
70         + "postgresql artist id3v2", parse.getData().getTitle());
71     assertEquals("http://localhost/", parse.getData().getOutlinks()[0].getToUrl());
72
73   }
74
75   public void testId3v1() throws ProtocolException, ParseException {
76
77     String JavaDoc urlString;
78     Protocol protocol;
79     Content content;
80     Parser parser;
81     Parse parse;
82
83     urlString = "file:" + sampleDir + fileSeparator + id3v1;
84     protocol = ProtocolFactory.getProtocol(urlString);
85     content = protocol.getContent(urlString);
86     parser = ParserFactory.getParser(content.getContentType(), urlString);
87     parse = parser.getParse(content);
88
89     Properties JavaDoc metadata = parse.getData().getMetadata();
90     assertEquals("postgresql comment id3v1", metadata.getProperty("COMM-Text"));
91     assertEquals("postgresql artist id3v1", metadata.getProperty("TPE1-Text"));
92     assertEquals("(28)", metadata.getProperty("TCON-Text"));
93     assertEquals("2004", metadata.getProperty("TYER-Text"));
94     assertEquals("postgresql title id3v1", metadata.getProperty("TIT2-Text"));
95     assertEquals("postgresql album id3v1", metadata.getProperty("TALB-Text"));
96
97     assertEquals("postgresql title id3v1 - "
98         + "postgresql album id3v1 - "
99         + "postgresql artist id3v1", parse.getData().getTitle());
100
101   }
102
103   public void testNone() throws ProtocolException, ParseException {
104     String JavaDoc urlString;
105     Protocol protocol;
106     Content content;
107     Parser parser;
108     Parse parse;
109
110     urlString = "file:" + sampleDir + fileSeparator + none;
111     protocol = ProtocolFactory.getProtocol(urlString);
112     content = protocol.getContent(urlString);
113     parser = ParserFactory.getParser(content.getContentType(), urlString);
114     try {
115       parse = parser.getParse(content);
116       Properties JavaDoc metadata = parse.getData().getMetadata();
117     } catch (ParseException e) {
118       return;
119     }
120     fail("Expected ParseException");
121
122   }
123
124 }
125
Popular Tags