Author: nick
Date: Tue Dec 23 06:43:18 2014
New Revision: 1647489

URL: http://svn.apache.org/r1647489
Log:
Fix test for TIKA-1502 - re-order the MediaTypeRegistry logic for getting the 
super type, so that if an explicit inheritance has been defined between one 
parametered type and another, that inheritance is used in preference to "drop 
all parameters"

Modified:
    
tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MediaTypeRegistry.java
    
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java
    
tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java

Modified: 
tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MediaTypeRegistry.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MediaTypeRegistry.java?rev=1647489&r1=1647488&r2=1647489&view=diff
==============================================================================
--- 
tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MediaTypeRegistry.java 
(original)
+++ 
tika/trunk/tika-core/src/main/java/org/apache/tika/mime/MediaTypeRegistry.java 
Tue Dec 23 06:43:18 2014
@@ -153,12 +153,12 @@ public class MediaTypeRegistry implement
     }
 
     /**
-     * Returns the supertype of the given type. If the given type has any
-     * parameters, then the respective base type is returned. Otherwise
-     * built-in heuristics like text/... -> text/plain and
-     * .../...+xml -> application/xml are used in addition to explicit
-     * type inheritance rules read from the media type database. Finally
-     * application/octet-stream is returned for all types for which no other
+     * Returns the supertype of the given type. If the media type database
+     * has an explicit inheritance rule for the type, then that is used. 
+     * Next, if the given type has any parameters, then the respective base 
+     * type (parameter-less) is returned. Otherwise built-in heuristics like 
+     * text/... -> text/plain and .../...+xml -> application/xml are 
used. 
+     * Finally application/octet-stream is returned for all types for which no 
other
      * supertype is known, and the return value for application/octet-stream
      * is <code>null</code>.
      *
@@ -169,10 +169,10 @@ public class MediaTypeRegistry implement
     public MediaType getSupertype(MediaType type) {
         if (type == null) {
             return null;
-        } else if (type.hasParameters()) {
-            return type.getBaseType();
         } else if (inheritance.containsKey(type)) {
             return inheritance.get(type);
+        } else if (type.hasParameters()) {
+            return type.getBaseType();
         } else if (type.getSubtype().endsWith("+xml")) {
             return MediaType.APPLICATION_XML;
         } else if (type.getSubtype().endsWith("+zip")) {

Modified: 
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java?rev=1647489&r1=1647488&r2=1647489&view=diff
==============================================================================
--- 
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java
 (original)
+++ 
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeTypesReaderTest.java
 Tue Dec 23 06:43:18 2014
@@ -24,7 +24,6 @@ import java.util.List;
 import org.apache.tika.config.TikaConfig;
 import org.apache.tika.metadata.Metadata;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -143,10 +142,8 @@ public class MimeTypesReaderTest {
             mime.getLinks().get(0).toString());
     }
     
-    // TODO Get this to work - currently jumps two levels!
     @Test
-    @Ignore
-    public void testReadParameterHeirarchy() throws Exception {
+    public void testReadParameterHierarchy() throws Exception {
         MimeType mimeBTree4 = 
this.mimeTypes.forName("application/x-berkeley-db;format=btree;version=4");
         MediaType mtBTree4 = mimeBTree4.getType();
         

Modified: 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java?rev=1647489&r1=1647488&r2=1647489&view=diff
==============================================================================
--- 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java 
(original)
+++ 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/mime/TestMimeTypes.java 
Tue Dec 23 06:43:18 2014
@@ -587,7 +587,8 @@ public class TestMimeTypes {
              
repo.getMediaTypeRegistry().getSupertype(getTypeByNameAndData("testDITA.ditamap")).toString());
        assertEquals("application/dita+xml", 
              
repo.getMediaTypeRegistry().getSupertype(getTypeByNameAndData("testDITA.dita")).toString());
-       assertEquals("application/dita+xml", 
+       // Concept inherits from topic
+       assertEquals("application/dita+xml; format=topic", 
              
repo.getMediaTypeRegistry().getSupertype(getTypeByNameAndData("testDITA2.dita")).toString());
     }
 


Reply via email to