package org.sagebionetworks.bridge.models.studies;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Test;

import org.sagebionetworks.bridge.json.BridgeObjectMapper;

public class MimeTypeTest {

    @Test
    public void canDeserializeAutogeneratedMimeTypes() throws Exception {
        MimeType deser = BridgeObjectMapper.get().readValue("\"pdf\"", MimeType.class);
        assertEquals(MimeType.PDF, deser);
        
        deser = BridgeObjectMapper.get().readValue("\"application/pdf\"", MimeType.class);
        assertEquals(MimeType.PDF, deser);
        
        deser = BridgeObjectMapper.get().readValue("\"HTML\"", MimeType.class);
        assertEquals(MimeType.HTML, deser);
        
        deser = BridgeObjectMapper.get().readValue("\"TEXT/PLAIN\"", MimeType.class);
        assertEquals(MimeType.TEXT, deser);
    }
    
    @Test
    public void nullDoesNotBreakDeserialization() throws Exception {
        assertNull(BridgeObjectMapper.get().readValue("\"\"", MimeType.class));
    }
}

@@ -218,16 +218,69 @@
 apper;%0A%0A
+import com.fasterxml.jackson.databind.ObjectMapper;%0A%0A
 public c
@@ -396,20 +396,25 @@
     
-MimeType des
+ObjectMapper mapp
 er =
@@ -430,32 +430,74 @@
 jectMapper.get()
+;%0A        %0A        MimeType deser = mapper
 .readValue(%22%5C%22pd
@@ -591,32 +591,14 @@
 r = 
-BridgeObjectMapper.get()
+mapper
 .rea
@@ -716,32 +716,14 @@
 r = 
-BridgeObjectMapper.get()
+mapper
 .rea
@@ -831,32 +831,14 @@
 r = 
-BridgeObjectMapper.get()
+mapper
 .rea
@@ -930,24 +930,474 @@
 %0A    %7D%0A    %0A
+    /**%0A     * Test that serialization works with a normal ObjectMapper, not just BridgeObjectMapper.%0A     */%0A    @Test%0A    public void canSerializeWithNormalObjectMaper() throws Exception %7B%0A        ObjectMapper mapper = new ObjectMapper();%0A        %0A        String json = mapper.writeValueAsString(MimeType.HTML);%0A        %0A        MimeType type = mapper.readValue(json, MimeType.class);%0A        %0A        assertEquals(MimeType.HTML, type);%0A    %7D%0A    %0A
     @Test%0A  

Test with ObjectMapper.