From 730a010e24e20d691fa1ed7c0d5c35527d72daa4 Mon Sep 17 00:00:00 2001 From: PK Jacob Date: Tue, 28 May 2024 17:47:52 -0400 Subject: [PATCH] MODLD-385: Create beans for Default and StructureB LCCN normalization --- .../search/cql/LccnSearchTermProcessor.java | 7 +- .../integration/KafkaMessageListener.java | 3 +- .../service/lccn/DefaultLccnNormalizer.java | 21 ++++++ .../search/service/lccn/LccnNormalizer.java | 7 ++ .../LccnNormalizerStructureB.java} | 9 ++- .../service/setter/AbstractLccnProcessor.java | 8 ++- .../authority/LccnAuthorityProcessor.java | 6 +- .../bibframe/BibframeLccnProcessor.java | 5 +- .../instance/LccnInstanceProcessor.java | 6 +- .../org/folio/search/utils/SearchUtils.java | 14 ---- src/main/resources/application.yml | 3 - .../cql/LccnSearchTermProcessorTest.java | 19 +++++- .../lccn/DefaultLccnNormalizerTest.java | 21 ++++++ .../lccn/LccnNormalizerStructurebTest.java | 58 ++++++++++++++++ .../authority/LccnAuthorityProcessorTest.java | 10 ++- .../setter/bibframe/LccnNormalizerTest.java | 66 ------------------- .../instance/LccnInstanceProcessorTest.java | 10 ++- .../folio/search/utils/SearchUtilsTest.java | 9 --- 18 files changed, 168 insertions(+), 114 deletions(-) create mode 100644 src/main/java/org/folio/search/service/lccn/DefaultLccnNormalizer.java create mode 100644 src/main/java/org/folio/search/service/lccn/LccnNormalizer.java rename src/main/java/org/folio/search/service/{setter/bibframe/LccnNormalizer.java => lccn/LccnNormalizerStructureB.java} (89%) create mode 100644 src/test/java/org/folio/search/service/lccn/DefaultLccnNormalizerTest.java create mode 100644 src/test/java/org/folio/search/service/lccn/LccnNormalizerStructurebTest.java delete mode 100644 src/test/java/org/folio/search/service/setter/bibframe/LccnNormalizerTest.java diff --git a/src/main/java/org/folio/search/cql/LccnSearchTermProcessor.java b/src/main/java/org/folio/search/cql/LccnSearchTermProcessor.java index bc8c92a84..decf0a617 100644 --- a/src/main/java/org/folio/search/cql/LccnSearchTermProcessor.java +++ b/src/main/java/org/folio/search/cql/LccnSearchTermProcessor.java @@ -1,15 +1,18 @@ package org.folio.search.cql; import lombok.RequiredArgsConstructor; -import org.folio.search.utils.SearchUtils; +import org.folio.search.service.lccn.LccnNormalizer; import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor public class LccnSearchTermProcessor implements SearchTermProcessor { + private final LccnNormalizer lccnNormalizer; + @Override public String getSearchTerm(String inputTerm) { - return SearchUtils.normalizeLccn(inputTerm); + return lccnNormalizer.apply(inputTerm) + .orElse(null); } } diff --git a/src/main/java/org/folio/search/integration/KafkaMessageListener.java b/src/main/java/org/folio/search/integration/KafkaMessageListener.java index 1f46a0200..f580bdd84 100644 --- a/src/main/java/org/folio/search/integration/KafkaMessageListener.java +++ b/src/main/java/org/folio/search/integration/KafkaMessageListener.java @@ -209,8 +209,7 @@ public void handleBibframeEvents(List> con .map(bibframe -> bibframe.resourceName(BIBFRAME_RESOURCE).id(getResourceEventId(bibframe))) .toList(); - folioMessageBatchProcessor.consumeBatchWithFallback(batch, KAFKA_RETRY_TEMPLATE_NAME, - resourceService::indexResources, KafkaMessageListener::logFailedEvent); + indexResources(batch, resourceService::indexResources); } private void indexResources(List batch, Consumer> indexConsumer) { diff --git a/src/main/java/org/folio/search/service/lccn/DefaultLccnNormalizer.java b/src/main/java/org/folio/search/service/lccn/DefaultLccnNormalizer.java new file mode 100644 index 000000000..7da59a92a --- /dev/null +++ b/src/main/java/org/folio/search/service/lccn/DefaultLccnNormalizer.java @@ -0,0 +1,21 @@ +package org.folio.search.service.lccn; + +import java.util.Optional; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; + +@Service +@Primary +public class DefaultLccnNormalizer implements LccnNormalizer { + + @Override + public Optional apply(String lccn) { + if (StringUtils.isBlank(lccn)) { + return Optional.empty(); + } + + return Optional.of(StringUtils.deleteWhitespace(lccn)) + .map(String::toLowerCase); + } +} diff --git a/src/main/java/org/folio/search/service/lccn/LccnNormalizer.java b/src/main/java/org/folio/search/service/lccn/LccnNormalizer.java new file mode 100644 index 000000000..cfbae4b20 --- /dev/null +++ b/src/main/java/org/folio/search/service/lccn/LccnNormalizer.java @@ -0,0 +1,7 @@ +package org.folio.search.service.lccn; + +import java.util.Optional; +import java.util.function.Function; + +public interface LccnNormalizer extends Function> { +} diff --git a/src/main/java/org/folio/search/service/setter/bibframe/LccnNormalizer.java b/src/main/java/org/folio/search/service/lccn/LccnNormalizerStructureB.java similarity index 89% rename from src/main/java/org/folio/search/service/setter/bibframe/LccnNormalizer.java rename to src/main/java/org/folio/search/service/lccn/LccnNormalizerStructureB.java index 595038654..07e4bbdc6 100644 --- a/src/main/java/org/folio/search/service/setter/bibframe/LccnNormalizer.java +++ b/src/main/java/org/folio/search/service/lccn/LccnNormalizerStructureB.java @@ -1,4 +1,4 @@ -package org.folio.search.service.setter.bibframe; +package org.folio.search.service.lccn; import jakarta.validation.constraints.NotNull; import java.util.Optional; @@ -6,9 +6,12 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +/** + * Class responsible for normalizing Structure B LCCN values. + */ @Log4j2 @Service -public class LccnNormalizer { +public class LccnNormalizerStructureB implements LccnNormalizer { private static final String NORMALIZED_LCCN_REGEX = "\\d{10}"; private static final char HYPHEN = '-'; @@ -19,7 +22,7 @@ public class LccnNormalizer { * @param lccn LCCN to be normalized * @return Returns the normalized LCCN. If the given LCCN is invalid, returns an empty Optional */ - public Optional normalizeLccn(@NotNull final String lccn) { + public Optional apply(@NotNull final String lccn) { var normalizedLccn = lccn; // Remove white spaces diff --git a/src/main/java/org/folio/search/service/setter/AbstractLccnProcessor.java b/src/main/java/org/folio/search/service/setter/AbstractLccnProcessor.java index d7eda0d3f..ac50c4657 100644 --- a/src/main/java/org/folio/search/service/setter/AbstractLccnProcessor.java +++ b/src/main/java/org/folio/search/service/setter/AbstractLccnProcessor.java @@ -7,20 +7,22 @@ import java.util.stream.Collectors; import org.folio.search.domain.dto.Identifier; import org.folio.search.integration.ReferenceDataService; -import org.folio.search.utils.SearchUtils; +import org.folio.search.service.lccn.LccnNormalizer; public abstract class AbstractLccnProcessor extends AbstractIdentifierProcessor { private static final List LCCN_IDENTIFIER_NAME = List.of("LCCN", "Canceled LCCN"); + private final LccnNormalizer lccnNormalizer; - protected AbstractLccnProcessor(ReferenceDataService referenceDataService) { + protected AbstractLccnProcessor(ReferenceDataService referenceDataService, LccnNormalizer lccnNormalizer) { super(referenceDataService, LCCN_IDENTIFIER_NAME); + this.lccnNormalizer = lccnNormalizer; } @Override public Set getFieldValue(T entity) { return filterIdentifiersValue(getIdentifiers(entity)).stream() - .map(SearchUtils::normalizeLccn) + .flatMap(s -> lccnNormalizer.apply(s).stream()) .filter(Objects::nonNull) .collect(Collectors.toCollection(LinkedHashSet::new)); } diff --git a/src/main/java/org/folio/search/service/setter/authority/LccnAuthorityProcessor.java b/src/main/java/org/folio/search/service/setter/authority/LccnAuthorityProcessor.java index 8f2e56cf4..527baf320 100644 --- a/src/main/java/org/folio/search/service/setter/authority/LccnAuthorityProcessor.java +++ b/src/main/java/org/folio/search/service/setter/authority/LccnAuthorityProcessor.java @@ -6,6 +6,7 @@ import org.folio.search.domain.dto.Authority; import org.folio.search.domain.dto.Identifier; import org.folio.search.integration.ReferenceDataService; +import org.folio.search.service.lccn.LccnNormalizer; import org.folio.search.service.setter.AbstractLccnProcessor; import org.springframework.stereotype.Component; @@ -16,9 +17,10 @@ public class LccnAuthorityProcessor extends AbstractLccnProcessor { * Used by dependency injection. * * @param referenceDataService {@link ReferenceDataService} bean + * @param lccnNormalizer {@link LccnNormalizer} bean */ - public LccnAuthorityProcessor(ReferenceDataService referenceDataService) { - super(referenceDataService); + public LccnAuthorityProcessor(ReferenceDataService referenceDataService, LccnNormalizer lccnNormalizer) { + super(referenceDataService, lccnNormalizer); } @Override diff --git a/src/main/java/org/folio/search/service/setter/bibframe/BibframeLccnProcessor.java b/src/main/java/org/folio/search/service/setter/bibframe/BibframeLccnProcessor.java index f6a007ba5..1ac3fb900 100644 --- a/src/main/java/org/folio/search/service/setter/bibframe/BibframeLccnProcessor.java +++ b/src/main/java/org/folio/search/service/setter/bibframe/BibframeLccnProcessor.java @@ -13,13 +13,16 @@ import lombok.RequiredArgsConstructor; import org.folio.search.domain.dto.Bibframe; import org.folio.search.domain.dto.BibframeInstancesInnerIdentifiersInner; +import org.folio.search.service.lccn.LccnNormalizer; import org.folio.search.service.setter.FieldProcessor; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor public class BibframeLccnProcessor implements FieldProcessor> { + @Qualifier("StructBLccnNormalizer") private final LccnNormalizer lccnNormalizer; @Override @@ -31,7 +34,7 @@ public Set getFieldValue(Bibframe bibframe) { .filter(i -> LCCN.equals(i.getType())) .map(BibframeInstancesInnerIdentifiersInner::getValue) .filter(Objects::nonNull) - .map(lccnNormalizer::normalizeLccn) + .map(lccnNormalizer) .flatMap(Optional::stream) .collect(toCollection(LinkedHashSet::new)); } diff --git a/src/main/java/org/folio/search/service/setter/instance/LccnInstanceProcessor.java b/src/main/java/org/folio/search/service/setter/instance/LccnInstanceProcessor.java index 6c24483df..fd2d1a991 100644 --- a/src/main/java/org/folio/search/service/setter/instance/LccnInstanceProcessor.java +++ b/src/main/java/org/folio/search/service/setter/instance/LccnInstanceProcessor.java @@ -6,6 +6,7 @@ import org.folio.search.domain.dto.Identifier; import org.folio.search.domain.dto.Instance; import org.folio.search.integration.ReferenceDataService; +import org.folio.search.service.lccn.LccnNormalizer; import org.folio.search.service.setter.AbstractLccnProcessor; import org.springframework.stereotype.Component; @@ -19,9 +20,10 @@ public class LccnInstanceProcessor extends AbstractLccnProcessor { * Used by dependency injection. * * @param referenceDataService {@link ReferenceDataService} bean + * @param lccnNormalizer {@link LccnNormalizer} bean */ - public LccnInstanceProcessor(ReferenceDataService referenceDataService) { - super(referenceDataService); + public LccnInstanceProcessor(ReferenceDataService referenceDataService, LccnNormalizer lccnNormalizer) { + super(referenceDataService, lccnNormalizer); } @Override diff --git a/src/main/java/org/folio/search/utils/SearchUtils.java b/src/main/java/org/folio/search/utils/SearchUtils.java index 397c56df5..f74ff9f15 100644 --- a/src/main/java/org/folio/search/utils/SearchUtils.java +++ b/src/main/java/org/folio/search/utils/SearchUtils.java @@ -329,20 +329,6 @@ public static int getNumberOfRequests(Map> requ .sum(); } - /** - * Normalizes LCCN value. - * - * @param value LCCN value - * @return normalized LCCN value - */ - public static String normalizeLccn(String value) { - if (StringUtils.isBlank(value)) { - return null; - } - - return StringUtils.deleteWhitespace(value).toLowerCase(); - } - /** * This method normalize the given string to an alphanumeric string. * If the input string is null or blank, this method returns null. diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index fefd78031..969013fc7 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -106,9 +106,6 @@ folio: - name: search.consortium.instance numPartitions: ${KAFKA_CONSORTIUM_INSTANCE_TOPIC_PARTITIONS:50} replicationFactor: ${KAFKA_CONSORTIUM_INSTANCE_TOPIC_REPLICATION_FACTOR:} - - name: search.bibframe - numPartitions: ${KAFKA_BIBFRAME_TOPIC_PARTITIONS:3} - replicationFactor: ${KAFKA_BIBFRAME_TOPIC_REPLICATION_FACTOR:} listener: events: concurrency: ${KAFKA_EVENTS_CONCURRENCY:2} diff --git a/src/test/java/org/folio/search/cql/LccnSearchTermProcessorTest.java b/src/test/java/org/folio/search/cql/LccnSearchTermProcessorTest.java index f04dc6810..e0eac345b 100644 --- a/src/test/java/org/folio/search/cql/LccnSearchTermProcessorTest.java +++ b/src/test/java/org/folio/search/cql/LccnSearchTermProcessorTest.java @@ -1,23 +1,36 @@ package org.folio.search.cql; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; +import java.util.Optional; +import org.folio.search.service.lccn.LccnNormalizer; import org.folio.spring.testing.type.UnitTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; - @UnitTest @ExtendWith(MockitoExtension.class) class LccnSearchTermProcessorTest { + @Mock + private LccnNormalizer normalizer; + @InjectMocks + private LccnSearchTermProcessor lccnSearchTermProcessor; @Test void getSearchTerm_positive() { + // given var searchTerm = " N 123456 "; - var lccnSearchTermProcessor = new LccnSearchTermProcessor(); + var normalizedTerm = "n123456"; + when(normalizer.apply(searchTerm)).thenReturn(Optional.of(normalizedTerm)); + // when var actual = lccnSearchTermProcessor.getSearchTerm(searchTerm); - assertThat(actual).isEqualTo("n123456"); + + // then + assertThat(actual).isEqualTo(normalizedTerm); } } diff --git a/src/test/java/org/folio/search/service/lccn/DefaultLccnNormalizerTest.java b/src/test/java/org/folio/search/service/lccn/DefaultLccnNormalizerTest.java new file mode 100644 index 000000000..0b5902286 --- /dev/null +++ b/src/test/java/org/folio/search/service/lccn/DefaultLccnNormalizerTest.java @@ -0,0 +1,21 @@ +package org.folio.search.service.lccn; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.folio.spring.testing.type.UnitTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +@UnitTest +class DefaultLccnNormalizerTest { + private DefaultLccnNormalizer lccnNormalizer = new DefaultLccnNormalizer(); + + @DisplayName("LCCN value normalization") + @CsvSource({"n 1234,n1234", " N 1234 ,n1234", "*1234,*1234", "1234*,1234*"}) + @ParameterizedTest(name = "[{index}] value={0}, expected={1}") + void getLccnNormalized_parameterized(String value, String expected) { + var normalized = lccnNormalizer.apply(value); + assertThat(normalized).contains(expected); + } +} diff --git a/src/test/java/org/folio/search/service/lccn/LccnNormalizerStructurebTest.java b/src/test/java/org/folio/search/service/lccn/LccnNormalizerStructurebTest.java new file mode 100644 index 000000000..62ef98607 --- /dev/null +++ b/src/test/java/org/folio/search/service/lccn/LccnNormalizerStructurebTest.java @@ -0,0 +1,58 @@ +package org.folio.search.service.lccn; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Optional; +import org.folio.spring.testing.type.UnitTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +@UnitTest +class LccnNormalizerStructurebTest { + private final LccnNormalizerStructureB lccnNormalizer = new LccnNormalizerStructureB(); + + @Test + void shouldRemoveSpaces() { + assertThat(lccnNormalizer.apply(" 2017000002")).isEqualTo(Optional.of("2017000002")); + assertThat(lccnNormalizer.apply("2017000002 ")).isEqualTo(Optional.of("2017000002")); + assertThat(lccnNormalizer.apply("2017 000002")).isEqualTo(Optional.of("2017000002")); + assertThat(lccnNormalizer.apply(" 20 17000 002 ")).isEqualTo(Optional.of("2017000002")); + } + + @Test + void shouldRemoveForwardSlash() { + assertThat(lccnNormalizer.apply("2012425165//r75")).isEqualTo(Optional.of("2012425165")); + assertThat(lccnNormalizer.apply("2022139101/AC/r932")).isEqualTo(Optional.of("2022139101")); + } + + @Test + void shouldRemoveHyphen() { + assertThat(lccnNormalizer.apply("2022-890351")).isEqualTo(Optional.of("2022890351")); + } + + @Test + void shouldNormalizeSerialNumber() { + assertThat(lccnNormalizer.apply("2011-89035")).isEqualTo(Optional.of("2011089035")); + assertThat(lccnNormalizer.apply("2020-2")).isEqualTo(Optional.of("2020000002")); + } + + @Test + void shouldNormalizeSpacesAndHyphenAndForwardSlash() { + assertThat(lccnNormalizer.apply(" 20 20-2 //r23/AC")).isEqualTo(Optional.of("2020000002")); + } + + @ParameterizedTest + @ValueSource(strings = { + "01234567891", // more than 10 digits + "2020-2-34", // more than one hyphen + "A017000002", // non-digit character + "/2017000002", // slash in the beginning + "", // empty string + "202-0234334", // "-" is in third index (instead of forth) + "2020-", // "-" is the last character + }) + void shouldReturnEmptyOptionalWhenLccnIsNotValid(String toNormalize) { + assertThat(lccnNormalizer.apply(toNormalize)).isEmpty(); + } +} diff --git a/src/test/java/org/folio/search/service/setter/authority/LccnAuthorityProcessorTest.java b/src/test/java/org/folio/search/service/setter/authority/LccnAuthorityProcessorTest.java index 6f36b0d0f..84e1dd899 100644 --- a/src/test/java/org/folio/search/service/setter/authority/LccnAuthorityProcessorTest.java +++ b/src/test/java/org/folio/search/service/setter/authority/LccnAuthorityProcessorTest.java @@ -16,14 +16,15 @@ import org.folio.search.domain.dto.Identifier; import org.folio.search.integration.ReferenceDataService; import org.folio.search.model.client.CqlQueryParam; +import org.folio.search.service.lccn.DefaultLccnNormalizer; import org.folio.spring.testing.type.UnitTest; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -31,11 +32,16 @@ @ExtendWith(MockitoExtension.class) class LccnAuthorityProcessorTest { - @InjectMocks private LccnAuthorityProcessor lccnProcessor; @Mock private ReferenceDataService referenceDataService; + @BeforeEach + void setup() { + var lccnNormalizer = new DefaultLccnNormalizer(); + lccnProcessor = new LccnAuthorityProcessor(referenceDataService, lccnNormalizer); + } + @MethodSource("lccnDataProvider") @DisplayName("getFieldValue_parameterized") @ParameterizedTest(name = "[{index}] authority with {0}, expected={2}") diff --git a/src/test/java/org/folio/search/service/setter/bibframe/LccnNormalizerTest.java b/src/test/java/org/folio/search/service/setter/bibframe/LccnNormalizerTest.java deleted file mode 100644 index 0c60a99f2..000000000 --- a/src/test/java/org/folio/search/service/setter/bibframe/LccnNormalizerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.folio.search.service.setter.bibframe; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Optional; -import org.folio.spring.testing.type.UnitTest; -import org.junit.jupiter.api.Test; - -@UnitTest -class LccnNormalizerTest { - private final LccnNormalizer lccnNormalizer = new LccnNormalizer(); - - @Test - void shouldRemoveSpaces() { - assertThat(lccnNormalizer.normalizeLccn(" 2017000002")).isEqualTo(Optional.of("2017000002")); - assertThat(lccnNormalizer.normalizeLccn("2017000002 ")).isEqualTo(Optional.of("2017000002")); - assertThat(lccnNormalizer.normalizeLccn("2017 000002")).isEqualTo(Optional.of("2017000002")); - assertThat(lccnNormalizer.normalizeLccn(" 20 17000 002 ")).isEqualTo(Optional.of("2017000002")); - } - - @Test - void shouldRemoveForwardSlash() { - assertThat(lccnNormalizer.normalizeLccn("2012425165//r75")).isEqualTo(Optional.of("2012425165")); - assertThat(lccnNormalizer.normalizeLccn("2022139101/AC/r932")).isEqualTo(Optional.of("2022139101")); - } - - @Test - void shouldRemoveHyphen() { - assertThat(lccnNormalizer.normalizeLccn("2022-890351")).isEqualTo(Optional.of("2022890351")); - } - - @Test - void shouldNormalizeSerialNumber() { - assertThat(lccnNormalizer.normalizeLccn("2011-89035")).isEqualTo(Optional.of("2011089035")); - assertThat(lccnNormalizer.normalizeLccn("2020-2")).isEqualTo(Optional.of("2020000002")); - } - - @Test - void shouldNormalizeSpacesAndHyphenAndForwardSlash() { - assertThat(lccnNormalizer.normalizeLccn(" 20 20-2 //r23/AC")).isEqualTo(Optional.of("2020000002")); - } - - @Test - void shouldReturnEmptyOptionalWhenLccnIsNotValid() { - // more than 10 digits - assertThat(lccnNormalizer.normalizeLccn("01234567891")).isEmpty(); - - // more than one hyphen - assertThat(lccnNormalizer.normalizeLccn("2020-2-34")).isEmpty(); - - // non-digit character - assertThat(lccnNormalizer.normalizeLccn("A017000002")).isEmpty(); - - // slash in the beginning - assertThat(lccnNormalizer.normalizeLccn("/2017000002")).isEmpty(); - - // empty string - assertThat(lccnNormalizer.normalizeLccn("")).isEmpty(); - - // "-" is in third index (instead of forth) - assertThat(lccnNormalizer.normalizeLccn("202-0234334")).isEmpty(); - - // "-" is the last character - assertThat(lccnNormalizer.normalizeLccn("2020-")).isEmpty(); - } -} diff --git a/src/test/java/org/folio/search/service/setter/instance/LccnInstanceProcessorTest.java b/src/test/java/org/folio/search/service/setter/instance/LccnInstanceProcessorTest.java index e2a39ad94..8536d156d 100644 --- a/src/test/java/org/folio/search/service/setter/instance/LccnInstanceProcessorTest.java +++ b/src/test/java/org/folio/search/service/setter/instance/LccnInstanceProcessorTest.java @@ -16,14 +16,15 @@ import org.folio.search.domain.dto.Instance; import org.folio.search.integration.ReferenceDataService; import org.folio.search.model.client.CqlQueryParam; +import org.folio.search.service.lccn.DefaultLccnNormalizer; import org.folio.spring.testing.type.UnitTest; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -35,9 +36,14 @@ class LccnInstanceProcessorTest { @Mock private ReferenceDataService referenceDataService; - @InjectMocks private LccnInstanceProcessor lccnProcessor; + @BeforeEach + void setup() { + var lccnNormalizer = new DefaultLccnNormalizer(); + lccnProcessor = new LccnInstanceProcessor(referenceDataService, lccnNormalizer); + } + @MethodSource("lccnDataProvider") @DisplayName("getFieldValue_parameterized") @ParameterizedTest(name = "[{index}] instance with {0}, expected={2}") diff --git a/src/test/java/org/folio/search/utils/SearchUtilsTest.java b/src/test/java/org/folio/search/utils/SearchUtilsTest.java index bc16a1e7a..00e23e532 100644 --- a/src/test/java/org/folio/search/utils/SearchUtilsTest.java +++ b/src/test/java/org/folio/search/utils/SearchUtilsTest.java @@ -11,7 +11,6 @@ import static org.folio.search.utils.SearchUtils.getIndexName; import static org.folio.search.utils.SearchUtils.getResourceName; import static org.folio.search.utils.SearchUtils.getTotalPages; -import static org.folio.search.utils.SearchUtils.normalizeLccn; import static org.folio.search.utils.SearchUtils.performExceptionalOperation; import static org.folio.search.utils.SearchUtils.updateMultilangPlainFieldKey; import static org.folio.search.utils.TestConstants.INDEX_NAME; @@ -91,14 +90,6 @@ void getTotalPages_parameterized(long total, long expected) { assertThat(totalPages).isEqualTo(expected); } - @DisplayName("LCCN value normalization") - @CsvSource({"n 1234,n1234", " N 1234 ,n1234", "*1234,*1234", "1234*,1234*"}) - @ParameterizedTest(name = "[{index}] value={0}, expected={1}") - void getLccnNormalized_parameterized(String value, String expected) { - var normalized = normalizeLccn(value); - assertThat(normalized).isEqualTo(expected); - } - @CsvSource({ "path,path", "object.value,object.value",