Skip to content

Commit 04745f3

Browse files
committed
Add test for DaprClientProperties
Signed-off-by: Matheus Cruz <[email protected]>
1 parent c6bd48d commit 04745f3

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
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+
}

0 commit comments

Comments
 (0)