如何测试仅设置属性的骆驼路线

发布于 2025-01-25 02:21:48 字数 104 浏览 0 评论 0原文

我有一个路由构建器,它取决于消息设置特定属性的内容。它不会将其发送到其他端点,因此我无法嘲笑它们并检查它们得到的内容。 我可以产生一条消息或交换,但是在该路线建设者将其转换后,是否有办法检查它?

I have a route builder that depending on the content of a message sets specific properties. It doesn't send it to other endpoints so I cannot mock them and check what they got.
I can produce a message or exchange but is there a way to check it after it was transformed by this route builder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

去了角落 2025-02-01 02:21:48

假设您的路线是同步的(即不是来自:SEDA),则可以简单地检查通过product> productereTemplate发送的属性已更新该属性。

假设您需要检查属性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");
    }

}

Assuming that your route is synchronous (i.e. not from:seda), you can simply check that the property was updated on the exchange that you send via the ProducerTemplate.

Let's assume that you need to check the value of the property 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");
    }

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文