Skip to content

Support annotated arguments in a form of Map in Spring tests for controllers #2489

Open
@EgorkaKulikov

Description

@EgorkaKulikov

Description

Although @RequestParam annotation is supported after #2487, there is a not very often occured scenario that we can not deal with. Actually, the same problem happens for @PathVariable.

Expected behavior

Integration tests can be generated properly for the following syntax of the annotation

@PostMapping("/api/foos")
@ResponseBody
public String updateFoos(@RequestParam Map<String,String> allParams) {
    return "Parameters are " + allParams.entrySet();
}

curl -X POST -F 'name=abc' -F 'id=123' http://localhost:8080/spring-mvc-basics/api/foos

or

@GetMapping("/api/employeeswithmapvariable/{id}/{name}")
@ResponseBody
public String getEmployeesByIdAndNameWithMapVariable(@PathVariable Map<String, String> pathVarsMap) {
    String id = pathVarsMap.get("id");
    String name = pathVarsMap.get("name");
    if (id != null && name != null) {
        return "ID: " + id + ", name: " + name;
    } else {
        return "Missing Parameters";
    }
}

http://localhost:8080/api/employees/1/bar 

Metadata

Metadata

Assignees

Labels

comp-fuzzingIssue is related to the fuzzingcomp-springIssue is related to Spring projects supportctg-enhancementNew feature, improvement or change request

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions