Skip to content

Instantly share code, notes, and snippets.

@smlc
Last active February 6, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smlc/568a1953f2877573635a1c9938dadcd3 to your computer and use it in GitHub Desktop.
Save smlc/568a1953f2877573635a1c9938dadcd3 to your computer and use it in GitHub Desktop.
package services
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.mock.web.MockMultipartFile
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
@ContextConfiguration
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class FileUploadControllerTest extends Specification {
@Autowired
private TestRestTemplate restTemplate
def "test loading a empyt file"(){
when: "give a empyt file to load"
MockMultipartFile multipartFile = new MockMultipartFile("file", "test.txt", "text/plain", "Please select a file to upload".getBytes())
String requestResult = restTemplate.postForObject("/uploadFile",multipartFile,String.class)
then: "return a error message"
requestResult.contains("Please select a file to upload")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment