Skip to content

Commit 8cb8099

Browse files
authored
Remove flaky test using Testcontainers and a more specific test approach (#1288)
* Remove flaky test using Testcontainers and a more specific test approach Signed-off-by: Matheus Cruz <[email protected]> * Add license header Signed-off-by: Matheus Cruz <[email protected]> --------- Signed-off-by: Matheus Cruz <[email protected]>
1 parent 0572e24 commit 8cb8099

File tree

11 files changed

+283
-141
lines changed

11 files changed

+283
-141
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright 2024 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.spring.boot.autoconfigure.client;
15+
16+
import org.assertj.core.api.SoftAssertions;
17+
import org.junit.Test;
18+
import org.junit.jupiter.api.DisplayName;
19+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
20+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
21+
22+
public class DaprClientPropertiesTest {
23+
24+
25+
private final ApplicationContextRunner runner = new ApplicationContextRunner()
26+
.withUserConfiguration(EnableDaprClientProperties.class);
27+
28+
@Test
29+
@DisplayName("Should create DaprClientProperties correctly through constructor")
30+
public void shouldCreateDaprClientPropertiesCorrectly() {
31+
32+
DaprClientProperties properties = new DaprClientProperties(
33+
"http://localhost", "localhost", 3500, 50001
34+
);
35+
36+
SoftAssertions.assertSoftly(softAssertions -> {
37+
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
38+
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
39+
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500);
40+
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001);
41+
});
42+
}
43+
44+
@Test
45+
@DisplayName("Should create DaprClientProperties correctly through setters")
46+
public void shouldSetDaprClientPropertiesCorrectly() {
47+
48+
DaprClientProperties properties = new DaprClientProperties();
49+
50+
properties.setGrpcEndpoint("localhost");
51+
properties.setGrpcPort(50001);
52+
properties.setHttpEndpoint("http://localhost");
53+
properties.setHttpPort(3500);
54+
55+
SoftAssertions.assertSoftly(softAssertions -> {
56+
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
57+
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
58+
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500);
59+
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001);
60+
});
61+
}
62+
63+
@Test
64+
@DisplayName("Should map DaprClient properties correctly")
65+
public void shouldMapDaprClientProperties() {
66+
67+
runner.withSystemProperties(
68+
"dapr.client.http-endpoint=http://localhost",
69+
"dapr.client.http-port=3500",
70+
"dapr.client.grpc-endpoint=localhost",
71+
"dapr.client.grpc-port=50001"
72+
).run(context -> {
73+
DaprClientProperties properties = context.getBean(DaprClientProperties.class);
74+
SoftAssertions.assertSoftly(softAssertions -> {
75+
softAssertions.assertThat(properties.getGrpcEndpoint()).isEqualTo("localhost");
76+
softAssertions.assertThat(properties.getHttpEndpoint()).isEqualTo("http://localhost");
77+
softAssertions.assertThat(properties.getHttpPort()).isEqualTo(3500);
78+
softAssertions.assertThat(properties.getGrpcPort()).isEqualTo(50001);
79+
});
80+
81+
});
82+
83+
}
84+
85+
@EnableConfigurationProperties(DaprClientProperties.class)
86+
static class EnableDaprClientProperties {
87+
88+
}
89+
}

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)