Skip to content

Commit 253adbf

Browse files
committed
chore(docs): Fix Citrus documentation code samples
- Update configuration code samples to use Citrus bean, Spring bean and Spring XML bean configurations - Update code samples with proper test case in Java, XML, YAML and Spring XML
1 parent e0473a0 commit 253adbf

21 files changed

+7787
-1436
lines changed

src/manual/data-dictionary.adoc

Lines changed: 294 additions & 25 deletions
Large diffs are not rendered by default.

src/manual/endpoint-adapter.adoc

Lines changed: 353 additions & 43 deletions
Large diffs are not rendered by default.

src/manual/endpoint-docker.adoc

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,31 @@ After that you are able to use customized Citrus XML elements in order to define
3939

4040
Citrus operates with the Docker remote REST API in order to interact with the Docker daemon. The Docker client is defined as Spring bean component in the configuration as follows:
4141

42-
[source,xml]
42+
.Citrus Bean
43+
[source,java,indent=0,role="primary"]
44+
----
45+
@BindToRegistry
46+
public DockerClient dockerClient() {
47+
return new DockerClientBuilder().build();
48+
}
49+
----
50+
51+
.Spring Bean
52+
[source,java,indent=0,role="secondary"]
53+
----
54+
@Bean
55+
public DockerClient dockerClient() {
56+
return new DockerClientBuilder().build();
57+
}
58+
----
59+
60+
.Spring XML
61+
[source,xml,indent=0,role="secondary"]
4362
----
4463
<citrus-docker:client id="dockerClient"/>
4564
----
4665

47-
The Docker client component above is using all default configuration values. By default Citrus is searching the system properties as well as environment variables for default Docker settings such as:
66+
The Docker client component above is using all default configuration values. By default, Citrus is searching the system properties as well as environment variables for default Docker settings such as:
4867

4968
[horizontal]
5069
DOCKER_HOST:: tcp://localhost:2376
@@ -54,7 +73,44 @@ DOCKER_MACHINE_NAME:: default
5473

5574
In case these settings are not settable in your environment you can also use explicit settings in the Docker client component:
5675

57-
[source,xml]
76+
.Citrus Bean
77+
[source,java,indent=0,role="primary"]
78+
----
79+
@BindToRegistry
80+
public DockerClient dockerClient() {
81+
return new DockerClientBuilder()
82+
.url("tcp://localhost:2376")
83+
.version("1.20")
84+
.username("user")
85+
.password("s!cr!t")
86+
.email("user@foo.bar")
87+
.registry("https://index.docker.io/v1/")
88+
.certPath("/path/to/some/cert/directory")
89+
.configPath("/path/to/some/config/directory")
90+
.build();
91+
}
92+
----
93+
94+
.Spring Bean
95+
[source,java,indent=0,role="secondary"]
96+
----
97+
@Bean
98+
public DockerClient dockerClient() {
99+
return new DockerClientBuilder()
100+
.url("tcp://localhost:2376")
101+
.version("1.20")
102+
.username("user")
103+
.password("s!cr!t")
104+
.email("user@foo.bar")
105+
.registry("https://index.docker.io/v1/")
106+
.certPath("/path/to/some/cert/directory")
107+
.configPath("/path/to/some/config/directory")
108+
.build();
109+
}
110+
----
111+
112+
.Spring XML
113+
[source,xml,indent=0,role="secondary"]
58114
----
59115
<citrus-docker:client id="dockerClient"
60116
url="tcp://localhost:2376"

src/manual/endpoint-file.adoc

Lines changed: 144 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,170 @@ In chapter link:#message-channels[message-channels] we have discussed the native
88

99
We want to use the Spring Integration file adapter for both reading and writing files with a local directory. Citrus can easily connect to this file adapter implementation with its message channel support. Citrus message sender and receiver speak to message channels that are connected to the Spring Integration file adapters.
1010

