test(gateway-engine-beans): Test HeaderMap serializer and deserializer.
MODIFY
gateway/engine/beans/src/test/java/io/apiman/gateway/engine/beans/util/HeaderMapIOTest.java
gateway/engine/beans/src/test/java/io/apiman/gateway/engine/beans/util/HeaderMapIOTest.java
package io.apiman.gateway.engine.beans.util;
+import java.io.IOException;
+
+import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
@@ -71,4 +76,29 @@ public class HeaderMapIOTest {
Assert.assertEquals("Value-4", deserializedMap.get("Header-4"));
}
+ @Test
+ public void testJsonMarshalling_DuplicateValues() throws JsonParseException, JsonMappingException, IOException {
+ HeaderMap map = new HeaderMap();
+ map.add("foo", "val");
+ map.add("foo", "val2");
+ map.add("weeble", "wobble");
+ map.add("savy", "marc");
+ map.add("savy", "alain");
+ map.add("savy", "yvon");
+ map.add("Single", "thing");
+
+ ObjectMapper mapper = new ObjectMapper();
+ String actualWritten = mapper.writeValueAsString(map);
+ Assert.assertEquals("{\"foo\":[\"val2\",\"val\"],\"savy\":[\"yvon\",\"alain\",\"marc\"],\"Single\":\"thing\",\"weeble\":\"wobble\"}",
+ actualWritten);
+
+ HeaderMap deserializedMap = mapper.readValue(actualWritten, HeaderMap.class);
+
+ Assert.assertThat(deserializedMap.getAll("foo"), Matchers.hasItems("val2", "val"));
+ Assert.assertThat(deserializedMap.getAll("savy"), Matchers.hasItems("marc", "alain", "yvon"));
+ Assert.assertThat(deserializedMap.getAll("weeble"), Matchers.hasItems("wobble"));
+ Assert.assertEquals(deserializedMap.get("Single"), "thing");
+ Assert.assertEquals(deserializedMap.get("savy"), "yvon");
+ }
+
}

test(gateway-engine-beans): Test HeaderMap serializer and deserializer.

Signed-off-by: Marc Savy <marc@rhymewithgravy.com>