diff --git a/karate-mock-servlet/src/main/java/com/intuit/karate/mock/servlet/MockMultiPart.java b/karate-mock-servlet/src/main/java/com/intuit/karate/mock/servlet/MockMultiPart.java index 5a5885ac3..b39c3e562 100644 --- a/karate-mock-servlet/src/main/java/com/intuit/karate/mock/servlet/MockMultiPart.java +++ b/karate-mock-servlet/src/main/java/com/intuit/karate/mock/servlet/MockMultiPart.java @@ -110,10 +110,14 @@ public void delete() throws IOException { } - @Override - public String getHeader(String string) { - return headers.get(string); - } + @Override + public String getHeader(String string) { + /** + * support spring boot 2 StandardMultipartHttpServletRequest implementation to + * give CONTENT_DISPOSITION header details. + */ + return headers.getOrDefault(string, headers.get(string.toLowerCase())); + } @Override public Collection getHeaders(String string) { diff --git a/karate-mock-servlet/src/test/java/com/intuit/karate/mock/servlet/test/MockMultiPartTest.java b/karate-mock-servlet/src/test/java/com/intuit/karate/mock/servlet/test/MockMultiPartTest.java new file mode 100644 index 000000000..1a7c46161 --- /dev/null +++ b/karate-mock-servlet/src/test/java/com/intuit/karate/mock/servlet/test/MockMultiPartTest.java @@ -0,0 +1,48 @@ +package com.intuit.karate.mock.servlet.test; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.springframework.http.HttpHeaders; + +import com.intuit.karate.ScriptValue; +import com.intuit.karate.http.MultiPartItem; +import com.intuit.karate.mock.servlet.MockMultiPart; + +/** + * @author nsehgal + * + * Test for different StandardMultipartHttpServletRequest implementation + * in spring. Below test checks both the implementation should return + * the CONTENT_DISPOSITION header details when asked via getHeader(). + * + */ +public class MockMultiPartTest { + + private MockMultiPart mockMultiPart = null; + + private static final String CONTENT_DISPOSITION = "content-disposition"; + + @Before + public void init() { + ScriptValue NULL = new ScriptValue(null); + MultiPartItem item = new MultiPartItem("file", NULL); + item.setContentType("text/csv"); + item.setFilename("test.csv"); + mockMultiPart = new MockMultiPart(item); + } + + @Test + public void testSpring2MultipartHeader() { + String headerValue = mockMultiPart.getHeader(HttpHeaders.CONTENT_DISPOSITION); + Assert.assertNotNull(headerValue); + Assert.assertEquals("form-data; filename=\"test.csv\"; name=\"file\"", headerValue); + } + + @Test + public void testSpring1MultipartHeader() { + String headerValue = mockMultiPart.getHeader(CONTENT_DISPOSITION); + Assert.assertNotNull(headerValue); + Assert.assertEquals("form-data; filename=\"test.csv\"; name=\"file\"", headerValue); + } +}