我正在为我的控制器层编写测试用例。我的控制器方法之一如下所示。
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
@RequestMapping("/v1")
public class MyController {
private static Logger logger = LoggerFactory.getLogger(MyController.class);
@Autowired
private MyService service;
@GetMapping("/{pathVar}/check")
@MyAuthentication
public ResponseEntity<Object> check(@PathVariable String pathVar,
@MyAuthContext MyAuthInfo myAuthInfo) throws Exception {
try {
logger.info("Check API started by "+myAuthInfo.getUserId()+" and email "+ myAuthInfo.getUserEmail());
return ResponseEntity
.status(HttpStatus.OK)
.body(service.isPartner(pathVar, myAuthInfo));
} catch (Exception e) {
logger.info("Check API encountered the error.", e);
throw e;
}
}
}
有人可以在我编写测试用例时帮助模拟我的身份验证上下文吗?