Skip to content

Commit e49a70f

Browse files
Copilottrask
andcommitted
Update HttpClients smoke test to use new assertion framework
Co-authored-by: trask <[email protected]>
1 parent e3ac7a7 commit e49a70f

File tree

3 files changed

+65
-50
lines changed

3 files changed

+65
-50
lines changed

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

Lines changed: 42 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,48 @@ 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+
.hasDependencySatisying(
91+
dependency ->
92+
dependency
93+
.hasName("GET /mock/200")
94+
.hasData(successUrlWithQueryString)
95+
.hasType("Http")
96+
.hasTarget("host.testcontainers.internal:6060")
97+
.hasResultCode("200")
98+
.hasSuccess(true)
99+
.hasProperty("_MS.ProcessedByMetricExtractors", "True")
100+
.hasParent(trace.getRequestId(0)))
101+
.hasDependencySatisying(
102+
dependency ->
103+
dependency
104+
.hasName("GET /mock/404")
105+
.hasData("http://host.testcontainers.internal:6060/mock/404")
106+
.hasType("Http")
107+
.hasTarget("host.testcontainers.internal:6060")
108+
.hasResultCode("404")
109+
.hasSuccess(false)
110+
.hasProperty("_MS.ProcessedByMetricExtractors", "True")
111+
.hasParent(trace.getRequestId(0)))
112+
.hasDependencySatisying(
113+
dependency ->
114+
dependency
115+
.hasName("GET /mock/500")
116+
.hasData("http://host.testcontainers.internal:6060/mock/500")
117+
.hasType("Http")
118+
.hasTarget("host.testcontainers.internal:6060")
119+
.hasResultCode("500")
120+
.hasSuccess(false)
121+
.hasProperty("_MS.ProcessedByMetricExtractors", "True")
122+
.hasParent(trace.getRequestId(0))));
129123
}
130124

131125
@Environment(TOMCAT_8_JAVA_8)

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,28 @@ public DependencyAssert hasNoParent() {
6262
@CanIgnoreReturnValue
6363
public DependencyAssert hasParent(String parentId) {
6464
isNotNull();
65-
assertThat(getDependencyData().getProperties().get("ai.operation.parentId")).isNull();
65+
assertThat(getDependencyData().getProperties().get("ai.operation.parentId")).isEqualTo(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);
6687
return this;
6788
}
6889

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public RequestAssert hasNoParent() {
5454
@CanIgnoreReturnValue
5555
public RequestAssert hasParent(String parentId) {
5656
isNotNull();
57-
assertThat(getRequestData().getProperties().get("ai.operation.parentId")).isNull();
57+
assertThat(getRequestData().getProperties().get("ai.operation.parentId")).isEqualTo(parentId);
5858
return this;
5959
}
6060

0 commit comments

Comments
 (0)