Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multipart/form-data works via REST client but fails in Karate tests #797 #914

Merged
merged 1 commit into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}