11-
[source,xml]
11+
.Citrus Bean
12+
[source,java,indent=0,role="primary"]
1213
----
13-
<citrus-si:channel-endpoint id="fileEndpoint" channel="fileChannel"/>
14-
15-
<file:outbound-channel-adapter id="fileOutboundAdapter"
16-
channel="fileChannel"
17-
directory="file:${some.directory.property}"/>
18-
19-
<si:channel id="fileChannel"/>
14+
@BindToRegistry
15+
public ChannelEndpointAdapter fileEndpoint() {
16+
ChannelSyncEndpointConfiguration endpointConfiguration = new ChannelSyncEndpointConfiguration();
17+
endpointConfiguration.setChannelName("fileChannel");
18+
return new ChannelEndpointAdapter(endpointConfiguration);
19+
}
20+
21+
@BindToRegistry
22+
public MessageChannel fileChannel() {
23+
return new DirectChannel();
24+
}
25+
26+
@BindToRegistry
27+
public FileWritingMessageHandler fileOutboundAdapter() {
28+
FileWritingMessageHandler messageHandler = new FileWritingMessageHandler(new File("some/directory"));
29+
messageHandler.setOutboundChannel(fileChannel());
30+
return messageHandler;
31+
}
2032
----
2133

22-
The configuration above describes a Citrus message channel endpoint connected to a Spring Integration outbound file adapter that writes messages to a storage directory. With this combination you are able to write files to a directory in your Citrus test case. The test case uses the channel endpoint in its send action and the endpoint interacts with the Spring Integration file adapter so sending out the file.
23-
24-
NOTE: The Spring Integration file adapter configuration components add a new namespace to our Spring application context. See this template which holds all necessary namespaces and schema locations:
34+
.Spring Bean
35+
[source,java,indent=0,role="secondary"]
36+
----
37+
@Bean
38+
public ChannelEndpointAdapter fileEndpoint() {
39+
ChannelSyncEndpointConfiguration endpointConfiguration = new ChannelSyncEndpointConfiguration();
40+
endpointConfiguration.setChannelName("fileChannel");
41+
return new ChannelEndpointAdapter(endpointConfiguration);
42+
}
43+
44+
@Bean
45+
public MessageChannel fileChannel() {
46+
return new DirectChannel();
47+
}
48+
49+
@Bean
50+
public FileWritingMessageHandler fileOutboundAdapter() {
51+
FileWritingMessageHandler messageHandler = new FileWritingMessageHandler(new File("some/directory"));
52+
messageHandler.setOutboundChannel(fileChannel());
53+
return messageHandler;
54+
}
55+
----
2556

26-
[source,xml]
57+
.Spring XML
58+
[source,xml,indent=0,role="secondary"]
2759
----
2860
<?xml version="1.0" encoding="UTF-8"?>
2961
<beans xmlns="http://www.springframework.org/schema/beans"
3062
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3163
xmlns:citrus="http://www.citrusframework.org/schema/config"
64+
xmlns:citrus-si="http://www.citrusframework.org/schema/spring-integration/config"
3265
xmlns:si="http://www.springframework.org/schema/integration"
33-
xmlns:file="http://www.springframework.org/schema/integration/file"
66+
xmlns:si-file="http://www.springframework.org/schema/integration/file"
3467
xsi:schemaLocation="http://www.springframework.org/schema/beans
35-
http://www.springframework.org/schema/beans/spring-beans.xsd
36-
http://www.citrusframework.org/schema/config
37-
http://www.citrusframework.org/schema/config/citrus-config.xsd
38-
http://www.springframework.org/schema/integration
39-
http://www.springframework.org/schema/integration/spring-integration.xsd
40-
http://www.springframework.org/schema/integration/file
41-
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
42-
</beans>
68+
http://www.springframework.org/schema/beans/spring-beans.xsd
69+
http://www.citrusframework.org/schema/config
70+
http://www.citrusframework.org/schema/config/citrus-config.xsd
71+
http://www.citrusframework.org/schema/spring-integration/config
72+
http://www.citrusframework.org/schema/spring-integration/config/citrus-spring-integration-config.xsd
73+
http://www.springframework.org/schema/integration
74+
http://www.springframework.org/schema/integration/spring-integration.xsd
75+
http://www.springframework.org/schema/integration/file
76+
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
77+
<citrus-si:channel-endpoint id="fileEndpoint" channel="fileChannel"/>
78+
79+
<si-file:outbound-channel-adapter id="fileOutboundAdapter"
80+
channel="fileChannel"
81+
directory="file:some/directory"/>
82+
83+
<si:channel id="fileChannel"/>
84+
</beans>
4385
----
4486

