mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-07-02 16:47:30 +02:00
Add api to overwrite content type resolver (#2051)
Introduce content type resolver extension to provide custom content types for specific file extensions.
This commit is contained in:
@@ -46,6 +46,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -74,7 +75,7 @@ public class ContentResourceTest {
|
||||
|
||||
@Before
|
||||
public void initService() throws Exception {
|
||||
contentResource = new ContentResource(repositoryServiceFactory, new DefaultContentTypeResolver());
|
||||
contentResource = new ContentResource(repositoryServiceFactory, new DefaultContentTypeResolver(Collections.emptySet()));
|
||||
|
||||
NamespaceAndName existingNamespaceAndName = new NamespaceAndName(NAMESPACE, REPO_NAME);
|
||||
RepositoryService repositoryService = repositoryServiceFactory.create(existingNamespaceAndName);
|
||||
|
||||
@@ -36,6 +36,7 @@ import sonia.scm.repository.api.DiffResult;
|
||||
import sonia.scm.repository.api.Hunk;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
@@ -53,7 +54,7 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
private static final Repository REPOSITORY = new Repository("1", "git", "space", "X");
|
||||
|
||||
ResourceLinks resourceLinks = ResourceLinksMock.createMock(create("/scm/api/v2"));
|
||||
DiffResultToDiffResultDtoMapper mapper = new DiffResultToDiffResultDtoMapper(resourceLinks, new DefaultContentTypeResolver());
|
||||
DiffResultToDiffResultDtoMapper mapper = new DiffResultToDiffResultDtoMapper(resourceLinks, new DefaultContentTypeResolver(Collections.emptySet()));
|
||||
|
||||
@Test
|
||||
void shouldMapDiffResult() {
|
||||
|
||||
@@ -24,19 +24,22 @@
|
||||
|
||||
package sonia.scm.io;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class DefaultContentTypeResolverTest {
|
||||
|
||||
private final DefaultContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver();
|
||||
private final DefaultContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver(Collections.emptySet());
|
||||
|
||||
@Test
|
||||
void shouldReturnPrimaryPart() {
|
||||
@@ -56,6 +59,14 @@ class DefaultContentTypeResolverTest {
|
||||
assertThat(contentType.getRaw()).isEqualTo("application/pdf");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnContentTypeFromExtension() {
|
||||
DefaultContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver(ImmutableSet.of((path, contentPrefix) -> Optional.of("scm/test")));
|
||||
|
||||
ContentType contentType = contentTypeResolver.resolve("hog.pdf");
|
||||
assertThat(contentType.getRaw()).isEqualTo("scm/test");
|
||||
}
|
||||
|
||||
@Nested
|
||||
class IsTextTests {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user