这个请求的目的-至少得到一些关于如何做的提示/想法-Java新手-新手问题也是如此-
我想匹配我的csv列与输出get请求然后告诉我-匹配所有或所有列——
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestApplication.class)
//@WebMvcTest(value = SwProductController.class)
@ActiveProfiles("dev") // In case you want to test a particular profile
@AutoConfigureMockMvc
public class SwProductImplTest
{
@Autowired
private MockMvc mockMvc;
@Test
public void testRetrieveDetails() throws Exception {
String filesss = "csv--file--path";
JSONArray expected = new JSONArray(Files.readAllLines(Paths.get(filesss))
.stream()
.map(s -> new yourJson(s.split(",")[0], s.split(",")[1]))
.collect(toList()));
RequestBuilder requestBuilder = MockMvcRequestBuilders
.get("/swproduct/list")
.accept(MediaType.APPLICATION_JSON);
MvcResult result = mockMvc.perform(requestBuilder).andReturn();
//System.out.println(result.getResponse());
JSONAssert.assertEquals(result.getResponse().getContentAsString(), expected, false);
}
private class yourJson {
String s;
String s1;
public yourJson(String s, String s1) {
this.s = s;
this.s1 = s1;
}
}
}
get请求的输出看起来像这样-get请求
csv文件-
sw product,sw product module,technology
Product 1,Module 1,REGULAR
Product 1,Module 2,SPRING CLOUD
Product 2,Module 1,REGULAR
Product 2,Module 3,REGULAR
两个数据都是相同的,但唯一的区别是您的输出是JSON格式,而您发布的示例是表格形式。两者都可以