Skip to content

Commit 387afe3

Browse files
committed
添加yml上传下载的测试
1 parent acda952 commit 387afe3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

platform-api/src/test/java/com/flow/platform/api/test/controller/FlowControllerTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.flow.platform.api.test.controller;
1818

19+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.fileUpload;
1920
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2021
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
2122
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
@@ -28,10 +29,12 @@
2829
import com.flow.platform.api.util.PathUtil;
2930
import com.flow.platform.core.response.ResponseError;
3031
import com.flow.platform.util.StringUtil;
32+
import java.io.IOException;
3133
import org.junit.Assert;
3234
import org.junit.Before;
3335
import org.junit.Test;
3436
import org.springframework.http.MediaType;
37+
import org.springframework.mock.web.MockMultipartFile;
3538
import org.springframework.test.web.servlet.MvcResult;
3639
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
3740

@@ -167,4 +170,37 @@ public void should_return_empty_string_if_no_yml_content() throws Throwable {
167170
// then:
168171
Assert.assertEquals(StringUtil.EMPTY, content);
169172
}
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+
}
170206
}

0 commit comments

Comments
 (0)