parent
a596c0e226
commit
db48813181
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -63,24 +63,21 @@ public class MockPart implements Part {
|
|||
* @see #getHeaders()
|
||||
*/
|
||||
public MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
|
||||
Assert.hasLength(name, "'name' must not be empty");
|
||||
this.name = name;
|
||||
this.filename = filename;
|
||||
this.content = (content != null ? content : new byte[0]);
|
||||
this.headers.setContentDispositionFormData(name, filename);
|
||||
this(name, filename, content, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a part with a filename, byte[] content and MediaType mediaType.
|
||||
* Constructor for a part with a filename, byte[] content, and content type.
|
||||
* @since 6.1.2
|
||||
* @see #getHeaders()
|
||||
*/
|
||||
public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType mediaType) {
|
||||
public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType contentType) {
|
||||
Assert.hasLength(name, "'name' must not be empty");
|
||||
this.name = name;
|
||||
this.filename = filename;
|
||||
this.content = (content != null ? content : new byte[0]);
|
||||
this.headers.setContentDispositionFormData(name, filename);
|
||||
this.headers.setContentType(mediaType);
|
||||
this.headers.setContentType(contentType);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,7 @@ class MockMultipartHttpServletRequestTests {
|
|||
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
|
||||
request.addFile(new MockMultipartFile("file", "myOrigFilename", MediaType.TEXT_PLAIN_VALUE, "myContent2".getBytes()));
|
||||
|
||||
MockPart metadataPart = new MockPart("metadata", "{\"foo\": \"bar\"}".getBytes());
|
||||
metadataPart.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
MockPart metadataPart = new MockPart("metadata", null, "{\"foo\": \"bar\"}".getBytes(), MediaType.APPLICATION_JSON);
|
||||
request.addPart(metadataPart);
|
||||
|
||||
HttpHeaders fileHttpHeaders = request.getMultipartHeaders("file");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -34,7 +34,7 @@ import org.springframework.util.Assert;
|
|||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
* @since 4.3.12
|
||||
* @see MockHttpServletRequest#addPart
|
||||
* @see MockMultipartFile
|
||||
*/
|
||||
|
|
@ -63,11 +63,21 @@ public class MockPart implements Part {
|
|||
* @see #getHeaders()
|
||||
*/
|
||||
public MockPart(String name, @Nullable String filename, @Nullable byte[] content) {
|
||||
this(name, filename, content, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a part with a filename, byte[] content, and content type.
|
||||
* @since 6.1.2
|
||||
* @see #getHeaders()
|
||||
*/
|
||||
public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType contentType) {
|
||||
Assert.hasLength(name, "'name' must not be empty");
|
||||
this.name = name;
|
||||
this.filename = filename;
|
||||
this.content = (content != null ? content : new byte[0]);
|
||||
this.headers.setContentDispositionFormData(name, filename);
|
||||
this.headers.setContentType(contentType);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue