Skip to content

Commit acba370

Browse files
committed
Remove flaky test using Testcontainers and a more specific test approach
Signed-off-by: Matheus Cruz <[email protected]>
1 parent 0572e24 commit acba370

File tree

12 files changed

+286
-144
lines changed

12 files changed

+286
-144
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package io.dapr.spring.boot.autoconfigure.client;
2+
3+
import org.assertj.core.api.SoftAssertions;
4+
import org.junit.Test;
5+
import org.junit.jupiter.api.DisplayName;
6+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
7+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
8+
9+
public class DaprClientPropertiesTest {
10+
11+
12+
private final ApplicationContextRunner runner = new ApplicationContextRunner()
13+
.withUserConfiguration(EnableDaprClientProperties.class);
14+
15+
@Test
16+
@DisplayName("Should create DaprClientProperties correctly through constructor")
17+
public void shouldCreateDaprClientPropertiesCorrectly() {
18+
19+
DaprClientProperties properties = new DaprClientProperties(
20+
"http://localhost", "localhost", 3500, 50001
21+
);
22+
23+
SoftAssertions.assertSoftly(softAssertions -> {
24+
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
25+
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
26+
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500);
27+
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001);
28+
});
29+
}
30+
31+
@Test
32+
@DisplayName("Should create DaprClientProperties correctly through setters")
33+
public void shouldSetDaprClientPropertiesCorrectly() {
34+
35+
DaprClientProperties properties = new DaprClientProperties();
36+
37+
properties.setGrpcEndpoint("localhost");
38+
properties.setGrpcPort(50001);
39+
properties.setHttpEndpoint("http://localhost");
40+
properties.setHttpPort(3500);
41+
42+
SoftAssertions.assertSoftly(softAssertions -> {
43+
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
44+
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
45+
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500);
46+
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001);
47+
});
48+
}
49+
50+
@Test
51+
@DisplayName("Should map DaprClient properties correctly")
52+
public void shouldMapDaprClientProperties() {
53+
54+
runner.withSystemProperties(
55+
"dapr.client.http-endpoint=http://localhost",
56+
"dapr.client.http-port=3500",
57+
"dapr.client.grpc-endpoint=localhost",
58+
"dapr.client.grpc-port=50001"
59+
).run(context -> {
60+
DaprClientProperties properties = context.getBean(DaprClientProperties.class);
61+
SoftAssertions.assertSoftly(softAssertions -> {
62+
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
63+
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
64+
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500);
65+
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001);
66+
});
67+
68+
});
69+
70+
}
71+
72+
@EnableConfigurationProperties(DaprClientProperties.class)
73+
static class EnableDaprClientProperties {
74+
75+
}
76+
}

sdk-tests/pom.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@
240240
<version>1.3.2</version>
241241
<scope>compile</scope>
242242
</dependency>
243-
<dependency>
244-
<groupId>eu.rekawek.toxiproxy</groupId>
245-
<artifactId>toxiproxy-java</artifactId>
246-
<version>2.1.7</version>
247-
</dependency>
248243
<dependency>
249244
<groupId>jakarta.servlet</groupId>
250245
<artifactId>jakarta.servlet-api</artifactId>
@@ -260,6 +255,12 @@
260255
<artifactId>junit-platform-engine</artifactId>
261256
<scope>test</scope>
262257
</dependency>
258+
<dependency>
259+
<groupId>org.testcontainers</groupId>
260+
<artifactId>toxiproxy</artifactId>
261+
<version>${testcontainers-test.version}</version>
262+
<scope>test</scope>
263+
</dependency>
263264
</dependencies>
264265

265266
<build>

0 commit comments

Comments
 (0)