Closed ZuikovAV closed 5 months ago
I think you can use BeforeSuite
-beans, if you're using Spring. like this:
@Bean
public BeforeSuite whatever() {
return new SequenceBeforeSuite.Builder().actions(new EchoAction.Builder().message("Hello World")).build();
}
are you using Spring and is this feasible for you? 😉
are you using Spring and is this feasible for you
Thanks for the reply! Yes, i use Spring.
The problem is i need to implement not only citrus actions but also for example clean database or mq queue, set channel polling interval and etc. @christophd can you help with my question please?
that's totally possible! just code it like this:
var whatever; // this is your database, or mq client, or "whatever"
[...]
return new SequenceBeforeSuite.Builder().actions(context -> whatever.youWant()).build();
check the citrusframework/citrus-simulator sources if you need more samples 😜
that's totally possible! just code it like this:
var whatever; // this is your database, or mq client, or "whatever" [...] return new SequenceBeforeSuite.Builder().actions(context -> whatever.youWant()).build();
check the citrusframework/citrus-simulator sources if you need more samples 😜
Thanks a lot! It helps me.
If somebody needs sample for miltiple actions:
return new SequenceBeforeSuite.Builder().actions(context -> whatever.youWant(), context -> whatever.youWant1()).build();
@bbortt @christophd i've got some questions.
Why it's not possible to set polling interval directly in HttpServerBuilder (In MQ Server we at the same time we have this opportunity)?
@Bean public HttpServer server() { return new HttpServerBuilder() .port(8080) .timeout(10000) .autoStart(true) .build(); }
How to set polling interval in class with @Configuration? My attempt to deal with it does'nt work. Nothing happens - polling interval remained default 500 ms.
@Configuration public class CitrusSpringConfig {
@Bean
public HttpServer server() {
return new HttpServerBuilder()
.port(8080)
.timeout(10000)
.autoStart(true)
.build();
}
@Bean
public BeforeSuite beforeSuite() {
MessageSelectingQueueChannel messageSelectingQueueChannelServerCallBack = new MessageSelectingQueueChannel();
messageSelectingQueueChannelServerCallBack.setBeanName("server.inbound");
return new SequenceBeforeSuite.Builder().actions
(context -> messageSelectingQueueChannelServerCallBack.setPollingInterval(10)).build();
}
}
Why it's not possible to set polling interval directly in HttpServerBuilder
This is because this is not a setting on the Http server but on the endpoint adapter and the underlying message channel. If you want to set this on the server component, please use a custom channel endpoint adapter with a custom message channel.
How to set polling interval in class with @Configuration?
You before suite action is not setting the message channel on the server component. Only setting the name to server.inbound
is not sufficient in this manner. Instead you should add the message channel as a @Bean
with name server.inbound
. On the Http server bean you can then add a depends-on
predicate to the bean configuration so the server bean depends on the message channel. Then the custom channel is automatically set for the server component.
General question would be why you need to set this polling interval on the server. Usually it is an interval that is used internally. This interval has no effect on the server connections or how the request/response is handled with the clients.
Please let me know if this helps. And I would suggest to close this issue and open another one if there are more questions as it is not really related to the initial problem if this issue. Many thanks!
Why it's not possible to set polling interval directly in HttpServerBuilder
This is because this is not a setting on the Http server but on the endpoint adapter and the underlying message channel. If you want to set this on the server component, please use a custom channel endpoint adapter with a custom message channel.
How to set polling interval in class with @configuration?
You before suite action is not setting the message channel on the server component. Only setting the name to
server.inbound
is not sufficient in this manner. Instead you should add the message channel as a@Bean
with nameserver.inbound
. On the Http server bean you can then add adepends-on
predicate to the bean configuration so the server bean depends on the message channel. Then the custom channel is automatically set for the server component.General question would be why you need to set this polling interval on the server. Usually it is an interval that is used internally. This interval has no effect on the server connections or how the request/response is handled with the clients.
Please let me know if this helps. And I would suggest to close this issue and open another one if there are more questions as it is not really related to the initial problem if this issue. Many thanks!
Thanks for the reply! I'll try it and return with the results asap.
return new SequenceBeforeSuite.Builder().actions(context -> whatever.youWant()).build();
It should look like this?
@Bean
public MessageSelectingQueueChannel serverChannel(){
MessageSelectingQueueChannel messageSelectingQueueChannel = new MessageSelectingQueueChannel();
messageSelectingQueueChannel.setBeanName("server.inbound");
messageSelectingQueueChannel.setPollingInterval(10);
return messageSelectingQueueChannel;
}
@Bean
@DependsOn("serverChannel")
public HttpServer server() {
return new HttpServerBuilder()
.port(8080)
.timeout(10000)
.autoStart(true)
.build();
}
Not exactly, please use server.inbound
as a bean name for serverChannel
One more thing. Since Citrus 4.0 the default implementation on a server is not MessageSelectingQueueChannel
but org.citrusframework.message.DefaultMessageQueue
so I'd suggest to change the bean to this type.
Please let me know if this works for you
org.citrusframework.message.DefaultMessageQueue
Thanks a lot! It works for me!
If somebody interested the sample is the following:
@Bean("server.inbound") public DefaultMessageQueue serverInbound(){
DefaultMessageQueue defaultMessageQueue = new DefaultMessageQueue("server.inbound");
defaultMessageQueue.setPollingInterval(10);
return defaultMessageQueue;
}
@Bean
@DependsOn("server.inbound")
public HttpServer server() {
return new HttpServerBuilder()
.port(8080)
.timeout(10000)
.autoStart(true)
.build();
}
Citrus Version 4.0.0
Question Hi! Could you explain how to work now with BeforeSuite/ AfterSuite, BeforeTest/AfterTest?
In docs for 4.0.0 (https://citrusframework.org/citrus/reference/4.0.0/html/index.html) the examples like this one are still present:
public class MyBeforeSuite extends TestRunnerBeforeSuiteSupport { @Override public void beforeSuite(TestRunner runner) { runner.echo("This action should be executed before suite"); } }
But at 4.0.0 version TestRunnerBeforeSuiteSupport, TestRunnerBeforeTestSupport and etc. don't exist.