13
13
14
14
package io .dapr .it .spring .data ;
15
15
16
- import com .fasterxml .jackson .databind .ObjectMapper ;
17
16
import io .dapr .client .DaprClient ;
18
- import io .dapr .client .DaprClientBuilder ;
19
- import io .dapr .spring .data .DaprKeyValueAdapterResolver ;
20
17
import io .dapr .spring .data .DaprKeyValueTemplate ;
21
- import io .dapr .spring .data .KeyValueAdapterResolver ;
22
18
import io .dapr .testcontainers .Component ;
23
19
import io .dapr .testcontainers .DaprContainer ;
24
20
import io .dapr .testcontainers .DaprLogLevel ;
25
21
import org .junit .jupiter .api .AfterEach ;
26
- import org .junit .jupiter .api .BeforeAll ;
27
- import org .junit .jupiter .api .BeforeEach ;
22
+ import org .junit .jupiter .api .Tag ;
28
23
import org .junit .jupiter .api .Test ;
24
+ import org .junit .jupiter .api .extension .ExtendWith ;
25
+ import org .springframework .beans .factory .annotation .Autowired ;
29
26
import org .springframework .data .keyvalue .core .query .KeyValueQuery ;
27
+ import org .springframework .test .context .ContextConfiguration ;
28
+ import org .springframework .test .context .DynamicPropertyRegistry ;
29
+ import org .springframework .test .context .DynamicPropertySource ;
30
+ import org .springframework .test .context .junit .jupiter .SpringExtension ;
30
31
import org .testcontainers .containers .MySQLContainer ;
31
32
import org .testcontainers .containers .Network ;
32
33
import org .testcontainers .junit .jupiter .Container ;
41
42
42
43
import static io .dapr .it .spring .data .DaprSpringDataConstants .STATE_STORE_NAME ;
43
44
import static io .dapr .it .spring .data .DaprSpringDataConstants .BINDING_NAME ;
44
- import static io .dapr .it .spring .data .DaprSpringDataConstants .PUBSUB_NAME ;
45
45
import static org .assertj .core .api .Assertions .assertThat ;
46
46
import static org .junit .jupiter .api .Assertions .assertEquals ;
47
47
48
48
/**
49
49
* Integration tests for {@link MySQLDaprKeyValueTemplateIT}.
50
50
*/
51
51
@ SuppressWarnings ("AbbreviationAsWordInName" )
52
+ @ ExtendWith (SpringExtension .class )
53
+ @ ContextConfiguration (classes = TestDaprSpringDataConfiguration .class )
52
54
@ Testcontainers
55
+ @ Tag ("testcontainers" )
53
56
public class MySQLDaprKeyValueTemplateIT {
54
57
private static final String STATE_STORE_DSN = "mysql:password@tcp(mysql:3306)/" ;
55
58
private static final String BINDING_DSN = "mysql:password@tcp(mysql:3306)/dapr_db" ;
@@ -70,39 +73,19 @@ public class MySQLDaprKeyValueTemplateIT {
70
73
71
74
@ Container
72
75
private static final DaprContainer DAPR_CONTAINER = new DaprContainer ("daprio/daprd:1.13.2" )
73
- .withAppName ("local -dapr-app" )
76
+ .withAppName ("mysql -dapr-app" )
74
77
.withNetwork (DAPR_NETWORK )
75
78
.withComponent (new Component (STATE_STORE_NAME , "state.mysql" , "v1" , STATE_STORE_PROPERTIES ))
76
79
.withComponent (new Component (BINDING_NAME , "bindings.mysql" , "v1" , BINDING_PROPERTIES ))
77
- .withComponent (new Component (PUBSUB_NAME , "pubsub.in-memory" , "v1" , Collections .emptyMap ()))
78
- .withAppPort (8080 )
79
80
.withDaprLogLevel (DaprLogLevel .DEBUG )
80
- .withAppChannelAddress ("host.testcontainers.internal" )
81
81
.withLogConsumer (outputFrame -> System .out .println (outputFrame .getUtf8String ()))
82
82
.dependsOn (MY_SQL_CONTAINER );
83
83
84
- private final ObjectMapper mapper = new ObjectMapper ();
85
-
86
- private DaprClient daprClient ;
87
- private DaprKeyValueTemplate keyValueTemplate ;
88
-
89
- @ BeforeAll
90
- static void beforeAll () {
91
- org .testcontainers .Testcontainers .exposeHostPorts (8080 );
92
- }
93
-
94
- @ BeforeEach
95
- public void setUp () {
96
- daprClient = new DaprClientBuilder ().build ();
97
- KeyValueAdapterResolver daprKeyValueResolver = new DaprKeyValueAdapterResolver (
98
- daprClient ,
99
- mapper ,
100
- STATE_STORE_NAME ,
101
- BINDING_NAME
102
- );
103
- keyValueTemplate = new DaprKeyValueTemplate (daprKeyValueResolver );
104
-
105
- daprClient .waitForSidecar (10000 ).block ();
84
+ @ DynamicPropertySource
85
+ static void daprProperties (DynamicPropertyRegistry registry ) {
86
+ DAPR_CONTAINER .start ();
87
+ registry .add ("dapr.grpc.port" , DAPR_CONTAINER ::getGrpcPort );
88
+ registry .add ("dapr.http.port" , DAPR_CONTAINER ::getHttpPort );
106
89
}
107
90
108
91
private static Map <String , String > createStateStoreProperties () {
@@ -116,6 +99,12 @@ private static Map<String, String> createStateStoreProperties() {
116
99
return result ;
117
100
}
118
101
102
+ @ Autowired
103
+ private DaprClient daprClient ;
104
+
105
+ @ Autowired
106
+ private DaprKeyValueTemplate keyValueTemplate ;
107
+
119
108
/**
120
109
* Cleans up the state store after each test.
121
110
*/
0 commit comments