|
1 | 1 | package com.meilisearch.integration;
|
2 | 2 |
|
3 | 3 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 4 | +import static org.hamcrest.Matchers.blankOrNullString; |
4 | 5 | import static org.hamcrest.Matchers.equalTo;
|
5 | 6 | import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
6 | 7 | import static org.hamcrest.Matchers.instanceOf;
|
7 | 8 | import static org.hamcrest.Matchers.is;
|
| 9 | +import static org.hamcrest.Matchers.not; |
8 | 10 | import static org.hamcrest.Matchers.notNullValue;
|
9 | 11 | import static org.hamcrest.Matchers.nullValue;
|
10 | 12 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
@@ -88,6 +90,48 @@ public void testClientGetTasksLimit() throws Exception {
|
88 | 90 | assertThat(result.getResults().length, is(notNullValue()));
|
89 | 91 | }
|
90 | 92 |
|
| 93 | + /** Test Get Task Error Values */ |
| 94 | + @Test |
| 95 | + public void testClientGetTaskErrorValues() throws Exception { |
| 96 | + String indexUid = "CheckTaskErrorValues"; |
| 97 | + Index index = client.index(indexUid); |
| 98 | + |
| 99 | + // Deleting all documents from an index that does not exist results in a task error. |
| 100 | + TaskInfo taskInfo = index.deleteAllDocuments(); |
| 101 | + index.waitForTask(taskInfo.getTaskUid()); |
| 102 | + |
| 103 | + Task task = client.getTask(taskInfo.getTaskUid()); |
| 104 | + |
| 105 | + assertThat(task.getError(), is(notNullValue())); |
| 106 | + assertThat(task.getError().getCode(), not(blankOrNullString())); |
| 107 | + assertThat(task.getError().getType(), not(blankOrNullString())); |
| 108 | + assertThat(task.getError().getLink(), not(blankOrNullString())); |
| 109 | + assertThat(task.getError().getMessage(), not(blankOrNullString())); |
| 110 | + } |
| 111 | + |
| 112 | + /** Test Get Task Error Values When Adding Documents */ |
| 113 | + @Test |
| 114 | + public void testClientGetTaskErrorWhenAddingDocuments() throws Exception { |
| 115 | + String indexUid = "CheckTaskErrorWhenAddingDocuments"; |
| 116 | + Index index = client.index(indexUid); |
| 117 | + |
| 118 | + TaskInfo taskInfo = client.createIndex(indexUid); |
| 119 | + client.waitForTask(taskInfo.getTaskUid()); |
| 120 | + |
| 121 | + String json = "{\"identifyer\": 1, \"name\": \"Donald Duck\"}"; |
| 122 | + // Adding a document with a wrong identifier results in a task error. |
| 123 | + TaskInfo taskInfoAddDocuments = index.addDocuments(json, "identifier"); |
| 124 | + client.waitForTask(taskInfoAddDocuments.getTaskUid()); |
| 125 | + |
| 126 | + Task task = client.getTask(taskInfoAddDocuments.getTaskUid()); |
| 127 | + |
| 128 | + assertThat(task.getError(), is(notNullValue())); |
| 129 | + assertThat(task.getError().getCode(), not(blankOrNullString())); |
| 130 | + assertThat(task.getError().getType(), not(blankOrNullString())); |
| 131 | + assertThat(task.getError().getLink(), not(blankOrNullString())); |
| 132 | + assertThat(task.getError().getMessage(), not(blankOrNullString())); |
| 133 | + } |
| 134 | + |
91 | 135 | /** Test Get Tasks with limit and from */
|
92 | 136 | @Test
|
93 | 137 | public void testClientGetTasksLimitAndFrom() throws Exception {
|
|
0 commit comments