Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 14, 2025

This PR updates the Logback smoke tests to use the new assertion framework introduced in #4141, following the same pattern as the HttpClients smoke test migration.

Changes Made

Extended the Assertion Framework

  • Added MessageAssert class for fluent assertions on log messages with methods like:

    • hasMessage(String) - Assert message content
    • hasSeverityLevel(SeverityLevel) - Assert log level
    • hasProperty(String, String) - Assert properties
    • hasPropertyCount(int) - Assert property count
    • Standard parent/sample rate assertions
  • Added ExceptionAssert class for fluent assertions on exceptions with methods like:

    • hasExceptionTypeName(String) - Assert exception type
    • hasExceptionMessage(String) - Assert exception message
    • hasSeverityLevel(SeverityLevel) - Assert severity level
    • hasProperty(String, String) - Assert properties
    • Standard parent/sample rate assertions
  • Extended TraceAssert with new methods:

    • hasMessageSatisying(Consumer<MessageAssert>) - Assert message conditions
    • hasExceptionSatisying(Consumer<ExceptionAssert>) - Assert exception conditions
    • hasMessageCount(int) - Assert message count
    • hasExceptionCount(int) - Assert exception count

Migrated All Logback Tests

  • LogbackTest - Converted from manual envelope processing to fluent assertions using testing.waitAndAssertTrace()
  • LogbackLevelOffTest - Updated to use new assertion framework
  • LogbackDisabledTest - Updated to use new assertion framework

Before vs After

Before (Old Pattern)

List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
Envelope rdEnvelope = rdList.get(0);
String operationId = rdEnvelope.getTags().get("ai.operation.id");
List<Envelope> mdList = testing.mockedIngestion.waitForMessageItemsInRequest(3, operationId);

List<MessageData> logs = testing.mockedIngestion.getMessageDataInRequest(3);
logs.sort(Comparator.comparing(MessageData::getSeverityLevel));
MessageData md1 = logs.get(0);

assertThat(md1.getMessage()).isEqualTo("This is logback warn.");
assertThat(md1.getSeverityLevel()).isEqualTo(SeverityLevel.WARNING);
assertThat(md1.getProperties())
    .containsEntry("SourceType", "Logger")
    .containsEntry("LoggerName", "smoketestapp");

After (New Pattern)

testing.waitAndAssertTrace(
    trace ->
        trace
            .hasRequestSatisying(
                request ->
                    request
                        .hasSuccess(true)
                        .hasNoParent()
                        .hasTag("ai.operation.name", "GET /Logback/test"))
            .hasMessageCount(3)
            .hasMessageSatisying(
                message ->
                    message
                        .hasMessage("This is logback warn.")
                        .hasSeverityLevel(SeverityLevel.WARNING)
                        .hasProperty("SourceType", "Logger")
                        .hasProperty("LoggerName", "smoketestapp")));

Benefits

  1. Consistency - All smoke tests now use the same assertion pattern
  2. Readability - Fluent API makes test intentions clearer
  3. Maintainability - Centralized assertion logic in reusable classes
  4. Reduced Boilerplate - No more manual envelope filtering and sorting
  5. Better Error Messages - AssertJ provides more descriptive failure messages

Testing

  • All Logback smoke test classes compile successfully
  • Framework unit tests pass
  • Maintains identical test coverage and assertions as the original tests
  • Handles both Wildfly and non-Wildfly server differences correctly

This completes the migration of the Logback smoke tests to the new assertion framework as requested in the original issue.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Update the Logback smoke test to use the new assertion framework introduced in @microsoft/ApplicationInsights-Java/pull/4141 Extend the assertion framework if needed. Update Logback smoke test to use new assertion framework Jul 14, 2025
Copilot AI requested a review from trask July 14, 2025 18:08
Copilot finished work on behalf of trask July 14, 2025 18:08
@trask trask closed this Jul 14, 2025
@trask trask deleted the copilot/fix-1a6d13c1-80cb-40ee-b4f6-ddac03ff2bed branch July 23, 2025 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants