Skip to content

Commit d7e4006

Browse files
author
JW Wesson
committed
add tests for match v2
1 parent 1b13d4d commit d7e4006

File tree

3 files changed

+172
-3
lines changed

3 files changed

+172
-3
lines changed

src/main/java/com/textkernel/tx/services/ApiEndpoints.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ private static String sanitize(String indexOrDocId) throws IllegalArgumentExcept
9292

9393
String matchV2CandidatesAddDocument(String documentId) { return _dataCenter.Url + "/matchv2/candidates/" + documentId; }
9494
String matchV2CandidatesDeleteDocuments(List<String> documentIds, String env) {
95-
return String.format("%smatchv2/candidates?ids=%s&SearchAndMatchEnvironment=%s", _dataCenter.Url, String.join(",", documentIds), env);
95+
return String.format("%s/matchv2/candidates?ids=%s&SearchAndMatchEnvironment=%s", _dataCenter.Url, String.join(",", documentIds), env);
9696
}
9797
String matchV2CandidatesSearch() { return _dataCenter.Url + "/matchv2/candidates/search"; }
9898
String matchV2CandidatesMatchDocument() { return _dataCenter.Url + "/matchv2/candidates/match"; }
9999
String matchV2CandidatesAutocomplete() { return _dataCenter.Url + "/matchv2/candidates/autocomplete"; }
100100
String matchV2JobsAddDocument(String documentId) { return _dataCenter.Url + "/matchv2/vacancies/" + documentId; }
101101
String matchV2JobsDeleteDocuments(List<String> documentIds, String env) {
102-
return String.format("%smatchv2/vacancies?ids=%s&SearchAndMatchEnvironment=%s", _dataCenter.Url, String.join(",", documentIds), env);
102+
return String.format("%s/matchv2/vacancies?ids=%s&SearchAndMatchEnvironment=%s", _dataCenter.Url, String.join(",", documentIds), env);
103103
}
104104
String matchV2JobsSearch() { return _dataCenter.Url + "/matchv2/vacancies/search"; }
105105
String matchV2JobsMatchDocument() { return _dataCenter.Url + "/matchv2/vacancies/match"; }

src/test/java/com/textkernel/tx/TestBase.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.textkernel.tx.models.TxDate;
1212
import com.textkernel.tx.models.api.geocoding.GeocodeCredentials;
1313
import com.textkernel.tx.models.api.geocoding.GeocodeProvider;
14+
import com.textkernel.tx.models.api.matchV2.MatchV2Environment;
1415
import com.textkernel.tx.models.api.parsing.ParseJobResponseValue;
1516
import com.textkernel.tx.models.api.parsing.ParseOptions;
1617
import com.textkernel.tx.models.api.parsing.ParseRequest;
@@ -75,6 +76,7 @@ protected TestDataCenter(String root) {
7576
settingsV2.ServiceKey = data.ServiceKey;
7677
settingsV2.DataCenter = TestDataCenter.Local;
7778
settingsV2.SkillsIntelligenceIncludeCertifications = true;
79+
settingsV2.MatchV2Environment = MatchV2Environment.PROD;
7880
ClientDESv2 = new TxClient(settingsV2);
7981

8082
ParseResumeResponseValue parseResumeResponseValue = Client.parser().parseResume(new ParseRequest(TestData.Resume, null)).Value;
@@ -109,9 +111,14 @@ public Document getTestFileAsDocument(String filename) throws IOException {
109111
return new Document("./src/test/resources/" + filename);
110112
}
111113

114+
112115
public static void delayForIndexSync() {
116+
delayForIndexSync(1);
117+
}
118+
119+
public static void delayForIndexSync(long timeout) {
113120
try {
114-
TimeUnit.SECONDS.sleep(1);
121+
TimeUnit.SECONDS.sleep(timeout);
115122
}
116123
catch (Exception e) { }
117124
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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

Comments
 (0)