Skip to content

Commit 99dfc2a

Browse files
committed
Add smoke tests
1 parent 8a1c201 commit 99dfc2a

File tree

8 files changed

+86
-8
lines changed

8 files changed

+86
-8
lines changed

smoke-tests/apps/JavaUtilLogging/src/main/java/com/microsoft/applicationinsights/smoketestapp/JavaUtilLoggingWithExceptionServlet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public class JavaUtilLoggingWithExceptionServlet extends HttpServlet {
1616
private static final Logger logger = Logger.getLogger("smoketestapp");
1717

1818
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
19-
logger.log(Level.SEVERE, "This is an exception!", new Exception("Fake Exception"));
19+
String testNullMessage = request.getParameter("test-null-message");
20+
if ("true".equalsIgnoreCase(testNullMessage)) {
21+
logger.log(Level.SEVERE, "This is an exception with null message!", new Exception());
22+
} else {
23+
logger.log(Level.SEVERE, "This is an exception!", new Exception("Fake Exception"));
24+
}
2025
}
2126
}

smoke-tests/apps/JavaUtilLogging/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JavaUtilLoggingTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ void test() throws Exception {
7878
@Test
7979
@TargetUri("/testWithException")
8080
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 {
8191
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
8292

8393
Envelope rdEnvelope = rdList.get(0);
@@ -97,7 +107,11 @@ void testWithException() throws Exception {
97107
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
98108

99109
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+
}
101115
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
102116
assertThat(ed.getProperties()).containsEntry("Logger Message", "This is an exception!");
103117
assertThat(ed.getProperties()).containsEntry("SourceType", "Logger");

smoke-tests/apps/Log4j1/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j1WithExceptionServlet.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package com.microsoft.applicationinsights.smoketestapp;
55

66
import java.lang.reflect.Field;
7+
import java.util.logging.Level;
8+
79
import javax.servlet.annotation.WebServlet;
810
import javax.servlet.http.HttpServlet;
911
import javax.servlet.http.HttpServletRequest;
@@ -35,7 +37,12 @@ public class Log4j1WithExceptionServlet extends HttpServlet {
3537
@Override
3638
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
3739
MDC.put("MDC key", "MDC value");
38-
logger.error("This is an exception!", new Exception("Fake Exception"));
40+
String testNullMessage = request.getParameter("test-null-message");
41+
if ("true".equalsIgnoreCase(testNullMessage)) {
42+
logger.error("This is an exception with null message!", new Exception());
43+
} else {
44+
logger.error("This is an exception!", new Exception("Fake Exception"));
45+
}
3946
MDC.remove("MDC key");
4047
}
4148
}

smoke-tests/apps/Log4j1/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j1Test.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ private void logDisableMessage() {
9999
@Test
100100
@TargetUri("/testWithException")
101101
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 {
102112
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
103113

104114
Envelope rdEnvelope = rdList.get(0);
@@ -119,7 +129,11 @@ void testWithException() throws Exception {
119129
ExceptionDetails ex = details.get(0);
120130

121131
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+
}
123137
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
124138
assertThat(ed.getProperties()).containsEntry("Logger Message", "This is an exception!");
125139
assertThat(ed.getProperties()).containsEntry("SourceType", "Logger");

smoke-tests/apps/Log4j2/src/main/java/com/microsoft/applicationinsights/smoketestapp/Log4j2WithExceptionServlet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public class Log4j2WithExceptionServlet extends HttpServlet {
1818

1919
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
2020
ThreadContext.put("MDC key", "MDC value");
21-
logger.error("This is an exception!", new Exception("Fake Exception"));
21+
String testNullMessage = request.getParameter("test-null-message");
22+
if ("true".equalsIgnoreCase(testNullMessage)) {
23+
logger.error("This is an exception with null message!", new Exception());
24+
} else {
25+
logger.error("This is an exception!", new Exception("Fake Exception"));
26+
}
2227
ThreadContext.remove("MDC key");
2328
}
2429
}

smoke-tests/apps/Log4j2/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/Log4j2Test.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ void test() throws Exception {
110110
@Test
111111
@TargetUri("/testWithException")
112112
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 {
113123
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
114124

115125
Envelope rdEnvelope = rdList.get(0);
@@ -130,7 +140,11 @@ void testWithException() throws Exception {
130140
ExceptionDetails ex = details.get(0);
131141

132142
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+
}
134148
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
135149
assertThat(ed.getProperties()).containsEntry("Logger Message", "This is an exception!");
136150
assertThat(ed.getProperties()).containsEntry("SourceType", "Logger");

smoke-tests/apps/Logback/src/main/java/com/microsoft/applicationinsights/smoketestapp/LogbackWithExceptionServlet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public class LogbackWithExceptionServlet extends HttpServlet {
1818

1919
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
2020
MDC.put("MDC key", "MDC value");
21-
logger.error("This is an exception!", new Exception("Fake Exception"));
21+
String testNullMessage = request.getParameter("test-null-message");
22+
if ("true".equalsIgnoreCase(testNullMessage)) {
23+
logger.error("This is an exception with null message!", new Exception());
24+
} else {
25+
logger.error("This is an exception!", new Exception("Fake Exception"));
26+
}
2227
MDC.remove("MDC key");
2328
}
2429
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,16 @@ void test() throws Exception {
115115
@Test
116116
@TargetUri("/testWithException")
117117
void testWithException() throws Exception {
118+
testWithException(false);
119+
}
120+
121+
@Test
122+
@TargetUri("/testWithException?test-null-message=true")
123+
void testWithExceptionWithNullMessage() throws Exception {
124+
testWithException(true);
125+
}
126+
127+
private void testWithException(boolean testNullMessage) throws Exception {
118128
List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
119129

120130
Envelope rdEnvelope = rdList.get(0);
@@ -132,7 +142,11 @@ void testWithException() throws Exception {
132142
ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData();
133143

134144
assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("java.lang.Exception");
135-
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Fake Exception");
145+
if (testNullMessage) {
146+
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("java.lang.Exception");
147+
} else {
148+
assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Fake Exception");
149+
}
136150
assertThat(ed.getSeverityLevel()).isEqualTo(SeverityLevel.ERROR);
137151
assertThat(ed.getProperties())
138152
.containsEntry("Logger Message", "This is an exception!")

0 commit comments

Comments
 (0)