子模块从父级的kafka生产者那里接收请求。子模块仅具有kafak接收和发送功能。父母从其余api获取请求,然后生成孩子的kafka列表器。
我想为上述项目结构编写集成测试用例。我想测试整个应用程序,即接收其余的api调用,然后将请求转发到子模块,然后将响应发送回去。
这是项目结构
这是初始请求到达的api控制器:
@Controller
@RequestMapping(value = "/api")
public class ApiController {
@Autowired
KafkaTemplate<String, String> kafkaTemple;
@RequestMapping(value={"/welcome"}, method = RequestMethod.POST)
@ResponseBody
public PojoClass welcomeUser(@RequestBody String request) {
// TODO Prepares request to JSON format and forward towards child module
kafkaTemple.send("ChildTopic", request);
return new PojoClass("Test","Test Message String");
}
}
儿童卡夫卡的接收者和制作人
@Component
@EnableKafka
public class KafkaReceiver extends config {
@Autowired
KafkaTemplate<String, String> kafkaTemple;
private static final String kafkaTopic = "ChildTopic";
@KafkaListener(topics = kafkaTopic)
public void listen(List<ConsumerRecord<String, String>> records) {
// TODO Some parsing and validation
System.out.println("Received request: " + records);
kafkaTemple.send("ParentTopic", records + " :Response-true");
}
}
这是父卡夫卡接收者
@Component
@EnableKafka
public class ParentKafkaReceiver extends config {
private static final String kafkaTopic = "ParentTopic";
@KafkaListener(topics = kafkaTopic)
public void listen(List<ConsumerRecord<String, String>> records) {
System.out.println("Final result string: " + records);
}
}
我应该在哪里以及如何编写测试用例?即在父模块或子模块中