DefaultMimeSupport implements MimeSupport { @Nonnull @Override public String guessMimeTypeFromPath(final String path, final MimeRulesSource... mimeRulesSources) { return guessMimeTypesListFromPath(path, mimeRulesSources).get(0); } @Inject  DefaultMimeSupport(); @VisibleForTesting  DefaultMimeSupport(final NexusMimeTypes nexusMimeTypes); @Nonnull @Override String guessMimeTypeFromPath(final String path, final MimeRulesSource... mimeRulesSources); @Nonnull @Override List<String> guessMimeTypesListFromPath(final String path, final MimeRulesSource... mimeRulesSources); @Nonnull @Override String detectMimeType(final InputStream input, @Nullable final String fileName); @Nonnull @Override List<String> detectMimeTypes(final InputStream input, @Nullable final String fileName);  }
@Test public void testGuessMimeTypeFromPath() { assertThat(underTest.guessMimeTypeFromPath("/some/path/artifact.pom"), equalTo("application/xml")); assertThat(underTest.guessMimeTypeFromPath("/some/path/artifact.jar"), equalTo("application/java-archive")); assertThat(underTest.guessMimeTypeFromPath("/some/path/artifact-sources.jar"), equalTo("application/java-archive")); assertThat(underTest.guessMimeTypeFromPath("/some/path/maven-metadata.xml"), equalTo("application/xml")); assertThat(underTest.guessMimeTypeFromPath("/some/path/some.xml"), equalTo("application/xml")); assertThat(underTest.guessMimeTypeFromPath("/some/path/some.tar.gz"), equalTo("application/x-gzip")); assertThat(underTest.guessMimeTypeFromPath("/some/path/some.tar.bz2"), equalTo("application/x-bzip2")); assertThat(underTest.guessMimeTypeFromPath("/some/path/some.zip"), equalTo("application/zip")); assertThat(underTest.guessMimeTypeFromPath("/some/path/some.war"), equalTo("application/java-archive")); assertThat(underTest.guessMimeTypeFromPath("/some/path/some.rar"), equalTo("application/java-archive")); assertThat(underTest.guessMimeTypeFromPath("/some/path/some.ear"), equalTo("application/java-archive")); assertThat(underTest.guessMimeTypeFromPath("/some/path/some.ejb"), equalTo("application/java-archive")); }
@Test public void testGuessfakeMimeRulesSourceMimeTypeFromPath() { MimeRulesSource source = new MimeRulesSource() { @Override public MimeRule getRuleForName(String path) { return new MimeRule(false, "foo/bar"); } }; assertThat(underTest.guessMimeTypeFromPath("/some/path/artifact.pom", source), equalTo("foo/bar")); }
@Test public void testGuessWithoutMimeRulesSourceMimeTypeFromPath() { assertThat(underTest.guessMimeTypeFromPath("/some/path/artifact.pom"), equalTo("application/xml")); }
@Test public void useNexusMimeTypes() { this.underTest = new DefaultMimeSupport(mimeTypes); when(mimeTypes.getMimeRuleForExtension("test")).thenReturn(mimeType); when(mimeType.getMimetypes()).thenReturn(Lists.newArrayList("fake/mimetype")); assertThat(underTest.guessMimeTypeFromPath("foo.test"), is("fake/mimetype")); }
@Test public void retainDefaultMimeTypes() { this.underTest = new DefaultMimeSupport(mimeTypes); assertThat(underTest.guessMimeTypeFromPath("foo.doc"), is("application/msword")); }
@Test public void overrideDefaultMimeType() { this.underTest = new DefaultMimeSupport(mimeTypes); when(mimeTypes.getMimeRuleForExtension("zip")).thenReturn(mimeType); when(mimeType.isOverride()).thenReturn(true); when(mimeType.getMimetypes()).thenReturn(Lists.newArrayList("fake/mimetype")); assertThat(underTest.guessMimeTypeFromPath("foo.zip"), is("fake/mimetype")); }