Skip to content

Commit 84a0cc1

Browse files
author
a-brandt
committed
added tests for createRawDocuments
1 parent 7328852 commit 84a0cc1

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.List;
3131

3232
import org.junit.After;
33+
import org.junit.Assert;
3334
import org.junit.Before;
3435
import org.junit.Test;
3536
import org.slf4j.Logger;
@@ -618,7 +619,7 @@ public void test_delete_doc_not_found() throws ArangoException {
618619
driver.deleteDocument(collectionName, 1);
619620
fail();
620621
} catch (ArangoException e) {
621-
assertThat(e.getCode(), is(404));
622+
assertThat(e.getCode(), is(ErrorNums.ERROR_HTTP_NOT_FOUND));
622623
}
623624
}
624625

@@ -643,4 +644,57 @@ public void test_BaseDocumentProperties() throws ArangoException {
643644
assertThat((Double) myObject2.getProperties().get("b"), is(42.0));
644645
assertThat(myObject2.getProperties().get("c"), is(nullValue()));
645646
}
647+
648+
@Test
649+
public void createRawDocument() throws ArangoException {
650+
String jsonString = "{\"test\":123}";
651+
logger.debug("jsonString before: " + jsonString);
652+
DocumentEntity<String> entity = driver.createDocumentRaw(collectionName, jsonString, true, false);
653+
Assert.assertNotNull(entity);
654+
Assert.assertNotNull(entity.getDocumentHandle());
655+
Assert.assertNotNull(entity.getDocumentKey());
656+
Assert.assertNotNull(entity.getDocumentRevision());
657+
String documentHandle = entity.getDocumentHandle();
658+
659+
String str = driver.getDocumentRaw(documentHandle, null, null);
660+
Assert.assertNotNull(str);
661+
Assert.assertTrue(str.contains("\"test\":123"));
662+
// this string has "_id", "_key" and "_rev" attributes:
663+
logger.debug("jsonString after: " + str);
664+
}
665+
666+
@Test
667+
public void createRawDocumentWithKey() throws ArangoException {
668+
String key = "key1";
669+
String jsonString = "{\"_key\":\"" + key + "\",\"test\":123}";
670+
logger.debug("jsonString before: " + jsonString);
671+
DocumentEntity<String> entity = driver.createDocumentRaw(collectionName, jsonString, true, false);
672+
Assert.assertNotNull(entity);
673+
Assert.assertNotNull(entity.getDocumentHandle());
674+
Assert.assertNotNull(entity.getDocumentKey());
675+
Assert.assertNotNull(entity.getDocumentRevision());
676+
Assert.assertEquals(collectionName + "/" + key, entity.getDocumentHandle());
677+
Assert.assertEquals(key, entity.getDocumentKey());
678+
String documentHandle = entity.getDocumentHandle();
679+
680+
String str = driver.getDocumentRaw(documentHandle, null, null);
681+
Assert.assertNotNull(str);
682+
Assert.assertTrue(str.contains("\"test\":123"));
683+
Assert.assertTrue(str.contains("\"_key\":\"" + key + "\""));
684+
Assert.assertTrue(str.contains("\"_id\":\"" + collectionName + "/" + key + "\""));
685+
logger.debug("jsonString after: " + str);
686+
}
687+
688+
@Test
689+
public void createRawDocumentFails() throws ArangoException {
690+
try {
691+
String jsonString = "no JSON";
692+
driver.createDocumentRaw(collectionName, jsonString, true, false);
693+
fail();
694+
} catch (ArangoException e) {
695+
Assert.assertEquals(ErrorNums.ERROR_HTTP_BAD_PARAMETER, e.getCode());
696+
Assert.assertEquals(ErrorNums.ERROR_HTTP_CORRUPTED_JSON, e.getErrorNumber());
697+
}
698+
}
699+
646700
}

0 commit comments

Comments
 (0)