Skip to content

Commit

Permalink
chore: improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia committed Jan 23, 2025
1 parent 76e31ff commit 57a06e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public Flux<CodeNameDto> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -257,6 +258,12 @@ void testFindActiveUpdateReasonsByClientTypeAndActionCode() {

CodeNameDto expectedDto = new CodeNameDto("CORR", "Correction");

Logger logger = (Logger) LoggerFactory.getLogger(ClientLegacyService.class);

ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
listAppender.start();
logger.addAppender(listAppender);

legacyStub.stubFor(
get(urlPathEqualTo("/api/codes/update-reasons/" + clientTypeCode + "/" + actionCode))
.willReturn(okJson("[{\"code\":\"CORR\",\"name\":\"Correction\"}]"))
Expand All @@ -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
Expand Down

0 comments on commit 57a06e5

Please sign in to comment.