Skip to content

Commit

Permalink
feat: Implement task read integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
QU3B1M committed Sep 20, 2024
1 parent 13f6c5c commit 2cae5cb
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/test/java/org/opensearch/tasks/TasksPluginIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public void testPluginInstalled() throws IOException, ParseException {
assertTrue(body.contains("tasks"));
}

public void testIndexIsCreated() throws IOException, ParseException {
Request request = new Request("POST", BASE_URI);
request.setJsonEntity("{\"title\":\"test\"}");
getRestClient().performRequest(request);

Response response = getRestClient().performRequest(new Request("GET", "_cat/indices"));
String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);

assertTrue(body.contains(TASK_INDEX));
}

public void testTaskIndexing() throws IOException, ParseException {
String title = "Task 1";
String description = "Description of Task 1";
Expand All @@ -56,14 +67,21 @@ public void testTaskIndexing() throws IOException, ParseException {
assertTrue(responseBody.contains("\"result\":\"created\""));
}

public void testIndexIsCreated() throws IOException, ParseException {
Request request = new Request("POST", BASE_URI);
request.setJsonEntity("{\"title\":\"test\"}");
getRestClient().performRequest(request);
public void testTaskRead() throws IOException, ParseException {
String title = "Task_1";
String description = "Description of Task 1";
String status = "PENDING";
String source = "{\"title\":\""+title +"\",\"description\":\""+description+"\",\"status\":\""+status+"\"}";

Response response = getRestClient().performRequest(new Request("GET", "_cat/indices"));
Request post = new Request("POST", BASE_URI);
post.setJsonEntity(source);
getRestClient().performRequest(post);

Request request = new Request("GET", BASE_URI + "/" + title);
Response response = getRestClient().performRequest(request);
String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);

assertTrue(body.contains(TASK_INDEX));
assertTrue(body.contains("\"found\":true"));
assertTrue(body.contains(source));
}
}

0 comments on commit 2cae5cb

Please sign in to comment.