Skip to content

Commit

Permalink
multipart/form-data endpoint success from REST client but fails in Ka…
Browse files Browse the repository at this point in the history
…rate tests karatelabs#797
  • Loading branch information
Nishant-sehgal committed Oct 3, 2019
1 parent 7b5438f commit bb3ed91
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getHeaders(String string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit bb3ed91

Please sign in to comment.