1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.tika.parser.asm;
18  
19  import junit.framework.TestCase;
20  
21  import org.apache.tika.Tika;
22  import org.apache.tika.metadata.Metadata;
23  
24  /**
25   * Test case for parsing Java class files.
26   */
27  public class ClassParserTest extends TestCase {
28  
29      public void testClassParsing() throws Exception {
30          String path = "/test-documents/AutoDetectParser.class";
31          Metadata metadata = new Metadata();
32          String content = new Tika().parseToString(
33                  ClassParserTest.class.getResourceAsStream(path), metadata);
34  
35          assertEquals("AutoDetectParser", metadata.get(Metadata.TITLE));
36          assertEquals(
37                  "AutoDetectParser.class",
38                  metadata.get(Metadata.RESOURCE_NAME_KEY));
39  
40          assertTrue(content.contains("package org.apache.tika.parser;"));
41          assertTrue(content.contains(
42                  "class AutoDetectParser extends CompositeParser"));
43          assertTrue(content.contains(
44                  "private org.apache.tika.mime.MimeTypes types"));
45          assertTrue(content.contains(
46                  "public void parse("
47                  + "java.io.InputStream, org.xml.sax.ContentHandler,"
48                  + " org.apache.tika.metadata.Metadata) throws"
49                  + " java.io.IOException, org.xml.sax.SAXException,"
50                  + " org.apache.tika.exception.TikaException;"));
51          assertTrue(content.contains(
52                  "private byte[] getPrefix(java.io.InputStream, int)"
53                  + " throws java.io.IOException;"));
54      }
55  
56  }