87+
The configuration above describes a Citrus message channel endpoint connected to a Spring Integration outbound file adapter that writes messages to a storage directory.
88+
With this combination you are able to write files to a directory in your Citrus test case.
89+
The test case uses the channel endpoint in its send action and the endpoint interacts with the Spring Integration file adapter so sending out the file.
90+
91+
NOTE: The Spring Integration file adapter configuration component adds new namespaces (`si`, `si-file`, `citrus-si`) to the Spring XML application context. Please see the individual XML schema locations for details of the supported component in these namespaces.
92+
4593
[[read-files]]
4694
== Read files
4795

4896
The next program listing shows a possible inbound file communication. So the Spring Integration file inbound adapter will read files from a storage directory and publish the file contents to a message channel. Citrus can then receive those files as messages in a test case via the channel endpoint and validate the file contents for instance.
4997

50-
[source,xml]
98+
.Citrus Bean
99+
[source,java,indent=0,role="primary"]
100+
----
101+
@BindToRegistry
102+
public ChannelEndpointAdapter fileEndpoint() {
103+
ChannelSyncEndpointConfiguration endpointConfiguration = new ChannelSyncEndpointConfiguration();
104+
endpointConfiguration.setChannelName("fileChannel");
105+
return new ChannelEndpointAdapter(endpointConfiguration);
106+
}
107+
108+
@BindToRegistry
109+
public MessageChannel fileChannel() {
110+
return new DirectChannel();
111+
}
112+
113+
@BindToRegistry
114+
public FileWritingMessageHandler fileOutboundAdapter() {
115+
FileWritingMessageHandler messageHandler = new FileWritingMessageHandler(new File("some/directory"));
116+
messageHandler.setOutboundChannel(fileChannel());
117+
return messageHandler;
118+
}
119+
----
120+
121+
.Spring Bean
122+
[source,java,indent=0,role="secondary"]
51123
----
52-
<file:inbound-channel-adapter id="fileInboundAdapter"
124+
@Bean
125+
public ChannelEndpointAdapter fileEndpoint() {
126+
ChannelSyncEndpointConfiguration endpointConfiguration = new ChannelSyncEndpointConfiguration();
127+
endpointConfiguration.setChannelName("fileChannel");
128+
return new ChannelEndpointAdapter(endpointConfiguration);
129+
}
130+
131+
@Bean
132+
public MessageChannel fileChannel() {
133+
return new DirectChannel();
134+
}
135+
136+
@Bean
137+
public FileReadingMessageSource fileInboundAdapter() {
138+
FileReadingMessageSource messageSource = new FileReadingMessageSource();
139+
messageSource.setDirectory(new File("some/directory"));
140+
messageSource.setInboundChannel(fileChannel());
141+
return messageSource;
142+
}
143+
----
144+
145+
.Spring XML
146+
[source,xml,indent=0,role="secondary"]
147+
----
148+
<?xml version="1.0" encoding="UTF-8"?>
149+
<beans xmlns="http://www.springframework.org/schema/beans"
150+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
151+
xmlns:citrus="http://www.citrusframework.org/schema/config"
152+
xmlns:citrus-si="http://www.citrusframework.org/schema/spring-integration/config"
153+
xmlns:si="http://www.springframework.org/schema/integration"
154+
xmlns:si-file="http://www.springframework.org/schema/integration/file"
155+
xsi:schemaLocation="http://www.springframework.org/schema/beans
156+
http://www.springframework.org/schema/beans/spring-beans.xsd
157+
http://www.citrusframework.org/schema/config
158+
http://www.citrusframework.org/schema/config/citrus-config.xsd
159+
http://www.citrusframework.org/schema/spring-integration/config
160+
http://www.citrusframework.org/schema/spring-integration/config/citrus-spring-integration-config.xsd
161+
http://www.springframework.org/schema/integration
162+
http://www.springframework.org/schema/integration/spring-integration.xsd
163+
http://www.springframework.org/schema/integration/file
164+
http://www.springframework.org/schema/integration/file/spring-integration-file.xsd">
165+
166+
<citrus-si:channel-endpoint id="fileEndpoint" channel="fileChannel"/>
167+
168+
<si-file:inbound-channel-adapter id="fileInboundAdapter"
53169
channel="fileChannel"
54-
directory="file:${some.directory.property}">
170+
directory="file:some/directory">
55171
<si:poller fixed-rate="100"/>
56-
</file:inbound-channel-adapter>
172+
</si-file:inbound-channel-adapter>
57173
58-
<si:channel id="fileChannel">
174+
<si:channel id="fileChannel">
59175
<si:queue capacity="25"/>
60176
<si:interceptors>
61177
<bean class="org.springframework.integration.transformer.MessageTransformingChannelInterceptor">
@@ -64,9 +180,9 @@ The next program listing shows a possible inbound file communication. So the Spr
64180
</constructor-arg>
65181
</bean>
66182
</si:interceptors>
67-
</si:channel>
183+
</si:channel>
68184
69-
<citrus-si:channel-endpoint id="fileEndpoint" channel="fileChannel"/>
185+
</beans>
70186
----
71187

