Skip to content

Commit

Permalink
Merge #757
Browse files Browse the repository at this point in the history
757: Fixing empty TaskError response r=curquiza a=larskristianhaga

# Pull Request

Seems like the `TaskError` object is only returning empty Strings when trying to get the error details of a task. Seems to be a missmatch between the field naming, and number of fields based on the API response. Therefor it dosent understand what to map, and only gives empty strings back.


## Related issue
None

## What does this PR do?
- It moves the `TaskError` class to the `model` package, closer to the usage in `Task` class.
  - Since its peers`TaskDetails`, and `TaskStatus` are already here.
- Updates the field in `TaskError` to match the API naming, and number of fields.
- Updates the Exception integration test to use the correct naming and import.
- Adds Integration tests to check that `TaskError` fields is not blank or null.

## PR checklist
Please check if your PR fulfills the following requirements:
- [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [X] Have you read the contributing guidelines?
- [X] Have you made sure that the title is accurate and descriptive of the changes?


Co-authored-by: larskristianhaga <[email protected]>
  • Loading branch information
meili-bors[bot] and larskristianhaga authored Jul 15, 2024
2 parents d591794 + 725a05f commit 45c2d88
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 20 deletions.
16 changes: 0 additions & 16 deletions src/main/java/com/meilisearch/sdk/TaskError.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/com/meilisearch/sdk/model/Task.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.meilisearch.sdk.model;

import com.meilisearch.sdk.TaskError;
import java.util.Date;
import lombok.Getter;

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/meilisearch/sdk/model/TaskError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.meilisearch.sdk.model;

import lombok.Getter;
import lombok.Setter;

/** The code, type‚ error and message of the task error */
@Getter
@Setter
public class TaskError {

public TaskError() {}

protected String code = "";
protected String type = "";
protected String link = "";
protected String message = "";
}
6 changes: 3 additions & 3 deletions src/test/java/com/meilisearch/integration/ExceptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import com.meilisearch.integration.classes.AbstractIT;
import com.meilisearch.sdk.Client;
import com.meilisearch.sdk.Config;
import com.meilisearch.sdk.TaskError;
import com.meilisearch.sdk.exceptions.APIError;
import com.meilisearch.sdk.exceptions.MeilisearchApiException;
import com.meilisearch.sdk.exceptions.MeilisearchCommunicationException;
import com.meilisearch.sdk.model.TaskError;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -60,8 +60,8 @@ public void testErrorSerializeAndGetters() {
@Test
public void testTaskErrorGetters() {
TaskError error = new TaskError();
error.setTaskErrorCode("wrong field");
assertThat(error.getTaskErrorCode(), is(equalTo("wrong field")));
error.setCode("wrong field");
assertThat(error.getCode(), is(equalTo("wrong field")));
}

/** Test MeilisearchApiException is thrown on Meilisearch bad request */
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/com/meilisearch/integration/TasksTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.meilisearch.integration;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.blankOrNullString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -88,6 +90,48 @@ public void testClientGetTasksLimit() throws Exception {
assertThat(result.getResults().length, is(notNullValue()));
}

/** Test Get Task Error Values */
@Test
public void testClientGetTaskErrorValues() throws Exception {
String indexUid = "CheckTaskErrorValues";
Index index = client.index(indexUid);

// Deleting all documents from an index that does not exist results in a task error.
TaskInfo taskInfo = index.deleteAllDocuments();
index.waitForTask(taskInfo.getTaskUid());

Task task = client.getTask(taskInfo.getTaskUid());

assertThat(task.getError(), is(notNullValue()));
assertThat(task.getError().getCode(), not(blankOrNullString()));
assertThat(task.getError().getType(), not(blankOrNullString()));
assertThat(task.getError().getLink(), not(blankOrNullString()));
assertThat(task.getError().getMessage(), not(blankOrNullString()));
}

/** Test Get Task Error Values When Adding Documents */
@Test
public void testClientGetTaskErrorWhenAddingDocuments() throws Exception {
String indexUid = "CheckTaskErrorWhenAddingDocuments";
Index index = client.index(indexUid);

TaskInfo taskInfo = client.createIndex(indexUid);
client.waitForTask(taskInfo.getTaskUid());

String json = "{\"identifyer\": 1, \"name\": \"Donald Duck\"}";
// Adding a document with a wrong identifier results in a task error.
TaskInfo taskInfoAddDocuments = index.addDocuments(json, "identifier");
client.waitForTask(taskInfoAddDocuments.getTaskUid());

Task task = client.getTask(taskInfoAddDocuments.getTaskUid());

assertThat(task.getError(), is(notNullValue()));
assertThat(task.getError().getCode(), not(blankOrNullString()));
assertThat(task.getError().getType(), not(blankOrNullString()));
assertThat(task.getError().getLink(), not(blankOrNullString()));
assertThat(task.getError().getMessage(), not(blankOrNullString()));
}

/** Test Get Tasks with limit and from */
@Test
public void testClientGetTasksLimitAndFrom() throws Exception {
Expand Down

0 comments on commit 45c2d88

Please sign in to comment.