From 57a06e5d8685993128203d2d8ad44189287fa6fd Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Thu, 23 Jan 2025 15:33:17 -0800 Subject: [PATCH] chore: improved tests --- .../service/client/ClientLegacyService.java | 2 +- .../ClientLegacyServiceIntegrationTest.java | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/service/client/ClientLegacyService.java b/backend/src/main/java/ca/bc/gov/app/service/client/ClientLegacyService.java index e5dce6d56..cfa406617 100644 --- a/backend/src/main/java/ca/bc/gov/app/service/client/ClientLegacyService.java +++ b/backend/src/main/java/ca/bc/gov/app/service/client/ClientLegacyService.java @@ -258,7 +258,7 @@ public Flux findActiveUpdateReasonsByClientTypeAndActionCode( String actionCode ) { // Log the parameters for debugging purposes - log.info("Searching for client type {} and action {} in legacy", + log.info("Searching for client type {} and action code {} in legacy", clientTypeCode, actionCode); diff --git a/backend/src/test/java/ca/bc/gov/app/service/client/ClientLegacyServiceIntegrationTest.java b/backend/src/test/java/ca/bc/gov/app/service/client/ClientLegacyServiceIntegrationTest.java index 3fcf43953..e696758c4 100644 --- a/backend/src/test/java/ca/bc/gov/app/service/client/ClientLegacyServiceIntegrationTest.java +++ b/backend/src/test/java/ca/bc/gov/app/service/client/ClientLegacyServiceIntegrationTest.java @@ -16,21 +16,22 @@ import ca.bc.gov.app.dto.legacy.ForestClientDetailsDto; import ca.bc.gov.app.extensions.AbstractTestContainerIntegrationTest; import ca.bc.gov.app.extensions.WiremockLogNotifier; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; import com.github.tomakehurst.wiremock.junit5.WireMockExtension; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Stream; import org.apache.commons.lang3.StringUtils; -import org.mockito.Mockito; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.beans.factory.annotation.Autowired; -import reactor.core.publisher.Flux; +import org.slf4j.LoggerFactory; import reactor.test.StepVerifier; @DisplayName("Integration Test | Client Legacy Service Test") @@ -257,6 +258,12 @@ void testFindActiveUpdateReasonsByClientTypeAndActionCode() { CodeNameDto expectedDto = new CodeNameDto("CORR", "Correction"); + Logger logger = (Logger) LoggerFactory.getLogger(ClientLegacyService.class); + + ListAppender listAppender = new ListAppender<>(); + listAppender.start(); + logger.addAppender(listAppender); + legacyStub.stubFor( get(urlPathEqualTo("/api/codes/update-reasons/" + clientTypeCode + "/" + actionCode)) .willReturn(okJson("[{\"code\":\"CORR\",\"name\":\"Correction\"}]")) @@ -270,6 +277,19 @@ void testFindActiveUpdateReasonsByClientTypeAndActionCode() { assertEquals(expectedDto.name(), dto.name()); }) .verifyComplete(); + + boolean logMessage1Found = listAppender.list.stream() + .anyMatch(event -> event.getFormattedMessage().contains("Searching for client type") && + event.getFormattedMessage().contains(clientTypeCode) && + event.getFormattedMessage().contains(actionCode)); + + boolean logMessage2Found = listAppender.list.stream() + .anyMatch(event -> event.getFormattedMessage().contains("Found data for client type") && + event.getFormattedMessage().contains(clientTypeCode) && + event.getFormattedMessage().contains(actionCode)); + + assertTrue(logMessage1Found, "Expected log message for searching not found."); + assertTrue(logMessage2Found, "Expected log message for found data not found."); } @Test