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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations