|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package com.microsoft.applicationinsights.smoketest; |
| 5 | + |
| 6 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11; |
| 7 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9; |
| 8 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17; |
| 9 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17_OPENJ9; |
| 10 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_21; |
| 11 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_21_OPENJ9; |
| 12 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_25; |
| 13 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_25_OPENJ9; |
| 14 | + |
| 15 | +import com.microsoft.applicationinsights.smoketest.schemav2.SeverityLevel; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 18 | + |
| 19 | +@UseAgent |
| 20 | +abstract class LogbackFluentLoggingTest { |
| 21 | + |
| 22 | + @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); |
| 23 | + |
| 24 | + @Test |
| 25 | + @TargetUri("/test") |
| 26 | + void test() { |
| 27 | + testing.waitAndAssertTrace( |
| 28 | + trace -> |
| 29 | + trace |
| 30 | + .hasRequestSatisying( |
| 31 | + request -> |
| 32 | + request.hasName("GET /LogbackFluentLogging/test").hasSuccess(true).hasNoSampleRate()) |
| 33 | + .hasMessageCount(2) |
| 34 | + .hasMessageSatisfying( |
| 35 | + message -> |
| 36 | + message |
| 37 | + .hasMessage("This is logback warn.") |
| 38 | + .hasSeverityLevel(SeverityLevel.WARNING) |
| 39 | + .hasProperty("FileName", "LogbackFluentLoggingServlet.java") |
| 40 | + .hasProperty("ClassName", "com.microsoft.applicationinsights.smoketestapp.LogbackFluentLoggingServlet") |
| 41 | + .hasProperty("MethodName", "doGet") |
| 42 | + .hasProperty("LineNumber", "27") |
| 43 | + .hasProperty("SourceType", "Logger") |
| 44 | + .hasProperty("LoggerName", "smoketestapp") |
| 45 | + .hasPropertyKey("ThreadName") |
| 46 | + .hasProperty("MDC key", "MDC value") |
| 47 | + .hasProperty("Marker", "aMarker") |
| 48 | + .hasProperty("customKey", "customValue") |
| 49 | + .hasNoSampleRate() |
| 50 | + .hasPropertiesSize(10) |
| 51 | + ) |
| 52 | + .hasMessageSatisfying( |
| 53 | + message -> |
| 54 | + message |
| 55 | + .hasMessage("This is logback error.") |
| 56 | + .hasSeverityLevel(SeverityLevel.ERROR) |
| 57 | + .hasProperty("FileName", "LogbackFluentLoggingServlet.java") |
| 58 | + .hasProperty("ClassName", "com.microsoft.applicationinsights.smoketestapp.LogbackFluentLoggingServlet") |
| 59 | + .hasProperty("MethodName", "doGet") |
| 60 | + .hasProperty("LineNumber", "28") |
| 61 | + .hasProperty("SourceType", "Logger") |
| 62 | + .hasProperty("LoggerName", "smoketestapp") |
| 63 | + .hasPropertyKey("ThreadName") |
| 64 | + .hasProperty("Marker", "aMarker") |
| 65 | + .hasProperty("customKey", "customValue") |
| 66 | + .hasPropertiesSize(10) |
| 67 | + .hasNoSampleRate() |
| 68 | + )); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + @TargetUri("/testWithException") |
| 73 | + void testWithException() { |
| 74 | + testing.waitAndAssertTrace( |
| 75 | + trace -> |
| 76 | + trace |
| 77 | + .hasRequestSatisying( |
| 78 | + request -> |
| 79 | + request |
| 80 | + .hasName("GET /LogbackFluentLogging/testWithException") |
| 81 | + .hasSuccess(true) |
| 82 | + .hasNoSampleRate()) |
| 83 | + .hasExceptionCount(1) |
| 84 | + .hasExceptionSatisfying( |
| 85 | + exception -> |
| 86 | + exception |
| 87 | + .hasExceptionType("java.lang.Exception") |
| 88 | + .hasExceptionMessage("Fake Exception") |
| 89 | + .hasSeverityLevel(SeverityLevel.ERROR) |
| 90 | + .hasProperty("FileName", "LogbackFluentLoggingWithExceptionServlet.java") |
| 91 | + .hasProperty("ClassName", "com.microsoft.applicationinsights.smoketestapp.LogbackFluentLoggingWithExceptionServlet") |
| 92 | + .hasProperty("MethodName", "doGet") |
| 93 | + .hasProperty("LineNumber", "24") |
| 94 | + .hasPropertiesSize(11) |
| 95 | + .hasProperty("Logger Message", "This is an exception!") |
| 96 | + .hasProperty("SourceType", "Logger") |
| 97 | + .hasProperty("LoggerName", "smoketestapp") |
| 98 | + .hasPropertyKey("ThreadName") |
| 99 | + .hasProperty("MDC key", "MDC value") |
| 100 | + .hasProperty("Marker", "aMarker") |
| 101 | + .hasProperty("customKey", "customValue") |
| 102 | + .hasNoSampleRate())); |
| 103 | + } |
| 104 | + |
| 105 | + |
| 106 | + @Environment(TOMCAT_8_JAVA_11) |
| 107 | + static class Tomcat8Java11Test extends LogbackFluentLoggingTest {} |
| 108 | + |
| 109 | + @Environment(TOMCAT_8_JAVA_11_OPENJ9) |
| 110 | + static class Tomcat8Java11OpenJ9Test extends LogbackFluentLoggingTest {} |
| 111 | + |
| 112 | + @Environment(TOMCAT_8_JAVA_17) |
| 113 | + static class Tomcat8Java17Test extends LogbackFluentLoggingTest {} |
| 114 | + |
| 115 | + @Environment(TOMCAT_8_JAVA_17_OPENJ9) |
| 116 | + static class Tomcat8Java17OpenJ9Test extends LogbackFluentLoggingTest {} |
| 117 | + |
| 118 | + @Environment(TOMCAT_8_JAVA_21) |
| 119 | + static class Tomcat8Java21Test extends LogbackFluentLoggingTest {} |
| 120 | + |
| 121 | + @Environment(TOMCAT_8_JAVA_21_OPENJ9) |
| 122 | + static class Tomcat8Java21OpenJ9Test extends LogbackFluentLoggingTest {} |
| 123 | + |
| 124 | + @Environment(TOMCAT_8_JAVA_25) |
| 125 | + static class Tomcat8Java23Test extends LogbackFluentLoggingTest {} |
| 126 | + |
| 127 | + @Environment(TOMCAT_8_JAVA_25_OPENJ9) |
| 128 | + static class Tomcat8Java23OpenJ9Test extends LogbackFluentLoggingTest {} |
| 129 | + |
| 130 | +} |
0 commit comments