11package io .dapr .it .spring .feign ;
22
3+ import io .dapr .client .DaprClient ;
4+ import io .dapr .client .domain .HttpExtension ;
35import io .dapr .testcontainers .Component ;
46import io .dapr .testcontainers .DaprContainer ;
57import io .dapr .testcontainers .DaprLogLevel ;
8+ import io .dapr .utils .TypeRef ;
9+ import org .junit .jupiter .api .BeforeAll ;
10+ import org .junit .jupiter .api .BeforeEach ;
611import org .junit .jupiter .api .Tag ;
712import org .junit .jupiter .api .Test ;
813import org .junit .jupiter .api .extension .ExtendWith ;
1217import org .springframework .test .context .junit .jupiter .SpringExtension ;
1318import org .testcontainers .containers .Network ;
1419import org .testcontainers .containers .PostgreSQLContainer ;
20+ import org .testcontainers .containers .wait .strategy .Wait ;
1521import org .testcontainers .junit .jupiter .Container ;
1622import org .testcontainers .junit .jupiter .Testcontainers ;
1723
24+ import java .util .Arrays ;
25+ import java .util .Collections ;
1826import java .util .HashMap ;
1927import java .util .Map ;
2028
2129import static io .dapr .it .spring .data .DaprSpringDataConstants .STATE_STORE_NAME ;
2230import static io .dapr .it .testcontainers .DaprContainerConstants .IMAGE_TAG ;
2331import static org .junit .jupiter .api .Assertions .assertEquals ;
2432
25- @ ExtendWith (SpringExtension .class )
26- @ SpringBootTest (properties = {"dapr.feign.enable=true" })
33+ @ SpringBootTest (
34+ webEnvironment = SpringBootTest .WebEnvironment .DEFINED_PORT ,
35+ classes = {
36+ DaprFeignTestApplication .class
37+ },
38+ properties = {
39+ "dapr.feign.enabled=true" ,
40+ "dapr.feign.retries=1"
41+ }
42+ )
2743@ Testcontainers
2844@ Tag ("testcontainers" )
2945public class DaprFeignIT {
@@ -36,6 +52,9 @@ public class DaprFeignIT {
3652
3753 public static final String BINDING_NAME = "postgresbinding" ;
3854
55+ private static final int APP_PORT = 8080 ;
56+ private static final String SUBSCRIPTION_MESSAGE_PATTERN = ".*app is subscribed to the following topics.*" ;
57+
3958 @ Container
4059 private static final PostgreSQLContainer <?> POSTGRE_SQL_CONTAINER = new PostgreSQLContainer <>("postgres:16-alpine" )
4160 .withNetworkAliases ("postgres-repository" )
@@ -49,11 +68,26 @@ public class DaprFeignIT {
4968 private static final DaprContainer DAPR_CONTAINER = new DaprContainer (IMAGE_TAG )
5069 .withAppName ("dapr-feign-test" )
5170 .withNetwork (DAPR_NETWORK )
71+ .withComponent (new Component ("pubsub" , "pubsub.in-memory" , "v1" , Collections .emptyMap ()))
5272 .withComponent (new Component (BINDING_NAME , "bindings.postgresql" , "v1" , BINDING_PROPERTIES ))
5373 .withDaprLogLevel (DaprLogLevel .DEBUG )
74+ .withAppPort (APP_PORT )
75+ .withAppHealthCheckPath ("/ready" )
76+ .withAppChannelAddress ("host.testcontainers.internal" )
5477 .withLogConsumer (outputFrame -> System .out .println (outputFrame .getUtf8String ()))
5578 .dependsOn (POSTGRE_SQL_CONTAINER );
5679
80+ @ BeforeAll
81+ public static void beforeAll (){
82+ org .testcontainers .Testcontainers .exposeHostPorts (APP_PORT );
83+ }
84+
85+ @ BeforeEach
86+ public void beforeEach () {
87+ // Ensure the subscriptions are registered
88+ Wait .forLogMessage (SUBSCRIPTION_MESSAGE_PATTERN , 1 ).waitUntilReady (DAPR_CONTAINER );
89+ }
90+
5791 @ Autowired
5892 PostgreBindingClient postgreBindingClient ;
5993
@@ -66,9 +100,18 @@ public void invokeBindingTest() {
66100 }
67101
68102 @ Test
69- public void invokeMethodTest () {
103+ public void invokeSimpleGetMethodTest () {
70104 assertEquals ("hello" , testMethodClient .hello ());
105+ }
106+
107+ @ Test
108+ public void invokeSimplePostMethodTest () {
71109 assertEquals ("hello" , testMethodClient .echo ("hello" ));
72110 }
73111
112+ @ Test
113+ public void invokeJsonMethodTest () {
114+ assertEquals ("hello" , testMethodClient .echoJson ("hello" ).getMessage ());
115+ }
116+
74117}
0 commit comments