小编use*_*632的帖子

MockMvc返回null而不是对象

我正在开发微服务应用程序,我需要测试对控制器的发布请求。手动测试有效,但是测试用例始终返回null。

我已经在Stackoverflow和文档中阅读了许多类似的问题,但是还没有弄清楚我所缺少的东西。

这是我目前拥有的以及为了使其工作而尝试的方法:

//Profile controller method need to be tested
@RequestMapping(path = "/", method = RequestMethod.POST)
public ResponseEntity<Profile> createProfile(@Valid @RequestBody User user, UriComponentsBuilder ucBuilder) {
    Profile createdProfile = profileService.create(user); // line that returns null in the test
    if (createdProfile == null) {
        System.out.println("Profile already exist");
        return new ResponseEntity<>(HttpStatus.CONFLICT);
    }
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ucBuilder.path("/{name}").buildAndExpand(createdProfile.getName()).toUri());
    return new ResponseEntity<>(createdProfile , headers, HttpStatus.CREATED);
}

//ProfileService create function that returns null in the test case
public Profile create(User user) {
    Profile existing = …
Run Code Online (Sandbox Code Playgroud)

junit spring spring-mvc mockito microservices

1
推荐指数
1
解决办法
4779
查看次数

将词典添加到列表python中

我是python的新手,我正在尝试创建一个csv解析脚本.我将行从csv传递到列表,但目前我遇到的麻烦是我需要在每个项目中添加第一个标题行作为字典.

def parse_csv(datafile):     
    data = []
    with open(datafile, "r") as f: 
        next(f) #skip headerline
        for line in f:
            splitLine = line.strip(',') 
            rowL = splitLine.rstrip('\n') #remove the newline char
            data.append(rowL)
        pprint(data)

    return data
Run Code Online (Sandbox Code Playgroud)

如果第一个标题行有字典(例如标题,名称等),我将如何传递给每个被剥离的元素?

例如{'Dict1':'data1','Dict2':'data2'}

这可能被视为重复,但从类似的帖子尝试了各种方式,但没有在我的情况下正常工作.

python csv dictionary

0
推荐指数
1
解决办法
107
查看次数

标签 统计

csv ×1

dictionary ×1

junit ×1

microservices ×1

mockito ×1

python ×1

spring ×1

spring-mvc ×1