Tuesday, 5 July 2022

File upload test

 Path to test resources

java.nio.file.Path;=

Path resourceDirectory = Paths.get("src", "test", "resources");

String filePath = resourceDirectory.toFile().getAbsolutePath();

File f = new File(absolutePath);

File[] list = f.listFiles();


InputStream targetStream = new FileInputStream(list[0]);


MockMultipartFile file = new MockMultipartFile("file", "sampletest.xml", MediaType.TEXT_PLAIN_VALUE,

targetStream);


MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();

mockMvc.perform(multipart("/uploadFile").file(file).param("filePath", absolutePath)).andExpect(status().isOk());

No comments:

Post a Comment

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...