|
16 | 16 |
|
17 | 17 | package com.flow.platform.api.test.controller; |
18 | 18 |
|
| 19 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.fileUpload; |
19 | 20 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
20 | 21 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
21 | 22 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; |
|
28 | 29 | import com.flow.platform.api.util.PathUtil; |
29 | 30 | import com.flow.platform.core.response.ResponseError; |
30 | 31 | import com.flow.platform.util.StringUtil; |
| 32 | +import java.io.IOException; |
31 | 33 | import org.junit.Assert; |
32 | 34 | import org.junit.Before; |
33 | 35 | import org.junit.Test; |
34 | 36 | import org.springframework.http.MediaType; |
| 37 | +import org.springframework.mock.web.MockMultipartFile; |
35 | 38 | import org.springframework.test.web.servlet.MvcResult; |
36 | 39 | import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; |
37 | 40 |
|
@@ -167,4 +170,37 @@ public void should_return_empty_string_if_no_yml_content() throws Throwable { |
167 | 170 | // then: |
168 | 171 | Assert.assertEquals(StringUtil.EMPTY, content); |
169 | 172 | } |
| 173 | + |
| 174 | + @Test |
| 175 | + public void should_upload_yml_success() throws Exception { |
| 176 | + String url = "/flows/" + flowName + "/yml/upload"; |
| 177 | + performRequestWith200Status(fileUpload(url) |
| 178 | + .file(createYmlFilePart(".flow.yml")) |
| 179 | + ); |
| 180 | + |
| 181 | + MockHttpServletRequestBuilder request = get("/flows/" + flowName) |
| 182 | + .contentType(MediaType.APPLICATION_JSON); |
| 183 | + |
| 184 | + MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); |
| 185 | + Node flowNode = Node.parse(result.getResponse().getContentAsString(), Node.class); |
| 186 | + Assert.assertEquals("FOUND", flowNode.getEnv(FlowEnvs.FLOW_YML_STATUS)); |
| 187 | + } |
| 188 | + |
| 189 | + @Test |
| 190 | + public void should_download_yml_success() throws Exception { |
| 191 | + String url = "/flows/" + flowName + "/yml/upload"; |
| 192 | + performRequestWith200Status(fileUpload(url) |
| 193 | + .file(createYmlFilePart(".flow.yml")) |
| 194 | + ); |
| 195 | + |
| 196 | + MockHttpServletRequestBuilder request = get("/flows/" + flowName + "/yml/download") |
| 197 | + .contentType(MediaType.ALL); |
| 198 | + MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); |
| 199 | + Assert.assertNotNull(result.getResponse()); |
| 200 | + } |
| 201 | + |
| 202 | + private MockMultipartFile createYmlFilePart(String name) throws IOException { |
| 203 | + String resourceContent = getResourceContent("demo_flow.yaml"); |
| 204 | + return new MockMultipartFile("file", name, "", resourceContent.getBytes()); |
| 205 | + } |
170 | 206 | } |
0 commit comments