|
| 1 | +package com.arangodb; |
| 2 | + |
| 3 | +import static org.hamcrest.CoreMatchers.is; |
| 4 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 5 | +import static org.hamcrest.CoreMatchers.nullValue; |
| 6 | +import static org.junit.Assert.assertThat; |
| 7 | +import static org.junit.Assert.fail; |
| 8 | + |
| 9 | +import java.util.Map; |
| 10 | + |
| 11 | +import org.junit.Test; |
| 12 | + |
| 13 | +import com.arangodb.entity.DocumentEntity; |
| 14 | +import com.arangodb.entity.EdgeEntity; |
| 15 | +import com.arangodb.entity.GraphEntity; |
| 16 | + |
| 17 | +public class ArangoDriverBatchGraphTest extends BaseGraphTest { |
| 18 | + |
| 19 | + private final String graphName = "ArangoDriverBatchGraphTest"; |
| 20 | + private final String edgeCollectionName = "edge-1"; |
| 21 | + |
| 22 | + @Test |
| 23 | + public void createGraph() throws ArangoException { |
| 24 | + driver.startBatchMode(); |
| 25 | + final GraphEntity tmpResult = driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), |
| 26 | + this.createOrphanCollections(2), true); |
| 27 | + assertThat(tmpResult, is(notNullValue())); |
| 28 | + assertThat(tmpResult.getRequestId(), is(notNullValue())); |
| 29 | + |
| 30 | + driver.executeBatch(); |
| 31 | + |
| 32 | + final GraphEntity createGraph = driver.getBatchResponseByRequestId(tmpResult.getRequestId()); |
| 33 | + assertThat(createGraph, is(notNullValue())); |
| 34 | + assertThat(createGraph.getName(), is(this.graphName)); |
| 35 | + assertThat(createGraph.getRequestId(), is(nullValue())); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void createGraphVertex() throws ArangoException { |
| 40 | + driver.startBatchMode(); |
| 41 | + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); |
| 42 | + |
| 43 | + final DocumentEntity<TestComplexEntity03> v1 = driver.graphCreateVertex(this.graphName, "from1-1", |
| 44 | + new TestComplexEntity03("v1-user", "desc1", 10), null); |
| 45 | + assertThat(v1, is(notNullValue())); |
| 46 | + assertThat(v1.getRequestId(), is(notNullValue())); |
| 47 | + |
| 48 | + final DocumentEntity<TestComplexEntity03> v2 = driver.graphCreateVertex(this.graphName, "to1-1", |
| 49 | + new TestComplexEntity03("v2-user", "desc2", 12), null); |
| 50 | + assertThat(v2, is(notNullValue())); |
| 51 | + assertThat(v2.getRequestId(), is(notNullValue())); |
| 52 | + |
| 53 | + driver.executeBatch(); |
| 54 | + |
| 55 | + final DocumentEntity<TestComplexEntity03> v3 = driver.getBatchResponseByRequestId(v1.getRequestId()); |
| 56 | + assertThat(v3, is(notNullValue())); |
| 57 | + assertThat(v3.getDocumentKey(), is(notNullValue())); |
| 58 | + assertThat(v3.getRequestId(), is(nullValue())); |
| 59 | + |
| 60 | + final DocumentEntity<TestComplexEntity03> v4 = driver.getBatchResponseByRequestId(v2.getRequestId()); |
| 61 | + assertThat(v4, is(notNullValue())); |
| 62 | + assertThat(v4.getDocumentKey(), is(notNullValue())); |
| 63 | + assertThat(v4.getRequestId(), is(nullValue())); |
| 64 | + } |
| 65 | + |
| 66 | + @SuppressWarnings("rawtypes") |
| 67 | + @Test |
| 68 | + public void createGraphEdge() throws ArangoException { |
| 69 | + |
| 70 | + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); |
| 71 | + |
| 72 | + final DocumentEntity<TestComplexEntity03> v1 = driver.graphCreateVertex(this.graphName, "from1-1", |
| 73 | + new TestComplexEntity03("v1-user", "desc1", 10), null); |
| 74 | + |
| 75 | + final DocumentEntity<TestComplexEntity03> v2 = driver.graphCreateVertex(this.graphName, "to1-1", |
| 76 | + new TestComplexEntity03("v2-user", "desc2", 12), null); |
| 77 | + |
| 78 | + driver.startBatchMode(); |
| 79 | + |
| 80 | + driver.graphCreateEdge(this.graphName, edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), |
| 81 | + null, null); |
| 82 | + |
| 83 | + driver.graphCreateEdge(this.graphName, edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), |
| 84 | + null, null); |
| 85 | + |
| 86 | + final EdgeEntity<?> e1 = driver.graphCreateEdge(this.graphName, edgeCollectionName, null, |
| 87 | + v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); |
| 88 | + assertThat(e1, is(notNullValue())); |
| 89 | + assertThat(e1.getRequestId(), is(notNullValue())); |
| 90 | + |
| 91 | + driver.executeBatch(); |
| 92 | + |
| 93 | + final EdgeEntity<?> e2 = driver.getBatchResponseByRequestId(e1.getRequestId()); |
| 94 | + assertThat(e2, is(notNullValue())); |
| 95 | + assertThat(e2.getDocumentKey(), is(notNullValue())); |
| 96 | + assertThat(e2.getRequestId(), is(nullValue())); |
| 97 | + |
| 98 | + EdgeEntity<Map> graphGetEdge = driver.graphGetEdge(graphName, edgeCollectionName, e2.getDocumentKey(), |
| 99 | + Map.class, null, null); |
| 100 | + assertThat(graphGetEdge, is(notNullValue())); |
| 101 | + assertThat(graphGetEdge.getDocumentKey(), is(e2.getDocumentKey())); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + public void createGraphEdgeFail() throws ArangoException { |
| 106 | + |
| 107 | + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); |
| 108 | + |
| 109 | + driver.startBatchMode(); |
| 110 | + |
| 111 | + final DocumentEntity<TestComplexEntity03> v1 = driver.graphCreateVertex(this.graphName, "from1-1", |
| 112 | + new TestComplexEntity03("v1-user", "desc1", 10), null); |
| 113 | + |
| 114 | + final DocumentEntity<TestComplexEntity03> v2 = driver.graphCreateVertex(this.graphName, "to1-1", |
| 115 | + new TestComplexEntity03("v2-user", "desc2", 12), null); |
| 116 | + |
| 117 | + final EdgeEntity<?> e1 = driver.graphCreateEdge(this.graphName, edgeCollectionName, null, |
| 118 | + v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); |
| 119 | + assertThat(e1, is(notNullValue())); |
| 120 | + assertThat(e1.getRequestId(), is(notNullValue())); |
| 121 | + |
| 122 | + driver.executeBatch(); |
| 123 | + |
| 124 | + EdgeEntity<?> e2 = null; |
| 125 | + try { |
| 126 | + e2 = driver.getBatchResponseByRequestId(e1.getRequestId()); |
| 127 | + fail("this should fail"); |
| 128 | + } catch (Exception ex) { |
| 129 | + } |
| 130 | + assertThat(e2, is(nullValue())); |
| 131 | + |
| 132 | + } |
| 133 | + |
| 134 | +} |
0 commit comments