72188
IMPORTANT: The file inbound adapter constructs Java file objects as the message payload by default. Citrus can only work on String message payloads. So we need a file transformer that converts the file objects to String payloads representing the file's content.

src/manual/endpoint-ftp.adoc

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -594,18 +594,26 @@ Listing files results in a command result that gives us the list of files on the
594594

595595
Now that we are able to access FTP as a client we might also want to simulate the server side. Therefore Citrus offers a server component that is listening on a port for incoming FTP connections. The server has a default home directory on the local file system specified. But you can also define home directories per user. For now let us have a look at the server configuration component:
596596

597-
.XML
598-
[source,xml]
597+
.Citrus Bean
598+
[source,java,indent=0,role="primary"]
599599
----
600-
<citrus-ftp:server id="ftpServer">
601-
port="2222"
602-
auto-start="true"
603-
auto-handle-commands="MKD,PORT,TYPE"
604-
user-manager-properties="classpath:ftp.server.properties"/>
600+
@BindToRegistry
601+
public FtpServer ftpListServer() {
602+
return CitrusEndpoints.ftp()
603+
.server()
604+
.port(2222)
605+
.autoLogin(true)
606+
.autoStart(true)
607+
.autoHandleCommands(Stream.of(FTPCmd.MKD.getCommand(),
608+
FTPCmd.PORT.getCommand(),
609+
FTPCmd.TYPE.getCommand()).collect(Collectors.joining(",")))
610+
.userManagerProperties(new ClassPathResource("citrus.ftp.user.properties"))
611+
.build();
612+
}
605613
----
606614

607-
.Java
608-
[source,java]
615+
.Spring Bean
616+
[source,java,indent=0,role="secondary"]
609617
----
610618
@Bean
611619
public FtpServer ftpListServer() {
@@ -619,6 +627,17 @@ public FtpServer ftpListServer() {
619627
FTPCmd.TYPE.getCommand()).collect(Collectors.joining(",")))
620628
.userManagerProperties(new ClassPathResource("citrus.ftp.user.properties"))
621629
.build();
630+
}
631+
----
632+
633+
.Spring XML
634+
[source,xml,indent=0,role="secondary"]
635+
----
636+
<citrus-ftp:server id="ftpServer"
637+
port="2222"
638+
auto-start="true"
639+
auto-handle-commands="MKD,PORT,TYPE"
640+
user-manager-properties="classpath:ftp.server.properties"/>
622641
----
623642

624643
The ftp server configuration is quite simple. The server starts automatically and binds to a port. With `autoLogin` and `autoHandleCommands` we can specify the behavior of the server.
@@ -627,7 +646,7 @@ have to verify those commands in a test case. The server will automatically resp
627646

628647
The user configuration is read from a *user-manager-property* file. Let us have a look at the content of this user management file:
629648

630-
[source,xml]
649+
[source,properties]
631650
----
632651
# Password is "admin"
633652
ftpserver.user.admin.userpassword=c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec

src/manual/endpoint-jdbc.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Citrus is able to verify the behavior of your system under test concerning start
178178
actions of transactions. The verification of transactions has to be enabled in the server Citrus-JDBC-Server
179179
configuration. For more information, please have a look at the <<jdbc-server-configuration>> section.
180180

181-
.Verifiying transaction commit
181+
.Verifying transaction commit
182182
[source,java]
183183
----
184184
receive(jdbcServer)

0 commit comments

Comments
 (0)