MetadataContentTypeProvider extends ContentTypeProviderImpl { @Override public String getContentType(AdaptrisMessage msg) throws CoreException { return build(extract(msg), msg.getContentEncoding()); } MetadataContentTypeProvider();  MetadataContentTypeProvider(String key); @Override String getContentType(AdaptrisMessage msg); String getMetadataKey(); void setMetadataKey(String key); String getDefaultMimeType(); void setDefaultMimeType(String mt);  }
@Test public void testGetContentType() throws Exception { MetadataContentTypeProvider provider = new MetadataContentTypeProvider(testName.getMethodName()); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(""); msg.addMetadata(testName.getMethodName(), "text/complicated"); String contentType = provider.getContentType(msg); assertEquals("text/complicated", contentType); }
@Test public void testGetContentType_WithCharset() throws Exception { MetadataContentTypeProvider provider = new MetadataContentTypeProvider(testName.getMethodName()); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(""); msg.setContentEncoding("UTF-8"); msg.addMetadata(testName.getMethodName(), "text/complicated"); String contentType = provider.getContentType(msg); assertEquals("text/complicated; charset=UTF-8", contentType); }
@Test public void testGetContentType_MetadataKeyNonExistent() throws Exception { MetadataContentTypeProvider provider = new MetadataContentTypeProvider(testName.getMethodName()); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(""); String contentType = provider.getContentType(msg); assertEquals("text/plain", contentType); }
@Test public void testGetContentType_NullMetadataKey() throws Exception { MetadataContentTypeProvider provider = new MetadataContentTypeProvider(); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(""); msg.addMetadata(testName.getMethodName(), "text/complicated"); try { provider.getContentType(msg); fail(); } catch (CoreException expected) { } }