|
| 1 | +package com.textkernel.tx.integration; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 6 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.util.List; |
| 11 | +import java.util.UUID; |
| 12 | +import java.util.stream.Stream; |
| 13 | + |
| 14 | +import org.junit.jupiter.api.AfterAll; |
| 15 | +import org.junit.jupiter.api.BeforeAll; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | +import org.junit.jupiter.params.ParameterizedTest; |
| 18 | +import org.junit.jupiter.params.provider.Arguments; |
| 19 | +import org.junit.jupiter.params.provider.MethodSource; |
| 20 | + |
| 21 | +import com.textkernel.tx.TestBase; |
| 22 | +import com.textkernel.tx.exceptions.TxException; |
| 23 | +import com.textkernel.tx.models.Document; |
| 24 | +import com.textkernel.tx.models.api.indexes.IndexingOptionsGeneric; |
| 25 | +import com.textkernel.tx.models.api.matchV2.MatchV2Environment; |
| 26 | +import com.textkernel.tx.models.api.matchV2.autocomplete.AutocompleteCandidatesField; |
| 27 | +import com.textkernel.tx.models.api.matchV2.autocomplete.AutocompleteJobsField; |
| 28 | +import com.textkernel.tx.models.api.matchV2.autocomplete.AutocompleteResponse; |
| 29 | +import com.textkernel.tx.models.api.matchV2.documents.DocumentSource; |
| 30 | +import com.textkernel.tx.models.api.matchV2.documents.DocumentType; |
| 31 | +import com.textkernel.tx.models.api.matchV2.querying.Options; |
| 32 | +import com.textkernel.tx.models.api.matchV2.querying.SearchQuery; |
| 33 | +import com.textkernel.tx.models.api.matchV2.querying.results.ResultItem; |
| 34 | +import com.textkernel.tx.models.api.matchV2.querying.results.SearchResult; |
| 35 | +import com.textkernel.tx.models.api.parsing.ParseOptions; |
| 36 | +import com.textkernel.tx.models.api.parsing.ParseRequest; |
| 37 | +import com.textkernel.tx.models.api.parsing.ParseResumeResponse; |
| 38 | + |
| 39 | +public class MatchV2Tests extends TestBase { |
| 40 | + |
| 41 | + private static final String _documentId = "1"; |
| 42 | + |
| 43 | + @BeforeAll |
| 44 | + static void setup() throws TxException { |
| 45 | + // add a document to each index |
| 46 | + ClientDESv2.searchMatchV2().addJob(_documentId, TestParsedJobTech, null, null); |
| 47 | + ClientDESv2.searchMatchV2().addCandidate(_documentId, TestParsedResume, null, false, null); |
| 48 | + delayForIndexSync(5); |
| 49 | + } |
| 50 | + |
| 51 | + @AfterAll |
| 52 | + static void done() throws TxException { |
| 53 | + ClientDESv2.searchMatchV2().deleteCandidates(List.of(_documentId)); |
| 54 | + ClientDESv2.searchMatchV2().deleteJobs(List.of(_documentId)); |
| 55 | + } |
| 56 | + |
| 57 | + private static Stream<Arguments> provideSearchTerms() { |
| 58 | + return Stream.of( |
| 59 | + Arguments.of("Developer"), |
| 60 | + Arguments.of("VB6") |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + @ParameterizedTest |
| 65 | + @MethodSource("provideSearchTerms") |
| 66 | + public void testSearch(String validSearchTerm) { |
| 67 | + assertThrows(TxException.class, () -> { |
| 68 | + ClientDESv2.searchMatchV2().searchCandidates(null, null); |
| 69 | + }); |
| 70 | + |
| 71 | + SearchQuery query = new SearchQuery(); |
| 72 | + assertThrows(TxException.class, () -> { |
| 73 | + ClientDESv2.searchMatchV2().searchCandidates(query, null); |
| 74 | + }); |
| 75 | + |
| 76 | + Options opts = new Options(); |
| 77 | + query.QueryString = validSearchTerm; |
| 78 | + assertDoesNotThrow(() -> { |
| 79 | + SearchResult response = ClientDESv2.searchMatchV2().searchCandidates(query, opts).Value; |
| 80 | + assertNotEquals(0, response.MatchSize); |
| 81 | + }); |
| 82 | + |
| 83 | + query.QueryString = "ThisIsATermThatIsntInTheDocument"; |
| 84 | + assertDoesNotThrow(() -> { |
| 85 | + SearchResult response = ClientDESv2.searchMatchV2().searchCandidates(query, opts).Value; |
| 86 | + assertEquals(0, response.MatchSize); |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testParseAndUpload() throws TxException, IOException { |
| 92 | + Document document = getTestFileAsDocument("resume.docx"); |
| 93 | + String docId = UUID.randomUUID().toString(); |
| 94 | + |
| 95 | + ParseOptions options = new ParseOptions(); |
| 96 | + options.IndexingOptions = new IndexingOptionsGeneric(MatchV2Environment.PROD, docId, null, null); |
| 97 | + |
| 98 | + ParseResumeResponse parseResponse = ClientDESv2.parser().parseResume(new ParseRequest(document, options)); |
| 99 | + assertTrue(parseResponse.Value.IndexingResponse.isSuccess()); |
| 100 | + delayForIndexSync(5); |
| 101 | + |
| 102 | + Options opts = new Options(); |
| 103 | + SearchQuery query = new SearchQuery(); |
| 104 | + query.QueryString = "Developer"; |
| 105 | + |
| 106 | + assertDoesNotThrow(() -> { |
| 107 | + SearchResult response = ClientDESv2.searchMatchV2().searchCandidates(query, opts).Value; |
| 108 | + assertNotEquals(0, response.MatchSize); |
| 109 | + boolean foundDocId = false; |
| 110 | + for (ResultItem item : response.ResultItems) { |
| 111 | + foundDocId |= item.DocID.equals(docId); |
| 112 | + } |
| 113 | + assertTrue(foundDocId); |
| 114 | + }); |
| 115 | + |
| 116 | + ClientDESv2.searchMatchV2().deleteCandidates(List.of(docId)); |
| 117 | + delayForIndexSync(5); |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + public void testMatch() throws TxException { |
| 122 | + assertThrows(TxException.class, () -> { |
| 123 | + ClientDESv2.searchMatchV2().matchJobs(null, null, null); |
| 124 | + }); |
| 125 | + |
| 126 | + Options options = new Options(); |
| 127 | + assertThrows(TxException.class, () -> { |
| 128 | + ClientDESv2.searchMatchV2().matchJobs(null, options, null); |
| 129 | + }); |
| 130 | + |
| 131 | + DocumentSource docSrc = new DocumentSource(); |
| 132 | + docSrc.Id = "fake-doc-id"; |
| 133 | + |
| 134 | + assertThrows(TxException.class, () -> { |
| 135 | + ClientDESv2.searchMatchV2().matchJobs(docSrc, options, null); |
| 136 | + }); |
| 137 | + |
| 138 | + docSrc.Id = _documentId; |
| 139 | + docSrc.Type = DocumentType.vacancy; |
| 140 | + |
| 141 | + assertDoesNotThrow(() -> { |
| 142 | + ClientDESv2.searchMatchV2().matchJobs(docSrc, options, null); |
| 143 | + }); |
| 144 | + |
| 145 | + assertDoesNotThrow(() -> { |
| 146 | + ClientDESv2.searchMatchV2().matchCandidates(docSrc, options, null); |
| 147 | + }); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + public void testAutocomplete() throws TxException { |
| 152 | + assertDoesNotThrow(() -> { |
| 153 | + AutocompleteResponse response = ClientDESv2.searchMatchV2().autocompleteJobs(AutocompleteJobsField.Location, "York"); |
| 154 | + assertHasItems(response.Value.Return); |
| 155 | + }); |
| 156 | + |
| 157 | + assertDoesNotThrow(() -> { |
| 158 | + AutocompleteResponse response = ClientDESv2.searchMatchV2().autocompleteCandidates(AutocompleteCandidatesField.AllJobTitles, "Softwa"); |
| 159 | + assertHasItems(response.Value.Return); |
| 160 | + }); |
| 161 | + } |
| 162 | +} |
0 commit comments