Search in sources :

Example 1 with MimeTypeMapper

use of ddf.mime.MimeTypeMapper in project ddf by codice.

the class ContentProducerDataAccessObjectTest method testGetMimeType.

@Test
public void testGetMimeType() throws Exception {
    File testFile1 = temporaryFolder.newFile("testGetMimeType1.xml");
    File testFile2 = temporaryFolder.newFile("testGetMimeType2.txt");
    //mock out two different ways for getting mimeType
    MimeTypeMapper mockMimeTypeMapper = mock(MimeTypeMapper.class);
    doReturn("guess").when(mockMimeTypeMapper).guessMimeType(any(), any());
    doReturn("extension").when(mockMimeTypeMapper).getMimeTypeForFileExtension(any());
    //mock out Component that returns mockMimeTypeMapper when the mimeTypeMapper is requested
    ContentComponent mockComponent = mock(ContentComponent.class);
    doReturn(mockMimeTypeMapper).when(mockComponent).getMimeTypeMapper();
    //mock out ContentEndpoint that returns the mockComponent
    ContentEndpoint mockEndpoint = mock(ContentEndpoint.class);
    doReturn(mockComponent).when(mockEndpoint).getComponent();
    //assert the mock mimeTypeMappers are reached if/not xml
    assertThat(contentProducerDataAccessObject.getMimeType(mockEndpoint, testFile1).equals("guess"), is(true));
    assertThat(contentProducerDataAccessObject.getMimeType(mockEndpoint, testFile2).equals("extension"), is(true));
}
Also used : MimeTypeMapper(ddf.mime.MimeTypeMapper) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File) Test(org.junit.Test)

Example 2 with MimeTypeMapper

use of ddf.mime.MimeTypeMapper in project ddf by codice.

the class FileSystemStorageProviderTest method setUp.

@Before
public void setUp() throws IOException {
    tempFolder.create();
    baseDir = tempFolder.getRoot().getAbsolutePath();
    baseTmpDir = baseDir + File.separator + FileSystemStorageProvider.DEFAULT_TMP;
    MimeTypeResolver resolver = new MockMimeTypeResolver();
    MimeTypeMapper mapper = new MimeTypeMapperImpl(Collections.singletonList(resolver));
    this.provider = new FileSystemStorageProvider();
    try {
        provider.setBaseContentDirectory(baseDir);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    provider.setMimeTypeMapper(mapper);
}
Also used : MimeTypeResolver(ddf.mime.MimeTypeResolver) MimeTypeMapper(ddf.mime.MimeTypeMapper) MimeTypeMapperImpl(ddf.mime.mapper.MimeTypeMapperImpl) IOException(java.io.IOException) Before(org.junit.Before)

Example 3 with MimeTypeMapper

use of ddf.mime.MimeTypeMapper in project ddf by codice.

the class MimeTypeMapperTest method testGuessMimeTypeForXmlIngestNoExtension.

@Test
public void testGuessMimeTypeForXmlIngestNoExtension() throws Exception {
    MimeTypeMapper mapper = new MimeTypeMapperImpl(MOCK_MIME_TYPE_RESOLVERS);
    InputStream is = FileUtils.openInputStream(new File(CSW_RECORD_FILE_NO_EXTENSION));
    String mimeType = mapper.guessMimeType(is, "");
    LOGGER.debug("mimeType = {}", mimeType);
    assertEquals("text/xml;id=csw", mimeType);
    is = FileUtils.openInputStream(new File(XML_METACARD_FILE_NO_EXTENSION));
    mimeType = mapper.guessMimeType(is, "");
    LOGGER.debug("mimeType = {}", mimeType);
    assertEquals("text/xml", mimeType);
}
Also used : MimeTypeMapper(ddf.mime.MimeTypeMapper) InputStream(java.io.InputStream) File(java.io.File) Test(org.junit.Test)

Example 4 with MimeTypeMapper

use of ddf.mime.MimeTypeMapper in project ddf by codice.

the class MimeTypeMapperTest method testGuessMimeTypeForFileExtension.

@Test
public void testGuessMimeTypeForFileExtension() throws Exception {
    MimeTypeMapper mapper = new MimeTypeMapperImpl(MOCK_MIME_TYPE_RESOLVERS);
    String mimeType = mapper.getMimeTypeForFileExtension("xml");
    LOGGER.debug("mimeType = {}", mimeType);
    assertEquals("text/xml", mimeType);
    mimeType = mapper.getMimeTypeForFileExtension(".nitf");
    LOGGER.debug("mimeType = {}", mimeType);
    assertEquals("image/nitf", mimeType);
}
Also used : MimeTypeMapper(ddf.mime.MimeTypeMapper) Test(org.junit.Test)

Example 5 with MimeTypeMapper

use of ddf.mime.MimeTypeMapper in project ddf by codice.

the class MimeTypeMapperTest method testGuessMimeTypeForXmlIngest.

@Test
public void testGuessMimeTypeForXmlIngest() throws Exception {
    MimeTypeMapper mapper = new MimeTypeMapperImpl(MOCK_MIME_TYPE_RESOLVERS);
    InputStream is = FileUtils.openInputStream(new File(CSW_RECORD_FILE));
    String mimeType = mapper.guessMimeType(is, "xml");
    LOGGER.debug("mimeType = {}", mimeType);
    assertEquals("text/xml;id=csw", mimeType);
    is = FileUtils.openInputStream(new File(XML_METACARD_FILE));
    mimeType = mapper.guessMimeType(is, "xml");
    LOGGER.debug("mimeType = {}", mimeType);
    assertEquals("text/xml", mimeType);
    is = FileUtils.openInputStream(new File(NITF_FILE));
    mimeType = mapper.guessMimeType(is, "nitf");
    LOGGER.debug("mimeType = {}", mimeType);
    assertEquals("image/nitf", mimeType);
    // Verify an XML file with a root element namespace, e.g., a pom.xml file, that does not match any
    // MimeTypeResolver returns a null mime type
    is = FileUtils.openInputStream(new File(NO_NAMESPACE_MATCHES_XML_FILE));
    mimeType = mapper.guessMimeType(is, "xml");
    LOGGER.debug("mimeType = {}", mimeType);
    assertNull(mimeType);
    // Verify an XML file with no namespaces that does not match any
    // MimeTypeResolver returns a null mime type
    is = FileUtils.openInputStream(new File(NO_NAMESPACES_XML_FILE));
    mimeType = mapper.guessMimeType(is, "xml");
    LOGGER.debug("mimeType = {}", mimeType);
    assertNull(mimeType);
}
Also used : MimeTypeMapper(ddf.mime.MimeTypeMapper) InputStream(java.io.InputStream) File(java.io.File) Test(org.junit.Test)

Aggregations

MimeTypeMapper (ddf.mime.MimeTypeMapper)12 Test (org.junit.Test)10 InputStream (java.io.InputStream)4 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 InputTransformer (ddf.catalog.transform.InputTransformer)3 File (java.io.File)3 CatalogFramework (ddf.catalog.CatalogFramework)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)2 ContentDisposition (org.apache.cxf.jaxrs.ext.multipart.ContentDisposition)2 BundleContext (org.osgi.framework.BundleContext)2 ServiceReference (org.osgi.framework.ServiceReference)2 StorageProvider (ddf.catalog.content.StorageProvider)1 ContentItem (ddf.catalog.content.data.ContentItem)1 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)1 MockMemoryStorageProvider (ddf.catalog.content.impl.MockMemoryStorageProvider)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)1