Skip to content

Commit 13ebe81

Browse files
Copilottrask
andcommitted
Create assertion framework extensions and update Logback smoke tests
Co-authored-by: trask <[email protected]>
1 parent c3ca6f7 commit 13ebe81

File tree

6 files changed

+405
-178
lines changed

6 files changed

+405
-178
lines changed

smoke-tests/apps/Logback/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LogbackDisabledTest.java

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
package com.microsoft.applicationinsights.smoketest;
55

66
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
7-
import static org.assertj.core.api.Assertions.assertThat;
87

9-
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
10-
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
11-
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData;
12-
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
13-
import java.util.List;
148
import org.junit.jupiter.api.Test;
159
import org.junit.jupiter.api.extension.RegisterExtension;
1610

@@ -23,39 +17,41 @@ class LogbackDisabledTest {
2317
@Test
2418
@TargetUri("/test")
2519
void testDisabled() throws Exception {
26-
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
27-
28-
Envelope rdEnvelope = rdList.get(0);
29-
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
30-
assertThat(rd.getName()).isEqualTo("GET /Logback/test");
31-
32-
assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
20+
testing.waitAndAssertTrace(
21+
trace ->
22+
trace
23+
.hasRequestSatisying(
24+
request ->
25+
request
26+
.hasName("GET /Logback/test")
27+
.hasSuccess(true)
28+
.hasNoParent()
29+
.hasTag("ai.operation.name", "GET /Logback/test"))
30+
.hasMessageCount(0));
3331
}
3432

3533
@Test
3634
@TargetUri("/testWithSpanException")
3735
void testWithSpanException() throws Exception {
38-
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
39-
40-
Envelope rdEnvelope = rdList.get(0);
41-
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
42-
assertThat(rd.getName()).isEqualTo("GET /Logback/testWithSpanException");
43-
44-
assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
45-
46-
// check that span exception is still captured
47-
String operationId = rdEnvelope.getTags().get("ai.operation.id");
48-
List<Envelope> edList =
49-
testing.mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId);
50-
51-
Envelope edEnvelope = edList.get(0);
52-
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
53-
54-
assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("java.lang.RuntimeException");
55-
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Test Exception");
56-
assertThat(ed.getProperties()).isEmpty(); // this is not a logger-based exception
57-
58-
SmokeTestExtension.assertParentChild(
59-
rd, rdEnvelope, edEnvelope, "GET /Logback/testWithSpanException");
36+
testing.waitAndAssertTrace(
37+
trace ->
38+
trace
39+
.hasRequestSatisying(
40+
request ->
41+
request
42+
.hasName("GET /Logback/testWithSpanException")
43+
.hasSuccess(true)
44+
.hasNoParent()
45+
.hasTag("ai.operation.name", "GET /Logback/testWithSpanException"))
46+
.hasMessageCount(0)
47+
.hasExceptionCount(1)
48+
.hasExceptionSatisying(
49+
exception ->
50+
exception
51+
.hasExceptionTypeName("java.lang.RuntimeException")
52+
.hasExceptionMessage("Test Exception")
53+
.hasPropertyCount(0) // this is not a logger-based exception
54+
.hasParent(trace.getRequestId(0))
55+
.hasTag("ai.operation.name", "GET /Logback/testWithSpanException")));
6056
}
6157
}

smoke-tests/apps/Logback/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LogbackLevelOffTest.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
package com.microsoft.applicationinsights.smoketest;
55

66
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
7-
import static org.assertj.core.api.Assertions.assertThat;
87

9-
import com.microsoft.applicationinsights.smoketest.schemav2.Data;
10-
import com.microsoft.applicationinsights.smoketest.schemav2.Envelope;
11-
import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData;
12-
import com.microsoft.applicationinsights.smoketest.schemav2.RequestData;
13-
import java.util.List;
8+
import com.microsoft.applicationinsights.smoketest.schemav2.SeverityLevel;
149
import org.junit.jupiter.api.Test;
1510
import org.junit.jupiter.api.extension.RegisterExtension;
1611

@@ -23,39 +18,41 @@ class LogbackLevelOffTest {
2318
@Test
2419
@TargetUri("/test")
2520
void testDisabled() throws Exception {
26-
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
27-
28-
Envelope rdEnvelope = rdList.get(0);
29-
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
30-
assertThat(rd.getName()).isEqualTo("GET /Logback/test");
31-
32-
assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
21+
testing.waitAndAssertTrace(
22+
trace ->
23+
trace
24+
.hasRequestSatisying(
25+
request ->
26+
request
27+
.hasName("GET /Logback/test")
28+
.hasSuccess(true)
29+
.hasNoParent()
30+
.hasTag("ai.operation.name", "GET /Logback/test"))
31+
.hasMessageCount(0));
3332
}
3433

3534
@Test
3635
@TargetUri("/testWithSpanException")
3736
void testWithSpanException() throws Exception {
38-
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
39-
40-
Envelope rdEnvelope = rdList.get(0);
41-
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
42-
assertThat(rd.getName()).isEqualTo("GET /Logback/testWithSpanException");
43-
44-
assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero();
45-
46-
// check that span exception is still captured
47-
String operationId = rdEnvelope.getTags().get("ai.operation.id");
48-
List<Envelope> edList =
49-
testing.mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId);
50-
51-
Envelope edEnvelope = edList.get(0);
52-
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
53-
54-
assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("java.lang.RuntimeException");
55-
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Test Exception");
56-
assertThat(ed.getProperties()).isEmpty(); // this is not a logger-based exception
57-
58-
SmokeTestExtension.assertParentChild(
59-
rd, rdEnvelope, edEnvelope, "GET /Logback/testWithSpanException");
37+
testing.waitAndAssertTrace(
38+
trace ->
39+
trace
40+
.hasRequestSatisying(
41+
request ->
42+
request
43+
.hasName("GET /Logback/testWithSpanException")
44+
.hasSuccess(true)
45+
.hasNoParent()
46+
.hasTag("ai.operation.name", "GET /Logback/testWithSpanException"))
47+
.hasMessageCount(0)
48+
.hasExceptionCount(1)
49+
.hasExceptionSatisying(
50+
exception ->
51+
exception
52+
.hasExceptionTypeName("java.lang.RuntimeException")
53+
.hasExceptionMessage("Test Exception")
54+
.hasPropertyCount(0) // this is not a logger-based exception
55+
.hasParent(trace.getRequestId(0))
56+
.hasTag("ai.operation.name", "GET /Logback/testWithSpanException")));
6057
}
6158
}

0 commit comments

Comments
 (0)