package org.codehaus.xfire.attachments;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;

import org.codehaus.xfire.test.AbstractXFireTest;

/**
 * @author <a href="mailto:dan@envoisolutiosn.com">Dan Diephouse</a>
 */
public class DataHandlerTest
    extends AbstractXFireTest
{
    public void testText()
        throws Exception
    {
        DataSource ds = new FileDataSource(
            getTestFile("src/test/org/codehaus/xfire/attachments/test.txt"));

        DataHandler handler = new DataHandler(ds);

        Object content = handler.getContent();
        assertNotNull(content);
        assertTrue(content instanceof String);
        assertEquals("bleh", content);
    }
    
    public void testImages()
        throws Exception
    {
        DataSource ds = new FileDataSource(
            getTestFile("src/test/org/codehaus/xfire/attachments/xfire_logo.jpg"));
    
        DefaultDataContentHandlerFactory factory = new DefaultDataContentHandlerFactory();

        Object content = factory.createDataContentHandler("image/jpeg").getContent(ds);
        assertNotNull(content);
        assertTrue(content instanceof java.awt.Image);
        
        ds = new FileDataSource(getTestFile("src/test/org/codehaus/xfire/attachments/fax.tif"));
        assertNotNull(ds);
        
        content = factory.createDataContentHandler("image/tiff").getContent(ds);
        assertNotNull(content);
        // FIXME: For some reason this fails on some machines...
        // assertTrue(content instanceof java.awt.Image);
    }
}

@@ -151,197 +151,1667 @@
 ce;%0A
-%0Aimport org.codehaus.xfire.test.AbstractXFireTest;%0A%0A/**%0A * @author %3Ca href=%22mailto:dan@envoisolutiosn.com%22%3EDan Diephouse%3C/a%3E%0A */%0Apublic class DataHandlerTest%0A    extends AbstractXFireTest%0A%7B
+import javax.activation.FileTypeMap;%0Aimport javax.activation.MimetypesFileTypeMap;%0A%0Aimport java.io.File;%0Aimport java.io.InputStream;%0Aimport java.io.FileInputStream;%0A%0Aimport org.codehaus.xfire.test.AbstractXFireTest;%0A%0A/**%0A * This test exercises more the Activation framework than XFire itself.%0A * @author %3Ca href=%22mailto:dan@envoisolutiosn.com%22%3EDan Diephouse%3C/a%3E%0A */%0Apublic class DataHandlerTest%0A    extends AbstractXFireTest%0A%7B%0A    // on some Linux systems, file type mapping is stored in a location%0A    // not searched by default, thus breaking this test. Let's override it temporarily%0A    private static final FileTypeMap DEFAULT_FILE_TYPE_MAP = FileTypeMap.getDefaultFileTypeMap();%0A    private static final FileTypeMap OVERRIDING_FILE_TYPE_MAP = createOverridingFileTypeMap();%0A%0A    // Note: this is not perfect: in a perfect world /etc/mime.types should be overriden by %0A    // the user ~/.mime.types file. Because of what we do here, it won't.%0A    private static final FileTypeMap createOverridingFileTypeMap()%0A    %7B%0A        File file = new File(%22/etc/mime.types%22);%0A        FileTypeMap result = DEFAULT_FILE_TYPE_MAP;%0A        if (file.exists())%0A        %7B%0A            try %7B%0A                InputStream inputStream = new FileInputStream(file);%0A                result = new MimetypesFileTypeMap(inputStream);%0A                inputStream.close();%0A            %7D catch(Exception ignored) %7B%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    protected void setUp()%0A    %7B%0A        FileTypeMap.setDefaultFileTypeMap(OVERRIDING_FILE_TYPE_MAP);%0A    %7D%0A%0A    protected void tearDown()%0A    %7B%0A        FileTypeMap.setDefaultFileTypeMap(DEFAULT_FILE_TYPE_MAP);%0A    %7D%0A%0A
 %0A   
@@ -2130,32 +2130,204 @@
      assertTrue(
+%22The content data type was not correctly detected. Check you computer/activation framework setup. %22 %0A                   + %22Expected String but got: %22 + content.getClass(), 
 content instance
@@ -3115,87 +3115,199 @@
     
-// FIXME: For some reason this fails on some machines...%0A        // assertTrue(
+assertTrue(%22The content data type was not correctly detected. Check you computer/activation framework setup. %22 %0A                   + %22Expected java.awt.Image but got: %22 + content.getClass(), 
 cont

Fix unit test. Little hack to make the test pass on a Linux environment where the mime types configuration is not read by the activation framework by default.