У меня есть приложение для весенней загрузки с маршрутами, определенными следующим образом:
@Component
public class SampleRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
rest("/customers-controller/")
.get("/customers").to("direct:getcustomer)
.get("/{id}").to("direct:customerDetail")
.get("/{id}/orders").to("direct:customerOrders")
.post("/neworder").to("direct:customerNewOrder");
}
Я пытаюсь создать контракт для тестирования этой конечной точки ('/ customers') и создать заглушку, которая будет использоваться в моем потребительском классе.
Контракт для служб обмена сообщениями, таких как camel, похож на этот:
Contract.make {
label("positive")
input {
messageFrom("seda:getcustomer")
messageBody([
id: "25_body"
])
messageHeaders {
messagingContentType(applicationJson())
// header("id","123_header")
}
}
outputMessage {
sentTo("seda:iris-address-int")
body([
"id":"25_body","firstname":null,"lastname":null,"email":null,"phone":null,"street":null,"city":null,"postcode":null
]
)
headers {
messagingContentType()
}
}
}
Теперь я не уверен в том, как определить контракт так, чтобы он указывал на моя выбранная конечная точка отдыха, как я бы сделал с RestController.
Рассмотрим тест ниже. Можно ли сгенерировать этот тест на стороне провайдера с использованием весеннего облачного контракта, учитывая, что я использую не компонент @RestController
, а компонент rest
?
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class TestRestRoute {
@Autowired
private TestRestTemplate restTemplate;
@LocalServerPort
int randomServerPort
@Test
public void test_bank_route() throws URISyntaxException, IOException {
//call the REST API
final String baseUrl = "http://localhost:" + randomServerPort + "/customers-controller/customers";
URI uri = new URI(baseUrl);
ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class );
Assert.assertEquals(MediaType.APPLICATION_JSON_VALUE, Objects.requireNonNull(response.getHeaders().getContentType()).toString());
Assert.assertEquals(200, response.getStatusCodeValue());
Assert.assertNull(response.getBody());
}