Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
Signed-off-by: br3no <[email protected]>
  • Loading branch information
br3no committed Oct 23, 2024
1 parent dfa03fe commit a5977b2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class TextEmbeddingProcessorIT extends BaseNeuralSearchIT {
private final String INGEST_DOC2 = Files.readString(Path.of(classLoader.getResource("processor/ingest_doc2.json").toURI()));
private final String INGEST_DOC3 = Files.readString(Path.of(classLoader.getResource("processor/ingest_doc3.json").toURI()));
private final String INGEST_DOC4 = Files.readString(Path.of(classLoader.getResource("processor/ingest_doc4.json").toURI()));
private final String INGEST_DOC5 = Files.readString(Path.of(classLoader.getResource("processor/ingest_doc5.json").toURI()));
private final String BULK_ITEM_TEMPLATE = Files.readString(
Path.of(classLoader.getResource("processor/bulk_item_template.json").toURI())
);
Expand Down Expand Up @@ -264,51 +265,13 @@ public void testAsymmetricTextEmbeddingProcessor() throws Exception {
loadModel(modelId);
createPipelineProcessor(modelId, PIPELINE_NAME, ProcessorType.TEXT_EMBEDDING, 2);
createTextEmbeddingIndex();
ingestDocument();
ingestDocument(INGEST_DOC5, null);
assertEquals(1, getDocCount(INDEX_NAME));
} finally {
wipeOfTestResources(INDEX_NAME, PIPELINE_NAME, modelId, null);
}
}

private void ingestDocument() throws Exception {
String ingestDocument = "{\n"
+ " \"title\": \"This is a good day\",\n"
+ " \"description\": \"daily logging\",\n"
+ " \"favor_list\": [\n"
+ " \"test\",\n"
+ " \"hello\",\n"
+ " \"mock\"\n"
+ " ],\n"
+ " \"favorites\": {\n"
+ " \"game\": \"overwatch\",\n"
+ " \"movie\": null\n"
+ " },\n"
+ " \"nested_passages\": [\n"
+ " {\n"
+ " \"text\": \"hello\"\n"
+ " },\n"
+ " {\n"
+ " \"text\": \"world\"\n"
+ " }\n"
+ " ]\n"
+ "}\n";
Response response = makeRequest(
client(),
"POST",
INDEX_NAME + "/_doc?refresh",
null,
toHttpEntity(ingestDocument),
ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "Kibana"))
);
Map<String, Object> map = XContentHelper.convertToMap(
XContentType.JSON.xContent(),
EntityUtils.toString(response.getEntity()),
false
);
assertEquals("created", map.get("result"));
}

private void ingestDocument(String doc, String id) throws Exception {
String endpoint;
if (StringUtils.isEmpty(id)) {
Expand Down
21 changes: 21 additions & 0 deletions src/test/resources/processor/ingest_doc5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"title": "This is a good day",
"description": "daily logging",
"favor_list": [
"test",
"hello",
"mock"
],
"favorites": {
"game": "overwatch",
"movie": null
},
"nested_passages": [
{
"text": "hello"
},
{
"text": "world"
}
]
}

0 comments on commit a5977b2

Please sign in to comment.