-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FSADT1-973): adding doing business as matcher
- Loading branch information
1 parent
7221eec
commit 08b7861
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
processor/src/main/java/ca/bc/gov/app/service/processor/DoingBusinessAsProcessorMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package ca.bc.gov.app.service.processor; | ||
|
||
import static java.util.function.Predicate.not; | ||
|
||
import ca.bc.gov.app.dto.MatcherResult; | ||
import ca.bc.gov.app.dto.SubmissionInformationDto; | ||
import ca.bc.gov.app.entity.legacy.ClientDoingBusinessAsEntity; | ||
import ca.bc.gov.app.entity.legacy.ForestClientEntity; | ||
import ca.bc.gov.app.repository.legacy.ClientDoingBusinessAsRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class DoingBusinessAsProcessorMatcher implements ProcessorMatcher { | ||
|
||
private final ClientDoingBusinessAsRepository doingBusinessAsRepository; | ||
|
||
@Override | ||
public boolean enabled(SubmissionInformationDto submission) { | ||
return "RSP".equalsIgnoreCase(submission.clientType()); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "Doing Business As Fuzzy Matcher"; | ||
} | ||
|
||
@Override | ||
public Mono<MatcherResult> matches(SubmissionInformationDto submission) { | ||
|
||
log.info("{} :: Validating {}", name(), submission.corporationName()); | ||
|
||
return | ||
matchBy(submission.corporationName()) | ||
.map(ClientDoingBusinessAsEntity::getClientNumber) | ||
.collectList() | ||
.filter(not(List::isEmpty)) | ||
.map(values -> | ||
new MatcherResult("corporationName", String.join(",", values)) | ||
); | ||
} | ||
|
||
private Flux<ClientDoingBusinessAsEntity> matchBy(String companyName) { | ||
return | ||
doingBusinessAsRepository | ||
.matchBy(companyName) | ||
.doOnNext(entity -> log.info("Found a match {}", entity)); | ||
|
||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
...or/src/test/java/ca/bc/gov/app/service/processor/DoingBusinessAsProcessorMatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package ca.bc.gov.app.service.processor; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import ca.bc.gov.app.dto.MatcherResult; | ||
import ca.bc.gov.app.dto.SubmissionInformationDto; | ||
import ca.bc.gov.app.entity.legacy.ClientDoingBusinessAsEntity; | ||
import ca.bc.gov.app.entity.legacy.ForestClientEntity; | ||
import ca.bc.gov.app.repository.legacy.ClientDoingBusinessAsRepository; | ||
import ca.bc.gov.app.repository.legacy.ForestClientRepository; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import reactor.core.publisher.Flux; | ||
import reactor.test.StepVerifier; | ||
|
||
@DisplayName("Unit Test | Doing Business As Matcher") | ||
class DoingBusinessAsProcessorMatcherTest { | ||
|
||
private final ClientDoingBusinessAsRepository repository = mock(ClientDoingBusinessAsRepository.class); | ||
ProcessorMatcher matcher = new DoingBusinessAsProcessorMatcher(repository); | ||
|
||
@Test | ||
@DisplayName("Name matching") | ||
void shouldMatchName() { | ||
assertEquals("Doing Business As Fuzzy Matcher", matcher.name()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("legalName") | ||
@DisplayName("Match or not") | ||
void shouldMatchOrNot( | ||
SubmissionInformationDto dto, | ||
boolean success, | ||
MatcherResult result, | ||
Flux<ClientDoingBusinessAsEntity> mockData | ||
) { | ||
|
||
when(repository.matchBy(dto.corporationName())) | ||
.thenReturn(mockData); | ||
|
||
StepVerifier.FirstStep<MatcherResult> verifier = | ||
matcher | ||
.matches(dto) | ||
.as(StepVerifier::create); | ||
|
||
if (success) { | ||
verifier.verifyComplete(); | ||
} else { | ||
verifier | ||
.expectNext(result) | ||
.verifyComplete(); | ||
} | ||
} | ||
|
||
private static Stream<Arguments> legalName() { | ||
return | ||
Stream.of( | ||
Arguments.of( | ||
new SubmissionInformationDto("James", null,null, null,"C"), | ||
true, | ||
null, | ||
Flux.empty() | ||
), | ||
Arguments.of( | ||
new SubmissionInformationDto("Marco", null, null, null,"C"), | ||
false, | ||
new MatcherResult("corporationName", String.join(",", "00000000")), | ||
Flux.just(new ForestClientEntity().withClientNumber("00000000")) | ||
), | ||
Arguments.of( | ||
new SubmissionInformationDto("Lucca", null, null, null,"C"), | ||
false, | ||
new MatcherResult("corporationName", String.join(",", "00000000", "00000001")), | ||
Flux.just(new ClientDoingBusinessAsEntity().withClientNumber("00000000"), | ||
new ClientDoingBusinessAsEntity().withClientNumber("00000001")) | ||
) | ||
); | ||
} | ||
|
||
} |