优化
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
package com.baiyue.firstleg.controller;
|
||||
|
||||
import com.baiyue.common.event.EventProtocolException;
|
||||
import com.baiyue.common.event.EventDependencyNotReadyException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
class EventConsumptionExceptionHandlerTest {
|
||||
@RestController static class Probe {
|
||||
@GetMapping("/protocol") void protocol() { throw new EventProtocolException("invalid hash"); }
|
||||
@GetMapping("/dependency") void dependency() { throw new EventDependencyNotReadyException("source not ready"); }
|
||||
}
|
||||
@Test void protocolAndDependencyHaveDistinctWireCodes() throws Exception {
|
||||
var mvc = MockMvcBuilders.standaloneSetup(new Probe()).setControllerAdvice(new EventConsumptionExceptionHandler()).build();
|
||||
mvc.perform(get("/protocol")).andExpect(status().isOk()).andExpect(jsonPath("$.code").value("EVT_PROTOCOL"));
|
||||
mvc.perform(get("/dependency")).andExpect(status().isOk()).andExpect(jsonPath("$.code").value("EVT_DEPENDENCY"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user