15
15
import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .TOMCAT_8_JAVA_8_OPENJ9 ;
16
16
import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .WILDFLY_13_JAVA_8 ;
17
17
import static com .microsoft .applicationinsights .smoketest .EnvironmentValue .WILDFLY_13_JAVA_8_OPENJ9 ;
18
- import static org .assertj .core .api .Assertions .assertThat ;
19
18
20
- import com .microsoft .applicationinsights .smoketest .schemav2 .Data ;
21
- import com .microsoft .applicationinsights .smoketest .schemav2 .Envelope ;
22
- import com .microsoft .applicationinsights .smoketest .schemav2 .ExceptionData ;
23
- import com .microsoft .applicationinsights .smoketest .schemav2 .MessageData ;
24
- import com .microsoft .applicationinsights .smoketest .schemav2 .RequestData ;
25
19
import com .microsoft .applicationinsights .smoketest .schemav2 .SeverityLevel ;
26
- import java .util .Comparator ;
27
- import java .util .List ;
28
20
import org .junit .jupiter .api .Test ;
29
21
import org .junit .jupiter .api .extension .RegisterExtension ;
30
22
@@ -42,120 +34,116 @@ boolean isWildflyServer() {
42
34
43
35
@ Test
44
36
@ TargetUri ("/test" )
45
- void test () throws Exception {
46
- List <Envelope > rdList = testing .mockedIngestion .waitForItems ("RequestData" , 1 );
47
-
48
- Envelope rdEnvelope = rdList .get (0 );
49
- String operationId = rdEnvelope .getTags ().get ("ai.operation.id" );
50
- List <Envelope > mdList = testing .mockedIngestion .waitForMessageItemsInRequest (3 , operationId );
51
-
52
- Envelope mdEnvelope1 = mdList .get (0 );
53
- Envelope mdEnvelope2 = mdList .get (1 );
54
-
55
- assertThat (rdEnvelope .getSampleRate ()).isNull ();
56
- assertThat (mdEnvelope1 .getSampleRate ()).isNull ();
57
- assertThat (mdEnvelope2 .getSampleRate ()).isNull ();
58
-
59
- RequestData rd = (RequestData ) ((Data <?>) rdEnvelope .getData ()).getBaseData ();
60
-
61
- List <MessageData > logs = testing .mockedIngestion .getMessageDataInRequest (3 );
62
- logs .sort (Comparator .comparing (MessageData ::getSeverityLevel ));
63
-
64
- MessageData md1 = logs .get (0 );
65
- MessageData md2 = logs .get (1 );
66
- MessageData md3 = logs .get (2 );
67
-
68
- assertThat (md1 .getMessage ()).isEqualTo ("This is logback warn." );
69
- assertThat (md1 .getSeverityLevel ()).isEqualTo (SeverityLevel .WARNING );
70
- assertThat (md1 .getProperties ())
71
- .containsEntry ("SourceType" , "Logger" )
72
- .containsEntry ("LoggerName" , "smoketestapp" )
73
- .containsKey ("ThreadName" )
74
- .containsEntry ("MDC key" , "MDC value" );
75
-
76
- if (!isWildflyServer ()) {
77
- assertThat (md1 .getProperties ())
78
- .containsEntry ("FileName" , "LogbackServlet.java" )
79
- .containsEntry (
80
- "ClassName" , "com.microsoft.applicationinsights.smoketestapp.LogbackServlet" )
81
- .containsEntry ("MethodName" , "doGet" )
82
- .containsEntry ("LineNumber" , "26" )
83
- .hasSize (8 );
84
- } else {
85
- assertThat (md1 .getProperties ()).hasSize (4 );
86
- }
87
-
88
- assertThat (md2 .getMessage ()).isEqualTo ("This is logback error." );
89
- assertThat (md2 .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
90
- assertThat (md2 .getProperties ())
91
- .containsEntry ("SourceType" , "Logger" )
92
- .containsEntry ("LoggerName" , "smoketestapp" )
93
- .containsKey ("ThreadName" );
37
+ void test () {
38
+ testing .waitAndAssertTrace (
39
+ trace ->
40
+ trace
41
+ .hasRequestSatisying (
42
+ request ->
43
+ request .hasName ("GET /Logback/test" ).hasSuccess (true ).hasNoSampleRate ())
44
+ .hasMessageCount (3 )
45
+ .hasMessageSatisfying (
46
+ message ->
47
+ message
48
+ .hasMessage ("This is logback warn." )
49
+ .hasSeverityLevel (SeverityLevel .WARNING )
50
+ .hasProperty ("SourceType" , "Logger" )
51
+ .hasProperty ("LoggerName" , "smoketestapp" )
52
+ .hasPropertyKey ("ThreadName" )
53
+ .hasProperty ("MDC key" , "MDC value" )
54
+ .hasNoSampleRate ())
55
+ .hasMessageSatisfying (
56
+ message ->
57
+ message
58
+ .hasMessage ("This is logback error." )
59
+ .hasSeverityLevel (SeverityLevel .ERROR )
60
+ .hasProperty ("SourceType" , "Logger" )
61
+ .hasProperty ("LoggerName" , "smoketestapp" )
62
+ .hasPropertyKey ("ThreadName" )
63
+ .hasNoSampleRate ()));
94
64
95
65
if (!isWildflyServer ()) {
96
- assertThat (md2 .getProperties ())
97
- .containsEntry ("FileName" , "LogbackServlet.java" )
98
- .containsEntry (
99
- "ClassName" , "com.microsoft.applicationinsights.smoketestapp.LogbackServlet" )
100
- .containsEntry ("MethodName" , "doGet" )
101
- .containsEntry ("LineNumber" , "28" )
102
- .hasSize (7 );
66
+ testing .waitAndAssertTrace (
67
+ trace ->
68
+ trace
69
+ .hasMessageSatisfying (
70
+ message ->
71
+ message
72
+ .hasMessage ("This is logback warn." )
73
+ .hasProperty ("FileName" , "LogbackServlet.java" )
74
+ .hasProperty (
75
+ "ClassName" ,
76
+ "com.microsoft.applicationinsights.smoketestapp.LogbackServlet" )
77
+ .hasProperty ("MethodName" , "doGet" )
78
+ .hasProperty ("LineNumber" , "26" )
79
+ .hasPropertiesSize (8 ))
80
+ .hasMessageSatisfying (
81
+ message ->
82
+ message
83
+ .hasMessage ("This is logback error." )
84
+ .hasProperty ("FileName" , "LogbackServlet.java" )
85
+ .hasProperty (
86
+ "ClassName" ,
87
+ "com.microsoft.applicationinsights.smoketestapp.LogbackServlet" )
88
+ .hasProperty ("MethodName" , "doGet" )
89
+ .hasProperty ("LineNumber" , "28" )
90
+ .hasPropertiesSize (7 ))
91
+ .hasMessageSatisfying (message -> message .hasProperty ("Marker" , "aMarker" )));
103
92
} else {
104
- assertThat (md2 .getProperties ()).hasSize (3 );
105
- }
106
-
107
- if (!isWildflyServer ()) {
108
- assertThat (md3 .getProperties ()).containsEntry ("Marker" , "aMarker" );
93
+ testing .waitAndAssertTrace (
94
+ trace ->
95
+ trace
96
+ .hasMessageSatisfying (
97
+ message -> message .hasMessage ("This is logback warn." ).hasPropertiesSize (4 ))
98
+ .hasMessageSatisfying (
99
+ message ->
100
+ message .hasMessage ("This is logback error." ).hasPropertiesSize (3 )));
109
101
}
110
-
111
- SmokeTestExtension .assertParentChild (rd , rdEnvelope , mdEnvelope1 , "GET /Logback/test" );
112
- SmokeTestExtension .assertParentChild (rd , rdEnvelope , mdEnvelope2 , "GET /Logback/test" );
113
102
}
114
103
115
104
@ Test
116
105
@ TargetUri ("/testWithException" )
117
- void testWithException () throws Exception {
118
- List <Envelope > rdList = testing .mockedIngestion .waitForItems ("RequestData" , 1 );
119
-
120
- Envelope rdEnvelope = rdList .get (0 );
121
- String operationId = rdEnvelope .getTags ().get ("ai.operation.id" );
122
- List <Envelope > edList =
123
- testing .mockedIngestion .waitForItemsInOperation ("ExceptionData" , 1 , operationId );
124
- assertThat (testing .mockedIngestion .getCountForType ("EventData" )).isZero ();
125
-
126
- Envelope edEnvelope = edList .get (0 );
127
-
128
- assertThat (rdEnvelope .getSampleRate ()).isNull ();
129
- assertThat (edEnvelope .getSampleRate ()).isNull ();
130
-
131
- RequestData rd = (RequestData ) ((Data <?>) rdEnvelope .getData ()).getBaseData ();
132
- ExceptionData ed = (ExceptionData ) ((Data <?>) edEnvelope .getData ()).getBaseData ();
133
-
134
- assertThat (ed .getExceptions ().get (0 ).getTypeName ()).isEqualTo ("java.lang.Exception" );
135
- assertThat (ed .getExceptions ().get (0 ).getMessage ()).isEqualTo ("Fake Exception" );
136
- assertThat (ed .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
137
- assertThat (ed .getProperties ())
138
- .containsEntry ("Logger Message" , "This is an exception!" )
139
- .containsEntry ("SourceType" , "Logger" )
140
- .containsEntry ("LoggerName" , "smoketestapp" )
141
- .containsKey ("ThreadName" )
142
- .containsEntry ("MDC key" , "MDC value" );
106
+ void testWithException () {
107
+ testing .waitAndAssertTrace (
108
+ trace ->
109
+ trace
110
+ .hasRequestSatisying (
111
+ request ->
112
+ request
113
+ .hasName ("GET /Logback/testWithException" )
114
+ .hasSuccess (true )
115
+ .hasNoSampleRate ())
116
+ .hasExceptionCount (1 )
117
+ .hasExceptionSatisfying (
118
+ exception ->
119
+ exception
120
+ .hasExceptionType ("java.lang.Exception" )
121
+ .hasExceptionMessage ("Fake Exception" )
122
+ .hasSeverityLevel (SeverityLevel .ERROR )
123
+ .hasProperty ("Logger Message" , "This is an exception!" )
124
+ .hasProperty ("SourceType" , "Logger" )
125
+ .hasProperty ("LoggerName" , "smoketestapp" )
126
+ .hasPropertyKey ("ThreadName" )
127
+ .hasProperty ("MDC key" , "MDC value" )
128
+ .hasNoSampleRate ()));
143
129
144
130
if (!isWildflyServer ()) {
145
- assertThat (ed .getProperties ())
146
- .containsEntry ("FileName" , "LogbackWithExceptionServlet.java" )
147
- .containsEntry (
148
- "ClassName" ,
149
- "com.microsoft.applicationinsights.smoketestapp.LogbackWithExceptionServlet" )
150
- .containsEntry ("MethodName" , "doGet" )
151
- .containsEntry ("LineNumber" , "21" )
152
- .hasSize (9 );
131
+ testing .waitAndAssertTrace (
132
+ trace ->
133
+ trace .hasExceptionSatisfying (
134
+ exception ->
135
+ exception
136
+ .hasProperty ("FileName" , "LogbackWithExceptionServlet.java" )
137
+ .hasProperty (
138
+ "ClassName" ,
139
+ "com.microsoft.applicationinsights.smoketestapp.LogbackWithExceptionServlet" )
140
+ .hasProperty ("MethodName" , "doGet" )
141
+ .hasProperty ("LineNumber" , "21" )
142
+ .hasPropertiesSize (9 )));
153
143
} else {
154
- assertThat (ed .getProperties ()).hasSize (5 );
144
+ testing .waitAndAssertTrace (
145
+ trace -> trace .hasExceptionSatisfying (exception -> exception .hasPropertiesSize (5 )));
155
146
}
156
-
157
- SmokeTestExtension .assertParentChild (
158
- rd , rdEnvelope , edEnvelope , "GET /Logback/testWithException" );
159
147
}
160
148
161
149
@ Environment (TOMCAT_8_JAVA_8 )
0 commit comments