|
| 1 | +package org.icij.datashare.web; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 4 | +import org.icij.datashare.json.JsonObjectMapper; |
| 5 | +import org.icij.datashare.text.ContentTypeCategory; |
| 6 | +import org.icij.datashare.web.testhelpers.AbstractProdWebServerTest; |
| 7 | +import org.junit.Before; |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +import java.util.List; |
| 11 | +import java.util.Map; |
| 12 | + |
| 13 | +import static org.fest.assertions.Assertions.assertThat; |
| 14 | + |
| 15 | +public class ContentTypeResourceTest extends AbstractProdWebServerTest { |
| 16 | + |
| 17 | + @Before |
| 18 | + public void setUp() { |
| 19 | + configure(routes -> routes.add(new ContentTypeResource())); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void test_group_by_categories_with_audio_and_video() throws Exception { |
| 24 | + String content = post("/api/contentType/categories", "[\"audio/mp3\", \"video/mp4\"]").response().content(); |
| 25 | + Map<ContentTypeCategory, List<String>> result = JsonObjectMapper.readValue(content, new TypeReference<>() {}); |
| 26 | + |
| 27 | + assertThat(result).hasSize(2); |
| 28 | + assertThat(result.get(ContentTypeCategory.AUDIO)).containsExactly("audio/mp3"); |
| 29 | + assertThat(result.get(ContentTypeCategory.VIDEO)).containsExactly("video/mp4"); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void test_group_by_categories_with_unknown_content_type() throws Exception { |
| 34 | + String content = post("/api/contentType/categories", "[\"application/unknown\"]").response().content(); |
| 35 | + Map<ContentTypeCategory, List<String>> result = JsonObjectMapper.readValue(content, new TypeReference<>() {}); |
| 36 | + |
| 37 | + assertThat(result).hasSize(1); |
| 38 | + assertThat(result.get(ContentTypeCategory.OTHER)).containsExactly("application/unknown"); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void test_group_by_categories_with_empty_list() throws Exception { |
| 43 | + String content = post("/api/contentType/categories", "[]").response().content(); |
| 44 | + Map<ContentTypeCategory, List<String>> result = JsonObjectMapper.readValue(content, new TypeReference<>() {}); |
| 45 | + |
| 46 | + assertThat(result).isEmpty(); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void test_group_by_categories_with_image() throws Exception { |
| 51 | + String content = post("/api/contentType/categories", "[\"image/png\"]").response().content(); |
| 52 | + Map<ContentTypeCategory, List<String>> result = JsonObjectMapper.readValue(content, new TypeReference<>() {}); |
| 53 | + |
| 54 | + assertThat(result).hasSize(1); |
| 55 | + assertThat(result.get(ContentTypeCategory.IMAGE)).containsExactly("image/png"); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void test_group_by_categories_mixed() throws Exception { |
| 60 | + String content = post("/api/contentType/categories", "[\"audio/mp3\", \"application/unknown\", \"image/jpeg\"]").response().content(); |
| 61 | + Map<ContentTypeCategory, List<String>> result = JsonObjectMapper.readValue(content, new TypeReference<>() {}); |
| 62 | + |
| 63 | + assertThat(result).hasSize(3); |
| 64 | + assertThat(result.get(ContentTypeCategory.AUDIO)).containsExactly("audio/mp3"); |
| 65 | + assertThat(result.get(ContentTypeCategory.OTHER)).containsExactly("application/unknown"); |
| 66 | + assertThat(result.get(ContentTypeCategory.IMAGE)).containsExactly("image/jpeg"); |
| 67 | + } |
| 68 | +} |
0 commit comments