我有一個路由構建器,它根據訊息的內容設定特定屬性。它不會將其發送到其他端點,因此我無法模擬它們并檢查它們得到了什么。我可以生成訊息或交換,但是在此路由構建器轉換它之后有沒有辦法檢查它?
uj5u.com熱心網友回復:
假設您的路由是同步的(即不是from:seda),您可以簡單地檢查屬性是否在您通過ProducerTemplate.
假設您需要檢查屬性的值TestProp:
package com.example.demo;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.ExchangeBuilder;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest
class PropertyUpdateTest {
@Produce("direct:testProps")
ProducerTemplate template;
@Autowired
CamelContext camelContext;
@Test
void verifyRouteUpdatesProperty() {
Exchange exchange = ExchangeBuilder.anExchange(camelContext)
.withProperty("TestProp", "InitialVal")
.build();
template.send(exchange);
assertThat(exchange.getProperty("TestProp")).isEqualTo("UpdatedVal");
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/467598.html
上一篇:如何將引數傳遞給無法在SpringBoot中自動裝配的@Component類
下一篇:計算句子中的詞頻
