Skip to content

Commit e64e6d3

Browse files
Copilottrask
andauthored
Update HttpClients smoke test to use new assertion framework (#4269)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: trask <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]>
1 parent d79cff0 commit e64e6d3

File tree

3 files changed

+104
-52
lines changed

3 files changed

+104
-52
lines changed

smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientTest.java

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9;
1616
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
1717
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
18-
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.assertj.core.data.MapEntry.entry;
2018

2119
import org.junit.jupiter.api.Test;
2220
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -80,52 +78,57 @@ private static void verify() throws Exception {
8078
}
8179

8280
private static void verify(String successUrlWithQueryString) throws Exception {
83-
Telemetry telemetry = testing.getTelemetry(3);
84-
85-
assertThat(telemetry.rd.getProperties())
86-
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
87-
assertThat(telemetry.rd.getSuccess()).isTrue();
88-
// TODO (trask) add this check in all smoke tests?
89-
assertThat(telemetry.rdEnvelope.getSampleRate()).isNull();
90-
91-
assertThat(telemetry.rdd1.getName()).isEqualTo("GET /mock/200");
92-
assertThat(telemetry.rdd1.getData()).isEqualTo(successUrlWithQueryString);
93-
assertThat(telemetry.rdd1.getType()).isEqualTo("Http");
94-
assertThat(telemetry.rdd1.getTarget()).isEqualTo("host.testcontainers.internal:6060");
95-
assertThat(telemetry.rdd1.getResultCode()).isEqualTo("200");
96-
assertThat(telemetry.rdd1.getProperties())
97-
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
98-
assertThat(telemetry.rdd1.getSuccess()).isTrue();
99-
assertThat(telemetry.rddEnvelope1.getSampleRate()).isNull();
100-
101-
assertThat(telemetry.rdd2.getName()).isEqualTo("GET /mock/404");
102-
assertThat(telemetry.rdd2.getData())
103-
.isEqualTo("http://host.testcontainers.internal:6060/mock/404");
104-
assertThat(telemetry.rdd2.getType()).isEqualTo("Http");
105-
assertThat(telemetry.rdd2.getTarget()).isEqualTo("host.testcontainers.internal:6060");
106-
assertThat(telemetry.rdd2.getResultCode()).isEqualTo("404");
107-
assertThat(telemetry.rdd2.getProperties())
108-
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
109-
assertThat(telemetry.rdd2.getSuccess()).isFalse();
110-
assertThat(telemetry.rddEnvelope2.getSampleRate()).isNull();
111-
112-
assertThat(telemetry.rdd3.getName()).isEqualTo("GET /mock/500");
113-
assertThat(telemetry.rdd3.getData())
114-
.isEqualTo("http://host.testcontainers.internal:6060/mock/500");
115-
assertThat(telemetry.rdd3.getType()).isEqualTo("Http");
116-
assertThat(telemetry.rdd3.getTarget()).isEqualTo("host.testcontainers.internal:6060");
117-
assertThat(telemetry.rdd3.getResultCode()).isEqualTo("500");
118-
assertThat(telemetry.rdd3.getProperties())
119-
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
120-
assertThat(telemetry.rdd3.getSuccess()).isFalse();
121-
assertThat(telemetry.rddEnvelope3.getSampleRate()).isNull();
122-
123-
SmokeTestExtension.assertParentChild(
124-
telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope1, "GET /HttpClients/*");
125-
SmokeTestExtension.assertParentChild(
126-
telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope2, "GET /HttpClients/*");
127-
SmokeTestExtension.assertParentChild(
128-
telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope3, "GET /HttpClients/*");
81+
testing.waitAndAssertTrace(
82+
trace ->
83+
trace
84+
.hasRequestSatisying(
85+
request ->
86+
request
87+
.hasSuccess(true)
88+
.hasProperty("_MS.ProcessedByMetricExtractors", "True")
89+
.hasNoParent()
90+
// TODO (trask) add this check in all smoke tests?
91+
.hasNoSampleRate()
92+
.hasTag("ai.operation.name", "GET /HttpClients/*"))
93+
.hasDependencySatisying(
94+
dependency ->
95+
dependency
96+
.hasName("GET /mock/200")
97+
.hasData(successUrlWithQueryString)
98+
.hasType("Http")
99+
.hasTarget("host.testcontainers.internal:6060")
100+
.hasResultCode("200")
101+
.hasSuccess(true)
102+
.hasProperty("_MS.ProcessedByMetricExtractors", "True")
103+
.hasParent(trace.getRequestId(0))
104+
.hasNoSampleRate()
105+
.hasTag("ai.operation.name", "GET /HttpClients/*"))
106+
.hasDependencySatisying(
107+
dependency ->
108+
dependency
109+
.hasName("GET /mock/404")
110+
.hasData("http://host.testcontainers.internal:6060/mock/404")
111+
.hasType("Http")
112+
.hasTarget("host.testcontainers.internal:6060")
113+
.hasResultCode("404")
114+
.hasSuccess(false)
115+
.hasProperty("_MS.ProcessedByMetricExtractors", "True")
116+
.hasParent(trace.getRequestId(0))
117+
.hasNoSampleRate()
118+
.hasTag("ai.operation.name", "GET /HttpClients/*"))
119+
.hasDependencySatisying(
120+
dependency ->
121+
dependency
122+
.hasName("GET /mock/500")
123+
.hasData("http://host.testcontainers.internal:6060/mock/500")
124+
.hasType("Http")
125+
.hasTarget("host.testcontainers.internal:6060")
126+
.hasResultCode("500")
127+
.hasSuccess(false)
128+
.hasProperty("_MS.ProcessedByMetricExtractors", "True")
129+
.hasParent(trace.getRequestId(0))
130+
.hasNoSampleRate()
131+
.hasTag("ai.operation.name", "GET /HttpClients/*")));
129132
}
130133

131134
@Environment(TOMCAT_8_JAVA_8)

smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/DependencyAssert.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,49 @@ public DependencyAssert hasTag(String key, String value) {
5555
@CanIgnoreReturnValue
5656
public DependencyAssert hasNoParent() {
5757
isNotNull();
58-
assertThat(getDependencyData().getProperties().get("ai.operation.parentId")).isNull();
58+
assertThat(actual.getTags()).doesNotContainKey("ai.operation.parentId");
5959
return this;
6060
}
6161

6262
@CanIgnoreReturnValue
6363
public DependencyAssert hasParent(String parentId) {
6464
isNotNull();
65-
assertThat(getDependencyData().getProperties().get("ai.operation.parentId")).isNull();
65+
assertThat(actual.getTags()).containsEntry("ai.operation.parentId", parentId);
66+
return this;
67+
}
68+
69+
@CanIgnoreReturnValue
70+
public DependencyAssert hasData(String data) {
71+
isNotNull();
72+
assertThat(getDependencyData().getData()).isEqualTo(data);
73+
return this;
74+
}
75+
76+
@CanIgnoreReturnValue
77+
public DependencyAssert hasType(String type) {
78+
isNotNull();
79+
assertThat(getDependencyData().getType()).isEqualTo(type);
80+
return this;
81+
}
82+
83+
@CanIgnoreReturnValue
84+
public DependencyAssert hasResultCode(String resultCode) {
85+
isNotNull();
86+
assertThat(getDependencyData().getResultCode()).isEqualTo(resultCode);
87+
return this;
88+
}
89+
90+
@CanIgnoreReturnValue
91+
public DependencyAssert hasSampleRate(Float expectedSampleRate) {
92+
isNotNull();
93+
assertThat(actual.getSampleRate()).isEqualTo(expectedSampleRate);
94+
return this;
95+
}
96+
97+
@CanIgnoreReturnValue
98+
public DependencyAssert hasNoSampleRate() {
99+
isNotNull();
100+
assertThat(actual.getSampleRate()).isNull();
66101
return this;
67102
}
68103

smoke-tests/framework/src/main/java/com/microsoft/applicationinsights/smoketest/RequestAssert.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,28 @@ public RequestAssert hasTag(String key, String value) {
4747
@CanIgnoreReturnValue
4848
public RequestAssert hasNoParent() {
4949
isNotNull();
50-
assertThat(getRequestData().getProperties().get("ai.operation.parentId")).isNull();
50+
assertThat(actual.getTags()).doesNotContainKey("ai.operation.parentId");
5151
return this;
5252
}
5353

5454
@CanIgnoreReturnValue
5555
public RequestAssert hasParent(String parentId) {
5656
isNotNull();
57-
assertThat(getRequestData().getProperties().get("ai.operation.parentId")).isNull();
57+
assertThat(actual.getTags()).containsEntry("ai.operation.parentId", parentId);
58+
return this;
59+
}
60+
61+
@CanIgnoreReturnValue
62+
public RequestAssert hasSampleRate(Float expectedSampleRate) {
63+
isNotNull();
64+
assertThat(actual.getSampleRate()).isEqualTo(expectedSampleRate);
65+
return this;
66+
}
67+
68+
@CanIgnoreReturnValue
69+
public RequestAssert hasNoSampleRate() {
70+
isNotNull();
71+
assertThat(actual.getSampleRate()).isNull();
5872
return this;
5973
}
6074

0 commit comments

Comments
 (0)