Added support for multipart with content type, fixes gh-599

This commit is contained in:
Marcin Grzejszczak
2018-04-11 15:37:13 +02:00
parent 34f367e62b
commit b965c49a7e
13 changed files with 241 additions and 10 deletions

View File

@@ -0,0 +1,36 @@
package com.example.fraud;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
public class TestController {
@PostMapping("/tests")
public Test createNew(@RequestPart MultipartFile file1,
@RequestPart MultipartFile file2,
@RequestPart Test test) {
return new Test("ok");
}
}
class Test {
private String status;
public Test(String status) {
this.status = status;
}
public Test() {
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

View File

@@ -0,0 +1,14 @@
package com.example.fraud;
import com.example.fraud.TestController;
import io.restassured.module.mockmvc.RestAssuredMockMvc;
import org.junit.Before;
import org.junit.runner.RunWith;
public class MultipartBase {
@Before
public void setUp() throws Exception {
RestAssuredMockMvc.standaloneSetup(new TestController());
}
}

View File

@@ -0,0 +1,35 @@
import org.springframework.cloud.contract.spec.Contract
Contract.make {
request {
method 'POST'
url '/tests'
multipart(
[
file1: named(
name: value(consumer(regex(nonEmpty())), producer('filename1')),
content: value(consumer(regex(nonEmpty())), producer('content1'))),
file2: named(
name: value(consumer(regex(nonEmpty())), producer('filename1')),
content: value(c(regex(nonEmpty())), producer('content2'))),
test : named(
name: value(consumer(regex(nonEmpty())), producer('filename1')),
content: value(c(regex(nonEmpty())), producer(file("test.json"))),
contentType: "application/json")
]
)
headers {
contentType('multipart/form-data')
}
}
response {
status 200
body([
status: 'ok'
])
headers {
contentType('application/json')
}
}
}

View File

@@ -0,0 +1,3 @@
{
"status": "test"
}