File tree Expand file tree Collapse file tree 8 files changed +74
-8
lines changed
main/java/com/microsoft/applicationinsights/smoketestapp
smokeTest/java/com/microsoft/applicationinsights/smoketest
main/java/com/microsoft/applicationinsights/smoketestapp
smokeTest/java/com/microsoft/applicationinsights/smoketest
main/java/com/microsoft/applicationinsights/smoketestapp
smokeTest/java/com/microsoft/applicationinsights/smoketest
main/java/com/microsoft/applicationinsights/smoketestapp
smokeTest/java/com/microsoft/applicationinsights/smoketest Expand file tree Collapse file tree 8 files changed +74
-8
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ public class JavaUtilLoggingWithExceptionServlet extends HttpServlet {
16
16
private static final Logger logger = Logger .getLogger ("smoketestapp" );
17
17
18
18
protected void doGet (HttpServletRequest request , HttpServletResponse response ) {
19
- logger .log (Level .SEVERE , "This is an exception!" , new Exception ("Fake Exception" ));
19
+ Exception e = testNullMessage (request ) ? new Exception () : new Exception ("Fake Exception" );
20
+ logger .log (Level .SEVERE , "This is an exception!" , e );
21
+ }
22
+
23
+ private static boolean testNullMessage (HttpServletRequest request ) {
24
+ String testNullMessage = request .getParameter ("test-null-message" );
25
+ return "true" .equalsIgnoreCase (testNullMessage );
20
26
}
21
27
}
Original file line number Diff line number Diff line change @@ -78,6 +78,16 @@ void test() throws Exception {
78
78
@ Test
79
79
@ TargetUri ("/testWithException" )
80
80
void testWithException () throws Exception {
81
+ testWithException (false );
82
+ }
83
+
84
+ @ Test
85
+ @ TargetUri ("/testWithException?test-null-message=true" )
86
+ void testWithExceptionWithNullMessage () throws Exception {
87
+ testWithException (true );
88
+ }
89
+
90
+ private void testWithException (boolean testNullMessage ) throws Exception {
81
91
List <Envelope > rdList = testing .mockedIngestion .waitForItems ("RequestData" , 1 );
82
92
83
93
Envelope rdEnvelope = rdList .get (0 );
@@ -97,7 +107,11 @@ void testWithException() throws Exception {
97
107
ExceptionData ed = (ExceptionData ) ((Data <?>) edEnvelope .getData ()).getBaseData ();
98
108
99
109
assertThat (ed .getExceptions ().get (0 ).getTypeName ()).isEqualTo ("java.lang.Exception" );
100
- assertThat (ed .getExceptions ().get (0 ).getMessage ()).isEqualTo ("Fake Exception" );
110
+ if (testNullMessage ) {
111
+ assertThat (ed .getExceptions ().get (0 ).getMessage ()).isEqualTo ("java.lang.Exception" );
112
+ } else {
113
+ assertThat (ed .getExceptions ().get (0 ).getMessage ()).isEqualTo ("Fake Exception" );
114
+ }
101
115
assertThat (ed .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
102
116
assertThat (ed .getProperties ()).containsEntry ("Logger Message" , "This is an exception!" );
103
117
assertThat (ed .getProperties ()).containsEntry ("SourceType" , "Logger" );
Original file line number Diff line number Diff line change @@ -35,7 +35,13 @@ public class Log4j1WithExceptionServlet extends HttpServlet {
35
35
@ Override
36
36
protected void doGet (HttpServletRequest request , HttpServletResponse response ) {
37
37
MDC .put ("MDC key" , "MDC value" );
38
- logger .error ("This is an exception!" , new Exception ("Fake Exception" ));
38
+ Exception e = testNullMessage (request ) ? new Exception () : new Exception ("Fake Exception" );
39
+ logger .error ("This is an exception!" , e );
39
40
MDC .remove ("MDC key" );
40
41
}
42
+
43
+ private static boolean testNullMessage (HttpServletRequest request ) {
44
+ String testNullMessage = request .getParameter ("test-null-message" );
45
+ return "true" .equalsIgnoreCase (testNullMessage );
46
+ }
41
47
}
Original file line number Diff line number Diff line change @@ -99,6 +99,16 @@ private void logDisableMessage() {
99
99
@ Test
100
100
@ TargetUri ("/testWithException" )
101
101
void testWithException () throws Exception {
102
+ testWithException (false );
103
+ }
104
+
105
+ @ Test
106
+ @ TargetUri ("/testWithException?test-null-message=true" )
107
+ void testWithExceptionWithNullMessage () throws Exception {
108
+ testWithException (true );
109
+ }
110
+
111
+ private void testWithException (boolean testNullMessage ) throws Exception {
102
112
List <Envelope > rdList = testing .mockedIngestion .waitForItems ("RequestData" , 1 );
103
113
104
114
Envelope rdEnvelope = rdList .get (0 );
@@ -119,7 +129,11 @@ void testWithException() throws Exception {
119
129
ExceptionDetails ex = details .get (0 );
120
130
121
131
assertThat (ex .getTypeName ()).isEqualTo ("java.lang.Exception" );
122
- assertThat (ex .getMessage ()).isEqualTo ("Fake Exception" );
132
+ if (testNullMessage ) {
133
+ assertThat (ex .getMessage ()).isEqualTo ("java.lang.Exception" );
134
+ } else {
135
+ assertThat (ex .getMessage ()).isEqualTo ("Fake Exception" );
136
+ }
123
137
assertThat (ed .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
124
138
assertThat (ed .getProperties ()).containsEntry ("Logger Message" , "This is an exception!" );
125
139
assertThat (ed .getProperties ()).containsEntry ("SourceType" , "Logger" );
Original file line number Diff line number Diff line change @@ -18,7 +18,13 @@ public class Log4j2WithExceptionServlet extends HttpServlet {
18
18
19
19
protected void doGet (HttpServletRequest request , HttpServletResponse response ) {
20
20
ThreadContext .put ("MDC key" , "MDC value" );
21
- logger .error ("This is an exception!" , new Exception ("Fake Exception" ));
21
+ Exception e = testNullMessage (request ) ? new Exception () : new Exception ("Fake Exception" );
22
+ logger .error ("This is an exception!" , e );
22
23
ThreadContext .remove ("MDC key" );
23
24
}
25
+
26
+ private static boolean testNullMessage (HttpServletRequest request ) {
27
+ String testNullMessage = request .getParameter ("test-null-message" );
28
+ return "true" .equalsIgnoreCase (testNullMessage );
29
+ }
24
30
}
Original file line number Diff line number Diff line change @@ -110,6 +110,16 @@ void test() throws Exception {
110
110
@ Test
111
111
@ TargetUri ("/testWithException" )
112
112
void testWithException () throws Exception {
113
+ testWithException (false );
114
+ }
115
+
116
+ @ Test
117
+ @ TargetUri ("/testWithException?test-null-message=true" )
118
+ void testWithExceptionWithNullMessage () throws Exception {
119
+ testWithException (true );
120
+ }
121
+
122
+ private void testWithException (boolean testNullMessage ) throws Exception {
113
123
List <Envelope > rdList = testing .mockedIngestion .waitForItems ("RequestData" , 1 );
114
124
115
125
Envelope rdEnvelope = rdList .get (0 );
@@ -130,7 +140,11 @@ void testWithException() throws Exception {
130
140
ExceptionDetails ex = details .get (0 );
131
141
132
142
assertThat (ex .getTypeName ()).isEqualTo ("java.lang.Exception" );
133
- assertThat (ex .getMessage ()).isEqualTo ("Fake Exception" );
143
+ if (testNullMessage ) {
144
+ assertThat (ex .getMessage ()).isEqualTo ("java.lang.Exception" );
145
+ } else {
146
+ assertThat (ex .getMessage ()).isEqualTo ("Fake Exception" );
147
+ }
134
148
assertThat (ed .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
135
149
assertThat (ed .getProperties ()).containsEntry ("Logger Message" , "This is an exception!" );
136
150
assertThat (ed .getProperties ()).containsEntry ("SourceType" , "Logger" );
Original file line number Diff line number Diff line change @@ -18,7 +18,13 @@ public class LogbackWithExceptionServlet extends HttpServlet {
18
18
19
19
protected void doGet (HttpServletRequest request , HttpServletResponse response ) {
20
20
MDC .put ("MDC key" , "MDC value" );
21
- logger .error ("This is an exception!" , new Exception ("Fake Exception" ));
21
+ Exception e = testNullMessage (request ) ? new Exception () : new Exception ("Fake Exception" );
22
+ logger .error ("This is an exception!" , e );
22
23
MDC .remove ("MDC key" );
23
24
}
25
+
26
+ private static boolean testNullMessage (HttpServletRequest request ) {
27
+ String testNullMessage = request .getParameter ("test-null-message" );
28
+ return "true" .equalsIgnoreCase (testNullMessage );
29
+ }
24
30
}
Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ void testWithException() {
138
138
"ClassName" ,
139
139
"com.microsoft.applicationinsights.smoketestapp.LogbackWithExceptionServlet" )
140
140
.hasProperty ("MethodName" , "doGet" )
141
- .hasProperty ("LineNumber" , "21 " )
141
+ .hasProperty ("LineNumber" , "22 " )
142
142
.hasPropertiesSize (9 )));
143
143
} else {
144
144
testing .waitAndAssertTrace (
You can’t perform that action at this time.
0 commit comments