-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
121 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.inject.Inject; | ||
import org.apache.camel.demo.behavior.VerifyBookingCompletedMail; | ||
import org.apache.camel.demo.behavior.WaitForEntityPersisted; | ||
import org.apache.camel.demo.behavior.WaitForProductCreated; | ||
import org.apache.camel.demo.model.Booking; | ||
import org.apache.camel.demo.model.Product; | ||
import org.apache.camel.demo.model.Supply; | ||
|
@@ -31,18 +34,15 @@ | |
import org.citrusframework.annotations.CitrusEndpoint; | ||
import org.citrusframework.annotations.CitrusResource; | ||
import org.citrusframework.kafka.endpoint.KafkaEndpoint; | ||
import org.citrusframework.mail.message.MailMessage; | ||
import org.citrusframework.mail.server.MailServer; | ||
import org.citrusframework.quarkus.CitrusSupport; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.citrusframework.actions.ExecuteSQLAction.Builder.sql; | ||
import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive; | ||
import static org.citrusframework.actions.SendMessageAction.Builder.send; | ||
import static org.citrusframework.actions.SleepAction.Builder.delay; | ||
import static org.citrusframework.container.Iterate.Builder.iterate; | ||
import static org.citrusframework.container.Parallel.Builder.parallel; | ||
import static org.citrusframework.container.RepeatOnErrorUntilTrue.Builder.repeatOnError; | ||
import static org.citrusframework.dsl.JsonSupport.marshal; | ||
|
||
@QuarkusTest | ||
|
@@ -81,28 +81,14 @@ void shouldCompleteOnSupply() { | |
.endpoint(products) | ||
.message().body(marshal(product))); | ||
|
||
t.then(repeatOnError() | ||
.condition((i, context) -> i > 25) | ||
.autoSleep(500) | ||
.actions(sql().dataSource(dataSource) | ||
.query() | ||
.statement("select count(id) as found from product where product.name='%s'".formatted(product.getName())) | ||
.validate("found", "1")) | ||
); | ||
t.then(t.applyBehavior(new WaitForProductCreated(product, dataSource))); | ||
|
||
Booking booking = new Booking("citrus-test", product, 100, 0.99D); | ||
t.when(send() | ||
.endpoint(bookings) | ||
.message().body(marshal(booking))); | ||
|
||
t.then(repeatOnError() | ||
.condition((i, context) -> i > 25) | ||
.autoSleep(500) | ||
.actions(sql().dataSource(dataSource) | ||
.query() | ||
.statement("select count(id) as found from booking where booking.status='PENDING'") | ||
.validate("found", "1")) | ||
); | ||
t.then(t.applyBehavior(new WaitForEntityPersisted(booking, dataSource))); | ||
|
||
Supply supply = new Supply(product, 100, 0.99D); | ||
t.when(send() | ||
|
@@ -122,16 +108,7 @@ void shouldCompleteOnSupply() { | |
.message().body(marshal(shippingEvent)) | ||
)); | ||
|
||
t.then(receive() | ||
.endpoint(mailServer) | ||
.message(MailMessage.request("[email protected]", "%[email protected]".formatted(completedEvent.getClient()), "Booking completed!") | ||
.body("Hey %s, your booking %s has been completed.".formatted(completedEvent.getClient(), completedEvent.getProduct()), "text/plain")) | ||
); | ||
|
||
t.then(send() | ||
.endpoint(mailServer) | ||
.message(MailMessage.response()) | ||
); | ||
t.then(t.applyBehavior(new VerifyBookingCompletedMail(booking, mailServer))); | ||
} | ||
|
||
@Test | ||
|
@@ -143,14 +120,7 @@ void shouldCompleteOnBooking() { | |
.endpoint(supplies) | ||
.message().body(marshal(supply))); | ||
|
||
t.then(repeatOnError() | ||
.condition((i, context) -> i > 25) | ||
.autoSleep(500) | ||
.actions(sql().dataSource(dataSource) | ||
.query() | ||
.statement("select count(id) as found from supply where supply.status='AVAILABLE'") | ||
.validate("found", "1")) | ||
); | ||
t.then(t.applyBehavior(new WaitForEntityPersisted(supply, dataSource))); | ||
|
||
Booking booking = new Booking("citrus-test", product, 100, 0.99D); | ||
t.when(send() | ||
|
@@ -170,16 +140,7 @@ void shouldCompleteOnBooking() { | |
.message().body(marshal(shippingEvent)) | ||
)); | ||
|
||
t.then(receive() | ||
.endpoint(mailServer) | ||
.message(MailMessage.request("[email protected]", "%[email protected]".formatted(completedEvent.getClient()), "Booking completed!") | ||
.body("Hey %s, your booking %s has been completed.".formatted(completedEvent.getClient(), completedEvent.getProduct()), "text/plain")) | ||
); | ||
|
||
t.then(send() | ||
.endpoint(mailServer) | ||
.message(MailMessage.response()) | ||
); | ||
t.then(t.applyBehavior(new VerifyBookingCompletedMail(booking, mailServer))); | ||
} | ||
|
||
@Test | ||
|
36 changes: 36 additions & 0 deletions
36
...mple-quarkus/src/test/java/org/apache/camel/demo/behavior/VerifyBookingCompletedMail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.apache.camel.demo.behavior; | ||
|
||
import org.apache.camel.demo.model.Booking; | ||
import org.citrusframework.TestActionRunner; | ||
import org.citrusframework.TestBehavior; | ||
import org.citrusframework.mail.message.MailMessage; | ||
import org.citrusframework.mail.server.MailServer; | ||
|
||
import static org.citrusframework.actions.ReceiveMessageAction.Builder.receive; | ||
import static org.citrusframework.actions.SendMessageAction.Builder.send; | ||
|
||
public class VerifyBookingCompletedMail implements TestBehavior { | ||
|
||
private final Booking booking; | ||
private final MailServer mailServer; | ||
|
||
public VerifyBookingCompletedMail(Booking booking, MailServer mailServer) { | ||
this.booking = booking; | ||
this.mailServer = mailServer; | ||
} | ||
|
||
@Override | ||
public void apply(TestActionRunner t) { | ||
t.run(receive() | ||
.endpoint(mailServer) | ||
.message(MailMessage.request("[email protected]", "%[email protected]".formatted(booking.getClient()), "Booking completed!") | ||
.body("Hey %s, your booking %s has been completed." | ||
.formatted(booking.getClient(), booking.getProduct().getName()), "text/plain")) | ||
); | ||
|
||
t.run(send() | ||
.endpoint(mailServer) | ||
.message(MailMessage.response()) | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
demo/sample-quarkus/src/test/java/org/apache/camel/demo/behavior/WaitForEntityPersisted.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.apache.camel.demo.behavior; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.camel.demo.model.Booking; | ||
import org.apache.camel.demo.model.Supply; | ||
import org.citrusframework.TestActionRunner; | ||
import org.citrusframework.TestBehavior; | ||
|
||
import static org.citrusframework.actions.ExecuteSQLAction.Builder.sql; | ||
import static org.citrusframework.container.RepeatOnErrorUntilTrue.Builder.repeatOnError; | ||
|
||
public class WaitForEntityPersisted implements TestBehavior { | ||
|
||
private final String entityName; | ||
private final String status; | ||
private final DataSource dataSource; | ||
|
||
public WaitForEntityPersisted(Booking booking, DataSource dataSource) { | ||
this.entityName = "booking"; | ||
this.status = booking.getStatus().name(); | ||
this.dataSource = dataSource; | ||
} | ||
|
||
public WaitForEntityPersisted(Supply supply, DataSource dataSource) { | ||
this.entityName = "supply"; | ||
this.status = supply.getStatus().name(); | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@Override | ||
public void apply(TestActionRunner t) { | ||
t.run(repeatOnError() | ||
.condition((i, context) -> i > 25) | ||
.autoSleep(500) | ||
.actions(sql().dataSource(dataSource) | ||
.query() | ||
.statement("select count(id) as found from %s where %s.status='%s'" | ||
.formatted(entityName, entityName, status)) | ||
.validate("found", "1")) | ||
); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
demo/sample-quarkus/src/test/java/org/apache/camel/demo/behavior/WaitForProductCreated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.apache.camel.demo.behavior; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.apache.camel.demo.model.Product; | ||
import org.citrusframework.TestActionRunner; | ||
import org.citrusframework.TestBehavior; | ||
|
||
import static org.citrusframework.actions.ExecuteSQLAction.Builder.sql; | ||
import static org.citrusframework.container.RepeatOnErrorUntilTrue.Builder.repeatOnError; | ||
|
||
public class WaitForProductCreated implements TestBehavior { | ||
|
||
private final Product product; | ||
private final DataSource dataSource; | ||
|
||
public WaitForProductCreated(Product product, DataSource dataSource) { | ||
this.product = product; | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@Override | ||
public void apply(TestActionRunner t) { | ||
t.run(repeatOnError() | ||
.condition((i, context) -> i > 25) | ||
.autoSleep(500) | ||
.actions(sql().dataSource(dataSource) | ||
.query() | ||
.statement("select count(id) as found from product where product.name='%s'" | ||
.formatted(product.getName())) | ||
.validate("found", "1")) | ||
); | ||
} | ||
} |