Skip to content

Commit 0ad84fa

Browse files
author
a-brandt
committed
added tests for readRawDocuments
1 parent 84a0cc1 commit 0ad84fa

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5795,6 +5795,8 @@ public DocumentEntity<String> createDocumentRaw(
57955795
* *ifNoneMatchRevision* and *ifMatchRevision* can not be used at the same
57965796
* time, one of these two has to be null.
57975797
*
5798+
* Throws ArangoException if the requested document is not available.
5799+
*
57985800
* @param documentHandle
57995801
* The document handle
58005802
* @param ifNoneMatchRevision

src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@ public String getDocumentRaw(String database, String documentHandle, Long ifNone
223223
new MapBuilder().put("If-None-Match", ifNoneMatchRevision, true).put("If-Match", ifMatchRevision).get(),
224224
null);
225225

226+
if (res.getStatusCode() >= 400) {
227+
BaseDocument entity = new BaseDocument();
228+
entity.setError(true);
229+
entity.setCode(res.getStatusCode());
230+
entity.setStatusCode(res.getStatusCode());
231+
entity.setErrorNumber(res.getStatusCode());
232+
entity.setErrorMessage(res.getText());
233+
throw new ArangoException(entity);
234+
}
235+
226236
return res.getText();
227237
}
228238

src/test/java/com/arangodb/ArangoDriverDocumentTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,4 +697,14 @@ public void createRawDocumentFails() throws ArangoException {
697697
}
698698
}
699699

700+
@Test
701+
public void getRawDocumentFails() throws ArangoException {
702+
try {
703+
driver.getDocumentRaw(collectionName + "/notfound", null, null);
704+
fail();
705+
} catch (ArangoException e) {
706+
Assert.assertEquals(ErrorNums.ERROR_HTTP_NOT_FOUND, e.getCode());
707+
Assert.assertEquals(ErrorNums.ERROR_HTTP_NOT_FOUND, e.getErrorNumber());
708+
}
709+
}
700710
}

src/test/java/com/arangodb/example/document/RawDocumentExample.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.arangodb.ArangoDriver;
2929
import com.arangodb.ArangoException;
3030
import com.arangodb.CursorRawResult;
31+
import com.arangodb.ErrorNums;
3132
import com.arangodb.entity.DocumentEntity;
3233

3334
public class RawDocumentExample extends BaseExample {
@@ -114,6 +115,17 @@ public void ReadDocuments() {
114115
Assert.fail("Failed to read document. " + e.getMessage());
115116
}
116117

118+
//
119+
printHeadline("read wrong document");
120+
//
121+
122+
try {
123+
arangoDriver.getDocumentRaw(COLLECTION_NAME + "/unknown", null, null);
124+
Assert.fail("This should fail");
125+
} catch (ArangoException e) {
126+
Assert.assertEquals(ErrorNums.ERROR_HTTP_NOT_FOUND, e.getCode());
127+
}
128+
117129
//
118130
printHeadline("using org.json.JSONML to save a xml file");
119131
//

0 commit comments

Comments
 (0)