我是 Spring 开发的新手,正在尝试学习。安装了 Netbeans 11.1 并克隆了这个git 存储库并尝试让这个 VideoController 通过。
我很惊讶为什么 testAddGetVideo() 测试在组中运行时失败,但在单独运行时却通过。测试套件在这里。纠结了好几天了。通读SO和其他帖子。
testAddGetVideo 在测试套件中失败,但个别测试通过(向下滚动查看下文)
在堆栈跟踪中有一个
org.springframework.web.HttpMediaTypeNotAcceptableException
测试添加获取视频():
@Test
public void testAddGetVideo() throws Exception {
videoSvc.addVideo(video);
Collection<Video> stored = videoSvc.getVideoList();
assertTrue(stored.contains(video));
}
它调用的我的 VideoController 方法:
/**
* getVideos
*
* @return Collection<Video>
*/
@RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.GET)
public @ResponseBody Collection<Video> getVideos(HttpServletResponse response) {
System.out.println("---------------getVideos---------------");
System.out.println(videos.size() + " videos");
System.out.println("===================");
response.setContentType("application/json");
response.setStatus(200);
return videos.values();
}
/**
* newVideo
*
* @param v
* @return Video
*/
@RequestMapping(value = VIDEO_SVC_PATH, method = RequestMethod.POST)
public @ResponseBody Video newVideo(@RequestBody Video v) {
System.out.println("---------------newVideo---------------");
checkAndSetId(v);
String url = getDataUrl(v.getId());
v.setDataUrl(url);
videos.put(v.getId(), v);
System.out.println("video " + v.getId() + " at " + v.getDataUrl());
System.out.println("===================");
return v;
}
视频服务
public static final String VIDEO_SVC_PATH = "/video";
public static final String VIDEO_DATA_PATH = VIDEO_SVC_PATH + "/{id}/data";
/**
* This endpoint in the API returns a list of the videos that have
* been added to the server. The Video objects should be returned as
* JSON.
*
* To manually test this endpoint, run your server and open this URL in a browser:
* http://localhost:8080/video
*
* @return
*/
潇湘沐
相关分类