From 0fc9081ff1bf60f5640e951fcdbe1626b5db2d89 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 15 Apr 2016 13:02:31 +0200 Subject: [PATCH 01/56] startet 2.7.5-SNAPSHOT --- ChangeLog | 4 ++++ pom.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a90ded03d..3a90a053e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +v2.7.5 (2016-XX-XX) +--------------------------- + + v2.7.4 (2016-04-15) --------------------------- * fixed issue #35 (There is no replaceDocumentRaw similar to createDocumentRaw) diff --git a/pom.xml b/pom.xml index 5b173d333..517b9b37e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-java-driver - 2.7.4 + 2.7.5-SNAPSHOT 2012 jar From 57a873ce67318d6230e77cfa1dab29f576b2734f Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 20 May 2016 10:02:55 +0200 Subject: [PATCH 02/56] first version of 3.0 --- ChangeLog | 5 +- README.md | 29 +- src/main/java/com/arangodb/ArangoDriver.java | 194 ++----- src/main/java/com/arangodb/ErrorNums.java | 534 +++++++++--------- .../java/com/arangodb/InternalEdgeDriver.java | 39 -- .../com/arangodb/InternalGraphDriver.java | 8 + .../com/arangodb/InternalIndexDriver.java | 26 +- .../com/arangodb/InternalSimpleDriver.java | 6 - .../arangodb/entity/EntityDeserializers.java | 15 +- .../java/com/arangodb/entity/IndexType.java | 7 +- .../java/com/arangodb/http/HttpManager.java | 24 +- .../com/arangodb/impl/AnnotationHandler.java | 16 +- .../java/com/arangodb/impl/ImplFactory.java | 7 - .../impl/InternalDocumentDriverImpl.java | 31 +- .../arangodb/impl/InternalEdgeDriverImpl.java | 62 -- .../impl/InternalGraphDriverImpl.java | 77 ++- .../impl/InternalIndexDriverImpl.java | 28 - .../impl/InternalSimpleDriverImpl.java | 35 -- .../com/arangodb/ArangoDriverAsyncTest.java | 4 + .../com/arangodb/ArangoDriverBatchTest.java | 6 + .../arangodb/ArangoDriverDocumentKeyTest.java | 4 + .../arangodb/ArangoDriverDocumentTest.java | 5 + .../com/arangodb/ArangoDriverEdgeTest.java | 83 --- .../ArangoDriverGraphEdgeReplaceTest.java | 58 +- .../ArangoDriverGraphEdgeUpdateTest.java | 457 +++++++-------- .../com/arangodb/ArangoDriverIndexTest.java | 61 +- .../com/arangodb/ArangoDriverSimpleTest.java | 169 ------ .../arangodb/ArangoDriverTransactionTest.java | 10 + .../java/com/arangodb/BaseDocumentTest.java | 2 +- src/test/java/com/arangodb/NegativeTest.java | 13 +- .../com/arangodb/PrimitiveDocumentTest.java | 10 + 31 files changed, 805 insertions(+), 1220 deletions(-) delete mode 100644 src/main/java/com/arangodb/InternalEdgeDriver.java delete mode 100644 src/main/java/com/arangodb/impl/InternalEdgeDriverImpl.java delete mode 100644 src/test/java/com/arangodb/ArangoDriverEdgeTest.java diff --git a/ChangeLog b/ChangeLog index 3a90a053e..67d67e90f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ -v2.7.5 (2016-XX-XX) +v3.0.0 (2016-XX-XX) --------------------------- - +* removed ArangoDriver.EdgeEntity() (/_api/edge withdrawn in Server) +* removed CAP-Index (Cap-constraints are withdrawn in Server) v2.7.4 (2016-04-15) --------------------------- diff --git a/README.md b/README.md index 66682a48a..59adaeb45 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,13 @@ This library is a Java driver for ArangoDB. -Supported version: ArangoDB 2.7.x and ArangoDB 2.8.x +Supported version: ArangoDB 3.0.X + +(Use ```arangodb-java-driver 2.7.4``` for ArangoDB 2.7.x and ArangoDB 2.8.x) # Required -* [ArangoDB](https://github.com/arangodb/arangodb) version 2.7.x or 2.8.x +* [ArangoDB](https://github.com/arangodb/arangodb) version 3.0.X * Java 1.6 later # Basics @@ -21,18 +23,31 @@ Supported version: ArangoDB 2.7.x and ArangoDB 2.8.x To add the driver to your project with maven, add the following code to your pom.xml (please use a driver with a version number compatible to your ArangoDB server's version): +ArangoDB 3.0.X +```XML + + + com.arangodb + arangodb-java-driver + 3.0.0 + + .... + +``` + +ArangoDB 2.7.x and ArangoDB 2.8.x: ```XML com.arangodb arangodb-java-driver - 2.7.4 + 3.0.0 .... ``` -If you want to test with a snapshot version (e.g. 2.7.5-SNAPSHOT), add the staging repository of oss.sonatype.org to your pom.xml: +If you want to test with a snapshot version (e.g. 3.0.0-SNAPSHOT), add the staging repository of oss.sonatype.org to your pom.xml: ```XML @@ -77,12 +92,6 @@ The driver is configured with some default values: defaultDatabasedefault database enableCURLLoggerlogging flag by curl format for debugfalse useSsluse HTTPS connectionfalse - - - -Since 2.5.4 you can configure a default and a fallback database: - - diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 524c3926e..704dd47f4 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -38,7 +38,6 @@ import com.arangodb.entity.DefaultEntity; import com.arangodb.entity.DeletedEntity; import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.DocumentResultEntity; import com.arangodb.entity.EdgeDefinitionEntity; import com.arangodb.entity.EdgeEntity; import com.arangodb.entity.Endpoint; @@ -123,7 +122,6 @@ public class ArangoDriver extends BaseArangoDriver { private InternalEndpointDriver endpointDriver; private InternalReplicationDriver replicationDriver; private InternalGraphDriver graphDriver; - private InternalEdgeDriver edgeDriver; private InternalTransactionDriver transactionDriver; private InternalTraversalDriver traversalDriver; private InternalQueryCacheDriver queryCacheDriver; @@ -2606,62 +2604,6 @@ public IndexEntity createSkipListIndex(String collectionName, boolean unique, bo fields); } - /** - * This method creates a capped index for a collection. - * - * @param collectionId - * The collection id. - * @param size - * the maximum amount of documents - * @return IndexEntity - * @throws ArangoException - */ - public IndexEntity createCappedIndex(long collectionId, int size) throws ArangoException { - return createCappedIndex(String.valueOf(collectionId), size); - } - - /** - * This method creates a capped index for a collection. - * - * @param collectionName - * The collection name. - * @param size - * the maximum amount of documents - * @return IndexEntity - * @throws ArangoException - */ - public IndexEntity createCappedIndex(String collectionName, int size) throws ArangoException { - return indexDriver.createCappedIndex(getDefaultDatabase(), collectionName, size); - } - - /** - * This method creates a capped index for a collection. - * - * @param collectionId - * The collection id. - * @param byteSize - * the maximum size of the document data in bytes - * @return IndexEntity - * @throws ArangoException - */ - public IndexEntity createCappedByDocumentSizeIndex(long collectionId, int byteSize) throws ArangoException { - return createCappedByDocumentSizeIndex(String.valueOf(collectionId), byteSize); - } - - /** - * This method creates a capped index for a collection. - * - * @param collectionName - * The collection name. - * @param byteSize - * the maximum size of the document data in bytes - * @return IndexEntity - * @throws ArangoException - */ - public IndexEntity createCappedByDocumentSizeIndex(String collectionName, int byteSize) throws ArangoException { - return indexDriver.createCappedByDocumentSizeIndex(getDefaultDatabase(), collectionName, byteSize); - } - /** * This method creates a full text index for a collection. * @@ -3663,46 +3605,6 @@ public SimpleByResultEntity executeSimpleUpdateByExample( keepNull, waitForSync, limit); } - /** - * This will return the first document(s) from the collection, in the order - * of insertion/update time. - * - * @param collectionName - * The collection name. - * @param count - * the number of documents to return at most. Specifiying count - * is optional. If it is not specified, it defaults to 1. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return DocumentResultEntity - * @throws ArangoException - */ - public DocumentResultEntity executeSimpleFirst(String collectionName, Integer count, Class clazz) - throws ArangoException { - return simpleDriver.executeSimpleFirst(getDefaultDatabase(), collectionName, count, clazz); - } - - /** - * This will return the last document(s) from the collection, in the order - * of insertion/update time. - * - * @param collectionName - * The collection name. - * @param count - * the number of documents to return at most. Specifiying count - * is optional. If it is not specified, it defaults to 1. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return DocumentResultEntity - * @throws ArangoException - */ - public DocumentResultEntity executeSimpleLast(String collectionName, Integer count, Class clazz) - throws ArangoException { - return simpleDriver.executeSimpleLast(getDefaultDatabase(), collectionName, count, clazz); - } - /** * Creates a database user. * @@ -4818,8 +4720,7 @@ public EdgeEntity graphCreateEdge( } /** - * Stores a new edge with the information contained within the body into the - * given collection. + * Stores a new edge with no further information into the given collection. * * @param graphName * The name of the graph. @@ -4972,15 +4873,26 @@ public DeletedEntity graphDeleteEdge( * The name of the collection containing edge to replace. * @param key * The key of the edge to replace. + * @param fromHandle + * Document handle of vertex, where the edge comes from. (can be + * null if value contains "_from" attribute) + * @param toHandle + * Document handle of vertex, where the edge goes to. (can be + * null if value contains "_to" attribute) * @param value * The object to replace the existing edge. * @return a EdgeEntity object * @throws ArangoException */ - public EdgeEntity graphReplaceEdge(String graphName, String edgeCollectionName, String key, T value) - throws ArangoException { - return graphDriver.replaceEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, value, null, null, - null); + public EdgeEntity graphReplaceEdge( + String graphName, + String edgeCollectionName, + String key, + String fromHandle, + String toHandle, + T value) throws ArangoException { + return graphDriver.replaceEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, + value, null, null, null); } /** @@ -4993,8 +4905,15 @@ public EdgeEntity graphReplaceEdge(String graphName, String edgeCollectio * The name of the collection containing edge to replace. * @param key * The key of the edge to replace. + * @param fromHandle + * Document handle of vertex, where the edge comes from. (can be + * null if value contains "_from" attribute) + * @param toHandle + * Document handle of vertex, where the edge goes to. (can be + * null if value contains "_to" attribute) * @param value - * The object to replace the existing edge. + * The object to replace the existing edge. Since ArangoDB 3.X + * the replacement should contain "_from" and "_to". * @param waitForSync * Wait for sync. * @param ifMatchRevision @@ -5010,12 +4929,14 @@ public EdgeEntity graphReplaceEdge( String graphName, String edgeCollectionName, String key, + String fromHandle, + String toHandle, T value, Boolean waitForSync, Long ifMatchRevision, Long ifNoneMatchRevision) throws ArangoException { - return graphDriver.replaceEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, value, waitForSync, - ifMatchRevision, ifNoneMatchRevision); + return graphDriver.replaceEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, + value, waitForSync, ifMatchRevision, ifNoneMatchRevision); } /** @@ -5029,6 +4950,12 @@ public EdgeEntity graphReplaceEdge( * The name of the collection containing edge to update. * @param key * The key of the edge to update. + * @param fromHandle + * Document handle of vertex, where the edge comes from. (can be + * null if value contains "_from" attribute) + * @param toHandle + * Document handle of vertex, where the edge goes to. (can be + * null if value contains "_to" attribute) * @param value * The object to update the existing edge. * @param keepNull @@ -5039,10 +4966,12 @@ public EdgeEntity graphUpdateEdge( String graphName, String edgeCollectionName, String key, + String fromHandle, + String toHandle, T value, Boolean keepNull) throws ArangoException { - return graphDriver.updateEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, value, null, keepNull, - null, null); + return graphDriver.updateEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, + value, null, keepNull, null, null); } /** @@ -5058,6 +4987,12 @@ public EdgeEntity graphUpdateEdge( * The key of the edge to update. * @param value * The object to update the existing edge. + * @param fromHandle + * Document handle of vertex, where the edge comes from. (can be + * null if value contains "_from" attribute) + * @param toHandle + * Document handle of vertex, where the edge goes to. (can be + * null if value contains "_to" attribute) * @param waitForSync * Wait for sync. * @param keepNull @@ -5074,13 +5009,15 @@ public EdgeEntity graphUpdateEdge( String graphName, String edgeCollectionName, String key, + String fromHandle, + String toHandle, T value, Boolean waitForSync, Boolean keepNull, Long ifMatchRevision, Long ifNoneMatchRevision) throws ArangoException { - return graphDriver.updateEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, value, waitForSync, - keepNull, ifMatchRevision, ifNoneMatchRevision); + return graphDriver.updateEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, + value, waitForSync, keepNull, ifMatchRevision, ifNoneMatchRevision); } // Some methods not using the graph api @@ -5419,40 +5356,10 @@ public TransactionResultEntity executeTransaction(TransactionEntity transactionE return this.transactionDriver.executeTransaction(getDefaultDatabase(), transactionEntity); } - /** - * Create an edge in an edge collection. - * - * @param collectionName - * name of the edge collection - * @param object - * the edge object - * @param from - * id of document 'from' - * @param to - * id of document 'to' - * @param createCollection - * if true, the collection will be created if it does not exists - * @param waitForSync - * wait for sync - * @return the new created EdgeEntity object - * @throws ArangoException - */ - public EdgeEntity createEdge( - String collectionName, - T object, - String from, - String to, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - - return this.edgeDriver.createEdge(getDefaultDatabase(), collectionName, object, from, to, createCollection, - waitForSync); - } - /** * Do a graph traversal. * - * See API documatation of Traversals + * See API documentation of Traversals * * @param traversalQueryOptions * the traversal options @@ -5783,7 +5690,6 @@ private void createModuleDrivers(boolean createProxys) { this.endpointDriver = ImplFactory.createEndpointDriver(configure, this.httpManager); this.replicationDriver = ImplFactory.createReplicationDriver(configure, this.httpManager); this.graphDriver = ImplFactory.createGraphDriver(configure, cursorDriver, this.httpManager); - this.edgeDriver = ImplFactory.createEdgeDriver(configure, cursorDriver, this.httpManager); this.jobsDriver = ImplFactory.createJobsDriver(configure, this.httpManager); this.transactionDriver = ImplFactory.createTransactionDriver(configure, this.httpManager); this.traversalDriver = ImplFactory.createTraversalDriver(configure, httpManager); @@ -5829,8 +5735,6 @@ private void createModuleDrivers(boolean createProxys) { new InvocationHandlerImpl(this.replicationDriver)); this.graphDriver = (InternalGraphDriver) Proxy.newProxyInstance(InternalGraphDriver.class.getClassLoader(), new Class[] { InternalGraphDriver.class }, new InvocationHandlerImpl(this.graphDriver)); - this.edgeDriver = (InternalEdgeDriver) Proxy.newProxyInstance(InternalEdgeDriver.class.getClassLoader(), - new Class[] { InternalEdgeDriver.class }, new InvocationHandlerImpl(this.edgeDriver)); this.traversalDriver = (InternalTraversalDriver) Proxy.newProxyInstance( InternalTraversalDriver.class.getClassLoader(), new Class[] { InternalTraversalDriver.class }, new InvocationHandlerImpl(this.traversalDriver)); diff --git a/src/main/java/com/arangodb/ErrorNums.java b/src/main/java/com/arangodb/ErrorNums.java index b97bae66b..e95a3fd4b 100644 --- a/src/main/java/com/arangodb/ErrorNums.java +++ b/src/main/java/com/arangodb/ErrorNums.java @@ -2,281 +2,263 @@ public class ErrorNums { - public static final int ERROR_NO_ERROR = 0; - public static final int ERROR_FAILED = 1; - public static final int ERROR_SYS_ERROR = 2; - public static final int ERROR_OUT_OF_MEMORY = 3; - public static final int ERROR_INTERNAL = 4; - public static final int ERROR_ILLEGAL_NUMBER = 5; - public static final int ERROR_NUMERIC_OVERFLOW = 6; - public static final int ERROR_ILLEGAL_OPTION = 7; - public static final int ERROR_DEAD_PID = 8; - public static final int ERROR_NOT_IMPLEMENTED = 9; - public static final int ERROR_BAD_PARAMETER = 10; - public static final int ERROR_FORBIDDEN = 11; - public static final int ERROR_OUT_OF_MEMORY_MMAP = 12; - public static final int ERROR_CORRUPTED_CSV = 13; - public static final int ERROR_FILE_NOT_FOUND = 14; - public static final int ERROR_CANNOT_WRITE_FILE = 15; - public static final int ERROR_CANNOT_OVERWRITE_FILE = 16; - public static final int ERROR_TYPE_ERROR = 17; - public static final int ERROR_LOCK_TIMEOUT = 18; - public static final int ERROR_CANNOT_CREATE_DIRECTORY = 19; - public static final int ERROR_CANNOT_CREATE_TEMP_FILE = 20; - public static final int ERROR_REQUEST_CANCELED = 21; - public static final int ERROR_DEBUG = 22; - public static final int ERROR_AID_NOT_FOUND = 23; - public static final int ERROR_LEGEND_INCOMPLETE = 24; - public static final int ERROR_IP_ADDRESS_INVALID = 25; - public static final int ERROR_LEGEND_NOT_IN_WAL_FILE = 26; - public static final int ERROR_FILE_EXISTS = 27; - public static final int ERROR_LOCKED = 28; - public static final int ERROR_HTTP_BAD_PARAMETER = 400; - public static final int ERROR_HTTP_UNAUTHORIZED = 401; - public static final int ERROR_HTTP_FORBIDDEN = 403; - public static final int ERROR_HTTP_NOT_FOUND = 404; - public static final int ERROR_HTTP_METHOD_NOT_ALLOWED = 405; - public static final int ERROR_HTTP_PRECONDITION_FAILED = 412; - public static final int ERROR_HTTP_SERVER_ERROR = 500; - public static final int ERROR_HTTP_CORRUPTED_JSON = 600; - public static final int ERROR_HTTP_SUPERFLUOUS_SUFFICES = 601; - public static final int ERROR_ARANGO_ILLEGAL_STATE = 1000; - public static final int ERROR_ARANGO_SHAPER_FAILED = 1001; - public static final int ERROR_ARANGO_DATAFILE_SEALED = 1002; - public static final int ERROR_ARANGO_UNKNOWN_COLLECTION_TYPE = 1003; - public static final int ERROR_ARANGO_READ_ONLY = 1004; - public static final int ERROR_ARANGO_DUPLICATE_IDENTIFIER = 1005; - public static final int ERROR_ARANGO_DATAFILE_UNREADABLE = 1006; - public static final int ERROR_ARANGO_DATAFILE_EMPTY = 1007; - public static final int ERROR_ARANGO_RECOVERY = 1008; - public static final int ERROR_ARANGO_CORRUPTED_DATAFILE = 1100; - public static final int ERROR_ARANGO_ILLEGAL_PARAMETER_FILE = 1101; - public static final int ERROR_ARANGO_CORRUPTED_COLLECTION = 1102; - public static final int ERROR_ARANGO_MMAP_FAILED = 1103; - public static final int ERROR_ARANGO_FILESYSTEM_FULL = 1104; - public static final int ERROR_ARANGO_NO_JOURNAL = 1105; - public static final int ERROR_ARANGO_DATAFILE_ALREADY_EXISTS = 1106; - public static final int ERROR_ARANGO_DATADIR_LOCKED = 1107; - public static final int ERROR_ARANGO_COLLECTION_DIRECTORY_ALREADY_EXISTS = 1108; - public static final int ERROR_ARANGO_MSYNC_FAILED = 1109; - public static final int ERROR_ARANGO_DATADIR_UNLOCKABLE = 1110; - public static final int ERROR_ARANGO_SYNC_TIMEOUT = 1111; - public static final int ERROR_ARANGO_CONFLICT = 1200; - public static final int ERROR_ARANGO_DATADIR_INVALID = 1201; - public static final int ERROR_ARANGO_DOCUMENT_NOT_FOUND = 1202; - public static final int ERROR_ARANGO_COLLECTION_NOT_FOUND = 1203; - public static final int ERROR_ARANGO_COLLECTION_PARAMETER_MISSING = 1204; - public static final int ERROR_ARANGO_DOCUMENT_HANDLE_BAD = 1205; - public static final int ERROR_ARANGO_MAXIMAL_SIZE_TOO_SMALL = 1206; - public static final int ERROR_ARANGO_DUPLICATE_NAME = 1207; - public static final int ERROR_ARANGO_ILLEGAL_NAME = 1208; - public static final int ERROR_ARANGO_NO_INDEX = 1209; - public static final int ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED = 1210; - public static final int ERROR_ARANGO_INDEX_NOT_FOUND = 1212; - public static final int ERROR_ARANGO_CROSS_COLLECTION_REQUEST = 1213; - public static final int ERROR_ARANGO_INDEX_HANDLE_BAD = 1214; - public static final int ERROR_ARANGO_CAP_CONSTRAINT_ALREADY_DEFINED = 1215; - public static final int ERROR_ARANGO_DOCUMENT_TOO_LARGE = 1216; - public static final int ERROR_ARANGO_COLLECTION_NOT_UNLOADED = 1217; - public static final int ERROR_ARANGO_COLLECTION_TYPE_INVALID = 1218; - public static final int ERROR_ARANGO_VALIDATION_FAILED = 1219; - public static final int ERROR_ARANGO_PARSER_FAILED = 1220; - public static final int ERROR_ARANGO_DOCUMENT_KEY_BAD = 1221; - public static final int ERROR_ARANGO_DOCUMENT_KEY_UNEXPECTED = 1222; - public static final int ERROR_ARANGO_DATADIR_NOT_WRITABLE = 1224; - public static final int ERROR_ARANGO_OUT_OF_KEYS = 1225; - public static final int ERROR_ARANGO_DOCUMENT_KEY_MISSING = 1226; - public static final int ERROR_ARANGO_DOCUMENT_TYPE_INVALID = 1227; - public static final int ERROR_ARANGO_DATABASE_NOT_FOUND = 1228; - public static final int ERROR_ARANGO_DATABASE_NAME_INVALID = 1229; - public static final int ERROR_ARANGO_USE_SYSTEM_DATABASE = 1230; - public static final int ERROR_ARANGO_ENDPOINT_NOT_FOUND = 1231; - public static final int ERROR_ARANGO_INVALID_KEY_GENERATOR = 1232; - public static final int ERROR_ARANGO_INVALID_EDGE_ATTRIBUTE = 1233; - public static final int ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING = 1234; - public static final int ERROR_ARANGO_INDEX_CREATION_FAILED = 1235; - public static final int ERROR_ARANGO_WRITE_THROTTLE_TIMEOUT = 1236; - public static final int ERROR_ARANGO_COLLECTION_TYPE_MISMATCH = 1237; - public static final int ERROR_ARANGO_COLLECTION_NOT_LOADED = 1238; - public static final int ERROR_ARANGO_DATAFILE_FULL = 1300; - public static final int ERROR_ARANGO_EMPTY_DATADIR = 1301; - public static final int ERROR_REPLICATION_NO_RESPONSE = 1400; - public static final int ERROR_REPLICATION_INVALID_RESPONSE = 1401; - public static final int ERROR_REPLICATION_MASTER_ERROR = 1402; - public static final int ERROR_REPLICATION_MASTER_INCOMPATIBLE = 1403; - public static final int ERROR_REPLICATION_MASTER_CHANGE = 1404; - public static final int ERROR_REPLICATION_LOOP = 1405; - public static final int ERROR_REPLICATION_UNEXPECTED_MARKER = 1406; - public static final int ERROR_REPLICATION_INVALID_APPLIER_STATE = 1407; - public static final int ERROR_REPLICATION_UNEXPECTED_TRANSACTION = 1408; - public static final int ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION = 1410; - public static final int ERROR_REPLICATION_RUNNING = 1411; - public static final int ERROR_REPLICATION_APPLIER_STOPPED = 1412; - public static final int ERROR_REPLICATION_NO_START_TICK = 1413; - public static final int ERROR_REPLICATION_START_TICK_NOT_PRESENT = 1414; - public static final int ERROR_CLUSTER_NO_AGENCY = 1450; - public static final int ERROR_CLUSTER_NO_COORDINATOR_HEADER = 1451; - public static final int ERROR_CLUSTER_COULD_NOT_LOCK_PLAN = 1452; - public static final int ERROR_CLUSTER_COLLECTION_ID_EXISTS = 1453; - public static final int ERROR_CLUSTER_COULD_NOT_CREATE_COLLECTION_IN_PLAN = 1454; - public static final int ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION = 1455; - public static final int ERROR_CLUSTER_COULD_NOT_CREATE_COLLECTION = 1456; - public static final int ERROR_CLUSTER_TIMEOUT = 1457; - public static final int ERROR_CLUSTER_COULD_NOT_REMOVE_COLLECTION_IN_PLAN = 1458; - public static final int ERROR_CLUSTER_COULD_NOT_REMOVE_COLLECTION_IN_CURRENT = 1459; - public static final int ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE_IN_PLAN = 1460; - public static final int ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE = 1461; - public static final int ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_PLAN = 1462; - public static final int ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_CURRENT = 1463; - public static final int ERROR_CLUSTER_SHARD_GONE = 1464; - public static final int ERROR_CLUSTER_CONNECTION_LOST = 1465; - public static final int ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY = 1466; - public static final int ERROR_CLUSTER_GOT_CONTRADICTING_ANSWERS = 1467; - public static final int ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN = 1468; - public static final int ERROR_CLUSTER_MUST_NOT_CHANGE_SHARDING_ATTRIBUTES = 1469; - public static final int ERROR_CLUSTER_UNSUPPORTED = 1470; - public static final int ERROR_CLUSTER_ONLY_ON_COORDINATOR = 1471; - public static final int ERROR_CLUSTER_READING_PLAN_AGENCY = 1472; - public static final int ERROR_CLUSTER_COULD_NOT_TRUNCATE_COLLECTION = 1473; - public static final int ERROR_CLUSTER_AQL_COMMUNICATION = 1474; - public static final int ERROR_ARANGO_DOCUMENT_NOT_FOUND_OR_SHARDING_ATTRIBUTES_CHANGED = 1475; - public static final int ERROR_CLUSTER_COULD_NOT_DETERMINE_ID = 1476; - public static final int ERROR_QUERY_KILLED = 1500; - public static final int ERROR_QUERY_PARSE = 1501; - public static final int ERROR_QUERY_EMPTY = 1502; - public static final int ERROR_QUERY_SCRIPT = 1503; - public static final int ERROR_QUERY_NUMBER_OUT_OF_RANGE = 1504; - public static final int ERROR_QUERY_VARIABLE_NAME_INVALID = 1510; - public static final int ERROR_QUERY_VARIABLE_REDECLARED = 1511; - public static final int ERROR_QUERY_VARIABLE_NAME_UNKNOWN = 1512; - public static final int ERROR_QUERY_COLLECTION_LOCK_FAILED = 1521; - public static final int ERROR_QUERY_TOO_MANY_COLLECTIONS = 1522; - public static final int ERROR_QUERY_DOCUMENT_ATTRIBUTE_REDECLARED = 1530; - public static final int ERROR_QUERY_FUNCTION_NAME_UNKNOWN = 1540; - public static final int ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH = 1541; - public static final int ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH = 1542; - public static final int ERROR_QUERY_INVALID_REGEX = 1543; - public static final int ERROR_QUERY_BIND_PARAMETERS_INVALID = 1550; - public static final int ERROR_QUERY_BIND_PARAMETER_MISSING = 1551; - public static final int ERROR_QUERY_BIND_PARAMETER_UNDECLARED = 1552; - public static final int ERROR_QUERY_BIND_PARAMETER_TYPE = 1553; - public static final int ERROR_QUERY_INVALID_LOGICAL_VALUE = 1560; - public static final int ERROR_QUERY_INVALID_ARITHMETIC_VALUE = 1561; - public static final int ERROR_QUERY_DIVISION_BY_ZERO = 1562; - public static final int ERROR_QUERY_ARRAY_EXPECTED = 1563; - public static final int ERROR_QUERY_FAIL_CALLED = 1569; - public static final int ERROR_QUERY_GEO_INDEX_MISSING = 1570; - public static final int ERROR_QUERY_FULLTEXT_INDEX_MISSING = 1571; - public static final int ERROR_QUERY_INVALID_DATE_VALUE = 1572; - public static final int ERROR_QUERY_MULTI_MODIFY = 1573; - public static final int ERROR_QUERY_MODIFY_IN_SUBQUERY = 1574; - public static final int ERROR_QUERY_COMPILE_TIME_OPTIONS = 1575; - public static final int ERROR_QUERY_EXCEPTION_OPTIONS = 1576; - public static final int ERROR_QUERY_COLLECTION_USED_IN_EXPRESSION = 1577; - public static final int ERROR_QUERY_DISALLOWED_DYNAMIC_CALL = 1578; - public static final int ERROR_QUERY_ACCESS_AFTER_MODIFICATION = 1579; - public static final int ERROR_QUERY_FUNCTION_INVALID_NAME = 1580; - public static final int ERROR_QUERY_FUNCTION_INVALID_CODE = 1581; - public static final int ERROR_QUERY_FUNCTION_NOT_FOUND = 1582; - public static final int ERROR_QUERY_FUNCTION_RUNTIME_ERROR = 1583; - public static final int ERROR_QUERY_BAD_JSON_PLAN = 1590; - public static final int ERROR_QUERY_NOT_FOUND = 1591; - public static final int ERROR_QUERY_IN_USE = 1592; - public static final int ERROR_CURSOR_NOT_FOUND = 1600; - public static final int ERROR_CURSOR_BUSY = 1601; - public static final int ERROR_TRANSACTION_INTERNAL = 1650; - public static final int ERROR_TRANSACTION_NESTED = 1651; - public static final int ERROR_TRANSACTION_UNREGISTERED_COLLECTION = 1652; - public static final int ERROR_TRANSACTION_DISALLOWED_OPERATION = 1653; - public static final int ERROR_TRANSACTION_ABORTED = 1654; - public static final int ERROR_USER_INVALID_NAME = 1700; - public static final int ERROR_USER_INVALID_PASSWORD = 1701; - public static final int ERROR_USER_DUPLICATE = 1702; - public static final int ERROR_USER_NOT_FOUND = 1703; - public static final int ERROR_USER_CHANGE_PASSWORD = 1704; - public static final int ERROR_APPLICATION_INVALID_NAME = 1750; - public static final int ERROR_APPLICATION_INVALID_MOUNT = 1751; - public static final int ERROR_APPLICATION_DOWNLOAD_FAILED = 1752; - public static final int ERROR_APPLICATION_UPLOAD_FAILED = 1753; - public static final int ERROR_KEYVALUE_INVALID_KEY = 1800; - public static final int ERROR_KEYVALUE_KEY_EXISTS = 1801; - public static final int ERROR_KEYVALUE_KEY_NOT_FOUND = 1802; - public static final int ERROR_KEYVALUE_KEY_NOT_UNIQUE = 1803; - public static final int ERROR_KEYVALUE_KEY_NOT_CHANGED = 1804; - public static final int ERROR_KEYVALUE_KEY_NOT_REMOVED = 1805; - public static final int ERROR_KEYVALUE_NO_VALUE = 1806; - public static final int ERROR_TASK_INVALID_ID = 1850; - public static final int ERROR_TASK_DUPLICATE_ID = 1851; - public static final int ERROR_TASK_NOT_FOUND = 1852; - public static final int ERROR_GRAPH_INVALID_GRAPH = 1901; - public static final int ERROR_GRAPH_COULD_NOT_CREATE_GRAPH = 1902; - public static final int ERROR_GRAPH_INVALID_VERTEX = 1903; - public static final int ERROR_GRAPH_COULD_NOT_CREATE_VERTEX = 1904; - public static final int ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX = 1905; - public static final int ERROR_GRAPH_INVALID_EDGE = 1906; - public static final int ERROR_GRAPH_COULD_NOT_CREATE_EDGE = 1907; - public static final int ERROR_GRAPH_COULD_NOT_CHANGE_EDGE = 1908; - public static final int ERROR_GRAPH_TOO_MANY_ITERATIONS = 1909; - public static final int ERROR_GRAPH_INVALID_FILTER_RESULT = 1910; - public static final int ERROR_GRAPH_COLLECTION_MULTI_USE = 1920; - public static final int ERROR_GRAPH_COLLECTION_USE_IN_MULTI_GRAPHS = 1921; - public static final int ERROR_GRAPH_CREATE_MISSING_NAME = 1922; - public static final int ERROR_GRAPH_CREATE_MALFORMED_EDGE_DEFINITION = 1923; - public static final int ERROR_GRAPH_NOT_FOUND = 1924; - public static final int ERROR_GRAPH_DUPLICATE = 1925; - public static final int ERROR_GRAPH_VERTEX_COL_DOES_NOT_EXIST = 1926; - public static final int ERROR_GRAPH_WRONG_COLLECTION_TYPE_VERTEX = 1927; - public static final int ERROR_GRAPH_NOT_IN_ORPHAN_COLLECTION = 1928; - public static final int ERROR_GRAPH_COLLECTION_USED_IN_EDGE_DEF = 1929; - public static final int ERROR_GRAPH_EDGE_COLLECTION_NOT_USED = 1930; - public static final int ERROR_GRAPH_NOT_AN_ARANGO_COLLECTION = 1931; - public static final int ERROR_GRAPH_NO_GRAPH_COLLECTION = 1932; - public static final int ERROR_GRAPH_INVALID_EXAMPLE_ARRAY_OBJECT_STRING = 1933; - public static final int ERROR_GRAPH_INVALID_EXAMPLE_ARRAY_OBJECT = 1934; - public static final int ERROR_GRAPH_INVALID_NUMBER_OF_ARGUMENTS = 1935; - public static final int ERROR_GRAPH_INVALID_PARAMETER = 1936; - public static final int ERROR_GRAPH_INVALID_ID = 1937; - public static final int ERROR_GRAPH_COLLECTION_USED_IN_ORPHANS = 1938; - public static final int ERROR_GRAPH_EDGE_COL_DOES_NOT_EXIST = 1939; - public static final int ERROR_SESSION_UNKNOWN = 1950; - public static final int ERROR_SESSION_EXPIRED = 1951; - public static final int SIMPLE_CLIENT_UNKNOWN_ERROR = 2000; - public static final int SIMPLE_CLIENT_COULD_NOT_CONNECT = 2001; - public static final int SIMPLE_CLIENT_COULD_NOT_WRITE = 2002; - public static final int SIMPLE_CLIENT_COULD_NOT_READ = 2003; - public static final int ERROR_MALFORMED_MANIFEST_FILE = 3000; - public static final int ERROR_INVALID_APPLICATION_MANIFEST = 3001; - public static final int ERROR_MANIFEST_FILE_ATTRIBUTE_MISSING = 3002; - public static final int ERROR_CANNOT_EXTRACT_APPLICATION_ROOT = 3003; - public static final int ERROR_INVALID_FOXX_OPTIONS = 3004; - public static final int ERROR_FAILED_TO_EXECUTE_SCRIPT = 3005; - public static final int ERROR_SYNTAX_ERROR_IN_SCRIPT = 3006; - public static final int ERROR_INVALID_MOUNTPOINT = 3007; - public static final int ERROR_NO_FOXX_FOUND = 3008; - public static final int ERROR_APP_NOT_FOUND = 3009; - public static final int ERROR_APP_NEEDS_CONFIGURATION = 3010; - public static final int ERROR_MODULE_NOT_FOUND = 3100; - public static final int ERROR_MODULE_SYNTAX_ERROR = 3101; - public static final int ERROR_MODULE_BAD_WRAPPER = 3102; - public static final int ERROR_MODULE_FAILURE = 3103; - public static final int ERROR_MODULE_UNKNOWN_FILE_TYPE = 3110; - public static final int ERROR_MODULE_PATH_MUST_BE_ABSOLUTE = 3111; - public static final int ERROR_MODULE_CAN_NOT_ESCAPE = 3112; - public static final int ERROR_MODULE_DRIVE_LETTER = 3113; - public static final int ERROR_MODULE_BAD_MODULE_ORIGIN = 3120; - public static final int ERROR_MODULE_BAD_PACKAGE_ORIGIN = 3121; - public static final int ERROR_MODULE_DOCUMENT_IS_EMPTY = 3125; - public static final int ERROR_MODULE_MAIN_NOT_READABLE = 3130; - public static final int ERROR_MODULE_MAIN_NOT_JS = 3131; - public static final int RESULT_ELEMENT_EXISTS = 10000; - public static final int RESULT_ELEMENT_NOT_FOUND = 10001; - public static final int ERROR_APP_ALREADY_EXISTS = 20000; - public static final int ERROR_QUEUE_ALREADY_EXISTS = 21000; - public static final int ERROR_DISPATCHER_IS_STOPPING = 21001; - public static final int ERROR_QUEUE_UNKNOWN = 21002; - public static final int ERROR_QUEUE_FULL = 21003; + public static final int ERROR_NO_ERROR = 0; + public static final int ERROR_FAILED = 1; + public static final int ERROR_SYS_ERROR = 2; + public static final int ERROR_OUT_OF_MEMORY = 3; + public static final int ERROR_INTERNAL = 4; + public static final int ERROR_ILLEGAL_NUMBER = 5; + public static final int ERROR_NUMERIC_OVERFLOW = 6; + public static final int ERROR_ILLEGAL_OPTION = 7; + public static final int ERROR_DEAD_PID = 8; + public static final int ERROR_NOT_IMPLEMENTED = 9; + public static final int ERROR_BAD_PARAMETER = 10; + public static final int ERROR_FORBIDDEN = 11; + public static final int ERROR_OUT_OF_MEMORY_MMAP = 12; + public static final int ERROR_CORRUPTED_CSV = 13; + public static final int ERROR_FILE_NOT_FOUND = 14; + public static final int ERROR_CANNOT_WRITE_FILE = 15; + public static final int ERROR_CANNOT_OVERWRITE_FILE = 16; + public static final int ERROR_TYPE_ERROR = 17; + public static final int ERROR_LOCK_TIMEOUT = 18; + public static final int ERROR_CANNOT_CREATE_DIRECTORY = 19; + public static final int ERROR_CANNOT_CREATE_TEMP_FILE = 20; + public static final int ERROR_REQUEST_CANCELED = 21; + public static final int ERROR_DEBUG = 22; + public static final int ERROR_IP_ADDRESS_INVALID = 25; + public static final int ERROR_FILE_EXISTS = 27; + public static final int ERROR_LOCKED = 28; + public static final int ERROR_DEADLOCK = 29; + public static final int ERROR_HTTP_BAD_PARAMETER = 400; + public static final int ERROR_HTTP_UNAUTHORIZED = 401; + public static final int ERROR_HTTP_FORBIDDEN = 403; + public static final int ERROR_HTTP_NOT_FOUND = 404; + public static final int ERROR_HTTP_METHOD_NOT_ALLOWED = 405; + public static final int ERROR_HTTP_PRECONDITION_FAILED = 412; + public static final int ERROR_HTTP_SERVER_ERROR = 500; + public static final int ERROR_HTTP_CORRUPTED_JSON = 600; + public static final int ERROR_HTTP_SUPERFLUOUS_SUFFICES = 601; + public static final int ERROR_ARANGO_ILLEGAL_STATE = 1000; + public static final int ERROR_ARANGO_DATAFILE_SEALED = 1002; + public static final int ERROR_ARANGO_UNKNOWN_COLLECTION_TYPE = 1003; + public static final int ERROR_ARANGO_READ_ONLY = 1004; + public static final int ERROR_ARANGO_DUPLICATE_IDENTIFIER = 1005; + public static final int ERROR_ARANGO_DATAFILE_UNREADABLE = 1006; + public static final int ERROR_ARANGO_DATAFILE_EMPTY = 1007; + public static final int ERROR_ARANGO_RECOVERY = 1008; + public static final int ERROR_ARANGO_CORRUPTED_DATAFILE = 1100; + public static final int ERROR_ARANGO_ILLEGAL_PARAMETER_FILE = 1101; + public static final int ERROR_ARANGO_CORRUPTED_COLLECTION = 1102; + public static final int ERROR_ARANGO_MMAP_FAILED = 1103; + public static final int ERROR_ARANGO_FILESYSTEM_FULL = 1104; + public static final int ERROR_ARANGO_NO_JOURNAL = 1105; + public static final int ERROR_ARANGO_DATAFILE_ALREADY_EXISTS = 1106; + public static final int ERROR_ARANGO_DATADIR_LOCKED = 1107; + public static final int ERROR_ARANGO_COLLECTION_DIRECTORY_ALREADY_EXISTS = 1108; + public static final int ERROR_ARANGO_MSYNC_FAILED = 1109; + public static final int ERROR_ARANGO_DATADIR_UNLOCKABLE = 1110; + public static final int ERROR_ARANGO_SYNC_TIMEOUT = 1111; + public static final int ERROR_ARANGO_CONFLICT = 1200; + public static final int ERROR_ARANGO_DATADIR_INVALID = 1201; + public static final int ERROR_ARANGO_DOCUMENT_NOT_FOUND = 1202; + public static final int ERROR_ARANGO_COLLECTION_NOT_FOUND = 1203; + public static final int ERROR_ARANGO_COLLECTION_PARAMETER_MISSING = 1204; + public static final int ERROR_ARANGO_DOCUMENT_HANDLE_BAD = 1205; + public static final int ERROR_ARANGO_MAXIMAL_SIZE_TOO_SMALL = 1206; + public static final int ERROR_ARANGO_DUPLICATE_NAME = 1207; + public static final int ERROR_ARANGO_ILLEGAL_NAME = 1208; + public static final int ERROR_ARANGO_NO_INDEX = 1209; + public static final int ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED = 1210; + public static final int ERROR_ARANGO_INDEX_NOT_FOUND = 1212; + public static final int ERROR_ARANGO_CROSS_COLLECTION_REQUEST = 1213; + public static final int ERROR_ARANGO_INDEX_HANDLE_BAD = 1214; + public static final int ERROR_ARANGO_DOCUMENT_TOO_LARGE = 1216; + public static final int ERROR_ARANGO_COLLECTION_NOT_UNLOADED = 1217; + public static final int ERROR_ARANGO_COLLECTION_TYPE_INVALID = 1218; + public static final int ERROR_ARANGO_VALIDATION_FAILED = 1219; + public static final int ERROR_ARANGO_ATTRIBUTE_PARSER_FAILED = 1220; + public static final int ERROR_ARANGO_DOCUMENT_KEY_BAD = 1221; + public static final int ERROR_ARANGO_DOCUMENT_KEY_UNEXPECTED = 1222; + public static final int ERROR_ARANGO_DATADIR_NOT_WRITABLE = 1224; + public static final int ERROR_ARANGO_OUT_OF_KEYS = 1225; + public static final int ERROR_ARANGO_DOCUMENT_KEY_MISSING = 1226; + public static final int ERROR_ARANGO_DOCUMENT_TYPE_INVALID = 1227; + public static final int ERROR_ARANGO_DATABASE_NOT_FOUND = 1228; + public static final int ERROR_ARANGO_DATABASE_NAME_INVALID = 1229; + public static final int ERROR_ARANGO_USE_SYSTEM_DATABASE = 1230; + public static final int ERROR_ARANGO_ENDPOINT_NOT_FOUND = 1231; + public static final int ERROR_ARANGO_INVALID_KEY_GENERATOR = 1232; + public static final int ERROR_ARANGO_INVALID_EDGE_ATTRIBUTE = 1233; + public static final int ERROR_ARANGO_INDEX_DOCUMENT_ATTRIBUTE_MISSING = 1234; + public static final int ERROR_ARANGO_INDEX_CREATION_FAILED = 1235; + public static final int ERROR_ARANGO_WRITE_THROTTLE_TIMEOUT = 1236; + public static final int ERROR_ARANGO_COLLECTION_TYPE_MISMATCH = 1237; + public static final int ERROR_ARANGO_COLLECTION_NOT_LOADED = 1238; + public static final int ERROR_ARANGO_DOCUMENT_REV_BAD = 1239; + public static final int ERROR_ARANGO_DATAFILE_FULL = 1300; + public static final int ERROR_ARANGO_EMPTY_DATADIR = 1301; + public static final int ERROR_REPLICATION_NO_RESPONSE = 1400; + public static final int ERROR_REPLICATION_INVALID_RESPONSE = 1401; + public static final int ERROR_REPLICATION_MASTER_ERROR = 1402; + public static final int ERROR_REPLICATION_MASTER_INCOMPATIBLE = 1403; + public static final int ERROR_REPLICATION_MASTER_CHANGE = 1404; + public static final int ERROR_REPLICATION_LOOP = 1405; + public static final int ERROR_REPLICATION_UNEXPECTED_MARKER = 1406; + public static final int ERROR_REPLICATION_INVALID_APPLIER_STATE = 1407; + public static final int ERROR_REPLICATION_UNEXPECTED_TRANSACTION = 1408; + public static final int ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION = 1410; + public static final int ERROR_REPLICATION_RUNNING = 1411; + public static final int ERROR_REPLICATION_APPLIER_STOPPED = 1412; + public static final int ERROR_REPLICATION_NO_START_TICK = 1413; + public static final int ERROR_REPLICATION_START_TICK_NOT_PRESENT = 1414; + public static final int ERROR_CLUSTER_NO_AGENCY = 1450; + public static final int ERROR_CLUSTER_NO_COORDINATOR_HEADER = 1451; + public static final int ERROR_CLUSTER_COULD_NOT_LOCK_PLAN = 1452; + public static final int ERROR_CLUSTER_COLLECTION_ID_EXISTS = 1453; + public static final int ERROR_CLUSTER_COULD_NOT_CREATE_COLLECTION_IN_PLAN = 1454; + public static final int ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION = 1455; + public static final int ERROR_CLUSTER_COULD_NOT_CREATE_COLLECTION = 1456; + public static final int ERROR_CLUSTER_TIMEOUT = 1457; + public static final int ERROR_CLUSTER_COULD_NOT_REMOVE_COLLECTION_IN_PLAN = 1458; + public static final int ERROR_CLUSTER_COULD_NOT_REMOVE_COLLECTION_IN_CURRENT = 1459; + public static final int ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE_IN_PLAN = 1460; + public static final int ERROR_CLUSTER_COULD_NOT_CREATE_DATABASE = 1461; + public static final int ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_PLAN = 1462; + public static final int ERROR_CLUSTER_COULD_NOT_REMOVE_DATABASE_IN_CURRENT = 1463; + public static final int ERROR_CLUSTER_SHARD_GONE = 1464; + public static final int ERROR_CLUSTER_CONNECTION_LOST = 1465; + public static final int ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY = 1466; + public static final int ERROR_CLUSTER_GOT_CONTRADICTING_ANSWERS = 1467; + public static final int ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN = 1468; + public static final int ERROR_CLUSTER_MUST_NOT_CHANGE_SHARDING_ATTRIBUTES = 1469; + public static final int ERROR_CLUSTER_UNSUPPORTED = 1470; + public static final int ERROR_CLUSTER_ONLY_ON_COORDINATOR = 1471; + public static final int ERROR_CLUSTER_READING_PLAN_AGENCY = 1472; + public static final int ERROR_CLUSTER_COULD_NOT_TRUNCATE_COLLECTION = 1473; + public static final int ERROR_CLUSTER_AQL_COMMUNICATION = 1474; + public static final int ERROR_ARANGO_DOCUMENT_NOT_FOUND_OR_SHARDING_ATTRIBUTES_CHANGED = 1475; + public static final int ERROR_CLUSTER_COULD_NOT_DETERMINE_ID = 1476; + public static final int ERROR_CLUSTER_ONLY_ON_DBSERVER = 1477; + public static final int ERROR_CLUSTER_BACKEND_UNAVAILABLE = 1478; + public static final int ERROR_CLUSTER_UNKNOWN_CALLBACK_ENDPOINT = 1479; + public static final int ERROR_QUERY_KILLED = 1500; + public static final int ERROR_QUERY_PARSE = 1501; + public static final int ERROR_QUERY_EMPTY = 1502; + public static final int ERROR_QUERY_SCRIPT = 1503; + public static final int ERROR_QUERY_NUMBER_OUT_OF_RANGE = 1504; + public static final int ERROR_QUERY_VARIABLE_NAME_INVALID = 1510; + public static final int ERROR_QUERY_VARIABLE_REDECLARED = 1511; + public static final int ERROR_QUERY_VARIABLE_NAME_UNKNOWN = 1512; + public static final int ERROR_QUERY_COLLECTION_LOCK_FAILED = 1521; + public static final int ERROR_QUERY_TOO_MANY_COLLECTIONS = 1522; + public static final int ERROR_QUERY_DOCUMENT_ATTRIBUTE_REDECLARED = 1530; + public static final int ERROR_QUERY_FUNCTION_NAME_UNKNOWN = 1540; + public static final int ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH = 1541; + public static final int ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH = 1542; + public static final int ERROR_QUERY_INVALID_REGEX = 1543; + public static final int ERROR_QUERY_BIND_PARAMETERS_INVALID = 1550; + public static final int ERROR_QUERY_BIND_PARAMETER_MISSING = 1551; + public static final int ERROR_QUERY_BIND_PARAMETER_UNDECLARED = 1552; + public static final int ERROR_QUERY_BIND_PARAMETER_TYPE = 1553; + public static final int ERROR_QUERY_INVALID_LOGICAL_VALUE = 1560; + public static final int ERROR_QUERY_INVALID_ARITHMETIC_VALUE = 1561; + public static final int ERROR_QUERY_DIVISION_BY_ZERO = 1562; + public static final int ERROR_QUERY_ARRAY_EXPECTED = 1563; + public static final int ERROR_QUERY_FAIL_CALLED = 1569; + public static final int ERROR_QUERY_GEO_INDEX_MISSING = 1570; + public static final int ERROR_QUERY_FULLTEXT_INDEX_MISSING = 1571; + public static final int ERROR_QUERY_INVALID_DATE_VALUE = 1572; + public static final int ERROR_QUERY_MULTI_MODIFY = 1573; + public static final int ERROR_QUERY_INVALID_AGGREGATE_EXPRESSION = 1574; + public static final int ERROR_QUERY_COMPILE_TIME_OPTIONS = 1575; + public static final int ERROR_QUERY_EXCEPTION_OPTIONS = 1576; + public static final int ERROR_QUERY_COLLECTION_USED_IN_EXPRESSION = 1577; + public static final int ERROR_QUERY_DISALLOWED_DYNAMIC_CALL = 1578; + public static final int ERROR_QUERY_ACCESS_AFTER_MODIFICATION = 1579; + public static final int ERROR_QUERY_FUNCTION_INVALID_NAME = 1580; + public static final int ERROR_QUERY_FUNCTION_INVALID_CODE = 1581; + public static final int ERROR_QUERY_FUNCTION_NOT_FOUND = 1582; + public static final int ERROR_QUERY_FUNCTION_RUNTIME_ERROR = 1583; + public static final int ERROR_QUERY_BAD_JSON_PLAN = 1590; + public static final int ERROR_QUERY_NOT_FOUND = 1591; + public static final int ERROR_QUERY_IN_USE = 1592; + public static final int ERROR_CURSOR_NOT_FOUND = 1600; + public static final int ERROR_CURSOR_BUSY = 1601; + public static final int ERROR_TRANSACTION_INTERNAL = 1650; + public static final int ERROR_TRANSACTION_NESTED = 1651; + public static final int ERROR_TRANSACTION_UNREGISTERED_COLLECTION = 1652; + public static final int ERROR_TRANSACTION_DISALLOWED_OPERATION = 1653; + public static final int ERROR_TRANSACTION_ABORTED = 1654; + public static final int ERROR_USER_INVALID_NAME = 1700; + public static final int ERROR_USER_INVALID_PASSWORD = 1701; + public static final int ERROR_USER_DUPLICATE = 1702; + public static final int ERROR_USER_NOT_FOUND = 1703; + public static final int ERROR_USER_CHANGE_PASSWORD = 1704; + public static final int ERROR_APPLICATION_INVALID_NAME = 1750; + public static final int ERROR_APPLICATION_INVALID_MOUNT = 1751; + public static final int ERROR_APPLICATION_DOWNLOAD_FAILED = 1752; + public static final int ERROR_APPLICATION_UPLOAD_FAILED = 1753; + public static final int ERROR_KEYVALUE_INVALID_KEY = 1800; + public static final int ERROR_KEYVALUE_KEY_EXISTS = 1801; + public static final int ERROR_KEYVALUE_KEY_NOT_FOUND = 1802; + public static final int ERROR_KEYVALUE_KEY_NOT_UNIQUE = 1803; + public static final int ERROR_KEYVALUE_KEY_NOT_CHANGED = 1804; + public static final int ERROR_KEYVALUE_KEY_NOT_REMOVED = 1805; + public static final int ERROR_KEYVALUE_NO_VALUE = 1806; + public static final int ERROR_TASK_INVALID_ID = 1850; + public static final int ERROR_TASK_DUPLICATE_ID = 1851; + public static final int ERROR_TASK_NOT_FOUND = 1852; + public static final int ERROR_GRAPH_INVALID_GRAPH = 1901; + public static final int ERROR_GRAPH_COULD_NOT_CREATE_GRAPH = 1902; + public static final int ERROR_GRAPH_INVALID_VERTEX = 1903; + public static final int ERROR_GRAPH_COULD_NOT_CREATE_VERTEX = 1904; + public static final int ERROR_GRAPH_COULD_NOT_CHANGE_VERTEX = 1905; + public static final int ERROR_GRAPH_INVALID_EDGE = 1906; + public static final int ERROR_GRAPH_COULD_NOT_CREATE_EDGE = 1907; + public static final int ERROR_GRAPH_COULD_NOT_CHANGE_EDGE = 1908; + public static final int ERROR_GRAPH_TOO_MANY_ITERATIONS = 1909; + public static final int ERROR_GRAPH_INVALID_FILTER_RESULT = 1910; + public static final int ERROR_GRAPH_COLLECTION_MULTI_USE = 1920; + public static final int ERROR_GRAPH_COLLECTION_USE_IN_MULTI_GRAPHS = 1921; + public static final int ERROR_GRAPH_CREATE_MISSING_NAME = 1922; + public static final int ERROR_GRAPH_CREATE_MALFORMED_EDGE_DEFINITION = 1923; + public static final int ERROR_GRAPH_NOT_FOUND = 1924; + public static final int ERROR_GRAPH_DUPLICATE = 1925; + public static final int ERROR_GRAPH_VERTEX_COL_DOES_NOT_EXIST = 1926; + public static final int ERROR_GRAPH_WRONG_COLLECTION_TYPE_VERTEX = 1927; + public static final int ERROR_GRAPH_NOT_IN_ORPHAN_COLLECTION = 1928; + public static final int ERROR_GRAPH_COLLECTION_USED_IN_EDGE_DEF = 1929; + public static final int ERROR_GRAPH_EDGE_COLLECTION_NOT_USED = 1930; + public static final int ERROR_GRAPH_NOT_AN_ARANGO_COLLECTION = 1931; + public static final int ERROR_GRAPH_NO_GRAPH_COLLECTION = 1932; + public static final int ERROR_GRAPH_INVALID_EXAMPLE_ARRAY_OBJECT_STRING = 1933; + public static final int ERROR_GRAPH_INVALID_EXAMPLE_ARRAY_OBJECT = 1934; + public static final int ERROR_GRAPH_INVALID_NUMBER_OF_ARGUMENTS = 1935; + public static final int ERROR_GRAPH_INVALID_PARAMETER = 1936; + public static final int ERROR_GRAPH_INVALID_ID = 1937; + public static final int ERROR_GRAPH_COLLECTION_USED_IN_ORPHANS = 1938; + public static final int ERROR_GRAPH_EDGE_COL_DOES_NOT_EXIST = 1939; + public static final int ERROR_GRAPH_EMPTY = 1940; + public static final int ERROR_SESSION_UNKNOWN = 1950; + public static final int ERROR_SESSION_EXPIRED = 1951; + public static final int SIMPLE_CLIENT_UNKNOWN_ERROR = 2000; + public static final int SIMPLE_CLIENT_COULD_NOT_CONNECT = 2001; + public static final int SIMPLE_CLIENT_COULD_NOT_WRITE = 2002; + public static final int SIMPLE_CLIENT_COULD_NOT_READ = 2003; + public static final int ERROR_MALFORMED_MANIFEST_FILE = 3000; + public static final int ERROR_INVALID_APPLICATION_MANIFEST = 3001; + public static final int ERROR_INVALID_FOXX_OPTIONS = 3004; + public static final int ERROR_INVALID_MOUNTPOINT = 3007; + public static final int ERROR_APP_NOT_FOUND = 3009; + public static final int ERROR_APP_NEEDS_CONFIGURATION = 3010; + public static final int ERROR_MODULE_NOT_FOUND = 3100; + public static final int ERROR_MODULE_FAILURE = 3103; + public static final int RESULT_ELEMENT_EXISTS = 10000; + public static final int RESULT_ELEMENT_NOT_FOUND = 10001; + public static final int ERROR_QUEUE_ALREADY_EXISTS = 21000; + public static final int ERROR_DISPATCHER_IS_STOPPING = 21001; + public static final int ERROR_QUEUE_UNKNOWN = 21002; + public static final int ERROR_QUEUE_FULL = 21003; - private ErrorNums() { - // this is a helper class - } } + diff --git a/src/main/java/com/arangodb/InternalEdgeDriver.java b/src/main/java/com/arangodb/InternalEdgeDriver.java deleted file mode 100644 index 7c2666f8f..000000000 --- a/src/main/java/com/arangodb/InternalEdgeDriver.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2004-2015 triAGENS GmbH, Cologne, Germany - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright holder is triAGENS GmbH, Cologne, Germany - * - * @author fbartels - * @author gschwab - * @author a-brandt - * @author Copyright 2015, triAGENS GmbH, Cologne, Germany - */ - -package com.arangodb; - -import com.arangodb.entity.EdgeEntity; -import com.arangodb.impl.BaseDriverInterface; - -public interface InternalEdgeDriver extends BaseDriverInterface { - - EdgeEntity createEdge( - String graphName, - String collectionName, - T object, - String from, - String to, - Boolean createCollection, - Boolean waitForSync) throws ArangoException; - -} diff --git a/src/main/java/com/arangodb/InternalGraphDriver.java b/src/main/java/com/arangodb/InternalGraphDriver.java index 9d21dbdbb..64dfe6057 100644 --- a/src/main/java/com/arangodb/InternalGraphDriver.java +++ b/src/main/java/com/arangodb/InternalGraphDriver.java @@ -415,6 +415,8 @@ DeletedEntity deleteEdge( * @param graphName * @param edgeCollectionName * @param key + * @param fromHandle + * @param toHandle * @param value * @param waitForSync * @param ifMatchRevision @@ -427,6 +429,8 @@ EdgeEntity replaceEdge( String graphName, String edgeCollectionName, String key, + String fromHandle, + String toHandle, T value, Boolean waitForSync, Long ifMatchRevision, @@ -441,6 +445,8 @@ EdgeEntity replaceEdge( * @param graphName * @param edgeCollectionName * @param key + * @param fromHandle + * @param toHandle * @param value * @param waitForSync * @param keepNull @@ -454,6 +460,8 @@ EdgeEntity updateEdge( String graphName, String edgeCollectionName, String key, + String fromHandle, + String toHandle, T value, Boolean waitForSync, Boolean keepNull, diff --git a/src/main/java/com/arangodb/InternalIndexDriver.java b/src/main/java/com/arangodb/InternalIndexDriver.java index 69e0ac2f3..83f03dd52 100644 --- a/src/main/java/com/arangodb/InternalIndexDriver.java +++ b/src/main/java/com/arangodb/InternalIndexDriver.java @@ -8,20 +8,24 @@ /** * Created by fbartels on 10/27/14. */ -public interface InternalIndexDriver extends BaseDriverInterface { - IndexEntity createIndex(String database, String collectionName, IndexType type, boolean unique, boolean sparse, String... fields) throws ArangoException; +public interface InternalIndexDriver extends BaseDriverInterface { + IndexEntity createIndex( + String database, + String collectionName, + IndexType type, + boolean unique, + boolean sparse, + String... fields) throws ArangoException; - IndexEntity createIndex(String database, String collectionName, IndexType type, boolean unique, String... fields) throws ArangoException; + IndexEntity createIndex(String database, String collectionName, IndexType type, boolean unique, String... fields) + throws ArangoException; - IndexEntity createCappedIndex(String database, String collectionName, int size) throws ArangoException; + IndexEntity createFulltextIndex(String database, String collectionName, Integer minLength, String... fields) + throws ArangoException; - IndexEntity createCappedByDocumentSizeIndex(String database, String collectionName, int byteSize) throws ArangoException; + IndexEntity deleteIndex(String database, String indexHandle) throws ArangoException; - IndexEntity createFulltextIndex(String database, String collectionName, Integer minLength, String... fields) throws ArangoException; + IndexEntity getIndex(String database, String indexHandle) throws ArangoException; - IndexEntity deleteIndex(String database, String indexHandle) throws ArangoException; - - IndexEntity getIndex(String database, String indexHandle) throws ArangoException; - - IndexesEntity getIndexes(String database, String collectionName) throws ArangoException; + IndexesEntity getIndexes(String database, String collectionName) throws ArangoException; } diff --git a/src/main/java/com/arangodb/InternalSimpleDriver.java b/src/main/java/com/arangodb/InternalSimpleDriver.java index a94a29fea..2e03ab05c 100644 --- a/src/main/java/com/arangodb/InternalSimpleDriver.java +++ b/src/main/java/com/arangodb/InternalSimpleDriver.java @@ -4,7 +4,6 @@ import com.arangodb.entity.CursorEntity; import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.DocumentResultEntity; import com.arangodb.entity.ScalarExampleEntity; import com.arangodb.entity.SimpleByResultEntity; import com.arangodb.impl.BaseDriverInterface; @@ -239,9 +238,4 @@ DocumentCursor executeSimpleFulltextWithDocuments( String index, Class clazz) throws ArangoException; - DocumentResultEntity executeSimpleFirst(String database, String collectionName, Integer count, Class clazz) - throws ArangoException; - - DocumentResultEntity executeSimpleLast(String database, String collectionName, Integer count, Class clazz) - throws ArangoException; } diff --git a/src/main/java/com/arangodb/entity/EntityDeserializers.java b/src/main/java/com/arangodb/entity/EntityDeserializers.java index 56b6684f4..953a78e4a 100644 --- a/src/main/java/com/arangodb/entity/EntityDeserializers.java +++ b/src/main/java/com/arangodb/entity/EntityDeserializers.java @@ -751,12 +751,15 @@ public DocumentEntity deserialize(JsonElement json, Type typeOfT, JsonDeseria Class clazz = getParameterized(); if (clazz != null) { entity.entity = context.deserialize(obj, clazz); - if (clazz.getName().equalsIgnoreCase(BaseDocument.class.getName())) { - // iterate all key/value pairs of the jsonObject and - // determine its class(String, Number, Boolean, HashMap, - // List) - ((BaseDocument) entity.entity).setProperties(DeserializeSingleEntry.deserializeJsonObject(obj)); - } + // if + // (clazz.getName().equalsIgnoreCase(BaseDocument.class.getName())) + // { + // // iterate all key/value pairs of the jsonObject and + // // determine its class(String, Number, Boolean, HashMap, + // // List) + // ((BaseDocument) + // entity.entity).setProperties(DeserializeSingleEntry.deserializeJsonObject(obj)); + // } } return entity; diff --git a/src/main/java/com/arangodb/entity/IndexType.java b/src/main/java/com/arangodb/entity/IndexType.java index 931029e27..17eb1de69 100644 --- a/src/main/java/com/arangodb/entity/IndexType.java +++ b/src/main/java/com/arangodb/entity/IndexType.java @@ -20,16 +20,15 @@ * Index Type. * * @author tamtam180 - kirscheless at gmail.com - * @see HttpIndexIntro + * @see + * HttpIndexIntro */ public enum IndexType { /** Primary Index */ PRIMARY, /** Edge Index */ EDGE, - /** Cap Index */ - CAP, /** Geo Index */ GEO, /** Hash Index */ diff --git a/src/main/java/com/arangodb/http/HttpManager.java b/src/main/java/com/arangodb/http/HttpManager.java index 3bcd1847d..f81315746 100644 --- a/src/main/java/com/arangodb/http/HttpManager.java +++ b/src/main/java/com/arangodb/http/HttpManager.java @@ -52,6 +52,7 @@ import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.ConnectionKeepAliveStrategy; +import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; @@ -61,8 +62,8 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.BasicHttpClientConnectionManager; import org.apache.http.impl.conn.DefaultProxyRoutePlanner; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.message.BasicHeaderElementIterator; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; @@ -87,7 +88,7 @@ public class HttpManager { private static Logger logger = LoggerFactory.getLogger(HttpManager.class); - private PoolingHttpClientConnectionManager cm; + private HttpClientConnectionManager cm; private CloseableHttpClient client; private ArangoConfigure configure; @@ -124,9 +125,10 @@ public void init() { .register("http", plainsf).register("https", sslsf).build(); // ConnectionManager - cm = new PoolingHttpClientConnectionManager(r); - cm.setDefaultMaxPerRoute(configure.getMaxPerConnection()); - cm.setMaxTotal(configure.getMaxTotalConnection()); + // cm = new PoolingHttpClientConnectionManager(r); + cm = new BasicHttpClientConnectionManager(r); + // cm.setDefaultMaxPerRoute(configure.getMaxPerConnection()); + // cm.setMaxTotal(configure.getMaxTotalConnection()); Builder custom = RequestConfig.custom(); @@ -452,7 +454,9 @@ private HttpResponseEntity buildHttpResponseEntity(HttpRequestEntity requestEnti responseEntity.statusCode = status.getStatusCode(); responseEntity.statusPhrase = status.getReasonPhrase(); - logger.debug("[RES]http-{}: statusCode={}", requestEntity.type, responseEntity.statusCode); + if (logger.isDebugEnabled()) { + logger.debug("[RES]http-{}: statusCode={}", requestEntity.type, responseEntity.statusCode); + } // ヘッダの処理 // // TODO etag特殊処理は削除する。 @@ -474,13 +478,17 @@ private HttpResponseEntity buildHttpResponseEntity(HttpRequestEntity requestEnti responseEntity.contentType = contentType.getValue(); if (responseEntity.isDumpResponse()) { responseEntity.stream = entity.getContent(); - logger.debug("[RES]http-{}: stream, {}", requestEntity.type, contentType.getValue()); + if (logger.isDebugEnabled()) { + logger.debug("[RES]http-{}: stream, {}", requestEntity.type, contentType.getValue()); + } } } // Close stream in this method. if (responseEntity.stream == null) { responseEntity.text = IOUtils.toString(entity.getContent()); - logger.debug("[RES]http-{}: text={}", requestEntity.type, responseEntity.text); + if (logger.isDebugEnabled()) { + logger.debug("[RES]http-{}: text={}", requestEntity.type, responseEntity.text); + } } } return responseEntity; diff --git a/src/main/java/com/arangodb/impl/AnnotationHandler.java b/src/main/java/com/arangodb/impl/AnnotationHandler.java index 82317680f..c4cbbd4c3 100644 --- a/src/main/java/com/arangodb/impl/AnnotationHandler.java +++ b/src/main/java/com/arangodb/impl/AnnotationHandler.java @@ -73,15 +73,23 @@ public synchronized void updateEdgeAttributes(Object o, long rev, String id, Str m.put(BaseDocument.ID, id); m.put(BaseDocument.KEY, key); m.put(BaseDocument.REV, rev); - m.put(BaseDocument.FROM, from); - m.put(BaseDocument.TO, to); + if (from != null) { + m.put(BaseDocument.FROM, from); + } + if (to != null) { + m.put(BaseDocument.TO, to); + } } else { DocumentAttributes documentAttributes = getDocumentAttributes(o); setAttribute(documentAttributes.id, o, id); setAttribute(documentAttributes.key, o, key); setAttribute(documentAttributes.rev, o, rev); - setAttribute(documentAttributes.from, o, from); - setAttribute(documentAttributes.to, o, to); + if (from != null) { + setAttribute(documentAttributes.from, o, from); + } + if (to != null) { + setAttribute(documentAttributes.to, o, to); + } } } } diff --git a/src/main/java/com/arangodb/impl/ImplFactory.java b/src/main/java/com/arangodb/impl/ImplFactory.java index 70c4176ec..c59b56082 100644 --- a/src/main/java/com/arangodb/impl/ImplFactory.java +++ b/src/main/java/com/arangodb/impl/ImplFactory.java @@ -110,13 +110,6 @@ public static InternalGraphDriverImpl createGraphDriver( return new InternalGraphDriverImpl(configure, cursorDriver, httpManager); } - public static InternalEdgeDriverImpl createEdgeDriver( - ArangoConfigure configure, - InternalCursorDriver cursorDriver, - HttpManager httpManager) { - return new InternalEdgeDriverImpl(configure, cursorDriver, httpManager); - } - public static InternalTraversalDriverImpl createTraversalDriver( ArangoConfigure configure, HttpManager httpManager) { diff --git a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java index 82a378e2d..8dc7698ac 100644 --- a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java @@ -25,14 +25,13 @@ import com.arangodb.ArangoConfigure; import com.arangodb.ArangoException; import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.CursorEntity; import com.arangodb.entity.DefaultEntity; import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.DocumentsEntity; import com.arangodb.entity.EntityFactory; import com.arangodb.entity.Policy; import com.arangodb.http.HttpManager; import com.arangodb.http.HttpResponseEntity; -import com.arangodb.util.CollectionUtils; import com.arangodb.util.MapBuilder; import com.google.gson.JsonElement; @@ -209,16 +208,28 @@ public DocumentEntity updateDocumentRaw( public List getDocuments(String database, String collectionName, boolean handleConvert) throws ArangoException { - HttpResponseEntity res = httpManager.doGet(createDocumentEndpointUrl(database), - new MapBuilder("collection", collectionName).get()); + // HttpResponseEntity res = + // httpManager.doGet(createDocumentEndpointUrl(database), + // new MapBuilder("collection", collectionName).get()); - DocumentsEntity entity = createEntity(res, DocumentsEntity.class); - List documents = CollectionUtils.safety(entity.getDocuments()); + HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/all-keys"), null, + EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).get())); - if (handleConvert && !documents.isEmpty()) { - updateDocumentHandles(documents); - } - return documents; + @SuppressWarnings("unchecked") + CursorEntity tmp = createEntity(res, CursorEntity.class, String.class); + + return tmp.getResults(); + // + // + // DocumentResultEntity entity = createEntity(res, + // DocumentResultEntity.class); + // List documents = + // CollectionUtils.safety(entity.getDocuments()); + // + // if (handleConvert && !documents.isEmpty()) { + // updateDocumentHandles(documents); + // } + // return documents; } private void updateDocumentHandles(List documents) { diff --git a/src/main/java/com/arangodb/impl/InternalEdgeDriverImpl.java b/src/main/java/com/arangodb/impl/InternalEdgeDriverImpl.java deleted file mode 100644 index cf35df946..000000000 --- a/src/main/java/com/arangodb/impl/InternalEdgeDriverImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2012,2013 tamtam180 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arangodb.impl; - -import java.util.Map; - -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoException; -import com.arangodb.InternalCursorDriver; -import com.arangodb.entity.EdgeEntity; -import com.arangodb.entity.EntityFactory; -import com.arangodb.http.HttpManager; -import com.arangodb.http.HttpResponseEntity; -import com.arangodb.util.MapBuilder; - -/** - * @author gschwab - */ -public class InternalEdgeDriverImpl extends BaseArangoDriverWithCursorImpl implements com.arangodb.InternalEdgeDriver { - - InternalEdgeDriverImpl(ArangoConfigure configure, InternalCursorDriver cursorDriver, HttpManager httpManager) { - super(configure, cursorDriver, httpManager); - } - - @Override - public EdgeEntity createEdge( - String database, - String collectionName, - T object, - String from, - String to, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - - Map params = new MapBuilder().put("collection", collectionName).put("from", from).put("to", to) - .put("createCollection", createCollection).put("waitForSync", waitForSync).get(); - - String body = EntityFactory.toJsonString(object); - - HttpResponseEntity response = httpManager.doPost(createEndpointUrl(database, "/_api/edge"), params, body); - - @SuppressWarnings("unchecked") - EdgeEntity edgeEntity = createEntity(response, EdgeEntity.class); - edgeEntity.setEntity(object); - return edgeEntity; - } - -} diff --git a/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java b/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java index 246544439..30c3ef653 100644 --- a/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java @@ -531,22 +531,7 @@ public EdgeEntity createEdge( T value, Boolean waitForSync) throws ArangoException { - JsonObject obj; - if (value == null) { - obj = new JsonObject(); - } else { - JsonElement elem = EntityFactory.toJsonElement(value, false); - if (elem.isJsonObject()) { - obj = elem.getAsJsonObject(); - } else { - throw new IllegalArgumentException("value need object type(not support array, primitive, etc..)."); - } - } - if (key != null) { - obj.addProperty("_key", key); - } - obj.addProperty("_from", fromHandle); - obj.addProperty("_to", toHandle); + JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); validateCollectionName(graphName); HttpResponseEntity res = httpManager.doPost( @@ -566,6 +551,30 @@ public EdgeEntity createEdge( return entity; } + private JsonObject valueToEdgeJsonObject(String key, String fromHandle, String toHandle, T value) { + JsonObject obj; + if (value == null) { + obj = new JsonObject(); + } else { + JsonElement elem = EntityFactory.toJsonElement(value, false); + if (elem.isJsonObject()) { + obj = elem.getAsJsonObject(); + } else { + throw new IllegalArgumentException("value need object type(not support array, primitive, etc..)."); + } + } + if (key != null) { + obj.addProperty("_key", key); + } + if (fromHandle != null) { + obj.addProperty("_from", fromHandle); + } + if (toHandle != null) { + obj.addProperty("_to", toHandle); + } + return obj; + } + @SuppressWarnings("unchecked") @Override public EdgeEntity getEdge( @@ -615,25 +624,35 @@ public EdgeEntity replaceEdge( String graphName, String edgeCollectionName, String key, + String fromHandle, + String toHandle, T value, Boolean waitForSync, Long ifMatchRevision, Long ifNoneMatchRevision) throws ArangoException { + JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); + validateCollectionName(graphName); HttpResponseEntity res = httpManager.doPut( createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(), - new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), - value == null ? null : EntityFactory.toJsonString(value)); + new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(obj)); EdgeEntity entity = createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); if (value != null) { entity.setEntity(value); - annotationHandler.updateDocumentAttributes(entity.getEntity(), entity.getDocumentRevision(), - entity.getDocumentHandle(), entity.getDocumentKey()); + annotationHandler.updateEdgeAttributes(entity.getEntity(), entity.getDocumentRevision(), + entity.getDocumentHandle(), entity.getDocumentKey(), fromHandle, toHandle); + } + if (fromHandle != null) { + entity.setFromVertexHandle(fromHandle); + } + if (toHandle != null) { + entity.setToVertexHandle(toHandle); } + return entity; } @@ -644,26 +663,38 @@ public EdgeEntity updateEdge( String graphName, String edgeCollectionName, String key, + String fromHandle, + String toHandle, T value, Boolean waitForSync, Boolean keepNull, Long ifMatchRevision, Long ifNoneMatchRevision) throws ArangoException { + JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); + validateCollectionName(graphName); HttpResponseEntity res = httpManager.doPatch( createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(), - value == null ? null : EntityFactory.toJsonString(value)); + EntityFactory.toJsonString(obj)); EdgeEntity entity = createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); if (value != null) { entity.setEntity(value); - annotationHandler.updateDocumentAttributes(entity.getEntity(), entity.getDocumentRevision(), - entity.getDocumentHandle(), entity.getDocumentKey()); + annotationHandler.updateEdgeAttributes(entity.getEntity(), entity.getDocumentRevision(), + entity.getDocumentHandle(), entity.getDocumentKey(), fromHandle, toHandle); + } + + if (fromHandle != null) { + entity.setFromVertexHandle(fromHandle); } + if (toHandle != null) { + entity.setToVertexHandle(toHandle); + } + return entity; } diff --git a/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java b/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java index 060b25a92..e897f4e5c 100644 --- a/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java @@ -61,9 +61,6 @@ public IndexEntity createIndex( if (type == IndexType.EDGE) { throw new IllegalArgumentException("cannot create edge index."); } - if (type == IndexType.CAP) { - throw new IllegalArgumentException("cannot create cap index. use createCappedIndex."); - } validateCollectionName(collectionName); HttpResponseEntity res = httpManager.doPost(createIndexEndpointUrl(database), @@ -84,31 +81,6 @@ public IndexEntity createIndex( return createIndex(database, collectionName, type, unique, false, fields); } - @Override - public IndexEntity createCappedIndex(String database, String collectionName, int size) throws ArangoException { - - validateCollectionName(collectionName); - - HttpResponseEntity res = httpManager.doPost(createIndexEndpointUrl(database), - new MapBuilder(COLLECTION, collectionName).get(), EntityFactory.toJsonString( - new MapBuilder().put(TYPE, IndexType.CAP.name().toLowerCase(Locale.US)).put(SIZE, size).get())); - - return createEntity(res, IndexEntity.class); - } - - @Override - public IndexEntity createCappedByDocumentSizeIndex(String database, String collectionName, int byteSize) - throws ArangoException { - - validateCollectionName(collectionName); - - HttpResponseEntity res = httpManager.doPost(createIndexEndpointUrl(database), - new MapBuilder(COLLECTION, collectionName).get(), EntityFactory.toJsonString(new MapBuilder() - .put(TYPE, IndexType.CAP.name().toLowerCase(Locale.US)).put("byteSize", byteSize).get())); - - return createEntity(res, IndexEntity.class); - } - @Override public IndexEntity createFulltextIndex(String database, String collectionName, Integer minLength, String... fields) throws ArangoException { diff --git a/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java b/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java index c6a1d241c..b0857c9b8 100644 --- a/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java @@ -26,7 +26,6 @@ import com.arangodb.InternalCursorDriver; import com.arangodb.entity.CursorEntity; import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.DocumentResultEntity; import com.arangodb.entity.EntityFactory; import com.arangodb.entity.ScalarExampleEntity; import com.arangodb.entity.SimpleByResultEntity; @@ -433,40 +432,6 @@ public DocumentCursor executeSimpleFulltextWithDocuments( return responseToDocumentCursor(database, clazz, res); } - // ----- first -------------------- - - @SuppressWarnings("unchecked") - @Override - public DocumentResultEntity executeSimpleFirst( - String database, - String collectionName, - Integer count, - Class clazz) throws ArangoException { - - validateCollectionName(collectionName); - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/first"), null, - EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put("count", count).get())); - - return createEntity(res, DocumentResultEntity.class, clazz); - } - - // ----- last -------------------- - - @SuppressWarnings("unchecked") - @Override - public DocumentResultEntity executeSimpleLast( - String database, - String collectionName, - Integer count, - Class clazz) throws ArangoException { - - validateCollectionName(collectionName); - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/last"), null, - EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put("count", count).get())); - - return createEntity(res, DocumentResultEntity.class, clazz); - } - // ----- private functions private HttpResponseEntity getSimpleAll(String database, String collectionName, int skip, int limit) diff --git a/src/test/java/com/arangodb/ArangoDriverAsyncTest.java b/src/test/java/com/arangodb/ArangoDriverAsyncTest.java index 18dbdbde2..ba7e987f9 100644 --- a/src/test/java/com/arangodb/ArangoDriverAsyncTest.java +++ b/src/test/java/com/arangodb/ArangoDriverAsyncTest.java @@ -51,6 +51,10 @@ public void before() throws ArangoException { driver.deleteCollection(col); } catch (ArangoException e) { } + try { + driver.createCollection(col); + } catch (ArangoException e) { + } try { driver.stopAsyncMode(); } catch (ArangoException e) { diff --git a/src/test/java/com/arangodb/ArangoDriverBatchTest.java b/src/test/java/com/arangodb/ArangoDriverBatchTest.java index c79c8a6b6..d0ae58e04 100644 --- a/src/test/java/com/arangodb/ArangoDriverBatchTest.java +++ b/src/test/java/com/arangodb/ArangoDriverBatchTest.java @@ -52,6 +52,12 @@ public void before() throws ArangoException { driver.deleteCollection(colName); } catch (ArangoException e) { } + try { + driver.createCollection(colName); + } catch (Exception e) { + e.printStackTrace(); + } + } @After diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentKeyTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentKeyTest.java index bf384c02b..7a20948c3 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentKeyTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentKeyTest.java @@ -60,6 +60,10 @@ public void before() throws ArangoException { driver.deleteCollection("unit_test_arango_001"); } catch (ArangoException e) { } + try { + driver.createCollection("unit_test_arango_001"); + } catch (ArangoException e) { + } } diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java index ff5107dea..71a20de0e 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java @@ -176,6 +176,11 @@ public void test_create_404() throws ArangoException { @Test public void test_create_404_insert() throws ArangoException { + try { + driver.createCollection(collectionName404); + } catch (ArangoException e) { + } + TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // 存在しないコレクションに追加しようとする DocumentEntity res = driver.createDocument(collectionName404, value, true, true); diff --git a/src/test/java/com/arangodb/ArangoDriverEdgeTest.java b/src/test/java/com/arangodb/ArangoDriverEdgeTest.java deleted file mode 100644 index b7a178d39..000000000 --- a/src/test/java/com/arangodb/ArangoDriverEdgeTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2012 tamtam180 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arangodb; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.EdgeEntity; - -/** - * @author tamtam180 - kirscheless at gmail.com - */ -public class ArangoDriverEdgeTest extends BaseTest { - - public ArangoDriverEdgeTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - final String collectionName = "unit_test_edge_collection_EdgeTest"; - final String collectionName2 = "unit_test_normal_collection_EdgeTest"; - - @Before - public void before() throws ArangoException { - try { - driver.deleteCollection(collectionName); - } catch (ArangoException e) { - } - try { - driver.deleteCollection(collectionName2); - } catch (ArangoException e) { - } - } - - @After - public void after() throws ArangoException { - try { - driver.deleteCollection(collectionName); - } catch (ArangoException e) { - } - try { - driver.deleteCollection(collectionName2); - } catch (ArangoException e) { - } - } - - @Test - public void test_create_normal() throws ArangoException { - - TestComplexEntity01 value = new TestComplexEntity01("user", "desc", 42); - DocumentEntity fromDoc = driver.createDocument(collectionName2, value, true, true); - DocumentEntity toDoc = driver.createDocument(collectionName2, value, true, true); - - EdgeEntity doc = driver.createEdge(collectionName, value, fromDoc.getDocumentHandle(), - toDoc.getDocumentHandle(), true, true); - - assertThat(doc.getDocumentKey(), is(notNullValue())); - assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); - assertThat(doc.getDocumentRevision(), is(not(0L))); - - } - -} diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgeReplaceTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgeReplaceTest.java index 1a314ba95..3b6919f56 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgeReplaceTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgeReplaceTest.java @@ -58,7 +58,8 @@ public void test_replace_edge() throws ArangoException { assertThat(edge.getCode(), is(202)); EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), new TestComplexEntity01("xx", "yy", 20)); + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), + new TestComplexEntity01("xx", "yy", 20)); assertThat(replacedEdge.getCode(), is(202)); assertThat(replacedEdge.isError(), is(false)); assertThat(replacedEdge.getDocumentKey(), is(edge.getDocumentKey())); @@ -92,7 +93,7 @@ public void test_replace_edge_null() throws ArangoException { assertThat(edge.getCode(), is(202)); EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), null); + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), null); assertThat(replacedEdge.getCode(), is(202)); assertThat(replacedEdge.isError(), is(false)); assertThat(replacedEdge.getDocumentKey(), is(edge.getDocumentKey())); @@ -124,7 +125,7 @@ public void test_replace_edge_waitForSync() throws ArangoException { assertThat(edge.getCode(), is(202)); EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), null, false, null, null); + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), null, false, null, null); assertThat(replacedEdge.getCode(), is(202)); assertThat(replacedEdge.isError(), is(false)); assertThat(replacedEdge.getDocumentKey(), is(edge.getDocumentKey())); @@ -154,7 +155,8 @@ public void test_replace_edge_rev_eq() throws ArangoException { Long rev = edge.getDocumentRevision(); EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), new TestComplexEntity01("xx", "yy", 20), null, rev, null); + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), + new TestComplexEntity01("xx", "yy", 20), null, rev, null); assertThat(replacedEdge.getCode(), is(202)); assertThat(replacedEdge.isError(), is(false)); assertThat(replacedEdge.getDocumentKey(), is(edge.getDocumentKey())); @@ -189,7 +191,8 @@ public void test_replace_edge_rev_ne() throws ArangoException { try { Long rev = edge.getDocumentRevision() + 1; driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), - new TestComplexEntity01("xx", "yy", 20), null, rev, null); + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, rev, + null); fail(); } catch (ArangoException e) { assertThat(e.getCode(), is(412)); @@ -216,7 +219,8 @@ public void test_replace_edge_match_eq() throws ArangoException { Long rev = edge.getDocumentRevision(); EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), new TestComplexEntity01("xx", "yy", 20), null, rev, null); + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), + new TestComplexEntity01("xx", "yy", 20), null, rev, null); assertThat(replacedEdge.getCode(), is(202)); assertThat(replacedEdge.isError(), is(false)); assertThat(replacedEdge.getDocumentKey(), is(edge.getDocumentKey())); @@ -252,7 +256,8 @@ public void test_replace_edge_match_ne() throws ArangoException { try { Long rev = edge.getDocumentRevision() + 1; driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), - new TestComplexEntity01("xx", "yy", 20), null, rev, null); + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, rev, + null); fail(); } catch (ArangoException e) { assertThat(e.getCode(), is(412)); @@ -262,4 +267,43 @@ public void test_replace_edge_match_ne() throws ArangoException { } + @Test + public void test_replace_from_to() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); + + EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + assertThat(edge.getCode(), is(202)); + + Long rev = edge.getDocumentRevision(); + EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), v2.getDocumentHandle(), v1.getDocumentHandle(), edge.getEntity(), null, rev, null); + + assertThat(replacedEdge.getCode(), is(202)); + assertThat(replacedEdge.isError(), is(false)); + assertThat(replacedEdge.getDocumentKey(), is(edge.getDocumentKey())); + assertThat(replacedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); + assertThat(replacedEdge.getFromVertexHandle(), is(v2.getDocumentHandle())); + assertThat(replacedEdge.getToVertexHandle(), is(v1.getDocumentHandle())); + + replacedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), + TestComplexEntity02.class); + + assertThat(replacedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); + assertThat(replacedEdge.getFromVertexHandle(), is(v2.getDocumentHandle())); + assertThat(replacedEdge.getToVertexHandle(), is(v1.getDocumentHandle())); + assertThat(replacedEdge.getEntity(), instanceOf(TestComplexEntity02.class)); + assertThat(replacedEdge.getEntity().getX(), is(1)); + assertThat(replacedEdge.getEntity().getY(), is(2)); + assertThat(replacedEdge.getEntity().getZ(), is(3)); + + } + } diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgeUpdateTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgeUpdateTest.java index fd5e1ddc4..84cd9352a 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgeUpdateTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgeUpdateTest.java @@ -33,230 +33,235 @@ public class ArangoDriverGraphEdgeUpdateTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String edgeCollectionName = "edge-1"; - - public ArangoDriverGraphEdgeUpdateTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - @Test - public void test_graphUpdateEdge() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", - new TestComplexEntity01("v2-user", "desc2", 12), null); - driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); - driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, - v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - assertThat(edge.getCode(), is(202)); - - EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), new TestComplexEntity01("xx", "yy", 20), true); - assertThat(updatedEdge.getCode(), is(202)); - assertThat(updatedEdge.isError(), is(false)); - assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); - assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); - assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); - updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, updatedEdge.getDocumentKey(), - TestComplexEntity01.class); - assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); - assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); - - assertThat(updatedEdge.getEntity(), instanceOf(TestComplexEntity01.class)); - assertThat(updatedEdge.getEntity().getUser(), is("xx")); - assertThat(updatedEdge.getEntity().getDesc(), is("yy")); - assertThat(updatedEdge.getEntity().getAge(), is(20)); - - } - - @Test - public void test_updateEdge_null() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", - new TestComplexEntity01("v2-user", "desc2", 12), null); - driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); - driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, - v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - assertThat(edge.getCode(), is(202)); - - EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), null, null); - assertThat(updatedEdge.getCode(), is(202)); - assertThat(updatedEdge.isError(), is(false)); - assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); - assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); - assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); - - updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, updatedEdge.getDocumentKey(), null); - - assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); - assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); - assertThat(updatedEdge.getEntity(), is(nullValue())); - - } - - @Test - public void test_updateEdge_waitForSync() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", - new TestComplexEntity01("v2-user", "desc2", 12), null); - driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); - driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, - v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - assertThat(edge.getCode(), is(202)); - - EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), null, false, true, null, null); - assertThat(updatedEdge.getCode(), is(202)); - assertThat(updatedEdge.isError(), is(false)); - assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); - assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); - assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); - updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), null); - assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); - assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); - assertThat(updatedEdge.getEntity(), is(nullValue())); - - } - - @Test - public void test_updateEdge_rev_eq() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", - new TestComplexEntity01("v2-user", "desc2", 12), null); - driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); - driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, - v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - assertThat(edge.getCode(), is(202)); - - Long rev = edge.getDocumentRevision(); - EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); - assertThat(updatedEdge.getCode(), is(202)); - assertThat(updatedEdge.isError(), is(false)); - assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); - assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); - assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); - updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), - TestComplexEntity01.class); - assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); - assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); - assertThat(updatedEdge.getEntity(), instanceOf(TestComplexEntity01.class)); - assertThat(updatedEdge.getEntity().getUser(), is("xx")); - assertThat(updatedEdge.getEntity().getDesc(), is("yy")); - assertThat(updatedEdge.getEntity().getAge(), is(20)); - - } - - @Test - public void test_updateEdge_rev_ne() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", - new TestComplexEntity01("v2-user", "desc2", 12), null); - driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); - driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, - v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - assertThat(edge.getCode(), is(202)); - - try { - Long rev = edge.getDocumentRevision() + 1; - driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), - new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(412)); - assertThat(e.getErrorNumber(), is(1903)); - assertThat(e.getErrorMessage(), is("wrong revision")); - } - - } - - @Test - public void test_updateEdge_match_eq() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", - new TestComplexEntity01("v2-user", "desc2", 12), null); - driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); - driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, - v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - assertThat(edge.getCode(), is(202)); - - Long rev = edge.getDocumentRevision(); - EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, - edge.getDocumentKey(), new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); - - assertThat(updatedEdge.getCode(), is(202)); - assertThat(updatedEdge.isError(), is(false)); - assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); - assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); - updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), - TestComplexEntity01.class); - assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); - assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); - assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); - - assertThat(updatedEdge.getEntity(), instanceOf(TestComplexEntity01.class)); - assertThat(updatedEdge.getEntity().getUser(), is("xx")); - assertThat(updatedEdge.getEntity().getDesc(), is("yy")); - assertThat(updatedEdge.getEntity().getAge(), is(20)); - - } - - @Test - public void test_updateEdge_match_ne() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", - new TestComplexEntity01("v2-user", "desc2", 12), null); - driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); - driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, - v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - assertThat(edge.getCode(), is(202)); - - try { - Long rev = edge.getDocumentRevision() + 1; - driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), - new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(412)); - assertThat(e.getErrorNumber(), is(1903)); - assertThat(e.getErrorMessage(), is("wrong revision")); - } - - } + String graphName = "UnitTestGraph"; + String edgeCollectionName = "edge-1"; + + public ArangoDriverGraphEdgeUpdateTest(ArangoConfigure configure, ArangoDriver driver) { + super(configure, driver); + } + + @Test + public void test_graphUpdateEdge() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); + + EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + assertThat(edge.getCode(), is(202)); + + EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), + new TestComplexEntity01("xx", "yy", 20), true); + assertThat(updatedEdge.getCode(), is(202)); + assertThat(updatedEdge.isError(), is(false)); + assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); + assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); + assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); + updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, updatedEdge.getDocumentKey(), + TestComplexEntity01.class); + assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); + assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); + + assertThat(updatedEdge.getEntity(), instanceOf(TestComplexEntity01.class)); + assertThat(updatedEdge.getEntity().getUser(), is("xx")); + assertThat(updatedEdge.getEntity().getDesc(), is("yy")); + assertThat(updatedEdge.getEntity().getAge(), is(20)); + + } + + @Test + public void test_updateEdge_null() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); + + EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + assertThat(edge.getCode(), is(202)); + + EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); + assertThat(updatedEdge.getCode(), is(202)); + assertThat(updatedEdge.isError(), is(false)); + assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); + assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); + assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); + + updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, updatedEdge.getDocumentKey(), null); + + assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); + assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); + assertThat(updatedEdge.getEntity(), is(nullValue())); + + } + + @Test + public void test_updateEdge_waitForSync() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); + + EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + assertThat(edge.getCode(), is(202)); + + EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), null, false, true, null, null); + assertThat(updatedEdge.getCode(), is(202)); + assertThat(updatedEdge.isError(), is(false)); + assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); + assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); + assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); + updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), null); + assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); + assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); + assertThat(updatedEdge.getEntity(), is(nullValue())); + + } + + @Test + public void test_updateEdge_rev_eq() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); + + EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + assertThat(edge.getCode(), is(202)); + + Long rev = edge.getDocumentRevision(); + EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), + new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); + assertThat(updatedEdge.getCode(), is(202)); + assertThat(updatedEdge.isError(), is(false)); + assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); + assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); + assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); + updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), + TestComplexEntity01.class); + assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); + assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); + assertThat(updatedEdge.getEntity(), instanceOf(TestComplexEntity01.class)); + assertThat(updatedEdge.getEntity().getUser(), is("xx")); + assertThat(updatedEdge.getEntity().getDesc(), is("yy")); + assertThat(updatedEdge.getEntity().getAge(), is(20)); + + } + + @Test + public void test_updateEdge_rev_ne() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); + + EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + assertThat(edge.getCode(), is(202)); + + try { + Long rev = edge.getDocumentRevision() + 1; + driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, null, + rev, null); + fail(); + } catch (ArangoException e) { + assertThat(e.getCode(), is(412)); + assertThat(e.getErrorNumber(), is(1903)); + assertThat(e.getErrorMessage(), is("wrong revision")); + } + + } + + @Test + public void test_updateEdge_match_eq() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); + + EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + assertThat(edge.getCode(), is(202)); + + Long rev = edge.getDocumentRevision(); + EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), + new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); + + assertThat(updatedEdge.getCode(), is(202)); + assertThat(updatedEdge.isError(), is(false)); + assertThat(updatedEdge.getDocumentKey(), is(edge.getDocumentKey())); + assertThat(updatedEdge.getDocumentRevision(), is(not(edge.getDocumentRevision()))); + updatedEdge = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), + TestComplexEntity01.class); + assertThat(updatedEdge.getDocumentHandle(), is(edge.getDocumentHandle())); + assertThat(updatedEdge.getFromVertexHandle(), is(v1.getDocumentHandle())); + assertThat(updatedEdge.getToVertexHandle(), is(v2.getDocumentHandle())); + + assertThat(updatedEdge.getEntity(), instanceOf(TestComplexEntity01.class)); + assertThat(updatedEdge.getEntity().getUser(), is("xx")); + assertThat(updatedEdge.getEntity().getDesc(), is("yy")); + assertThat(updatedEdge.getEntity().getAge(), is(20)); + + } + + @Test + public void test_updateEdge_match_ne() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); + + EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + assertThat(edge.getCode(), is(202)); + + try { + Long rev = edge.getDocumentRevision() + 1; + driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), + v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, null, + rev, null); + fail(); + } catch (ArangoException e) { + assertThat(e.getCode(), is(412)); + assertThat(e.getErrorNumber(), is(1903)); + assertThat(e.getErrorMessage(), is("wrong revision")); + } + + } } diff --git a/src/test/java/com/arangodb/ArangoDriverIndexTest.java b/src/test/java/com/arangodb/ArangoDriverIndexTest.java index 0e0a25d74..d6fd55a2a 100644 --- a/src/test/java/com/arangodb/ArangoDriverIndexTest.java +++ b/src/test/java/com/arangodb/ArangoDriverIndexTest.java @@ -345,59 +345,6 @@ public void test_create_hash_index_dup_unique() throws ArangoException { } - @Test - public void test_create_cap_index() throws ArangoException { - - IndexEntity entity = driver.createCappedIndex(collectionName, 10); - - assertThat(entity, is(notNullValue())); - assertThat(entity.getCode(), is(201)); - assertThat(entity.isError(), is(false)); - assertThat(entity.isNewlyCreated(), is(true)); - assertThat(entity.getSize(), is(10)); - assertThat(entity.getId(), is(notNullValue())); - assertThat(entity.getType(), is(IndexType.CAP)); - - // 確認 ピンポイントで取得 - IndexEntity entity2 = driver.getIndex(entity.getId()); - assertThat(entity2.getCode(), is(200)); - assertThat(entity2.isError(), is(false)); - assertThat(entity2.isNewlyCreated(), is(false)); - assertThat(entity2.getSize(), is(10)); - assertThat(entity2.getId(), is(entity.getId())); - assertThat(entity2.getType(), is(IndexType.CAP)); - - // 確認 インデックス一覧を取得 - IndexesEntity indexes = driver.getIndexes(collectionName); - assertThat(indexes.getCode(), is(200)); - assertThat(indexes.isError(), is(false)); - assertThat(indexes.getIndexes().size(), is(2)); - - String pkHandle = col1.getName() + "/0"; - IndexEntity pk = indexes.getIdentifiers().get(pkHandle); - assertThat(pk.getType(), is(IndexType.PRIMARY)); - assertThat(pk.getFields().size(), is(1)); - assertThat(pk.getFields().get(0), is("_key")); - - IndexEntity idx1 = indexes.getIdentifiers().get(entity.getId()); - assertThat(idx1.getType(), is(IndexType.CAP)); - assertThat(idx1.getFields(), is(nullValue())); - assertThat(idx1.getSize(), is(10)); - - } - - @Test - public void test_create_cap_index_404() throws ArangoException { - - try { - driver.createCappedIndex(collectionName404, 10); - fail("例外が飛ばないといけない"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(1203)); - } - - } - @Test public void test_getIndexes() throws ArangoException { @@ -414,8 +361,8 @@ public void test_getIndexes() throws ArangoException { assertThat(indexes.getIndexes().get(0).getFields().get(0), is("_key")); assertThat(indexes.getIndexes().get(1).getType(), is(IndexType.HASH)); assertThat(indexes.getIndexes().get(1).getFields().size(), is(2)); - assertThat(indexes.getIndexes().get(1).getFields().get(0), is("name")); - assertThat(indexes.getIndexes().get(1).getFields().get(1), is("age")); + assertThat(indexes.getIndexes().get(1).getFields().get(1), is("name")); + assertThat(indexes.getIndexes().get(1).getFields().get(0), is("age")); String id1 = indexes.getIndexes().get(0).getId(); String id2 = indexes.getIndexes().get(1).getId(); @@ -426,8 +373,8 @@ public void test_getIndexes() throws ArangoException { assertThat(indexes.getIdentifiers().get(id1).getFields().get(0), is("_key")); assertThat(indexes.getIdentifiers().get(id2).getType(), is(IndexType.HASH)); assertThat(indexes.getIdentifiers().get(id2).getFields().size(), is(2)); - assertThat(indexes.getIdentifiers().get(id2).getFields().get(0), is("name")); - assertThat(indexes.getIdentifiers().get(id2).getFields().get(1), is("age")); + assertThat(indexes.getIdentifiers().get(id2).getFields().get(1), is("name")); + assertThat(indexes.getIdentifiers().get(id2).getFields().get(0), is("age")); } diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java index b41c2ca29..771ab2fb5 100644 --- a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java +++ b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java @@ -35,7 +35,6 @@ import org.slf4j.LoggerFactory; import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.DocumentResultEntity; import com.arangodb.entity.IndexType; import com.arangodb.entity.ScalarExampleEntity; import com.arangodb.entity.SimpleByResultEntity; @@ -650,172 +649,4 @@ public void test_geo() throws ArangoException, IOException { } - @Test - public void test_first() throws ArangoException { - - // server returns object-type - DocumentResultEntity entity = driver.executeSimpleFirst(COLLECTION_NAME, null, - TestComplexEntity01.class); - assertThat(entity.getCode(), is(200)); - assertThat(entity.isError(), is(false)); - assertThat(entity.getResult().size(), is(1)); - - DocumentEntity obj = entity.getOne(); - assertThat(obj.getDocumentHandle(), is(notNullValue())); - assertThat(obj.getDocumentRevision(), is(not(0L))); - assertThat(obj.getDocumentKey(), is(notNullValue())); - - assertThat(obj.getEntity().getAge(), is(0)); - assertThat(obj.getEntity().getUser(), is("user_0")); - assertThat(obj.getEntity().getDesc(), is("desc0")); - - } - - @Test - public void test_first_count1() throws ArangoException { - - // count = null と count = 1はサーバが返してくるresultの戻りの型が違う - // server returns array-type - DocumentResultEntity entity = driver.executeSimpleFirst(COLLECTION_NAME, 1, - TestComplexEntity01.class); - assertThat(entity.getCode(), is(200)); - assertThat(entity.isError(), is(false)); - assertThat(entity.getResult().size(), is(1)); - - DocumentEntity obj = entity.getOne(); - assertThat(obj.getDocumentHandle(), is(notNullValue())); - assertThat(obj.getDocumentRevision(), is(not(0L))); - assertThat(obj.getDocumentKey(), is(notNullValue())); - - assertThat(obj.getEntity().getAge(), is(0)); - assertThat(obj.getEntity().getUser(), is("user_0")); - assertThat(obj.getEntity().getDesc(), is("desc0")); - - } - - @Test - public void test_first_count5() throws ArangoException { - - DocumentResultEntity entity = driver.executeSimpleFirst(COLLECTION_NAME, 5, - TestComplexEntity01.class); - assertThat(entity.getCode(), is(200)); - assertThat(entity.isError(), is(false)); - assertThat(entity.getResult().size(), is(5)); - - DocumentEntity obj = entity.getOne(); - assertThat(obj.getDocumentHandle(), is(notNullValue())); - assertThat(obj.getDocumentRevision(), is(not(0L))); - assertThat(obj.getDocumentKey(), is(notNullValue())); - - assertThat(obj.getEntity().getAge(), is(0)); - assertThat(obj.getEntity().getUser(), is("user_0")); - assertThat(obj.getEntity().getDesc(), is("desc0")); - - DocumentEntity obj4 = entity.getResult().get(4); - assertThat(obj4.getDocumentHandle(), is(notNullValue())); - assertThat(obj4.getDocumentRevision(), is(not(0L))); - assertThat(obj4.getDocumentKey(), is(notNullValue())); - - assertThat(obj4.getEntity().getAge(), is(4)); - assertThat(obj4.getEntity().getUser(), is("user_4")); - assertThat(obj4.getEntity().getDesc(), is("desc4")); - - } - - @Test - public void test_first_400() throws ArangoException { - try { - driver.executeSimpleFirst(COLLECTION_NAME_400, 1, TestComplexEntity01.class); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(400)); - assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_TYPE_ERROR)); - } - - } - - @Test - public void test_last() throws ArangoException { - - // server returns object-type - DocumentResultEntity entity = driver.executeSimpleLast(COLLECTION_NAME, null, - TestComplexEntity01.class); - assertThat(entity.getCode(), is(200)); - assertThat(entity.isError(), is(false)); - assertThat(entity.getResult().size(), is(1)); - - DocumentEntity obj = entity.getOne(); - assertThat(obj.getDocumentHandle(), is(notNullValue())); - assertThat(obj.getDocumentRevision(), is(not(0L))); - assertThat(obj.getDocumentKey(), is(notNullValue())); - - assertThat(obj.getEntity().getAge(), is(99)); - assertThat(obj.getEntity().getUser(), is("user_9")); - assertThat(obj.getEntity().getDesc(), is("desc9")); - - } - - @Test - public void test_last_count1() throws ArangoException { - - // count = null と count = 1はサーバが返してくるresultの戻りの型が違う - // server returns array-type - DocumentResultEntity entity = driver.executeSimpleLast(COLLECTION_NAME, 1, - TestComplexEntity01.class); - assertThat(entity.getCode(), is(200)); - assertThat(entity.isError(), is(false)); - assertThat(entity.getResult().size(), is(1)); - - DocumentEntity obj = entity.getOne(); - assertThat(obj.getDocumentHandle(), is(notNullValue())); - assertThat(obj.getDocumentRevision(), is(not(0L))); - assertThat(obj.getDocumentKey(), is(notNullValue())); - - assertThat(obj.getEntity().getAge(), is(99)); - assertThat(obj.getEntity().getUser(), is("user_9")); - assertThat(obj.getEntity().getDesc(), is("desc9")); - - } - - @Test - public void test_last_count5() throws ArangoException { - - DocumentResultEntity entity = driver.executeSimpleLast(COLLECTION_NAME, 5, - TestComplexEntity01.class); - assertThat(entity.getCode(), is(200)); - assertThat(entity.isError(), is(false)); - assertThat(entity.getResult().size(), is(5)); - - DocumentEntity obj = entity.getOne(); - assertThat(obj.getDocumentHandle(), is(notNullValue())); - assertThat(obj.getDocumentRevision(), is(not(0L))); - assertThat(obj.getDocumentKey(), is(notNullValue())); - - assertThat(obj.getEntity().getAge(), is(99)); - assertThat(obj.getEntity().getUser(), is("user_9")); - assertThat(obj.getEntity().getDesc(), is("desc9")); - - DocumentEntity obj4 = entity.getResult().get(4); - assertThat(obj4.getDocumentHandle(), is(notNullValue())); - assertThat(obj4.getDocumentRevision(), is(not(0L))); - assertThat(obj4.getDocumentKey(), is(notNullValue())); - - assertThat(obj4.getEntity().getAge(), is(95)); - assertThat(obj4.getEntity().getUser(), is("user_5")); - assertThat(obj4.getEntity().getDesc(), is("desc5")); - - } - - @Test - public void test_last_400() throws ArangoException { - try { - driver.executeSimpleLast(COLLECTION_NAME_400, 1, TestComplexEntity01.class); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(400)); - assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_TYPE_ERROR)); - } - - } - } diff --git a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java index 8423cd14b..789d20355 100644 --- a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java @@ -72,6 +72,16 @@ public ArangoDriverTransactionTest(ArangoConfigure configure, ArangoDriver drive public void setup() throws ArangoException { TestComplexEntity01 value = new TestComplexEntity01("user-" + 9999, "desc:" + 9999, 9999); driver.createDocument("someCollection", value, true, false); + try { + driver.deleteCollection("someCollection"); + } catch (ArangoException e) { + + } + try { + driver.createCollection("someCollection"); + } catch (ArangoException e) { + + } } @After diff --git a/src/test/java/com/arangodb/BaseDocumentTest.java b/src/test/java/com/arangodb/BaseDocumentTest.java index e02ed5feb..da74c9526 100644 --- a/src/test/java/com/arangodb/BaseDocumentTest.java +++ b/src/test/java/com/arangodb/BaseDocumentTest.java @@ -158,7 +158,7 @@ public void save_document() throws ArangoException { assertThat(v1DB.getDocumentRevision(), is(not(0L))); assertThat(v1DB.getDocumentKey(), is(notNullValue())); Map dbProperties = v1DB.getEntity().getProperties(); - dbProperties.get(key1); + Object x = dbProperties.get(key1); assertThat((String) v1DB.getEntity().getProperties().get(key1), is(val1)); assertThat((Double) v1DB.getEntity().getProperties().get(key2), is(val2)); diff --git a/src/test/java/com/arangodb/NegativeTest.java b/src/test/java/com/arangodb/NegativeTest.java index 0ec039a67..caaeb8d8c 100644 --- a/src/test/java/com/arangodb/NegativeTest.java +++ b/src/test/java/com/arangodb/NegativeTest.java @@ -55,7 +55,8 @@ public void test_collections() throws ArangoException { // TODO Create configure of common test. HttpResponseEntity res = httpManager.doGet("http://" + configure.getArangoHost().getHost() + ":" - + configure.getArangoHost().getPort() + "/_api/collections", null); + + configure.getArangoHost().getPort() + "/_api/collections", + null); DefaultEntity entity = EntityFactory.createEntity(res.getText(), DefaultEntity.class); assertThat(entity.isError(), is(true)); @@ -85,6 +86,11 @@ public void test_issue_35_and_41() throws Exception { configure.init(); ArangoDriver driver = new ArangoDriver(configure); + try { + driver.createCollection("unit_test_issue35"); + } catch (ArangoException e) { + } + TestComplex value = new TestComplex(); value.setName("A\"A'@:///A"); @@ -104,6 +110,11 @@ public void test_primitive() throws Exception { configure.init(); ArangoDriver driver = new ArangoDriver(configure); + try { + driver.createCollection("unit_test_issue35"); + } catch (ArangoException e) { + } + try { String value = "AAA"; DocumentEntity doc = driver.createDocument("unit_test_issue35", value, true, true); diff --git a/src/test/java/com/arangodb/PrimitiveDocumentTest.java b/src/test/java/com/arangodb/PrimitiveDocumentTest.java index 419bc0b48..e9a77dbb4 100644 --- a/src/test/java/com/arangodb/PrimitiveDocumentTest.java +++ b/src/test/java/com/arangodb/PrimitiveDocumentTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; @@ -40,6 +41,15 @@ public PrimitiveDocumentTest(ArangoConfigure configure, ArangoDriver driver) { super(configure, driver); } + @Before + public void setUp() { + try { + driver.createCollection("unit_test_primitive"); + } catch (ArangoException e) { + } + + } + @Test public void test_string() throws ArangoException { From d9734e47587efb37da7fc7fff1938013f97797af Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 20 May 2016 10:05:07 +0200 Subject: [PATCH 03/56] fixed docu --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59adaeb45..093c7332c 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ ArangoDB 2.7.x and ArangoDB 2.8.x: com.arangodb arangodb-java-driver - 3.0.0 + 2.7.4 .... diff --git a/pom.xml b/pom.xml index 517b9b37e..842252030 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-java-driver - 2.7.5-SNAPSHOT + 3.0.0-SNAPSHOT 2012 jar From 6e0e202072d7bfb815f30286ffdc87243ec275c7 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 20 May 2016 12:57:55 +0200 Subject: [PATCH 04/56] added version 3.0.0 --- tests/travis/setup_arangodb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/travis/setup_arangodb.sh b/tests/travis/setup_arangodb.sh index d52f39c97..f481be795 100644 --- a/tests/travis/setup_arangodb.sh +++ b/tests/travis/setup_arangodb.sh @@ -3,7 +3,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR -VERSION=2.8.7 +VERSION=3.0.0 NAME=ArangoDB-$VERSION if [ ! -d "$DIR/$NAME" ]; then @@ -34,7 +34,7 @@ ${ARANGOD} \ --server.keyfile ./server.pem \ --javascript.app-path ${ARANGODB_DIR}/js/apps \ --javascript.startup-directory ${ARANGODB_DIR}/js \ - --server.disable-authentication false & + --server.authentication=true & sleep 2 From 5b6d9a6a500813e54d3c5b061021a73b31626734 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 20 May 2016 14:34:59 +0200 Subject: [PATCH 05/56] fixes for ArangoDB 3.0.0 --- src/main/java/com/arangodb/ArangoClient.java | 20 +- src/main/java/com/arangodb/ArangoDriver.java | 55 +- .../com/arangodb/InternalDocumentDriver.java | 2 +- .../com/arangodb/InternalImportDriver.java | 11 +- .../arangodb/entity/CollectionsEntity.java | 23 +- .../arangodb/entity/EntityDeserializers.java | 12 +- .../com/arangodb/entity/EntityFactory.java | 1 + .../impl/InternalDocumentDriverImpl.java | 21 +- .../impl/InternalImportDriverImpl.java | 16 +- .../arangodb/ArangoDriverCollectionTest.java | 1390 ++++++++--------- .../com/arangodb/ArangoDriverCursorTest.java | 3 +- .../arangodb/ArangoDriverDocumentTest.java | 2 +- .../com/arangodb/ArangoDriverImportTest.java | 29 +- .../ArangoDriverReplicationTestScenario1.java | 2 +- .../ImportDocumentBenchmarkImporter.java | 7 +- .../arangodb/sandbox/ImportNico2Video.java | 2 +- 16 files changed, 771 insertions(+), 825 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoClient.java b/src/main/java/com/arangodb/ArangoClient.java index dfac11499..664d56743 100644 --- a/src/main/java/com/arangodb/ArangoClient.java +++ b/src/main/java/com/arangodb/ArangoClient.java @@ -36,22 +36,16 @@ public ArangoClient(ArangoConfigure configure) { driver = new ArangoDriver(configure); } - private void importDocumentsImpl( - String collectionName, - boolean createCollection, - List values, - ImportResultEntity total) throws ArangoException { - ImportResultEntity result = driver.importDocuments(collectionName, createCollection, values); + private void importDocumentsImpl(String collectionName, List values, ImportResultEntity total) + throws ArangoException { + ImportResultEntity result = driver.importDocuments(collectionName, values); total.setCreated(total.getCreated() + result.getCreated()); total.setErrors(total.getErrors() + result.getErrors()); total.setEmpty(total.getEmpty() + result.getEmpty()); } - public ImportResultEntity importRawJsonDocuments( - String collectionName, - boolean createCollection, - Iterator itr, - int bufferCount) throws ArangoException { + public ImportResultEntity importRawJsonDocuments(String collectionName, Iterator itr, int bufferCount) + throws ArangoException { int tmpBufferCount = bufferCount; if (tmpBufferCount <= 0) { @@ -64,12 +58,12 @@ public ImportResultEntity importRawJsonDocuments( while (itr.hasNext()) { buffers.add(itr.next()); if (buffers.size() % tmpBufferCount == 0) { - importDocumentsImpl(collectionName, createCollection, buffers, total); + importDocumentsImpl(collectionName, buffers, total); buffers.clear(); } } if (!buffers.isEmpty()) { - importDocumentsImpl(collectionName, createCollection, buffers, total); + importDocumentsImpl(collectionName, buffers, total); } return total; diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 704dd47f4..703af2595 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -1608,18 +1608,6 @@ public DocumentEntity updateDocument( keepNull); } - /** - * This method returns all document handles from a collection. - * - * @param collectionId - * The collection id. - * @return List - The list of document handles - * @throws ArangoException - */ - public List getDocuments(long collectionId) throws ArangoException { - return getDocuments(String.valueOf(collectionId), false); - } - /** * This method returns all document handles from a collection. * @@ -1629,35 +1617,7 @@ public List getDocuments(long collectionId) throws ArangoException { * @throws ArangoException */ public List getDocuments(String collectionName) throws ArangoException { - return documentDriver.getDocuments(getDefaultDatabase(), collectionName, false); - } - - /** - * This method returns all document handles from a collection. - * - * @param collectionId - * The collection id. - * @param handleConvert - * if set to true only the document identifiers are returned - * @return List - The list of document handles - * @throws ArangoException - */ - public List getDocuments(long collectionId, boolean handleConvert) throws ArangoException { - return getDocuments(String.valueOf(collectionId), handleConvert); - } - - /** - * This method returns all document handles from a collection. - * - * @param collectionName - * The collection name. - * @param handleConvert - * if set to true only the document identifiers are returned - * @return List - The list of document handles - * @throws ArangoException - */ - public List getDocuments(String collectionName, boolean handleConvert) throws ArangoException { - return documentDriver.getDocuments(getDefaultDatabase(), collectionName, handleConvert); + return documentDriver.getDocuments(getDefaultDatabase(), collectionName); } /** @@ -3713,16 +3673,13 @@ public List getUsers() throws ArangoException { * * @param collection * the collection as a string - * @param createCollection - * if set to true the collection is created if it does not exist * @param values * a list of Objects that will be stored as documents * @return ImportResultEntity * @throws ArangoException */ - public ImportResultEntity importDocuments(String collection, Boolean createCollection, Collection values) - throws ArangoException { - return importDriver.importDocuments(getDefaultDatabase(), collection, createCollection, values); + public ImportResultEntity importDocuments(String collection, Collection values) throws ArangoException { + return importDriver.importDocuments(getDefaultDatabase(), collection, values); } /** @@ -3730,8 +3687,6 @@ public ImportResultEntity importDocuments(String collection, Boolean createColle * * @param collection * the collection as a string - * @param createCollection - * if set to true the collection is created if it does not exist * @param headerValues * a list of lists that will be stored as documents * @return ImportResultEntity @@ -3739,10 +3694,8 @@ public ImportResultEntity importDocuments(String collection, Boolean createColle */ public ImportResultEntity importDocumentsByHeaderValues( String collection, - Boolean createCollection, Collection> headerValues) throws ArangoException { - return importDriver.importDocumentsByHeaderValues(getDefaultDatabase(), collection, createCollection, - headerValues); + return importDriver.importDocumentsByHeaderValues(getDefaultDatabase(), collection, headerValues); } /** diff --git a/src/main/java/com/arangodb/InternalDocumentDriver.java b/src/main/java/com/arangodb/InternalDocumentDriver.java index 5fa216b78..c251b4104 100644 --- a/src/main/java/com/arangodb/InternalDocumentDriver.java +++ b/src/main/java/com/arangodb/InternalDocumentDriver.java @@ -59,7 +59,7 @@ DocumentEntity updateDocumentRaw( Boolean waitForSync, Boolean keepNull) throws ArangoException; - List getDocuments(String database, String collectionName, boolean handleConvert) throws ArangoException; + List getDocuments(String database, String collectionName) throws ArangoException; long checkDocument(String database, String documentHandle) throws ArangoException; diff --git a/src/main/java/com/arangodb/InternalImportDriver.java b/src/main/java/com/arangodb/InternalImportDriver.java index befad3291..ab773307d 100644 --- a/src/main/java/com/arangodb/InternalImportDriver.java +++ b/src/main/java/com/arangodb/InternalImportDriver.java @@ -8,8 +8,13 @@ /** * Created by fbartels on 10/27/14. */ -public interface InternalImportDriver extends BaseDriverInterface { - ImportResultEntity importDocuments(String database, String collection, Boolean createCollection, Collection values) throws ArangoException; +public interface InternalImportDriver extends BaseDriverInterface { + + ImportResultEntity importDocuments(String database, String collection, Collection values) throws ArangoException; + + ImportResultEntity importDocumentsByHeaderValues( + String database, + String collection, + Collection> headerValues) throws ArangoException; - ImportResultEntity importDocumentsByHeaderValues(String database, String collection, Boolean createCollection, Collection> headerValues) throws ArangoException; } diff --git a/src/main/java/com/arangodb/entity/CollectionsEntity.java b/src/main/java/com/arangodb/entity/CollectionsEntity.java index 50e4863f5..4cc99f8ff 100644 --- a/src/main/java/com/arangodb/entity/CollectionsEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionsEntity.java @@ -16,9 +16,12 @@ package com.arangodb.entity; +import java.util.HashMap; import java.util.List; import java.util.Map; +import com.arangodb.util.CollectionUtils; + /** * A entity representing a list of ArangoDB collections * @@ -30,19 +33,21 @@ public class CollectionsEntity extends BaseEntity { /** * The list of collections */ - List collections; - - /** - * A map containing the collection names as keys and the collections as - * values - */ - Map names; + private List collections; public List getCollections() { return collections; } public Map getNames() { + Map names = new HashMap(); + + if (CollectionUtils.isNotEmpty(collections)) { + for (CollectionEntity collectionEntity : collections) { + names.put(collectionEntity.getName(), collectionEntity); + } + } + return names; } @@ -50,10 +55,6 @@ public void setCollections(List collections) { this.collections = collections; } - public void setNames(Map names) { - this.names = names; - } - @Override public String toString() { return "CollectionsEntity [collections=" + collections + "]"; diff --git a/src/main/java/com/arangodb/entity/EntityDeserializers.java b/src/main/java/com/arangodb/entity/EntityDeserializers.java index 953a78e4a..8460334be 100644 --- a/src/main/java/com/arangodb/entity/EntityDeserializers.java +++ b/src/main/java/com/arangodb/entity/EntityDeserializers.java @@ -537,9 +537,8 @@ public CollectionEntity deserialize(JsonElement json, Type typeOfT, JsonDeserial public static class CollectionsEntityDeserializer implements JsonDeserializer { private Type collectionsType = new TypeToken>() { }.getType(); - private Type namesType = new TypeToken>() { - }.getType(); + @SuppressWarnings("unchecked") @Override public CollectionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { @@ -550,11 +549,10 @@ public CollectionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeseria JsonObject obj = json.getAsJsonObject(); CollectionsEntity entity = deserializeBaseParameter(obj, new CollectionsEntity()); - if (obj.has(COLLECTIONS)) { - entity.collections = context.deserialize(obj.get(COLLECTIONS), collectionsType); - } - if (obj.has("names")) { - entity.names = context.deserialize(obj.get("names"), namesType); + if (obj.has(RESULT)) { + entity.setCollections((List) context.deserialize(obj.get(RESULT), collectionsType)); + } else { + entity.setCollections(new ArrayList()); } return entity; diff --git a/src/main/java/com/arangodb/entity/EntityFactory.java b/src/main/java/com/arangodb/entity/EntityFactory.java index ba1a656e1..71710a6f3 100644 --- a/src/main/java/com/arangodb/entity/EntityFactory.java +++ b/src/main/java/com/arangodb/entity/EntityFactory.java @@ -59,6 +59,7 @@ public static GsonBuilder getGsonBuilder() { .setFieldNamingStrategy(new ArangoFieldNamingStrategy()) .registerTypeAdapter(CollectionStatus.class, new CollectionStatusTypeAdapter()) .registerTypeAdapter(CollectionEntity.class, new EntityDeserializers.CollectionEntityDeserializer()) + .registerTypeAdapter(CollectionsEntity.class, new EntityDeserializers.CollectionsEntityDeserializer()) .registerTypeAdapter(DocumentEntity.class, new EntityDeserializers.DocumentEntityDeserializer()) .registerTypeAdapter(DocumentsEntity.class, new EntityDeserializers.DocumentsEntityDeserializer()) .registerTypeAdapter(AqlFunctionsEntity.class, new EntityDeserializers.AqlfunctionsEntityDeserializer()) diff --git a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java index 8dc7698ac..84e618cbc 100644 --- a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java @@ -205,31 +205,14 @@ public DocumentEntity updateDocumentRaw( } @Override - public List getDocuments(String database, String collectionName, boolean handleConvert) - throws ArangoException { - - // HttpResponseEntity res = - // httpManager.doGet(createDocumentEndpointUrl(database), - // new MapBuilder("collection", collectionName).get()); - + public List getDocuments(String database, String collectionName) throws ArangoException { HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/all-keys"), null, - EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).get())); + EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).put("type", "id").get())); @SuppressWarnings("unchecked") CursorEntity tmp = createEntity(res, CursorEntity.class, String.class); return tmp.getResults(); - // - // - // DocumentResultEntity entity = createEntity(res, - // DocumentResultEntity.class); - // List documents = - // CollectionUtils.safety(entity.getDocuments()); - // - // if (handleConvert && !documents.isEmpty()) { - // updateDocumentHandles(documents); - // } - // return documents; } private void updateDocumentHandles(List documents) { diff --git a/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java b/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java index 0fc96fcc3..41e1a24d4 100644 --- a/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java @@ -39,15 +39,11 @@ public class InternalImportDriverImpl extends BaseArangoDriverImpl implements co } @Override - public ImportResultEntity importDocuments( - String database, - String collection, - Boolean createCollection, - Collection values) throws ArangoException { + public ImportResultEntity importDocuments(String database, String collection, Collection values) + throws ArangoException { - HttpResponseEntity res = httpManager.doPost( - createEndpointUrl(database, "/_api/import"), new MapBuilder().put("collection", collection) - .put("createCollection", createCollection).put("type", "array").get(), + HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), + new MapBuilder().put("collection", collection).put("type", "array").get(), EntityFactory.toJsonString(values)); return createEntity(res, ImportResultEntity.class); @@ -58,12 +54,10 @@ public ImportResultEntity importDocuments( public ImportResultEntity importDocumentsByHeaderValues( String database, String collection, - Boolean createCollection, Collection> headerValues) throws ArangoException { HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), - new MapBuilder().put("collection", collection).put("createCollection", createCollection).get(), - EntityFactory.toImportHeaderValues(headerValues)); + new MapBuilder().put("collection", collection).get(), EntityFactory.toImportHeaderValues(headerValues)); return createEntity(res, ImportResultEntity.class); diff --git a/src/test/java/com/arangodb/ArangoDriverCollectionTest.java b/src/test/java/com/arangodb/ArangoDriverCollectionTest.java index cf4606b6f..3c6d6f897 100644 --- a/src/test/java/com/arangodb/ArangoDriverCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCollectionTest.java @@ -52,700 +52,698 @@ */ public class ArangoDriverCollectionTest extends BaseTest { - public ArangoDriverCollectionTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - private static Logger logger = LoggerFactory.getLogger(ArangoDriverCollectionTest.class); - - final String collectionName = "unit_test_arango_001"; // 通常ケースで使うコレクション名 - final String collectionName2 = "unit_test_arango_002"; - final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 - - @Before - public void before() throws ArangoException { - - logger.debug("----------"); - - // 事前に消しておく - for (String col : new String[] { collectionName, collectionName2, collectionName404 }) { - try { - driver.deleteCollection(col); - } catch (ArangoException e) { - } - } - - logger.debug("--"); - - } - - @After - public void after() { - logger.debug("----------"); - } - - /** - * system test - * - * @throws ArangoException - */ - @Test - public void test_create_document_collection() throws ArangoException { - - // DocumentCollection - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1, is(notNullValue())); - assertThat(res1.getCode(), is(200)); - assertThat(res1.getId(), is(notNullValue())); - assertThat(res1.getName(), is(collectionName)); - assertThat(res1.getWaitForSync(), is(false)); - assertThat(res1.getIsVolatile(), is(false)); - assertThat(res1.getIsSystem(), is(false)); - assertThat(res1.getStatus(), is(CollectionStatus.LOADED)); - assertThat(res1.getType(), is(CollectionType.DOCUMENT)); - - } - - /** - * system test - * - * @throws ArangoException - */ - @Test - // @Parameters - public - void test_create_edge_collection() throws ArangoException { - CollectionOptions collectionOptions = new CollectionOptions(); - collectionOptions.setType(CollectionType.EDGE); - CollectionEntity res2 = driver.createCollection(collectionName, collectionOptions); - assertThat(res2, is(notNullValue())); - assertThat(res2.getCode(), is(200)); - assertThat(res2.getId(), is(notNullValue())); - assertThat(res2.getName(), is(collectionName)); - assertThat(res2.getWaitForSync(), is(false)); - assertThat(res2.getIsVolatile(), is(false)); - assertThat(res2.getIsSystem(), is(false)); - assertThat(res2.getStatus(), is(CollectionStatus.LOADED)); - assertThat(res2.getType(), is(CollectionType.EDGE)); - - } - - /** - * Test for InMemory Document Collection. - * - * @throws ArangoException - */ - @Test - public void test_create_inmemory_document_collection() throws ArangoException { - - CollectionOptions collectionOptions = new CollectionOptions(); - collectionOptions.setIsVolatile(true); - CollectionEntity res = driver.createCollection(collectionName, collectionOptions); - assertThat(res, is(notNullValue())); - assertThat(res.getCode(), is(200)); - assertThat(res.getId(), is(not(0L))); - assertThat(res.getName(), is(collectionName)); - assertThat(res.getWaitForSync(), is(false)); - assertThat(res.getIsVolatile(), is(true)); - assertThat(res.getIsSystem(), is(false)); - assertThat(res.getStatus(), is(CollectionStatus.LOADED)); - assertThat(res.getType(), is(CollectionType.DOCUMENT)); - - } - - @Test - public void test_create_with_options() throws ArangoException { - - CollectionKeyOption keyOptions = new CollectionKeyOption(); - keyOptions.setType("autoincrement"); - keyOptions.setAllowUserKeys(true); - keyOptions.setIncrement(10); - keyOptions.setOffset(200); - - CollectionOptions collectionOptions = new CollectionOptions(); - collectionOptions.setKeyOptions(keyOptions); - CollectionEntity res = driver.createCollection(collectionName, collectionOptions); - assertThat(res, is(notNullValue())); - assertThat(res.getCode(), is(200)); - assertThat(res.getId(), is(not(0L))); - assertThat(res.getName(), is(collectionName)); - assertThat(res.getWaitForSync(), is(false)); - assertThat(res.getIsVolatile(), is(false)); - assertThat(res.getIsSystem(), is(false)); - assertThat(res.getStatus(), is(CollectionStatus.LOADED)); - assertThat(res.getType(), is(CollectionType.DOCUMENT)); - - // 現状では戻り値でとれないので別のAPIで確認する - // // TODO 現状では戻ってこないことを確認する - assertThat(res.getKeyOptions(), is(nullValue())); - - // 別のAPIで確認する - CollectionEntity ent = driver.getCollectionProperties(collectionName); - CollectionKeyOption opt = ent.getKeyOptions(); - assertThat(opt.isAllowUserKeys(), is(true)); - assertThat(opt.getType(), is("autoincrement")); - assertThat(opt.getIncrement(), is(10L)); - assertThat(opt.getOffset(), is(200L)); - - } - - @Test - public void test_create_no_compact() throws ArangoException { - - // DocumentCollection - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1, is(notNullValue())); - assertThat(res1.getCode(), is(200)); - assertThat(res1.getId(), is(notNullValue())); - assertThat(res1.getName(), is(collectionName)); - assertThat(res1.getWaitForSync(), is(false)); - assertThat(res1.getIsVolatile(), is(false)); - assertThat(res1.getIsSystem(), is(false)); - assertThat(res1.getStatus(), is(CollectionStatus.LOADED)); - assertThat(res1.getType(), is(CollectionType.DOCUMENT)); - - CollectionEntity prop = driver.getCollectionProperties(collectionName); - assertThat(prop.getCode(), is(200)); - assertThat(prop.getId(), is(res1.getId())); - assertThat(prop.getDoCompact(), is(true)); - - } - - /** - * 既に存在する場合の挙動確認。 - * - * @throws ArangoException - */ - @Test - public void test_create_dup() throws ArangoException { - - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1, is(notNullValue())); - assertThat(res1.getCode(), is(200)); - assertThat(res1.getId(), is(not(0L))); - assertThat(res1.getName(), is(collectionName)); - assertThat(res1.getWaitForSync(), is(false)); - assertThat(res1.getIsVolatile(), is(false)); - assertThat(res1.getIsSystem(), is(false)); - assertThat(res1.getStatus(), is(CollectionStatus.LOADED)); - - { - try { - driver.createCollection(collectionName); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(409)); - assertThat(e.getErrorNumber(), is(1207)); - } - } - - } - - @Test - public void test_getCollection_01() throws ArangoException { - - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1.getCode(), is(200)); - - long collectionId = res1.getId(); - - // IDで取得 - CollectionEntity entity1 = driver.getCollection(collectionId); - // 名前で取得 - CollectionEntity entity2 = driver.getCollection(collectionName); - assertThat(entity1.getId(), is(collectionId)); - assertThat(entity2.getId(), is(collectionId)); - assertThat(entity1.getName(), is(collectionName)); - assertThat(entity2.getName(), is(collectionName)); - - // Type確認 - assertThat(entity1.getType(), is(CollectionType.DOCUMENT)); - assertThat(entity2.getType(), is(CollectionType.DOCUMENT)); - - } - - /** - * 存在しないコレクションを取得する場合 - * - * @throws ArangoException - */ - @Test - public void test_getCollection_404() throws ArangoException { - - try { - driver.getCollection(collectionName404); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_getCollectionProperties_01() throws ArangoException { - - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1.getCode(), is(200)); - - CollectionEntity collection = driver.getCollectionProperties(collectionName); - assertThat(collection.getCode(), is(200)); - assertThat(collection.getId(), is(res1.getId())); - assertThat(collection.getName(), is(collectionName)); - assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); - assertThat(collection.getJournalSize(), is(32L * 1024 * 1024)); // 32MB - assertThat(collection.getIsSystem(), is(false)); - assertThat(collection.getIsVolatile(), is(false)); - - assertThat(collection.getStatus(), is(CollectionStatus.LOADED)); // 3 - assertThat(collection.getType(), is(CollectionType.DOCUMENT)); // 2 - assertThat(collection.getDoCompact(), is(true)); - - assertThat(collection.getKeyOptions().getType(), is("traditional")); - assertThat(collection.getKeyOptions().isAllowUserKeys(), is(true)); - - // Countがないこと - // Revisionがないこと - assertThat(collection.getCount(), is(0L)); - assertThat(collection.getRevision(), is(0L)); - - } - - /** - * 存在しないコレクションを指定した場合。 - * - * @throws ArangoException - */ - @Test - public void test_getCollectionProperties_404() throws ArangoException { - - try { - driver.getCollectionProperties(collectionName404); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_getCollectionRevision() throws ArangoException { - - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1.getCode(), is(200)); - - // Get Revision - CollectionEntity collection = driver.getCollectionRevision(collectionName); - assertThat(collection.getRevision(), is(0L)); - - // Create Document - driver.createDocument(collectionName, new TestComplexEntity01("test_user1", "test user 1", 20), false, true); - - // Get Revision again - collection = driver.getCollectionRevision(collectionName); - // Check to updated revision - long rev2 = collection.getRevision(); - assertThat(rev2, is(not(0L))); - - // Create Document - driver.createDocument(collectionName, new TestComplexEntity01("test_user2", "test user 2", 21), false, true); - - // Get Revision again - collection = driver.getCollectionRevision(collectionName); - // Check to updated revision - long rev3 = collection.getRevision(); - assertThat(rev3, greaterThan(rev2)); - - } - - @Test - public void test_getCollectionRevision_404() throws ArangoException { - - try { - driver.getCollectionRevision(collectionName404); - fail("Because did not raise Exception."); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_getCollectionCount_01() throws ArangoException { - - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1.getCode(), is(200)); - - CollectionEntity collection = driver.getCollectionCount(collectionName); - assertThat(collection.getCode(), is(200)); - assertThat(collection.getId(), is(res1.getId())); - assertThat(collection.getName(), is(collectionName)); - assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); - assertThat(collection.getJournalSize(), is(32L * 1024 * 1024)); // 32MB - assertThat(collection.getCount(), is(0L)); // 何も入っていないのでゼロ - // TODO type, status - - // 100個ほどドキュメントを入れてみる - for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "tes user:" + i, 20 + i); - driver.createDocument(collectionName, value, false, true); - } - - // もっかいアクセスして10になっているか確認する - collection = driver.getCollectionCount(collectionName); - assertThat(collection.getCount(), is(100L)); - - } - - /** - * 存在しないコレクションを指定した場合。 - * - * @throws ArangoException - */ - @Test - public void test_getCollectionCount_404() throws ArangoException { - - try { - driver.getCollectionCount(collectionName404); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_getCollectionFigures_01() throws ArangoException { - - // コレクションを作る - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1.getCode(), is(200)); - - // 100個ほどドキュメントを入れてみる - for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); - DocumentEntity entity = driver.createDocument(collectionName, value, false, true); - // 1個消す - if (i == 50) { - driver.deleteDocument(entity.getDocumentHandle(), null, null); - } - } - - CollectionEntity collection = driver.getCollectionFigures(collectionName); - assertThat(collection.getCode(), is(200)); - assertThat(collection.getId(), is(res1.getId())); - assertThat(collection.getName(), is(collectionName)); - assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); - assertThat(collection.getJournalSize(), is(32L * 1024 * 1024)); // 32MB - assertThat(collection.getCount(), is(99L)); - assertThat(collection.getType(), is(CollectionType.DOCUMENT)); - assertThat(collection.getStatus(), is(CollectionStatus.LOADED)); - - // It is not possible to check the numbers - // assertThat(collection.getFigures().getAliveCount(), is(99L)); - // assertThat(collection.getFigures().getAliveSize(), is(not(0L))); - // assertThat(collection.getFigures().getDeadCount(), is(1L)); - // assertThat(collection.getFigures().getDeadSize(), is(not(0L))); - // assertThat(collection.getFigures().getJournalsCount(), is(1L)); - // assertThat(collection.getFigures().getJournalsFileSize(), - // is(not(0L))); - // assertThat(collection.getFigures().getShapefilesCount(), is(1L)); - // assertThat(collection.getFigures().getShapefilesFileSize(), - // is(not(0L))); - // assertThat(collection.getFigures().getShapesCount(), is(not(0L))); - // assertThat(collection.getFigures().getAttributesCount(), - // is(not(0L))); - - assertThat(collection.getFigures().getIndexesCount(), is(1L)); - assertThat(collection.getFigures().getIndexesSize(), is(not(0L))); - // assertThat(collection.getFigures().getLastTick(), is(1L)); - assertThat(collection.getFigures().getUncollectedLogfileEntries(), is(not(0L))); - - } - - /** - * 存在しないコレクションを指定した場合。 - * - * @throws ArangoException - */ - @Test - public void test_getCollectionFigures_404() throws ArangoException { - - try { - driver.getCollectionFigures(collectionName404); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_getCollectionChecksum() throws ArangoException { - - // create collection. - CollectionEntity res1 = driver.createCollection(collectionName); - assertThat(res1.getCode(), is(200)); - - // checksum - CollectionEntity entity = driver.getCollectionChecksum(collectionName, true, true); - assertThat(entity.getCode(), is(200)); - assertThat(entity.isError(), is(false)); - assertThat(entity.getRevision(), is(0L)); // レスポンスは戻ってきてるんだけど、0なのでどうチェックしたものか・・ - assertThat(entity.getChecksum(), is(0L)); // 同上 - - } - - @Test - public void test_getCollections() throws ArangoException { - - for (int i = 0; i < 10; i++) { - try { - driver.createCollection("unit_test_arango_" + (1000 + i)); - } catch (ArangoException e) { - } - } - - CollectionsEntity collections = driver.getCollections(); - assertThat(collections.getCode(), is(200)); - Map map = collections.getNames(); - for (int i = 0; i < 10; i++) { - String collectionName = "unit_test_arango_" + (1000 + i); - CollectionEntity collection = map.get(collectionName); - // id, name, status - assertThat(collection, is(notNullValue())); - assertThat(collection.getId(), is(not(0L))); - assertThat(collection.getName(), is(collectionName)); - } - - // with exluceSystem parameter. - int allColCount = collections.getCollections().size(); - int sysExcludeCount = driver.getCollections(true).getCollections().size(); - assertThat(allColCount > sysExcludeCount, is(true)); - - } - - @Test - public void test_load_unload() throws ArangoException { - - // create - CollectionEntity collection = driver.createCollection(collectionName); - assertThat(collection, is(notNullValue())); - assertThat(collection.getCode(), is(200)); - - // add document, for count parameter test. - driver.createDocument(collectionName, new MapBuilder("hoge", "fuga").put("fuga", "piyoko").get(), false, null); - - CollectionEntity collection1 = driver.unloadCollection(collectionName); - assertThat(collection1, is(notNullValue())); - assertThat(collection1.getCode(), is(200)); - assertThat(collection1.getCount(), is(0L)); - - assertThat( - collection1.getStatus(), - anyOf(is(CollectionStatus.UNLOADED), is(CollectionStatus.IN_THE_PROCESS_OF_BEING_UNLOADED))); - - CollectionEntity collection2 = driver.loadCollection(collectionName); - assertThat(collection2, is(notNullValue())); - assertThat(collection2.getCode(), is(200)); - assertThat(collection2.getStatus(), is(CollectionStatus.LOADED)); - assertThat(collection2.getCount(), is(1L)); - - // unload again, for count parameter test. - collection1 = driver.unloadCollection(collectionName); - assertThat(collection1, is(notNullValue())); - assertThat(collection1.getCode(), is(200)); - assertThat(collection1.getCount(), is(0L)); - - // with count parameter - CollectionEntity col3 = driver.loadCollection(collectionName, false); - assertThat(col3, is(notNullValue())); - assertThat(col3.getCode(), is(200)); - assertThat(col3.getStatus(), is(CollectionStatus.LOADED)); - assertThat(col3.getCount(), is(0L)); // Not contains count in response. - - } - - @Test - public void test_load_404() throws ArangoException { - - try { - driver.loadCollection(collectionName404); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_unload_404() throws ArangoException { - - try { - driver.unloadCollection(collectionName404); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_truncate() throws ArangoException { - - CollectionEntity collection = driver.createCollection(collectionName); - assertThat(collection, is(notNullValue())); - assertThat(collection.getCode(), is(200)); - - // 100個ほどドキュメントを入れてみる - for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); - assertThat(driver.createDocument(collectionName, value, false, true).getStatusCode(), is(201)); - } - // 100個入ったよね? - assertThat(driver.getCollectionCount(collectionName).getCount(), is(100L)); - - // 抹殺じゃー! - CollectionEntity collection2 = driver.truncateCollection(collectionName); - assertThat(collection2, is(notNullValue())); - assertThat(collection2.getCode(), is(200)); - - // 0件になってるか確認 - assertThat(driver.getCollectionCount(collectionName).getCount(), is(0L)); - - } - - @Test - public void test_truncate_404() throws ArangoException { - - try { - driver.unloadCollection(collectionName404); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_setCollectionProperties() throws ArangoException { - - CollectionEntity collection = driver.createCollection(collectionName); - assertThat(collection, is(notNullValue())); - assertThat(collection.getCode(), is(200)); - assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); - - // Change waitForSync: false -> true - CollectionEntity col = driver.setCollectionProperties(collectionName, true, null); - assertThat(col.getCode(), is(200)); - assertThat(col.getWaitForSync(), is(Boolean.TRUE)); - - // Change journalSize: default -> 1234567Byte - col = driver.setCollectionProperties(collectionName, null, 1234567L); - assertThat(col.getCode(), is(200)); - assertThat(col.getJournalSize(), is(1234567L)); - - } - - @Test - public void test_setCollectionProperties_404() throws ArangoException { - - try { - driver.setCollectionProperties(collectionName404, true, null); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_delete() throws ArangoException { - - // コレクションを適当に10個作る - TreeSet collectionNames = new TreeSet(); - for (int i = 0; i < 10; i++) { - try { - CollectionEntity col = driver.createCollection("unit_test_arango_" + (1000 + i)); - long collectionId = col.getId(); - if (i == 5) { - // 1個だけ消す - CollectionEntity res = driver.deleteCollection(collectionId); - assertThat(res.getCode(), is(200)); - assertThat(res.getId(), is(collectionId)); - } else { - collectionNames.add(col.getName()); - } - } catch (ArangoException e) { - } - } - - // 残りの9個は残っていること - Map collections = driver.getCollections().getNames(); - for (String name : collectionNames) { - assertThat(collections.containsKey(name), is(true)); - } - - } - - @Test - public void test_delete_404() throws ArangoException { - - try { - driver.deleteCollection(collectionName404); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - @Test - public void test_rename_404() throws ArangoException { - - CollectionEntity collection = driver.createCollection(collectionName); - assertThat(collection.getCode(), is(200)); - - try { - driver.renameCollection(collectionName404, collectionName); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } - - } - - /** - * Rename先が既に存在する場合 - * - * @throws ArangoException - */ - @Test - public void test_rename_dup() throws ArangoException { - - CollectionEntity collection1 = driver.createCollection(collectionName); - assertThat(collection1.getCode(), is(200)); - - CollectionEntity collection2 = driver.createCollection(collectionName2); - assertThat(collection2.getCode(), is(200)); - - try { - driver.renameCollection(collectionName, collectionName2); - fail("ここに来てはダメー!"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(409)); - assertThat(e.getErrorNumber(), is(1207)); - } - - } + public ArangoDriverCollectionTest(ArangoConfigure configure, ArangoDriver driver) { + super(configure, driver); + } + + private static Logger logger = LoggerFactory.getLogger(ArangoDriverCollectionTest.class); + + final String collectionName = "unit_test_arango_001"; // 通常ケースで使うコレクション名 + final String collectionName2 = "unit_test_arango_002"; + final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 + + @Before + public void before() throws ArangoException { + + logger.debug("----------"); + + // 事前に消しておく + for (String col : new String[] { collectionName, collectionName2, collectionName404 }) { + try { + driver.deleteCollection(col); + } catch (ArangoException e) { + } + } + + logger.debug("--"); + + } + + @After + public void after() { + logger.debug("----------"); + } + + /** + * system test + * + * @throws ArangoException + */ + @Test + public void test_create_document_collection() throws ArangoException { + + // DocumentCollection + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1, is(notNullValue())); + assertThat(res1.getCode(), is(200)); + assertThat(res1.getId(), is(notNullValue())); + assertThat(res1.getName(), is(collectionName)); + assertThat(res1.getWaitForSync(), is(false)); + assertThat(res1.getIsVolatile(), is(false)); + assertThat(res1.getIsSystem(), is(false)); + assertThat(res1.getStatus(), is(CollectionStatus.LOADED)); + assertThat(res1.getType(), is(CollectionType.DOCUMENT)); + + } + + /** + * system test + * + * @throws ArangoException + */ + @Test + // @Parameters + public void test_create_edge_collection() throws ArangoException { + CollectionOptions collectionOptions = new CollectionOptions(); + collectionOptions.setType(CollectionType.EDGE); + CollectionEntity res2 = driver.createCollection(collectionName, collectionOptions); + assertThat(res2, is(notNullValue())); + assertThat(res2.getCode(), is(200)); + assertThat(res2.getId(), is(notNullValue())); + assertThat(res2.getName(), is(collectionName)); + assertThat(res2.getWaitForSync(), is(false)); + assertThat(res2.getIsVolatile(), is(false)); + assertThat(res2.getIsSystem(), is(false)); + assertThat(res2.getStatus(), is(CollectionStatus.LOADED)); + assertThat(res2.getType(), is(CollectionType.EDGE)); + + } + + /** + * Test for InMemory Document Collection. + * + * @throws ArangoException + */ + @Test + public void test_create_inmemory_document_collection() throws ArangoException { + + CollectionOptions collectionOptions = new CollectionOptions(); + collectionOptions.setIsVolatile(true); + CollectionEntity res = driver.createCollection(collectionName, collectionOptions); + assertThat(res, is(notNullValue())); + assertThat(res.getCode(), is(200)); + assertThat(res.getId(), is(not(0L))); + assertThat(res.getName(), is(collectionName)); + assertThat(res.getWaitForSync(), is(false)); + assertThat(res.getIsVolatile(), is(true)); + assertThat(res.getIsSystem(), is(false)); + assertThat(res.getStatus(), is(CollectionStatus.LOADED)); + assertThat(res.getType(), is(CollectionType.DOCUMENT)); + + } + + @Test + public void test_create_with_options() throws ArangoException { + + CollectionKeyOption keyOptions = new CollectionKeyOption(); + keyOptions.setType("autoincrement"); + keyOptions.setAllowUserKeys(true); + keyOptions.setIncrement(10); + keyOptions.setOffset(200); + + CollectionOptions collectionOptions = new CollectionOptions(); + collectionOptions.setKeyOptions(keyOptions); + CollectionEntity res = driver.createCollection(collectionName, collectionOptions); + assertThat(res, is(notNullValue())); + assertThat(res.getCode(), is(200)); + assertThat(res.getId(), is(not(0L))); + assertThat(res.getName(), is(collectionName)); + assertThat(res.getWaitForSync(), is(false)); + assertThat(res.getIsVolatile(), is(false)); + assertThat(res.getIsSystem(), is(false)); + assertThat(res.getStatus(), is(CollectionStatus.LOADED)); + assertThat(res.getType(), is(CollectionType.DOCUMENT)); + + // 現状では戻り値でとれないので別のAPIで確認する + // // TODO 現状では戻ってこないことを確認する + assertThat(res.getKeyOptions(), is(nullValue())); + + // 別のAPIで確認する + CollectionEntity ent = driver.getCollectionProperties(collectionName); + CollectionKeyOption opt = ent.getKeyOptions(); + assertThat(opt.isAllowUserKeys(), is(true)); + assertThat(opt.getType(), is("autoincrement")); + assertThat(opt.getIncrement(), is(10L)); + assertThat(opt.getOffset(), is(200L)); + + } + + @Test + public void test_create_no_compact() throws ArangoException { + + // DocumentCollection + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1, is(notNullValue())); + assertThat(res1.getCode(), is(200)); + assertThat(res1.getId(), is(notNullValue())); + assertThat(res1.getName(), is(collectionName)); + assertThat(res1.getWaitForSync(), is(false)); + assertThat(res1.getIsVolatile(), is(false)); + assertThat(res1.getIsSystem(), is(false)); + assertThat(res1.getStatus(), is(CollectionStatus.LOADED)); + assertThat(res1.getType(), is(CollectionType.DOCUMENT)); + + CollectionEntity prop = driver.getCollectionProperties(collectionName); + assertThat(prop.getCode(), is(200)); + assertThat(prop.getId(), is(res1.getId())); + assertThat(prop.getDoCompact(), is(true)); + + } + + /** + * 既に存在する場合の挙動確認。 + * + * @throws ArangoException + */ + @Test + public void test_create_dup() throws ArangoException { + + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1, is(notNullValue())); + assertThat(res1.getCode(), is(200)); + assertThat(res1.getId(), is(not(0L))); + assertThat(res1.getName(), is(collectionName)); + assertThat(res1.getWaitForSync(), is(false)); + assertThat(res1.getIsVolatile(), is(false)); + assertThat(res1.getIsSystem(), is(false)); + assertThat(res1.getStatus(), is(CollectionStatus.LOADED)); + + { + try { + driver.createCollection(collectionName); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(409)); + assertThat(e.getErrorNumber(), is(1207)); + } + } + + } + + @Test + public void test_getCollection_01() throws ArangoException { + + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1.getCode(), is(200)); + + long collectionId = res1.getId(); + + // IDで取得 + CollectionEntity entity1 = driver.getCollection(collectionId); + // 名前で取得 + CollectionEntity entity2 = driver.getCollection(collectionName); + assertThat(entity1.getId(), is(collectionId)); + assertThat(entity2.getId(), is(collectionId)); + assertThat(entity1.getName(), is(collectionName)); + assertThat(entity2.getName(), is(collectionName)); + + // Type確認 + assertThat(entity1.getType(), is(CollectionType.DOCUMENT)); + assertThat(entity2.getType(), is(CollectionType.DOCUMENT)); + + } + + /** + * 存在しないコレクションを取得する場合 + * + * @throws ArangoException + */ + @Test + public void test_getCollection_404() throws ArangoException { + + try { + driver.getCollection(collectionName404); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_getCollectionProperties_01() throws ArangoException { + + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1.getCode(), is(200)); + + CollectionEntity collection = driver.getCollectionProperties(collectionName); + assertThat(collection.getCode(), is(200)); + assertThat(collection.getId(), is(res1.getId())); + assertThat(collection.getName(), is(collectionName)); + assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); + assertThat(collection.getJournalSize(), is(32L * 1024 * 1024)); // 32MB + assertThat(collection.getIsSystem(), is(false)); + assertThat(collection.getIsVolatile(), is(false)); + + assertThat(collection.getStatus(), is(CollectionStatus.LOADED)); // 3 + assertThat(collection.getType(), is(CollectionType.DOCUMENT)); // 2 + assertThat(collection.getDoCompact(), is(true)); + + assertThat(collection.getKeyOptions().getType(), is("traditional")); + assertThat(collection.getKeyOptions().isAllowUserKeys(), is(true)); + + // Countがないこと + // Revisionがないこと + assertThat(collection.getCount(), is(0L)); + assertThat(collection.getRevision(), is(0L)); + + } + + /** + * 存在しないコレクションを指定した場合。 + * + * @throws ArangoException + */ + @Test + public void test_getCollectionProperties_404() throws ArangoException { + + try { + driver.getCollectionProperties(collectionName404); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_getCollectionRevision() throws ArangoException { + + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1.getCode(), is(200)); + + // Get Revision + CollectionEntity collection = driver.getCollectionRevision(collectionName); + assertThat(collection.getRevision(), is(0L)); + + // Create Document + driver.createDocument(collectionName, new TestComplexEntity01("test_user1", "test user 1", 20), false, true); + + // Get Revision again + collection = driver.getCollectionRevision(collectionName); + // Check to updated revision + long rev2 = collection.getRevision(); + assertThat(rev2, is(not(0L))); + + // Create Document + driver.createDocument(collectionName, new TestComplexEntity01("test_user2", "test user 2", 21), false, true); + + // Get Revision again + collection = driver.getCollectionRevision(collectionName); + // Check to updated revision + long rev3 = collection.getRevision(); + assertThat(rev3, greaterThan(rev2)); + + } + + @Test + public void test_getCollectionRevision_404() throws ArangoException { + + try { + driver.getCollectionRevision(collectionName404); + fail("Because did not raise Exception."); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_getCollectionCount_01() throws ArangoException { + + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1.getCode(), is(200)); + + CollectionEntity collection = driver.getCollectionCount(collectionName); + assertThat(collection.getCode(), is(200)); + assertThat(collection.getId(), is(res1.getId())); + assertThat(collection.getName(), is(collectionName)); + assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); + assertThat(collection.getJournalSize(), is(32L * 1024 * 1024)); // 32MB + assertThat(collection.getCount(), is(0L)); // 何も入っていないのでゼロ + // TODO type, status + + // 100個ほどドキュメントを入れてみる + for (int i = 0; i < 100; i++) { + TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "tes user:" + i, 20 + i); + driver.createDocument(collectionName, value, false, true); + } + + // もっかいアクセスして10になっているか確認する + collection = driver.getCollectionCount(collectionName); + assertThat(collection.getCount(), is(100L)); + + } + + /** + * 存在しないコレクションを指定した場合。 + * + * @throws ArangoException + */ + @Test + public void test_getCollectionCount_404() throws ArangoException { + + try { + driver.getCollectionCount(collectionName404); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_getCollectionFigures_01() throws ArangoException { + + // コレクションを作る + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1.getCode(), is(200)); + + // 100個ほどドキュメントを入れてみる + for (int i = 0; i < 100; i++) { + TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); + DocumentEntity entity = driver.createDocument(collectionName, value, false, true); + // 1個消す + if (i == 50) { + driver.deleteDocument(entity.getDocumentHandle(), null, null); + } + } + + CollectionEntity collection = driver.getCollectionFigures(collectionName); + assertThat(collection.getCode(), is(200)); + assertThat(collection.getId(), is(res1.getId())); + assertThat(collection.getName(), is(collectionName)); + assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); + assertThat(collection.getJournalSize(), is(32L * 1024 * 1024)); // 32MB + assertThat(collection.getCount(), is(99L)); + assertThat(collection.getType(), is(CollectionType.DOCUMENT)); + assertThat(collection.getStatus(), is(CollectionStatus.LOADED)); + + // It is not possible to check the numbers + // assertThat(collection.getFigures().getAliveCount(), is(99L)); + // assertThat(collection.getFigures().getAliveSize(), is(not(0L))); + // assertThat(collection.getFigures().getDeadCount(), is(1L)); + // assertThat(collection.getFigures().getDeadSize(), is(not(0L))); + // assertThat(collection.getFigures().getJournalsCount(), is(1L)); + // assertThat(collection.getFigures().getJournalsFileSize(), + // is(not(0L))); + // assertThat(collection.getFigures().getShapefilesCount(), is(1L)); + // assertThat(collection.getFigures().getShapefilesFileSize(), + // is(not(0L))); + // assertThat(collection.getFigures().getShapesCount(), is(not(0L))); + // assertThat(collection.getFigures().getAttributesCount(), + // is(not(0L))); + + assertThat(collection.getFigures().getIndexesCount(), is(1L)); + assertThat(collection.getFigures().getIndexesSize(), is(not(0L))); + // assertThat(collection.getFigures().getLastTick(), is(1L)); + assertThat(collection.getFigures().getUncollectedLogfileEntries(), is(not(0L))); + + } + + /** + * 存在しないコレクションを指定した場合。 + * + * @throws ArangoException + */ + @Test + public void test_getCollectionFigures_404() throws ArangoException { + + try { + driver.getCollectionFigures(collectionName404); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_getCollectionChecksum() throws ArangoException { + + // create collection. + CollectionEntity res1 = driver.createCollection(collectionName); + assertThat(res1.getCode(), is(200)); + + // checksum + CollectionEntity entity = driver.getCollectionChecksum(collectionName, true, true); + assertThat(entity.getCode(), is(200)); + assertThat(entity.isError(), is(false)); + assertThat(entity.getRevision(), is(0L)); // レスポンスは戻ってきてるんだけど、0なのでどうチェックしたものか・・ + assertThat(entity.getChecksum(), is(0L)); // 同上 + + } + + @Test + public void test_getCollections() throws ArangoException { + + for (int i = 0; i < 10; i++) { + try { + driver.createCollection("unit_test_arango_" + (1000 + i)); + } catch (ArangoException e) { + } + } + + CollectionsEntity collections = driver.getCollections(); + assertThat(collections.getCode(), is(200)); + Map map = collections.getNames(); + for (int i = 0; i < 10; i++) { + String collectionName = "unit_test_arango_" + (1000 + i); + CollectionEntity collection = map.get(collectionName); + // id, name, status + assertThat(collection, is(notNullValue())); + assertThat(collection.getId(), is(not(0L))); + assertThat(collection.getName(), is(collectionName)); + } + + // with exluceSystem parameter. + int allColCount = collections.getCollections().size(); + int sysExcludeCount = driver.getCollections(true).getCollections().size(); + assertThat(allColCount > sysExcludeCount, is(true)); + + } + + @Test + public void test_load_unload() throws ArangoException { + + // create + CollectionEntity collection = driver.createCollection(collectionName); + assertThat(collection, is(notNullValue())); + assertThat(collection.getCode(), is(200)); + + // add document, for count parameter test. + driver.createDocument(collectionName, new MapBuilder("hoge", "fuga").put("fuga", "piyoko").get(), false, null); + + CollectionEntity collection1 = driver.unloadCollection(collectionName); + assertThat(collection1, is(notNullValue())); + assertThat(collection1.getCode(), is(200)); + assertThat(collection1.getCount(), is(0L)); + + assertThat(collection1.getStatus(), + anyOf(is(CollectionStatus.UNLOADED), is(CollectionStatus.IN_THE_PROCESS_OF_BEING_UNLOADED))); + + CollectionEntity collection2 = driver.loadCollection(collectionName); + assertThat(collection2, is(notNullValue())); + assertThat(collection2.getCode(), is(200)); + assertThat(collection2.getStatus(), is(CollectionStatus.LOADED)); + assertThat(collection2.getCount(), is(1L)); + + // unload again, for count parameter test. + collection1 = driver.unloadCollection(collectionName); + assertThat(collection1, is(notNullValue())); + assertThat(collection1.getCode(), is(200)); + assertThat(collection1.getCount(), is(0L)); + + // with count parameter + CollectionEntity col3 = driver.loadCollection(collectionName, false); + assertThat(col3, is(notNullValue())); + assertThat(col3.getCode(), is(200)); + assertThat(col3.getStatus(), is(CollectionStatus.LOADED)); + assertThat(col3.getCount(), is(0L)); // Not contains count in response. + + } + + @Test + public void test_load_404() throws ArangoException { + + try { + driver.loadCollection(collectionName404); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_unload_404() throws ArangoException { + + try { + driver.unloadCollection(collectionName404); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_truncate() throws ArangoException { + + CollectionEntity collection = driver.createCollection(collectionName); + assertThat(collection, is(notNullValue())); + assertThat(collection.getCode(), is(200)); + + // 100個ほどドキュメントを入れてみる + for (int i = 0; i < 100; i++) { + TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); + assertThat(driver.createDocument(collectionName, value, false, true).getStatusCode(), is(201)); + } + // 100個入ったよね? + assertThat(driver.getCollectionCount(collectionName).getCount(), is(100L)); + + // 抹殺じゃー! + CollectionEntity collection2 = driver.truncateCollection(collectionName); + assertThat(collection2, is(notNullValue())); + assertThat(collection2.getCode(), is(200)); + + // 0件になってるか確認 + assertThat(driver.getCollectionCount(collectionName).getCount(), is(0L)); + + } + + @Test + public void test_truncate_404() throws ArangoException { + + try { + driver.unloadCollection(collectionName404); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_setCollectionProperties() throws ArangoException { + + CollectionEntity collection = driver.createCollection(collectionName); + assertThat(collection, is(notNullValue())); + assertThat(collection.getCode(), is(200)); + assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); + + // Change waitForSync: false -> true + CollectionEntity col = driver.setCollectionProperties(collectionName, true, null); + assertThat(col.getCode(), is(200)); + assertThat(col.getWaitForSync(), is(Boolean.TRUE)); + + // Change journalSize: default -> 1234567Byte + col = driver.setCollectionProperties(collectionName, null, 1234567L); + assertThat(col.getCode(), is(200)); + assertThat(col.getJournalSize(), is(1234567L)); + + } + + @Test + public void test_setCollectionProperties_404() throws ArangoException { + + try { + driver.setCollectionProperties(collectionName404, true, null); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_delete() throws ArangoException { + + // コレクションを適当に10個作る + TreeSet collectionNames = new TreeSet(); + for (int i = 0; i < 10; i++) { + try { + CollectionEntity col = driver.createCollection("unit_test_arango_" + (1000 + i)); + long collectionId = col.getId(); + if (i == 5) { + // 1個だけ消す + CollectionEntity res = driver.deleteCollection(collectionId); + assertThat(res.getCode(), is(200)); + assertThat(res.getId(), is(collectionId)); + } else { + collectionNames.add(col.getName()); + } + } catch (ArangoException e) { + } + } + + // 残りの9個は残っていること + Map collections = driver.getCollections().getNames(); + for (String name : collectionNames) { + assertThat(collections.containsKey(name), is(true)); + } + + } + + @Test + public void test_delete_404() throws ArangoException { + + try { + driver.deleteCollection(collectionName404); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_rename_404() throws ArangoException { + + CollectionEntity collection = driver.createCollection(collectionName); + assertThat(collection.getCode(), is(200)); + + try { + driver.renameCollection(collectionName404, collectionName); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + /** + * Rename先が既に存在する場合 + * + * @throws ArangoException + */ + @Test + public void test_rename_dup() throws ArangoException { + + CollectionEntity collection1 = driver.createCollection(collectionName); + assertThat(collection1.getCode(), is(200)); + + CollectionEntity collection2 = driver.createCollection(collectionName2); + assertThat(collection2.getCode(), is(200)); + + try { + driver.renameCollection(collectionName, collectionName2); + fail("ここに来てはダメー!"); + } catch (ArangoException e) { + assertThat(e.getCode(), is(409)); + assertThat(e.getErrorNumber(), is(1207)); + } + + } } diff --git a/src/test/java/com/arangodb/ArangoDriverCursorTest.java b/src/test/java/com/arangodb/ArangoDriverCursorTest.java index 844d6b937..43f6de530 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorTest.java @@ -278,8 +278,7 @@ public void test_warning() throws ArangoException { String query = "return _users + 1"; Map bindVars = new HashMap(); - @SuppressWarnings("rawtypes") - CursorResult cursor = driver.executeAqlQuery(query, bindVars, null, Map.class); + CursorResult cursor = driver.executeAqlQuery(query, bindVars, null, Long.class); assertThat(cursor.hasWarning(), is(true)); List warnings = cursor.getWarnings(); diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java index 71a20de0e..dd995f247 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java @@ -430,7 +430,7 @@ public void test_getDocuments_handle() throws ArangoException { assertThat(doc3, is(notNullValue())); // get documents - List documents = driver.getDocuments(collectionName, true); + List documents = driver.getDocuments(collectionName); assertEquals(3, documents.size()); List list = Arrays.asList(doc1.getDocumentHandle(), doc2.getDocumentHandle(), doc3.getDocumentHandle()); diff --git a/src/test/java/com/arangodb/ArangoDriverImportTest.java b/src/test/java/com/arangodb/ArangoDriverImportTest.java index dc24066e4..474190c54 100644 --- a/src/test/java/com/arangodb/ArangoDriverImportTest.java +++ b/src/test/java/com/arangodb/ArangoDriverImportTest.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.List; +import org.junit.Before; import org.junit.Test; import com.arangodb.entity.ImportResultEntity; @@ -37,15 +38,29 @@ @SuppressWarnings("unchecked") public class ArangoDriverImportTest extends BaseTest { + private static final String UT_IMPORT_TEST = "ut-import-test"; + public ArangoDriverImportTest(ArangoConfigure configure, ArangoDriver driver) { super(configure, driver); } + @Before + public void setUp() { + try { + driver.deleteCollection(UT_IMPORT_TEST); + } catch (ArangoException e) { + } + try { + driver.createCollection(UT_IMPORT_TEST); + } catch (ArangoException e) { + } + } + @Test public void test_import_documents() throws ArangoException, IOException { List stations = TestUtils.readStations(); - ImportResultEntity result = driver.importDocuments("ut-import-test", true, stations); + ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, stations); assertThat(result.getStatusCode(), is(201)); assertThat(result.isError(), is(false)); @@ -59,13 +74,13 @@ public void test_import_documents() throws ArangoException, IOException { public void test_import_documents_404() throws ArangoException, IOException { try { - driver.deleteCollection("ut-import-test"); + driver.deleteCollection(UT_IMPORT_TEST); } catch (ArangoException e) { } List stations = TestUtils.readStations(); try { - driver.importDocuments("ut-import-test", false, stations); + driver.importDocuments(UT_IMPORT_TEST, stations); fail(); } catch (ArangoException e) { assertThat(e.getCode(), is(404)); @@ -82,7 +97,7 @@ public void test_import_xsv() throws ArangoException, IOException { values.add(Arrays.asList("Joe", "Public", 42, "male")); values.add(Arrays.asList("Jane", "Doe", 31, "female")); - ImportResultEntity result = driver.importDocumentsByHeaderValues("ut-import-test", true, values); + ImportResultEntity result = driver.importDocumentsByHeaderValues(UT_IMPORT_TEST, values); assertThat(result.getStatusCode(), is(201)); assertThat(result.isError(), is(false)); @@ -100,7 +115,7 @@ public void test_import_xsv_errors() throws ArangoException, IOException { values.add(Arrays.asList("Joe", "Public", 42, "male", 10)); // error values.add(Arrays.asList("Jane", "Doe", 31, "female")); - ImportResultEntity result = driver.importDocumentsByHeaderValues("ut-import-test", true, values); + ImportResultEntity result = driver.importDocumentsByHeaderValues(UT_IMPORT_TEST, values); assertThat(result.getStatusCode(), is(201)); assertThat(result.isError(), is(false)); @@ -114,7 +129,7 @@ public void test_import_xsv_errors() throws ArangoException, IOException { public void test_import_xsv_404() throws ArangoException, IOException { try { - driver.deleteCollection("ut-import-test"); + driver.deleteCollection(UT_IMPORT_TEST); } catch (ArangoException e) { } @@ -124,7 +139,7 @@ public void test_import_xsv_404() throws ArangoException, IOException { values.add(Arrays.asList("Jane", "Doe", 31, "female")); try { - driver.importDocuments("ut-import-test", false, values); + driver.importDocuments(UT_IMPORT_TEST, values); fail(); } catch (ArangoException e) { assertThat(e.getCode(), is(404)); diff --git a/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java b/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java index 64575fe10..d6e10359b 100644 --- a/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java +++ b/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java @@ -153,7 +153,7 @@ public void test_scienario() throws ArangoException, InterruptedException { for (int i = 10; i < 300; i++) { values.add(new MapBuilder().put("my-key" + i, 1234567).get()); } - ImportResultEntity importResult = masterDriver.importDocuments(collectionName1, false, values); + ImportResultEntity importResult = masterDriver.importDocuments(collectionName1, values); assertThat(importResult.getCreated(), is(290)); // wait diff --git a/src/test/java/com/arangodb/bench/ImportDocumentBenchmarkImporter.java b/src/test/java/com/arangodb/bench/ImportDocumentBenchmarkImporter.java index e4db6f3ba..a7abed823 100644 --- a/src/test/java/com/arangodb/bench/ImportDocumentBenchmarkImporter.java +++ b/src/test/java/com/arangodb/bench/ImportDocumentBenchmarkImporter.java @@ -18,7 +18,12 @@ public ImportDocumentBenchmarkImporter(ArangoDriver driver, String collectionNam @Override protected void execute(List values) throws Exception { - driver.importDocuments(collectionName, true, values); + try { + driver.createCollection(collectionName); + } catch (Exception ex) { + } + + driver.importDocuments(collectionName, values); } } diff --git a/src/test/java/com/arangodb/sandbox/ImportNico2Video.java b/src/test/java/com/arangodb/sandbox/ImportNico2Video.java index d1fabaab4..d42e37031 100644 --- a/src/test/java/com/arangodb/sandbox/ImportNico2Video.java +++ b/src/test/java/com/arangodb/sandbox/ImportNico2Video.java @@ -44,7 +44,7 @@ public static void main(String[] args) throws ArangoException, IllegalArgumentEx File file = new File("0000.dat.gz"); LineIterator itr = new LineIterator( new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), "utf-8"))); - client.importRawJsonDocuments("nico", true, itr, 10); + client.importRawJsonDocuments("nico", itr, 10); LineIterator.closeQuietly(itr); configure.shutdown(); From b0acfdfed7e90586de13a7ebc4bc84175734a749 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 20 May 2016 15:16:17 +0200 Subject: [PATCH 06/56] updates for ArangoDB 3.0.0 --- src/main/java/com/arangodb/ArangoDriver.java | 42 ---- .../arangodb/entity/EntityDeserializers.java | 16 +- .../java/com/arangodb/http/HttpManager.java | 12 +- .../arangodb/ArangoDriverDocumentTest.java | 11 +- .../com/arangodb/ArangoDriverSimpleTest.java | 189 ------------------ .../arangodb/ArangoDriverTransactionTest.java | 12 +- .../arangodb/example/TransactionExample.java | 5 + 7 files changed, 24 insertions(+), 263 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 703af2595..5bc48d80f 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -3087,48 +3087,6 @@ public ScalarExampleEntity executeSimpleAny(String collectionName, Class< return simpleDriver.executeSimpleAny(getDefaultDatabase(), collectionName, clazz); } - /** - * This will find all documents within a given range. In order to execute a - * range query, a skip-list index on the queried attribute must be present. - * - * @param collectionName - * The collection name. - * @param attribute - * The attribute path to check. - * @param left - * The lower bound - * @param right - * The upper bound - * @param closed - * If true, use interval including left and right, otherwise - * exclude right, but include left. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return a CursorEntity object - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleRangeWithDocuments(String, String, Object, Object, Boolean, int, int, Class)} - */ - @Deprecated - public CursorEntity executeSimpleRange( - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { - return simpleDriver.executeSimpleRange(getDefaultDatabase(), collectionName, attribute, left, right, closed, - skip, limit, clazz); - } - /** * This will find all documents within a given range. In order to execute a * range query, a skip-list index on the queried attribute must be present. diff --git a/src/main/java/com/arangodb/entity/EntityDeserializers.java b/src/main/java/com/arangodb/entity/EntityDeserializers.java index 8460334be..7bdae9b7f 100644 --- a/src/main/java/com/arangodb/entity/EntityDeserializers.java +++ b/src/main/java/com/arangodb/entity/EntityDeserializers.java @@ -749,15 +749,13 @@ public DocumentEntity deserialize(JsonElement json, Type typeOfT, JsonDeseria Class clazz = getParameterized(); if (clazz != null) { entity.entity = context.deserialize(obj, clazz); - // if - // (clazz.getName().equalsIgnoreCase(BaseDocument.class.getName())) - // { - // // iterate all key/value pairs of the jsonObject and - // // determine its class(String, Number, Boolean, HashMap, - // // List) - // ((BaseDocument) - // entity.entity).setProperties(DeserializeSingleEntry.deserializeJsonObject(obj)); - // } + + if (clazz.getName().equalsIgnoreCase(BaseDocument.class.getName())) { + // iterate all key/value pairs of the jsonObject and + // determine its class(String, Number, Boolean, HashMap, + // List) + ((BaseDocument) entity.entity).setProperties(DeserializeSingleEntry.deserializeJsonObject(obj)); + } } return entity; diff --git a/src/main/java/com/arangodb/http/HttpManager.java b/src/main/java/com/arangodb/http/HttpManager.java index f81315746..a7b5840aa 100644 --- a/src/main/java/com/arangodb/http/HttpManager.java +++ b/src/main/java/com/arangodb/http/HttpManager.java @@ -52,7 +52,6 @@ import org.apache.http.config.Registry; import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.ConnectionKeepAliveStrategy; -import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.PlainConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; @@ -62,8 +61,8 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.BasicHttpClientConnectionManager; import org.apache.http.impl.conn.DefaultProxyRoutePlanner; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.message.BasicHeaderElementIterator; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; @@ -88,7 +87,7 @@ public class HttpManager { private static Logger logger = LoggerFactory.getLogger(HttpManager.class); - private HttpClientConnectionManager cm; + private PoolingHttpClientConnectionManager cm; private CloseableHttpClient client; private ArangoConfigure configure; @@ -125,10 +124,9 @@ public void init() { .register("http", plainsf).register("https", sslsf).build(); // ConnectionManager - // cm = new PoolingHttpClientConnectionManager(r); - cm = new BasicHttpClientConnectionManager(r); - // cm.setDefaultMaxPerRoute(configure.getMaxPerConnection()); - // cm.setMaxTotal(configure.getMaxTotalConnection()); + cm = new PoolingHttpClientConnectionManager(r); + cm.setDefaultMaxPerRoute(configure.getMaxPerConnection()); + cm.setMaxTotal(configure.getMaxTotalConnection()); Builder custom = RequestConfig.custom(); diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java index dd995f247..4efd176d6 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java @@ -401,16 +401,7 @@ public void test_getDocuments() throws ArangoException { List documents = driver.getDocuments(collectionName); assertEquals(3, documents.size()); - String prefix; - if (documents.get(0).startsWith("/_db/")) { - // since ArangoDB 2.6 - prefix = "/_db/" + DATABASE_NAME + "/_api/document/"; - } else { - prefix = "/_api/document/"; - } - - List list = Arrays.asList(prefix + doc1.getDocumentHandle(), prefix + doc2.getDocumentHandle(), - prefix + doc3.getDocumentHandle()); + List list = Arrays.asList(doc1.getDocumentHandle(), doc2.getDocumentHandle(), doc3.getDocumentHandle()); assertTrue(documents.containsAll(list)); } diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java index 771ab2fb5..a5d7661cb 100644 --- a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java +++ b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java @@ -71,7 +71,6 @@ public void setup() throws ArangoException { driver.createCollection(COLLECTION_NAME); } catch (ArangoException e) { } - driver.truncateCollection(COLLECTION_NAME); // add some test data for (int i = 0; i < 100; i++) { @@ -105,52 +104,6 @@ public void test_simple_all() throws ArangoException { assertThat(count, is(100)); } - @SuppressWarnings("deprecation") - @Test - public void test_simple_all_deprecated() throws ArangoException { - - CursorResultSet rs = driver.executeSimpleAllWithResultSet(COLLECTION_NAME, 0, 0, - TestComplexEntity01.class); - int count = 0; - while (rs.hasNext()) { - TestComplexEntity01 entity = rs.next(); - count++; - - assertThat(entity, is(notNullValue())); - } - rs.close(); - - assertThat(count, is(100)); - } - - @SuppressWarnings("deprecation") - @Test - public void test_simple_all_with_doc_deprecated() throws ArangoException { - - CursorResultSet> rs = driver - .executeSimpleAllWithDocumentResultSet(COLLECTION_NAME, 0, 0, TestComplexEntity01.class); - int count = 0; - int ageCount = 0; - while (rs.hasNext()) { - DocumentEntity doc = rs.next(); - count++; - - assertThat(doc, is(notNullValue())); - assertThat(doc.getDocumentHandle(), startsWith(COLLECTION_NAME)); - assertThat(doc.getDocumentKey(), is(notNullValue())); - assertThat(doc.getDocumentRevision(), is(not(0L))); - - if (doc.getEntity().getAge() != 0) { - ageCount++; - } - } - rs.close(); - - assertThat(count, is(100)); - assertThat(ageCount, is(99)); - - } - @Test public void test_example_by() throws ArangoException { @@ -168,48 +121,6 @@ public void test_example_by() throws ArangoException { assertThat(count, is(10)); } - @SuppressWarnings("deprecation") - @Test - public void test_example_by_deprecated() throws ArangoException { - - CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, - new MapBuilder().put("user", "user_6").get(), 0, 0, TestComplexEntity01.class); - int count = 0; - while (rs.hasNext()) { - TestComplexEntity01 entity = rs.next(); - count++; - - assertThat(entity.getUser(), is("user_6")); - } - rs.close(); - - assertThat(count, is(10)); - - } - - @SuppressWarnings("deprecation") - @Test - public void test_example_by_with_doc_deprecated() throws ArangoException { - - CursorResultSet> rs = driver.executeSimpleByExampleWithDocumentResusltSet( - COLLECTION_NAME, new MapBuilder().put("user", "user_6").get(), 0, 0, TestComplexEntity01.class); - int count = 0; - while (rs.hasNext()) { - DocumentEntity doc = rs.next(); - count++; - - assertThat(doc.getDocumentHandle(), startsWith(COLLECTION_NAME)); - assertThat(doc.getDocumentKey(), is(notNullValue())); - assertThat(doc.getDocumentRevision(), is(not(0L))); - - assertThat(doc.getEntity().getUser(), is("user_6")); - } - rs.close(); - - assertThat(count, is(10)); - - } - @Test public void test_first_example() throws ArangoException { @@ -263,22 +174,6 @@ public void test_range_no_skiplist() throws ArangoException { } - @SuppressWarnings("deprecation") - @Test - public void test_range_no_skiplist_deprecated() throws ArangoException { - - // no suitable index known - try { - driver.executeSimpleRangeWithResultSet(COLLECTION_NAME, "age", 5, 30, null, 0, 0, - TestComplexEntity01.class); - fail("request should fail"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(1209)); - assertThat(e.getCode(), is(404)); - } - - } - @Test public void test_range() throws ArangoException { @@ -317,90 +212,6 @@ public void test_range() throws ArangoException { } - @SuppressWarnings("deprecation") - @Test - public void test_range_deprecated() throws ArangoException { - - // create skip-list - driver.createIndex(COLLECTION_NAME, IndexType.SKIPLIST, false, "age"); - - { - CursorResultSet rs = driver.executeSimpleRangeWithResultSet(COLLECTION_NAME, "age", 5, - 30, null, 0, 0, TestComplexEntity01.class); - - int count = 0; - while (rs.hasNext()) { - TestComplexEntity01 entity = rs.next(); - count++; - assertThat(entity, is(notNullValue())); - } - rs.close(); - assertThat(count, is(25)); - } - - { - CursorResultSet rs = driver.executeSimpleRangeWithResultSet(COLLECTION_NAME, "age", 5, - 30, true, 0, 0, TestComplexEntity01.class); - - int count = 0; - while (rs.hasNext()) { - TestComplexEntity01 entity = rs.next(); - count++; - assertThat(entity, is(notNullValue())); - } - rs.close(); - assertThat(count, is(26)); - } - - } - - @SuppressWarnings("deprecation") - @Test - public void test_range_with_doc_deprecated() throws ArangoException { - - // create skip-list - driver.createIndex(COLLECTION_NAME, IndexType.SKIPLIST, false, "age"); - - { - CursorResultSet> rs = driver.executeSimpleRangeWithDocumentResultSet( - COLLECTION_NAME, "age", 5, 30, null, 0, 0, TestComplexEntity01.class); - - int count = 0; - while (rs.hasNext()) { - DocumentEntity doc = rs.next(); - count++; - assertThat(doc, is(notNullValue())); - assertThat(doc.getDocumentHandle(), startsWith(COLLECTION_NAME)); - assertThat(doc.getDocumentKey(), is(notNullValue())); - assertThat(doc.getDocumentRevision(), is(not(0L))); - assertThat(doc.getEntity(), is(notNullValue())); - assertThat(doc.getEntity().getAge(), is(not(0))); - } - rs.close(); - assertThat(count, is(25)); - } - - { - CursorResultSet> rs = driver.executeSimpleRangeWithDocumentResultSet( - COLLECTION_NAME, "age", 5, 30, true, 0, 0, TestComplexEntity01.class); - - int count = 0; - while (rs.hasNext()) { - DocumentEntity doc = rs.next(); - count++; - assertThat(doc, is(notNullValue())); - assertThat(doc.getDocumentHandle(), startsWith(COLLECTION_NAME)); - assertThat(doc.getDocumentKey(), is(notNullValue())); - assertThat(doc.getDocumentRevision(), is(not(0L))); - assertThat(doc.getEntity(), is(notNullValue())); - assertThat(doc.getEntity().getAge(), is(not(0))); - } - rs.close(); - assertThat(count, is(26)); - } - - } - @Test public void test_remove_by_example() throws ArangoException { diff --git a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java index 789d20355..26141ecd7 100644 --- a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java @@ -32,6 +32,8 @@ */ public class ArangoDriverTransactionTest extends BaseTest { + private static final String SOME_COLLECTION = "someCollection"; + public class ParamObject { private String a = "a"; @@ -70,15 +72,13 @@ public ArangoDriverTransactionTest(ArangoConfigure configure, ArangoDriver drive @Before public void setup() throws ArangoException { - TestComplexEntity01 value = new TestComplexEntity01("user-" + 9999, "desc:" + 9999, 9999); - driver.createDocument("someCollection", value, true, false); try { - driver.deleteCollection("someCollection"); + driver.deleteCollection(SOME_COLLECTION); } catch (ArangoException e) { } try { - driver.createCollection("someCollection"); + driver.createCollection(SOME_COLLECTION); } catch (ArangoException e) { } @@ -87,7 +87,7 @@ public void setup() throws ArangoException { @After public void teardown() throws ArangoException { try { - driver.deleteCollection("someCollection"); + driver.deleteCollection(SOME_COLLECTION); } catch (ArangoException e) { } @@ -107,7 +107,7 @@ public void test_Transaction() throws ArangoException { transaction = driver.createTransaction("function (params) {" + "var db = require('internal').db;" + "return db.someCollection.all().toArray()[0];" + "}"); - transaction.addReadCollection("someCollection"); + transaction.addReadCollection(SOME_COLLECTION); result = driver.executeTransaction(transaction); assertThat(result.getStatusCode(), is(200)); diff --git a/src/test/java/com/arangodb/example/TransactionExample.java b/src/test/java/com/arangodb/example/TransactionExample.java index 3287e9321..91ae34676 100644 --- a/src/test/java/com/arangodb/example/TransactionExample.java +++ b/src/test/java/com/arangodb/example/TransactionExample.java @@ -60,6 +60,11 @@ public void _before() { configuration = getConfiguration(); arangoDriver = getArangoDriver(configuration); createDatabase(arangoDriver, DATABASE_NAME); + + try { + arangoDriver.createCollection(COLLECTION_NAME); + } catch (Exception ex) { + } } @Test From 07169caa217a28a3d183e81efee74da433d777bf Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 20 May 2016 15:53:17 +0200 Subject: [PATCH 07/56] fixed simple/range --- .../arangodb/impl/InternalDocumentDriverImpl.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java index 84e618cbc..edfe00b82 100644 --- a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.ListIterator; import java.util.Locale; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -126,10 +127,15 @@ public DocumentEntity replaceDocument( Boolean waitForSync) throws ArangoException { validateDocumentHandle(documentHandle); - HttpResponseEntity res = httpManager.doPut( - createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("rev", rev) - .put(POLICY, policy == null ? null : policy.name()).put(WAIT_FOR_SYNC, waitForSync).get(), - EntityFactory.toJsonString(value)); + + Map header = null; + if (rev != null) { + MapBuilder mapBuilder = new MapBuilder().put("If-Match", rev); + header = mapBuilder.get(); + } + + HttpResponseEntity res = httpManager.doPut(createDocumentEndpointUrl(database, documentHandle), header, + new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(value)); DocumentEntity result = createEntity(res, DocumentEntity.class); annotationHandler.updateDocumentRev(value, result.getDocumentRevision()); From eb99c1675c9a18fcb28fd5fdc8152478a1fe6206 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 24 May 2016 08:41:29 +0200 Subject: [PATCH 08/56] HttpManager.destory() should close HttpClient --- .../java/com/arangodb/http/HttpManager.java | 272 ++++++++++-------- 1 file changed, 149 insertions(+), 123 deletions(-) diff --git a/src/main/java/com/arangodb/http/HttpManager.java b/src/main/java/com/arangodb/http/HttpManager.java index a7b5840aa..0e62818f8 100644 --- a/src/main/java/com/arangodb/http/HttpManager.java +++ b/src/main/java/com/arangodb/http/HttpManager.java @@ -68,6 +68,7 @@ import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; import org.apache.http.ssl.SSLContexts; +import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,13 +99,13 @@ public class HttpManager { private List jobIds = new ArrayList(); - private Map jobs = new HashMap(); + private final Map jobs = new HashMap(); public enum HttpMode { SYNC, ASYNC, FIREANDFORGET } - public HttpManager(ArangoConfigure configure) { + public HttpManager(final ArangoConfigure configure) { this.configure = configure; } @@ -114,13 +115,13 @@ public ArangoConfigure getConfiguration() { public void init() { // socket factory for HTTP - ConnectionSocketFactory plainsf = new PlainConnectionSocketFactory(); + final ConnectionSocketFactory plainsf = new PlainConnectionSocketFactory(); // socket factory for HTTPS - SSLConnectionSocketFactory sslsf = initSSLConnectionSocketFactory(); + final SSLConnectionSocketFactory sslsf = initSSLConnectionSocketFactory(); // register socket factories - Registry r = RegistryBuilder. create() + final Registry r = RegistryBuilder. create() .register("http", plainsf).register("https", sslsf).build(); // ConnectionManager @@ -128,7 +129,7 @@ public void init() { cm.setDefaultMaxPerRoute(configure.getMaxPerConnection()); cm.setMaxTotal(configure.getMaxTotalConnection()); - Builder custom = RequestConfig.custom(); + final Builder custom = RequestConfig.custom(); // RequestConfig if (configure.getConnectionTimeout() >= 0) { @@ -140,16 +141,16 @@ public void init() { } custom.setStaleConnectionCheckEnabled(configure.isStaleConnectionCheck()); - RequestConfig requestConfig = custom.build(); + final RequestConfig requestConfig = custom.build(); - HttpClientBuilder builder = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig); + final HttpClientBuilder builder = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig); builder.setConnectionManager(cm); // KeepAlive Strategy - ConnectionKeepAliveStrategy keepAliveStrategy = new ConnectionKeepAliveStrategy() { + final ConnectionKeepAliveStrategy keepAliveStrategy = new ConnectionKeepAliveStrategy() { @Override - public long getKeepAliveDuration(HttpResponse response, HttpContext context) { + public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) { return HttpManager.this.getKeepAliveDuration(response); } @@ -166,17 +167,17 @@ public long getKeepAliveDuration(HttpResponse response, HttpContext context) { client = builder.build(); } - private long getKeepAliveDuration(HttpResponse response) { + private long getKeepAliveDuration(final HttpResponse response) { // Honor 'keep-alive' header - HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); + final HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { - HeaderElement he = it.nextElement(); - String param = he.getName(); - String value = he.getValue(); + final HeaderElement he = it.nextElement(); + final String param = he.getName(); + final String value = he.getValue(); if (value != null && "timeout".equalsIgnoreCase(param)) { try { return Long.parseLong(value) * 1000L; - } catch (NumberFormatException ignore) { + } catch (final NumberFormatException ignore) { // ignore this exception } } @@ -185,11 +186,11 @@ private long getKeepAliveDuration(HttpResponse response) { return 30L * 1000L; } - private void addProxyToBuilder(HttpClientBuilder builder) { + private void addProxyToBuilder(final HttpClientBuilder builder) { if (configure.getProxyHost() != null && configure.getProxyPort() != 0) { - HttpHost proxy = new HttpHost(configure.getProxyHost(), configure.getProxyPort(), "http"); + final HttpHost proxy = new HttpHost(configure.getProxyHost(), configure.getProxyPort(), "http"); - DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); + final DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy); builder.setRoutePlanner(routePlanner); } } @@ -199,67 +200,77 @@ public void destroy() { cm.shutdown(); } configure = null; + try { + if (client != null) { + client.close(); + } + } catch (final IOException e) { + } } public HttpMode getHttpMode() { return httpMode; } - public void setHttpMode(HttpMode httpMode) { + public void setHttpMode(final HttpMode httpMode) { this.httpMode = httpMode; } - public HttpResponseEntity doGet(String url) throws ArangoException { + public HttpResponseEntity doGet(final String url) throws ArangoException { return doGet(url, null); } - public HttpResponseEntity doGet(String url, Map params) throws ArangoException { + public HttpResponseEntity doGet(final String url, final Map params) throws ArangoException { return doHeadGetDelete(RequestType.GET, url, null, params); } - public HttpResponseEntity doGet(String url, Map headers, Map params) - throws ArangoException { + public HttpResponseEntity doGet( + final String url, + final Map headers, + final Map params) throws ArangoException { return doHeadGetDelete(RequestType.GET, url, headers, params); } public HttpResponseEntity doGet( - String url, - Map headers, - Map params, - String username, - String password) throws ArangoException { + final String url, + final Map headers, + final Map params, + final String username, + final String password) throws ArangoException { return doHeadGetDelete(RequestType.GET, url, headers, params, username, password); } - public HttpResponseEntity doHead(String url, Map params) throws ArangoException { + public HttpResponseEntity doHead(final String url, final Map params) throws ArangoException { return doHeadGetDelete(RequestType.HEAD, url, null, params); } - public HttpResponseEntity doDelete(String url, Map params) throws ArangoException { + public HttpResponseEntity doDelete(final String url, final Map params) throws ArangoException { return doHeadGetDelete(RequestType.DELETE, url, null, params); } - public HttpResponseEntity doDelete(String url, Map headers, Map params) - throws ArangoException { + public HttpResponseEntity doDelete( + final String url, + final Map headers, + final Map params) throws ArangoException { return doHeadGetDelete(RequestType.DELETE, url, headers, params); } public HttpResponseEntity doHeadGetDelete( - RequestType type, - String url, - Map headers, - Map params) throws ArangoException { + final RequestType type, + final String url, + final Map headers, + final Map params) throws ArangoException { return doHeadGetDelete(type, url, headers, params, null, null); } public HttpResponseEntity doHeadGetDelete( - RequestType type, - String url, - Map headers, - Map params, - String username, - String password) throws ArangoException { - HttpRequestEntity requestEntity = new HttpRequestEntity(); + final RequestType type, + final String url, + final Map headers, + final Map params, + final String username, + final String password) throws ArangoException { + final HttpRequestEntity requestEntity = new HttpRequestEntity(); requestEntity.type = type; requestEntity.url = url; requestEntity.headers = headers; @@ -270,62 +281,66 @@ public HttpResponseEntity doHeadGetDelete( } public HttpResponseEntity doPost( - String url, - Map headers, - Map params, - String bodyText) throws ArangoException { + final String url, + final Map headers, + final Map params, + final String bodyText) throws ArangoException { return doPostPutPatch(RequestType.POST, url, headers, params, bodyText, null); } - public HttpResponseEntity doPost(String url, Map params, String bodyText) throws ArangoException { + public HttpResponseEntity doPost(final String url, final Map params, final String bodyText) + throws ArangoException { return doPostPutPatch(RequestType.POST, url, null, params, bodyText, null); } - public HttpResponseEntity doPost(String url, Map params, HttpEntity entity) throws ArangoException { + public HttpResponseEntity doPost(final String url, final Map params, final HttpEntity entity) + throws ArangoException { return doPostPutPatch(RequestType.POST, url, null, params, null, entity); } public HttpResponseEntity doPostWithHeaders( - String url, - Map params, - HttpEntity entity, - Map headers, - String body) throws ArangoException { + final String url, + final Map params, + final HttpEntity entity, + final Map headers, + final String body) throws ArangoException { return doPostPutPatch(RequestType.POST, url, headers, params, body, entity); } public HttpResponseEntity doPut( - String url, - Map headers, - Map params, - String bodyText) throws ArangoException { + final String url, + final Map headers, + final Map params, + final String bodyText) throws ArangoException { return doPostPutPatch(RequestType.PUT, url, headers, params, bodyText, null); } - public HttpResponseEntity doPut(String url, Map params, String bodyText) throws ArangoException { + public HttpResponseEntity doPut(final String url, final Map params, final String bodyText) + throws ArangoException { return doPostPutPatch(RequestType.PUT, url, null, params, bodyText, null); } public HttpResponseEntity doPatch( - String url, - Map headers, - Map params, - String bodyText) throws ArangoException { + final String url, + final Map headers, + final Map params, + final String bodyText) throws ArangoException { return doPostPutPatch(RequestType.PATCH, url, headers, params, bodyText, null); } - public HttpResponseEntity doPatch(String url, Map params, String bodyText) throws ArangoException { + public HttpResponseEntity doPatch(final String url, final Map params, final String bodyText) + throws ArangoException { return doPostPutPatch(RequestType.PATCH, url, null, params, bodyText, null); } private HttpResponseEntity doPostPutPatch( - RequestType type, - String url, - Map headers, - Map params, - String bodyText, - HttpEntity entity) throws ArangoException { - HttpRequestEntity requestEntity = new HttpRequestEntity(); + final RequestType type, + final String url, + final Map headers, + final Map params, + final String bodyText, + final HttpEntity entity) throws ArangoException { + final HttpRequestEntity requestEntity = new HttpRequestEntity(); requestEntity.type = type; requestEntity.url = url; requestEntity.headers = headers; @@ -344,14 +359,14 @@ private HttpResponseEntity doPostPutPatch( * * @throws ArangoException */ - public HttpResponseEntity execute(HttpRequestEntity requestEntity) throws ArangoException { + public HttpResponseEntity execute(final HttpRequestEntity requestEntity) throws ArangoException { int retries = 0; - int connectRetryCount = configure.getConnectRetryCount(); + final int connectRetryCount = configure.getConnectRetryCount(); while (true) { try { return executeInternal(configure.getBaseUrl(), requestEntity); - } catch (SocketException ex) { + } catch (final SocketException ex) { retries++; if (connectRetryCount > 0 && retries > connectRetryCount) { logger.error(ex.getMessage(), ex); @@ -366,7 +381,7 @@ public HttpResponseEntity execute(HttpRequestEntity requestEntity) throws Arango try { // 1000 milliseconds is one second. Thread.sleep(configure.getConnectRetryWait()); - } catch (InterruptedException iex) { + } catch (final InterruptedException iex) { Thread.currentThread().interrupt(); } } @@ -381,17 +396,17 @@ public HttpResponseEntity execute(HttpRequestEntity requestEntity) throws Arango * @return the response of the request * @throws ArangoException */ - private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity requestEntity) + private HttpResponseEntity executeInternal(final String baseUrl, final HttpRequestEntity requestEntity) throws ArangoException, SocketException { - String url = buildUrl(baseUrl, requestEntity); + final String url = buildUrl(baseUrl, requestEntity); logRequest(requestEntity, url); - HttpRequestBase request = buildHttpRequestBase(requestEntity, url); + final HttpRequestBase request = buildHttpRequestBase(requestEntity, url); // common-header - String userAgent = "Mozilla/5.0 (compatible; ArangoDB-JavaDriver/1.1; +http://mt.orz.at/)"; + final String userAgent = "Mozilla/5.0 (compatible; ArangoDB-JavaDriver/1.1; +http://mt.orz.at/)"; request.setHeader("User-Agent", userAgent); addOptionalHeaders(requestEntity, request); @@ -399,7 +414,7 @@ private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity req addHttpModeHeader(request); // Basic Auth - Credentials credentials = addCredentials(requestEntity, request); + final Credentials credentials = addCredentials(requestEntity, request); // CURL/HTTP Logger if (configure.isEnableCURLLogger()) { @@ -410,16 +425,17 @@ private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity req if (preDefinedResponse != null) { responseEntity = preDefinedResponse; } else { - HttpResponse response = executeRequest(request); + final HttpResponse response = executeRequest(request); if (response != null) { try { responseEntity = buildHttpResponseEntity(requestEntity, response); - } catch (IOException e) { + consumeResponse(response); + } catch (final IOException e) { throw new ArangoException(e); } if (this.getHttpMode().equals(HttpMode.ASYNC)) { - Map map = responseEntity.getHeaders(); + final Map map = responseEntity.getHeaders(); this.addJob(map.get("X-Arango-Async-Id"), this.getCurrentObject()); } else if (this.getHttpMode().equals(HttpMode.FIREANDFORGET)) { responseEntity = null; @@ -430,25 +446,33 @@ private HttpResponseEntity executeInternal(String baseUrl, HttpRequestEntity req return responseEntity; } - private HttpResponse executeRequest(HttpRequestBase request) throws SocketException, ArangoException { + private void consumeResponse(final HttpResponse response) throws IOException { + final HttpEntity entity = response.getEntity(); + if (entity != null) { + EntityUtils.consume(entity); + } + } + + private HttpResponse executeRequest(final HttpRequestBase request) throws SocketException, ArangoException { try { return client.execute(request); - } catch (SocketException ex) { + } catch (final SocketException ex) { // catch SocketException before IOException throw ex; - } catch (ClientProtocolException e) { + } catch (final ClientProtocolException e) { throw new ArangoException(e); - } catch (IOException e) { + } catch (final IOException e) { throw new ArangoException(e); } } - private HttpResponseEntity buildHttpResponseEntity(HttpRequestEntity requestEntity, HttpResponse response) - throws IOException { - HttpResponseEntity responseEntity = new HttpResponseEntity(); + private HttpResponseEntity buildHttpResponseEntity( + final HttpRequestEntity requestEntity, + final HttpResponse response) throws IOException { + final HttpResponseEntity responseEntity = new HttpResponseEntity(); // http status - StatusLine status = response.getStatusLine(); + final StatusLine status = response.getStatusLine(); responseEntity.statusCode = status.getStatusCode(); responseEntity.statusPhrase = status.getReasonPhrase(); @@ -458,20 +482,20 @@ private HttpResponseEntity buildHttpResponseEntity(HttpRequestEntity requestEnti // ヘッダの処理 // // TODO etag特殊処理は削除する。 - Header etagHeader = response.getLastHeader("etag"); + final Header etagHeader = response.getLastHeader("etag"); if (etagHeader != null) { responseEntity.etag = Long.parseLong(etagHeader.getValue().replace("\"", "")); } // ヘッダをMapに変換する responseEntity.headers = new TreeMap(); - for (Header header : response.getAllHeaders()) { + for (final Header header : response.getAllHeaders()) { responseEntity.headers.put(header.getName(), header.getValue()); } // レスポンスの取得 - HttpEntity entity = response.getEntity(); + final HttpEntity entity = response.getEntity(); if (entity != null) { - Header contentType = entity.getContentType(); + final Header contentType = entity.getContentType(); if (contentType != null) { responseEntity.contentType = contentType.getValue(); if (responseEntity.isDumpResponse()) { @@ -492,7 +516,7 @@ private HttpResponseEntity buildHttpResponseEntity(HttpRequestEntity requestEnti return responseEntity; } - private void addHttpModeHeader(HttpRequestBase request) { + private void addHttpModeHeader(final HttpRequestBase request) { if (this.getHttpMode().equals(HttpMode.ASYNC)) { request.addHeader("x-arango-async", "store"); } else if (this.getHttpMode().equals(HttpMode.FIREANDFORGET)) { @@ -500,7 +524,7 @@ private void addHttpModeHeader(HttpRequestBase request) { } } - private Credentials addCredentials(HttpRequestEntity requestEntity, HttpRequestBase request) + private Credentials addCredentials(final HttpRequestEntity requestEntity, final HttpRequestBase request) throws ArangoException { Credentials credentials = null; if (requestEntity.username != null && requestEntity.password != null) { @@ -509,39 +533,39 @@ private Credentials addCredentials(HttpRequestEntity requestEntity, HttpRequestB credentials = new UsernamePasswordCredentials(configure.getUser(), configure.getPassword()); } if (credentials != null) { - BasicScheme basicScheme = new BasicScheme(); + final BasicScheme basicScheme = new BasicScheme(); try { request.addHeader(basicScheme.authenticate(credentials, request, null)); - } catch (AuthenticationException e) { + } catch (final AuthenticationException e) { throw new ArangoException(e); } } return credentials; } - private void addOptionalHeaders(HttpRequestEntity requestEntity, HttpRequestBase request) { + private void addOptionalHeaders(final HttpRequestEntity requestEntity, final HttpRequestBase request) { if (requestEntity.headers != null) { - for (Entry keyValue : requestEntity.headers.entrySet()) { + for (final Entry keyValue : requestEntity.headers.entrySet()) { request.setHeader(keyValue.getKey(), keyValue.getValue().toString()); } } } - private HttpRequestBase buildHttpRequestBase(HttpRequestEntity requestEntity, String url) { + private HttpRequestBase buildHttpRequestBase(final HttpRequestEntity requestEntity, final String url) { HttpRequestBase request; switch (requestEntity.type) { case POST: - HttpPost post = new HttpPost(url); + final HttpPost post = new HttpPost(url); configureBodyParams(requestEntity, post); request = post; break; case PUT: - HttpPut put = new HttpPut(url); + final HttpPut put = new HttpPut(url); configureBodyParams(requestEntity, put); request = put; break; case PATCH: - HttpPatch patch = new HttpPatch(url); + final HttpPatch patch = new HttpPatch(url); configureBodyParams(requestEntity, patch); request = patch; break; @@ -559,7 +583,7 @@ private HttpRequestBase buildHttpRequestBase(HttpRequestEntity requestEntity, St return request; } - private void logRequest(HttpRequestEntity requestEntity, String url) { + private void logRequest(final HttpRequestEntity requestEntity, final String url) { if (logger.isDebugEnabled()) { if (requestEntity.type == RequestType.POST || requestEntity.type == RequestType.PUT || requestEntity.type == RequestType.PATCH) { @@ -572,9 +596,9 @@ private void logRequest(HttpRequestEntity requestEntity, String url) { } } - public static String buildUrl(String baseUrl, HttpRequestEntity requestEntity) { + public static String buildUrl(final String baseUrl, final HttpRequestEntity requestEntity) { if (requestEntity.parameters != null && !requestEntity.parameters.isEmpty()) { - String paramString = URLEncodedUtils.format(toList(requestEntity.parameters), "utf-8"); + final String paramString = URLEncodedUtils.format(toList(requestEntity.parameters), "utf-8"); if (requestEntity.url.contains("?")) { return baseUrl + requestEntity.url + "&" + paramString; } else { @@ -584,9 +608,9 @@ public static String buildUrl(String baseUrl, HttpRequestEntity requestEntity) { return baseUrl + requestEntity.url; } - private static List toList(Map parameters) { - ArrayList paramList = new ArrayList(parameters.size()); - for (Entry param : parameters.entrySet()) { + private static List toList(final Map parameters) { + final ArrayList paramList = new ArrayList(parameters.size()); + for (final Entry param : parameters.entrySet()) { if (param.getValue() != null) { paramList.add(new BasicNameValuePair(param.getKey(), param.getValue().toString())); } @@ -594,7 +618,9 @@ private static List toList(Map parameters) { return paramList; } - public static void configureBodyParams(HttpRequestEntity requestEntity, HttpEntityEnclosingRequestBase request) { + public static void configureBodyParams( + final HttpRequestEntity requestEntity, + final HttpEntityEnclosingRequestBase request) { if (requestEntity.entity != null) { request.setEntity(requestEntity.entity); @@ -604,31 +630,31 @@ public static void configureBodyParams(HttpRequestEntity requestEntity, HttpEnti } - public static boolean is400Error(ArangoException e) { + public static boolean is400Error(final ArangoException e) { return e.getCode() == HttpStatus.SC_BAD_REQUEST; } - public static boolean is404Error(ArangoException e) { + public static boolean is404Error(final ArangoException e) { return e.getCode() == HttpStatus.SC_NOT_FOUND; } - public static boolean is412Error(ArangoException e) { + public static boolean is412Error(final ArangoException e) { return e.getCode() == HttpStatus.SC_PRECONDITION_FAILED; } - public static boolean is200(HttpResponseEntity res) { + public static boolean is200(final HttpResponseEntity res) { return res.getStatusCode() == HttpStatus.SC_OK; } - public static boolean is400Error(HttpResponseEntity res) { + public static boolean is400Error(final HttpResponseEntity res) { return res.getStatusCode() == HttpStatus.SC_BAD_REQUEST; } - public static boolean is404Error(HttpResponseEntity res) { + public static boolean is404Error(final HttpResponseEntity res) { return res.getStatusCode() == HttpStatus.SC_NOT_FOUND; } - public static boolean is412Error(HttpResponseEntity res) { + public static boolean is412Error(final HttpResponseEntity res) { return res.getStatusCode() == HttpStatus.SC_PRECONDITION_FAILED; } @@ -641,11 +667,11 @@ public InvocationObject getCurrentObject() { return null; } - public void setCurrentObject(InvocationObject currentObject) { + public void setCurrentObject(final InvocationObject currentObject) { // do nothing here (used in BatchHttpManager) } - public void setPreDefinedResponse(HttpResponseEntity preDefinedResponse) { + public void setPreDefinedResponse(final HttpResponseEntity preDefinedResponse) { this.preDefinedResponse = preDefinedResponse; } @@ -657,7 +683,7 @@ public Map getJobs() { return jobs; } - public void addJob(String jobId, InvocationObject invocationObject) { + public void addJob(final String jobId, final InvocationObject invocationObject) { jobIds.add(jobId); jobs.put(jobId, invocationObject); } From 8e8fc1c52bcb828a83e2a6fefe5803ae5d22c1e2 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 24 May 2016 08:42:18 +0200 Subject: [PATCH 09/56] optimize tests (too many open http connections) -step 1 --- .../ArangoDriverDatabaseAndUserTest.java | 149 +++++++++--------- .../arangodb/ArangoDriverDatabaseTest.java | 75 +++++---- .../arangodb/ArangoDriverEndpointTest.java | 74 ++++++--- .../ArangoDriverReplicationTestScenario1.java | 46 +++--- src/test/java/com/arangodb/BaseTest.java | 70 +++++--- .../com/arangodb/bench/BenchmarkImport.java | 29 ++-- .../arangodb/example/TransactionExample.java | 89 ++++++----- ...AqlQueryWithSpecialReturnTypesExample.java | 43 +++-- .../example/document/BaseExample.java | 49 +++--- .../example/document/CollectionExample.java | 50 +++--- .../CreateAndDeleteDatabaseExample.java | 34 ++-- .../document/CreateDocumentExample.java | 52 +++--- .../DocumentPersonAqlQueryExample.java | 39 +++-- .../example/document/RawDocumentExample.java | 75 +++++---- .../example/document/ReadDocumentExample.java | 66 ++++---- .../ReplaceAndUpdateDocumentExample.java | 54 ++++--- .../document/SimplePersonAqlQueryExample.java | 46 ++++-- .../SimplePersonAqlQueryWithLimitExample.java | 40 +++-- .../arangodb/example/graph/BaseExample.java | 68 ++++---- .../example/graph/CreateGraphExample.java | 28 +++- .../graph/CreateVerticesAndEdgesExample.java | 34 ++-- .../graph/DeleteVerticesAndEdgesExample.java | 52 +++--- .../graph/GetVerticesAndEdgesExample.java | 119 +++++++------- .../example/graph/GraphAqlQueryExample.java | 90 ++++++----- .../graph/GraphAqlTraversalQueryExample.java | 68 ++++---- .../graph/UpdateAndReplaceVertexExample.java | 48 +++--- 26 files changed, 931 insertions(+), 656 deletions(-) diff --git a/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java b/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java index 9476b385e..0d5d960c0 100644 --- a/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java @@ -37,78 +37,81 @@ */ public class ArangoDriverDatabaseAndUserTest { - ArangoConfigure configure; - ArangoDriver driver; - - @Before - public void before() { - - configure = new ArangoConfigure(); - configure.init(); - driver = new ArangoDriver(configure); - - } - - @After - public void after() { - configure.shutdown(); - } - - @Test - public void test_create_database_with_users_and_database_user() throws ArangoException { - - String database = "db-1"; - - try { - driver.deleteDatabase(database); - } catch (ArangoException e) { - } - - try { - driver.deleteDatabase("unitTestDatabase"); - } catch (ArangoException e) { - } - - BooleanResultEntity entity = driver.createDatabase(database, new UserEntity("user1", "pass1", true, null), - new UserEntity("user2", "pass2", false, null), - new UserEntity("user3", "pass3", true, new MapBuilder().put("attr1", "value1").get()), new UserEntity( - "user4", "pass4", false, new MapBuilder().put("attr2", "value2").get())); - assertThat(entity.getResult(), is(true)); - - // change default db - try { - driver.createUser("user1", "pass1", true, null); - } catch (ArangoException e) { - } - driver.setDefaultDatabase(database); - - // root user cannot access - try { - driver.getUsers(); - fail(); - } catch (ArangoException e) { - assertThat(e.isUnauthorized(), is(true)); - } - - // user1 can access - configure.setUser("user1"); - configure.setPassword("pass1"); - StringsResultEntity res2 = driver.getDatabases(true); - assertThat(res2.getResult(), is(Arrays.asList("_system", "db-1"))); - - // user2 cannot access - configure.setUser("user2"); - configure.setPassword("pass2"); - try { - driver.getUsers(); - fail(); - } catch (ArangoException e) { - assertThat(e.isUnauthorized(), is(true)); - } - - StringsResultEntity res3 = driver.getDatabases("user1", "pass1"); - assertThat(res3.getResult(), is(Arrays.asList("_system", "db-1"))); - - } + private ArangoConfigure configure; + private ArangoDriver driver; + private static final String DATABASE = "db-1"; + + @Before + public void before() { + + configure = new ArangoConfigure(); + configure.init(); + driver = new ArangoDriver(configure); + + } + + @After + public void after() { + try { + driver.deleteDatabase(DATABASE); + } catch (final ArangoException e) { + } + configure.shutdown(); + } + + @Test + public void test_create_database_with_users_and_database_user() throws ArangoException { + + try { + driver.deleteDatabase(DATABASE); + } catch (final ArangoException e) { + } + + try { + driver.deleteDatabase("unitTestDatabase"); + } catch (final ArangoException e) { + } + + final BooleanResultEntity entity = driver.createDatabase(DATABASE, new UserEntity("user1", "pass1", true, null), + new UserEntity("user2", "pass2", false, null), + new UserEntity("user3", "pass3", true, new MapBuilder().put("attr1", "value1").get()), + new UserEntity("user4", "pass4", false, new MapBuilder().put("attr2", "value2").get())); + assertThat(entity.getResult(), is(true)); + + // change default db + try { + driver.createUser("user1", "pass1", true, null); + } catch (final ArangoException e) { + } + driver.setDefaultDatabase(DATABASE); + + // root user cannot access + try { + driver.getUsers(); + fail(); + } catch (final ArangoException e) { + assertThat(e.isUnauthorized(), is(true)); + } + + // user1 can access + configure.setUser("user1"); + configure.setPassword("pass1"); + final StringsResultEntity res2 = driver.getDatabases(true); + assertThat(res2.getResult(), is(Arrays.asList("_system", DATABASE))); + + // user2 cannot access + configure.setUser("user2"); + configure.setPassword("pass2"); + try { + driver.getUsers(); + fail(); + } catch (final ArangoException e) { + assertThat(e.isUnauthorized(), is(true)); + } + + final StringsResultEntity res3 = driver.getDatabases("user1", "pass1"); + assertThat(res3.getResult(), is(Arrays.asList("_system", DATABASE))); + + } } diff --git a/src/test/java/com/arangodb/ArangoDriverDatabaseTest.java b/src/test/java/com/arangodb/ArangoDriverDatabaseTest.java index b824605de..1ad1e4b21 100644 --- a/src/test/java/com/arangodb/ArangoDriverDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDatabaseTest.java @@ -24,6 +24,7 @@ import java.util.Collections; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -37,7 +38,15 @@ */ public class ArangoDriverDatabaseTest extends BaseTest { - public ArangoDriverDatabaseTest(ArangoConfigure configure, ArangoDriver driver) { + private static final String DB_NAME = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234"; + private static final String[] DATABASES = new String[] { "db-1", "db_2", "db-_-3", "mydb", // other + // testcase + "mydb2", // other testcase + "repl_scenario_test1", // other test case + "unitTestDatabase", // other test case + }; + + public ArangoDriverDatabaseTest(final ArangoConfigure configure, final ArangoDriver driver) { super(configure, driver); } @@ -46,12 +55,26 @@ public void before() { } + @AfterClass + public static void _afterClass() { + try { + driver.deleteDatabase(DB_NAME); + } catch (final ArangoException e) { + } + for (final String database : DATABASES) { + try { + driver.deleteDatabase(database); + } catch (final ArangoException e) { + } + } + } + @Test public void test_invalid_dbname1() throws ArangoException { try { driver.createDatabase(null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getMessage(), is("invalid format database:null")); } } @@ -61,7 +84,7 @@ public void test_invalid_dbname2() throws ArangoException { try { driver.createDatabase("0"); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getMessage(), is("invalid format database:0")); } } @@ -71,7 +94,7 @@ public void test_invalid_dbname3() throws ArangoException { try { driver.createDatabase("abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi612345"); // len=65 fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getMessage(), is("invalid format database:abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi612345")); } @@ -82,7 +105,7 @@ public void test_invalid_dbname_for_delete() throws ArangoException { try { driver.deleteDatabase("abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi612345"); // len=65 fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getMessage(), is("invalid format database:abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi612345")); } @@ -91,7 +114,7 @@ public void test_invalid_dbname_for_delete() throws ArangoException { @Test public void test_current_database() throws ArangoException { - DatabaseEntity entity = driver.getCurrentDatabase(); + final DatabaseEntity entity = driver.getCurrentDatabase(); assertThat(entity.isError(), is(false)); assertThat(entity.getCode(), is(200)); assertThat(entity.getName(), is("_system")); @@ -104,14 +127,14 @@ public void test_current_database() throws ArangoException { @Test public void test_createDatabase() throws ArangoException { - String database = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234"; + final String database = DB_NAME; try { driver.deleteDatabase(database); - } catch (ArangoException e) { + } catch (final ArangoException e) { } - BooleanResultEntity entity = driver.createDatabase(database); // len=64 + final BooleanResultEntity entity = driver.createDatabase(database); // len=64 assertThat(entity.getResult(), is(true)); } @@ -119,20 +142,20 @@ public void test_createDatabase() throws ArangoException { @Test public void test_createDatabase_duplicate() throws ArangoException { - String database = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234"; + final String database = DB_NAME; try { driver.deleteDatabase(database); - } catch (ArangoException e) { + } catch (final ArangoException e) { } - BooleanResultEntity entity = driver.createDatabase(database); // len=64 + final BooleanResultEntity entity = driver.createDatabase(database); // len=64 assertThat(entity.getResult(), is(true)); try { driver.createDatabase(database); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(409)); assertThat(e.getErrorNumber(), is(1207)); } @@ -142,11 +165,11 @@ public void test_createDatabase_duplicate() throws ArangoException { @Test public void test_delete() throws ArangoException { - String database = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234"; + final String database = DB_NAME; try { driver.deleteDatabase(database); - } catch (ArangoException e) { + } catch (final ArangoException e) { } BooleanResultEntity entity = driver.createDatabase(database); // len=64 @@ -164,17 +187,17 @@ public void test_delete() throws ArangoException { @Test public void test_delete_404() throws ArangoException { - String database = "abcdefghi1abcdefghi2abcdefghi3abcdefghi4abcdefghi5abcdefghi61234"; + final String database = DB_NAME; try { driver.deleteDatabase(database); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.deleteDatabase(database); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1228)); } @@ -184,25 +207,18 @@ public void test_delete_404() throws ArangoException { @Test public void test_get_databases() throws ArangoException { - String[] databases = new String[] { "db-1", "db_2", "db-_-3", "mydb", // other - // testcase - "mydb2", // other testcase - "repl_scenario_test1", // other test case - "unitTestDatabase", // other test case - }; - - for (String database : databases) { + for (final String database : DATABASES) { try { driver.deleteDatabase(database); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createDatabase(database); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } - StringsResultEntity entity = driver.getDatabases(); + final StringsResultEntity entity = driver.getDatabases(); assertThat(entity.isError(), is(false)); assertThat(entity.getCode(), is(200)); @@ -215,7 +231,6 @@ public void test_get_databases() throws ArangoException { assertThat(entity.getResult().indexOf("mydb2"), not(-1)); assertThat(entity.getResult().indexOf("repl_scenario_test1"), not(-1)); assertThat(entity.getResult().indexOf("unitTestDatabase"), not(-1)); - } } diff --git a/src/test/java/com/arangodb/ArangoDriverEndpointTest.java b/src/test/java/com/arangodb/ArangoDriverEndpointTest.java index 9d53b8d6c..457f19b7f 100644 --- a/src/test/java/com/arangodb/ArangoDriverEndpointTest.java +++ b/src/test/java/com/arangodb/ArangoDriverEndpointTest.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.TreeMap; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import com.arangodb.entity.BooleanResultEntity; @@ -35,23 +37,53 @@ */ public class ArangoDriverEndpointTest extends BaseTest { - public ArangoDriverEndpointTest(ArangoConfigure configure, ArangoDriver driver) { + private static final String DB = "db"; + private static final String MYDB = "mydb"; + private static final String MYDB1 = "mydb1"; + private static final String MYDB2 = "mydb2"; + private static final String[] DB_S = new String[] { DB, MYDB, MYDB1, MYDB2 }; + + public ArangoDriverEndpointTest(final ArangoConfigure configure, final ArangoDriver driver) { super(configure, driver); } + @Before + public void _before() { + for (final String db : DB_S) { + try { + driver.deleteDatabase(db); + } catch (final ArangoException e) { + } + try { + driver.createDatabase(db); + } catch (final ArangoException e) { + } + } + } + + @After + public void _after() { + for (final String db : DB_S) { + try { + driver.deleteDatabase(db); + } catch (final ArangoException e) { + } + } + } + @Test public void test_create_endpoint() throws ArangoException { - BooleanResultEntity result = driver.createEndpoint("tcp://0.0.0.0:18529", "db"); + final BooleanResultEntity result = driver.createEndpoint("tcp://0.0.0.0:18529", DB); assertThat(result.getResult(), is(true)); } @Test public void test_create_endpoint_dup() throws ArangoException { - BooleanResultEntity result1 = driver.createEndpoint("tcp://0.0.0.0:18529", "db"); + final BooleanResultEntity result1 = driver.createEndpoint("tcp://0.0.0.0:18529", DB); assertThat(result1.getResult(), is(true)); - BooleanResultEntity result2 = driver.createEndpoint("tcp://0.0.0.0:18529", "db"); + final BooleanResultEntity result2 = driver.createEndpoint("tcp://0.0.0.0:18529", DB); assertThat(result2.getResult(), is(true)); } @@ -59,21 +91,21 @@ public void test_create_endpoint_dup() throws ArangoException { @Test public void test_get_endpoints() throws ArangoException { - BooleanResultEntity result1 = driver.createEndpoint("tcp://0.0.0.0:18530", "db"); + final BooleanResultEntity result1 = driver.createEndpoint("tcp://0.0.0.0:18530", DB); assertThat(result1.getResult(), is(true)); - BooleanResultEntity result2 = driver.createEndpoint("tcp://0.0.0.0:18531", "mydb1", "mydb2", "mydb"); + final BooleanResultEntity result2 = driver.createEndpoint("tcp://0.0.0.0:18531", MYDB1, MYDB2, MYDB); assertThat(result2.getResult(), is(true)); - List endpoints = driver.getEndpoints(); + final List endpoints = driver.getEndpoints(); // convert to Map - TreeMap> endpointMap = new TreeMap>(); - for (Endpoint ep : endpoints) { + final TreeMap> endpointMap = new TreeMap>(); + for (final Endpoint ep : endpoints) { endpointMap.put(ep.getEndpoint(), ep.getDatabases()); } - assertThat(endpointMap.get("tcp://0.0.0.0:18530"), is(Arrays.asList("db"))); - assertThat(endpointMap.get("tcp://0.0.0.0:18531"), is(Arrays.asList("mydb1", "mydb2", "mydb"))); + assertThat(endpointMap.get("tcp://0.0.0.0:18530"), is(Arrays.asList(DB))); + assertThat(endpointMap.get("tcp://0.0.0.0:18531"), is(Arrays.asList(MYDB1, MYDB2, MYDB))); } @@ -81,18 +113,18 @@ public void test_get_endpoints() throws ArangoException { public void test_connect_new_endpoint() throws ArangoException { try { - driver.createDatabase("mydb2"); - } catch (ArangoException e) { + driver.createDatabase(MYDB2); + } catch (final ArangoException e) { } - BooleanResultEntity result2 = driver.createEndpoint("tcp://0.0.0.0:18531", "mydb1", "mydb2", "mydb"); + final BooleanResultEntity result2 = driver.createEndpoint("tcp://0.0.0.0:18531", MYDB1, MYDB2, MYDB); assertThat(result2.getResult(), is(true)); - ArangoConfigure configure = new ArangoConfigure(); + final ArangoConfigure configure = new ArangoConfigure(); configure.getArangoHost().setPort(18531); // change port configure.init(); try { - ArangoDriver driver = new ArangoDriver(configure, "mydb2"); + final ArangoDriver driver = new ArangoDriver(configure, MYDB2); driver.getCollections(); } finally { configure.shutdown(); @@ -104,20 +136,20 @@ public void test_connect_new_endpoint() throws ArangoException { public void test_delete() throws ArangoException { try { - driver.createDatabase("mydb2"); - } catch (ArangoException e) { + driver.createDatabase(MYDB2); + } catch (final ArangoException e) { } - BooleanResultEntity result2 = driver.createEndpoint("tcp://0.0.0.0:18531", "mydb1", "mydb2", "mydb"); + final BooleanResultEntity result2 = driver.createEndpoint("tcp://0.0.0.0:18531", MYDB1, MYDB2, MYDB); assertThat(result2.getResult(), is(true)); - BooleanResultEntity result3 = driver.deleteEndpoint("tcp://0.0.0.0:18531"); + final BooleanResultEntity result3 = driver.deleteEndpoint("tcp://0.0.0.0:18531"); assertThat(result3.getResult(), is(true)); try { driver.deleteEndpoint("tcp://0.0.0.0:18531"); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1231)); } diff --git a/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java b/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java index d6e10359b..a6fb4d694 100644 --- a/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java +++ b/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java @@ -80,6 +80,10 @@ public void before() throws ArangoException { @After public void after() throws ArangoException { + try { + masterDriver.deleteDatabase(database); + } catch (final ArangoException e) { + } masterConfigure.shutdown(); slaveConfigure.shutdown(); } @@ -94,10 +98,10 @@ public void test_scienario() throws ArangoException, InterruptedException { // create database in master try { masterDriver.deleteDatabase(database); - } catch (ArangoException e) { + } catch (final ArangoException e) { } { - BooleanResultEntity result = masterDriver.createDatabase(database); + final BooleanResultEntity result = masterDriver.createDatabase(database); assertThat(result.getResult(), is(true)); } // configure database @@ -106,14 +110,14 @@ public void test_scienario() throws ArangoException, InterruptedException { try { slaveDriver.deleteCollection(collectionName1); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // [Master] add document masterDriver.createCollection(collectionName1); - DocumentEntity> doc1 = masterDriver.createDocument(collectionName1, + final DocumentEntity> doc1 = masterDriver.createDocument(collectionName1, new MapBuilder().put("my-key1", "100").get(), false, false); - DocumentEntity> doc2 = masterDriver.createDocument(collectionName1, + final DocumentEntity> doc2 = masterDriver.createDocument(collectionName1, new MapBuilder().put("my-key2", "255").get(), false, false); masterDriver.createDocument(collectionName1, new MapBuilder().put("my-key3", 1234567).get(), false, false); @@ -127,12 +131,12 @@ public void test_scienario() throws ArangoException, InterruptedException { slaveDriver.stopReplicationApplier(); // [Master] get logger state - ReplicationLoggerStateEntity state1 = masterDriver.getReplicationLoggerState(); + final ReplicationLoggerStateEntity state1 = masterDriver.getReplicationLoggerState(); assertThat(state1.getClients().size(), is(0)); // [Slave] sync - ReplicationSyncEntity syncResult = slaveDriver.syncReplication(masterConfigure.getEndpoint(), database, "root", - null, null); + final ReplicationSyncEntity syncResult = slaveDriver.syncReplication(masterConfigure.getEndpoint(), database, + "root", null, null); Thread.sleep(3000L); @@ -149,18 +153,18 @@ public void test_scienario() throws ArangoException, InterruptedException { } // [Master] import 290 document - LinkedList> values = new LinkedList>(); + final LinkedList> values = new LinkedList>(); for (int i = 10; i < 300; i++) { values.add(new MapBuilder().put("my-key" + i, 1234567).get()); } - ImportResultEntity importResult = masterDriver.importDocuments(collectionName1, values); + final ImportResultEntity importResult = masterDriver.importDocuments(collectionName1, values); assertThat(importResult.getCreated(), is(290)); // wait TimeUnit.SECONDS.sleep(2); // [Slave] check a replication data - CollectionEntity entity1 = slaveDriver.getCollectionCount(collectionName1); + final CollectionEntity entity1 = slaveDriver.getCollectionCount(collectionName1); assertThat(entity1.getCount(), is(303L)); // ------------------------------------------------------------ @@ -168,7 +172,7 @@ public void test_scienario() throws ArangoException, InterruptedException { // ------------------------------------------------------------ // [Master] delete document - DocumentEntity delEntity = masterDriver.deleteDocument(doc1.getDocumentHandle(), null, null); + final DocumentEntity delEntity = masterDriver.deleteDocument(doc1.getDocumentHandle(), null, null); assertThat(delEntity.isError(), is(false)); assertThat(delEntity.getDocumentKey(), is(doc1.getDocumentKey())); @@ -176,13 +180,13 @@ public void test_scienario() throws ArangoException, InterruptedException { TimeUnit.SECONDS.sleep(2); // [Slave] check a replication data - CollectionEntity entity2 = slaveDriver.getCollectionCount(collectionName1); + final CollectionEntity entity2 = slaveDriver.getCollectionCount(collectionName1); assertThat(entity2.getCount(), is(302L)); try { slaveDriver.getDocument(doc1.getDocumentHandle(), Map.class); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); } @@ -197,10 +201,10 @@ public void test_scienario() throws ArangoException, InterruptedException { TimeUnit.SECONDS.sleep(2); // [Slave] check a replication data - CollectionEntity entity3 = slaveDriver.getCollectionCount(collectionName1); + final CollectionEntity entity3 = slaveDriver.getCollectionCount(collectionName1); assertThat(entity3.getCount(), is(302L)); - DocumentEntity doc2a = slaveDriver.getDocument(doc2.getDocumentHandle(), Map.class); + final DocumentEntity doc2a = slaveDriver.getDocument(doc2.getDocumentHandle(), Map.class); assertThat(doc2a.getDocumentHandle(), is(doc2a.getDocumentHandle())); assertThat(doc2a.getEntity().size(), is(4)); // _id, _rev, _key assertThat((String) doc2a.getEntity().get("updatedKey"), is("あいうえお")); @@ -216,10 +220,10 @@ public void test_scienario() throws ArangoException, InterruptedException { TimeUnit.SECONDS.sleep(2); // [Slave] check a replication data - CollectionEntity entity4 = slaveDriver.getCollectionCount(collectionName1); + final CollectionEntity entity4 = slaveDriver.getCollectionCount(collectionName1); assertThat(entity4.getCount(), is(302L)); - DocumentEntity doc2b = slaveDriver.getDocument(doc2.getDocumentHandle(), Map.class); + final DocumentEntity doc2b = slaveDriver.getDocument(doc2.getDocumentHandle(), Map.class); assertThat(doc2b.getDocumentHandle(), is(doc2a.getDocumentHandle())); assertThat(doc2b.getEntity().size(), is(5)); // _id, _rev, _key assertThat((String) doc2b.getEntity().get("updatedKey"), is("あいうえお")); @@ -238,7 +242,7 @@ public void test_scienario() throws ArangoException, InterruptedException { try { masterDriver.getCollection(collectionName1); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); } @@ -247,7 +251,7 @@ public void test_scienario() throws ArangoException, InterruptedException { // ------------------------------------------------------------ // [Master] logger state - ReplicationLoggerStateEntity state2 = masterDriver.getReplicationLoggerState(); + final ReplicationLoggerStateEntity state2 = masterDriver.getReplicationLoggerState(); assertThat(state2.getState().isRunning(), is(true)); assertThat(state2.getState().getLastLogTick(), is(not(0L))); assertThat(state2.getState().getTotalEvents(), is(307L)); @@ -262,7 +266,7 @@ public void test_scienario() throws ArangoException, InterruptedException { assertThat(state2.getClients().get(0).getTime(), is(notNullValue())); // [Slave] applier state - ReplicationApplierStateEntity state3 = slaveDriver.getReplicationApplierState(); + final ReplicationApplierStateEntity state3 = slaveDriver.getReplicationApplierState(); assertThat(state3.getStatusCode(), is(200)); assertThat(state3.getServerVersion(), is(notNullValue())); assertThat(state3.getServerId(), is(slaveDriver.getReplicationServerId())); diff --git a/src/test/java/com/arangodb/BaseTest.java b/src/test/java/com/arangodb/BaseTest.java index 9ed2df5f4..053aa504d 100644 --- a/src/test/java/com/arangodb/BaseTest.java +++ b/src/test/java/com/arangodb/BaseTest.java @@ -40,7 +40,7 @@ public abstract class BaseTest { protected static ArangoConfigure configure; - protected ArangoDriver driver; + protected static ArangoDriver driver; // Suite.classを使った場合、Parametersがテストクラスの数だけ最初に一気に連続で呼ばれる。 // そのため、単純にクラス変数にconfigureを保持すると、AfterClassの時に別のテストケースのものを終了してしまう。 @@ -61,53 +61,71 @@ public abstract class BaseTest { @Parameters() public static Collection getParameterizedDrivers() { - ArangoConfigure configure = new ArangoConfigure(); - configure.setConnectRetryCount(2); - configure.init(); - ArangoDriver driver = new ArangoDriver(configure); - ArangoDriver driverMDB = new ArangoDriver(configure, DATABASE_NAME); - - // create mydb - try { - driver.createDatabase(DATABASE_NAME); - } catch (ArangoException e) { - } + // final ArangoConfigure configure = new ArangoConfigure(); + // configure.setConnectRetryCount(2); + // configure.init(); + // + // final ArangoDriver driver = new ArangoDriver(configure); + // final ArangoDriver driverMDB = new ArangoDriver(configure, + // DATABASE_NAME); + // // create mydb + // try { + // driver.createDatabase(DATABASE_NAME); + // } catch (final ArangoException e) { + // } // this is the original list: // return Arrays.asList( // new Object[]{ configure, driver }, // new Object[] { configure, driverMDB }); - List result = new ArrayList(); + final List result = new ArrayList(); // result.add(new Object[] { configure, driver }); - result.add(new Object[] { configure, driverMDB }); + // result.add(new Object[] { configure, driverMDB }); + result.add(new Object[] { null, null }); + return result; } - public BaseTest(ArangoConfigure configure, ArangoDriver driver) { - this.driver = driver; - BaseTest.configure = configure; - - try { - driver.createDatabase(DATABASE_NAME); - } catch (ArangoException e) { - } - + public BaseTest(final ArangoConfigure configure, final ArangoDriver driver) { + // BaseTest.driver = driver; + // BaseTest.configure = configure; + // + // try { + // driver.createDatabase(DATABASE_NAME); + // } catch (final ArangoException e) { + // } } @BeforeClass public static void __setup() { + final ArangoConfigure configure = new ArangoConfigure(); + configure.setConnectRetryCount(2); + configure.init(); + final ArangoDriver driver = new ArangoDriver(configure); + final ArangoDriver driverMDB = new ArangoDriver(configure, DATABASE_NAME); + // create mydb + try { + driver.createDatabase(DATABASE_NAME); + } catch (final ArangoException e) { + } + BaseTest.driver = driverMDB; + BaseTest.configure = configure; } @AfterClass public static void __shutdown() { + try { + driver.deleteDatabase(DATABASE_NAME); + } catch (final ArangoException e) { + } configure.shutdown(); } - public boolean isMinimumVersion(String version) throws ArangoException { - ArangoVersion ver = driver.getVersion(); - int b = TestUtils.compareVersion(ver.getVersion(), version); + public boolean isMinimumVersion(final String version) throws ArangoException { + final ArangoVersion ver = driver.getVersion(); + final int b = TestUtils.compareVersion(ver.getVersion(), version); return b > -1; } diff --git a/src/test/java/com/arangodb/bench/BenchmarkImport.java b/src/test/java/com/arangodb/bench/BenchmarkImport.java index 55571cb70..b4daed8b3 100644 --- a/src/test/java/com/arangodb/bench/BenchmarkImport.java +++ b/src/test/java/com/arangodb/bench/BenchmarkImport.java @@ -18,10 +18,12 @@ import java.util.List; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.Station; @@ -42,17 +44,26 @@ public class BenchmarkImport extends BaseExample { private static final String DATABASE_NAME = "BenchmarkImport"; - private static final String COLLECTION_NAME = "BenchmarkImportCollection"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public BenchmarkImport(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); + createDatabase(driver, DATABASE_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -64,17 +75,17 @@ public void BenchmarkImportTest() throws Exception { printHeadline("read example data"); // - List stations = TestUtils.readStations(); + final List stations = TestUtils.readStations(); // truncate collection try { - arangoDriver.truncateCollection(COLLECTION_NAME); - } catch (ArangoException e) { + driver.truncateCollection(COLLECTION_NAME); + } catch (final ArangoException e) { } // create importer - AbstractBenchmarkImporter logic1 = new ImportDocumentBenchmarkImporter(arangoDriver, COLLECTION_NAME); - AbstractBenchmarkImporter logic2 = new SingleDocumentBenchmarkImporter(arangoDriver, COLLECTION_NAME); + final AbstractBenchmarkImporter logic1 = new ImportDocumentBenchmarkImporter(driver, COLLECTION_NAME); + final AbstractBenchmarkImporter logic2 = new SingleDocumentBenchmarkImporter(driver, COLLECTION_NAME); // printHeadline("import data"); diff --git a/src/test/java/com/arangodb/example/TransactionExample.java b/src/test/java/com/arangodb/example/TransactionExample.java index 91ae34676..f2ce2b83d 100644 --- a/src/test/java/com/arangodb/example/TransactionExample.java +++ b/src/test/java/com/arangodb/example/TransactionExample.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -49,43 +50,50 @@ public class TransactionExample extends BaseExample { // increment counter 10 times private static final int NUMBER_UPDATES = 10; - public ArangoDriver arangoDriver; - - public static ArangoConfigure configuration; + /** + * @param configure + * @param driver + */ + public TransactionExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - configuration = getConfiguration(); - arangoDriver = getArangoDriver(configuration); - createDatabase(arangoDriver, DATABASE_NAME); + createDatabase(driver, DATABASE_NAME); try { - arangoDriver.createCollection(COLLECTION_NAME); - } catch (Exception ex) { + driver.createCollection(COLLECTION_NAME); + } catch (final Exception ex) { } } + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); + } + @Test public void transactionExample() throws ArangoException { - List noTransactionThreadslist = new ArrayList(); - List transactionThreadslist = new ArrayList(); + final List noTransactionThreadslist = new ArrayList(); + final List transactionThreadslist = new ArrayList(); - myCounter entity = new myCounter(); + final myCounter entity = new myCounter(); entity.setCount(0L); - DocumentEntity documentEntity1 = arangoDriver.createDocument(COLLECTION_NAME, entity, true, null); - DocumentEntity documentEntity2 = arangoDriver.createDocument(COLLECTION_NAME, entity, true, null); + DocumentEntity documentEntity1 = driver.createDocument(COLLECTION_NAME, entity, true, null); + DocumentEntity documentEntity2 = driver.createDocument(COLLECTION_NAME, entity, true, null); // start threads without transaction for (int i = 0; i < NUMBER_THREADS; i++) { - NoTransactionThread s = new NoTransactionThread(documentEntity1.getDocumentHandle()); + final NoTransactionThread s = new NoTransactionThread(documentEntity1.getDocumentHandle()); noTransactionThreadslist.add(s); s.start(); } joinThreads(noTransactionThreadslist); - documentEntity1 = arangoDriver.getDocument(documentEntity1.getDocumentHandle(), myCounter.class); + documentEntity1 = driver.getDocument(documentEntity1.getDocumentHandle(), myCounter.class); // result should be NUMBER_THREADS * NUMBER_UPDATES = 100 but has random // values @@ -95,13 +103,13 @@ public void transactionExample() throws ArangoException { // start threads with ArangoDB transaction for (int i = 0; i < NUMBER_THREADS; i++) { - TransactionThread s = new TransactionThread(documentEntity2.getDocumentHandle()); + final TransactionThread s = new TransactionThread(documentEntity2.getDocumentHandle()); transactionThreadslist.add(s); s.start(); } joinThreads(transactionThreadslist); - documentEntity2 = arangoDriver.getDocument(documentEntity2.getDocumentHandle(), myCounter.class); + documentEntity2 = driver.getDocument(documentEntity2.getDocumentHandle(), myCounter.class); // result should be NUMBER_THREADS * NUMBER_UPDATES = 100 System.out.println("with transaction result: count = " + documentEntity2.getEntity().getCount()); @@ -114,29 +122,31 @@ public void transactionExample() throws ArangoException { */ public static class NoTransactionThread extends Thread { - private String documentHandle; + private final String documentHandle; - public NoTransactionThread(String documentHandle) { + public NoTransactionThread(final String documentHandle) { this.documentHandle = documentHandle; } + @Override public void run() { - ArangoDriver driver = new ArangoDriver(configuration, DATABASE_NAME); + final ArangoDriver driver2 = new ArangoDriver(configure, DATABASE_NAME); try { ; for (int i = 0; i < NUMBER_UPDATES; i++) { sleepRandom(); // read counter - DocumentEntity documentEntity = driver.getDocument(documentHandle, myCounter.class); - myCounter entity = documentEntity.getEntity(); + final DocumentEntity documentEntity = driver2.getDocument(documentHandle, + myCounter.class); + final myCounter entity = documentEntity.getEntity(); // update counter entity.setCount(entity.getCount() + 1); sleepRandom(); // save counter - driver.replaceDocument(documentHandle, entity); + driver2.replaceDocument(documentHandle, entity); } - } catch (ArangoException e) { + } catch (final ArangoException e) { e.printStackTrace(); } } @@ -148,17 +158,18 @@ public void run() { */ public static class TransactionThread extends Thread { - private String documentHandle; + private final String documentHandle; - public TransactionThread(String documentHandle) { + public TransactionThread(final String documentHandle) { this.documentHandle = documentHandle; } + @Override public void run() { - ArangoDriver driver = new ArangoDriver(configuration, DATABASE_NAME); + final ArangoDriver driver = new ArangoDriver(configure, DATABASE_NAME); - TransactionEntity transaction = buildTransaction(driver); + final TransactionEntity transaction = buildTransaction(driver); try { ; for (int i = 0; i < NUMBER_UPDATES; i++) { @@ -167,7 +178,7 @@ public void run() { // call transaction function driver.executeTransaction(transaction); } - } catch (ArangoException e) { + } catch (final ArangoException e) { e.printStackTrace(); } } @@ -183,16 +194,16 @@ public Long getCount() { return count; } - public void setCount(Long count) { + public void setCount(final Long count) { this.count = count; } } - public static void joinThreads(List threads) { - for (T st : threads) { + public static void joinThreads(final List threads) { + for (final T st : threads) { try { st.join(); - } catch (Exception ex) { + } catch (final Exception ex) { } } } @@ -200,7 +211,7 @@ public static void joinThreads(List threads) { private static void sleepRandom() { try { Thread.sleep((long) (Math.random() * 1000L)); - } catch (Exception ex) { + } catch (final Exception ex) { } } @@ -212,10 +223,10 @@ private static void sleepRandom() { * the ArangoDB driver * @return a transaction entity */ - private static TransactionEntity buildTransaction(ArangoDriver driver) { + private static TransactionEntity buildTransaction(final ArangoDriver driver) { // create action function - String action = "function (id) {" + final String action = "function (id) {" // use internal database functions + " var db = require('internal').db;" // get the document @@ -225,7 +236,7 @@ private static TransactionEntity buildTransaction(ArangoDriver driver) { // store the new value + "db._replace(id, a);}"; - TransactionEntity transaction = driver.createTransaction(action); + final TransactionEntity transaction = driver.createTransaction(action); transaction.addWriteCollection(COLLECTION_NAME); @@ -242,8 +253,8 @@ private static TransactionEntity buildTransaction(ArangoDriver driver) { * @return the current value * @throws ArangoException */ - public static Long getCount(ArangoDriver driver, String documentHandle) throws ArangoException { - DocumentEntity documentEntity = driver.getDocument(documentHandle, myCounter.class); + public static Long getCount(final ArangoDriver driver, final String documentHandle) throws ArangoException { + final DocumentEntity documentEntity = driver.getDocument(documentHandle, myCounter.class); return documentEntity.getEntity().getCount(); } diff --git a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java index a67433e18..bf4e0c243 100644 --- a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java +++ b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java @@ -21,10 +21,12 @@ import java.util.List; import java.util.Map; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorResult; @@ -33,18 +35,27 @@ public class AqlQueryWithSpecialReturnTypesExample extends BaseExample { private static final String DATABASE_NAME = "SimplePersonAqlQueryWithLimitExample"; - private static final String COLLECTION_NAME = "SimplePersonAqlQueryWithLimitExample"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public AqlQueryWithSpecialReturnTypesExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createCollection(arangoDriver, COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createCollection(driver, COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -67,11 +78,11 @@ public void simplePersonAqlWithLimitQuery() { // // bind @gender to WOMAN - HashMap bindVars = new HashMap(); + final HashMap bindVars = new HashMap(); bindVars.put("gender", FEMALE); // query (count = true, batchSize = 5) - AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true).setBatchSize(5); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true).setBatchSize(5); // printHeadline("get query results in a map"); @@ -82,13 +93,13 @@ public void simplePersonAqlWithLimitQuery() { System.out.println(queryString); @SuppressWarnings("rawtypes") - CursorResult cursor = arangoDriver.executeAqlQuery(queryString, bindVars, aqlQueryOptions, Map.class); + final CursorResult cursor = driver.executeAqlQuery(queryString, bindVars, aqlQueryOptions, Map.class); Assert.assertNotNull(cursor); @SuppressWarnings("rawtypes") - Iterator iterator = cursor.iterator(); + final Iterator iterator = cursor.iterator(); while (iterator.hasNext()) { - Map map = iterator.next(); + final Map map = iterator.next(); Assert.assertNotNull(map); Assert.assertNotNull(map.get("name")); @@ -107,14 +118,14 @@ public void simplePersonAqlWithLimitQuery() { System.out.println(queryString); @SuppressWarnings("rawtypes") - CursorResult cursor2 = arangoDriver.executeAqlQuery(queryString, bindVars, aqlQueryOptions, + final CursorResult cursor2 = driver.executeAqlQuery(queryString, bindVars, aqlQueryOptions, List.class); Assert.assertNotNull(cursor2); @SuppressWarnings("rawtypes") - Iterator iterator2 = cursor2.iterator(); + final Iterator iterator2 = cursor2.iterator(); while (iterator2.hasNext()) { - List list = iterator2.next(); + final List list = iterator2.next(); Assert.assertNotNull(list); Assert.assertNotNull(list.get(0)); @@ -124,7 +135,7 @@ public void simplePersonAqlWithLimitQuery() { System.out.printf("%15s (%5s): %s%n", list.get(0), list.get(1), list.get(2).toString()); } - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Example failed. " + e.getMessage()); } @@ -133,12 +144,12 @@ public void simplePersonAqlWithLimitQuery() { private void createExamples() throws ArangoException { // create some persons for (int i = 0; i < 100; i++) { - SimplePerson person = new SimplePerson(); + final SimplePerson person = new SimplePerson(); person.setName("TestUser" + i); person.setGender((i % 2) == 0 ? MALE : FEMALE); person.setAge((int) (Math.random() * 100) + 10); - arangoDriver.createDocument(COLLECTION_NAME, person, true, null); + driver.createDocument(COLLECTION_NAME, person, true, null); } } diff --git a/src/test/java/com/arangodb/example/document/BaseExample.java b/src/test/java/com/arangodb/example/document/BaseExample.java index 7a001749b..895baa1f0 100644 --- a/src/test/java/com/arangodb/example/document/BaseExample.java +++ b/src/test/java/com/arangodb/example/document/BaseExample.java @@ -21,69 +21,62 @@ import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; +import com.arangodb.BaseTest; import com.arangodb.entity.BooleanResultEntity; import com.arangodb.entity.CollectionEntity; -public class BaseExample { +public class BaseExample extends BaseTest { protected static final String FEMALE = "female"; - protected static final String MALE = "male"; - protected ArangoConfigure getConfiguration() { - ArangoConfigure configure = new ArangoConfigure(); - // configure.setUser("myUser"); - // configure.setPassword("password"); - // configuration file: src/test/resources/arangodb.properties - configure.init(); - - return configure; + /** + * @param configure + * @param driver + */ + public BaseExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); } - protected ArangoDriver getArangoDriver(ArangoConfigure configuration) { - return new ArangoDriver(configuration); - } - - protected void removeTestDatabase(String name) { - ArangoDriver arangoDriver = getArangoDriver(getConfiguration()); + protected void removeTestDatabase(final String name) { try { - arangoDriver.deleteDatabase(name); - } catch (Exception e) { + driver.deleteDatabase(name); + } catch (final Exception e) { } } - protected void createDatabase(ArangoDriver arangoDriver, String name) { + protected void createDatabase(final ArangoDriver arangoDriver, final String name) { try { - BooleanResultEntity createDatabase = arangoDriver.createDatabase(name); + final BooleanResultEntity createDatabase = arangoDriver.createDatabase(name); Assert.assertNotNull(createDatabase); Assert.assertNotNull(createDatabase.getResult()); Assert.assertTrue(createDatabase.getResult()); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail("Failed to create database " + name + "; " + e.getMessage()); } arangoDriver.setDefaultDatabase(name); } - protected void deleteDatabase(ArangoDriver arangoDriver, String name) { + protected void deleteDatabase(final ArangoDriver arangoDriver, final String name) { try { arangoDriver.deleteDatabase(name); - } catch (Exception e) { + } catch (final Exception e) { } } - protected void createCollection(ArangoDriver arangoDriver, String name) { + protected void createCollection(final ArangoDriver arangoDriver, final String name) { try { - CollectionEntity createCollection = arangoDriver.createCollection(name); + final CollectionEntity createCollection = arangoDriver.createCollection(name); Assert.assertNotNull(createCollection); Assert.assertNotNull(createCollection.getName()); Assert.assertEquals(name, createCollection.getName()); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("create collection failed. " + e.getMessage()); } } - protected void printEntity(Object object) { + protected void printEntity(final Object object) { if (object == null) { System.out.println("Document not found"); } else { @@ -91,7 +84,7 @@ protected void printEntity(Object object) { } } - protected void printHeadline(String name) { + protected void printHeadline(final String name) { System.out.println("---------------------------------------------"); System.out.println(name); System.out.println("---------------------------------------------"); diff --git a/src/test/java/com/arangodb/example/document/CollectionExample.java b/src/test/java/com/arangodb/example/document/CollectionExample.java index b8fbe834d..3afc3767c 100644 --- a/src/test/java/com/arangodb/example/document/CollectionExample.java +++ b/src/test/java/com/arangodb/example/document/CollectionExample.java @@ -16,10 +16,12 @@ package com.arangodb.example.document; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.CollectionEntity; @@ -29,14 +31,24 @@ public class CollectionExample extends BaseExample { private static final String DATABASE_NAME = "CreateCollectionExample"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public CollectionExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); + createDatabase(driver, DATABASE_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -49,7 +61,7 @@ public void createAndDeleteCollection() { printHeadline("create a collection"); // try { - CollectionEntity entity = arangoDriver.createCollection(myFirstCollection); + final CollectionEntity entity = driver.createCollection(myFirstCollection); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getName()); Assert.assertEquals(myFirstCollection, entity.getName()); @@ -58,27 +70,27 @@ public void createAndDeleteCollection() { printCollectionEntity(entity); // System.out.println(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("create collection failed. " + e.getMessage()); } - createCollection(arangoDriver, "collection2"); - createCollection(arangoDriver, "collection3"); + createCollection(driver, "collection2"); + createCollection(driver, "collection3"); // printHeadline("get list of all collections"); // try { - CollectionsEntity collectionsEntity = arangoDriver.getCollections(); + final CollectionsEntity collectionsEntity = driver.getCollections(); Assert.assertNotNull(collectionsEntity); Assert.assertNotNull(collectionsEntity.getCollections()); - for (CollectionEntity entity : collectionsEntity.getCollections()) { + for (final CollectionEntity entity : collectionsEntity.getCollections()) { printCollectionEntity(entity); // System.out.println(entity); } - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("could not get collections. " + e.getMessage()); } @@ -86,14 +98,14 @@ public void createAndDeleteCollection() { printHeadline("get one collection"); // try { - CollectionEntity entity = arangoDriver.getCollection(myFirstCollection); + final CollectionEntity entity = driver.getCollection(myFirstCollection); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getName()); Assert.assertNotNull(entity.getId()); printCollectionEntity(entity); // System.out.println(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("could not get collection. " + e.getMessage()); } @@ -101,7 +113,7 @@ public void createAndDeleteCollection() { printHeadline("rename collection"); // try { - CollectionEntity entity = arangoDriver.renameCollection(myFirstCollection, "collection4"); + final CollectionEntity entity = driver.renameCollection(myFirstCollection, "collection4"); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getName()); Assert.assertNotNull(entity.getId()); @@ -110,7 +122,7 @@ public void createAndDeleteCollection() { printCollectionEntity(entity); // System.out.println(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("could not rename collection. " + e.getMessage()); } @@ -118,13 +130,13 @@ public void createAndDeleteCollection() { printHeadline("truncate collection"); // try { - CollectionEntity truncateCollection = arangoDriver.truncateCollection(myFirstCollection); + final CollectionEntity truncateCollection = driver.truncateCollection(myFirstCollection); Assert.assertNotNull(truncateCollection); Assert.assertNotNull(truncateCollection.getName()); Assert.assertNotNull(truncateCollection.getId()); Assert.assertEquals(myFirstCollectionId, truncateCollection.getId()); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("could not truncate collection. " + e.getMessage()); } @@ -132,7 +144,7 @@ public void createAndDeleteCollection() { printHeadline("delete collection"); // try { - CollectionEntity entity = arangoDriver.deleteCollection(myFirstCollection); + final CollectionEntity entity = driver.deleteCollection(myFirstCollection); Assert.assertNotNull(entity); // the name has to be null Assert.assertNull(entity.getName()); @@ -141,13 +153,13 @@ public void createAndDeleteCollection() { printCollectionEntity(entity); // System.out.println(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("could not delete collection. " + e.getMessage()); } } - private void printCollectionEntity(CollectionEntity collection) { + private void printCollectionEntity(final CollectionEntity collection) { if (collection == null) { System.out.println("Collection not found"); } else if (collection.getName() == null) { diff --git a/src/test/java/com/arangodb/example/document/CreateAndDeleteDatabaseExample.java b/src/test/java/com/arangodb/example/document/CreateAndDeleteDatabaseExample.java index 2aa09bb57..7e34103c0 100644 --- a/src/test/java/com/arangodb/example/document/CreateAndDeleteDatabaseExample.java +++ b/src/test/java/com/arangodb/example/document/CreateAndDeleteDatabaseExample.java @@ -30,6 +30,14 @@ public class CreateAndDeleteDatabaseExample extends BaseExample { private static final String DATABASE_NAME = "CreateDatabaseExample"; + /** + * @param configure + * @param driver + */ + public CreateAndDeleteDatabaseExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } + @Before public void _before() { removeTestDatabase(DATABASE_NAME); @@ -46,27 +54,21 @@ public void createAndDeleteDatabase() { // printHeadline("create a driver"); - // - - ArangoDriver arangoDriver = new ArangoDriver(getConfiguration()); - - Assert.assertNotNull(arangoDriver); - // printHeadline("create a database"); // try { - BooleanResultEntity createDatabase = arangoDriver.createDatabase(DATABASE_NAME); + final BooleanResultEntity createDatabase = driver.createDatabase(DATABASE_NAME); Assert.assertNotNull(createDatabase); Assert.assertNotNull(createDatabase.getResult()); Assert.assertTrue(createDatabase.getResult()); System.out.println("Database created: " + DATABASE_NAME); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create database " + DATABASE_NAME + "; " + e.getMessage()); } // set a default database for the connection - arangoDriver.setDefaultDatabase(DATABASE_NAME); + driver.setDefaultDatabase(DATABASE_NAME); // do something ... @@ -74,25 +76,25 @@ public void createAndDeleteDatabase() { printHeadline("read names of all databases"); // try { - StringsResultEntity databases = arangoDriver.getDatabases(); + final StringsResultEntity databases = driver.getDatabases(); Assert.assertNotNull(databases); Assert.assertNotNull(databases.getResult()); Assert.assertTrue(databases.getResult().size() > 0); - for (String str : databases.getResult()) { + for (final String str : databases.getResult()) { System.out.println("Database: " + str); } - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read databases. " + e.getMessage()); } // printHeadline("create a driver with default database"); // - ArangoConfigure configure2 = new ArangoConfigure(); + final ArangoConfigure configure2 = new ArangoConfigure(); configure2.init(); - ArangoDriver arangoDriver2 = new ArangoDriver(configure2, DATABASE_NAME); + final ArangoDriver arangoDriver2 = new ArangoDriver(configure2, DATABASE_NAME); Assert.assertNotNull(arangoDriver2); // do something ... @@ -101,11 +103,11 @@ public void createAndDeleteDatabase() { printHeadline("delete database"); // try { - BooleanResultEntity deleteDatabase = arangoDriver.deleteDatabase(DATABASE_NAME); + final BooleanResultEntity deleteDatabase = driver.deleteDatabase(DATABASE_NAME); Assert.assertNotNull(deleteDatabase); Assert.assertNotNull(deleteDatabase.getResult()); Assert.assertTrue(deleteDatabase.getResult()); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to delete database " + DATABASE_NAME + "; " + e.getMessage()); } diff --git a/src/test/java/com/arangodb/example/document/CreateDocumentExample.java b/src/test/java/com/arangodb/example/document/CreateDocumentExample.java index 7ecde2787..9f32e5d97 100644 --- a/src/test/java/com/arangodb/example/document/CreateDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/CreateDocumentExample.java @@ -18,10 +18,12 @@ import java.util.HashMap; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.BaseDocument; @@ -41,15 +43,25 @@ public class CreateDocumentExample extends BaseExample { private static final String KEY4 = "key4"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public CreateDocumentExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createCollection(arangoDriver, COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createCollection(driver, COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -66,7 +78,7 @@ public void createAndDeleteDocuments() { // System.out.println("1. create a document by a BaseDocument object:"); - BaseDocument myBaseDocument = new BaseDocument(); + final BaseDocument myBaseDocument = new BaseDocument(); myBaseDocument.setDocumentKey(KEY1); // attributes are stored in a HashMap myBaseDocument.addAttribute("name", "Alice"); @@ -74,7 +86,7 @@ public void createAndDeleteDocuments() { myBaseDocument.addAttribute("age", 18); try { - DocumentEntity entity = arangoDriver.createDocument(COLLECTION_NAME, myBaseDocument); + final DocumentEntity entity = driver.createDocument(COLLECTION_NAME, myBaseDocument); // or DocumentEntity entity = // arangoDriver.createDocument(COLLECTION_NAME, KEY1, // myBaseDocument); @@ -90,7 +102,7 @@ public void createAndDeleteDocuments() { System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); - BaseDocument baseDocument = entity.getEntity(); + final BaseDocument baseDocument = entity.getEntity(); // the BaseDocument contains the key, document handle and revision System.out.println("Key: " + baseDocument.getDocumentKey()); System.out.println("Id: " + baseDocument.getDocumentHandle()); @@ -101,12 +113,12 @@ public void createAndDeleteDocuments() { System.out.println("Attribute 'age': " + baseDocument.getProperties().get("age")); // printEntity(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } System.out.println("2. create a document by a HashMap object:"); - HashMap myHashMap = new HashMap(); + final HashMap myHashMap = new HashMap(); myHashMap.put("_key", KEY2); // attributes are stored in a HashMap myHashMap.put("name", "Alice"); @@ -114,7 +126,7 @@ public void createAndDeleteDocuments() { myHashMap.put("age", 18); try { - DocumentEntity> entity = arangoDriver.createDocument(COLLECTION_NAME, myHashMap); + final DocumentEntity> entity = driver.createDocument(COLLECTION_NAME, myHashMap); // or DocumentEntity> entity = // arangoDriver.createDocument(COLLECTION_NAME, KEY2, myHashMap); @@ -129,7 +141,7 @@ public void createAndDeleteDocuments() { System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); - HashMap hashMap = entity.getEntity(); + final HashMap hashMap = entity.getEntity(); // the HashMap contains the key, document handle and revision System.out.println("Key: " + hashMap.get("_key")); System.out.println("Id: " + hashMap.get("_id")); @@ -140,14 +152,14 @@ public void createAndDeleteDocuments() { System.out.println("Attribute 'age': " + hashMap.get("age")); // printEntity(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } System.out.println("3. create a document by an object:"); - SimplePerson mySimplePerson = new SimplePerson("Angela", "female", 42); + final SimplePerson mySimplePerson = new SimplePerson("Angela", "female", 42); try { - DocumentEntity entity = arangoDriver.createDocument(COLLECTION_NAME, KEY3, mySimplePerson); + final DocumentEntity entity = driver.createDocument(COLLECTION_NAME, KEY3, mySimplePerson); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentKey()); @@ -160,21 +172,21 @@ public void createAndDeleteDocuments() { System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); - SimplePerson simplePerson = entity.getEntity(); + final SimplePerson simplePerson = entity.getEntity(); // get the attributes System.out.println("Attribute 'name': " + simplePerson.getName()); System.out.println("Attribute 'gender': " + simplePerson.getGender()); System.out.println("Attribute 'age': " + simplePerson.getAge()); // printEntity(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } System.out.println("4. create a document by an object with document attributes:"); - DocumentPerson myDocumentPerson = new DocumentPerson("Peter", "male", 24); + final DocumentPerson myDocumentPerson = new DocumentPerson("Peter", "male", 24); try { - DocumentEntity entity = arangoDriver.createDocument(COLLECTION_NAME, KEY4, + final DocumentEntity entity = driver.createDocument(COLLECTION_NAME, KEY4, myDocumentPerson); Assert.assertNotNull(entity); @@ -188,7 +200,7 @@ public void createAndDeleteDocuments() { System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); - DocumentPerson documentPerson = entity.getEntity(); + final DocumentPerson documentPerson = entity.getEntity(); // the DocumentPerson contains the key, document handle and revision System.out.println("Key: " + documentPerson.getDocumentKey()); System.out.println("Id: " + documentPerson.getDocumentHandle()); @@ -199,7 +211,7 @@ public void createAndDeleteDocuments() { System.out.println("Attribute 'age': " + documentPerson.getAge()); // printEntity(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } diff --git a/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java b/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java index 3690284fe..5821aa863 100644 --- a/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java @@ -19,10 +19,12 @@ import java.util.HashMap; import java.util.Iterator; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.DocumentCursor; @@ -31,18 +33,27 @@ public class DocumentPersonAqlQueryExample extends BaseExample { private static final String DATABASE_NAME = "DocumentPersonAqlQueryExample"; - private static final String COLLECTION_NAME = "DocumentPersonAqlQueryExample"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public DocumentPersonAqlQueryExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createCollection(arangoDriver, COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createCollection(driver, COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -65,22 +76,22 @@ public void documentPersonAqlQuery() { // // build an AQL query string - String queryString = "FOR t IN " + COLLECTION_NAME + final String queryString = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t"; System.out.println(queryString); // bind @gender to female - HashMap bindVars = new HashMap(); + final HashMap bindVars = new HashMap(); bindVars.put("gender", FEMALE); // query (count = true, batchSize = 5) - AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true).setBatchSize(5); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true).setBatchSize(5); // printHeadline("execute query"); // - DocumentCursor rs = arangoDriver.executeDocumentQuery(queryString, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(queryString, bindVars, aqlQueryOptions, DocumentPerson.class); Assert.assertNotNull(rs); @@ -96,9 +107,9 @@ public void documentPersonAqlQuery() { // // using the entity iterator - Iterator iterator = rs.entityIterator(); + final Iterator iterator = rs.entityIterator(); while (iterator.hasNext()) { - DocumentPerson person = iterator.next(); + final DocumentPerson person = iterator.next(); Assert.assertNotNull(person); Assert.assertNotNull(person.getDocumentKey()); @@ -109,7 +120,7 @@ public void documentPersonAqlQuery() { person.getGender(), person.getAge()); } - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Example failed. " + e.getMessage()); } @@ -118,12 +129,12 @@ public void documentPersonAqlQuery() { private void createExamples() throws ArangoException { // create some persons for (int i = 0; i < 1000; i++) { - DocumentPerson person = new DocumentPerson(); + final DocumentPerson person = new DocumentPerson(); person.setName("TestUser" + i); person.setGender((i % 2) == 0 ? MALE : FEMALE); person.setAge((int) (Math.random() * 100) + 10); - arangoDriver.createDocument(COLLECTION_NAME, person, true, null); + driver.createDocument(COLLECTION_NAME, person, true, null); } } diff --git a/src/test/java/com/arangodb/example/document/RawDocumentExample.java b/src/test/java/com/arangodb/example/document/RawDocumentExample.java index 816fddce6..1055a039b 100644 --- a/src/test/java/com/arangodb/example/document/RawDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/RawDocumentExample.java @@ -21,10 +21,12 @@ import org.json.JSONML; import org.json.JSONObject; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorRawResult; @@ -34,18 +36,27 @@ public class RawDocumentExample extends BaseExample { private static final String DATABASE_NAME = "RawDocument"; - private static final String COLLECTION_NAME = "RawDocument"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public RawDocumentExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createCollection(arangoDriver, COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createCollection(driver, COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -67,13 +78,13 @@ public void ReadDocuments() { String x = "{\"test\":123}"; try { - DocumentEntity entity = arangoDriver.createDocumentRaw(COLLECTION_NAME, x, true, false); + final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, x, true, false); // the DocumentEntity contains the key, document handle and revision System.out.println("Key: " + entity.getDocumentKey()); System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); documentHandle1 = entity.getDocumentHandle(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } @@ -82,9 +93,9 @@ public void ReadDocuments() { // try { - String str = arangoDriver.getDocumentRaw(documentHandle1, null, null); + final String str = driver.getDocumentRaw(documentHandle1, null, null); System.out.println("value: " + str); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read document. " + e.getMessage()); } @@ -94,13 +105,13 @@ public void ReadDocuments() { x = "{\"_key\":\"key2\",\"test\":123}"; try { - DocumentEntity entity = arangoDriver.createDocumentRaw(COLLECTION_NAME, x, true, false); + final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, x, true, false); // the DocumentEntity contains the key, document handle and revision System.out.println("Key: " + entity.getDocumentKey()); System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); documentHandle2 = entity.getDocumentHandle(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } @@ -109,9 +120,9 @@ public void ReadDocuments() { // try { - String str = arangoDriver.getDocumentRaw(documentHandle2, null, null); + final String str = driver.getDocumentRaw(documentHandle2, null, null); System.out.println("value: " + str); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read document. " + e.getMessage()); } @@ -120,9 +131,9 @@ public void ReadDocuments() { // try { - arangoDriver.getDocumentRaw(COLLECTION_NAME + "/unknown", null, null); + driver.getDocumentRaw(COLLECTION_NAME + "/unknown", null, null); Assert.fail("This should fail"); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.assertEquals(ErrorNums.ERROR_HTTP_NOT_FOUND, e.getCode()); } @@ -132,14 +143,14 @@ public void ReadDocuments() { x = "{\"test\":1234}"; try { - DocumentEntity updateDocumentRaw = arangoDriver.updateDocumentRaw(documentHandle2, x, null, null, + final DocumentEntity updateDocumentRaw = driver.updateDocumentRaw(documentHandle2, x, null, null, false, true); // print new document revision System.out.println("rev: " + updateDocumentRaw.getDocumentRevision()); // show request result (you have to use getDocumentRaw to get // all attributes of the changed object): System.out.println("value: " + updateDocumentRaw.getEntity()); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.assertEquals(ErrorNums.ERROR_HTTP_NOT_FOUND, e.getCode()); } @@ -149,32 +160,32 @@ public void ReadDocuments() { x = "{\"hund\":321,\"katze\":321,\"maus\":777}"; try { - DocumentEntity replaceDocumentRaw = arangoDriver.replaceDocumentRaw(documentHandle2, x, null, null, + final DocumentEntity replaceDocumentRaw = driver.replaceDocumentRaw(documentHandle2, x, null, null, false); // print new document revision System.out.println("rev: " + replaceDocumentRaw.getDocumentRevision()); // show request result (you have to use getDocumentRaw to get // all attributes of the replaced object): System.out.println("value: " + replaceDocumentRaw.getEntity()); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.assertEquals(ErrorNums.ERROR_HTTP_NOT_FOUND, e.getCode()); } // printHeadline("using org.json.JSONML to save a xml file"); // - String string = " Basic bread Flour Yeast Water Salt Mix all ingredients together. Knead thoroughly. Cover with a cloth, and leave for one hour in warm room. Knead again. Place in a bread baking tin. Cover with a cloth, and leave for one hour in warm room. Bake in the oven at 180(degrees)C for 30 minutes. "; + final String string = " Basic bread Flour Yeast Water Salt Mix all ingredients together. Knead thoroughly. Cover with a cloth, and leave for one hour in warm room. Knead again. Place in a bread baking tin. Cover with a cloth, and leave for one hour in warm room. Bake in the oven at 180(degrees)C for 30 minutes. "; System.out.println("Orig XML value: " + string); - JSONObject jsonObject = JSONML.toJSONObject(string); + final JSONObject jsonObject = JSONML.toJSONObject(string); try { - DocumentEntity entity = arangoDriver.createDocumentRaw(COLLECTION_NAME, jsonObject.toString(), true, + final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, jsonObject.toString(), true, false); // the DocumentEntity contains the key, document handle and revision System.out.println("Key: " + entity.getDocumentKey()); System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); documentHandle3 = entity.getDocumentHandle(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } @@ -183,11 +194,11 @@ public void ReadDocuments() { // try { - String str = arangoDriver.getDocumentRaw(documentHandle3, null, null); + final String str = driver.getDocumentRaw(documentHandle3, null, null); System.out.println("JSON value: " + str); - JSONObject jsonObject2 = new JSONObject(str); + final JSONObject jsonObject2 = new JSONObject(str); System.out.println("XML value: " + JSONML.toString(jsonObject2)); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read document. " + e.getMessage()); } @@ -195,19 +206,19 @@ public void ReadDocuments() { printHeadline("get query results"); // - String queryString = "FOR t IN " + COLLECTION_NAME + " FILTER t.cook_time == \"3 hours\" RETURN t"; + final String queryString = "FOR t IN " + COLLECTION_NAME + " FILTER t.cook_time == \"3 hours\" RETURN t"; System.out.println(queryString); - HashMap bindVars = new HashMap(); + final HashMap bindVars = new HashMap(); try { - CursorRawResult cursor = arangoDriver.executeAqlQueryRaw(queryString, bindVars, null); + final CursorRawResult cursor = driver.executeAqlQueryRaw(queryString, bindVars, null); Assert.assertNotNull(cursor); - Iterator iter = cursor.iterator(); + final Iterator iter = cursor.iterator(); while (iter.hasNext()) { - JSONObject jsonObject2 = new JSONObject(iter.next()); + final JSONObject jsonObject2 = new JSONObject(iter.next()); System.out.println("XML value: " + JSONML.toString(jsonObject2)); } - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to query documents. " + e.getMessage()); } diff --git a/src/test/java/com/arangodb/example/document/ReadDocumentExample.java b/src/test/java/com/arangodb/example/document/ReadDocumentExample.java index 6cfb3b863..1416902ea 100644 --- a/src/test/java/com/arangodb/example/document/ReadDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/ReadDocumentExample.java @@ -19,10 +19,12 @@ import java.util.HashMap; import java.util.List; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.BaseDocument; @@ -37,15 +39,25 @@ public class ReadDocumentExample extends BaseExample { private static final String KEY1 = "key1"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public ReadDocumentExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createCollection(arangoDriver, COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createCollection(driver, COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -61,7 +73,7 @@ public void ReadDocuments() { printHeadline("create example document"); // - HashMap myHashMap = new HashMap(); + final HashMap myHashMap = new HashMap(); myHashMap.put("_key", KEY1); // attributes are stored in a HashMap myHashMap.put("name", "Alice"); @@ -70,14 +82,14 @@ public void ReadDocuments() { String documentHandleExample = null; try { - DocumentEntity> entity = arangoDriver.createDocument(COLLECTION_NAME, myHashMap); + final DocumentEntity> entity = driver.createDocument(COLLECTION_NAME, myHashMap); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); Assert.assertNotNull(entity.getDocumentKey()); Assert.assertNotNull(entity.getDocumentRevision()); documentHandleExample = entity.getDocumentHandle(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } @@ -87,7 +99,7 @@ public void ReadDocuments() { System.out.println("1. read document as BaseDocument object:"); try { - DocumentEntity entity = arangoDriver.getDocument(COLLECTION_NAME, KEY1, BaseDocument.class); + final DocumentEntity entity = driver.getDocument(COLLECTION_NAME, KEY1, BaseDocument.class); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); @@ -100,7 +112,7 @@ public void ReadDocuments() { System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); - BaseDocument baseDocument2 = entity.getEntity(); + final BaseDocument baseDocument2 = entity.getEntity(); Assert.assertNotNull(baseDocument2); // the BaseDocument contains the key, document handle and revision @@ -118,14 +130,14 @@ public void ReadDocuments() { "Attribute 'age': " + baseDocument2.getProperties().get("age") + " <- Data type changed to double"); // printEntity(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read document. " + e.getMessage()); } System.out.println("2. read document as HashMap object:"); try { @SuppressWarnings("rawtypes") - DocumentEntity entity = arangoDriver.getDocument(COLLECTION_NAME, KEY1, HashMap.class); + final DocumentEntity entity = driver.getDocument(COLLECTION_NAME, KEY1, HashMap.class); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); @@ -133,7 +145,7 @@ public void ReadDocuments() { Assert.assertNotNull(entity.getDocumentRevision()); Assert.assertEquals(KEY1, entity.getDocumentKey()); - HashMap map = entity.getEntity(); + final HashMap map = entity.getEntity(); Assert.assertNotNull(map); // get the attributes @@ -148,13 +160,13 @@ public void ReadDocuments() { System.out.println("Attribute 'age': " + map.get("age") + " <- Data type changed to double"); // printEntity(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read document. " + e.getMessage()); } System.out.println("3. read document as SimplePerson object:"); try { - DocumentEntity entity = arangoDriver.getDocument(COLLECTION_NAME, KEY1, SimplePerson.class); + final DocumentEntity entity = driver.getDocument(COLLECTION_NAME, KEY1, SimplePerson.class); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); @@ -162,7 +174,7 @@ public void ReadDocuments() { Assert.assertNotNull(entity.getDocumentRevision()); Assert.assertEquals(KEY1, entity.getDocumentKey()); - SimplePerson sp = entity.getEntity(); + final SimplePerson sp = entity.getEntity(); Assert.assertNotNull(sp); // get the attributes @@ -173,13 +185,13 @@ public void ReadDocuments() { System.out.println("Attribute 'age': " + sp.getAge()); // printEntity(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read document. " + e.getMessage()); } System.out.println("4. read document as DocumentPerson object:"); try { - DocumentEntity entity = arangoDriver.getDocument(COLLECTION_NAME, KEY1, + final DocumentEntity entity = driver.getDocument(COLLECTION_NAME, KEY1, DocumentPerson.class); Assert.assertNotNull(entity); @@ -188,7 +200,7 @@ public void ReadDocuments() { Assert.assertNotNull(entity.getDocumentRevision()); Assert.assertEquals(KEY1, entity.getDocumentKey()); - DocumentPerson dp = entity.getEntity(); + final DocumentPerson dp = entity.getEntity(); Assert.assertNotNull(dp); System.out.println("Key: " + dp.getDocumentKey()); @@ -202,7 +214,7 @@ public void ReadDocuments() { System.out.println("Attribute 'age': " + dp.getAge()); // printEntity(entity); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read document. " + e.getMessage()); } @@ -210,7 +222,7 @@ public void ReadDocuments() { printHeadline("read document by document handle"); // try { - DocumentEntity entity = arangoDriver.getDocument(documentHandleExample, + final DocumentEntity entity = driver.getDocument(documentHandleExample, DocumentPerson.class); Assert.assertNotNull(entity); @@ -219,12 +231,12 @@ public void ReadDocuments() { Assert.assertNotNull(entity.getDocumentRevision()); Assert.assertEquals(KEY1, entity.getDocumentKey()); - DocumentPerson dp = entity.getEntity(); + final DocumentPerson dp = entity.getEntity(); Assert.assertNotNull(dp); System.out.println("Key: " + dp.getDocumentKey()); System.out.println("Attribute 'name': " + dp.getName()); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read document. " + e.getMessage()); } @@ -232,13 +244,13 @@ public void ReadDocuments() { printHeadline("read collection count"); // try { - CollectionEntity collectionCount = arangoDriver.getCollectionCount(COLLECTION_NAME); + final CollectionEntity collectionCount = driver.getCollectionCount(COLLECTION_NAME); Assert.assertNotNull(collectionCount); Assert.assertEquals(1, collectionCount.getCount()); System.out.println("Collection count: " + collectionCount.getCount()); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read collection count. " + e.getMessage()); } @@ -246,16 +258,16 @@ public void ReadDocuments() { printHeadline("read all document handles of a collection"); // try { - List documentHandles = arangoDriver.getDocuments(COLLECTION_NAME); + final List documentHandles = driver.getDocuments(COLLECTION_NAME); Assert.assertNotNull(documentHandles); Assert.assertEquals(1, documentHandles.size()); - for (String documentHandle : documentHandles) { + for (final String documentHandle : documentHandles) { System.out.println("document handle: " + documentHandle); } - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to read all documents. " + e.getMessage()); } } diff --git a/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java b/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java index 3875a6f69..7d2e77596 100644 --- a/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java @@ -18,10 +18,12 @@ import java.util.HashMap; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.ErrorNums; @@ -36,15 +38,25 @@ public class ReplaceAndUpdateDocumentExample extends BaseExample { private static final String KEY1 = "key1"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public ReplaceAndUpdateDocumentExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createCollection(arangoDriver, COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createCollection(driver, COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -60,7 +72,7 @@ public void replaceAndUpdateDocument() { printHeadline("create example document"); // - HashMap myHashMap = new HashMap(); + final HashMap myHashMap = new HashMap(); myHashMap.put("_key", KEY1); // attributes are stored in a HashMap myHashMap.put("name", "Alice"); @@ -70,7 +82,7 @@ public void replaceAndUpdateDocument() { long revision = 0L; try { - DocumentEntity> entity = arangoDriver.createDocument(COLLECTION_NAME, myHashMap); + final DocumentEntity> entity = driver.createDocument(COLLECTION_NAME, myHashMap); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); @@ -82,7 +94,7 @@ public void replaceAndUpdateDocument() { System.out.println("Id: " + entity.getDocumentHandle()); System.out.println("Revision: " + entity.getDocumentRevision()); documentHandleExample = entity.getDocumentHandle(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to create document. " + e.getMessage()); } @@ -91,8 +103,8 @@ public void replaceAndUpdateDocument() { // try { - DocumentPerson dp = new DocumentPerson("Moritz", "male", 6); - arangoDriver.replaceDocument(documentHandleExample, dp); + final DocumentPerson dp = new DocumentPerson("Moritz", "male", 6); + driver.replaceDocument(documentHandleExample, dp); System.out.println("Key: " + dp.getDocumentKey()); System.out.println("Revision: " + dp.getDocumentRevision() + " <- revision changed"); @@ -102,7 +114,7 @@ public void replaceAndUpdateDocument() { revision = dp.getDocumentRevision(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to replace document. " + e.getMessage()); } @@ -111,12 +123,12 @@ public void replaceAndUpdateDocument() { // // update one attribute - HashMap newHashMap = new HashMap(); + final HashMap newHashMap = new HashMap(); newHashMap.put("name", "Fritz"); try { - arangoDriver.updateDocument(documentHandleExample, newHashMap); + driver.updateDocument(documentHandleExample, newHashMap); - DocumentEntity entity = arangoDriver.getDocument(documentHandleExample, + final DocumentEntity entity = driver.getDocument(documentHandleExample, DocumentPerson.class); Assert.assertNotNull(entity); @@ -125,7 +137,7 @@ public void replaceAndUpdateDocument() { Assert.assertNotNull(entity.getDocumentRevision()); Assert.assertNotNull(entity.getEntity()); - DocumentPerson dp = entity.getEntity(); + final DocumentPerson dp = entity.getEntity(); System.out.println("Key: " + dp.getDocumentKey()); System.out.println("Revision: " + dp.getDocumentRevision() + " <- revision changed"); @@ -137,7 +149,7 @@ public void replaceAndUpdateDocument() { revision = dp.getDocumentRevision(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Failed to update document. " + e.getMessage()); } @@ -145,19 +157,19 @@ public void replaceAndUpdateDocument() { printHeadline("replace document with given revision"); // try { - DocumentPerson dp = new DocumentPerson("Nina", "female", 9); + final DocumentPerson dp = new DocumentPerson("Nina", "female", 9); // wrong revision - arangoDriver.replaceDocument(documentHandleExample, dp, 22L, Policy.ERROR, true); + driver.replaceDocument(documentHandleExample, dp, 22L, Policy.ERROR, true); Assert.fail("replaceDocument should fail here!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.assertEquals(ErrorNums.ERROR_ARANGO_CONFLICT, e.getErrorNumber()); } try { - DocumentPerson dp = new DocumentPerson("Nina", "female", 9); + final DocumentPerson dp = new DocumentPerson("Nina", "female", 9); // current revision - arangoDriver.replaceDocument(documentHandleExample, dp, revision, Policy.ERROR, true); - } catch (ArangoException e) { + driver.replaceDocument(documentHandleExample, dp, revision, Policy.ERROR, true); + } catch (final ArangoException e) { Assert.fail("Failed to replace document. " + e.getMessage()); } } diff --git a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java index acf7e352e..32db2849d 100644 --- a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java @@ -19,10 +19,12 @@ import java.util.HashMap; import java.util.Iterator; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.DocumentCursor; @@ -35,15 +37,25 @@ public class SimplePersonAqlQueryExample extends BaseExample { private static final String COLLECTION_NAME = "SimplePersonAqlQueryExample"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public SimplePersonAqlQueryExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createCollection(arangoDriver, COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createCollection(driver, COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -66,22 +78,22 @@ public void simplePersonAqlQuery() { // // build an AQL query string - String queryString = "FOR t IN " + COLLECTION_NAME + final String queryString = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t"; System.out.println(queryString); // bind @gender to female - HashMap bindVars = new HashMap(); + final HashMap bindVars = new HashMap(); bindVars.put("gender", FEMALE); // query (count = true, batchSize = 5) - AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true).setBatchSize(5); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true).setBatchSize(5); // printHeadline("execute query"); // - DocumentCursor rs = arangoDriver.executeDocumentQuery(queryString, bindVars, aqlQueryOptions, + DocumentCursor rs = driver.executeDocumentQuery(queryString, bindVars, aqlQueryOptions, SimplePerson.class); Assert.assertNotNull(rs); @@ -97,9 +109,9 @@ public void simplePersonAqlQuery() { // // using the DocumentEntity iterator - Iterator> iterator = rs.iterator(); + final Iterator> iterator = rs.iterator(); while (iterator.hasNext()) { - DocumentEntity documentEntity = iterator.next(); + final DocumentEntity documentEntity = iterator.next(); Assert.assertNotNull(documentEntity); Assert.assertNotNull(documentEntity.getDocumentKey()); @@ -107,7 +119,7 @@ public void simplePersonAqlQuery() { Assert.assertNotNull(documentEntity.getDocumentRevision()); Assert.assertNotNull(documentEntity.getEntity()); - SimplePerson person = documentEntity.getEntity(); + final SimplePerson person = documentEntity.getEntity(); System.out.printf("%20s %15s(%5s): %d%n", documentEntity.getDocumentKey(), person.getName(), person.getGender(), person.getAge()); } @@ -116,23 +128,23 @@ public void simplePersonAqlQuery() { printHeadline("execute query again"); // - rs = arangoDriver.executeDocumentQuery(queryString, bindVars, aqlQueryOptions, SimplePerson.class); + rs = driver.executeDocumentQuery(queryString, bindVars, aqlQueryOptions, SimplePerson.class); Assert.assertNotNull(rs); // get total number of results System.out.println(rs.getCount()); // using the entity iterator - Iterator iterator2 = rs.entityIterator(); + final Iterator iterator2 = rs.entityIterator(); while (iterator2.hasNext()) { - SimplePerson person = iterator2.next(); + final SimplePerson person = iterator2.next(); Assert.assertNotNull(person); System.out.printf(" %15s(%5s): %d%n", person.getName(), person.getGender(), person.getAge()); } - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Example failed. " + e.getMessage()); } @@ -141,12 +153,12 @@ public void simplePersonAqlQuery() { private void createExamples() throws ArangoException { // create some persons for (int i = 0; i < 1000; i++) { - SimplePerson person = new SimplePerson(); + final SimplePerson person = new SimplePerson(); person.setName("TestUser" + i); person.setGender((i % 2) == 0 ? MALE : FEMALE); person.setAge((int) (Math.random() * 100) + 10); - arangoDriver.createDocument(COLLECTION_NAME, person, true, null); + driver.createDocument(COLLECTION_NAME, person, true, null); } } diff --git a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java index 6efa599f7..9c7f240ce 100644 --- a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java +++ b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java @@ -19,10 +19,12 @@ import java.util.HashMap; import java.util.Iterator; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.DocumentCursor; @@ -35,15 +37,25 @@ public class SimplePersonAqlQueryWithLimitExample extends BaseExample { private static final String COLLECTION_NAME = "SimplePersonAqlQueryWithLimitExample"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public SimplePersonAqlQueryWithLimitExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createCollection(arangoDriver, COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createCollection(driver, COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -66,21 +78,21 @@ public void simplePersonAqlWithLimitQuery() { // // build an AQL query string - String queryString = "FOR t IN " + COLLECTION_NAME + " FILTER t.gender == @gender LIMIT 5 RETURN t"; + final String queryString = "FOR t IN " + COLLECTION_NAME + " FILTER t.gender == @gender LIMIT 5 RETURN t"; System.out.println(queryString); // bind @gender to female - HashMap bindVars = new HashMap(); + final HashMap bindVars = new HashMap(); bindVars.put("gender", FEMALE); // query (count = true, batchSize = 5) - AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true).setFullCount(true); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true).setFullCount(true); // printHeadline("execute query"); // - DocumentCursor rs = arangoDriver.executeDocumentQuery(queryString, bindVars, aqlQueryOptions, + final DocumentCursor rs = driver.executeDocumentQuery(queryString, bindVars, aqlQueryOptions, SimplePerson.class); Assert.assertNotNull(rs); @@ -101,9 +113,9 @@ public void simplePersonAqlWithLimitQuery() { // // using the DocumentEntity iterator - Iterator> iterator = rs.iterator(); + final Iterator> iterator = rs.iterator(); while (iterator.hasNext()) { - DocumentEntity documentEntity = iterator.next(); + final DocumentEntity documentEntity = iterator.next(); Assert.assertNotNull(documentEntity); Assert.assertNotNull(documentEntity.getDocumentKey()); @@ -111,12 +123,12 @@ public void simplePersonAqlWithLimitQuery() { Assert.assertNotNull(documentEntity.getDocumentRevision()); Assert.assertNotNull(documentEntity.getEntity()); - SimplePerson person = documentEntity.getEntity(); + final SimplePerson person = documentEntity.getEntity(); System.out.printf("%20s %15s(%5s): %d%n", documentEntity.getDocumentKey(), person.getName(), person.getGender(), person.getAge()); } - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("Example failed. " + e.getMessage()); } @@ -125,12 +137,12 @@ public void simplePersonAqlWithLimitQuery() { private void createExamples() throws ArangoException { // create some persons for (int i = 0; i < 100; i++) { - SimplePerson person = new SimplePerson(); + final SimplePerson person = new SimplePerson(); person.setName("TestUser" + i); person.setGender((i % 2) == 0 ? MALE : FEMALE); person.setAge((int) (Math.random() * 100) + 10); - arangoDriver.createDocument(COLLECTION_NAME, person, true, null); + driver.createDocument(COLLECTION_NAME, person, true, null); } } diff --git a/src/test/java/com/arangodb/example/graph/BaseExample.java b/src/test/java/com/arangodb/example/graph/BaseExample.java index 831cbc6e5..dbf07c32d 100644 --- a/src/test/java/com/arangodb/example/graph/BaseExample.java +++ b/src/test/java/com/arangodb/example/graph/BaseExample.java @@ -24,6 +24,7 @@ import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; +import com.arangodb.BaseTest; import com.arangodb.entity.ArangoVersion; import com.arangodb.entity.BooleanResultEntity; import com.arangodb.entity.CollectionEntity; @@ -33,62 +34,55 @@ import com.arangodb.entity.GraphEntity; import com.arangodb.util.TestUtils; -public class BaseExample { +public class BaseExample extends BaseTest { - protected ArangoConfigure getConfiguration() { - ArangoConfigure configure = new ArangoConfigure(); - // configure.setUser("myUser"); - // configure.setPassword("password"); - // configuration file: src/test/resources/arangodb.properties - configure.init(); - - return configure; - } - - protected ArangoDriver getArangoDriver(ArangoConfigure configuration) { - return new ArangoDriver(configuration); + /** + * @param configure + * @param driver + */ + public BaseExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); } - protected void removeTestDatabase(String name) { - ArangoDriver arangoDriver = getArangoDriver(getConfiguration()); + protected void removeTestDatabase(final String name) { try { - arangoDriver.deleteDatabase(name); - } catch (Exception e) { + driver.deleteDatabase(name); + } catch (final Exception e) { } } - protected void createDatabase(ArangoDriver arangoDriver, String name) { + protected void createDatabase(final ArangoDriver arangoDriver, final String name) { try { - BooleanResultEntity createDatabase = arangoDriver.createDatabase(name); + final BooleanResultEntity createDatabase = arangoDriver.createDatabase(name); Assert.assertNotNull(createDatabase); Assert.assertNotNull(createDatabase.getResult()); Assert.assertTrue(createDatabase.getResult()); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail("Failed to create database " + name + "; " + e.getMessage()); } arangoDriver.setDefaultDatabase(name); } - protected void deleteDatabase(ArangoDriver arangoDriver, String name) { + protected void deleteDatabase(final ArangoDriver arangoDriver, final String name) { try { arangoDriver.deleteDatabase(name); - } catch (Exception e) { + } catch (final Exception e) { } } - protected void createCollection(ArangoDriver arangoDriver, String name) { + protected void createCollection(final ArangoDriver arangoDriver, final String name) { try { - CollectionEntity createCollection = arangoDriver.createCollection(name); + final CollectionEntity createCollection = arangoDriver.createCollection(name); Assert.assertNotNull(createCollection); Assert.assertNotNull(createCollection.getName()); Assert.assertEquals(name, createCollection.getName()); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.fail("create collection failed. " + e.getMessage()); } } - protected void printEntity(Object object) { + protected void printEntity(final Object object) { if (object == null) { System.out.println("Document not found"); } else { @@ -96,17 +90,17 @@ protected void printEntity(Object object) { } } - protected void printHeadline(String name) { + protected void printHeadline(final String name) { System.out.println("---------------------------------------------"); System.out.println(name); System.out.println("---------------------------------------------"); } public void createGraph( - ArangoDriver arangoDriver, - String grapName, - String nameEdgeCollection, - String nameVertexCollection) throws ArangoException { + final ArangoDriver arangoDriver, + final String grapName, + final String nameEdgeCollection, + final String nameVertexCollection) throws ArangoException { // printHeadline("create edge collection"); @@ -132,7 +126,7 @@ public void createGraph( printHeadline("create edge definition"); // - EdgeDefinitionEntity ed = new EdgeDefinitionEntity(); + final EdgeDefinitionEntity ed = new EdgeDefinitionEntity(); // add edge collection name ed.setCollection(nameEdgeCollection); @@ -145,20 +139,20 @@ public void createGraph( // printHeadline("create edge definition list"); // - List edgeDefinitions = new ArrayList(); + final List edgeDefinitions = new ArrayList(); edgeDefinitions.add(ed); // printHeadline("create graph"); // - GraphEntity createGraph = arangoDriver.createGraph(grapName, edgeDefinitions, null, true); + final GraphEntity createGraph = arangoDriver.createGraph(grapName, edgeDefinitions, null, true); Assert.assertNotNull(createGraph); Assert.assertEquals(grapName, createGraph.getName()); } - public boolean isMinimumVersion(ArangoDriver arangoDriver, String version) throws ArangoException { - ArangoVersion ver = arangoDriver.getVersion(); - int b = TestUtils.compareVersion(ver.getVersion(), version); + public boolean isMinimumVersion(final ArangoDriver arangoDriver, final String version) throws ArangoException { + final ArangoVersion ver = arangoDriver.getVersion(); + final int b = TestUtils.compareVersion(ver.getVersion(), version); return b > -1; } diff --git a/src/test/java/com/arangodb/example/graph/CreateGraphExample.java b/src/test/java/com/arangodb/example/graph/CreateGraphExample.java index 7b40e02b6..762b0f14d 100644 --- a/src/test/java/com/arangodb/example/graph/CreateGraphExample.java +++ b/src/test/java/com/arangodb/example/graph/CreateGraphExample.java @@ -19,10 +19,12 @@ import java.util.ArrayList; import java.util.List; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.CollectionEntity; @@ -45,14 +47,24 @@ public class CreateGraphExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public CreateGraphExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); + createDatabase(driver, DATABASE_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -62,7 +74,7 @@ public void createGraph() throws ArangoException { printHeadline("create edge collection"); // - CollectionEntity createCollection = arangoDriver.createCollection(EDGE_COLLECTION_NAME, + CollectionEntity createCollection = driver.createCollection(EDGE_COLLECTION_NAME, new CollectionOptions().setType(CollectionType.EDGE)); Assert.assertNotNull(createCollection); Assert.assertNotNull(createCollection.getId()); @@ -72,7 +84,7 @@ public void createGraph() throws ArangoException { printHeadline("create vertex collection"); // - createCollection = arangoDriver.createCollection(VERTEXT_COLLECTION_NAME, + createCollection = driver.createCollection(VERTEXT_COLLECTION_NAME, new CollectionOptions().setType(CollectionType.DOCUMENT)); Assert.assertNotNull(createCollection); Assert.assertNotNull(createCollection.getId()); @@ -82,7 +94,7 @@ public void createGraph() throws ArangoException { printHeadline("create edge definition"); // - EdgeDefinitionEntity ed = new EdgeDefinitionEntity(); + final EdgeDefinitionEntity ed = new EdgeDefinitionEntity(); // add edge collection name ed.setCollection(EDGE_COLLECTION_NAME); @@ -95,13 +107,13 @@ public void createGraph() throws ArangoException { // printHeadline("create edge definition list"); // - List edgeDefinitions = new ArrayList(); + final List edgeDefinitions = new ArrayList(); edgeDefinitions.add(ed); // printHeadline("create graph"); // - GraphEntity createGraph = arangoDriver.createGraph(GRAPH_NAME, edgeDefinitions, null, true); + final GraphEntity createGraph = driver.createGraph(GRAPH_NAME, edgeDefinitions, null, true); Assert.assertNotNull(createGraph); Assert.assertEquals(GRAPH_NAME, createGraph.getName()); } diff --git a/src/test/java/com/arangodb/example/graph/CreateVerticesAndEdgesExample.java b/src/test/java/com/arangodb/example/graph/CreateVerticesAndEdgesExample.java index 2e9cafe93..c3d897975 100644 --- a/src/test/java/com/arangodb/example/graph/CreateVerticesAndEdgesExample.java +++ b/src/test/java/com/arangodb/example/graph/CreateVerticesAndEdgesExample.java @@ -16,10 +16,12 @@ package com.arangodb.example.graph; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.EdgeEntity; @@ -39,15 +41,25 @@ public class CreateVerticesAndEdgesExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public CreateVerticesAndEdgesExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createGraph(arangoDriver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createGraph(driver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -58,8 +70,8 @@ public void verticesAndEdges() throws ArangoException { // // create some persons - Person personA = new Person("A", Person.MALE); - VertexEntity v1 = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, personA, true); + final Person personA = new Person("A", Person.MALE); + final VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, personA, true); Assert.assertNotNull(v1); Assert.assertNotNull(v1.getEntity()); Person p = v1.getEntity(); @@ -68,8 +80,8 @@ public void verticesAndEdges() throws ArangoException { Assert.assertNotNull(p.getDocumentKey()); Assert.assertNotNull(p.getDocumentRevision()); - Person personB = new Person("B", Person.MALE); - VertexEntity v2 = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, personB, false); + final Person personB = new Person("B", Person.MALE); + final VertexEntity v2 = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, personB, false); Assert.assertNotNull(v2); Assert.assertNotNull(v2.getEntity()); p = v2.getEntity(); @@ -82,12 +94,12 @@ public void verticesAndEdges() throws ArangoException { printHeadline("create edge"); // - Knows knows = new Knows(1984); - EdgeEntity graphCreateEdge = arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, + final Knows knows = new Knows(1984); + final EdgeEntity graphCreateEdge = driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v1.getDocumentHandle(), v2.getDocumentHandle(), knows, false); Assert.assertNotNull(graphCreateEdge); - Knows entity = graphCreateEdge.getEntity(); + final Knows entity = graphCreateEdge.getEntity(); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); Assert.assertNotNull(entity.getDocumentKey()); diff --git a/src/test/java/com/arangodb/example/graph/DeleteVerticesAndEdgesExample.java b/src/test/java/com/arangodb/example/graph/DeleteVerticesAndEdgesExample.java index 8e684dff1..b3356f228 100644 --- a/src/test/java/com/arangodb/example/graph/DeleteVerticesAndEdgesExample.java +++ b/src/test/java/com/arangodb/example/graph/DeleteVerticesAndEdgesExample.java @@ -1,9 +1,11 @@ package com.arangodb.example.graph; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.ErrorNums; @@ -25,15 +27,25 @@ public class DeleteVerticesAndEdgesExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public DeleteVerticesAndEdgesExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createGraph(arangoDriver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createGraph(driver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -43,17 +55,17 @@ public void deleteVertex() throws ArangoException { printHeadline("delete vertex"); // - VertexEntity v1 = createVertex(new Person("A", Person.MALE)); + final VertexEntity v1 = createVertex(new Person("A", Person.MALE)); - DeletedEntity deletedEntity = arangoDriver.graphDeleteVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final DeletedEntity deletedEntity = driver.graphDeleteVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey()); Assert.assertNotNull(deletedEntity); Assert.assertTrue(deletedEntity.getDeleted()); try { - arangoDriver.graphGetVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey(), Person.class); + driver.graphGetVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey(), Person.class); Assert.fail("graphGetVertex should fail"); - } catch (ArangoException ex) { + } catch (final ArangoException ex) { Assert.assertEquals(ErrorNums.ERROR_ARANGO_DOCUMENT_NOT_FOUND, ex.getErrorNumber()); } } @@ -65,32 +77,34 @@ public void getEdge() throws ArangoException { printHeadline("delete edge"); // - VertexEntity v1 = createVertex(new Person("A", Person.MALE)); - VertexEntity v2 = createVertex(new Person("B", Person.FEMALE)); - EdgeEntity e1 = createEdge(v1, v2, new Knows(1984)); + final VertexEntity v1 = createVertex(new Person("A", Person.MALE)); + final VertexEntity v2 = createVertex(new Person("B", Person.FEMALE)); + final EdgeEntity e1 = createEdge(v1, v2, new Knows(1984)); - DeletedEntity deletedEntity = arangoDriver.graphDeleteEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, + final DeletedEntity deletedEntity = driver.graphDeleteEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, e1.getDocumentKey()); Assert.assertNotNull(deletedEntity); Assert.assertTrue(deletedEntity.getDeleted()); try { - arangoDriver.graphGetEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, e1.getDocumentKey(), Knows.class); + driver.graphGetEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, e1.getDocumentKey(), Knows.class); Assert.fail("graphGetEdge should fail"); - } catch (ArangoException ex) { + } catch (final ArangoException ex) { Assert.assertEquals(ErrorNums.ERROR_ARANGO_DOCUMENT_NOT_FOUND, ex.getErrorNumber()); } } - private VertexEntity createVertex(Person person) throws ArangoException { - VertexEntity v = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, person, true); + private VertexEntity createVertex(final Person person) throws ArangoException { + final VertexEntity v = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, person, true); Assert.assertNotNull(v); return v; } - private EdgeEntity createEdge(VertexEntity personFrom, VertexEntity personTo, Knows knows) - throws ArangoException { - EdgeEntity e = arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, + private EdgeEntity createEdge( + final VertexEntity personFrom, + final VertexEntity personTo, + final Knows knows) throws ArangoException { + final EdgeEntity e = driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, personFrom.getDocumentHandle(), personTo.getDocumentHandle(), knows, false); Assert.assertNotNull(e); return e; diff --git a/src/test/java/com/arangodb/example/graph/GetVerticesAndEdgesExample.java b/src/test/java/com/arangodb/example/graph/GetVerticesAndEdgesExample.java index 19585b0e2..257570093 100644 --- a/src/test/java/com/arangodb/example/graph/GetVerticesAndEdgesExample.java +++ b/src/test/java/com/arangodb/example/graph/GetVerticesAndEdgesExample.java @@ -3,10 +3,12 @@ import java.util.Iterator; import java.util.List; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.Direction; @@ -30,15 +32,25 @@ public class GetVerticesAndEdgesExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public GetVerticesAndEdgesExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createGraph(arangoDriver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createGraph(driver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -48,15 +60,15 @@ public void getVertex() throws ArangoException { printHeadline("get vertex"); // - Person personA = new Person("A", Person.MALE); - VertexEntity v1 = createVertex(personA); + final Person personA = new Person("A", Person.MALE); + final VertexEntity v1 = createVertex(personA); - VertexEntity vertexEntity = arangoDriver.graphGetVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity vertexEntity = driver.graphGetVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey(), Person.class); Assert.assertNotNull(vertexEntity); Assert.assertNotNull(vertexEntity.getEntity()); - Person p = vertexEntity.getEntity(); + final Person p = vertexEntity.getEntity(); Assert.assertEquals(personA.getName(), p.getName()); Assert.assertNotNull(p.getDocumentHandle()); Assert.assertNotNull(p.getDocumentKey()); @@ -77,13 +89,12 @@ public void getVertices() throws ArangoException { printHeadline("using the cursor iterator"); // - VertexCursor vertexCursor = arangoDriver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, - null); + VertexCursor vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, null); Assert.assertNotNull(vertexCursor); - Iterator> iterator = vertexCursor.iterator(); + final Iterator> iterator = vertexCursor.iterator(); while (iterator.hasNext()) { - VertexEntity next = iterator.next(); + final VertexEntity next = iterator.next(); Assert.assertNotNull(next); printPerson(next.getEntity()); } @@ -92,12 +103,12 @@ public void getVertices() throws ArangoException { printHeadline("using the cursor entity iterator"); // - vertexCursor = arangoDriver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, null); + vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, null); Assert.assertNotNull(vertexCursor); - Iterator entityIterator = vertexCursor.entityIterator(); + final Iterator entityIterator = vertexCursor.entityIterator(); while (entityIterator.hasNext()) { - Person next = entityIterator.next(); + final Person next = entityIterator.next(); Assert.assertNotNull(next); printPerson(next); } @@ -106,12 +117,12 @@ public void getVertices() throws ArangoException { printHeadline("using cursor as list"); // - vertexCursor = arangoDriver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, null); + vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, null); Assert.assertNotNull(vertexCursor); - List> entityList = vertexCursor.asList(); + final List> entityList = vertexCursor.asList(); - for (VertexEntity next : entityList) { + for (final VertexEntity next : entityList) { Assert.assertNotNull(next); printPerson(next.getEntity()); } @@ -120,12 +131,12 @@ public void getVertices() throws ArangoException { printHeadline("using cursor as entity list"); // - vertexCursor = arangoDriver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, null); + vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, null); Assert.assertNotNull(vertexCursor); - List personList = vertexCursor.asEntityList(); + final List personList = vertexCursor.asEntityList(); - for (Person next : personList) { + for (final Person next : personList) { Assert.assertNotNull(next); printPerson(next); } @@ -144,16 +155,16 @@ public void getVerticesByExample() throws ArangoException { createVertex(new Person("C", Person.MALE)); // get all male persons - Person example = new Person(null, Person.MALE); + final Person example = new Person(null, Person.MALE); - VertexCursor vertexCursor = arangoDriver.graphGetVertexCursor(GRAPH_NAME, Person.class, example, null, + final VertexCursor vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, Person.class, example, null, null); Assert.assertNotNull(vertexCursor); - List personList = vertexCursor.asEntityList(); + final List personList = vertexCursor.asEntityList(); Assert.assertEquals(2, personList.size()); - for (Person next : personList) { + for (final Person next : personList) { Assert.assertNotNull(next); printPerson(next); } @@ -167,15 +178,15 @@ public void getEdge() throws ArangoException { printHeadline("get edge"); // - VertexEntity v1 = createVertex(new Person("A", Person.MALE)); - VertexEntity v2 = createVertex(new Person("B", Person.FEMALE)); - Knows knows = new Knows(1984); - EdgeEntity e1 = createEdge(v1, v2, knows); + final VertexEntity v1 = createVertex(new Person("A", Person.MALE)); + final VertexEntity v2 = createVertex(new Person("B", Person.FEMALE)); + final Knows knows = new Knows(1984); + final EdgeEntity e1 = createEdge(v1, v2, knows); - EdgeEntity edgeEntity = arangoDriver.graphGetEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, e1.getDocumentKey(), + final EdgeEntity edgeEntity = driver.graphGetEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, e1.getDocumentKey(), Knows.class); Assert.assertNotNull(edgeEntity); - Knows entity = edgeEntity.getEntity(); + final Knows entity = edgeEntity.getEntity(); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); Assert.assertNotNull(entity.getDocumentKey()); @@ -195,18 +206,18 @@ public void getEdges() throws ArangoException { printHeadline("get all edges"); // - VertexEntity v1 = createVertex(new Person("A", Person.MALE)); - VertexEntity v2 = createVertex(new Person("B", Person.FEMALE)); + final VertexEntity v1 = createVertex(new Person("A", Person.MALE)); + final VertexEntity v2 = createVertex(new Person("B", Person.FEMALE)); createEdge(v1, v2, new Knows(1984)); - VertexEntity v3 = createVertex(new Person("C", Person.MALE)); + final VertexEntity v3 = createVertex(new Person("C", Person.MALE)); createEdge(v1, v3, new Knows(1995)); createEdge(v2, v3, new Knows(2005)); - EdgeCursor cursor = arangoDriver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, null, null, null); - List list = cursor.asEntityList(); + final EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, null, null, null); + final List list = cursor.asEntityList(); Assert.assertEquals(3, list.size()); - for (Knows knows : list) { + for (final Knows knows : list) { printKnows(knows); } } @@ -218,52 +229,54 @@ public void getEdgesByVertexExample() throws ArangoException { printHeadline("get edges by vertex example"); // - VertexEntity v1 = createVertex(new Person("A", Person.MALE)); - VertexEntity v2 = createVertex(new Person("B", Person.FEMALE)); + final VertexEntity v1 = createVertex(new Person("A", Person.MALE)); + final VertexEntity v2 = createVertex(new Person("B", Person.FEMALE)); createEdge(v1, v2, new Knows(1984)); - VertexEntity v3 = createVertex(new Person("C", Person.MALE)); + final VertexEntity v3 = createVertex(new Person("C", Person.MALE)); createEdge(v1, v3, new Knows(1995)); createEdge(v2, v3, new Knows(2005)); // get all edges of female persons (inbound and outbound) - Person example = new Person(null, Person.FEMALE); + final Person example = new Person(null, Person.FEMALE); - EdgeCursor cursor = arangoDriver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, example, null, null); + EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, example, null, null); List list = cursor.asEntityList(); Assert.assertEquals(2, list.size()); - for (Knows knows : list) { + for (final Knows knows : list) { printKnows(knows); } // get all edges of female persons (outbound) - GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions().setDirection(Direction.OUTBOUND); + final GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions().setDirection(Direction.OUTBOUND); - cursor = arangoDriver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, example, graphEdgesOptions, null); + cursor = driver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, example, graphEdgesOptions, null); list = cursor.asEntityList(); Assert.assertEquals(1, list.size()); - for (Knows knows : list) { + for (final Knows knows : list) { printKnows(knows); } } - private VertexEntity createVertex(Person person) throws ArangoException { - VertexEntity v = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, person, true); + private VertexEntity createVertex(final Person person) throws ArangoException { + final VertexEntity v = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, person, true); Assert.assertNotNull(v); return v; } - private EdgeEntity createEdge(VertexEntity personFrom, VertexEntity personTo, Knows knows) - throws ArangoException { - EdgeEntity e = arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, + private EdgeEntity createEdge( + final VertexEntity personFrom, + final VertexEntity personTo, + final Knows knows) throws ArangoException { + final EdgeEntity e = driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, personFrom.getDocumentHandle(), personTo.getDocumentHandle(), knows, false); Assert.assertNotNull(e); return e; } - private void printPerson(Person person) { + private void printPerson(final Person person) { if (person == null) { System.out.println("Person is null"); } else { @@ -272,7 +285,7 @@ private void printPerson(Person person) { } } - private void printKnows(Knows knows) { + private void printKnows(final Knows knows) { if (knows == null) { System.out.println("Knows is null"); } else { diff --git a/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java b/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java index be4870d7f..bf10157e4 100644 --- a/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java @@ -21,10 +21,12 @@ import java.util.List; import java.util.Map; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorResult; @@ -51,18 +53,28 @@ public class GraphAqlQueryExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public GraphAqlQueryExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createGraph(arangoDriver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createGraph(driver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); addExampleElements(); } + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); + } + @Test public void graphAqlQuery() throws ArangoException { @@ -71,16 +83,15 @@ public void graphAqlQuery() throws ArangoException { // int count = 0; - VertexCursor vertexCursor = arangoDriver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, - null); + VertexCursor vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, Person.class, null, null, null); Assert.assertNotNull(vertexCursor); Iterator> vertexIterator = vertexCursor.iterator(); while (vertexIterator.hasNext()) { - VertexEntity entity = vertexIterator.next(); + final VertexEntity entity = vertexIterator.next(); Assert.assertNotNull(entity); - Person person = entity.getEntity(); + final Person person = entity.getEntity(); Assert.assertNotNull(person); System.out.printf("%d\t%20s %15s%n", ++count, entity.getDocumentHandle(), person.getName()); @@ -92,16 +103,15 @@ public void graphAqlQuery() throws ArangoException { // count = 0; - vertexCursor = arangoDriver.graphGetVertexCursor(GRAPH_NAME, Person.class, new Person("Christoph", null), null, - null); + vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, Person.class, new Person("Christoph", null), null, null); Assert.assertNotNull(vertexCursor); vertexIterator = vertexCursor.iterator(); while (vertexIterator.hasNext()) { - VertexEntity entity = vertexIterator.next(); + final VertexEntity entity = vertexIterator.next(); Assert.assertNotNull(entity); - Person person = entity.getEntity(); + final Person person = entity.getEntity(); Assert.assertNotNull(person); System.out.printf("%d\t%20s %15s%n", ++count, entity.getDocumentHandle(), person.getName()); @@ -113,15 +123,15 @@ public void graphAqlQuery() throws ArangoException { // count = 0; - EdgeCursor edgeCursor = arangoDriver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, null, null, null); + EdgeCursor edgeCursor = driver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, null, null, null); Assert.assertNotNull(edgeCursor); Iterator> edgeIterator = edgeCursor.iterator(); while (edgeIterator.hasNext()) { - EdgeEntity entity = edgeIterator.next(); + final EdgeEntity entity = edgeIterator.next(); Assert.assertNotNull(entity); - Knows knows = entity.getEntity(); + final Knows knows = entity.getEntity(); Assert.assertNotNull(knows); System.out.printf("%d\t%20s %20s->%20s %d%n", ++count, entity.getDocumentHandle(), @@ -134,16 +144,16 @@ public void graphAqlQuery() throws ArangoException { // count = 0; - edgeCursor = arangoDriver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, new Person("Christoph", Person.MALE), + edgeCursor = driver.graphGetEdgeCursor(GRAPH_NAME, Knows.class, new Person("Christoph", Person.MALE), new GraphEdgesOptions().setDirection(Direction.OUTBOUND), null); Assert.assertNotNull(edgeCursor); edgeIterator = edgeCursor.iterator(); while (edgeIterator.hasNext()) { - EdgeEntity entity = edgeIterator.next(); + final EdgeEntity entity = edgeIterator.next(); Assert.assertNotNull(entity); - Knows knows = entity.getEntity(); + final Knows knows = entity.getEntity(); Assert.assertNotNull(knows); System.out.printf("%d\t%20s %20s->%20s %d%n", ++count, entity.getDocumentHandle(), entity.getFromVertexHandle(), entity.getToVertexHandle(), knows.getSince()); @@ -155,7 +165,7 @@ public void graphAqlQuery() throws ArangoException { // // path Anton -> Frauke - ShortestPathEntity shortestPath = arangoDriver.graphGetShortestPath(GRAPH_NAME, + ShortestPathEntity shortestPath = driver.graphGetShortestPath(GRAPH_NAME, new Person("Anton", Person.MALE), new Person("Frauke", Person.FEMALE), new ShortestPathOptions().setDirection(Direction.OUTBOUND), Person.class, Knows.class); Assert.assertNotNull(shortestPath); @@ -168,7 +178,7 @@ public void graphAqlQuery() throws ArangoException { // // path Frauke -> Anton (empty result) - shortestPath = arangoDriver.graphGetShortestPath(GRAPH_NAME, new Person("Frauke", Person.FEMALE), + shortestPath = driver.graphGetShortestPath(GRAPH_NAME, new Person("Frauke", Person.FEMALE), new Person("Anton", Person.MALE), new ShortestPathOptions().setDirection(Direction.OUTBOUND), Person.class, Knows.class); Assert.assertNotNull(shortestPath); @@ -185,11 +195,11 @@ public void graphAqlQuery() throws ArangoException { Map bindVars = new HashMap(); bindVars.put("graphName", GRAPH_NAME); - CursorResult cursor = arangoDriver.executeAqlQuery(query, bindVars, null, String.class); + final CursorResult cursor = driver.executeAqlQuery(query, bindVars, null, String.class); Assert.assertNotNull(cursor); - List list = cursor.asList(); + final List list = cursor.asList(); count = 0; - for (String str : list) { + for (final String str : list) { System.out.printf("%d\t%20s%n", ++count, str); } Assert.assertEquals(6, list.size()); @@ -203,17 +213,17 @@ public void graphAqlQuery() throws ArangoException { bindVars.put("graphName", GRAPH_NAME); bindVars.put("name", "Boris"); - CursorResult cursor2 = arangoDriver.executeAqlQuery(query, bindVars, null, Person.class); + final CursorResult cursor2 = driver.executeAqlQuery(query, bindVars, null, Person.class); Assert.assertNotNull(cursor2); - List list2 = cursor2.asList(); + final List list2 = cursor2.asList(); count = 0; - for (Person person : list2) { + for (final Person person : list2) { System.out.printf("%d\t%20s\t%s%n", ++count, person.getDocumentHandle(), person.getName()); } Assert.assertEquals(5, list2.size()); } - private void printShortestPath(ShortestPathEntity shortestPath) { + private void printShortestPath(final ShortestPathEntity shortestPath) { if (shortestPath.getDistance() > -1) { System.out.printf("%s -> %s : distance = %d, getVertices().size() = %d, edges.size() = %d%n", shortestPath.getVertices().get(0).getDocumentHandle(), @@ -226,32 +236,32 @@ private void printShortestPath(ShortestPathEntity shortestPath) { private void addExampleElements() throws ArangoException { // create some persons - VertexEntity v1 = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, new Person("Anton", Person.MALE), true); - VertexEntity v2 = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity v2 = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, new Person("Boris", Person.MALE), false); - VertexEntity v3 = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity v3 = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, new Person("Christoph", Person.MALE), false); - VertexEntity v4 = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity v4 = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, new Person("Doris", Person.FEMALE), false); - VertexEntity v5 = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity v5 = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, new Person("Else", Person.FEMALE), false); - VertexEntity v6 = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity v6 = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, new Person("Frauke", Person.FEMALE), false); - arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v1.getDocumentHandle(), v2.getDocumentHandle(), + driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v1.getDocumentHandle(), v2.getDocumentHandle(), new Knows(1984), false); - arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v2.getDocumentHandle(), v6.getDocumentHandle(), + driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v2.getDocumentHandle(), v6.getDocumentHandle(), new Knows(1990), false); - arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v1.getDocumentHandle(), v3.getDocumentHandle(), + driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v1.getDocumentHandle(), v3.getDocumentHandle(), new Knows(1992), false); - arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v3.getDocumentHandle(), v4.getDocumentHandle(), + driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v3.getDocumentHandle(), v4.getDocumentHandle(), new Knows(1996), false); - arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v4.getDocumentHandle(), v6.getDocumentHandle(), + driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v4.getDocumentHandle(), v6.getDocumentHandle(), new Knows(2003), false); - arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v4.getDocumentHandle(), v5.getDocumentHandle(), + driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v4.getDocumentHandle(), v5.getDocumentHandle(), new Knows(2013), false); - arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v3.getDocumentHandle(), v5.getDocumentHandle(), + driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, v3.getDocumentHandle(), v5.getDocumentHandle(), new Knows(2003), false); } diff --git a/src/test/java/com/arangodb/example/graph/GraphAqlTraversalQueryExample.java b/src/test/java/com/arangodb/example/graph/GraphAqlTraversalQueryExample.java index d72fe896d..a84af3b8c 100644 --- a/src/test/java/com/arangodb/example/graph/GraphAqlTraversalQueryExample.java +++ b/src/test/java/com/arangodb/example/graph/GraphAqlTraversalQueryExample.java @@ -19,10 +19,12 @@ import java.util.HashMap; import java.util.Iterator; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorResult; @@ -45,22 +47,32 @@ public class GraphAqlTraversalQueryExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edges"; private static final String VERTEXT_COLLECTION_NAME = "circles"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public GraphAqlTraversalQueryExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createGraph(arangoDriver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createGraph(driver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); addExampleElements(); } + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); + } + @Test public void graphAqlQuery() throws ArangoException { - if (isMinimumVersion(arangoDriver, TestUtils.VERSION_2_8)) { + if (isMinimumVersion(driver, TestUtils.VERSION_2_8)) { // printHeadline( "To get started we select the full graph; for better overview we only return the vertex ids:"); @@ -125,19 +137,19 @@ public void graphAqlQuery() throws ArangoException { } } - private CursorResult executeAndPrintResultKeys(String queryString) throws ArangoException { - HashMap bindVars = new HashMap(); - AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true); + private CursorResult executeAndPrintResultKeys(final String queryString) throws ArangoException { + final HashMap bindVars = new HashMap(); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(true); System.out.println("Query: " + queryString); - CursorResult cursor = arangoDriver.executeAqlQuery(queryString, bindVars, aqlQueryOptions, + final CursorResult cursor = driver.executeAqlQuery(queryString, bindVars, aqlQueryOptions, String.class); Assert.assertNotNull(cursor); - Iterator iterator = cursor.iterator(); + final Iterator iterator = cursor.iterator(); while (iterator.hasNext()) { - String key = iterator.next(); + final String key = iterator.next(); Assert.assertNotNull(key); @@ -150,17 +162,17 @@ private CursorResult executeAndPrintResultKeys(String queryString) throw private void addExampleElements() throws ArangoException { // Add circle circles - VertexEntity vA = createVertex(new Circle("A", "1")); - VertexEntity vB = createVertex(new Circle("B", "2")); - VertexEntity vC = createVertex(new Circle("C", "3")); - VertexEntity vD = createVertex(new Circle("D", "4")); - VertexEntity vE = createVertex(new Circle("E", "5")); - VertexEntity vF = createVertex(new Circle("F", "6")); - VertexEntity vG = createVertex(new Circle("G", "7")); - VertexEntity vH = createVertex(new Circle("H", "8")); - VertexEntity vI = createVertex(new Circle("I", "9")); - VertexEntity vJ = createVertex(new Circle("J", "10")); - VertexEntity vK = createVertex(new Circle("K", "11")); + final VertexEntity vA = createVertex(new Circle("A", "1")); + final VertexEntity vB = createVertex(new Circle("B", "2")); + final VertexEntity vC = createVertex(new Circle("C", "3")); + final VertexEntity vD = createVertex(new Circle("D", "4")); + final VertexEntity vE = createVertex(new Circle("E", "5")); + final VertexEntity vF = createVertex(new Circle("F", "6")); + final VertexEntity vG = createVertex(new Circle("G", "7")); + final VertexEntity vH = createVertex(new Circle("H", "8")); + final VertexEntity vI = createVertex(new Circle("I", "9")); + final VertexEntity vJ = createVertex(new Circle("J", "10")); + final VertexEntity vK = createVertex(new Circle("K", "11")); // Add relevant edges - left branch: saveEdge(vA, vB, new CircleEdge(false, true, "left_bar")); @@ -177,14 +189,16 @@ private void addExampleElements() throws ArangoException { saveEdge(vJ, vK, new CircleEdge(false, true, "right_zup")); } - private EdgeEntity saveEdge(VertexEntity from, VertexEntity to, CircleEdge edge) - throws ArangoException { - return arangoDriver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, from.getDocumentHandle(), + private EdgeEntity saveEdge( + final VertexEntity from, + final VertexEntity to, + final CircleEdge edge) throws ArangoException { + return driver.graphCreateEdge(GRAPH_NAME, EDGE_COLLECTION_NAME, from.getDocumentHandle(), to.getDocumentHandle(), edge, false); } - private VertexEntity createVertex(Circle vertex) throws ArangoException { - return arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, vertex, true); + private VertexEntity createVertex(final Circle vertex) throws ArangoException { + return driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, vertex, true); } } diff --git a/src/test/java/com/arangodb/example/graph/UpdateAndReplaceVertexExample.java b/src/test/java/com/arangodb/example/graph/UpdateAndReplaceVertexExample.java index 334e7d1b7..2c2b162f5 100644 --- a/src/test/java/com/arangodb/example/graph/UpdateAndReplaceVertexExample.java +++ b/src/test/java/com/arangodb/example/graph/UpdateAndReplaceVertexExample.java @@ -1,9 +1,11 @@ package com.arangodb.example.graph; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.marker.VertexEntity; @@ -22,15 +24,25 @@ public class UpdateAndReplaceVertexExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - public ArangoDriver arangoDriver; + /** + * @param configure + * @param driver + */ + public UpdateAndReplaceVertexExample(final ArangoConfigure configure, final ArangoDriver driver) { + super(configure, driver); + } @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); - arangoDriver = getArangoDriver(getConfiguration()); - createDatabase(arangoDriver, DATABASE_NAME); - createGraph(arangoDriver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + createDatabase(driver, DATABASE_NAME); + createGraph(driver, GRAPH_NAME, EDGE_COLLECTION_NAME, VERTEXT_COLLECTION_NAME); + } + + @After + public void _after() { + removeTestDatabase(DATABASE_NAME); } @Test @@ -40,12 +52,12 @@ public void replaceVertex() throws ArangoException { printHeadline("replace vertex"); // - Person personA = new Person("A", Person.MALE); - VertexEntity v1 = createVertex(personA); + final Person personA = new Person("A", Person.MALE); + final VertexEntity v1 = createVertex(personA); - Person personB = new Person("B", Person.FEMALE); + final Person personB = new Person("B", Person.FEMALE); - VertexEntity replaceVertex = arangoDriver.graphReplaceVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity replaceVertex = driver.graphReplaceVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey(), personB); // document handle is unchanged Assert.assertNotNull(replaceVertex); @@ -64,13 +76,13 @@ public void updateVertex() throws ArangoException { printHeadline("update vertex"); // - Person personA = new Person("A", Person.MALE); - VertexEntity v1 = createVertex(personA); + final Person personA = new Person("A", Person.MALE); + final VertexEntity v1 = createVertex(personA); // update one attribute (gender) personA.setGender(Person.FEMALE); - VertexEntity updateVertex = arangoDriver.graphUpdateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity updateVertex = driver.graphUpdateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey(), personA, true); // document handle is unchanged @@ -91,16 +103,16 @@ public void updateOneAttribute() throws ArangoException { printHeadline("update one vertex attribute"); // - Person personA = new Person("A", Person.MALE); - VertexEntity v1 = createVertex(personA); + final Person personA = new Person("A", Person.MALE); + final VertexEntity v1 = createVertex(personA); // update one attribute (gender) - Person update = new Person(null, Person.FEMALE); + final Person update = new Person(null, Person.FEMALE); - arangoDriver.graphUpdateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey(), update, true); + driver.graphUpdateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey(), update, true); // reload vertex - VertexEntity updateVertex = arangoDriver.graphGetVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, + final VertexEntity updateVertex = driver.graphGetVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, v1.getDocumentKey(), Person.class); // document handle is unchanged @@ -114,8 +126,8 @@ public void updateOneAttribute() throws ArangoException { Assert.assertEquals(personA.getName(), updateVertex.getEntity().getName()); } - private VertexEntity createVertex(Person person) throws ArangoException { - VertexEntity v = arangoDriver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, person, true); + private VertexEntity createVertex(final Person person) throws ArangoException { + final VertexEntity v = driver.graphCreateVertex(GRAPH_NAME, VERTEXT_COLLECTION_NAME, person, true); Assert.assertNotNull(v); return v; } From 7f71f93b6e5b5caea17cc66d5340249c24f76df7 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 24 May 2016 09:13:13 +0200 Subject: [PATCH 10/56] optimize tests (too many open http connections) -step 2 --- .../com/arangodb/ArangoBaseParameterTest.java | 106 ++- .../com/arangodb/ArangoDriverAdminTest.java | 40 +- .../ArangoDriverAqlfunctionsTest.java | 127 ++- .../com/arangodb/ArangoDriverAsyncTest.java | 46 +- .../com/arangodb/ArangoDriverBatchTest.java | 59 +- .../arangodb/ArangoDriverCollectionTest.java | 149 ++-- .../ArangoDriverCursorResultSetTest.java | 66 +- .../com/arangodb/ArangoDriverCursorTest.java | 80 +- .../arangodb/ArangoDriverDatabaseTest.java | 10 - .../ArangoDriverDocumentCursorEntityTest.java | 51 +- .../ArangoDriverDocumentCursorTest.java | 152 ++-- .../arangodb/ArangoDriverDocumentTest.java | 200 +++-- .../arangodb/ArangoDriverEndpointTest.java | 4 - .../ArangoDriverGraphEdgeCreateTest.java | 44 +- .../ArangoDriverGraphEdgeDeleteTest.java | 408 ++++----- .../ArangoDriverGraphEdgeGetTest.java | 92 +- .../ArangoDriverGraphEdgeReplaceTest.java | 72 +- .../ArangoDriverGraphEdgeUpdateTest.java | 62 +- .../ArangoDriverGraphEdgesGetCursorTest.java | 143 ++- .../ArangoDriverGraphEdgesGetTest.java | 50 +- .../com/arangodb/ArangoDriverGraphTest.java | 821 +++++++++--------- .../ArangoDriverGraphVertexReplaceTest.java | 64 +- .../arangodb/ArangoDriverGraphVertexTest.java | 106 ++- .../ArangoDriverGraphVertexUpdateTest.java | 48 +- .../com/arangodb/ArangoDriverImportTest.java | 32 +- .../com/arangodb/ArangoDriverIndexTest.java | 70 +- .../arangodb/ArangoDriverQueryCacheTest.java | 19 +- .../com/arangodb/ArangoDriverQueryTest.java | 72 +- .../arangodb/ArangoDriverReplicationTest.java | 118 +-- .../arangodb/ArangoDriverSimpleGeoTest.java | 64 +- .../com/arangodb/ArangoDriverSimpleTest.java | 114 ++- .../arangodb/ArangoDriverTransactionTest.java | 16 +- .../arangodb/ArangoDriverTraversalTest.java | 47 +- .../com/arangodb/ArangoDriverUsersTest.java | 605 +++++++------ .../java/com/arangodb/BaseDocumentTest.java | 87 +- src/test/java/com/arangodb/BaseGraphTest.java | 26 +- src/test/java/com/arangodb/BaseTest.java | 74 +- src/test/java/com/arangodb/NegativeTest.java | 40 +- .../com/arangodb/PrimitiveDocumentTest.java | 58 +- .../com/arangodb/bench/BenchmarkImport.java | 10 - .../arangodb/example/TransactionExample.java | 9 - ...AqlQueryWithSpecialReturnTypesExample.java | 10 - .../example/document/BaseExample.java | 9 - .../example/document/CollectionExample.java | 10 - .../CreateAndDeleteDatabaseExample.java | 8 - .../document/CreateDocumentExample.java | 10 - .../DocumentPersonAqlQueryExample.java | 10 - .../example/document/RawDocumentExample.java | 10 - .../example/document/ReadDocumentExample.java | 10 - .../ReplaceAndUpdateDocumentExample.java | 10 - .../document/SimplePersonAqlQueryExample.java | 10 - .../SimplePersonAqlQueryWithLimitExample.java | 10 - .../arangodb/example/graph/BaseExample.java | 9 - .../example/graph/CreateGraphExample.java | 10 - .../graph/CreateVerticesAndEdgesExample.java | 10 - .../graph/DeleteVerticesAndEdgesExample.java | 10 - .../graph/GetVerticesAndEdgesExample.java | 10 - .../example/graph/GraphAqlQueryExample.java | 10 - .../graph/GraphAqlTraversalQueryExample.java | 10 - .../graph/UpdateAndReplaceVertexExample.java | 10 - 60 files changed, 2083 insertions(+), 2564 deletions(-) diff --git a/src/test/java/com/arangodb/ArangoBaseParameterTest.java b/src/test/java/com/arangodb/ArangoBaseParameterTest.java index dca8f6b94..793254d6e 100644 --- a/src/test/java/com/arangodb/ArangoBaseParameterTest.java +++ b/src/test/java/com/arangodb/ArangoBaseParameterTest.java @@ -17,60 +17,56 @@ */ public class ArangoBaseParameterTest extends BaseTest { - public ArangoBaseParameterTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - final String collectionName = "unit_test_base_parameter"; - - @Before - public void before() throws ArangoException { - try { - driver.deleteCollection(collectionName); - } catch (ArangoException e) { - - } - try { - driver.createCollection(collectionName); - } catch (ArangoException e) { - - } - } - - @After - public void after() throws ArangoException { - } - - @Test - public void test_base_parameters_1() { - String errorMessage = "some message"; - TestBaseParameters testBaseParameters = new TestBaseParameters(true, 500, 4711, errorMessage, -1); - - DocumentEntity documentEntity1 = null; - DocumentEntity documentEntity2 = null; - - try { - documentEntity1 = driver.createDocument(collectionName, testBaseParameters); - } catch (ArangoException e) { - e.printStackTrace(); - } - - try { - documentEntity2 = driver.getDocument(documentEntity1.getDocumentHandle(), TestBaseParameters.class); - } catch (ArangoException e) { - e.printStackTrace(); - } - - assertThat(documentEntity2.getEntity().isError(), is(true)); - assertThat(documentEntity2.getEntity().getCode(), is(500)); - assertThat(documentEntity2.getEntity().getErrorNum(), is(4711)); - assertThat(documentEntity2.getEntity().getErrorMessage(), is(errorMessage)); - - assertThat(documentEntity2.isError(), is(false)); - assertThat(documentEntity2.getCode(), is(200)); - assertThat(documentEntity2.getErrorNumber(), is(0)); - assertThat(documentEntity2.getErrorMessage(), is(nullValue())); - - } + final String collectionName = "unit_test_base_parameter"; + + @Before + public void before() throws ArangoException { + try { + driver.deleteCollection(collectionName); + } catch (final ArangoException e) { + + } + try { + driver.createCollection(collectionName); + } catch (final ArangoException e) { + + } + } + + @After + public void after() throws ArangoException { + } + + @Test + public void test_base_parameters_1() { + final String errorMessage = "some message"; + final TestBaseParameters testBaseParameters = new TestBaseParameters(true, 500, 4711, errorMessage, -1); + + DocumentEntity documentEntity1 = null; + DocumentEntity documentEntity2 = null; + + try { + documentEntity1 = driver.createDocument(collectionName, testBaseParameters); + } catch (final ArangoException e) { + e.printStackTrace(); + } + + try { + documentEntity2 = driver.getDocument(documentEntity1.getDocumentHandle(), TestBaseParameters.class); + } catch (final ArangoException e) { + e.printStackTrace(); + } + + assertThat(documentEntity2.getEntity().isError(), is(true)); + assertThat(documentEntity2.getEntity().getCode(), is(500)); + assertThat(documentEntity2.getEntity().getErrorNum(), is(4711)); + assertThat(documentEntity2.getEntity().getErrorMessage(), is(errorMessage)); + + assertThat(documentEntity2.isError(), is(false)); + assertThat(documentEntity2.getCode(), is(200)); + assertThat(documentEntity2.getErrorNumber(), is(0)); + assertThat(documentEntity2.getErrorMessage(), is(nullValue())); + + } } diff --git a/src/test/java/com/arangodb/ArangoDriverAdminTest.java b/src/test/java/com/arangodb/ArangoDriverAdminTest.java index 04b7e7d2b..b63dbf994 100644 --- a/src/test/java/com/arangodb/ArangoDriverAdminTest.java +++ b/src/test/java/com/arangodb/ArangoDriverAdminTest.java @@ -46,14 +46,10 @@ public class ArangoDriverAdminTest extends BaseTest { private static Logger logger = LoggerFactory.getLogger(ArangoDriverAdminTest.class); - public ArangoDriverAdminTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Test public void test_version() throws ArangoException { - ArangoVersion version = driver.getVersion(); + final ArangoVersion version = driver.getVersion(); assertEquals("arango", version.getServer()); assertNotNull(version.getVersion()); assertTrue(version.getVersion().startsWith("2.") || version.getVersion().startsWith("3.")); @@ -62,7 +58,7 @@ public void test_version() throws ArangoException { @Test public void test_time() throws ArangoException { - ArangoUnixTime time = driver.getTime(); + final ArangoUnixTime time = driver.getTime(); assertThat(time.getSecond(), is(not(0))); assertThat(time.getMicrosecond(), is(not(0))); @@ -75,14 +71,14 @@ public void test_time() throws ArangoException { @Test public void test_log_all() throws ArangoException { - AdminLogEntity entity = driver.getServerLog(null, null, null, null, null, null, null); + final AdminLogEntity entity = driver.getServerLog(null, null, null, null, null, null, null); assertThat(entity, is(notNullValue())); assertThat(entity.getTotalAmount(), is(not(0))); assertThat(entity.getLogs().size(), is(entity.getTotalAmount())); // debug - for (AdminLogEntity.LogEntry log : entity.getLogs()) { + for (final AdminLogEntity.LogEntry log : entity.getLogs()) { logger.debug("%d\t%d\t%tF % it = res.getAqlFunctions().keySet().iterator(); - while(it.hasNext()) { - driver.deleteAqlFunction(it.next(), false); - } - } - - @After - public void after() { - } - - @Test - public void test_AqlFunctions() throws ArangoException { - - DefaultEntity res = driver.createAqlFunction( - "someNamespace::testCode", "function (celsius) { return celsius * 2.8 + 32; }" - ); - assertThat(res.getCode(), is(201)); - assertThat(res.getErrorMessage(), is((String) null)); - - try { - res = driver.createAqlFunction( - "someNamespace::testC&&&&&&&&&&de", "function (celsius) { return celsius * 2.8 + 32; }" - ); - } catch (ArangoException e) { - assertThat(e.getCode(), is(400)); - assertThat(e.getErrorMessage(), is("invalid user function name")); - } - - res = driver.createAqlFunction( - "anotherNamespace::testCode", "function (celsius) { return celsius * 2.8 + 32; }" - ); - assertThat(res.getCode(), is(201)); - assertThat(res.getErrorMessage(), is((String) null)); - res = driver.createAqlFunction( - "anotherNamespace::testCode2", "function (celsius) { return celsius * 2.8 + 32; }" - ); - assertThat(res.getCode(), is(201)); - assertThat(res.getErrorMessage(), is((String) null)); - - AqlFunctionsEntity r = driver.getAqlFunctions(null); - assertThat(r.size() , is(3)); - assertTrue(r.getAqlFunctions().keySet().contains("anotherNamespace::testCode")); - assertTrue(r.getAqlFunctions().keySet().contains("someNamespace::testCode")); - - r = driver.getAqlFunctions("someNamespace"); - assertThat(r.size() , is(1)); - assertFalse(r.getAqlFunctions().keySet().contains("anotherNamespace::testCode")); - assertTrue(r.getAqlFunctions().keySet().contains("someNamespace::testCode")); - - res = driver.deleteAqlFunction("someNamespace::testCode", false); - assertThat(res.getCode(), is(200)); - assertThat(res.getErrorMessage(), is((String) null)); - - res = driver.deleteAqlFunction("anotherNamespace", true); - assertThat(res.getCode(), is(200)); - assertThat(res.getErrorMessage(), is((String) null)); - - AqlFunctionsEntity c = driver.getAqlFunctions("someNamespace"); - assertThat(c.size() , is(0)); - } + @Before + public void before() throws ArangoException { + final AqlFunctionsEntity res = driver.getAqlFunctions(null); + final Iterator it = res.getAqlFunctions().keySet().iterator(); + while (it.hasNext()) { + driver.deleteAqlFunction(it.next(), false); + } + } + + @After + public void after() { + } + + @Test + public void test_AqlFunctions() throws ArangoException { + + DefaultEntity res = driver.createAqlFunction("someNamespace::testCode", + "function (celsius) { return celsius * 2.8 + 32; }"); + assertThat(res.getCode(), is(201)); + assertThat(res.getErrorMessage(), is((String) null)); + + try { + res = driver.createAqlFunction("someNamespace::testC&&&&&&&&&&de", + "function (celsius) { return celsius * 2.8 + 32; }"); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(400)); + assertThat(e.getErrorMessage(), is("invalid user function name")); + } + + res = driver.createAqlFunction("anotherNamespace::testCode", + "function (celsius) { return celsius * 2.8 + 32; }"); + assertThat(res.getCode(), is(201)); + assertThat(res.getErrorMessage(), is((String) null)); + res = driver.createAqlFunction("anotherNamespace::testCode2", + "function (celsius) { return celsius * 2.8 + 32; }"); + assertThat(res.getCode(), is(201)); + assertThat(res.getErrorMessage(), is((String) null)); + + AqlFunctionsEntity r = driver.getAqlFunctions(null); + assertThat(r.size(), is(3)); + assertTrue(r.getAqlFunctions().keySet().contains("anotherNamespace::testCode")); + assertTrue(r.getAqlFunctions().keySet().contains("someNamespace::testCode")); + + r = driver.getAqlFunctions("someNamespace"); + assertThat(r.size(), is(1)); + assertFalse(r.getAqlFunctions().keySet().contains("anotherNamespace::testCode")); + assertTrue(r.getAqlFunctions().keySet().contains("someNamespace::testCode")); + + res = driver.deleteAqlFunction("someNamespace::testCode", false); + assertThat(res.getCode(), is(200)); + assertThat(res.getErrorMessage(), is((String) null)); + + res = driver.deleteAqlFunction("anotherNamespace", true); + assertThat(res.getCode(), is(200)); + assertThat(res.getErrorMessage(), is((String) null)); + + final AqlFunctionsEntity c = driver.getAqlFunctions("someNamespace"); + assertThat(c.size(), is(0)); + } } diff --git a/src/test/java/com/arangodb/ArangoDriverAsyncTest.java b/src/test/java/com/arangodb/ArangoDriverAsyncTest.java index ba7e987f9..a067baa1c 100644 --- a/src/test/java/com/arangodb/ArangoDriverAsyncTest.java +++ b/src/test/java/com/arangodb/ArangoDriverAsyncTest.java @@ -40,28 +40,24 @@ */ public class ArangoDriverAsyncTest extends BaseTest { - public ArangoDriverAsyncTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Before public void before() throws ArangoException { - for (String col : new String[] { "blub" }) { + for (final String col : new String[] { "blub" }) { try { driver.deleteCollection(col); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection(col); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.stopAsyncMode(); - } catch (ArangoException e) { + } catch (final ArangoException e) { } - AqlFunctionsEntity res = driver.getAqlFunctions(null); - Iterator it = res.getAqlFunctions().keySet().iterator(); + final AqlFunctionsEntity res = driver.getAqlFunctions(null); + final Iterator it = res.getAqlFunctions().keySet().iterator(); while (it.hasNext()) { driver.deleteAqlFunction(it.next(), false); } @@ -79,7 +75,7 @@ public void test_StartCancelExecuteAsyncMode() throws ArangoException { String msg = ""; try { driver.startAsyncMode(false); - } catch (ArangoException e) { + } catch (final ArangoException e) { msg = e.getErrorMessage(); } assertThat(msg, is("Arango driver already set to asynchronous mode.")); @@ -88,7 +84,7 @@ public void test_StartCancelExecuteAsyncMode() throws ArangoException { msg = ""; try { driver.stopAsyncMode(); - } catch (ArangoException e) { + } catch (final ArangoException e) { msg = e.getErrorMessage(); } assertThat(msg, is("Arango driver already set to synchronous mode.")); @@ -114,7 +110,7 @@ public void test_execAsyncMode() throws ArangoException { assertThat(driver.getJobIds().size(), is(3)); for (int i = 0; i < 10; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); driver.createDocument("blub", value, true, false); assertThat(driver.getJobIds().size(), is(4 + i)); } @@ -166,7 +162,7 @@ public void test_GetJobsMode() throws ArangoException { assertThat(driver.getJobIds().size(), is(3)); for (int i = 0; i < 10; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); driver.createDocument("blub", value, true, false); assertThat(driver.getJobIds().size(), is(4 + i)); } @@ -179,7 +175,7 @@ public void test_GetJobsMode() throws ArangoException { driver.startAsyncMode(false); for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); driver.createDocument("blub", value, true, false); } driver.stopAsyncMode(); @@ -197,20 +193,20 @@ public void test_GetJobsResult() throws ArangoException { driver.createAqlFunction("someNamespace::testCode", "function (celsius) { return celsius * 2.8 + 32; }"); - String id1 = driver.getLastJobId(); + final String id1 = driver.getLastJobId(); driver.createAqlFunction("someNamespace::testC&&&&&&&&&&de", "function (celsius) { return celsius * 2.8 + 32; }"); - String id2 = driver.getLastJobId(); + final String id2 = driver.getLastJobId(); driver.getAqlFunctions(null); - String id3 = driver.getLastJobId(); + final String id3 = driver.getLastJobId(); - List ids = new ArrayList(); + final List ids = new ArrayList(); for (int i = 0; i < 10; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); driver.createDocument("blub", value, true, false); ids.add(driver.getLastJobId()); } @@ -218,24 +214,24 @@ public void test_GetJobsResult() throws ArangoException { driver.stopAsyncMode(); try { Thread.sleep(2000); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { e.printStackTrace(); } - DefaultEntity de = driver.getJobResult(id1); + final DefaultEntity de = driver.getJobResult(id1); assertThat(de.getStatusCode(), is(201)); try { driver.getJobResult(id2); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertTrue(e.getErrorMessage().equals("java.lang.reflect.InvocationTargetException")); } - AqlFunctionsEntity functions = driver.getJobResult(id3); + final AqlFunctionsEntity functions = driver.getJobResult(id3); assertThat(functions.getStatusCode(), is(200)); DocumentEntity resultComplex; - for (String id : ids) { + for (final String id : ids) { resultComplex = driver.getJobResult(id); assertThat(resultComplex.getStatusCode(), is(202)); } diff --git a/src/test/java/com/arangodb/ArangoDriverBatchTest.java b/src/test/java/com/arangodb/ArangoDriverBatchTest.java index d0ae58e04..f4d8be522 100644 --- a/src/test/java/com/arangodb/ArangoDriverBatchTest.java +++ b/src/test/java/com/arangodb/ArangoDriverBatchTest.java @@ -36,25 +36,21 @@ */ public class ArangoDriverBatchTest extends BaseTest { - String colName = "unit_test_batchTest"; - - public ArangoDriverBatchTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private static final String COLLECTION_NAME = "unit_test_batchTest"; @Before public void before() throws ArangoException { try { driver.cancelBatchMode(); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { - driver.deleteCollection(colName); - } catch (ArangoException e) { + driver.deleteCollection(COLLECTION_NAME); + } catch (final ArangoException e) { } try { - driver.createCollection(colName); - } catch (Exception e) { + driver.createCollection(COLLECTION_NAME); + } catch (final Exception e) { e.printStackTrace(); } @@ -64,11 +60,11 @@ public void before() throws ArangoException { public void after() { try { driver.cancelBatchMode(); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { - driver.deleteCollection(colName); - } catch (ArangoException e) { + driver.deleteCollection(COLLECTION_NAME); + } catch (final ArangoException e) { } } @@ -79,7 +75,7 @@ public void test_StartCancelExecuteBatchMode() throws ArangoException { String msg = ""; try { driver.startBatchMode(); - } catch (ArangoException e) { + } catch (final ArangoException e) { msg = e.getErrorMessage(); } assertThat(msg, is("BatchMode is already active.")); @@ -88,7 +84,7 @@ public void test_StartCancelExecuteBatchMode() throws ArangoException { msg = ""; try { driver.cancelBatchMode(); - } catch (ArangoException e) { + } catch (final ArangoException e) { msg = e.getErrorMessage(); } assertThat(msg, is("BatchMode is not active.")); @@ -96,7 +92,7 @@ public void test_StartCancelExecuteBatchMode() throws ArangoException { msg = ""; try { driver.executeBatch(); - } catch (ArangoException e) { + } catch (final ArangoException e) { msg = e.getErrorMessage(); } assertThat(msg, is("BatchMode is not active.")); @@ -108,7 +104,7 @@ public void test_execBatchMode() throws ArangoException { try { driver.truncateCollection("_aqlfunctions"); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } @@ -131,32 +127,33 @@ public void test_execBatchMode() throws ArangoException { assertThat(res.getRequestId(), is("request3")); for (int i = 0; i < 10; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - res = driver.createDocument(colName, value, true, false); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); + res = driver.createDocument(COLLECTION_NAME, value, true, false); assertThat(res.getStatusCode(), is(206)); assertThat(res.getRequestId(), is("request" + (4 + i))); } - driver.getDocuments(colName); + driver.getDocuments(COLLECTION_NAME); driver.executeBatch(); - DefaultEntity created = driver.getBatchResponseByRequestId("request1"); + final DefaultEntity created = driver.getBatchResponseByRequestId("request1"); assertThat(created.getStatusCode(), is(201)); - AqlFunctionsEntity functions = driver.getBatchResponseByRequestId("request3"); + final AqlFunctionsEntity functions = driver.getBatchResponseByRequestId("request3"); assertThat(functions.getStatusCode(), is(200)); assertThat(String.valueOf(functions.getAqlFunctions().keySet().toArray()[0]), is("someNamespace::testCode")); for (int i = 0; i < 10; i++) { - DocumentEntity resultComplex = driver.getBatchResponseByRequestId("request" + (4 + i)); + final DocumentEntity resultComplex = driver + .getBatchResponseByRequestId("request" + (4 + i)); assertThat(resultComplex.getStatusCode(), is(202)); } - List documents = driver.getBatchResponseByRequestId("request14"); + final List documents = driver.getBatchResponseByRequestId("request14"); assertThat(documents.size(), is(10)); try { driver.truncateCollection("_aqlfunctions"); - } catch (Exception e) { + } catch (final Exception e) { e.printStackTrace(); } @@ -170,26 +167,26 @@ public void test_execBatchMode_twice() throws ArangoException { BaseEntity res; for (int i = 0; i < 10; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - res = driver.createDocument(colName, value, true, false); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); + res = driver.createDocument(COLLECTION_NAME, value, true, false); assertThat(res.getRequestId(), is("request" + (i + 1))); } driver.executeBatch(); - assertThat(driver.getDocuments(colName).size(), is(10)); + assertThat(driver.getDocuments(COLLECTION_NAME).size(), is(10)); driver.startBatchMode(); for (int i = 20; i < 30; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - res = driver.createDocument(colName, value, true, false); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); + res = driver.createDocument(COLLECTION_NAME, value, true, false); assertThat(res.getRequestId(), is("request" + (i + 1 - 20))); } driver.executeBatch(); - assertThat(driver.getDocuments(colName).size(), is(20)); + assertThat(driver.getDocuments(COLLECTION_NAME).size(), is(20)); } diff --git a/src/test/java/com/arangodb/ArangoDriverCollectionTest.java b/src/test/java/com/arangodb/ArangoDriverCollectionTest.java index 3c6d6f897..f84d816e4 100644 --- a/src/test/java/com/arangodb/ArangoDriverCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCollectionTest.java @@ -52,15 +52,11 @@ */ public class ArangoDriverCollectionTest extends BaseTest { - public ArangoDriverCollectionTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - private static Logger logger = LoggerFactory.getLogger(ArangoDriverCollectionTest.class); - final String collectionName = "unit_test_arango_001"; // 通常ケースで使うコレクション名 - final String collectionName2 = "unit_test_arango_002"; - final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 + private final String collectionName = "unit_test_arango_001"; // 通常ケースで使うコレクション名 + private final String collectionName2 = "unit_test_arango_002"; + private final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 @Before public void before() throws ArangoException { @@ -68,10 +64,10 @@ public void before() throws ArangoException { logger.debug("----------"); // 事前に消しておく - for (String col : new String[] { collectionName, collectionName2, collectionName404 }) { + for (final String col : new String[] { collectionName, collectionName2, collectionName404 }) { try { driver.deleteCollection(col); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @@ -93,7 +89,7 @@ public void after() { public void test_create_document_collection() throws ArangoException { // DocumentCollection - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1, is(notNullValue())); assertThat(res1.getCode(), is(200)); assertThat(res1.getId(), is(notNullValue())); @@ -114,9 +110,9 @@ public void test_create_document_collection() throws ArangoException { @Test // @Parameters public void test_create_edge_collection() throws ArangoException { - CollectionOptions collectionOptions = new CollectionOptions(); + final CollectionOptions collectionOptions = new CollectionOptions(); collectionOptions.setType(CollectionType.EDGE); - CollectionEntity res2 = driver.createCollection(collectionName, collectionOptions); + final CollectionEntity res2 = driver.createCollection(collectionName, collectionOptions); assertThat(res2, is(notNullValue())); assertThat(res2.getCode(), is(200)); assertThat(res2.getId(), is(notNullValue())); @@ -137,9 +133,9 @@ public void test_create_edge_collection() throws ArangoException { @Test public void test_create_inmemory_document_collection() throws ArangoException { - CollectionOptions collectionOptions = new CollectionOptions(); + final CollectionOptions collectionOptions = new CollectionOptions(); collectionOptions.setIsVolatile(true); - CollectionEntity res = driver.createCollection(collectionName, collectionOptions); + final CollectionEntity res = driver.createCollection(collectionName, collectionOptions); assertThat(res, is(notNullValue())); assertThat(res.getCode(), is(200)); assertThat(res.getId(), is(not(0L))); @@ -155,15 +151,15 @@ public void test_create_inmemory_document_collection() throws ArangoException { @Test public void test_create_with_options() throws ArangoException { - CollectionKeyOption keyOptions = new CollectionKeyOption(); + final CollectionKeyOption keyOptions = new CollectionKeyOption(); keyOptions.setType("autoincrement"); keyOptions.setAllowUserKeys(true); keyOptions.setIncrement(10); keyOptions.setOffset(200); - CollectionOptions collectionOptions = new CollectionOptions(); + final CollectionOptions collectionOptions = new CollectionOptions(); collectionOptions.setKeyOptions(keyOptions); - CollectionEntity res = driver.createCollection(collectionName, collectionOptions); + final CollectionEntity res = driver.createCollection(collectionName, collectionOptions); assertThat(res, is(notNullValue())); assertThat(res.getCode(), is(200)); assertThat(res.getId(), is(not(0L))); @@ -179,8 +175,8 @@ public void test_create_with_options() throws ArangoException { assertThat(res.getKeyOptions(), is(nullValue())); // 別のAPIで確認する - CollectionEntity ent = driver.getCollectionProperties(collectionName); - CollectionKeyOption opt = ent.getKeyOptions(); + final CollectionEntity ent = driver.getCollectionProperties(collectionName); + final CollectionKeyOption opt = ent.getKeyOptions(); assertThat(opt.isAllowUserKeys(), is(true)); assertThat(opt.getType(), is("autoincrement")); assertThat(opt.getIncrement(), is(10L)); @@ -192,7 +188,7 @@ public void test_create_with_options() throws ArangoException { public void test_create_no_compact() throws ArangoException { // DocumentCollection - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1, is(notNullValue())); assertThat(res1.getCode(), is(200)); assertThat(res1.getId(), is(notNullValue())); @@ -203,7 +199,7 @@ public void test_create_no_compact() throws ArangoException { assertThat(res1.getStatus(), is(CollectionStatus.LOADED)); assertThat(res1.getType(), is(CollectionType.DOCUMENT)); - CollectionEntity prop = driver.getCollectionProperties(collectionName); + final CollectionEntity prop = driver.getCollectionProperties(collectionName); assertThat(prop.getCode(), is(200)); assertThat(prop.getId(), is(res1.getId())); assertThat(prop.getDoCompact(), is(true)); @@ -218,7 +214,7 @@ public void test_create_no_compact() throws ArangoException { @Test public void test_create_dup() throws ArangoException { - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1, is(notNullValue())); assertThat(res1.getCode(), is(200)); assertThat(res1.getId(), is(not(0L))); @@ -232,7 +228,7 @@ public void test_create_dup() throws ArangoException { try { driver.createCollection(collectionName); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(409)); assertThat(e.getErrorNumber(), is(1207)); } @@ -243,15 +239,15 @@ public void test_create_dup() throws ArangoException { @Test public void test_getCollection_01() throws ArangoException { - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1.getCode(), is(200)); - long collectionId = res1.getId(); + final long collectionId = res1.getId(); // IDで取得 - CollectionEntity entity1 = driver.getCollection(collectionId); + final CollectionEntity entity1 = driver.getCollection(collectionId); // 名前で取得 - CollectionEntity entity2 = driver.getCollection(collectionName); + final CollectionEntity entity2 = driver.getCollection(collectionName); assertThat(entity1.getId(), is(collectionId)); assertThat(entity2.getId(), is(collectionId)); assertThat(entity1.getName(), is(collectionName)); @@ -274,7 +270,7 @@ public void test_getCollection_404() throws ArangoException { try { driver.getCollection(collectionName404); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -284,10 +280,10 @@ public void test_getCollection_404() throws ArangoException { @Test public void test_getCollectionProperties_01() throws ArangoException { - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1.getCode(), is(200)); - CollectionEntity collection = driver.getCollectionProperties(collectionName); + final CollectionEntity collection = driver.getCollectionProperties(collectionName); assertThat(collection.getCode(), is(200)); assertThat(collection.getId(), is(res1.getId())); assertThat(collection.getName(), is(collectionName)); @@ -321,7 +317,7 @@ public void test_getCollectionProperties_404() throws ArangoException { try { driver.getCollectionProperties(collectionName404); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -331,7 +327,7 @@ public void test_getCollectionProperties_404() throws ArangoException { @Test public void test_getCollectionRevision() throws ArangoException { - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1.getCode(), is(200)); // Get Revision @@ -344,7 +340,7 @@ public void test_getCollectionRevision() throws ArangoException { // Get Revision again collection = driver.getCollectionRevision(collectionName); // Check to updated revision - long rev2 = collection.getRevision(); + final long rev2 = collection.getRevision(); assertThat(rev2, is(not(0L))); // Create Document @@ -353,7 +349,7 @@ public void test_getCollectionRevision() throws ArangoException { // Get Revision again collection = driver.getCollectionRevision(collectionName); // Check to updated revision - long rev3 = collection.getRevision(); + final long rev3 = collection.getRevision(); assertThat(rev3, greaterThan(rev2)); } @@ -364,7 +360,7 @@ public void test_getCollectionRevision_404() throws ArangoException { try { driver.getCollectionRevision(collectionName404); fail("Because did not raise Exception."); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -374,7 +370,7 @@ public void test_getCollectionRevision_404() throws ArangoException { @Test public void test_getCollectionCount_01() throws ArangoException { - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1.getCode(), is(200)); CollectionEntity collection = driver.getCollectionCount(collectionName); @@ -388,7 +384,7 @@ public void test_getCollectionCount_01() throws ArangoException { // 100個ほどドキュメントを入れてみる for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "tes user:" + i, 20 + i); + final TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "tes user:" + i, 20 + i); driver.createDocument(collectionName, value, false, true); } @@ -409,7 +405,7 @@ public void test_getCollectionCount_404() throws ArangoException { try { driver.getCollectionCount(collectionName404); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -420,20 +416,21 @@ public void test_getCollectionCount_404() throws ArangoException { public void test_getCollectionFigures_01() throws ArangoException { // コレクションを作る - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1.getCode(), is(200)); // 100個ほどドキュメントを入れてみる for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); - DocumentEntity entity = driver.createDocument(collectionName, value, false, true); + final TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); + final DocumentEntity entity = driver.createDocument(collectionName, value, false, + true); // 1個消す if (i == 50) { driver.deleteDocument(entity.getDocumentHandle(), null, null); } } - CollectionEntity collection = driver.getCollectionFigures(collectionName); + final CollectionEntity collection = driver.getCollectionFigures(collectionName); assertThat(collection.getCode(), is(200)); assertThat(collection.getId(), is(res1.getId())); assertThat(collection.getName(), is(collectionName)); @@ -476,7 +473,7 @@ public void test_getCollectionFigures_404() throws ArangoException { try { driver.getCollectionFigures(collectionName404); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -487,11 +484,11 @@ public void test_getCollectionFigures_404() throws ArangoException { public void test_getCollectionChecksum() throws ArangoException { // create collection. - CollectionEntity res1 = driver.createCollection(collectionName); + final CollectionEntity res1 = driver.createCollection(collectionName); assertThat(res1.getCode(), is(200)); // checksum - CollectionEntity entity = driver.getCollectionChecksum(collectionName, true, true); + final CollectionEntity entity = driver.getCollectionChecksum(collectionName, true, true); assertThat(entity.getCode(), is(200)); assertThat(entity.isError(), is(false)); assertThat(entity.getRevision(), is(0L)); // レスポンスは戻ってきてるんだけど、0なのでどうチェックしたものか・・ @@ -505,16 +502,16 @@ public void test_getCollections() throws ArangoException { for (int i = 0; i < 10; i++) { try { driver.createCollection("unit_test_arango_" + (1000 + i)); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } - CollectionsEntity collections = driver.getCollections(); + final CollectionsEntity collections = driver.getCollections(); assertThat(collections.getCode(), is(200)); - Map map = collections.getNames(); + final Map map = collections.getNames(); for (int i = 0; i < 10; i++) { - String collectionName = "unit_test_arango_" + (1000 + i); - CollectionEntity collection = map.get(collectionName); + final String collectionName = "unit_test_arango_" + (1000 + i); + final CollectionEntity collection = map.get(collectionName); // id, name, status assertThat(collection, is(notNullValue())); assertThat(collection.getId(), is(not(0L))); @@ -522,8 +519,8 @@ public void test_getCollections() throws ArangoException { } // with exluceSystem parameter. - int allColCount = collections.getCollections().size(); - int sysExcludeCount = driver.getCollections(true).getCollections().size(); + final int allColCount = collections.getCollections().size(); + final int sysExcludeCount = driver.getCollections(true).getCollections().size(); assertThat(allColCount > sysExcludeCount, is(true)); } @@ -532,7 +529,7 @@ public void test_getCollections() throws ArangoException { public void test_load_unload() throws ArangoException { // create - CollectionEntity collection = driver.createCollection(collectionName); + final CollectionEntity collection = driver.createCollection(collectionName); assertThat(collection, is(notNullValue())); assertThat(collection.getCode(), is(200)); @@ -547,7 +544,7 @@ public void test_load_unload() throws ArangoException { assertThat(collection1.getStatus(), anyOf(is(CollectionStatus.UNLOADED), is(CollectionStatus.IN_THE_PROCESS_OF_BEING_UNLOADED))); - CollectionEntity collection2 = driver.loadCollection(collectionName); + final CollectionEntity collection2 = driver.loadCollection(collectionName); assertThat(collection2, is(notNullValue())); assertThat(collection2.getCode(), is(200)); assertThat(collection2.getStatus(), is(CollectionStatus.LOADED)); @@ -560,7 +557,7 @@ public void test_load_unload() throws ArangoException { assertThat(collection1.getCount(), is(0L)); // with count parameter - CollectionEntity col3 = driver.loadCollection(collectionName, false); + final CollectionEntity col3 = driver.loadCollection(collectionName, false); assertThat(col3, is(notNullValue())); assertThat(col3.getCode(), is(200)); assertThat(col3.getStatus(), is(CollectionStatus.LOADED)); @@ -574,7 +571,7 @@ public void test_load_404() throws ArangoException { try { driver.loadCollection(collectionName404); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -587,7 +584,7 @@ public void test_unload_404() throws ArangoException { try { driver.unloadCollection(collectionName404); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -597,20 +594,20 @@ public void test_unload_404() throws ArangoException { @Test public void test_truncate() throws ArangoException { - CollectionEntity collection = driver.createCollection(collectionName); + final CollectionEntity collection = driver.createCollection(collectionName); assertThat(collection, is(notNullValue())); assertThat(collection.getCode(), is(200)); // 100個ほどドキュメントを入れてみる for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); + final TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); assertThat(driver.createDocument(collectionName, value, false, true).getStatusCode(), is(201)); } // 100個入ったよね? assertThat(driver.getCollectionCount(collectionName).getCount(), is(100L)); // 抹殺じゃー! - CollectionEntity collection2 = driver.truncateCollection(collectionName); + final CollectionEntity collection2 = driver.truncateCollection(collectionName); assertThat(collection2, is(notNullValue())); assertThat(collection2.getCode(), is(200)); @@ -625,7 +622,7 @@ public void test_truncate_404() throws ArangoException { try { driver.unloadCollection(collectionName404); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -635,7 +632,7 @@ public void test_truncate_404() throws ArangoException { @Test public void test_setCollectionProperties() throws ArangoException { - CollectionEntity collection = driver.createCollection(collectionName); + final CollectionEntity collection = driver.createCollection(collectionName); assertThat(collection, is(notNullValue())); assertThat(collection.getCode(), is(200)); assertThat(collection.getWaitForSync(), is(Boolean.FALSE)); @@ -658,7 +655,7 @@ public void test_setCollectionProperties_404() throws ArangoException { try { driver.setCollectionProperties(collectionName404, true, null); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -669,26 +666,26 @@ public void test_setCollectionProperties_404() throws ArangoException { public void test_delete() throws ArangoException { // コレクションを適当に10個作る - TreeSet collectionNames = new TreeSet(); + final TreeSet collectionNames = new TreeSet(); for (int i = 0; i < 10; i++) { try { - CollectionEntity col = driver.createCollection("unit_test_arango_" + (1000 + i)); - long collectionId = col.getId(); + final CollectionEntity col = driver.createCollection("unit_test_arango_" + (1000 + i)); + final long collectionId = col.getId(); if (i == 5) { // 1個だけ消す - CollectionEntity res = driver.deleteCollection(collectionId); + final CollectionEntity res = driver.deleteCollection(collectionId); assertThat(res.getCode(), is(200)); assertThat(res.getId(), is(collectionId)); } else { collectionNames.add(col.getName()); } - } catch (ArangoException e) { + } catch (final ArangoException e) { } } // 残りの9個は残っていること - Map collections = driver.getCollections().getNames(); - for (String name : collectionNames) { + final Map collections = driver.getCollections().getNames(); + for (final String name : collectionNames) { assertThat(collections.containsKey(name), is(true)); } @@ -700,7 +697,7 @@ public void test_delete_404() throws ArangoException { try { driver.deleteCollection(collectionName404); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -710,13 +707,13 @@ public void test_delete_404() throws ArangoException { @Test public void test_rename_404() throws ArangoException { - CollectionEntity collection = driver.createCollection(collectionName); + final CollectionEntity collection = driver.createCollection(collectionName); assertThat(collection.getCode(), is(200)); try { driver.renameCollection(collectionName404, collectionName); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -731,16 +728,16 @@ public void test_rename_404() throws ArangoException { @Test public void test_rename_dup() throws ArangoException { - CollectionEntity collection1 = driver.createCollection(collectionName); + final CollectionEntity collection1 = driver.createCollection(collectionName); assertThat(collection1.getCode(), is(200)); - CollectionEntity collection2 = driver.createCollection(collectionName2); + final CollectionEntity collection2 = driver.createCollection(collectionName2); assertThat(collection2.getCode(), is(200)); try { driver.renameCollection(collectionName, collectionName2); fail("ここに来てはダメー!"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(409)); assertThat(e.getErrorNumber(), is(1207)); } diff --git a/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java b/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java index 48aba76d4..c5be09c5d 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java @@ -32,24 +32,20 @@ */ public class ArangoDriverCursorResultSetTest extends BaseTest { - public ArangoDriverCursorResultSetTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Before public void setup() throws ArangoException { // Collectionを作る - String collectionName = "unit_test_query_test"; + final String collectionName = "unit_test_query_test"; try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } driver.truncateCollection(collectionName); // テストデータを作る for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); driver.createDocument(collectionName, value, null, null); } @@ -61,15 +57,15 @@ public void test1() throws ArangoException { // String query = "SELECT t FROM unit_test_query_test t WHERE t.age >= // @age@ order by t.age"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); // 全件とれる範囲 - CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, + final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, TestComplexEntity01.class, true, 20); int count = 0; - for (TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -83,14 +79,14 @@ public void test2() throws ArangoException { // String query = "SELECT t FROM unit_test_query_test t WHERE t.age >= // @age@ order by t.age"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, + final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, TestComplexEntity01.class, true, 10); int count = 0; - for (TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -104,14 +100,14 @@ public void test3() throws ArangoException { // String query = "SELECT t FROM unit_test_query_test t WHERE t.age >= // @age@ order by t.age"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, + final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, TestComplexEntity01.class, true, 5); int count = 0; - for (TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -125,14 +121,14 @@ public void test4() throws ArangoException { // String query = "SELECT t FROM unit_test_query_test t WHERE t.age >= // @age@ order by t.age"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, + final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, TestComplexEntity01.class, true, 3); int count = 0; - for (TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -146,14 +142,14 @@ public void test5() throws ArangoException { // String query = "SELECT t FROM unit_test_query_test t WHERE t.age >= // @age@ order by t.age"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, + final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, TestComplexEntity01.class, true, 1); int count = 0; - for (TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -172,15 +168,15 @@ public void test6() throws ArangoException { // String query = "SELECT t FROM unit_test_query_test t WHERE t.age >= // @age@ order by t.age"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, + final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, TestComplexEntity01.class, true, 2); int count = 0; while (rs.hasNext()) { - TestComplexEntity01 obj = rs.next(); + final TestComplexEntity01 obj = rs.next(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -200,15 +196,15 @@ public void test7() throws ArangoException { // String query = "SELECT t FROM unit_test_query_test t WHERE t.age >= // @age@ order by t.age"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, + final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, TestComplexEntity01.class, true, 2); int count = 0; while (rs.hasNext()) { - TestComplexEntity01 obj = rs.next(); + final TestComplexEntity01 obj = rs.next(); assertThat(obj.getAge(), is(90 + count)); count++; if (count == 5) { diff --git a/src/test/java/com/arangodb/ArangoDriverCursorTest.java b/src/test/java/com/arangodb/ArangoDriverCursorTest.java index 43f6de530..1e0a1b499 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorTest.java @@ -39,14 +39,10 @@ */ public class ArangoDriverCursorTest extends BaseTest { - public ArangoDriverCursorTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Test public void test_validateQuery() throws ArangoException { - CursorEntity entity = driver.validateQuery( + final CursorEntity entity = driver.validateQuery( // "SELECT t FROM unit_test_cursor t WHERE t.name == @name@ && t.age // >= @age@" "FOR t IN unit_test_cursor FILTER t.name == @name && t.age >= @age RETURN t"); @@ -67,7 +63,7 @@ public void test_validateQuery_400_1() throws ArangoException { // "SELECT t FROM unit_test_cursor t WHERE t.name = @name@" "FOR t IN unit_test_cursor FILTER t.name = @name@"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(400)); assertThat(e.getErrorNumber(), is(1501)); } @@ -84,27 +80,27 @@ public void test_validateQuery_400_2() throws ArangoException { public void test_executeQuery() throws ArangoException { // Collectionを作る - String collectionName = "unit_test_query_test"; + final String collectionName = "unit_test_query_test"; try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } driver.truncateCollection(collectionName); // テストデータを作る for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); driver.createDocument(collectionName, value, null, null); } // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); // 全件とれる範囲 { - CursorEntity result = driver. executeQuery(query, bindVars, + final CursorEntity result = driver. executeQuery(query, bindVars, TestComplexEntity01.class, true, 20); assertThat(result.size(), is(10)); assertThat(result.getCount(), is(10)); @@ -118,29 +114,29 @@ public void test_executeQuery() throws ArangoException { public void test_executeQuery_2() throws ArangoException { // Collectionを作る - String collectionName = "unit_test_query_test"; + final String collectionName = "unit_test_query_test"; try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } driver.truncateCollection(collectionName); // テストデータを作る for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); driver.createDocument(collectionName, value, null, null); } // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); // ちまちまとる範囲 long cursorId; { - CursorEntity result = driver.executeQuery(query, bindVars, TestComplexEntity01.class, - true, 3); + final CursorEntity result = driver.executeQuery(query, bindVars, + TestComplexEntity01.class, true, 3); assertThat(result.size(), is(3)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(true)); @@ -152,7 +148,7 @@ public void test_executeQuery_2() throws ArangoException { // 次のRoundTrip { - CursorEntity result = driver.continueQuery(cursorId, TestComplexEntity01.class); + final CursorEntity result = driver.continueQuery(cursorId, TestComplexEntity01.class); assertThat(result.size(), is(3)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(true)); @@ -160,7 +156,7 @@ public void test_executeQuery_2() throws ArangoException { // 次のRoundTrip { - CursorEntity result = driver.continueQuery(cursorId, TestComplexEntity01.class); + final CursorEntity result = driver.continueQuery(cursorId, TestComplexEntity01.class); assertThat(result.size(), is(3)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(true)); @@ -168,7 +164,7 @@ public void test_executeQuery_2() throws ArangoException { // 次のRoundTrip { - CursorEntity result = driver.continueQuery(cursorId, TestComplexEntity01.class); + final CursorEntity result = driver.continueQuery(cursorId, TestComplexEntity01.class); assertThat(result.size(), is(1)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(false)); @@ -186,27 +182,27 @@ public void test_executeQuery_2() throws ArangoException { public void test_executeQueryFullCount() throws ArangoException { // Collectionを作る - String collectionName = "unit_test_query_test"; + final String collectionName = "unit_test_query_test"; try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } driver.truncateCollection(collectionName); // テストデータを作る for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); driver.createDocument(collectionName, value, null, null); } // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age LIMIT 2 RETURN t"; - Map bindVars = new MapBuilder().put("age", 10).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age LIMIT 2 RETURN t"; + final Map bindVars = new MapBuilder().put("age", 10).get(); // 全件とれる範囲 { - CursorEntity result = driver. executeQuery(query, bindVars, + final CursorEntity result = driver. executeQuery(query, bindVars, TestComplexEntity01.class, true, 1, true); assertThat(result.size(), is(1)); assertThat(result.getCount(), is(2)); @@ -221,34 +217,34 @@ public void test_executeQueryFullCount() throws ArangoException { public void test_executeQueryUniqueResult() throws ArangoException { // Collectionを作る - String collectionName = "unit_test_query_test"; + final String collectionName = "unit_test_query_test"; try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } driver.truncateCollection(collectionName); // テストデータを作る for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); driver.createDocument(collectionName, value, null, null); } // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; String query = "FOR t IN unit_test_query_test FILTER t.age >= @age LIMIT 2 RETURN t"; - Map bindVars = new MapBuilder().put("age", 10).get(); + final Map bindVars = new MapBuilder().put("age", 10).get(); // 全件とれる範囲 { - CursorEntity result = driver. executeQuery(query, bindVars, + final CursorEntity result = driver. executeQuery(query, bindVars, TestComplexEntity01.class, true, 2); assertThat(result.size(), is(2)); assertThat(result.getCount(), is(2)); String msg = ""; try { result.getUniqueResult(); - } catch (NonUniqueResultException e) { + } catch (final NonUniqueResultException e) { msg = e.getMessage(); } assertThat(msg, startsWith("Query did not return a unique result:")); @@ -258,30 +254,30 @@ public void test_executeQueryUniqueResult() throws ArangoException { // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; query = "FOR t IN unit_test_query_test FILTER t.age == @age LIMIT 2 RETURN t"; { - CursorEntity result = driver. executeQuery(query, bindVars, + final CursorEntity result = driver. executeQuery(query, bindVars, TestComplexEntity01.class, true, 2); assertThat(result.size(), is(1)); assertThat(result.getCount(), is(1)); - TestComplexEntity01 entity = result.getUniqueResult(); + final TestComplexEntity01 entity = result.getUniqueResult(); assertThat(entity.getAge(), is(10)); } } @Test public void test_warning() throws ArangoException { - String collectionName = "unit_test_query_test"; + final String collectionName = "unit_test_query_test"; try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } driver.truncateCollection(collectionName); - String query = "return _users + 1"; - Map bindVars = new HashMap(); - CursorResult cursor = driver.executeAqlQuery(query, bindVars, null, Long.class); + final String query = "return _users + 1"; + final Map bindVars = new HashMap(); + final CursorResult cursor = driver.executeAqlQuery(query, bindVars, null, Long.class); assertThat(cursor.hasWarning(), is(true)); - List warnings = cursor.getWarnings(); + final List warnings = cursor.getWarnings(); assertThat(warnings.size(), is(1)); } diff --git a/src/test/java/com/arangodb/ArangoDriverDatabaseTest.java b/src/test/java/com/arangodb/ArangoDriverDatabaseTest.java index 1ad1e4b21..047d0a10e 100644 --- a/src/test/java/com/arangodb/ArangoDriverDatabaseTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDatabaseTest.java @@ -25,7 +25,6 @@ import java.util.Collections; import org.junit.AfterClass; -import org.junit.Before; import org.junit.Test; import com.arangodb.entity.BooleanResultEntity; @@ -46,15 +45,6 @@ public class ArangoDriverDatabaseTest extends BaseTest { "unitTestDatabase", // other test case }; - public ArangoDriverDatabaseTest(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - - @Before - public void before() { - - } - @AfterClass public static void _afterClass() { try { diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentCursorEntityTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentCursorEntityTest.java index 0329f71f3..6b5a218d9 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentCursorEntityTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentCursorEntityTest.java @@ -39,10 +39,6 @@ */ public class ArangoDriverDocumentCursorEntityTest extends BaseTest { - public ArangoDriverDocumentCursorEntityTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - private static final String COLLECTION_NAME = "unit_test_query_test"; @Before @@ -51,13 +47,13 @@ public void before() throws ArangoException { // create test collection try { driver.createCollection(COLLECTION_NAME); - } catch (ArangoException e) { + } catch (final ArangoException e) { } driver.truncateCollection(COLLECTION_NAME); // create some test data for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); driver.createDocument(COLLECTION_NAME, value, null, null); } @@ -65,7 +61,7 @@ public void before() throws ArangoException { @Test public void test_validateQuery() throws ArangoException { - CursorEntity entity = driver + final CursorEntity entity = driver .validateQuery("FOR t IN unit_test_cursor FILTER t.name == @name && t.age >= @age RETURN t"); assertThat(entity.getCode(), is(200)); @@ -81,7 +77,7 @@ public void test_validateQuery_400_1() throws ArangoException { try { driver.validateQuery("FOR t IN unit_test_cursor FILTER t.name = @name@"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(400)); assertThat(e.getErrorNumber(), is(1501)); } @@ -92,12 +88,12 @@ public void test_validateQuery_400_1() throws ArangoException { public void test_executeQuery() throws ArangoException { // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); // 全件とれる範囲 { - CursorEntity result = driver.executeCursorEntityQuery(query, bindVars, true, 20, false, + final CursorEntity result = driver.executeCursorEntityQuery(query, bindVars, true, 20, false, TestComplexEntity01.class); assertThat(result.size(), is(10)); assertThat(result.getCount(), is(10)); @@ -110,13 +106,13 @@ public void test_executeQuery() throws ArangoException { public void test_executeQuery_2() throws ArangoException { // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); // ちまちまとる範囲 long cursorId; { - CursorEntity result = driver.executeCursorEntityQuery(query, bindVars, true, 3, false, + final CursorEntity result = driver.executeCursorEntityQuery(query, bindVars, true, 3, false, DocumentEntity.class, TestComplexEntity01.class); assertThat(result.size(), is(3)); assertThat(result.getCount(), is(10)); @@ -129,7 +125,8 @@ public void test_executeQuery_2() throws ArangoException { // 次のRoundTrip { - CursorEntity result = driver.continueQuery(cursorId, DocumentEntity.class, TestComplexEntity01.class); + final CursorEntity result = driver.continueQuery(cursorId, DocumentEntity.class, + TestComplexEntity01.class); assertThat(result.size(), is(3)); assertThat(result.getCount(), is(10)); @@ -138,7 +135,8 @@ public void test_executeQuery_2() throws ArangoException { // 次のRoundTrip { - CursorEntity result = driver.continueQuery(cursorId, DocumentEntity.class, TestComplexEntity01.class); + final CursorEntity result = driver.continueQuery(cursorId, DocumentEntity.class, + TestComplexEntity01.class); assertThat(result.size(), is(3)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(true)); @@ -146,7 +144,8 @@ public void test_executeQuery_2() throws ArangoException { // 次のRoundTrip { - CursorEntity result = driver.continueQuery(cursorId, DocumentEntity.class, TestComplexEntity01.class); + final CursorEntity result = driver.continueQuery(cursorId, DocumentEntity.class, + TestComplexEntity01.class); assertThat(result.size(), is(1)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(false)); @@ -163,12 +162,12 @@ public void test_executeQuery_2() throws ArangoException { public void test_executeQueryFullCount() throws ArangoException { // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age LIMIT 2 RETURN t"; - Map bindVars = new MapBuilder().put("age", 10).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age LIMIT 2 RETURN t"; + final Map bindVars = new MapBuilder().put("age", 10).get(); // 全件とれる範囲 { - CursorEntity result = driver.executeCursorEntityQuery(query, bindVars, true, 1, true, + final CursorEntity result = driver.executeCursorEntityQuery(query, bindVars, true, 1, true, DocumentEntity.class, TestComplexEntity01.class); assertThat(result.size(), is(1)); assertThat(result.getCount(), is(2)); @@ -184,18 +183,18 @@ public void test_executeQueryUniqueResult() throws ArangoException { // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; String query = "FOR t IN unit_test_query_test FILTER t.age >= @age LIMIT 2 RETURN t"; - Map bindVars = new MapBuilder().put("age", 10).get(); + final Map bindVars = new MapBuilder().put("age", 10).get(); // 全件とれる範囲 { - CursorEntity result = driver.executeCursorEntityQuery(query, bindVars, true, 2, false, + final CursorEntity result = driver.executeCursorEntityQuery(query, bindVars, true, 2, false, DocumentEntity.class, TestComplexEntity01.class); assertThat(result.size(), is(2)); assertThat(result.getCount(), is(2)); String msg = ""; try { result.getUniqueResult(); - } catch (NonUniqueResultException e) { + } catch (final NonUniqueResultException e) { msg = e.getMessage(); } assertThat(msg, startsWith("Query did not return a unique result:")); @@ -205,11 +204,11 @@ public void test_executeQueryUniqueResult() throws ArangoException { // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; query = "FOR t IN unit_test_query_test FILTER t.age == @age LIMIT 2 RETURN t"; { - CursorEntity> result = driver.executeCursorEntityQuery(query, bindVars, - true, 2, false, DocumentEntity.class, TestComplexEntity01.class); + final CursorEntity> result = driver.executeCursorEntityQuery(query, + bindVars, true, 2, false, DocumentEntity.class, TestComplexEntity01.class); assertThat(result.size(), is(1)); assertThat(result.getCount(), is(1)); - DocumentEntity uniqueResult = result.getUniqueResult(); + final DocumentEntity uniqueResult = result.getUniqueResult(); assertThat(uniqueResult.getEntity().getAge(), is(10)); } } diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java index 56e50694f..2918e6e16 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java @@ -43,10 +43,6 @@ public class ArangoDriverDocumentCursorTest extends BaseTest { private static Logger logger = LoggerFactory.getLogger(ArangoDriverDocumentCursorTest.class); - public ArangoDriverDocumentCursorTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - private static final String COLLECTION_NAME = "unit_test_query_test"; @Before @@ -55,19 +51,19 @@ public void setup() throws ArangoException { // create test collection try { driver.createCollection(COLLECTION_NAME); - } catch (ArangoException e) { + } catch (final ArangoException e) { } driver.truncateCollection(COLLECTION_NAME); // create some test data for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); driver.createDocument(COLLECTION_NAME, value, null, null); } } - private AqlQueryOptions getAqlQueryOptions(Boolean count, Integer batchSize, Boolean fullCount) { + private AqlQueryOptions getAqlQueryOptions(final Boolean count, final Integer batchSize, final Boolean fullCount) { return new AqlQueryOptions().setCount(count).setBatchSize(batchSize).setFullCount(fullCount); } @@ -77,19 +73,19 @@ public void test1_WithIterator() throws ArangoException { // String query = // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@ order by // t.age"; - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); // 全件とれる範囲 - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 20, null), TestComplexEntity01.class); int count = 0; - Iterator> iterator = rs.iterator(); + final Iterator> iterator = rs.iterator(); while (iterator.hasNext()) { - DocumentEntity next = iterator.next(); - TestComplexEntity01 obj = next.getEntity(); + final DocumentEntity next = iterator.next(); + final TestComplexEntity01 obj = next.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -99,15 +95,15 @@ public void test1_WithIterator() throws ArangoException { @Test public void test1_WithList() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 20, null), TestComplexEntity01.class); int count = 0; - for (DocumentEntity documentEntity : rs.asList()) { - TestComplexEntity01 obj = documentEntity.getEntity(); + for (final DocumentEntity documentEntity : rs.asList()) { + final TestComplexEntity01 obj = documentEntity.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -118,15 +114,15 @@ public void test1_WithList() throws ArangoException { @Test public void test2_BatchSize10() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 10, null), TestComplexEntity01.class); int count = 0; - for (DocumentEntity documentEntity : rs.asList()) { - TestComplexEntity01 obj = documentEntity.getEntity(); + for (final DocumentEntity documentEntity : rs.asList()) { + final TestComplexEntity01 obj = documentEntity.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -137,15 +133,15 @@ public void test2_BatchSize10() throws ArangoException { @Test public void test3_BatchSize5() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 5, null), TestComplexEntity01.class); int count = 0; - for (DocumentEntity documentEntity : rs.asList()) { - TestComplexEntity01 obj = documentEntity.getEntity(); + for (final DocumentEntity documentEntity : rs.asList()) { + final TestComplexEntity01 obj = documentEntity.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -157,15 +153,15 @@ public void test3_BatchSize5() throws ArangoException { public void test_withCache() throws ArangoException { if (isMinimumVersion(TestUtils.VERSION_2_7)) { // start caching - QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity(); + final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity(); properties.setMode("on"); driver.setQueryCacheProperties(properties); - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); // set caching to true for the query - AqlQueryOptions aqlQueryOptions = getAqlQueryOptions(true, 5, null); + final AqlQueryOptions aqlQueryOptions = getAqlQueryOptions(true, 5, null); aqlQueryOptions.setCache(true); // query @@ -181,18 +177,18 @@ public void test_withCache() throws ArangoException { @Test public void test4_withIterator() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 3, null), TestComplexEntity01.class); int count = 0; - Iterator> iterator = rs.iterator(); + final Iterator> iterator = rs.iterator(); while (iterator.hasNext()) { - DocumentEntity next = iterator.next(); - TestComplexEntity01 obj = next.getEntity(); + final DocumentEntity next = iterator.next(); + final TestComplexEntity01 obj = next.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -203,15 +199,15 @@ public void test4_withIterator() throws ArangoException { @Test public void test4_withList() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 3, null), TestComplexEntity01.class); int count = 0; - for (DocumentEntity documentEntity : rs.asList()) { - TestComplexEntity01 obj = documentEntity.getEntity(); + for (final DocumentEntity documentEntity : rs.asList()) { + final TestComplexEntity01 obj = documentEntity.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -222,15 +218,15 @@ public void test4_withList() throws ArangoException { @Test public void test5_BatchSize1_asList() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 1, null), TestComplexEntity01.class); int count = 0; - for (DocumentEntity documentEntity : rs.asList()) { - TestComplexEntity01 obj = documentEntity.getEntity(); + for (final DocumentEntity documentEntity : rs.asList()) { + final TestComplexEntity01 obj = documentEntity.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -241,19 +237,19 @@ public void test5_BatchSize1_asList() throws ArangoException { @Test public void test6_getCount() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); // get only two results but calculate the total number of results - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 2, null), TestComplexEntity01.class); // test total number of results assertThat(rs.getCount(), is(10)); int count = 0; - for (DocumentEntity documentEntity : rs.asList()) { - TestComplexEntity01 obj = documentEntity.getEntity(); + for (final DocumentEntity documentEntity : rs.asList()) { + final TestComplexEntity01 obj = documentEntity.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -265,18 +261,18 @@ public void test6_getCount() throws ArangoException { @Test public void test7_closeCursor() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 2, null), TestComplexEntity01.class); int count = 0; - Iterator> iterator = rs.iterator(); + final Iterator> iterator = rs.iterator(); while (iterator.hasNext()) { - DocumentEntity next = iterator.next(); - TestComplexEntity01 obj = next.getEntity(); + final DocumentEntity next = iterator.next(); + final TestComplexEntity01 obj = next.getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; if (count == 5) { @@ -291,17 +287,17 @@ public void test7_closeCursor() throws ArangoException { @Test public void test7_EntityCursor() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); - DocumentCursor documentCursor = driver.executeDocumentQuery(query, bindVars, + final DocumentCursor documentCursor = driver.executeDocumentQuery(query, bindVars, getAqlQueryOptions(true, 1, null), TestComplexEntity01.class); - Iterator entityIterator = documentCursor.entityIterator(); + final Iterator entityIterator = documentCursor.entityIterator(); int count = 0; while (entityIterator.hasNext()) { - TestComplexEntity01 obj = entityIterator.next(); + final TestComplexEntity01 obj = entityIterator.next(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -312,20 +308,20 @@ public void test7_EntityCursor() throws ArangoException { @Test public void test8_CursorResult_as_Map() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); @SuppressWarnings("rawtypes") - CursorResult cursor = driver.executeAqlQuery(query, bindVars, getAqlQueryOptions(true, 1, false), + final CursorResult cursor = driver.executeAqlQuery(query, bindVars, getAqlQueryOptions(true, 1, false), Map.class); @SuppressWarnings("rawtypes") - Iterator iterator = cursor.iterator(); + final Iterator iterator = cursor.iterator(); int count = 0; while (iterator.hasNext()) { - Map obj = iterator.next(); - Double i = (Double) obj.get("age"); + final Map obj = iterator.next(); + final Double i = (Double) obj.get("age"); assertThat(i, is(90.0 + count)); count++; } @@ -336,24 +332,24 @@ public void test8_CursorResult_as_Map() throws ArangoException { @Test public void test8_CursorResult_as_List() throws ArangoException { - String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN [t._key, t.user]"; - Map bindVars = new MapBuilder().put("age", 90).get(); + final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN [t._key, t.user]"; + final Map bindVars = new MapBuilder().put("age", 90).get(); @SuppressWarnings("rawtypes") - CursorResult cursor = driver.executeAqlQuery(query, bindVars, getAqlQueryOptions(true, 1, false), + final CursorResult cursor = driver.executeAqlQuery(query, bindVars, getAqlQueryOptions(true, 1, false), List.class); @SuppressWarnings("rawtypes") - Iterator iterator = cursor.iterator(); + final Iterator iterator = cursor.iterator(); int count = 0; while (iterator.hasNext()) { - List list = iterator.next(); - String user = "user_" + count; - String get1 = list.get(1).toString(); + final List list = iterator.next(); + final String user = "user_" + count; + final String get1 = list.get(1).toString(); assertThat(get1, is(user)); - for (Object obj : list) { + for (final Object obj : list) { logger.debug("value " + obj); } count++; diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java index 4efd176d6..515ff3263 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java @@ -46,19 +46,15 @@ */ public class ArangoDriverDocumentTest extends BaseTest { - public ArangoDriverDocumentTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - private static Logger logger = LoggerFactory.getLogger(ArangoDriverCollectionTest.class); - final String collectionName = "unit_test_arango_001"; // 通常ケースで使うコレクション名 - final String collectionName2 = "unit_test_arango_002"; - final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 + private final String collectionName = "unit_test_arango_001"; // 通常ケースで使うコレクション名 + private final String collectionName2 = "unit_test_arango_002"; + private final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 - CollectionEntity col1; - CollectionEntity col2; - TestInterfaceInstanceCreator testInstanceCreator; + private CollectionEntity col1; + private CollectionEntity col2; + private TestInterfaceInstanceCreator testInstanceCreator; @Before public void before() throws ArangoException { @@ -66,10 +62,10 @@ public void before() throws ArangoException { logger.debug("----------"); // 事前に消しておく - for (String col : new String[] { collectionName, collectionName2, collectionName404 }) { + for (final String col : new String[] { collectionName, collectionName2, collectionName404 }) { try { driver.deleteCollection(col); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @@ -98,8 +94,8 @@ public void after() { public void test_create_normal() throws ArangoException { // 適当にドキュメントを作る - TestComplexEntity01 value = new TestComplexEntity01("user-" + 9999, "説明:" + 9999, 9999); - DocumentEntity doc = driver.createDocument(collectionName, value, null, false); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + 9999, "説明:" + 9999, 9999); + final DocumentEntity doc = driver.createDocument(collectionName, value, null, false); assertThat(doc.getDocumentKey(), is(notNullValue())); assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); @@ -112,8 +108,8 @@ public void test_create_normal() throws ArangoException { public void test_create_normal_with_document_attributes() throws ArangoException { // 適当にドキュメントを作る - TestComplexEntity03 value = new TestComplexEntity03("user-" + 9999, "説明:" + 9999, 9999); - DocumentEntity doc = driver.createDocument(collectionName, value, null, false); + final TestComplexEntity03 value = new TestComplexEntity03("user-" + 9999, "説明:" + 9999, 9999); + final DocumentEntity doc = driver.createDocument(collectionName, value, null, false); assertThat(doc.getDocumentKey(), is(notNullValue())); assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); @@ -130,7 +126,7 @@ public void test_create_normal100() throws ArangoException { // 適当にドキュメントを作る for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "説明:" + i, i); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "説明:" + i, i); driver.createDocument(collectionName, value, null, false); } @@ -143,7 +139,7 @@ public void test_create_normal100() throws ArangoException { public void test_create_sameobject() throws ArangoException { // 適当にドキュメントを作る for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user", "説明:", 10); + final TestComplexEntity01 value = new TestComplexEntity01("user", "説明:", 10); driver.createDocument(collectionName, value, null, true); } // 100個格納できていることを確認する @@ -157,11 +153,11 @@ public void test_create_sameobject() throws ArangoException { */ @Test public void test_create_404() throws ArangoException { - TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); + final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); try { driver.createDocument(collectionName404, value, false, true); fail("no exception was thrown"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -178,14 +174,14 @@ public void test_create_404_insert() throws ArangoException { try { driver.createCollection(collectionName404); - } catch (ArangoException e) { + } catch (final ArangoException e) { } - TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); + final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // 存在しないコレクションに追加しようとする - DocumentEntity res = driver.createDocument(collectionName404, value, true, true); + final DocumentEntity res = driver.createDocument(collectionName404, value, true, true); assertThat(res, is(notNullValue())); - CollectionEntity col3 = driver.getCollection(collectionName404); + final CollectionEntity col3 = driver.getCollection(collectionName404); assertThat(col3, is(notNullValue())); assertThat(res.getDocumentHandle().startsWith(collectionName404 + "/"), is(true)); @@ -197,30 +193,30 @@ public void test_create_404_insert() throws ArangoException { @Test public void test_replace() throws ArangoException { - TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); + final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // Create Document - DocumentEntity doc = driver.createDocument(collectionName, value, true, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, true, false); assertThat(doc, is(notNullValue())); value.setUser(null); value.setDesc("UpdatedDescription"); value.setAge(15); - String id = doc.getDocumentHandle(); - String key = doc.getDocumentKey(); - Long rev = doc.getDocumentRevision(); + final String id = doc.getDocumentHandle(); + final String key = doc.getDocumentKey(); + final Long rev = doc.getDocumentRevision(); - DocumentEntity doc2 = driver.replaceDocument(doc.getDocumentHandle(), value, null, null, - null); + final DocumentEntity doc2 = driver.replaceDocument(doc.getDocumentHandle(), value, null, + null, null); assertThat(doc2.getDocumentHandle(), is(id)); assertThat(doc2.getDocumentKey(), is(key)); assertThat(doc2.getDocumentRevision(), is(not(rev))); - Long rev2 = doc2.getDocumentRevision(); + final Long rev2 = doc2.getDocumentRevision(); assertThat(doc2.getStatusCode(), is(202)); // Get - DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), + final DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), TestComplexEntity01.class); assertThat(doc3.getStatusCode(), is(200)); assertThat(doc3.getEntity(), is(notNullValue())); @@ -237,31 +233,31 @@ public void test_replace() throws ArangoException { @Test public void test_replace_with_document_attributes() throws ArangoException { - TestComplexEntity03 value = new TestComplexEntity03("test-user", "test user", 22); + final TestComplexEntity03 value = new TestComplexEntity03("test-user", "test user", 22); // Create Document - DocumentEntity doc = driver.createDocument(collectionName, value, true, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, true, false); assertThat(doc, is(notNullValue())); value.setUser(null); value.setDesc("UpdatedDescription"); value.setAge(15); - String id = doc.getDocumentHandle(); - String key = doc.getDocumentKey(); - Long rev = doc.getDocumentRevision(); + final String id = doc.getDocumentHandle(); + final String key = doc.getDocumentKey(); + final Long rev = doc.getDocumentRevision(); - DocumentEntity doc2 = driver.replaceDocument(doc.getDocumentHandle(), value, null, null, - null); + final DocumentEntity doc2 = driver.replaceDocument(doc.getDocumentHandle(), value, null, + null, null); TestComplexEntity03 ent = doc2.getEntity(); assertThat(ent.getDocumentHandle(), is(id)); assertThat(ent.getDocumentKey(), is(key)); assertThat(ent.getDocumentRevision(), is(not(rev))); - Long rev2 = ent.getDocumentRevision(); + final Long rev2 = ent.getDocumentRevision(); assertThat(doc2.getStatusCode(), is(202)); // Get - DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), + final DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), TestComplexEntity03.class); ent = doc3.getEntity(); @@ -281,12 +277,12 @@ public void test_replace_with_document_attributes() throws ArangoException { @Test public void test_replace_404() throws ArangoException { - TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); + final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // 存在しないコレクションに追加しようとする try { driver.replaceDocument(collectionName404, 1, value, null, null, null); fail("no exception was thrown"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -294,12 +290,12 @@ public void test_replace_404() throws ArangoException { @Test public void test_replace_404_2() throws ArangoException { - TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); + final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // 存在するコレクションだが、ドキュメントが存在しない try { driver.replaceDocument(collectionName, 1, value, null, null, null); fail("no exception was thrown"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1202)); } @@ -307,31 +303,31 @@ public void test_replace_404_2() throws ArangoException { @Test public void test_partial_update() throws ArangoException { - TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); + final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // Create Document - DocumentEntity doc = driver.createDocument(collectionName, value, true, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, true, false); assertThat(doc, is(notNullValue())); // PartialUpdate value.setUser(null); value.setDesc("UpdatedDescription"); value.setAge(15); - DocumentEntity doc2 = driver.updateDocument(doc.getDocumentHandle(), value, null, null, - null, null); + final DocumentEntity doc2 = driver.updateDocument(doc.getDocumentHandle(), value, null, + null, null, null); assertThat(doc2.getStatusCode(), is(202)); // Get - DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), + final DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), TestComplexEntity01.class); assertThat(doc3.getStatusCode(), is(200)); assertThat(doc3.getEntity(), is(notNullValue())); assertThat(doc3.getEntity().getUser(), is("test-user")); // not update assertThat(doc3.getEntity().getDesc(), is("UpdatedDescription")); assertThat(doc3.getEntity().getAge(), is(15)); - DocumentEntity doc4 = driver.updateDocument(doc.getDocumentHandle(), value, null, null, - null, false); + final DocumentEntity doc4 = driver.updateDocument(doc.getDocumentHandle(), value, null, + null, null, false); assertThat(doc4.getStatusCode(), is(202)); - DocumentEntity doc5 = driver.getDocument(doc2.getDocumentHandle(), + final DocumentEntity doc5 = driver.getDocument(doc2.getDocumentHandle(), TestComplexEntity01.class); assertThat(doc5.getStatusCode(), is(200)); assertThat(doc5.getEntity(), is(notNullValue())); @@ -342,28 +338,28 @@ public void test_partial_update() throws ArangoException { @Test public void test_partial_update_with_document_attributes() throws ArangoException { - TestComplexEntity03 value = new TestComplexEntity03("test-user", "test user", 22); + final TestComplexEntity03 value = new TestComplexEntity03("test-user", "test user", 22); // Create Document - DocumentEntity doc = driver.createDocument(collectionName, value, true, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, true, false); assertThat(doc, is(notNullValue())); // PartialUpdate value.setUser(null); value.setDesc("UpdatedDescription"); value.setAge(15); - DocumentEntity doc2 = driver.updateDocument(doc.getDocumentHandle(), value, null, null, - null, null); + final DocumentEntity doc2 = driver.updateDocument(doc.getDocumentHandle(), value, null, + null, null, null); assertThat(doc2.getStatusCode(), is(202)); - TestComplexEntity03 en1 = doc2.getEntity(); + final TestComplexEntity03 en1 = doc2.getEntity(); assertThat(en1.getDocumentHandle(), is(notNullValue())); assertThat(en1.getDocumentKey(), is(notNullValue())); - Long rev1 = en1.getDocumentRevision(); + final Long rev1 = en1.getDocumentRevision(); assertThat(rev1, is(notNullValue())); // Get - DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), + final DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), TestComplexEntity03.class); assertThat(doc3.getStatusCode(), is(200)); assertThat(doc3.getEntity(), is(notNullValue())); @@ -372,10 +368,10 @@ public void test_partial_update_with_document_attributes() throws ArangoExceptio assertThat(doc3.getEntity().getAge(), is(15)); assertThat(doc3.getDocumentRevision(), is(rev1)); - DocumentEntity doc4 = driver.updateDocument(doc.getDocumentHandle(), value, null, null, - null, false); + final DocumentEntity doc4 = driver.updateDocument(doc.getDocumentHandle(), value, null, + null, null, false); assertThat(doc4.getStatusCode(), is(202)); - DocumentEntity doc5 = driver.getDocument(doc2.getDocumentHandle(), + final DocumentEntity doc5 = driver.getDocument(doc2.getDocumentHandle(), TestComplexEntity03.class); assertThat(doc5.getStatusCode(), is(200)); assertThat(doc5.getEntity(), is(notNullValue())); @@ -387,21 +383,22 @@ public void test_partial_update_with_document_attributes() throws ArangoExceptio @Test public void test_getDocuments() throws ArangoException { // create document - DocumentEntity doc1 = driver.createDocument(collectionName, + final DocumentEntity doc1 = driver.createDocument(collectionName, new TestComplexEntity01("test-user1", "test-user1-desc", 21), true, false); - DocumentEntity doc2 = driver.createDocument(collectionName, + final DocumentEntity doc2 = driver.createDocument(collectionName, new TestComplexEntity01("test-user2", "test-user2-desc", 22), true, false); - DocumentEntity doc3 = driver.createDocument(collectionName, + final DocumentEntity doc3 = driver.createDocument(collectionName, new TestComplexEntity01("test-user3", "test-user3-desc", 23), true, false); assertThat(doc1, is(notNullValue())); assertThat(doc2, is(notNullValue())); assertThat(doc3, is(notNullValue())); // get documents - List documents = driver.getDocuments(collectionName); + final List documents = driver.getDocuments(collectionName); assertEquals(3, documents.size()); - List list = Arrays.asList(doc1.getDocumentHandle(), doc2.getDocumentHandle(), doc3.getDocumentHandle()); + final List list = Arrays.asList(doc1.getDocumentHandle(), doc2.getDocumentHandle(), + doc3.getDocumentHandle()); assertTrue(documents.containsAll(list)); } @@ -410,34 +407,35 @@ public void test_getDocuments() throws ArangoException { public void test_getDocuments_handle() throws ArangoException { // create document - DocumentEntity doc1 = driver.createDocument(collectionName, + final DocumentEntity doc1 = driver.createDocument(collectionName, new TestComplexEntity01("test-user1", "test-user1-desc", 21), true, false); - DocumentEntity doc2 = driver.createDocument(collectionName, + final DocumentEntity doc2 = driver.createDocument(collectionName, new TestComplexEntity01("test-user2", "test-user2-desc", 22), true, false); - DocumentEntity doc3 = driver.createDocument(collectionName, + final DocumentEntity doc3 = driver.createDocument(collectionName, new TestComplexEntity01("test-user3", "test-user3-desc", 23), true, false); assertThat(doc1, is(notNullValue())); assertThat(doc2, is(notNullValue())); assertThat(doc3, is(notNullValue())); // get documents - List documents = driver.getDocuments(collectionName); + final List documents = driver.getDocuments(collectionName); assertEquals(3, documents.size()); - List list = Arrays.asList(doc1.getDocumentHandle(), doc2.getDocumentHandle(), doc3.getDocumentHandle()); + final List list = Arrays.asList(doc1.getDocumentHandle(), doc2.getDocumentHandle(), + doc3.getDocumentHandle()); assertTrue(documents.containsAll(list)); } @Test public void test_get_document() throws ArangoException { - TestComplexEntity01 value = new TestComplexEntity01("user-" + 9999, "説明:" + 9999, 9999); - DocumentEntity doc = driver.createDocument(collectionName, value, null, false); + final TestComplexEntity01 value = new TestComplexEntity01("user-" + 9999, "説明:" + 9999, 9999); + final DocumentEntity doc = driver.createDocument(collectionName, value, null, false); assertThat(doc.getDocumentKey(), is(notNullValue())); assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); assertThat(doc.getDocumentRevision(), is(not(0L))); - DocumentEntity retVal = driver.getDocument(doc.getDocumentHandle(), + final DocumentEntity retVal = driver.getDocument(doc.getDocumentHandle(), TestComplexEntity01.class); assertThat(retVal.getDocumentHandle(), is(doc.getDocumentHandle())); assertThat(retVal.getDocumentRevision(), is(doc.getDocumentRevision())); @@ -451,8 +449,8 @@ public void test_get_document() throws ArangoException { @Test public void test_get_document_with_instance_creator() throws ArangoException { // save an instance of TestInterfaceImpl with null as "name" - DocumentEntity doc = driver.createDocument(collectionName, new TestInterfaceImpl(null), null, - false); + final DocumentEntity doc = driver.createDocument(collectionName, new TestInterfaceImpl(null), + null, false); assertThat(doc.getDocumentKey(), is(notNullValue())); assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); @@ -460,7 +458,7 @@ public void test_get_document_with_instance_creator() throws ArangoException { // now we should get back an instance created with our configured // InstanceCreator (with "name" already set) - DocumentEntity retVal = driver.getDocument(doc.getDocumentHandle(), TestInterface.class); + final DocumentEntity retVal = driver.getDocument(doc.getDocumentHandle(), TestInterface.class); assertThat(retVal.getDocumentHandle(), is(doc.getDocumentHandle())); assertThat(retVal.getDocumentRevision(), is(doc.getDocumentRevision())); assertThat(retVal.getDocumentKey(), is(doc.getDocumentKey())); @@ -476,7 +474,7 @@ public void test_get_document_collection_not_found() throws ArangoException { try { driver.getDocument(collectionName404, 1L, TestComplexEntity01.class); fail(""); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); // collection not found @@ -489,7 +487,7 @@ public void test_get_document_doc_not_found() throws ArangoException { try { driver.getDocument(collectionName, 1L, TestComplexEntity01.class); fail(""); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1202)); // document not found @@ -571,10 +569,10 @@ public void test_get_as_map() throws ArangoException { @Test public void test_checkDocument() throws ArangoException { - DocumentEntity doc = driver.createDocument(collectionName, + final DocumentEntity doc = driver.createDocument(collectionName, new TestComplexEntity02(1, 2, 3), null, null); - Long etag = driver.checkDocument(doc.getDocumentHandle()); + final Long etag = driver.checkDocument(doc.getDocumentHandle()); assertThat(etag, is(doc.getDocumentRevision())); } @@ -586,7 +584,7 @@ public void test_check_document_doc_not_found() throws ArangoException { try { driver.checkDocument(collectionName, 1); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(0)); } @@ -597,14 +595,14 @@ public void test_check_document_doc_not_exists() throws ArangoException { driver.createDocument(collectionName, new TestComplexEntity02(1, 2, 3), null, null); - boolean b = driver.exists(collectionName, 1); + final boolean b = driver.exists(collectionName, 1); assertThat(b, is(false)); } @Test public void test_delete() throws ArangoException { - DocumentEntity doc = driver.createDocument(collectionName, + final DocumentEntity doc = driver.createDocument(collectionName, new TestComplexEntity02(1, 2, 3)); driver.deleteDocument(doc.getDocumentHandle()); } @@ -614,7 +612,7 @@ public void test_delete_doc_not_found() throws ArangoException { try { driver.deleteDocument(collectionName, 1); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(ErrorNums.ERROR_HTTP_NOT_FOUND)); } } @@ -622,7 +620,7 @@ public void test_delete_doc_not_found() throws ArangoException { @Test public void test_BaseDocumentProperties() throws ArangoException { // create a document - BaseDocument myObject = new BaseDocument(); + final BaseDocument myObject = new BaseDocument(); myObject.setDocumentKey("myKey"); myObject.addAttribute("a", "Foo"); myObject.addAttribute("b", 42); @@ -643,16 +641,16 @@ public void test_BaseDocumentProperties() throws ArangoException { @Test public void createRawDocument() throws ArangoException { - String jsonString = "{\"test\":123}"; + final String jsonString = "{\"test\":123}"; logger.debug("jsonString before: " + jsonString); - DocumentEntity entity = driver.createDocumentRaw(collectionName, jsonString, true, false); + final DocumentEntity entity = driver.createDocumentRaw(collectionName, jsonString, true, false); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); Assert.assertNotNull(entity.getDocumentKey()); Assert.assertNotNull(entity.getDocumentRevision()); - String documentHandle = entity.getDocumentHandle(); + final String documentHandle = entity.getDocumentHandle(); - String str = driver.getDocumentRaw(documentHandle, null, null); + final String str = driver.getDocumentRaw(documentHandle, null, null); Assert.assertNotNull(str); Assert.assertTrue(str.contains("\"test\":123")); // this string has "_id", "_key" and "_rev" attributes: @@ -661,19 +659,19 @@ public void createRawDocument() throws ArangoException { @Test public void createRawDocumentWithKey() throws ArangoException { - String key = "key1"; - String jsonString = "{\"_key\":\"" + key + "\",\"test\":123}"; + final String key = "key1"; + final String jsonString = "{\"_key\":\"" + key + "\",\"test\":123}"; logger.debug("jsonString before: " + jsonString); - DocumentEntity entity = driver.createDocumentRaw(collectionName, jsonString, true, false); + final DocumentEntity entity = driver.createDocumentRaw(collectionName, jsonString, true, false); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); Assert.assertNotNull(entity.getDocumentKey()); Assert.assertNotNull(entity.getDocumentRevision()); Assert.assertEquals(collectionName + "/" + key, entity.getDocumentHandle()); Assert.assertEquals(key, entity.getDocumentKey()); - String documentHandle = entity.getDocumentHandle(); + final String documentHandle = entity.getDocumentHandle(); - String str = driver.getDocumentRaw(documentHandle, null, null); + final String str = driver.getDocumentRaw(documentHandle, null, null); Assert.assertNotNull(str); Assert.assertTrue(str.contains("\"test\":123")); Assert.assertTrue(str.contains("\"_key\":\"" + key + "\"")); @@ -684,10 +682,10 @@ public void createRawDocumentWithKey() throws ArangoException { @Test public void createRawDocumentFails() throws ArangoException { try { - String jsonString = "no JSON"; + final String jsonString = "no JSON"; driver.createDocumentRaw(collectionName, jsonString, true, false); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.assertEquals(ErrorNums.ERROR_HTTP_BAD_PARAMETER, e.getCode()); Assert.assertEquals(ErrorNums.ERROR_HTTP_CORRUPTED_JSON, e.getErrorNumber()); } @@ -698,7 +696,7 @@ public void getRawDocumentFails() throws ArangoException { try { driver.getDocumentRaw(collectionName + "/notfound", null, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { Assert.assertEquals(ErrorNums.ERROR_HTTP_NOT_FOUND, e.getCode()); Assert.assertEquals(ErrorNums.ERROR_HTTP_NOT_FOUND, e.getErrorNumber()); } diff --git a/src/test/java/com/arangodb/ArangoDriverEndpointTest.java b/src/test/java/com/arangodb/ArangoDriverEndpointTest.java index 457f19b7f..ca312bc0c 100644 --- a/src/test/java/com/arangodb/ArangoDriverEndpointTest.java +++ b/src/test/java/com/arangodb/ArangoDriverEndpointTest.java @@ -43,10 +43,6 @@ public class ArangoDriverEndpointTest extends BaseTest { private static final String MYDB2 = "mydb2"; private static final String[] DB_S = new String[] { DB, MYDB, MYDB1, MYDB2 }; - public ArangoDriverEndpointTest(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { for (final String db : DB_S) { diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgeCreateTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgeCreateTest.java index bbeed0a41..d2c5cb604 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgeCreateTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgeCreateTest.java @@ -36,22 +36,18 @@ */ public class ArangoDriverGraphEdgeCreateTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String edgeCollectionName = "edge-1"; - - public ArangoDriverGraphEdgeCreateTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String graphName = "UnitTestGraph"; + private final String edgeCollectionName = "edge-1"; @Test public void test_create_edge_no_key() throws ArangoException { - String edgeCollectionName = "edge-1"; + final String edgeCollectionName = "edge-1"; driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); EdgeEntity edge = driver.graphCreateEdge(this.graphName, edgeCollectionName, null, v1.getDocumentHandle(), @@ -73,9 +69,9 @@ public void test_create_edge_no_key() throws ArangoException { public void test_create_edge_key() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); EdgeEntity edge = driver.graphCreateEdge(this.graphName, edgeCollectionName, "e1", v1.getDocumentHandle(), @@ -96,11 +92,11 @@ public void test_create_edge_key() throws ArangoException { @Test public void test_create_edge_optional_value() throws ArangoException { - String edgeCollectionName = "edge-1"; + final String edgeCollectionName = "edge-1"; driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); EdgeEntity edge = driver.graphCreateEdge(this.graphName, edgeCollectionName, "e1", @@ -127,12 +123,12 @@ public void test_create_edge_optional_value() throws ArangoException { @Test public void test_create_edge_label() throws ArangoException { - String edgeCollectionName = "edge-1"; + final String edgeCollectionName = "edge-1"; driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); EdgeEntity edge = driver.graphCreateEdge(this.graphName, edgeCollectionName, "e1", @@ -161,7 +157,7 @@ public void test_create_edge_no_graph() throws ArangoException { try { driver.graphCreateEdge(this.graphName, "edge-1", null, "1", "2", null, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorMessage(), startsWith("graph not found")); } @@ -171,9 +167,9 @@ public void test_create_edge_no_graph() throws ArangoException { @Test public void test_create_edge_no_edge() throws ArangoException { - String edgeCollectionName = "edge-1"; + final String edgeCollectionName = "edge-1"; driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); @@ -181,7 +177,7 @@ public void test_create_edge_no_edge() throws ArangoException { driver.graphCreateEdge(this.graphName, edgeCollectionName, null, v1.getDocumentHandle(), "vol1/1", null, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(400)); assertThat(e.getErrorMessage(), startsWith("invalid edge")); } @@ -191,11 +187,11 @@ public void test_create_edge_no_edge() throws ArangoException { @Test public void test_create_edge_waitForSync() throws ArangoException { - String edgeCollectionName = "edge-1"; + final String edgeCollectionName = "edge-1"; driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); EdgeEntity edge = driver.graphCreateEdge(this.graphName, edgeCollectionName, null, v1.getDocumentHandle(), diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgeDeleteTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgeDeleteTest.java index 75718c2f4..a88fdcd60 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgeDeleteTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgeDeleteTest.java @@ -34,244 +34,174 @@ */ public class ArangoDriverGraphEdgeDeleteTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String edgeCollectionName = "edge-1"; - - public ArangoDriverGraphEdgeDeleteTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - @Test - public void test_delete_edge() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex( - this.graphName, - "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), - null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01( - "v2-user", "desc2", 12), null); - - EdgeEntity edge = driver.graphCreateEdge( - this.graphName, - this.edgeCollectionName, - null, - v1.getDocumentHandle(), - v2.getDocumentHandle(), - null, - null); - assertThat(edge.getCode(), is(202)); - - DeletedEntity deleted = driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey()); - assertThat(deleted.getCode(), is(202)); - assertThat(deleted.isError(), is(false)); - assertThat(deleted.getDeleted(), is(true)); - - } - - @Test - public void test_delete_edge_no_graph() throws ArangoException { - try { - driver.graphDeleteEdge("foo", "bar", null); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1924)); - assertThat(e.getErrorMessage(), startsWith("graph not found")); - } - - } - - @Test - public void test_delete_edge_no_edge_collection() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - - try { - driver.graphDeleteEdge(this.graphName, "1", "2"); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - assertThat(e.getErrorMessage(), startsWith("collection not found")); - } - - } - - @Test - public void test_delete_edge_waitForSync() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex( - this.graphName, - "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), - null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01( - "v2-user", "desc2", 12), null); - - EdgeEntity edge = driver.graphCreateEdge( - this.graphName, - this.edgeCollectionName, - null, - v1.getDocumentHandle(), - v2.getDocumentHandle(), - null, - false); - assertThat(edge.getCode(), is(202)); - assertThat(edge.isError(), is(false)); - - DeletedEntity deleted = driver.graphDeleteEdge( - this.graphName, - this.edgeCollectionName, - edge.getDocumentKey(), - false); - assertThat(deleted.getCode(), is(202)); - assertThat(deleted.getDeleted(), is(true)); - - } - - @Test - public void test_delete_edge_rev_eq() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex( - this.graphName, - "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), - null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01( - "v2-user", "desc2", 12), null); - - EdgeEntity edge = driver.graphCreateEdge( - this.graphName, - this.edgeCollectionName, - null, - v1.getDocumentHandle(), - v2.getDocumentHandle(), - null, - null); - assertThat(edge.getCode(), is(202)); - - Long rev = edge.getDocumentRevision(); - DeletedEntity deleted = driver.graphDeleteEdge( - this.graphName, - this.edgeCollectionName, - edge.getDocumentKey(), - null, - rev, - null); - assertThat(deleted.getCode(), is(202)); - assertThat(deleted.isError(), is(false)); - assertThat(deleted.getDeleted(), is(true)); - - } - - @Test - public void test_delete_edge_rev_ne() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex( - this.graphName, - "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), - null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01( - "v2-user", "desc2", 12), null); - - EdgeEntity edge = driver.graphCreateEdge( - this.graphName, - this.edgeCollectionName, - null, - v1.getDocumentHandle(), - v2.getDocumentHandle(), - null, - null); - assertThat(edge.getCode(), is(202)); - - try { - Long rev = edge.getDocumentRevision() + 1; - driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), null, rev, null); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(412)); - assertThat(e.getErrorNumber(), is(1903)); - assertThat(e.getErrorMessage(), is("wrong revision")); - } - - } - - @Test - public void test_delete_edge_match_eq() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex( - this.graphName, - "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), - null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01( - "v2-user", "desc2", 12), null); - - EdgeEntity edge = driver.graphCreateEdge( - this.graphName, - this.edgeCollectionName, - null, - v1.getDocumentHandle(), - v2.getDocumentHandle(), - null, - null); - assertThat(edge.getCode(), is(202)); - - Long rev = edge.getDocumentRevision(); - DeletedEntity deleted = driver.graphDeleteEdge( - this.graphName, - this.edgeCollectionName, - edge.getDocumentKey(), - null, - rev, - null); - assertThat(deleted.getCode(), is(202)); - assertThat(deleted.isError(), is(false)); - assertThat(deleted.getDeleted(), is(true)); - - } - - @Test - public void test_delete_edge_match_ne() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex( - this.graphName, - "from1-1", - new TestComplexEntity01("v1-user", "desc1", 10), - null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01( - "v2-user", "desc2", 12), null); - - EdgeEntity edge = driver.graphCreateEdge( - this.graphName, - this.edgeCollectionName, - null, - v1.getDocumentHandle(), - v2.getDocumentHandle(), - null, - null); - assertThat(edge.getCode(), is(202)); - - try { - Long rev = edge.getDocumentRevision() + 1; - driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), null, rev, null); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(412)); - assertThat(e.getErrorNumber(), is(1903)); - assertThat(e.getErrorMessage(), is("wrong revision")); - } - - } + private final String graphName = "UnitTestGraph"; + private final String edgeCollectionName = "edge-1"; + + @Test + public void test_delete_edge() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); + assertThat(edge.getCode(), is(202)); + + final DeletedEntity deleted = driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey()); + assertThat(deleted.getCode(), is(202)); + assertThat(deleted.isError(), is(false)); + assertThat(deleted.getDeleted(), is(true)); + + } + + @Test + public void test_delete_edge_no_graph() throws ArangoException { + try { + driver.graphDeleteEdge("foo", "bar", null); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1924)); + assertThat(e.getErrorMessage(), startsWith("graph not found")); + } + + } + + @Test + public void test_delete_edge_no_edge_collection() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); + driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); + + try { + driver.graphDeleteEdge(this.graphName, "1", "2"); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + assertThat(e.getErrorMessage(), startsWith("collection not found")); + } + + } + + @Test + public void test_delete_edge_waitForSync() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), null, false); + assertThat(edge.getCode(), is(202)); + assertThat(edge.isError(), is(false)); + + final DeletedEntity deleted = driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), false); + assertThat(deleted.getCode(), is(202)); + assertThat(deleted.getDeleted(), is(true)); + + } + + @Test + public void test_delete_edge_rev_eq() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); + assertThat(edge.getCode(), is(202)); + + final Long rev = edge.getDocumentRevision(); + final DeletedEntity deleted = driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), null, rev, null); + assertThat(deleted.getCode(), is(202)); + assertThat(deleted.isError(), is(false)); + assertThat(deleted.getDeleted(), is(true)); + + } + + @Test + public void test_delete_edge_rev_ne() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); + assertThat(edge.getCode(), is(202)); + + try { + final Long rev = edge.getDocumentRevision() + 1; + driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), null, rev, null); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(412)); + assertThat(e.getErrorNumber(), is(1903)); + assertThat(e.getErrorMessage(), is("wrong revision")); + } + + } + + @Test + public void test_delete_edge_match_eq() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); + assertThat(edge.getCode(), is(202)); + + final Long rev = edge.getDocumentRevision(); + final DeletedEntity deleted = driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, + edge.getDocumentKey(), null, rev, null); + assertThat(deleted.getCode(), is(202)); + assertThat(deleted.isError(), is(false)); + assertThat(deleted.getDeleted(), is(true)); + + } + + @Test + public void test_delete_edge_match_ne() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + new TestComplexEntity01("v1-user", "desc1", 10), null); + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + new TestComplexEntity01("v2-user", "desc2", 12), null); + + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); + assertThat(edge.getCode(), is(202)); + + try { + final Long rev = edge.getDocumentRevision() + 1; + driver.graphDeleteEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), null, rev, null); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(412)); + assertThat(e.getErrorNumber(), is(1903)); + assertThat(e.getErrorMessage(), is("wrong revision")); + } + + } } diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgeGetTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgeGetTest.java index 77014dae5..10dcca9cd 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgeGetTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgeGetTest.java @@ -32,26 +32,22 @@ */ public class ArangoDriverGraphEdgeGetTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String edgeCollectionName = "edge-1"; - - public ArangoDriverGraphEdgeGetTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String graphName = "UnitTestGraph"; + private final String edgeCollectionName = "edge-1"; @Test public void test_get_edge() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), null, null); - EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), + final EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), null); assertThat(edge2.getCode(), is(200)); assertThat(edge2.isError(), is(false)); @@ -68,15 +64,15 @@ public void test_get_edge() throws ArangoException { public void test_get_edge2() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, + final EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), TestComplexEntity02.class); assertThat(edge2.getCode(), is(200)); assertThat(edge2.isError(), is(false)); @@ -99,7 +95,7 @@ public void test_get_edge_graph_not_found() throws ArangoException { try { driver.graphGetEdge("foo", "bar", "v1", null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1924)); assertThat(e.getErrorMessage(), startsWith("graph not found")); @@ -111,9 +107,9 @@ public void test_get_edge_graph_not_found() throws ArangoException { public void test_get_edge_edge_not_found() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), @@ -122,7 +118,7 @@ public void test_get_edge_edge_not_found() throws ArangoException { try { driver.graphGetEdge(this.graphName, this.edgeCollectionName, "xx", null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1202)); assertThat(e.getErrorMessage(), startsWith("document not found")); @@ -134,16 +130,16 @@ public void test_get_edge_edge_not_found() throws ArangoException { public void test_get_edge_rev_eq() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - Long rev = edge1.getDocumentRevision(); - EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, + final Long rev = edge1.getDocumentRevision(); + final EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), TestComplexEntity02.class, rev, null); assertThat(edge2.getCode(), is(200)); assertThat(edge2.isError(), is(false)); @@ -164,20 +160,20 @@ public void test_get_edge_rev_eq() throws ArangoException { public void test_get_edge_rev_ne() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); try { - Long rev = edge1.getDocumentRevision() + 1; + final Long rev = edge1.getDocumentRevision() + 1; driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), TestComplexEntity02.class, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); @@ -189,16 +185,16 @@ public void test_get_edge_rev_ne() throws ArangoException { public void test_get_edge_nomatch_eq() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - Long rev = edge1.getDocumentRevision(); - EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, + final Long rev = edge1.getDocumentRevision(); + final EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), TestComplexEntity02.class, null, rev); assertThat(edge2.getStatusCode(), is(304)); assertThat(edge2.isNotModified(), is(true)); @@ -210,16 +206,16 @@ public void test_get_edge_nomatch_eq() throws ArangoException { public void test_get_edge_nomatch_ne() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - Long rev = edge1.getDocumentRevision() + 1; - EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, + final Long rev = edge1.getDocumentRevision() + 1; + final EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), TestComplexEntity02.class, null, rev); assertThat(edge2.getCode(), is(200)); @@ -241,16 +237,16 @@ public void test_get_edge_nomatch_ne() throws ArangoException { public void test_get_edge_match_eq() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - Long rev = edge1.getDocumentRevision(); - EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, + final Long rev = edge1.getDocumentRevision(); + final EdgeEntity edge2 = driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), TestComplexEntity02.class, rev, null); assertThat(edge2.getCode(), is(200)); assertThat(edge2.isError(), is(false)); @@ -271,20 +267,20 @@ public void test_get_edge_match_eq() throws ArangoException { public void test_get_edge_match_ne() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); - EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge1 = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); try { - Long rev = edge1.getDocumentRevision() + 1; + final Long rev = edge1.getDocumentRevision() + 1; driver.graphGetEdge(this.graphName, this.edgeCollectionName, edge1.getDocumentKey(), TestComplexEntity02.class, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgeReplaceTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgeReplaceTest.java index 3b6919f56..254a73c66 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgeReplaceTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgeReplaceTest.java @@ -35,25 +35,21 @@ */ public class ArangoDriverGraphEdgeReplaceTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String edgeCollectionName = "edge-1"; - - public ArangoDriverGraphEdgeReplaceTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String graphName = "UnitTestGraph"; + private final String edgeCollectionName = "edge-1"; @Test public void test_replace_edge() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); @@ -81,14 +77,14 @@ public void test_replace_edge() throws ArangoException { public void test_replace_edge_null() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); @@ -113,14 +109,14 @@ public void test_replace_edge_null() throws ArangoException { public void test_replace_edge_waitForSync() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); @@ -142,18 +138,18 @@ public void test_replace_edge_waitForSync() throws ArangoException { public void test_replace_edge_rev_eq() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); - Long rev = edge.getDocumentRevision(); + final Long rev = edge.getDocumentRevision(); EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, rev, null); @@ -177,24 +173,24 @@ public void test_replace_edge_rev_eq() throws ArangoException { public void test_replace_edge_rev_ne() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); try { - Long rev = edge.getDocumentRevision() + 1; + final Long rev = edge.getDocumentRevision() + 1; driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); @@ -206,18 +202,18 @@ public void test_replace_edge_rev_ne() throws ArangoException { public void test_replace_edge_match_eq() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); - Long rev = edge.getDocumentRevision(); + final Long rev = edge.getDocumentRevision(); EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, rev, null); @@ -242,24 +238,24 @@ public void test_replace_edge_match_eq() throws ArangoException { public void test_replace_edge_match_ne() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); try { - Long rev = edge.getDocumentRevision() + 1; + final Long rev = edge.getDocumentRevision() + 1; driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); @@ -271,18 +267,18 @@ public void test_replace_edge_match_ne() throws ArangoException { public void test_replace_from_to() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final VertexEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, - v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, + null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); - Long rev = edge.getDocumentRevision(); + final Long rev = edge.getDocumentRevision(); EdgeEntity replacedEdge = driver.graphReplaceEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v2.getDocumentHandle(), v1.getDocumentHandle(), edge.getEntity(), null, rev, null); diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgeUpdateTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgeUpdateTest.java index 84cd9352a..780e02289 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgeUpdateTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgeUpdateTest.java @@ -33,25 +33,21 @@ public class ArangoDriverGraphEdgeUpdateTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String edgeCollectionName = "edge-1"; - - public ArangoDriverGraphEdgeUpdateTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String graphName = "UnitTestGraph"; + private final String edgeCollectionName = "edge-1"; @Test public void test_graphUpdateEdge() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); @@ -79,14 +75,14 @@ public void test_graphUpdateEdge() throws ArangoException { public void test_updateEdge_null() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); @@ -110,14 +106,14 @@ public void test_updateEdge_null() throws ArangoException { public void test_updateEdge_waitForSync() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); @@ -139,18 +135,18 @@ public void test_updateEdge_waitForSync() throws ArangoException { public void test_updateEdge_rev_eq() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); - Long rev = edge.getDocumentRevision(); + final Long rev = edge.getDocumentRevision(); EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); @@ -174,24 +170,24 @@ public void test_updateEdge_rev_eq() throws ArangoException { public void test_updateEdge_rev_ne() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); try { - Long rev = edge.getDocumentRevision() + 1; + final Long rev = edge.getDocumentRevision() + 1; driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); @@ -203,18 +199,18 @@ public void test_updateEdge_rev_ne() throws ArangoException { public void test_updateEdge_match_eq() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); - Long rev = edge.getDocumentRevision(); + final Long rev = edge.getDocumentRevision(); EdgeEntity updatedEdge = driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); @@ -240,24 +236,24 @@ public void test_updateEdge_match_eq() throws ArangoException { public void test_updateEdge_match_ne() throws ArangoException { driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v1-user", "desc1", 10), null); - DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", + final DocumentEntity v2 = driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v2-user", "desc2", 12), null); driver.graphCreateVertex(this.graphName, "from1-1", new TestComplexEntity01("v3-user", "desc3", 14), null); driver.graphCreateVertex(this.graphName, "to1-1", new TestComplexEntity01("v4-user", "desc4", 20), null); - EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, + final EdgeEntity edge = driver.graphCreateEdge(this.graphName, this.edgeCollectionName, null, v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); assertThat(edge.getCode(), is(202)); try { - Long rev = edge.getDocumentRevision() + 1; + final Long rev = edge.getDocumentRevision() + 1; driver.graphUpdateEdge(this.graphName, this.edgeCollectionName, edge.getDocumentKey(), v1.getDocumentHandle(), v2.getDocumentHandle(), new TestComplexEntity01("xx", "yy", 20), null, null, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java index e6b04ff25..569988a0a 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java @@ -46,30 +46,26 @@ */ public class ArangoDriverGraphEdgesGetCursorTest extends BaseGraphTest { - public ArangoDriverGraphEdgesGetCursorTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - private static final String GRAPH_NAME = "UnitTestGraph"; @Before public void setup() throws ArangoException { try { driver.createGraph(GRAPH_NAME, this.createEdgeDefinitions(1, 0), this.createOrphanCollections(0), true); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @Test public void graphGetEdgeCursorTest() throws ArangoException { - GraphEntity graph = this.createTestGraph(); - EdgeCursor cursor = driver.graphGetEdgeCursor(graph.getName()); + final GraphEntity graph = this.createTestGraph(); + final EdgeCursor cursor = driver.graphGetEdgeCursor(graph.getName()); assertThat(cursor.getCount(), is(8)); assertThat(cursor.getCode(), is(201)); assertThat(cursor.hasMore(), is(false)); assertThat(cursor.getCursorId(), is(-1L)); - List results = cursor.asEntityList(); + final List results = cursor.asEntityList(); assertThat(results.size(), is(8)); assertThat(results.get(0).getFromCollection(), startsWith("Country/")); assertThat(results.get(0).getToCollection(), startsWith("Country/")); @@ -77,8 +73,8 @@ public void graphGetEdgeCursorTest() throws ArangoException { @Test public void graphGetEdgeCursorIteratorTest() throws ArangoException { - GraphEntity graph = this.createTestGraph(); - EdgeCursor cursor = driver.graphGetEdgeCursor(graph.getName()); + final GraphEntity graph = this.createTestGraph(); + final EdgeCursor cursor = driver.graphGetEdgeCursor(graph.getName()); assertThat(cursor.getCount(), is(8)); assertThat(cursor.getCode(), is(201)); assertThat(cursor.hasMore(), is(false)); @@ -86,9 +82,9 @@ public void graphGetEdgeCursorIteratorTest() throws ArangoException { int count = 0; - Iterator> iterator = cursor.iterator(); + final Iterator> iterator = cursor.iterator(); while (iterator.hasNext()) { - EdgeEntity edgeEntity = iterator.next(); + final EdgeEntity edgeEntity = iterator.next(); ++count; assertThat(edgeEntity.getEntity().getFromCollection(), startsWith("Country/")); assertThat(edgeEntity.getEntity().getToCollection(), startsWith("Country/")); @@ -100,13 +96,13 @@ public void graphGetEdgeCursorIteratorTest() throws ArangoException { @Test public void graphGetEdgeCursorByExampleVertexHandle() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); @@ -124,18 +120,18 @@ public void graphGetEdgeCursorByExampleVertexHandle() throws ArangoException { @Test public void graphGetEdgeCursorByExampleObjectTest() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); - TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); - VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); @@ -153,7 +149,7 @@ public void graphGetEdgeCursorByExampleObjectTest() throws ArangoException { cursor = driver.graphGetEdgeCursorByExample(GRAPH_NAME, TestComplexEntity02.class, v3); assertThat(cursor.getCount(), is(1)); - List results = cursor.asEntityList(); + final List results = cursor.asEntityList(); assertThat(results.get(0).getClass().getName(), is(TestComplexEntity02.class.getName())); assertThat(results.get(0).getX(), is(4)); @@ -162,15 +158,15 @@ public void graphGetEdgeCursorByExampleObjectTest() throws ArangoException { @Test public void graphGetEdgeCursorByExampleMapTest() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); - TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); - VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); @@ -181,7 +177,7 @@ public void graphGetEdgeCursorByExampleMapTest() throws ArangoException { driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(7, 8, 9), null); - Map exampleVertex = new HashMap(); + final Map exampleVertex = new HashMap(); exampleVertex.put("user", "Homer"); EdgeCursor cursor = driver.graphGetEdgeCursorByExample(GRAPH_NAME, @@ -192,29 +188,29 @@ public void graphGetEdgeCursorByExampleMapTest() throws ArangoException { cursor = driver.graphGetEdgeCursorByExample(GRAPH_NAME, TestComplexEntity02.class, exampleVertex); assertThat(cursor.getCount(), is(1)); - List results = cursor.asEntityList(); + final List results = cursor.asEntityList(); assertThat(results.get(0).getClass().getName(), is(TestComplexEntity02.class.getName())); assertThat(results.get(0).getX(), is(4)); } - private AqlQueryOptions getAqlQueryOptions(Boolean count, Integer batchSize, Boolean fullCount) { + private AqlQueryOptions getAqlQueryOptions(final Boolean count, final Integer batchSize, final Boolean fullCount) { return new AqlQueryOptions().setCount(count).setBatchSize(batchSize).setFullCount(fullCount); } @Test public void batchSizeAndLimitTest() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); - TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); - VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); @@ -228,14 +224,14 @@ public void batchSizeAndLimitTest() throws ArangoException { driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex3.getDocumentHandle(), new TestComplexEntity02(10, 11, 12), null); - Integer batchSize = 2; - Boolean count = true; - Boolean fullCount = true; + final Integer batchSize = 2; + final Boolean count = true; + final Boolean fullCount = true; - String query = "for i in graph_edges(@graphName, null, {includeData: true}) LIMIT 3 return i"; - Map bindVars = new MapBuilder().put("graphName", GRAPH_NAME).get(); + final String query = "for i in graph_edges(@graphName, null, {includeData: true}) LIMIT 3 return i"; + final Map bindVars = new MapBuilder().put("graphName", GRAPH_NAME).get(); - EdgeCursor cursor = driver.executeEdgeQuery(query, bindVars, + final EdgeCursor cursor = driver.executeEdgeQuery(query, bindVars, getAqlQueryOptions(count, batchSize, fullCount), TestComplexEntity02.class); assertEquals(3, cursor.getCount()); @@ -248,15 +244,15 @@ public void batchSizeAndLimitTest() throws ArangoException { @Test public void edgesAqlTest() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); - TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); - VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); @@ -270,15 +266,16 @@ public void edgesAqlTest() throws ArangoException { driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex3.getDocumentHandle(), new TestComplexEntity02(10, 11, 12), null); - Integer batchSize = 10; - Boolean count = true; - Boolean fullCount = true; + final Integer batchSize = 10; + final Boolean count = true; + final Boolean fullCount = true; // get outbound vertices of vertex1 (the should be 2) - String query = "for i in graph_edges(@graphName, @vertex, @options) return i"; + final String query = "for i in graph_edges(@graphName, @vertex, @options) return i"; // options bindVars - Map options = new MapBuilder().put("direction", "outbound").put("includeData", true).get(); + final Map options = new MapBuilder().put("direction", "outbound").put("includeData", true) + .get(); // bindVars Map bindVars = new MapBuilder().put("graphName", GRAPH_NAME) @@ -309,22 +306,22 @@ public void edgesAqlTest() throws ArangoException { @Test public void shortestPathTest() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); - ShortestPathOptions shortestPathOptions = new ShortestPathOptions(); + final ShortestPathOptions shortestPathOptions = new ShortestPathOptions(); shortestPathOptions.setDirection(Direction.OUTBOUND); // - ShortestPathEntity entity = driver.graphGetShortestPath(GRAPH_NAME, - vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), shortestPathOptions, TestComplexEntity01.class, - TestComplexEntity02.class); + final ShortestPathEntity entity = driver.graphGetShortestPath( + GRAPH_NAME, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), shortestPathOptions, + TestComplexEntity01.class, TestComplexEntity02.class); assertEquals(201, entity.getCode()); diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java index 3cc91bac6..579e88bdd 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java @@ -37,25 +37,21 @@ */ public class ArangoDriverGraphEdgesGetTest extends BaseGraphTest { - public ArangoDriverGraphEdgesGetTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - private static final String GRAPH_NAME = "UnitTestGraph"; @Before public void setup() throws ArangoException { try { driver.createGraph(GRAPH_NAME, this.createEdgeDefinitions(1, 0), this.createOrphanCollections(0), true); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @SuppressWarnings("deprecation") @Test public void test_getEdges_All() throws ArangoException { - GraphEntity graph = this.createTestGraph(); - CursorEntity cursor = driver.graphGetEdges(graph.getName()); + final GraphEntity graph = this.createTestGraph(); + final CursorEntity cursor = driver.graphGetEdges(graph.getName()); assertThat(cursor.getCount(), is(8)); assertThat(cursor.getCode(), is(201)); assertThat(cursor.isError(), is(false)); @@ -70,13 +66,13 @@ public void test_getEdges_All() throws ArangoException { @SuppressWarnings("deprecation") @Test public void test_getEdges_Vertex() throws ArangoException { - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", new TestComplexEntity01("Homer", "A Simpson", 38), true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", new TestComplexEntity01("Marge", "A Simpson", 36), true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", new TestComplexEntity01("Bart", "A Simpson", 10), true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), @@ -96,18 +92,18 @@ public void test_getEdges_Vertex() throws ArangoException { @SuppressWarnings("deprecation") @Test public void test_GetEdgesByExampleObject() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); - TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); - VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); @@ -132,18 +128,18 @@ public void test_GetEdgesByExampleObject() throws ArangoException { @SuppressWarnings("deprecation") @Test public void test_GetEdgesByExampleMap() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); - TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); - VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); @@ -154,7 +150,7 @@ public void test_GetEdgesByExampleMap() throws ArangoException { driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(7, 8, 9), null); - Map exampleVertex = new HashMap(); + final Map exampleVertex = new HashMap(); exampleVertex.put("user", "Homer"); CursorEntity cursor = driver.graphGetEdgesByExampleMap(GRAPH_NAME, diff --git a/src/test/java/com/arangodb/ArangoDriverGraphTest.java b/src/test/java/com/arangodb/ArangoDriverGraphTest.java index 2b6185093..dfef273a4 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphTest.java @@ -40,416 +40,415 @@ */ public class ArangoDriverGraphTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String collectionName = "UnitTestCollection"; - - public ArangoDriverGraphTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - @Test - public void test_getGraphs() throws ArangoException { - GraphsEntity graphs = driver.getGraphs(); - assertThat(graphs.getGraphs().size(), is(0)); - driver.createGraph("UnitTestGraph1", true); - driver.createGraph("UnitTestGraph2", true); - driver.createGraph("UnitTestGraph3", true); - graphs = driver.getGraphs(); - assertThat(graphs.getGraphs().size(), is(3)); - assertThat(graphs.getGraphs().get(0).getName(), startsWith("UnitTestGraph")); - assertThat(graphs.getGraphs().get(1).getName(), startsWith("UnitTestGraph")); - assertThat(graphs.getGraphs().get(2).getName(), startsWith("UnitTestGraph")); - } - - @Test - public void test_getGraphList() throws ArangoException { - List graphs = driver.getGraphList(); - assertThat(graphs.size(), is(0)); - String graphName1 = "UnitTestGraph1"; - String graphName2 = "UnitTestGraph2"; - String graphName3 = "UnitTestGraph3"; - driver.createGraph(graphName1, true); - driver.createGraph(graphName2, true); - driver.createGraph(graphName3, true); - graphs = driver.getGraphList(); - assertThat(graphs.size(), is(3)); - assertThat(graphs.contains(graphName1), is(true)); - assertThat(graphs.contains(graphName2), is(true)); - assertThat(graphs.contains(graphName3), is(true)); - assertThat(graphs.contains("foo"), is(false)); - } - - @Test - public void test_createGraph() throws ArangoException { - - List edgeDefinitions = new ArrayList(); - List orphanCollections = new ArrayList(); - - // create - GraphEntity graph = driver.createGraph(this.graphName, edgeDefinitions, orphanCollections, true); - - assertThat(graph.getCode(), is(201)); - assertThat(graph.getDocumentRevision(), is(not(0L))); - assertThat(graph.getDocumentHandle(), is("_graphs/" + this.graphName)); - assertThat(graph.getName(), is(this.graphName)); - assertThat(graph.getOrphanCollections(), is(orphanCollections)); - - } - - @Test - public void test_createGraph_2() throws ArangoException { - - List edgeDefinitions = this.createEdgeDefinitions(2, 0); - - List orphanCollections = this.createOrphanCollections(2); - - // create - GraphEntity graph = driver.createGraph(this.graphName, edgeDefinitions, orphanCollections, true); - assertThat(graph.getCode(), is(201)); - assertThat(graph.getDocumentRevision(), is(not(0L))); - assertThat(graph.getDocumentHandle(), is("_graphs/" + this.graphName)); - assertThat(graph.getName(), is(this.graphName)); - assertThat(graph.getOrphanCollections(), is(orphanCollections)); - } - - @Test - public void test_getGraph() throws ArangoException { - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - GraphEntity graph = driver.getGraph(this.graphName); - assertThat(graph.getEdgeDefinitionsEntity().getEdgeDefinitions().get(0).getClass().getName(), is(EdgeDefinitionEntity.class.getName())); - assertThat(graph.getEdgeDefinitionsEntity().getEdgeDefinitions().get(0).getFrom().size(), is(3)); - assertThat(graph.getOrphanCollections().size(), is(2)); - assertThat(graph.getName(), is(this.graphName)); - assertThat(graph.getEdgeDefinitionsEntity().getSize(), is(2)); - assertThat(graph.getEdgeDefinitionsEntity().getEdgeDefinitions().get(0).getCollection().startsWith("edge"), is(true)); - - } - - @Test - public void test_deleteGraph_keep_collections() throws ArangoException { - GraphsEntity graphs = driver.getGraphs(); - assertThat(graphs.getGraphs().size(), is(0)); - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - graphs = driver.getGraphs(); - assertThat(graphs.getGraphs().size(), is(1)); - assertThat(driver.getGraph(this.graphName).getName(), is(this.graphName)); - driver.deleteGraph(this.graphName); - graphs = driver.getGraphs(); - assertThat(graphs.getGraphs().size(), is(0)); - assertThat("number of collections", driver.getCollections(true).getCollections().size(), greaterThan(0)); - } - - @Test - public void test_deleteGraph_delete_collections() throws ArangoException { - GraphsEntity graphs = driver.getGraphs(); - assertThat(graphs.getGraphs().size(), is(0)); - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - graphs = driver.getGraphs(); - assertThat(graphs.getGraphs().size(), is(1)); - assertThat(driver.getGraph(this.graphName).getName(), is(this.graphName)); - driver.deleteGraph(this.graphName, true); - graphs = driver.getGraphs(); - assertThat(graphs.getGraphs().size(), is(0)); - assertThat("number of collections", driver.getCollections(true).getCollections().size(), is(0)); - } - - @Test - public void test_deleteGraph_not_found() throws ArangoException { - try { - driver.deleteGraph("foo"); - - } catch (ArangoException e) { - assertThat(e.getErrorMessage(), is("graph not found")); - } - } - - @Test - public void test_getVertexCollections() throws ArangoException { - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - List collections = driver.graphGetVertexCollections(this.graphName); - assertThat(collections.size(), is(14)); - } - - @Test - public void test_getVertexCollections_not_found() throws ArangoException { - try { - driver.graphGetVertexCollections("foo"); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorMessage(), is("graph not found")); - } - } - - @Test - public void test_createVertexCollection() throws ArangoException { - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - GraphEntity graph = driver.graphCreateVertexCollection(this.graphName, collectionName); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(true)); - assertThat(graph.getName(), is(this.graphName)); - } - - @Test - public void test_create_newVertexCollection_error() throws ArangoException { - try { - driver.graphCreateVertexCollection("foo", "UnitTestCollection"); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - } - } - - @Test - public void test_deleteVertexCollection_keep_collection() throws ArangoException { - - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - driver.graphCreateVertexCollection(this.graphName, collectionName); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(true)); - driver.graphDeleteVertexCollection(this.graphName, collectionName, false); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(false)); - assertThat(driver.getCollection(collectionName).getClass().getName(), is(CollectionEntity.class.getName())); - - } - - @Test - public void test_deleteVertexCollection_drop_collection() throws ArangoException { - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - driver.graphCreateVertexCollection(this.graphName, collectionName); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(true)); - driver.graphDeleteVertexCollection(this.graphName, collectionName, true); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(false)); - try { - driver.getCollection(collectionName); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), greaterThan(300)); - } - - } - - @Test - public void test_deleteVertexCollection_drop_collection_fail() throws ArangoException { - String graphName1 = "UnitTestGraph1"; - String graphName2 = "UnitTestGraph2"; - driver.createGraph(graphName1, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - driver.createGraph(graphName2, this.createEdgeDefinitions(2, 2), this.createOrphanCollections(2), true); - driver.graphCreateVertexCollection(graphName1, collectionName); - assertThat(driver.graphGetVertexCollections(graphName1).contains(collectionName), is(true)); - driver.graphCreateVertexCollection(graphName2, collectionName); - assertThat(driver.graphGetVertexCollections(graphName2).contains(collectionName), is(true)); - driver.graphDeleteVertexCollection(graphName1, collectionName, true); - assertThat(driver.graphGetVertexCollections(graphName1).contains(collectionName), is(false)); - assertThat(driver.graphGetVertexCollections(graphName2).contains(collectionName), is(true)); - assertThat(driver.getCollection(collectionName).getClass().getName(), is(CollectionEntity.class.getName())); - } - - @Test - public void test_delete_vertex_collection_error1() throws ArangoException { - try { - driver.graphDeleteVertexCollection("foo", "bar", true); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - } - } - - @Test - public void test_delete_vertex_collection_error2() throws ArangoException { - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - try { - driver.graphDeleteVertexCollection(this.graphName, "bar", true); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - } - } - - @Test - public void test_get_edge_Collections() throws ArangoException { - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - List collections = driver.graphGetEdgeCollections(this.graphName); - assertThat(collections.size(), is(2)); - } - - @Test - public void test_get_edge_Collections_not_found() throws ArangoException { - try { - driver.graphGetEdgeCollections("foo"); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorMessage(), is("graph not found")); - } - } - - @Test - public void test_create_edge_definition() throws ArangoException { - String edgeCollectionName = "UnitTestEdgeCollection"; - String fromCollectionName = "UnitTestFromCollection"; - String toCollectionName = "UnitTestToCollection"; - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); - edgeDefinition.setCollection(edgeCollectionName); - List from = new ArrayList(); - from.add(fromCollectionName); - edgeDefinition.setFrom(from); - List to = new ArrayList(); - to.add(toCollectionName); - edgeDefinition.setTo(to); - driver.graphCreateEdgeDefinition(this.graphName, edgeDefinition); - assertThat(driver.graphGetEdgeCollections(this.graphName).contains(edgeCollectionName), is(true)); - } - - @Test - public void test_create_edge_definition_2_graphs() throws ArangoException { - String graphName1 = "UnitTestGraph1"; - String graphName2 = "UnitTestGraph2"; - String edgeCollectionName = "UnitTestEdgeCollection"; - String fromCollectionName = "UnitTestFromCollection"; - String toCollectionName = "UnitTestToCollection"; - driver.createGraph(graphName1, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - driver.createGraph(graphName2, this.createEdgeDefinitions(2, 2), this.createOrphanCollections(2), true); - EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); - edgeDefinition.setCollection(edgeCollectionName); - List from = new ArrayList(); - from.add(fromCollectionName); - edgeDefinition.setFrom(from); - List to = new ArrayList(); - to.add(toCollectionName); - edgeDefinition.setTo(to); - driver.graphCreateEdgeDefinition(graphName1, edgeDefinition); - driver.graphCreateEdgeDefinition(graphName2, edgeDefinition); - assertThat(driver.graphGetEdgeCollections(graphName1).contains(edgeCollectionName), is(true)); - assertThat(driver.graphGetEdgeCollections(graphName2).contains(edgeCollectionName), is(true)); - } - - @Test - public void test_replace_edge_definition() throws ArangoException { - String edgeCollectionName = "UnitTestEdgeCollection"; - String fromCollectionName1 = "UnitTestFromCollection1"; - String fromCollectionName2 = "UnitTestFromCollection2"; - String toCollectionName1 = "UnitTestToCollection1"; - String toCollectionName2 = "UnitTestToCollection2"; - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - EdgeDefinitionEntity edgeDefinition1 = new EdgeDefinitionEntity(); - edgeDefinition1.setCollection(edgeCollectionName); - List from1 = new ArrayList(); - from1.add(fromCollectionName1); - edgeDefinition1.setFrom(from1); - List to1 = new ArrayList(); - to1.add(toCollectionName1); - edgeDefinition1.setTo(to1); - driver.graphCreateEdgeDefinition(this.graphName, edgeDefinition1); - assertThat(driver.graphGetEdgeCollections(this.graphName).contains(edgeCollectionName), is(true)); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(fromCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(toCollectionName1), is(true)); - EdgeDefinitionEntity edgeDefinition2 = new EdgeDefinitionEntity(); - edgeDefinition2.setCollection(edgeCollectionName); - List from2 = new ArrayList(); - from2.add(fromCollectionName2); - edgeDefinition2.setFrom(from2); - List to2 = new ArrayList(); - to2.add(toCollectionName2); - edgeDefinition2.setTo(to2); - GraphEntity graph = driver.graphReplaceEdgeDefinition(this.graphName, edgeCollectionName, edgeDefinition2); - List edgeDefinitions = graph.getEdgeDefinitionsEntity().getEdgeDefinitions(); - for (EdgeDefinitionEntity edgeDef : edgeDefinitions) { - List f = edgeDef.getFrom(); - assertThat(f.contains(from1), is(false)); - List t = edgeDef.getTo(); - assertThat(t.contains(to1), is(false)); - } - assertThat(driver.graphGetEdgeCollections(this.graphName).contains(edgeCollectionName), is(true)); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(fromCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(toCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(fromCollectionName2), is(true)); - assertThat(driver.graphGetVertexCollections(this.graphName).contains(toCollectionName2), is(true)); - } - - @Test - public void test_replace_edge_definition_2_graphs() throws ArangoException { - String graphName1 = "UnitTestGraph1"; - String graphName2 = "UnitTestGraph2"; - String edgeCollectionName = "UnitTestEdgeCollection"; - String fromCollectionName1 = "UnitTestFromCollection1"; - String fromCollectionName2 = "UnitTestFromCollection2"; - String toCollectionName1 = "UnitTestToCollection1"; - String toCollectionName2 = "UnitTestToCollection2"; - driver.createGraph(graphName1, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - driver.createGraph(graphName2, this.createEdgeDefinitions(2, 2), this.createOrphanCollections(2), true); - EdgeDefinitionEntity edgeDefinition1 = new EdgeDefinitionEntity(); - edgeDefinition1.setCollection(edgeCollectionName); - List from1 = new ArrayList(); - from1.add(fromCollectionName1); - edgeDefinition1.setFrom(from1); - List to1 = new ArrayList(); - to1.add(toCollectionName1); - edgeDefinition1.setTo(to1); - driver.graphCreateEdgeDefinition(graphName1, edgeDefinition1); - driver.graphCreateEdgeDefinition(graphName2, edgeDefinition1); - assertThat(driver.graphGetEdgeCollections(graphName1).contains(edgeCollectionName), is(true)); - assertThat(driver.graphGetVertexCollections(graphName1).contains(fromCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(graphName1).contains(toCollectionName1), is(true)); - assertThat(driver.graphGetEdgeCollections(graphName2).contains(edgeCollectionName), is(true)); - assertThat(driver.graphGetVertexCollections(graphName2).contains(fromCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(graphName2).contains(toCollectionName1), is(true)); - EdgeDefinitionEntity edgeDefinition2 = new EdgeDefinitionEntity(); - edgeDefinition2.setCollection(edgeCollectionName); - List from2 = new ArrayList(); - from2.add(fromCollectionName2); - edgeDefinition2.setFrom(from2); - List to2 = new ArrayList(); - to2.add(toCollectionName2); - edgeDefinition2.setTo(to2); - GraphEntity graph1 = driver.graphReplaceEdgeDefinition(graphName1, edgeCollectionName, edgeDefinition2); - List edgeDefinitions1 = graph1.getEdgeDefinitionsEntity().getEdgeDefinitions(); - for (EdgeDefinitionEntity edgeDef : edgeDefinitions1) { - List f = edgeDef.getFrom(); - assertThat(f.contains(from1), is(false)); - List t = edgeDef.getTo(); - assertThat(t.contains(to1), is(false)); - } - GraphEntity graph2 = driver.graphReplaceEdgeDefinition(graphName1, edgeCollectionName, edgeDefinition2); - List edgeDefinitions2 = graph2.getEdgeDefinitionsEntity().getEdgeDefinitions(); - for (EdgeDefinitionEntity edgeDef : edgeDefinitions2) { - List f = edgeDef.getFrom(); - assertThat(f.contains(from1), is(false)); - List t = edgeDef.getTo(); - assertThat(t.contains(to1), is(false)); - } - assertThat(driver.graphGetEdgeCollections(graphName1).contains(edgeCollectionName), is(true)); - assertThat(driver.graphGetVertexCollections(graphName1).contains(fromCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(graphName1).contains(toCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(graphName1).contains(fromCollectionName2), is(true)); - assertThat(driver.graphGetVertexCollections(graphName1).contains(toCollectionName2), is(true)); - assertThat(driver.graphGetEdgeCollections(graphName2).contains(edgeCollectionName), is(true)); - assertThat(driver.graphGetVertexCollections(graphName2).contains(fromCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(graphName2).contains(toCollectionName1), is(true)); - assertThat(driver.graphGetVertexCollections(graphName2).contains(fromCollectionName2), is(true)); - assertThat(driver.graphGetVertexCollections(graphName2).contains(toCollectionName2), is(true)); - } - - @Test - public void test_delete_edge_definition_keep_collections() throws ArangoException { - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - driver.graphDeleteEdgeDefinition(this.graphName, "edge-1", false); - assertThat(driver.graphGetEdgeCollections(this.graphName).contains("edge-1"), is(false)); - assertThat(driver.graphGetEdgeCollections(this.graphName).contains("edge-2"), is(true)); - - } - - @Test - public void test_delete_edge_definition_drop_collections() throws ArangoException { - driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - driver.graphDeleteEdgeDefinition(this.graphName, "edge-1", true); - assertThat(driver.graphGetEdgeCollections(this.graphName).contains("edge-1"), is(false)); - assertThat(driver.graphGetEdgeCollections(this.graphName).contains("edge-2"), is(true)); - try { - driver.getCollection("edge-1"); - fail(); - } catch (ArangoException e) { - assertThat(e.getCode(), greaterThan(300)); - } - - } + private final String graphName = "UnitTestGraph"; + private final String collectionName = "UnitTestCollection"; + + @Test + public void test_getGraphs() throws ArangoException { + GraphsEntity graphs = driver.getGraphs(); + assertThat(graphs.getGraphs().size(), is(0)); + driver.createGraph("UnitTestGraph1", true); + driver.createGraph("UnitTestGraph2", true); + driver.createGraph("UnitTestGraph3", true); + graphs = driver.getGraphs(); + assertThat(graphs.getGraphs().size(), is(3)); + assertThat(graphs.getGraphs().get(0).getName(), startsWith("UnitTestGraph")); + assertThat(graphs.getGraphs().get(1).getName(), startsWith("UnitTestGraph")); + assertThat(graphs.getGraphs().get(2).getName(), startsWith("UnitTestGraph")); + } + + @Test + public void test_getGraphList() throws ArangoException { + List graphs = driver.getGraphList(); + assertThat(graphs.size(), is(0)); + final String graphName1 = "UnitTestGraph1"; + final String graphName2 = "UnitTestGraph2"; + final String graphName3 = "UnitTestGraph3"; + driver.createGraph(graphName1, true); + driver.createGraph(graphName2, true); + driver.createGraph(graphName3, true); + graphs = driver.getGraphList(); + assertThat(graphs.size(), is(3)); + assertThat(graphs.contains(graphName1), is(true)); + assertThat(graphs.contains(graphName2), is(true)); + assertThat(graphs.contains(graphName3), is(true)); + assertThat(graphs.contains("foo"), is(false)); + } + + @Test + public void test_createGraph() throws ArangoException { + + final List edgeDefinitions = new ArrayList(); + final List orphanCollections = new ArrayList(); + + // create + final GraphEntity graph = driver.createGraph(this.graphName, edgeDefinitions, orphanCollections, true); + + assertThat(graph.getCode(), is(201)); + assertThat(graph.getDocumentRevision(), is(not(0L))); + assertThat(graph.getDocumentHandle(), is("_graphs/" + this.graphName)); + assertThat(graph.getName(), is(this.graphName)); + assertThat(graph.getOrphanCollections(), is(orphanCollections)); + + } + + @Test + public void test_createGraph_2() throws ArangoException { + + final List edgeDefinitions = this.createEdgeDefinitions(2, 0); + + final List orphanCollections = this.createOrphanCollections(2); + + // create + final GraphEntity graph = driver.createGraph(this.graphName, edgeDefinitions, orphanCollections, true); + assertThat(graph.getCode(), is(201)); + assertThat(graph.getDocumentRevision(), is(not(0L))); + assertThat(graph.getDocumentHandle(), is("_graphs/" + this.graphName)); + assertThat(graph.getName(), is(this.graphName)); + assertThat(graph.getOrphanCollections(), is(orphanCollections)); + } + + @Test + public void test_getGraph() throws ArangoException { + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final GraphEntity graph = driver.getGraph(this.graphName); + assertThat(graph.getEdgeDefinitionsEntity().getEdgeDefinitions().get(0).getClass().getName(), + is(EdgeDefinitionEntity.class.getName())); + assertThat(graph.getEdgeDefinitionsEntity().getEdgeDefinitions().get(0).getFrom().size(), is(3)); + assertThat(graph.getOrphanCollections().size(), is(2)); + assertThat(graph.getName(), is(this.graphName)); + assertThat(graph.getEdgeDefinitionsEntity().getSize(), is(2)); + assertThat(graph.getEdgeDefinitionsEntity().getEdgeDefinitions().get(0).getCollection().startsWith("edge"), + is(true)); + + } + + @Test + public void test_deleteGraph_keep_collections() throws ArangoException { + GraphsEntity graphs = driver.getGraphs(); + assertThat(graphs.getGraphs().size(), is(0)); + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + graphs = driver.getGraphs(); + assertThat(graphs.getGraphs().size(), is(1)); + assertThat(driver.getGraph(this.graphName).getName(), is(this.graphName)); + driver.deleteGraph(this.graphName); + graphs = driver.getGraphs(); + assertThat(graphs.getGraphs().size(), is(0)); + assertThat("number of collections", driver.getCollections(true).getCollections().size(), greaterThan(0)); + } + + @Test + public void test_deleteGraph_delete_collections() throws ArangoException { + GraphsEntity graphs = driver.getGraphs(); + assertThat(graphs.getGraphs().size(), is(0)); + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + graphs = driver.getGraphs(); + assertThat(graphs.getGraphs().size(), is(1)); + assertThat(driver.getGraph(this.graphName).getName(), is(this.graphName)); + driver.deleteGraph(this.graphName, true); + graphs = driver.getGraphs(); + assertThat(graphs.getGraphs().size(), is(0)); + assertThat("number of collections", driver.getCollections(true).getCollections().size(), is(0)); + } + + @Test + public void test_deleteGraph_not_found() throws ArangoException { + try { + driver.deleteGraph("foo"); + + } catch (final ArangoException e) { + assertThat(e.getErrorMessage(), is("graph not found")); + } + } + + @Test + public void test_getVertexCollections() throws ArangoException { + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final List collections = driver.graphGetVertexCollections(this.graphName); + assertThat(collections.size(), is(14)); + } + + @Test + public void test_getVertexCollections_not_found() throws ArangoException { + try { + driver.graphGetVertexCollections("foo"); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorMessage(), is("graph not found")); + } + } + + @Test + public void test_createVertexCollection() throws ArangoException { + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final GraphEntity graph = driver.graphCreateVertexCollection(this.graphName, collectionName); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(true)); + assertThat(graph.getName(), is(this.graphName)); + } + + @Test + public void test_create_newVertexCollection_error() throws ArangoException { + try { + driver.graphCreateVertexCollection("foo", "UnitTestCollection"); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(404)); + } + } + + @Test + public void test_deleteVertexCollection_keep_collection() throws ArangoException { + + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + driver.graphCreateVertexCollection(this.graphName, collectionName); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(true)); + driver.graphDeleteVertexCollection(this.graphName, collectionName, false); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(false)); + assertThat(driver.getCollection(collectionName).getClass().getName(), is(CollectionEntity.class.getName())); + + } + + @Test + public void test_deleteVertexCollection_drop_collection() throws ArangoException { + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + driver.graphCreateVertexCollection(this.graphName, collectionName); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(true)); + driver.graphDeleteVertexCollection(this.graphName, collectionName, true); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(collectionName), is(false)); + try { + driver.getCollection(collectionName); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), greaterThan(300)); + } + + } + + @Test + public void test_deleteVertexCollection_drop_collection_fail() throws ArangoException { + final String graphName1 = "UnitTestGraph1"; + final String graphName2 = "UnitTestGraph2"; + driver.createGraph(graphName1, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + driver.createGraph(graphName2, this.createEdgeDefinitions(2, 2), this.createOrphanCollections(2), true); + driver.graphCreateVertexCollection(graphName1, collectionName); + assertThat(driver.graphGetVertexCollections(graphName1).contains(collectionName), is(true)); + driver.graphCreateVertexCollection(graphName2, collectionName); + assertThat(driver.graphGetVertexCollections(graphName2).contains(collectionName), is(true)); + driver.graphDeleteVertexCollection(graphName1, collectionName, true); + assertThat(driver.graphGetVertexCollections(graphName1).contains(collectionName), is(false)); + assertThat(driver.graphGetVertexCollections(graphName2).contains(collectionName), is(true)); + assertThat(driver.getCollection(collectionName).getClass().getName(), is(CollectionEntity.class.getName())); + } + + @Test + public void test_delete_vertex_collection_error1() throws ArangoException { + try { + driver.graphDeleteVertexCollection("foo", "bar", true); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(404)); + } + } + + @Test + public void test_delete_vertex_collection_error2() throws ArangoException { + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + try { + driver.graphDeleteVertexCollection(this.graphName, "bar", true); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(404)); + } + } + + @Test + public void test_get_edge_Collections() throws ArangoException { + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final List collections = driver.graphGetEdgeCollections(this.graphName); + assertThat(collections.size(), is(2)); + } + + @Test + public void test_get_edge_Collections_not_found() throws ArangoException { + try { + driver.graphGetEdgeCollections("foo"); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorMessage(), is("graph not found")); + } + } + + @Test + public void test_create_edge_definition() throws ArangoException { + final String edgeCollectionName = "UnitTestEdgeCollection"; + final String fromCollectionName = "UnitTestFromCollection"; + final String toCollectionName = "UnitTestToCollection"; + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); + edgeDefinition.setCollection(edgeCollectionName); + final List from = new ArrayList(); + from.add(fromCollectionName); + edgeDefinition.setFrom(from); + final List to = new ArrayList(); + to.add(toCollectionName); + edgeDefinition.setTo(to); + driver.graphCreateEdgeDefinition(this.graphName, edgeDefinition); + assertThat(driver.graphGetEdgeCollections(this.graphName).contains(edgeCollectionName), is(true)); + } + + @Test + public void test_create_edge_definition_2_graphs() throws ArangoException { + final String graphName1 = "UnitTestGraph1"; + final String graphName2 = "UnitTestGraph2"; + final String edgeCollectionName = "UnitTestEdgeCollection"; + final String fromCollectionName = "UnitTestFromCollection"; + final String toCollectionName = "UnitTestToCollection"; + driver.createGraph(graphName1, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + driver.createGraph(graphName2, this.createEdgeDefinitions(2, 2), this.createOrphanCollections(2), true); + final EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); + edgeDefinition.setCollection(edgeCollectionName); + final List from = new ArrayList(); + from.add(fromCollectionName); + edgeDefinition.setFrom(from); + final List to = new ArrayList(); + to.add(toCollectionName); + edgeDefinition.setTo(to); + driver.graphCreateEdgeDefinition(graphName1, edgeDefinition); + driver.graphCreateEdgeDefinition(graphName2, edgeDefinition); + assertThat(driver.graphGetEdgeCollections(graphName1).contains(edgeCollectionName), is(true)); + assertThat(driver.graphGetEdgeCollections(graphName2).contains(edgeCollectionName), is(true)); + } + + @Test + public void test_replace_edge_definition() throws ArangoException { + final String edgeCollectionName = "UnitTestEdgeCollection"; + final String fromCollectionName1 = "UnitTestFromCollection1"; + final String fromCollectionName2 = "UnitTestFromCollection2"; + final String toCollectionName1 = "UnitTestToCollection1"; + final String toCollectionName2 = "UnitTestToCollection2"; + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + final EdgeDefinitionEntity edgeDefinition1 = new EdgeDefinitionEntity(); + edgeDefinition1.setCollection(edgeCollectionName); + final List from1 = new ArrayList(); + from1.add(fromCollectionName1); + edgeDefinition1.setFrom(from1); + final List to1 = new ArrayList(); + to1.add(toCollectionName1); + edgeDefinition1.setTo(to1); + driver.graphCreateEdgeDefinition(this.graphName, edgeDefinition1); + assertThat(driver.graphGetEdgeCollections(this.graphName).contains(edgeCollectionName), is(true)); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(fromCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(toCollectionName1), is(true)); + final EdgeDefinitionEntity edgeDefinition2 = new EdgeDefinitionEntity(); + edgeDefinition2.setCollection(edgeCollectionName); + final List from2 = new ArrayList(); + from2.add(fromCollectionName2); + edgeDefinition2.setFrom(from2); + final List to2 = new ArrayList(); + to2.add(toCollectionName2); + edgeDefinition2.setTo(to2); + final GraphEntity graph = driver.graphReplaceEdgeDefinition(this.graphName, edgeCollectionName, + edgeDefinition2); + final List edgeDefinitions = graph.getEdgeDefinitionsEntity().getEdgeDefinitions(); + for (final EdgeDefinitionEntity edgeDef : edgeDefinitions) { + final List f = edgeDef.getFrom(); + assertThat(f.contains(from1), is(false)); + final List t = edgeDef.getTo(); + assertThat(t.contains(to1), is(false)); + } + assertThat(driver.graphGetEdgeCollections(this.graphName).contains(edgeCollectionName), is(true)); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(fromCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(toCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(fromCollectionName2), is(true)); + assertThat(driver.graphGetVertexCollections(this.graphName).contains(toCollectionName2), is(true)); + } + + @Test + public void test_replace_edge_definition_2_graphs() throws ArangoException { + final String graphName1 = "UnitTestGraph1"; + final String graphName2 = "UnitTestGraph2"; + final String edgeCollectionName = "UnitTestEdgeCollection"; + final String fromCollectionName1 = "UnitTestFromCollection1"; + final String fromCollectionName2 = "UnitTestFromCollection2"; + final String toCollectionName1 = "UnitTestToCollection1"; + final String toCollectionName2 = "UnitTestToCollection2"; + driver.createGraph(graphName1, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + driver.createGraph(graphName2, this.createEdgeDefinitions(2, 2), this.createOrphanCollections(2), true); + final EdgeDefinitionEntity edgeDefinition1 = new EdgeDefinitionEntity(); + edgeDefinition1.setCollection(edgeCollectionName); + final List from1 = new ArrayList(); + from1.add(fromCollectionName1); + edgeDefinition1.setFrom(from1); + final List to1 = new ArrayList(); + to1.add(toCollectionName1); + edgeDefinition1.setTo(to1); + driver.graphCreateEdgeDefinition(graphName1, edgeDefinition1); + driver.graphCreateEdgeDefinition(graphName2, edgeDefinition1); + assertThat(driver.graphGetEdgeCollections(graphName1).contains(edgeCollectionName), is(true)); + assertThat(driver.graphGetVertexCollections(graphName1).contains(fromCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(graphName1).contains(toCollectionName1), is(true)); + assertThat(driver.graphGetEdgeCollections(graphName2).contains(edgeCollectionName), is(true)); + assertThat(driver.graphGetVertexCollections(graphName2).contains(fromCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(graphName2).contains(toCollectionName1), is(true)); + final EdgeDefinitionEntity edgeDefinition2 = new EdgeDefinitionEntity(); + edgeDefinition2.setCollection(edgeCollectionName); + final List from2 = new ArrayList(); + from2.add(fromCollectionName2); + edgeDefinition2.setFrom(from2); + final List to2 = new ArrayList(); + to2.add(toCollectionName2); + edgeDefinition2.setTo(to2); + final GraphEntity graph1 = driver.graphReplaceEdgeDefinition(graphName1, edgeCollectionName, edgeDefinition2); + final List edgeDefinitions1 = graph1.getEdgeDefinitionsEntity().getEdgeDefinitions(); + for (final EdgeDefinitionEntity edgeDef : edgeDefinitions1) { + final List f = edgeDef.getFrom(); + assertThat(f.contains(from1), is(false)); + final List t = edgeDef.getTo(); + assertThat(t.contains(to1), is(false)); + } + final GraphEntity graph2 = driver.graphReplaceEdgeDefinition(graphName1, edgeCollectionName, edgeDefinition2); + final List edgeDefinitions2 = graph2.getEdgeDefinitionsEntity().getEdgeDefinitions(); + for (final EdgeDefinitionEntity edgeDef : edgeDefinitions2) { + final List f = edgeDef.getFrom(); + assertThat(f.contains(from1), is(false)); + final List t = edgeDef.getTo(); + assertThat(t.contains(to1), is(false)); + } + assertThat(driver.graphGetEdgeCollections(graphName1).contains(edgeCollectionName), is(true)); + assertThat(driver.graphGetVertexCollections(graphName1).contains(fromCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(graphName1).contains(toCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(graphName1).contains(fromCollectionName2), is(true)); + assertThat(driver.graphGetVertexCollections(graphName1).contains(toCollectionName2), is(true)); + assertThat(driver.graphGetEdgeCollections(graphName2).contains(edgeCollectionName), is(true)); + assertThat(driver.graphGetVertexCollections(graphName2).contains(fromCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(graphName2).contains(toCollectionName1), is(true)); + assertThat(driver.graphGetVertexCollections(graphName2).contains(fromCollectionName2), is(true)); + assertThat(driver.graphGetVertexCollections(graphName2).contains(toCollectionName2), is(true)); + } + + @Test + public void test_delete_edge_definition_keep_collections() throws ArangoException { + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + driver.graphDeleteEdgeDefinition(this.graphName, "edge-1", false); + assertThat(driver.graphGetEdgeCollections(this.graphName).contains("edge-1"), is(false)); + assertThat(driver.graphGetEdgeCollections(this.graphName).contains("edge-2"), is(true)); + + } + + @Test + public void test_delete_edge_definition_drop_collections() throws ArangoException { + driver.createGraph(this.graphName, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); + driver.graphDeleteEdgeDefinition(this.graphName, "edge-1", true); + assertThat(driver.graphGetEdgeCollections(this.graphName).contains("edge-1"), is(false)); + assertThat(driver.graphGetEdgeCollections(this.graphName).contains("edge-2"), is(true)); + try { + driver.getCollection("edge-1"); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), greaterThan(300)); + } + + } } diff --git a/src/test/java/com/arangodb/ArangoDriverGraphVertexReplaceTest.java b/src/test/java/com/arangodb/ArangoDriverGraphVertexReplaceTest.java index 318c3577c..bed00f8d3 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphVertexReplaceTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphVertexReplaceTest.java @@ -33,12 +33,8 @@ */ public class ArangoDriverGraphVertexReplaceTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String collectionName = "UnitTestCollection"; - - public ArangoDriverGraphVertexReplaceTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String graphName = "UnitTestGraph"; + private final String collectionName = "UnitTestCollection"; @Test public void test_vertex_replace() throws ArangoException { @@ -48,15 +44,15 @@ public void test_vertex_replace() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("Homer", "Simpson", 38), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // replace - DocumentEntity updatedVertex = driver.graphReplaceVertex(this.graphName, + final DocumentEntity updatedVertex = driver.graphReplaceVertex(this.graphName, this.collectionName, v1.getDocumentKey(), new TestComplexEntity02(1, 2, 3)); assertThat(updatedVertex.getCode(), is(202)); assertThat(updatedVertex.isError(), is(false)); @@ -66,8 +62,8 @@ public void test_vertex_replace() throws ArangoException { assertThat(updatedVertex.getDocumentRevision(), is(not(0L))); assertThat(updatedVertex.getDocumentKey(), is(v1.getDocumentKey())); - DocumentEntity updatedVertex2 = driver.graphGetVertex(this.graphName, this.collectionName, - v1.getDocumentKey(), TestComplexEntity02.class); + final DocumentEntity updatedVertex2 = driver.graphGetVertex(this.graphName, + this.collectionName, v1.getDocumentKey(), TestComplexEntity02.class); assertThat(updatedVertex2.getEntity().getX(), is(1)); assertThat(updatedVertex2.getEntity().getY(), is(2)); assertThat(updatedVertex2.getEntity().getZ(), is(3)); @@ -83,7 +79,7 @@ public void test_vertex_replace_graph_not_found() throws ArangoException { try { driver.graphReplaceVertex(this.graphName, this.collectionName, "key1", new TestComplexEntity02(1, 2, 3)); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorMessage(), is("graph not found")); } @@ -101,7 +97,7 @@ public void test_vertex_replace_vertex_not_found() throws ArangoException { try { driver.graphReplaceVertex(this.graphName, this.collectionName, "key1", new TestComplexEntity02(1, 2, 3)); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); } @@ -115,16 +111,16 @@ public void test_vertex_replace_rev_eq() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("Homer", "Simpson", 38), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // replace - VertexEntity updatedVertex = driver.graphReplaceVertex(this.graphName, this.collectionName, - v1.getDocumentKey(), new TestComplexEntity02(1, 2, 3)); + final VertexEntity updatedVertex = driver.graphReplaceVertex(this.graphName, + this.collectionName, v1.getDocumentKey(), new TestComplexEntity02(1, 2, 3)); assertThat(updatedVertex.getCode(), is(202)); assertThat(updatedVertex.isError(), is(false)); @@ -133,8 +129,8 @@ public void test_vertex_replace_rev_eq() throws ArangoException { assertThat(updatedVertex.getDocumentRevision(), is(not(0L))); assertThat(updatedVertex.getDocumentKey(), is(v1.getDocumentKey())); - VertexEntity updatedVertex2 = driver.graphGetVertex(this.graphName, this.collectionName, - v1.getDocumentKey(), TestComplexEntity02.class); + final VertexEntity updatedVertex2 = driver.graphGetVertex(this.graphName, + this.collectionName, v1.getDocumentKey(), TestComplexEntity02.class); assertThat(updatedVertex2.getEntity().getX(), is(1)); assertThat(updatedVertex2.getEntity().getY(), is(2)); assertThat(updatedVertex2.getEntity().getZ(), is(3)); @@ -152,20 +148,20 @@ public void test_vertex_replace_rev_ne() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("Homer", "Simpson", 38), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // replace try { - Long rev = 1L; + final Long rev = 1L; driver.graphReplaceVertex(this.graphName, this.collectionName, v1.getDocumentKey(), new TestComplexEntity02(1, 2, 3), true, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); @@ -181,17 +177,17 @@ public void test_vertex_replace_ifmatch_eq() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("Homer", "Simpson", 38), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // replace - Long rev = vertex.getDocumentRevision(); - VertexEntity updatedVertex = driver.graphReplaceVertex(this.graphName, this.collectionName, - v1.getDocumentKey(), new TestComplexEntity02(1, 2, 3), true, rev, null); + final Long rev = vertex.getDocumentRevision(); + final VertexEntity updatedVertex = driver.graphReplaceVertex(this.graphName, + this.collectionName, v1.getDocumentKey(), new TestComplexEntity02(1, 2, 3), true, rev, null); assertThat(updatedVertex.getCode(), is(200)); assertThat(updatedVertex.isError(), is(false)); @@ -200,8 +196,8 @@ public void test_vertex_replace_ifmatch_eq() throws ArangoException { assertThat(updatedVertex.getDocumentRevision(), is(not(0L))); assertThat(updatedVertex.getDocumentKey(), is(v1.getDocumentKey())); - DocumentEntity updatedVertex2 = driver.graphGetVertex(this.graphName, this.collectionName, - v1.getDocumentKey(), TestComplexEntity02.class); + final DocumentEntity updatedVertex2 = driver.graphGetVertex(this.graphName, + this.collectionName, v1.getDocumentKey(), TestComplexEntity02.class); assertThat(updatedVertex2.getEntity().getX(), is(1)); assertThat(updatedVertex2.getEntity().getY(), is(2)); assertThat(updatedVertex2.getEntity().getZ(), is(3)); @@ -219,20 +215,20 @@ public void test_vertex_replace_ifmatch_ne() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("xxx", "yyy", 10), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // replace try { - Long rev = 1L; + final Long rev = 1L; driver.graphReplaceVertex(this.graphName, this.collectionName, v1.getDocumentKey(), new TestComplexEntity02(1, 2, 3), true, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); diff --git a/src/test/java/com/arangodb/ArangoDriverGraphVertexTest.java b/src/test/java/com/arangodb/ArangoDriverGraphVertexTest.java index e12e2f8dd..75ee41f5d 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphVertexTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphVertexTest.java @@ -47,29 +47,25 @@ public class ArangoDriverGraphVertexTest extends BaseGraphTest { private final static String GRAPH_NAME = "UnitTestGraph"; private final static String COLLECTION_NAME = "UnitTestCollection"; - public ArangoDriverGraphVertexTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Before public void setup() throws ArangoException { try { driver.createGraph(GRAPH_NAME, this.createEdgeDefinitions(2, 0), this.createOrphanCollections(2), true); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @Test public void test_create_vertex() throws ArangoException { - VertexEntity vertex = driver.graphCreateVertex(GRAPH_NAME, "from1-1", + final VertexEntity vertex = driver.graphCreateVertex(GRAPH_NAME, "from1-1", new TestComplexEntity01("Homer", "Simpson", 38), true); assertThat(vertex.getDocumentHandle(), is(notNullValue())); assertThat(vertex.getDocumentRevision(), is(not(0L))); assertThat(vertex.getDocumentKey(), is(notNullValue())); assertThat(vertex.getEntity(), isA(TestComplexEntity01.class)); - DocumentEntity document = driver.getDocument(vertex.getDocumentHandle(), + final DocumentEntity document = driver.getDocument(vertex.getDocumentHandle(), TestComplexEntity01.class); assertThat(document.getEntity().getUser(), is("Homer")); assertThat(document.getEntity().getDesc(), is("Simpson")); @@ -79,7 +75,7 @@ public void test_create_vertex() throws ArangoException { @Test public void test_create_vertex_with_document_attributes() throws ArangoException { - VertexEntity vertex = driver.graphCreateVertex(GRAPH_NAME, "from1-1", + final VertexEntity vertex = driver.graphCreateVertex(GRAPH_NAME, "from1-1", new TestComplexEntity03("Homer", "Simpson", 38), true); assertThat(vertex.getDocumentHandle(), is(notNullValue())); @@ -91,7 +87,7 @@ public void test_create_vertex_with_document_attributes() throws ArangoException assertThat(vertex.getEntity().getDocumentKey(), is(notNullValue())); assertThat(vertex.getEntity().getDocumentRevision(), is(notNullValue())); - DocumentEntity document = driver.getDocument(vertex.getDocumentHandle(), + final DocumentEntity document = driver.getDocument(vertex.getDocumentHandle(), TestComplexEntity03.class); assertThat(document.getEntity().getUser(), is("Homer")); assertThat(document.getEntity().getDesc(), is("Simpson")); @@ -105,7 +101,7 @@ public void test_create_vertex_error_graph() throws ArangoException { try { driver.graphCreateVertex("foo", "bar", new TestComplexEntity01("Homer", "Simpson", 38), true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), greaterThan(300)); } @@ -117,7 +113,7 @@ public void test_create_vertex_error_collection() throws ArangoException { try { driver.graphCreateVertex(GRAPH_NAME, "foo", new TestComplexEntity01("Homer", "Simpson", 38), true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), greaterThan(300)); } @@ -130,7 +126,7 @@ public void test_graphGetVertex() throws ArangoException { try { vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, vertex.getDocumentKey(), TestComplexEntity01.class, vertex.getDocumentRevision(), null); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), greaterThan(300)); } @@ -145,17 +141,17 @@ public void test_delete_vertex() throws ArangoException { // create collection driver.graphCreateVertexCollection(GRAPH_NAME, COLLECTION_NAME); // create vertex - VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, new TestComplexEntity01("Homer", "Simpson", 38), true); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), TestComplexEntity01.class); assertThat(vertex.getCode(), is(200)); // delete - DeletedEntity deleted = driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), true, null, - null); + final DeletedEntity deleted = driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), true, + null, null); assertThat(deleted.getCode(), is(200)); assertThat(deleted.getDeleted(), is(true)); @@ -167,7 +163,7 @@ public void test_delete_vertex_graph_not_found() throws ArangoException { try { driver.graphDeleteVertex("foo", "bar", "foobar", true, null, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1924)); } @@ -181,7 +177,7 @@ public void test_delete_vertex_not_found() throws ArangoException { try { driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, "foo", true, null, null); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); } @@ -192,14 +188,14 @@ public void test_delete_vertex_rev_eq() throws ArangoException { driver.graphCreateVertexCollection(GRAPH_NAME, COLLECTION_NAME); - VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, new TestComplexEntity01("Hoemr", "Simpson", 38), null); - VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // delete - DeletedEntity deleted = driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), null, + final DeletedEntity deleted = driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), null, v1.getDocumentRevision(), null); assertThat(deleted.getCode(), is(202)); assertThat(deleted.getDeleted(), is(true)); @@ -211,9 +207,9 @@ public void test_delete_vertex_rev_ng() throws ArangoException { driver.graphCreateVertexCollection(GRAPH_NAME, COLLECTION_NAME); - VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, new TestComplexEntity01("Homer", "Simspin", 38), null); - VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); @@ -221,7 +217,7 @@ public void test_delete_vertex_rev_ng() throws ArangoException { try { driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), null, v1.getDocumentRevision() + 1, null); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); @@ -233,14 +229,14 @@ public void test_delete_vertex_rev_ng() throws ArangoException { public void test_delete_vertex_match_eq() throws ArangoException { driver.graphCreateVertexCollection(GRAPH_NAME, COLLECTION_NAME); - VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, new TestComplexEntity01("Homer", "Simpson", 38), null); - VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // delete - DeletedEntity deleted = driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), null, + final DeletedEntity deleted = driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), null, v1.getDocumentRevision(), null); assertThat(deleted.getCode(), is(202)); assertThat(deleted.getDeleted(), is(true)); @@ -251,9 +247,9 @@ public void test_delete_vertex_match_eq() throws ArangoException { public void test_delete_vertex_match_ng() throws ArangoException { driver.graphCreateVertexCollection(GRAPH_NAME, COLLECTION_NAME); - VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity v1 = driver.graphCreateVertex(GRAPH_NAME, COLLECTION_NAME, new TestComplexEntity01("Homer", "Simpson", 38), null); - VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, + final VertexEntity vertex = driver.graphGetVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); @@ -261,7 +257,7 @@ public void test_delete_vertex_match_ng() throws ArangoException { try { driver.graphDeleteVertex(GRAPH_NAME, COLLECTION_NAME, v1.getDocumentKey(), null, null, v1.getDocumentRevision() + 1); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); @@ -271,15 +267,15 @@ public void test_delete_vertex_match_ng() throws ArangoException { @Test public void graphGetVertexCursorTest() throws ArangoException { - TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); - TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); - TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); - TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); - VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); - VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); - VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); - VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(1, 2, 3), null); @@ -294,7 +290,7 @@ public void graphGetVertexCursorTest() throws ArangoException { new TestComplexEntity02(10, 11, 12), null); // setCount = true - AqlQueryOptions aqlQueryOptions = driver.getDefaultAqlQueryOptions().setCount(true); + final AqlQueryOptions aqlQueryOptions = driver.getDefaultAqlQueryOptions().setCount(true); VertexCursor vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, TestComplexEntity01.class, null, null, aqlQueryOptions); @@ -306,7 +302,7 @@ public void graphGetVertexCursorTest() throws ArangoException { assertEquals(1, vertexCursor.getCount()); assertEquals(201, vertexCursor.getCode()); - GraphVerticesOptions graphVerticesOptions = new GraphVerticesOptions(); + final GraphVerticesOptions graphVerticesOptions = new GraphVerticesOptions(); graphVerticesOptions.setDirection(Direction.INBOUND); vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, TestComplexEntity01.class, null, graphVerticesOptions, @@ -314,7 +310,7 @@ public void graphGetVertexCursorTest() throws ArangoException { assertEquals(2, vertexCursor.getCount()); assertEquals(201, vertexCursor.getCode()); - List vertexCollectionRestriction = new ArrayList(); + final List vertexCollectionRestriction = new ArrayList(); vertexCollectionRestriction.add("from1-1"); graphVerticesOptions.setVertexCollectionRestriction(vertexCollectionRestriction); @@ -328,35 +324,35 @@ public void graphGetVertexCursorTest() throws ArangoException { @Test public void test_replace_vertex_with_document_attributes() throws ArangoException { - VertexEntity vertex = driver.graphCreateVertex(GRAPH_NAME, "from1-1", + final VertexEntity vertex = driver.graphCreateVertex(GRAPH_NAME, "from1-1", new TestComplexEntity03("Homer", "Simpson", 38), true); assertThat(vertex.getDocumentHandle(), is(notNullValue())); assertThat(vertex.getDocumentRevision(), is(not(0L))); assertThat(vertex.getDocumentKey(), is(notNullValue())); - TestComplexEntity03 en1 = vertex.getEntity(); + final TestComplexEntity03 en1 = vertex.getEntity(); assertThat(en1, isA(TestComplexEntity03.class)); assertThat(en1.getDocumentHandle(), is(notNullValue())); assertThat(en1.getDocumentKey(), is(notNullValue())); assertThat(en1.getDocumentRevision(), is(notNullValue())); - Long rev = en1.getDocumentRevision(); + final Long rev = en1.getDocumentRevision(); en1.setUser("Tim"); - DocumentEntity document2 = driver.graphReplaceVertex(GRAPH_NAME, "from1-1", + final DocumentEntity document2 = driver.graphReplaceVertex(GRAPH_NAME, "from1-1", en1.getDocumentKey(), en1); assertThat(document2.getEntity().getUser(), is("Tim")); assertThat(document2.getEntity().getDesc(), is("Simpson")); assertThat(document2.getEntity().getAge(), is(38)); - TestComplexEntity03 en2 = document2.getEntity(); + final TestComplexEntity03 en2 = document2.getEntity(); assertThat(en2.getDocumentHandle(), is(notNullValue())); assertThat(en2.getDocumentKey(), is(notNullValue())); assertThat(en2.getDocumentRevision(), is(notNullValue())); assertThat(en2.getDocumentRevision(), is(not(rev))); - Long rev2 = en2.getDocumentRevision(); + final Long rev2 = en2.getDocumentRevision(); - DocumentEntity document = driver.getDocument(vertex.getDocumentHandle(), + final DocumentEntity document = driver.getDocument(vertex.getDocumentHandle(), TestComplexEntity03.class); assertThat(document.getEntity().getUser(), is("Tim")); assertThat(document.getEntity().getDesc(), is("Simpson")); @@ -367,27 +363,27 @@ public void test_replace_vertex_with_document_attributes() throws ArangoExceptio @Test public void test_update_vertex_with_document_attributes() throws ArangoException { - VertexEntity vertex = driver.graphCreateVertex(GRAPH_NAME, "from1-1", + final VertexEntity vertex = driver.graphCreateVertex(GRAPH_NAME, "from1-1", new TestComplexEntity03("Homer", "Simpson", 38), true); assertThat(vertex.getDocumentHandle(), is(notNullValue())); assertThat(vertex.getDocumentRevision(), is(not(0L))); assertThat(vertex.getDocumentKey(), is(notNullValue())); - Long rev = vertex.getDocumentRevision(); + final Long rev = vertex.getDocumentRevision(); - TestComplexEntity03 en1 = new TestComplexEntity03("Tim", null, null); + final TestComplexEntity03 en1 = new TestComplexEntity03("Tim", null, null); - DocumentEntity document2 = driver.graphUpdateVertex(GRAPH_NAME, "from1-1", + final DocumentEntity document2 = driver.graphUpdateVertex(GRAPH_NAME, "from1-1", vertex.getDocumentKey(), en1, true); assertThat(document2.getEntity().getUser(), is("Tim")); - TestComplexEntity03 en2 = document2.getEntity(); + final TestComplexEntity03 en2 = document2.getEntity(); assertThat(en2.getDocumentHandle(), is(notNullValue())); assertThat(en2.getDocumentKey(), is(notNullValue())); assertThat(en2.getDocumentRevision(), is(notNullValue())); assertThat(en2.getDocumentRevision(), is(not(rev))); - Long rev2 = en2.getDocumentRevision(); + final Long rev2 = en2.getDocumentRevision(); - DocumentEntity document = driver.getDocument(vertex.getDocumentHandle(), + final DocumentEntity document = driver.getDocument(vertex.getDocumentHandle(), TestComplexEntity03.class); assertThat(document.getEntity().getUser(), is("Tim")); assertThat(document.getEntity().getDesc(), is("Simpson")); diff --git a/src/test/java/com/arangodb/ArangoDriverGraphVertexUpdateTest.java b/src/test/java/com/arangodb/ArangoDriverGraphVertexUpdateTest.java index 76a2ca975..351854a9e 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphVertexUpdateTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphVertexUpdateTest.java @@ -34,12 +34,8 @@ */ public class ArangoDriverGraphVertexUpdateTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String collectionName = "UnitTestCollection"; - - public ArangoDriverGraphVertexUpdateTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String graphName = "UnitTestGraph"; + private final String collectionName = "UnitTestCollection"; @Test public void test_vertex_update_keep_null() throws ArangoException { @@ -49,10 +45,10 @@ public void test_vertex_update_keep_null() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("Homa", "Simpson", 83), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); @@ -87,10 +83,10 @@ public void test_vertex_update_keep_null_false() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("Homer", "A Sompsin", 83), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); @@ -125,7 +121,7 @@ public void test_vertex_update_graph_not_found() throws ArangoException { driver.graphUpdateVertex(this.graphName, this.collectionName, "xx", new TestComplexEntity01("zzz", null, 99), true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorMessage(), startsWith("graph not found")); } @@ -143,7 +139,7 @@ public void test_vertex_update_collection_not_found() throws ArangoException { driver.graphUpdateVertex(this.graphName, this.collectionName, "xx", new TestComplexEntity01("zzz", null, 99), true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorMessage(), startsWith("collection not found")); } @@ -158,15 +154,15 @@ public void test_vertex_update_rev_eq() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("xxx", "yyy", 83), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // update - Long rev = vertex.getDocumentRevision(); + final Long rev = vertex.getDocumentRevision(); DocumentEntity updatedVertex = driver.graphUpdateVertex(this.graphName, this.collectionName, vertex.getDocumentKey(), new TestComplexEntity01("zzz", null, 99), null, true, rev, null); @@ -198,20 +194,20 @@ public void test_vertex_update_rev_ne() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("xxx", "yyy", 83), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // update try { - Long rev = vertex.getDocumentRevision() + 1; + final Long rev = vertex.getDocumentRevision() + 1; driver.graphUpdateVertex(this.graphName, this.collectionName, vertex.getDocumentKey(), new TestComplexEntity01("zzz", null, 99), null, true, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); @@ -227,15 +223,15 @@ public void test_vertex_update_ifmatch_eq() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("xxx", "yyy", 83), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // update - Long rev = vertex.getDocumentRevision(); + final Long rev = vertex.getDocumentRevision(); VertexEntity updatedVertex = driver.graphUpdateVertex(this.graphName, this.collectionName, vertex.getDocumentKey(), new TestComplexEntity01("zzz", null, 99), null, true, rev, null); assertThat(updatedVertex.getCode(), is(200)); @@ -266,20 +262,20 @@ public void test_vertex_update_ifmatch_ne() throws ArangoException { // create vertex collection driver.graphCreateVertexCollection(this.graphName, this.collectionName); // create vertex - VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, + final VertexEntity v1 = driver.graphCreateVertex(this.graphName, this.collectionName, new TestComplexEntity01("Homer", "A Sompsin", 83), null); // check exists vertex - VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, + final VertexEntity vertex = driver.graphGetVertex(this.graphName, this.collectionName, v1.getDocumentKey(), TestComplexEntity01.class, null, null); assertThat(vertex.getCode(), is(200)); // update try { - Long rev = vertex.getDocumentRevision() + 1; + final Long rev = vertex.getDocumentRevision() + 1; driver.graphUpdateVertex(this.graphName, this.collectionName, vertex.getDocumentKey(), new TestComplexEntity01("zzz", null, 99), null, true, rev, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(412)); assertThat(e.getErrorNumber(), is(1903)); assertThat(e.getErrorMessage(), is("wrong revision")); diff --git a/src/test/java/com/arangodb/ArangoDriverImportTest.java b/src/test/java/com/arangodb/ArangoDriverImportTest.java index 474190c54..e6b6cf890 100644 --- a/src/test/java/com/arangodb/ArangoDriverImportTest.java +++ b/src/test/java/com/arangodb/ArangoDriverImportTest.java @@ -40,27 +40,23 @@ public class ArangoDriverImportTest extends BaseTest { private static final String UT_IMPORT_TEST = "ut-import-test"; - public ArangoDriverImportTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Before public void setUp() { try { driver.deleteCollection(UT_IMPORT_TEST); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection(UT_IMPORT_TEST); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @Test public void test_import_documents() throws ArangoException, IOException { - List stations = TestUtils.readStations(); - ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, stations); + final List stations = TestUtils.readStations(); + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, stations); assertThat(result.getStatusCode(), is(201)); assertThat(result.isError(), is(false)); @@ -75,14 +71,14 @@ public void test_import_documents_404() throws ArangoException, IOException { try { driver.deleteCollection(UT_IMPORT_TEST); - } catch (ArangoException e) { + } catch (final ArangoException e) { } - List stations = TestUtils.readStations(); + final List stations = TestUtils.readStations(); try { driver.importDocuments(UT_IMPORT_TEST, stations); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } @@ -92,12 +88,12 @@ public void test_import_documents_404() throws ArangoException, IOException { @Test public void test_import_xsv() throws ArangoException, IOException { - List> values = new ArrayList>(); + final List> values = new ArrayList>(); values.add(Arrays.asList("firstName", "lastName", "age", "gender")); values.add(Arrays.asList("Joe", "Public", 42, "male")); values.add(Arrays.asList("Jane", "Doe", 31, "female")); - ImportResultEntity result = driver.importDocumentsByHeaderValues(UT_IMPORT_TEST, values); + final ImportResultEntity result = driver.importDocumentsByHeaderValues(UT_IMPORT_TEST, values); assertThat(result.getStatusCode(), is(201)); assertThat(result.isError(), is(false)); @@ -110,12 +106,12 @@ public void test_import_xsv() throws ArangoException, IOException { @Test public void test_import_xsv_errors() throws ArangoException, IOException { - List> values = new ArrayList>(); + final List> values = new ArrayList>(); values.add(Arrays.asList("firstName", "lastName", "age", "gender")); values.add(Arrays.asList("Joe", "Public", 42, "male", 10)); // error values.add(Arrays.asList("Jane", "Doe", 31, "female")); - ImportResultEntity result = driver.importDocumentsByHeaderValues(UT_IMPORT_TEST, values); + final ImportResultEntity result = driver.importDocumentsByHeaderValues(UT_IMPORT_TEST, values); assertThat(result.getStatusCode(), is(201)); assertThat(result.isError(), is(false)); @@ -130,10 +126,10 @@ public void test_import_xsv_404() throws ArangoException, IOException { try { driver.deleteCollection(UT_IMPORT_TEST); - } catch (ArangoException e) { + } catch (final ArangoException e) { } - List> values = new ArrayList>(); + final List> values = new ArrayList>(); values.add(Arrays.asList("firstName", "lastName", "age", "gender")); values.add(Arrays.asList("Joe", "Public", 42, "male", 10)); // error values.add(Arrays.asList("Jane", "Doe", 31, "female")); @@ -141,7 +137,7 @@ public void test_import_xsv_404() throws ArangoException, IOException { try { driver.importDocuments(UT_IMPORT_TEST, values); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1203)); } diff --git a/src/test/java/com/arangodb/ArangoDriverIndexTest.java b/src/test/java/com/arangodb/ArangoDriverIndexTest.java index d6fd55a2a..c2bd4636c 100644 --- a/src/test/java/com/arangodb/ArangoDriverIndexTest.java +++ b/src/test/java/com/arangodb/ArangoDriverIndexTest.java @@ -43,14 +43,10 @@ */ public class ArangoDriverIndexTest extends BaseTest { - public ArangoDriverIndexTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - private static Logger logger = LoggerFactory.getLogger(ArangoDriverCollectionTest.class); - final String collectionName = "unit_test_arango_index"; // - final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 + private final String collectionName = "unit_test_arango_index"; // + private final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 CollectionEntity col1; @@ -62,11 +58,11 @@ public void before() throws ArangoException { // 事前に消しておく try { driver.deleteCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.deleteCollection(collectionName404); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // 1は作る @@ -85,7 +81,7 @@ public void after() { public void test_create_index() throws ArangoException { { - IndexEntity entity = driver.createIndex(collectionName, IndexType.GEO, false, "a"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.GEO, false, "a"); assertThat(entity, is(notNullValue())); assertThat(entity.getCode(), is(201)); @@ -98,7 +94,7 @@ public void test_create_index() throws ArangoException { // 重複して作成する { - IndexEntity entity = driver.createIndex(collectionName, IndexType.GEO, false, "a"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.GEO, false, "a"); assertThat(entity, is(notNullValue())); assertThat(entity.getCode(), is(200)); @@ -117,7 +113,7 @@ public void test_create_index_404() throws ArangoException { try { driver.createIndex(collectionName404, IndexType.GEO, false, "a"); fail("We expect an Exception here"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(1203)); // FIXME MagicNumber } @@ -126,7 +122,7 @@ public void test_create_index_404() throws ArangoException { @Test public void test_create_geo_index_unique() throws ArangoException { - IndexEntity entity = driver.createIndex(collectionName, IndexType.GEO, true, "a", "b"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.GEO, true, "a", "b"); assertThat(entity, is(notNullValue())); assertThat(entity.getCode(), is(201)); @@ -146,7 +142,7 @@ public void test_create_geo_index_over_columnnum() throws ArangoException { try { driver.createIndex(collectionName, IndexType.GEO, true, "a", "b", "c"); fail("We expect an Exception here"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_BAD_PARAMETER)); } @@ -155,8 +151,8 @@ public void test_create_geo_index_over_columnnum() throws ArangoException { @Test public void test_create_hash_index() throws ArangoException { - IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, false, "a", "b", "c", "d", "e", "f", - "g"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, false, "a", "b", "c", "d", "e", + "f", "g"); assertThat(entity, is(notNullValue())); assertThat(entity.getCode(), is(201)); @@ -174,7 +170,7 @@ public void test_create_hash_index_404() throws ArangoException { try { driver.createIndex(collectionName404, IndexType.HASH, false, "a", "b", "c", "d", "e", "f", "g"); fail("We expect an Exception here"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_COLLECTION_NOT_FOUND)); } @@ -183,8 +179,8 @@ public void test_create_hash_index_404() throws ArangoException { @Test public void test_create_hash_index_unique() throws ArangoException { - IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "a", "b", "c", "d", "e", "f", - "g"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "a", "b", "c", "d", "e", + "f", "g"); assertThat(entity, is(notNullValue())); assertThat(entity.getCode(), is(201)); @@ -199,8 +195,8 @@ public void test_create_hash_index_unique() throws ArangoException { @Test public void test_create_skiplist_index() throws ArangoException { - IndexEntity entity = driver.createIndex(collectionName, IndexType.SKIPLIST, false, "a", "b", "c", "d", "e", "f", - "g"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.SKIPLIST, false, "a", "b", "c", "d", + "e", "f", "g"); assertThat(entity, is(notNullValue())); assertThat(entity.getCode(), is(201)); @@ -215,8 +211,8 @@ public void test_create_skiplist_index() throws ArangoException { @Test public void test_create_skiplist_index_unique() throws ArangoException { - IndexEntity entity = driver.createIndex(collectionName, IndexType.SKIPLIST, true, "a", "b", "c", "d", "e", "f", - "g"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.SKIPLIST, true, "a", "b", "c", "d", "e", + "f", "g"); assertThat(entity, is(notNullValue())); assertThat(entity.getCode(), is(201)); @@ -232,12 +228,12 @@ public void test_create_skiplist_index_unique() throws ArangoException { public void test_create_hash_index_with_document() throws ArangoException { for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + i, "", i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + i, "", i); assertThat(driver.createDocument(collectionName, value, false, false), is(notNullValue())); } - IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "name", "age"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "name", "age"); assertThat(entity, is(notNullValue())); assertThat(entity.getCode(), is(201)); @@ -254,13 +250,13 @@ public void test_create_fulltext_index() throws ArangoException { // create test data 100 count. for (int i = 0; i < 100; i++) { - String desc = i % 2 == 0 ? "寿司" : "天ぷら"; - TestComplexEntity01 value = new TestComplexEntity01("user_" + i, desc, i); + final String desc = i % 2 == 0 ? "寿司" : "天ぷら"; + final TestComplexEntity01 value = new TestComplexEntity01("user_" + i, desc, i); assertThat(driver.createDocument(collectionName, value, false, false), is(notNullValue())); } // create fulltext index - IndexEntity index = driver.createFulltextIndex(collectionName, 1, "desc"); + final IndexEntity index = driver.createFulltextIndex(collectionName, 1, "desc"); // {"id":"unit_test_arango_index/6420761720","unique":false,"type":"fulltext","minLength":1,"fields":["desc"],"isNewlyCreated":true,"error":false,"code":201} assertThat(index.getCode(), is(201)); @@ -277,13 +273,13 @@ public void test_create_fulltext_index() throws ArangoException { @Test public void test_delete_index() throws ArangoException { - IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "name", "age"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "name", "age"); assertThat(entity, is(notNullValue())); assertThat(entity.getId(), is(notNullValue())); - String id = entity.getId(); + final String id = entity.getId(); - IndexEntity entity2 = driver.deleteIndex(id); + final IndexEntity entity2 = driver.deleteIndex(id); assertThat(entity2, is(notNullValue())); assertThat(entity2.getCode(), is(200)); @@ -299,7 +295,7 @@ public void test_delete_index_pk() throws ArangoException { try { driver.deleteIndex(collectionName + "/0"); fail("例外が飛ばないといけない"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(1212)); } @@ -313,7 +309,7 @@ public void test_delete_index_404_1() throws ArangoException { try { driver.deleteIndex(collectionName + "/1"); fail("例外が飛ばないといけない"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(1212)); } @@ -328,7 +324,7 @@ public void test_delete_index_404_1() throws ArangoException { @Ignore public void test_create_hash_index_dup_unique() throws ArangoException { - IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "user", "age"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "user", "age"); assertThat(driver.createDocument(collectionName, new TestComplexEntity01("寿司天ぷら", "", 18), false, false), is(notNullValue())); @@ -348,10 +344,10 @@ public void test_create_hash_index_dup_unique() throws ArangoException { @Test public void test_getIndexes() throws ArangoException { - IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "name", "age"); + final IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "name", "age"); assertThat(entity, is(notNullValue())); - IndexesEntity indexes = driver.getIndexes(collectionName); + final IndexesEntity indexes = driver.getIndexes(collectionName); assertThat(indexes, is(notNullValue())); @@ -364,8 +360,8 @@ public void test_getIndexes() throws ArangoException { assertThat(indexes.getIndexes().get(1).getFields().get(1), is("name")); assertThat(indexes.getIndexes().get(1).getFields().get(0), is("age")); - String id1 = indexes.getIndexes().get(0).getId(); - String id2 = indexes.getIndexes().get(1).getId(); + final String id1 = indexes.getIndexes().get(0).getId(); + final String id2 = indexes.getIndexes().get(1).getId(); assertThat(indexes.getIdentifiers().size(), is(2)); assertThat(indexes.getIdentifiers().get(id1).getType(), is(IndexType.PRIMARY)); diff --git a/src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java b/src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java index 84e5c14ec..c2603b237 100644 --- a/src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java +++ b/src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.junit.Before; import org.junit.Test; import com.arangodb.entity.DefaultEntity; @@ -32,18 +31,10 @@ */ public class ArangoDriverQueryCacheTest extends BaseTest { - public ArangoDriverQueryCacheTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - @Before - public void setup() throws ArangoException { - } - @Test public void test_deleteQueryCache() throws ArangoException { if (isMinimumVersion(TestUtils.VERSION_2_7)) { - DefaultEntity ret = driver.deleteQueryCache(); + final DefaultEntity ret = driver.deleteQueryCache(); assertEquals(200, ret.getStatusCode()); assertEquals(200, ret.getCode()); assertEquals(false, ret.isError()); @@ -53,7 +44,7 @@ public void test_deleteQueryCache() throws ArangoException { @Test public void test_getQueryCacheProperties() throws ArangoException { if (isMinimumVersion(TestUtils.VERSION_2_7)) { - QueryCachePropertiesEntity ret = driver.getQueryCacheProperties(); + final QueryCachePropertiesEntity ret = driver.getQueryCacheProperties(); assertEquals(200, ret.getStatusCode()); assertNotNull(ret.getMode()); assertNotNull(ret.getMaxResults()); @@ -62,11 +53,11 @@ public void test_getQueryCacheProperties() throws ArangoException { @Test public void test_setQueryCacheProperties() throws ArangoException { - String on = "on"; - String off = "off"; + final String on = "on"; + final String off = "off"; if (isMinimumVersion(TestUtils.VERSION_2_7)) { - QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity(); + final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity(); properties.setMode(on); properties.setMaxResults(100L); diff --git a/src/test/java/com/arangodb/ArangoDriverQueryTest.java b/src/test/java/com/arangodb/ArangoDriverQueryTest.java index 2d3cfd11f..4ef1ccb18 100644 --- a/src/test/java/com/arangodb/ArangoDriverQueryTest.java +++ b/src/test/java/com/arangodb/ArangoDriverQueryTest.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; -import org.junit.Before; import org.junit.Test; import com.arangodb.entity.DefaultEntity; @@ -38,17 +37,9 @@ */ public class ArangoDriverQueryTest extends BaseTest { - public ArangoDriverQueryTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - @Before - public void setup() throws ArangoException { - } - @Test public void test_getQueryTrackingProperties() throws ArangoException { - QueryTrackingPropertiesEntity queryTrackingProperties = driver.getQueryTrackingProperties(); + final QueryTrackingPropertiesEntity queryTrackingProperties = driver.getQueryTrackingProperties(); assertEquals(200, queryTrackingProperties.getStatusCode()); assertNotNull(queryTrackingProperties.getEnabled()); assertNotNull(queryTrackingProperties.getTrackSlowQueries()); @@ -59,13 +50,13 @@ public void test_getQueryTrackingProperties() throws ArangoException { @Test public void test_setQueryTrackingProperties() throws ArangoException { - QueryTrackingPropertiesEntity properties1 = driver.getQueryTrackingProperties(); + final QueryTrackingPropertiesEntity properties1 = driver.getQueryTrackingProperties(); - Long maxQueryStringLength = properties1.getMaxQueryStringLength() + 10; + final Long maxQueryStringLength = properties1.getMaxQueryStringLength() + 10; properties1.setMaxQueryStringLength(maxQueryStringLength); - QueryTrackingPropertiesEntity properties2 = driver.setQueryTrackingProperties(properties1); + final QueryTrackingPropertiesEntity properties2 = driver.setQueryTrackingProperties(properties1); assertEquals(200, properties2.getStatusCode()); assertNotNull(properties2.getEnabled()); @@ -79,85 +70,86 @@ public void test_setQueryTrackingProperties() throws ArangoException { @Test public void test_getCurrentlyRunningQueries() throws ArangoException, InterruptedException { - String queryString = "return sleep(3)"; + final String queryString = "return sleep(3)"; - Thread thread1 = new Thread(new RunnableThread(driver.getDefaultDatabase(), configure, queryString), "thread1"); + final Thread thread1 = new Thread(new RunnableThread(driver.getDefaultDatabase(), configure, queryString), + "thread1"); thread1.start(); Thread.sleep(1000); - QueriesResultEntity currentlyRunningQueries = driver.getCurrentlyRunningQueries(); + final QueriesResultEntity currentlyRunningQueries = driver.getCurrentlyRunningQueries(); // wait for thread thread1.join(); // check result assertEquals(200, currentlyRunningQueries.getStatusCode()); - List queries = currentlyRunningQueries.getQueries(); + final List queries = currentlyRunningQueries.getQueries(); assertEquals(1, queries.size()); } @Test public void test_getCurrentlyRunningQueriesWithoutDatabase() throws ArangoException, InterruptedException { - String queryString = "return sleep(3)"; + final String queryString = "return sleep(3)"; // create job in _system database - Thread thread1 = new Thread(new RunnableThread(null, configure, queryString), "thread1"); + final Thread thread1 = new Thread(new RunnableThread(null, configure, queryString), "thread1"); thread1.start(); Thread.sleep(1000); // search in default database - QueriesResultEntity currentlyRunningQueries = driver.getCurrentlyRunningQueries(); + final QueriesResultEntity currentlyRunningQueries = driver.getCurrentlyRunningQueries(); // wait for thread thread1.join(); // check result assertEquals(200, currentlyRunningQueries.getStatusCode()); - List queries = currentlyRunningQueries.getQueries(); + final List queries = currentlyRunningQueries.getQueries(); assertEquals(0, queries.size()); } @Test public void test_getCurrentlyRunningQueriesWithoutDatabase2() throws ArangoException, InterruptedException { - String queryString = "return sleep(3)"; + final String queryString = "return sleep(3)"; // create job in _system database - Thread thread1 = new Thread(new RunnableThread(null, configure, queryString), "thread1"); + final Thread thread1 = new Thread(new RunnableThread(null, configure, queryString), "thread1"); thread1.start(); Thread.sleep(1000); // search in _system database - QueriesResultEntity currentlyRunningQueries = driver.getCurrentlyRunningQueries(null); + final QueriesResultEntity currentlyRunningQueries = driver.getCurrentlyRunningQueries(null); // wait for thread thread1.join(); // check result assertEquals(200, currentlyRunningQueries.getStatusCode()); - List queries = currentlyRunningQueries.getQueries(); + final List queries = currentlyRunningQueries.getQueries(); assertEquals(1, queries.size()); } @Test public void test_getSlowQueries() throws ArangoException, InterruptedException { // set SlowQueryThreshold to 2 - QueryTrackingPropertiesEntity properties1 = driver.getQueryTrackingProperties(); + final QueryTrackingPropertiesEntity properties1 = driver.getQueryTrackingProperties(); properties1.setSlowQueryThreshold(2L); driver.setQueryTrackingProperties(properties1); // create a slow query driver.executeDocumentQuery("return sleep(3)", new HashMap(), null, Map.class); - QueriesResultEntity currentlyRunningQueries = driver.getSlowQueries(); + final QueriesResultEntity currentlyRunningQueries = driver.getSlowQueries(); // check result assertEquals(200, currentlyRunningQueries.getStatusCode()); - List queries = currentlyRunningQueries.getQueries(); + final List queries = currentlyRunningQueries.getQueries(); assertTrue(queries.size() > 0); } @@ -172,7 +164,7 @@ public void test_deleteSlowQueries() throws ArangoException, InterruptedExceptio assertEquals(0, queries.size()); // set SlowQueryThreshold to 2 - QueryTrackingPropertiesEntity properties1 = driver.getQueryTrackingProperties(); + final QueryTrackingPropertiesEntity properties1 = driver.getQueryTrackingProperties(); properties1.setSlowQueryThreshold(2L); driver.setQueryTrackingProperties(properties1); @@ -190,10 +182,11 @@ public void test_deleteSlowQueries() throws ArangoException, InterruptedExceptio @Test public void test_killQuery() throws ArangoException, InterruptedException { - String queryString = "return sleep(3)"; + final String queryString = "return sleep(3)"; // create job in _system database - Thread thread1 = new Thread(new RunnableThread(driver.getDefaultDatabase(), configure, queryString), "thread1"); + final Thread thread1 = new Thread(new RunnableThread(driver.getDefaultDatabase(), configure, queryString), + "thread1"); thread1.start(); Thread.sleep(1000); @@ -201,17 +194,17 @@ public void test_killQuery() throws ArangoException, InterruptedException { int numKilled = 0; // search in default database - QueriesResultEntity currentlyRunningQueries = driver.getCurrentlyRunningQueries(); + final QueriesResultEntity currentlyRunningQueries = driver.getCurrentlyRunningQueries(); // check result assertEquals(200, currentlyRunningQueries.getStatusCode()); - List queries = currentlyRunningQueries.getQueries(); + final List queries = currentlyRunningQueries.getQueries(); if (queries.size() > 0) { - for (QueryEntity qe : queries) { + for (final QueryEntity qe : queries) { try { - DefaultEntity killQuery = driver.killQuery(qe.getId()); + final DefaultEntity killQuery = driver.killQuery(qe.getId()); assertEquals(200, killQuery.getStatusCode()); numKilled++; - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @@ -229,21 +222,22 @@ class RunnableThread implements Runnable { ArangoDriver driver; String queryString; - public RunnableThread(String database, ArangoConfigure configure, String queryString) { + public RunnableThread(final String database, final ArangoConfigure configure, final String queryString) { this.driver = new ArangoDriver(configure); this.driver.setDefaultDatabase(database); this.queryString = queryString; } - public RunnableThread(String threadName) { + public RunnableThread(final String threadName) { runner = new Thread(this, threadName); runner.start(); } + @Override public void run() { try { driver.executeDocumentQuery(queryString, new HashMap(), null, Map.class); - } catch (ArangoException e) { + } catch (final ArangoException e) { if (e.getErrorNumber() != ErrorNums.ERROR_QUERY_KILLED) { e.printStackTrace(); } diff --git a/src/test/java/com/arangodb/ArangoDriverReplicationTest.java b/src/test/java/com/arangodb/ArangoDriverReplicationTest.java index 2f0e8988d..c622defc7 100644 --- a/src/test/java/com/arangodb/ArangoDriverReplicationTest.java +++ b/src/test/java/com/arangodb/ArangoDriverReplicationTest.java @@ -54,10 +54,6 @@ public class ArangoDriverReplicationTest extends BaseTest { private static Logger logger = LoggerFactory.getLogger(ArangoConfigure.class); - public ArangoDriverReplicationTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Before public void before() { driver.setDefaultDatabase(null); @@ -68,10 +64,10 @@ public void test_get_inventory() throws ArangoException { try { driver.stopReplicationLogger(); - } catch (Exception e) { + } catch (final Exception e) { } - ReplicationInventoryEntity entity = driver.getReplicationInventory(); + final ReplicationInventoryEntity entity = driver.getReplicationInventory(); assertThat(entity.getCode(), is(0)); assertThat(entity.getStatusCode(), is(200)); @@ -84,12 +80,12 @@ public void test_get_inventory() throws ArangoException { @Test public void test_get_inventory_includeSystem() throws ArangoException { - ReplicationInventoryEntity entity = driver.getReplicationInventory(true); + final ReplicationInventoryEntity entity = driver.getReplicationInventory(true); assertThat(entity.getCode(), is(0)); assertThat(entity.getStatusCode(), is(200)); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - for (Collection col : entity.getCollections()) { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + for (final Collection col : entity.getCollections()) { logger.debug(gson.toJson(col.getParameter())); logger.debug(gson.toJson(col.getIndexes())); } @@ -103,7 +99,7 @@ public void test_get_inventory_404() throws ArangoException { try { driver.getReplicationInventory(); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1228)); // database not found } @@ -113,29 +109,29 @@ public void test_get_inventory_404() throws ArangoException { @Test public void test_get_dump() throws ArangoException { - String collectionName = "rep_dump_test"; + final String collectionName = "rep_dump_test"; try { driver.deleteCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // create 10 document for (int i = 0; i < 10; i++) { - TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); + final TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); driver.createDocument(collectionName, entity, true, null); } // truncate try { driver.truncateCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // create 1 document - TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); + final TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); driver.createDocument(collectionName, entity, true, null); final AtomicInteger upsertCount = new AtomicInteger(0); @@ -143,7 +139,8 @@ public void test_get_dump() throws ArangoException { final AtomicBoolean headCall = new AtomicBoolean(false); driver.getReplicationDump(collectionName, null, null, null, null, TestComplexEntity01.class, new DumpHandler() { - public boolean head(ReplicationDumpHeader header) { + @Override + public boolean head(final ReplicationDumpHeader header) { headCall.set(true); assertThat(header.getCheckmore(), is(not(nullValue()))); assertThat(header.getLastincluded(), is(not(nullValue()))); @@ -152,7 +149,8 @@ public boolean head(ReplicationDumpHeader header) { return true; } - public boolean handle(ReplicationDumpRecord entity) { + @Override + public boolean handle(final ReplicationDumpRecord entity) { switch (entity.getType()) { case DOCUMENT_UPSERT: case EDGE_UPSERT: @@ -188,36 +186,37 @@ public boolean handle(ReplicationDumpRecord entity) { @Test public void test_get_dump_noticks() throws ArangoException { - String collectionName = "rep_dump_test"; + final String collectionName = "rep_dump_test"; try { driver.deleteCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // create 10 document for (int i = 0; i < 10; i++) { - TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); + final TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); driver.createDocument(collectionName, entity, true, null); } // truncate try { driver.truncateCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // create 1 document - TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); + final TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); driver.createDocument(collectionName, entity, true, null); final AtomicInteger upsertCount = new AtomicInteger(0); final AtomicInteger deleteCount = new AtomicInteger(0); driver.getReplicationDump(collectionName, null, null, null, false, TestComplexEntity01.class, new DumpHandlerAdapter() { - public boolean handle(ReplicationDumpRecord entity) { + @Override + public boolean handle(final ReplicationDumpRecord entity) { switch (entity.getType()) { case DOCUMENT_UPSERT: case EDGE_UPSERT: @@ -252,40 +251,42 @@ public boolean handle(ReplicationDumpRecord entity) { @Test public void test_get_dump_handler_control_1() throws ArangoException { - String collectionName = "rep_dump_test"; + final String collectionName = "rep_dump_test"; try { driver.deleteCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // create 10 document for (int i = 0; i < 10; i++) { - TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); + final TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); driver.createDocument(collectionName, entity, true, null); } // truncate try { driver.truncateCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // create 1 document - TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); + final TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); driver.createDocument(collectionName, entity, true, null); final AtomicBoolean headCall = new AtomicBoolean(false); driver.getReplicationDump(collectionName, null, null, null, null, TestComplexEntity01.class, new DumpHandler() { - public boolean head(ReplicationDumpHeader header) { + @Override + public boolean head(final ReplicationDumpHeader header) { headCall.set(true); return false; } - public boolean handle(ReplicationDumpRecord entity) { + @Override + public boolean handle(final ReplicationDumpRecord entity) { fail(""); return true; } @@ -298,42 +299,44 @@ public boolean handle(ReplicationDumpRecord entity) { @Test public void test_get_dump_handler_control_2() throws ArangoException { - String collectionName = "rep_dump_test"; + final String collectionName = "rep_dump_test"; try { driver.deleteCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // create 10 document for (int i = 0; i < 10; i++) { - TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); + final TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); driver.createDocument(collectionName, entity, true, null); } // truncate try { driver.truncateCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // create 1 document - TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); + final TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); driver.createDocument(collectionName, entity, true, null); final AtomicInteger handleCount = new AtomicInteger(0); final AtomicBoolean headCall = new AtomicBoolean(false); driver.getReplicationDump(collectionName, null, null, null, null, TestComplexEntity01.class, new DumpHandler() { - public boolean head(ReplicationDumpHeader header) { + @Override + public boolean head(final ReplicationDumpHeader header) { headCall.set(true); return true; } - public boolean handle(ReplicationDumpRecord entity) { - int cnt = handleCount.incrementAndGet(); + @Override + public boolean handle(final ReplicationDumpRecord entity) { + final int cnt = handleCount.incrementAndGet(); if (cnt == 5) { return false; } @@ -359,7 +362,7 @@ public boolean handle(ReplicationDumpRecord entity) { @Test public void test_server_id() throws ArangoException { - String serverId = driver.getReplicationServerId(); + final String serverId = driver.getReplicationServerId(); assertThat(serverId, is(notNullValue())); } @@ -367,10 +370,10 @@ public void test_server_id() throws ArangoException { @Test public void test_start_logger() throws ArangoException { - boolean running = driver.startReplicationLogger(); + final boolean running = driver.startReplicationLogger(); assertThat(running, is(true)); - boolean running2 = driver.startReplicationLogger(); + final boolean running2 = driver.startReplicationLogger(); assertThat(running2, is(true)); } @@ -378,10 +381,10 @@ public void test_start_logger() throws ArangoException { @Test public void test_stop_logger() throws ArangoException { - boolean running = driver.stopReplicationLogger(); + final boolean running = driver.stopReplicationLogger(); assertThat(running, is(false)); - boolean running2 = driver.stopReplicationLogger(); + final boolean running2 = driver.stopReplicationLogger(); assertThat(running2, is(false)); } @@ -390,28 +393,29 @@ public void test_stop_logger() throws ArangoException { public void test_logger_config() throws ArangoException { // set - ReplicationLoggerConfigEntity config1 = driver.setReplicationLoggerConfig(true, true, 0L, 0L); + final ReplicationLoggerConfigEntity config1 = driver.setReplicationLoggerConfig(true, true, 0L, 0L); assertThat(config1.isAutoStart(), is(true)); assertThat(config1.isLogRemoteChanges(), is(true)); assertThat(config1.getMaxEvents(), is(0L)); assertThat(config1.getMaxEventsSize(), is(0L)); // get - ReplicationLoggerConfigEntity config2 = driver.getReplicationLoggerConfig(); + final ReplicationLoggerConfigEntity config2 = driver.getReplicationLoggerConfig(); assertThat(config2.isAutoStart(), is(true)); assertThat(config2.isLogRemoteChanges(), is(true)); assertThat(config2.getMaxEvents(), is(0L)); assertThat(config2.getMaxEventsSize(), is(0L)); // set - ReplicationLoggerConfigEntity config3 = driver.setReplicationLoggerConfig(false, false, 1048576L, 134217728L); + final ReplicationLoggerConfigEntity config3 = driver.setReplicationLoggerConfig(false, false, 1048576L, + 134217728L); assertThat(config3.isAutoStart(), is(false)); assertThat(config3.isLogRemoteChanges(), is(false)); assertThat(config3.getMaxEvents(), is(1048576L)); assertThat(config3.getMaxEventsSize(), is(134217728L)); // get - ReplicationLoggerConfigEntity config4 = driver.getReplicationLoggerConfig(); + final ReplicationLoggerConfigEntity config4 = driver.getReplicationLoggerConfig(); assertThat(config4.isAutoStart(), is(false)); assertThat(config4.isLogRemoteChanges(), is(false)); assertThat(config4.getMaxEvents(), is(1048576L)); @@ -421,7 +425,7 @@ public void test_logger_config() throws ArangoException { try { driver.setReplicationLoggerConfig(false, false, 0L, 32768L); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(500)); assertThat(e.getErrorNumber(), is(1409)); } @@ -441,7 +445,7 @@ public void test_set_applier_config_endpoint_null() { driver.setReplicationApplierConfig(null, // endpoint is null null, null, null, 99, 98, 97, 1024, true, true); fail(""); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(400)); assertThat(e.getErrorNumber(), is(1410)); } @@ -482,7 +486,7 @@ public void test_set_get_applier_config() throws ArangoException { @Test public void test_start_stop_applier() throws ArangoException { - ReplicationApplierStateEntity state1 = driver.startReplicationApplier(null); + final ReplicationApplierStateEntity state1 = driver.startReplicationApplier(null); assertThat(state1.getStatusCode(), is(200)); assertThat(state1.getServerVersion(), is(notNullValue())); assertThat(state1.getServerId(), is(notNullValue())); @@ -498,7 +502,7 @@ public void test_start_stop_applier() throws ArangoException { assertThat(state1.getState().getTotalEvents(), is(notNullValue())); // LastError, Progress -> see Sceinario Test - ReplicationApplierStateEntity state2 = driver.stopReplicationApplier(); + final ReplicationApplierStateEntity state2 = driver.stopReplicationApplier(); assertThat(state2.getStatusCode(), is(200)); assertThat(state2.getServerVersion(), is(notNullValue())); assertThat(state2.getServerId(), is(notNullValue())); @@ -518,7 +522,7 @@ public void test_start_stop_applier() throws ArangoException { @Test public void test_logger_state() throws ArangoException { - ReplicationLoggerStateEntity entity = driver.getReplicationLoggerState(); + final ReplicationLoggerStateEntity entity = driver.getReplicationLoggerState(); assertThat(entity.getState().isRunning(), is(false)); assertThat(entity.getState().getLastLogTick(), is(not(0L))); @@ -535,7 +539,7 @@ public void test_logger_state() throws ArangoException { @Test public void test_applier_state() throws ArangoException { - ReplicationApplierStateEntity state = driver.getReplicationApplierState(); + final ReplicationApplierStateEntity state = driver.getReplicationApplierState(); assertThat(state.getStatusCode(), is(200)); assertThat(state.getServerVersion(), is(notNullValue())); assertThat(state.getServerId(), is(notNullValue())); diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java index 31f925fd6..14115bb71 100644 --- a/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java +++ b/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java @@ -32,41 +32,39 @@ @Deprecated public class ArangoDriverSimpleGeoTest extends BaseTest { - public ArangoDriverSimpleGeoTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String collectionName = "unit_test_simple_geo_test"; - private String collectionName = "unit_test_simple_geo_test"; + @Before + public void setup() throws ArangoException, IOException { - @Before - public void setup() throws ArangoException, IOException { + // index破棄のために一度削除する + try { + driver.deleteCollection(collectionName); + } catch (final ArangoException e) { + } + // Collectionを作る + try { + driver.createCollection(collectionName); + } catch (final ArangoException e) { + } + driver.truncateCollection(collectionName); - // index破棄のために一度削除する - try { - driver.deleteCollection(collectionName); - } catch (ArangoException e) {} - // Collectionを作る - try { - driver.createCollection(collectionName); - } catch (ArangoException e) {} - driver.truncateCollection(collectionName); - - // テストデータを作る - List stations = TestUtils.readStations(); - for (Station station: stations) { - driver.createDocument(collectionName, station, null, null); - } + // テストデータを作る + final List stations = TestUtils.readStations(); + for (final Station station : stations) { + driver.createDocument(collectionName, station, null, null); + } + + } + + @Test + public void test() throws ArangoException { + + // create geo index + driver.createIndex(collectionName, IndexType.GEO, false, "lat", "lot"); + + // Tokyo Station: lat=35.681391, lon=139.766103 + + } - } - - @Test - public void test() throws ArangoException { - - // create geo index - driver.createIndex(collectionName, IndexType.GEO, false, "lat", "lot"); - - // Tokyo Station: lat=35.681391, lon=139.766103 - - } - } diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java index a5d7661cb..342ac596b 100644 --- a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java +++ b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java @@ -52,10 +52,6 @@ public class ArangoDriverSimpleTest extends BaseTest { private static Logger logger = LoggerFactory.getLogger(ArangoDriverSimpleTest.class); - public ArangoDriverSimpleTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - private static final String COLLECTION_NAME = "unit_test_simple_test"; private static final String COLLECTION_NAME_400 = "unit_test_simple_test_400"; @@ -65,23 +61,23 @@ public void setup() throws ArangoException { // create test collection try { driver.deleteCollection(COLLECTION_NAME); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection(COLLECTION_NAME); - } catch (ArangoException e) { + } catch (final ArangoException e) { } // add some test data for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); + final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); driver.createDocument(COLLECTION_NAME, value, null, null); } // delete second test collection try { driver.deleteCollection(COLLECTION_NAME_400); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @@ -89,14 +85,14 @@ public void setup() throws ArangoException { @Test public void test_simple_all() throws ArangoException { - DocumentCursor documentCursor = driver.executeSimpleAllDocuments(COLLECTION_NAME, 0, 0, - TestComplexEntity01.class); + final DocumentCursor documentCursor = driver.executeSimpleAllDocuments(COLLECTION_NAME, 0, + 0, TestComplexEntity01.class); - Iterator> iterator = documentCursor.iterator(); + final Iterator> iterator = documentCursor.iterator(); int count = 0; while (iterator.hasNext()) { - TestComplexEntity01 entity = iterator.next().getEntity(); + final TestComplexEntity01 entity = iterator.next().getEntity(); count++; assertThat(entity, is(notNullValue())); } @@ -107,14 +103,14 @@ public void test_simple_all() throws ArangoException { @Test public void test_example_by() throws ArangoException { - DocumentCursor documentCursor = driver.executeSimpleByExampleDocuments(COLLECTION_NAME, - new MapBuilder().put("user", "user_6").get(), 0, 0, TestComplexEntity01.class); + final DocumentCursor documentCursor = driver.executeSimpleByExampleDocuments( + COLLECTION_NAME, new MapBuilder().put("user", "user_6").get(), 0, 0, TestComplexEntity01.class); - Iterator> iterator = documentCursor.iterator(); + final Iterator> iterator = documentCursor.iterator(); int count = 0; while (iterator.hasNext()) { - TestComplexEntity01 entity = iterator.next().getEntity(); + final TestComplexEntity01 entity = iterator.next().getEntity(); count++; assertThat(entity.getUser(), is("user_6")); } @@ -124,10 +120,10 @@ public void test_example_by() throws ArangoException { @Test public void test_first_example() throws ArangoException { - ScalarExampleEntity entity = driver.executeSimpleFirstExample(COLLECTION_NAME, + final ScalarExampleEntity entity = driver.executeSimpleFirstExample(COLLECTION_NAME, new MapBuilder().put("user", "user_5").put("desc", "desc5").get(), TestComplexEntity01.class); - DocumentEntity doc = entity.getDocument(); + final DocumentEntity doc = entity.getDocument(); assertThat(entity.getStatusCode(), is(200)); assertThat(doc.getDocumentRevision(), is(not(0L))); @@ -142,11 +138,11 @@ public void test_first_example() throws ArangoException { @Test public void test_any() throws ArangoException { - ScalarExampleEntity entity = driver.executeSimpleAny(COLLECTION_NAME, + final ScalarExampleEntity entity = driver.executeSimpleAny(COLLECTION_NAME, TestComplexEntity01.class); for (int i = 0; i < 30; i++) { - DocumentEntity doc = entity.getDocument(); + final DocumentEntity doc = entity.getDocument(); assertThat(entity.getStatusCode(), is(200)); assertThat(doc.getDocumentRevision(), is(not(0L))); @@ -167,7 +163,7 @@ public void test_range_no_skiplist() throws ArangoException { driver.executeSimpleRangeWithDocuments(COLLECTION_NAME, "age", 5, 30, null, 0, 0, TestComplexEntity01.class); fail("request should fail"); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(1209)); assertThat(e.getCode(), is(404)); } @@ -181,13 +177,13 @@ public void test_range() throws ArangoException { driver.createIndex(COLLECTION_NAME, IndexType.SKIPLIST, false, "age"); { - DocumentCursor documentCursor = driver.executeSimpleRangeWithDocuments(COLLECTION_NAME, - "age", 5, 30, null, 0, 0, TestComplexEntity01.class); - Iterator> iterator = documentCursor.iterator(); + final DocumentCursor documentCursor = driver.executeSimpleRangeWithDocuments( + COLLECTION_NAME, "age", 5, 30, null, 0, 0, TestComplexEntity01.class); + final Iterator> iterator = documentCursor.iterator(); int count = 0; while (iterator.hasNext()) { - TestComplexEntity01 entity = iterator.next().getEntity(); + final TestComplexEntity01 entity = iterator.next().getEntity(); count++; assertThat(entity, is(notNullValue())); } @@ -196,13 +192,13 @@ public void test_range() throws ArangoException { } { - DocumentCursor documentCursor = driver.executeSimpleRangeWithDocuments(COLLECTION_NAME, - "age", 5, 30, true, 0, 0, TestComplexEntity01.class); - Iterator> iterator = documentCursor.iterator(); + final DocumentCursor documentCursor = driver.executeSimpleRangeWithDocuments( + COLLECTION_NAME, "age", 5, 30, true, 0, 0, TestComplexEntity01.class); + final Iterator> iterator = documentCursor.iterator(); int count = 0; while (iterator.hasNext()) { - TestComplexEntity01 entity = iterator.next().getEntity(); + final TestComplexEntity01 entity = iterator.next().getEntity(); count++; assertThat(entity, is(notNullValue())); } @@ -215,7 +211,7 @@ public void test_range() throws ArangoException { @Test public void test_remove_by_example() throws ArangoException { - SimpleByResultEntity entity = driver.executeSimpleRemoveByExample(COLLECTION_NAME, + final SimpleByResultEntity entity = driver.executeSimpleRemoveByExample(COLLECTION_NAME, new MapBuilder().put("user", "user_3").get(), null, null); assertThat(entity.getCode(), is(200)); @@ -229,7 +225,7 @@ public void test_remove_by_example() throws ArangoException { @Test public void test_remove_by_example_with_limit() throws ArangoException { - SimpleByResultEntity entity = driver.executeSimpleRemoveByExample(COLLECTION_NAME, + final SimpleByResultEntity entity = driver.executeSimpleRemoveByExample(COLLECTION_NAME, new MapBuilder().put("user", "user_3").get(), null, 5); assertThat(entity.getCode(), is(200)); @@ -244,7 +240,7 @@ public void test_remove_by_example_with_limit() throws ArangoException { @Test public void test_replace_by_example() throws ArangoException { - SimpleByResultEntity entity = driver.executeSimpleReplaceByExample(COLLECTION_NAME, + final SimpleByResultEntity entity = driver.executeSimpleReplaceByExample(COLLECTION_NAME, new MapBuilder().put("user", "user_3").get(), new MapBuilder().put("abc", "xxx").get(), null, null); assertThat(entity.getCode(), is(200)); @@ -254,14 +250,14 @@ public void test_replace_by_example() throws ArangoException { assertThat(entity.getUpdated(), is(0)); // Get Replaced Document - DocumentCursor documentCursor = driver.executeSimpleByExampleDocuments(COLLECTION_NAME, + final DocumentCursor documentCursor = driver.executeSimpleByExampleDocuments(COLLECTION_NAME, new MapBuilder().put("abc", "xxx").get(), 0, 0, Map.class); - List> list = documentCursor.asList(); + final List> list = documentCursor.asList(); assertThat(list.size(), is(10)); - for (DocumentEntity docuemntEntity : list) { - Map map = docuemntEntity.getEntity(); + for (final DocumentEntity docuemntEntity : list) { + final Map map = docuemntEntity.getEntity(); assertThat(map.size(), is(4)); // _id, _rev, _key and "abc" assertThat((String) map.get("abc"), is("xxx")); } @@ -272,7 +268,7 @@ public void test_replace_by_example() throws ArangoException { @Test public void test_replace_by_example_with_limit() throws ArangoException { - SimpleByResultEntity entity = driver.executeSimpleReplaceByExample(COLLECTION_NAME, + final SimpleByResultEntity entity = driver.executeSimpleReplaceByExample(COLLECTION_NAME, new MapBuilder().put("user", "user_3").get(), new MapBuilder().put("abc", "xxx").get(), null, 3); assertThat(entity.getCode(), is(200)); @@ -282,12 +278,12 @@ public void test_replace_by_example_with_limit() throws ArangoException { assertThat(entity.getUpdated(), is(0)); // Get Replaced Document - CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, + final CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, new MapBuilder().put("abc", "xxx").get(), 0, 0, Map.class); - List list = ResultSetUtils.toList(rs); + final List list = ResultSetUtils.toList(rs); assertThat(list.size(), is(3)); - for (Map map : list) { + for (final Map map : list) { assertThat(map.size(), is(4)); // _id, _rev, _key and "abc" assertThat((String) map.get("abc"), is("xxx")); } @@ -298,7 +294,7 @@ public void test_replace_by_example_with_limit() throws ArangoException { @Test public void test_update_by_example() throws ArangoException { - SimpleByResultEntity entity = driver.executeSimpleUpdateByExample(COLLECTION_NAME, + final SimpleByResultEntity entity = driver.executeSimpleUpdateByExample(COLLECTION_NAME, new MapBuilder().put("user", "user_3").get(), new MapBuilder().put("abc", "xxx").put("age", 999).get(), null, null, null); @@ -309,12 +305,12 @@ public void test_update_by_example() throws ArangoException { assertThat(entity.getUpdated(), is(10)); // Get Replaced Document - CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, + final CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, new MapBuilder().put("abc", "xxx").get(), 0, 0, Map.class); - List list = ResultSetUtils.toList(rs); + final List list = ResultSetUtils.toList(rs); assertThat(list.size(), is(10)); - for (Map map : list) { + for (final Map map : list) { assertThat(map.size(), is(7)); // _id, _rev, _key and "user", // "desc", "age", "abc" assertThat((String) map.get("user"), is("user_3")); @@ -329,7 +325,7 @@ public void test_update_by_example() throws ArangoException { @Test public void test_update_by_example_with_limit() throws ArangoException { - SimpleByResultEntity entity = driver.executeSimpleUpdateByExample(COLLECTION_NAME, + final SimpleByResultEntity entity = driver.executeSimpleUpdateByExample(COLLECTION_NAME, new MapBuilder().put("user", "user_3").get(), new MapBuilder().put("abc", "xxx").put("age", 999).get(), null, null, 3); @@ -340,12 +336,12 @@ public void test_update_by_example_with_limit() throws ArangoException { assertThat(entity.getUpdated(), is(3)); // Get Replaced Document - CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, + final CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, new MapBuilder().put("age", 999).get(), 0, 0, Map.class); - List list = ResultSetUtils.toList(rs); + final List list = ResultSetUtils.toList(rs); assertThat(list.size(), is(3)); - for (Map map : list) { + for (final Map map : list) { assertThat(map.size(), is(7)); // _id, _rev, _key and "user", // "desc", "age", "abc" assertThat((String) map.get("user"), is("user_3")); @@ -360,7 +356,7 @@ public void test_update_by_example_with_limit() throws ArangoException { @Test public void test_update_by_example_with_keepnull() throws ArangoException { - SimpleByResultEntity entity = driver.executeSimpleUpdateByExample(COLLECTION_NAME, + final SimpleByResultEntity entity = driver.executeSimpleUpdateByExample(COLLECTION_NAME, new MapBuilder().put("user", "user_3").get(), new MapBuilder(false).put("abc", "xxx").put("age", 999).put("user", null).get(), false, null, null); @@ -371,12 +367,12 @@ public void test_update_by_example_with_keepnull() throws ArangoException { assertThat(entity.getUpdated(), is(10)); // Get Replaced Document - CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, + final CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, new MapBuilder().put("abc", "xxx").get(), 0, 0, Map.class); - List list = ResultSetUtils.toList(rs); + final List list = ResultSetUtils.toList(rs); assertThat(list.size(), is(10)); - for (Map map : list) { + for (final Map map : list) { assertThat(map.size(), is(6)); // _id, _rev, _key and "desc", "age", // "abc" assertThat(map.get("user"), is(nullValue())); @@ -402,9 +398,9 @@ public void test_fulltext() throws ArangoException { driver.createDocument(COLLECTION_NAME, new TestComplexEntity01("xxx2", "this text also contains a word", 10), null, null); - DocumentCursor documentCursor = driver.executeSimpleFulltextWithDocuments(COLLECTION_NAME, - "desc", "word", 0, 0, null, TestComplexEntity01.class); - List> list = documentCursor.asList(); + final DocumentCursor documentCursor = driver.executeSimpleFulltextWithDocuments( + COLLECTION_NAME, "desc", "word", 0, 0, null, TestComplexEntity01.class); + final List> list = documentCursor.asList(); assertThat(list.size(), is(2)); assertThat(list.get(0).getEntity().getUser(), is("xxx1")); @@ -430,9 +426,9 @@ public void test_fulltext_with_doc() throws ArangoException { driver.createDocument(COLLECTION_NAME, new TestComplexEntity01("xxx2", "this text also contains a word", 10), null, null); - DocumentCursor documentCursor = driver.executeSimpleFulltextWithDocuments(COLLECTION_NAME, - "desc", "word", 0, 0, null, TestComplexEntity01.class); - List> list = documentCursor.asList(); + final DocumentCursor documentCursor = driver.executeSimpleFulltextWithDocuments( + COLLECTION_NAME, "desc", "word", 0, 0, null, TestComplexEntity01.class); + final List> list = documentCursor.asList(); assertThat(list.size(), is(2)); assertThat(list.get(0).getDocumentHandle(), startsWith(COLLECTION_NAME)); @@ -455,7 +451,7 @@ public void test_fulltext_with_doc() throws ArangoException { public void test_geo() throws ArangoException, IOException { // Load Station data - List stations = TestUtils.readStations(); + final List stations = TestUtils.readStations(); logger.debug(stations.toString()); } diff --git a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java index 26141ecd7..a88ab0745 100644 --- a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java @@ -45,7 +45,7 @@ public String getA() { return a; } - public void setA(String a) { + public void setA(final String a) { this.a = a; } @@ -53,7 +53,7 @@ public String getB() { return b; } - public void setB(String b) { + public void setB(final String b) { this.b = b; } @@ -61,25 +61,21 @@ public int getI() { return i; } - public void setI(int i) { + public void setI(final int i) { this.i = i; } } - public ArangoDriverTransactionTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Before public void setup() throws ArangoException { try { driver.deleteCollection(SOME_COLLECTION); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection(SOME_COLLECTION); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @@ -88,7 +84,7 @@ public void setup() throws ArangoException { public void teardown() throws ArangoException { try { driver.deleteCollection(SOME_COLLECTION); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } diff --git a/src/test/java/com/arangodb/ArangoDriverTraversalTest.java b/src/test/java/com/arangodb/ArangoDriverTraversalTest.java index 840696720..87e3e2b67 100644 --- a/src/test/java/com/arangodb/ArangoDriverTraversalTest.java +++ b/src/test/java/com/arangodb/ArangoDriverTraversalTest.java @@ -43,28 +43,24 @@ */ public class ArangoDriverTraversalTest extends BaseGraphTest { - String graphName = "TraversalTestGraph"; - String vertexCollectionName = "person"; - String edgeCollectionName = "knows"; - - public ArangoDriverTraversalTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String graphName = "TraversalTestGraph"; + private final String vertexCollectionName = "person"; + private final String edgeCollectionName = "knows"; @Override @Before public void _before() throws ArangoException { super._before(); - List edgeDefinitions = new ArrayList(); - EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); + final List edgeDefinitions = new ArrayList(); + final EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); edgeDefinition.setCollection(edgeCollectionName); - List from = new ArrayList(); + final List from = new ArrayList(); from.add(vertexCollectionName); edgeDefinition.setFrom(from); - List to = new ArrayList(); + final List to = new ArrayList(); to.add(vertexCollectionName); edgeDefinition.setTo(to); @@ -72,11 +68,11 @@ public void _before() throws ArangoException { driver.createGraph(graphName, edgeDefinitions, null, true); - VertexEntity alice = createPerson("Alice"); - VertexEntity bob = createPerson("Bob"); - VertexEntity charlie = createPerson("Charlie"); - VertexEntity dave = createPerson("Dave"); - VertexEntity eve = createPerson("Eve"); + final VertexEntity alice = createPerson("Alice"); + final VertexEntity bob = createPerson("Bob"); + final VertexEntity charlie = createPerson("Charlie"); + final VertexEntity dave = createPerson("Dave"); + final VertexEntity eve = createPerson("Eve"); driver.graphCreateEdge(graphName, edgeCollectionName, "Alice_knows_Bob", alice.getDocumentHandle(), bob.getDocumentHandle()); @@ -93,20 +89,21 @@ public void _before() throws ArangoException { @SuppressWarnings("rawtypes") @Test public void test_create_vertex() throws ArangoException { - TraversalQueryOptions traversalQueryOptions = new TraversalQueryOptions(); + final TraversalQueryOptions traversalQueryOptions = new TraversalQueryOptions(); traversalQueryOptions.setGraphName(graphName); traversalQueryOptions.setStartVertex("person/Alice"); traversalQueryOptions.setDirection(Direction.OUTBOUND); - Class vertexClass = Person.class; - Class edgeClass = Map.class; + final Class vertexClass = Person.class; + final Class edgeClass = Map.class; - TraversalEntity traversal = driver.getTraversal(traversalQueryOptions, vertexClass, edgeClass); + final TraversalEntity traversal = driver.getTraversal(traversalQueryOptions, vertexClass, + edgeClass); assertThat(traversal, is(notNullValue())); - List> vertices = traversal.getVertices(); + final List> vertices = traversal.getVertices(); assertThat(vertices, is(notNullValue())); assertThat(vertices.size(), is(4)); assertThat(vertices.get(0).getEntity().getName(), is("Alice")); @@ -114,7 +111,7 @@ public void test_create_vertex() throws ArangoException { assertThat(vertices.get(2).getEntity().getName(), is("Charlie")); assertThat(vertices.get(3).getEntity().getName(), is("Dave")); - List> paths = traversal.getPaths(); + final List> paths = traversal.getPaths(); assertThat(paths, is(notNullValue())); assertThat(paths.size(), is(4)); @@ -127,7 +124,7 @@ public void test_create_vertex() throws ArangoException { assertThat(paths.get(3).getVertices().size(), is(3)); } - private VertexEntity createPerson(String name) throws ArangoException { + private VertexEntity createPerson(final String name) throws ArangoException { return driver.graphCreateVertex(graphName, vertexCollectionName, name, new Person(name), true); } @@ -135,7 +132,7 @@ public class Person extends BaseEntity { private String name; - public Person(String name) { + public Person(final String name) { this.name = name; } @@ -143,7 +140,7 @@ public String getName() { return name; } - public void setName(String name) { + public void setName(final String name) { this.name = name; } } diff --git a/src/test/java/com/arangodb/ArangoDriverUsersTest.java b/src/test/java/com/arangodb/ArangoDriverUsersTest.java index 360b7fc28..3ead9b37d 100644 --- a/src/test/java/com/arangodb/ArangoDriverUsersTest.java +++ b/src/test/java/com/arangodb/ArangoDriverUsersTest.java @@ -44,309 +44,306 @@ */ public class ArangoDriverUsersTest extends BaseTest { - public ArangoDriverUsersTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - - @Before - public void setup() throws ArangoException { - // delete user - for (String user : new String[] { "user1", "user2", "user3", "user4", "testuser", "テスト☆ユーザー", "user-A", - "userA", "userB", "ゆーざーA" }) { - // user-A, userA, userB, ゆーざーA is created another(auth) testcase. - try { - driver.deleteUser(user); - } catch (ArangoException e) { - } - } - } - - private Map> toMap(List> users) { - TreeMap> map = new TreeMap>(); - for (DocumentEntity user : users) { - map.put(user.getEntity().getUsername(), user); - } - return map; - } - - @Test - public void test_create_user() throws ArangoException { - DefaultEntity ret = driver.createUser("testuser", "test-pass1", null, null); - - assertThat(ret.getStatusCode(), is(201)); - assertThat(ret.getCode(), is(201)); - assertThat(ret.isError(), is(false)); - } - - @Test - public void test_create_user_japanese() throws ArangoException { - - // create - DefaultEntity ret = driver.createUser("テスト☆ユーザー", "パスワード", null, null); - // validate - assertThat(ret.getStatusCode(), is(201)); - assertThat(ret.getCode(), is(201)); - assertThat(ret.isError(), is(false)); - - // get - UserEntity user = driver.getUser("テスト☆ユーザー"); - assertThat(user.getUsername(), is("テスト☆ユーザー")); - assertThat(user.getPassword(), is(nullValue())); - assertThat(user.isActive(), is(true)); - assertThat(user.getExtra().isEmpty(), is(true)); - - } - - @Test - public void test_create_user_inactive() throws ArangoException { - DefaultEntity ret = driver.createUser("testuser", "test-pass1", false, null); - - assertThat(ret.getStatusCode(), is(201)); - assertThat(ret.getCode(), is(201)); - assertThat(ret.isError(), is(false)); - } - - @Test - public void test_create_user_extra() throws ArangoException { - - // create user - DefaultEntity ret = driver.createUser("testuser", "test-pass1", false, - new MapBuilder().put("attr1", "寿司").put("日本語属性1", "日本語値").get()); - - // valdate - assertThat(ret.getStatusCode(), is(201)); - assertThat(ret.getCode(), is(201)); - assertThat(ret.isError(), is(false)); - - // get user - UserEntity user = driver.getUser("testuser"); - assertThat(user.getUsername(), is("testuser")); - assertThat(user.getPassword(), is(nullValue())); - assertThat(user.isActive(), is(false)); - assertThat(user.getExtra().size(), is(2)); - assertThat((String) user.getExtra().get("attr1"), is("寿司")); - assertThat((String) user.getExtra().get("日本語属性1"), is("日本語値")); - - } - - @Test - public void test_create_user_duplicate() throws ArangoException { - - DefaultEntity ret = driver.createUser("testuser", "test-pass1", null, null); - assertThat(ret.isError(), is(false)); - - try { - driver.createUser("testuser", "test-pass1", null, null); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(1702)); - assertThat(e.getMessage(), containsString("duplicate user")); - } - - } - - @Test - public void test_create_user_empty() throws ArangoException { - - try { - driver.createUser("", "test-pass1", null, null); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(1700)); - assertThat(e.getMessage(), containsString("invalid user name")); - } - - } - - @Test - public void test_delete_user_empty() throws ArangoException { - - try { - driver.deleteUser(""); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(400)); - assertThat(e.getMessage(), containsString("bad parameter")); - } - - } - - public void test_delete_user_404() throws ArangoException { - - try { - driver.deleteUser("testuser"); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(1703)); - assertThat(e.getMessage(), containsString("user not found")); - } - - } - - @Test - public void test_get_user_empty() throws ArangoException { - // returns a list of users - - // TODO check the list - driver.getUser(""); - - } - - @Test - public void test_get_user_404() throws ArangoException { - - try { - driver.getUser("testuser"); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(1703)); - assertThat(e.getMessage(), containsString("user not found")); - } - - } - - @Test - public void test_replace_user() throws ArangoException { - - // create - driver.createUser("testuser", "pass1", true, null); - // get document - DocumentEntity doc1 = toMap(driver.getUsersDocument()).get("testuser"); - - // replace - DefaultEntity res = driver.replaceUser("testuser", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); - assertThat(res.getCode(), is(200)); - assertThat(res.isError(), is(false)); - - // get replace user - DocumentEntity doc2 = toMap(driver.getUsersDocument()).get("testuser"); - - assertThat(doc2.getEntity().getUsername(), is("testuser")); - // assertThat(doc2.getEntity().getPassword(), - // is(not(doc1.getEntity().getPassword()))); - assertThat(doc2.getEntity().isActive(), is(false)); - assertThat((String) doc2.getEntity().getExtra().get("aaa"), is("bbbb")); - - assertThat(doc2.getDocumentRevision(), greaterThan(doc1.getDocumentRevision())); - assertThat(doc2.getDocumentKey(), is(doc1.getDocumentKey())); - assertThat(doc2.getDocumentHandle(), is(doc1.getDocumentHandle())); - - } - - @Test - public void test_replace_user_empty() throws ArangoException { - - try { - driver.replaceUser("", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(400)); - assertThat(e.getMessage(), containsString("bad parameter")); - } - - } - - @Test - public void test_replace_user_404() throws ArangoException { - - try { - driver.replaceUser("testuser", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(1703)); - assertThat(e.getMessage(), containsString("user not found")); - } - - } - - @Test - public void test_update_user() throws ArangoException { - - // create - driver.createUser("testuser", "pass1", true, null); - // get document - DocumentEntity doc1 = toMap(driver.getUsersDocument()).get("testuser"); - - // partial update - DefaultEntity res = driver.updateUser("testuser", null, null, new MapBuilder().put("aaa", "bbbb").get()); - assertThat(res.getCode(), is(200)); - assertThat(res.isError(), is(false)); - - // get replace user - DocumentEntity doc2 = toMap(driver.getUsersDocument()).get("testuser"); - - assertThat(doc2.getEntity().getUsername(), is("testuser")); - assertThat(doc2.getEntity().getPassword(), is(doc1.getEntity().getPassword())); - assertThat(doc2.getEntity().isActive(), is(true)); - assertThat((String) doc2.getEntity().getExtra().get("aaa"), is("bbbb")); - - assertThat(doc2.getDocumentRevision(), greaterThan(doc1.getDocumentRevision())); - assertThat(doc2.getDocumentKey(), is(doc1.getDocumentKey())); - assertThat(doc2.getDocumentHandle(), is(doc1.getDocumentHandle())); - - } - - @Test - public void test_update_user_empty() throws ArangoException { - - try { - driver.updateUser("", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(400)); - assertThat(e.getMessage(), containsString("bad parameter")); - } - - } - - @Test - public void test_update_user_404() throws ArangoException { - - try { - driver.updateUser("testuser", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); - fail("did not raise exception"); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(1703)); - assertThat(e.getMessage(), containsString("user not found")); - } - - } - - @Test - public void test_get_users() throws ArangoException { - - driver.createUser("user1", "pass1", true, null); - driver.createUser("user2", "pass2", false, null); - driver.createUser("user3", "pass3", true, new MapBuilder().put("key", "value").get()); - - // get users - List users = driver.getUsers(); - Collections.sort(users, new Comparator() { - @Override - public int compare(UserEntity o1, UserEntity o2) { - return o1.getUsername().compareTo(o2.getUsername()); - } - }); - - // validate - assertThat(users.size(), is(4)); // user1,2,3 and root - assertThat(users.get(0).getUsername(), is("root")); - - assertThat(users.get(1).getUsername(), is("user1")); - assertThat(users.get(1).isActive(), is(true)); - assertThat(users.get(1).getExtra(), is(notNullValue())); - assertThat(users.get(1).getExtra().size(), is(0)); - - assertThat(users.get(2).getUsername(), is("user2")); - assertThat(users.get(2).isActive(), is(false)); - assertThat(users.get(2).getExtra(), is(notNullValue())); - assertThat(users.get(2).getExtra().size(), is(0)); - - assertThat(users.get(3).getUsername(), is("user3")); - assertThat(users.get(3).isActive(), is(true)); - assertThat(users.get(3).getExtra().size(), is(1)); - assertThat((String) users.get(3).getExtra().get("key"), is("value")); - - } + @Before + public void setup() throws ArangoException { + // delete user + for (final String user : new String[] { "user1", "user2", "user3", "user4", "testuser", "テスト☆ユーザー", "user-A", + "userA", "userB", "ゆーざーA" }) { + // user-A, userA, userB, ゆーざーA is created another(auth) testcase. + try { + driver.deleteUser(user); + } catch (final ArangoException e) { + } + } + } + + private Map> toMap(final List> users) { + final TreeMap> map = new TreeMap>(); + for (final DocumentEntity user : users) { + map.put(user.getEntity().getUsername(), user); + } + return map; + } + + @Test + public void test_create_user() throws ArangoException { + final DefaultEntity ret = driver.createUser("testuser", "test-pass1", null, null); + + assertThat(ret.getStatusCode(), is(201)); + assertThat(ret.getCode(), is(201)); + assertThat(ret.isError(), is(false)); + } + + @Test + public void test_create_user_japanese() throws ArangoException { + + // create + final DefaultEntity ret = driver.createUser("テスト☆ユーザー", "パスワード", null, null); + // validate + assertThat(ret.getStatusCode(), is(201)); + assertThat(ret.getCode(), is(201)); + assertThat(ret.isError(), is(false)); + + // get + final UserEntity user = driver.getUser("テスト☆ユーザー"); + assertThat(user.getUsername(), is("テスト☆ユーザー")); + assertThat(user.getPassword(), is(nullValue())); + assertThat(user.isActive(), is(true)); + assertThat(user.getExtra().isEmpty(), is(true)); + + } + + @Test + public void test_create_user_inactive() throws ArangoException { + final DefaultEntity ret = driver.createUser("testuser", "test-pass1", false, null); + + assertThat(ret.getStatusCode(), is(201)); + assertThat(ret.getCode(), is(201)); + assertThat(ret.isError(), is(false)); + } + + @Test + public void test_create_user_extra() throws ArangoException { + + // create user + final DefaultEntity ret = driver.createUser("testuser", "test-pass1", false, + new MapBuilder().put("attr1", "寿司").put("日本語属性1", "日本語値").get()); + + // valdate + assertThat(ret.getStatusCode(), is(201)); + assertThat(ret.getCode(), is(201)); + assertThat(ret.isError(), is(false)); + + // get user + final UserEntity user = driver.getUser("testuser"); + assertThat(user.getUsername(), is("testuser")); + assertThat(user.getPassword(), is(nullValue())); + assertThat(user.isActive(), is(false)); + assertThat(user.getExtra().size(), is(2)); + assertThat((String) user.getExtra().get("attr1"), is("寿司")); + assertThat((String) user.getExtra().get("日本語属性1"), is("日本語値")); + + } + + @Test + public void test_create_user_duplicate() throws ArangoException { + + final DefaultEntity ret = driver.createUser("testuser", "test-pass1", null, null); + assertThat(ret.isError(), is(false)); + + try { + driver.createUser("testuser", "test-pass1", null, null); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(1702)); + assertThat(e.getMessage(), containsString("duplicate user")); + } + + } + + @Test + public void test_create_user_empty() throws ArangoException { + + try { + driver.createUser("", "test-pass1", null, null); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(1700)); + assertThat(e.getMessage(), containsString("invalid user name")); + } + + } + + @Test + public void test_delete_user_empty() throws ArangoException { + + try { + driver.deleteUser(""); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(400)); + assertThat(e.getMessage(), containsString("bad parameter")); + } + + } + + public void test_delete_user_404() throws ArangoException { + + try { + driver.deleteUser("testuser"); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(1703)); + assertThat(e.getMessage(), containsString("user not found")); + } + + } + + @Test + public void test_get_user_empty() throws ArangoException { + // returns a list of users + + // TODO check the list + driver.getUser(""); + + } + + @Test + public void test_get_user_404() throws ArangoException { + + try { + driver.getUser("testuser"); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(1703)); + assertThat(e.getMessage(), containsString("user not found")); + } + + } + + @Test + public void test_replace_user() throws ArangoException { + + // create + driver.createUser("testuser", "pass1", true, null); + // get document + final DocumentEntity doc1 = toMap(driver.getUsersDocument()).get("testuser"); + + // replace + final DefaultEntity res = driver.replaceUser("testuser", "pass2", false, + new MapBuilder().put("aaa", "bbbb").get()); + assertThat(res.getCode(), is(200)); + assertThat(res.isError(), is(false)); + + // get replace user + final DocumentEntity doc2 = toMap(driver.getUsersDocument()).get("testuser"); + + assertThat(doc2.getEntity().getUsername(), is("testuser")); + // assertThat(doc2.getEntity().getPassword(), + // is(not(doc1.getEntity().getPassword()))); + assertThat(doc2.getEntity().isActive(), is(false)); + assertThat((String) doc2.getEntity().getExtra().get("aaa"), is("bbbb")); + + assertThat(doc2.getDocumentRevision(), greaterThan(doc1.getDocumentRevision())); + assertThat(doc2.getDocumentKey(), is(doc1.getDocumentKey())); + assertThat(doc2.getDocumentHandle(), is(doc1.getDocumentHandle())); + + } + + @Test + public void test_replace_user_empty() throws ArangoException { + + try { + driver.replaceUser("", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(400)); + assertThat(e.getMessage(), containsString("bad parameter")); + } + + } + + @Test + public void test_replace_user_404() throws ArangoException { + + try { + driver.replaceUser("testuser", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(1703)); + assertThat(e.getMessage(), containsString("user not found")); + } + + } + + @Test + public void test_update_user() throws ArangoException { + + // create + driver.createUser("testuser", "pass1", true, null); + // get document + final DocumentEntity doc1 = toMap(driver.getUsersDocument()).get("testuser"); + + // partial update + final DefaultEntity res = driver.updateUser("testuser", null, null, new MapBuilder().put("aaa", "bbbb").get()); + assertThat(res.getCode(), is(200)); + assertThat(res.isError(), is(false)); + + // get replace user + final DocumentEntity doc2 = toMap(driver.getUsersDocument()).get("testuser"); + + assertThat(doc2.getEntity().getUsername(), is("testuser")); + assertThat(doc2.getEntity().getPassword(), is(doc1.getEntity().getPassword())); + assertThat(doc2.getEntity().isActive(), is(true)); + assertThat((String) doc2.getEntity().getExtra().get("aaa"), is("bbbb")); + + assertThat(doc2.getDocumentRevision(), greaterThan(doc1.getDocumentRevision())); + assertThat(doc2.getDocumentKey(), is(doc1.getDocumentKey())); + assertThat(doc2.getDocumentHandle(), is(doc1.getDocumentHandle())); + + } + + @Test + public void test_update_user_empty() throws ArangoException { + + try { + driver.updateUser("", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(400)); + assertThat(e.getMessage(), containsString("bad parameter")); + } + + } + + @Test + public void test_update_user_404() throws ArangoException { + + try { + driver.updateUser("testuser", "pass2", false, new MapBuilder().put("aaa", "bbbb").get()); + fail("did not raise exception"); + } catch (final ArangoException e) { + assertThat(e.getErrorNumber(), is(1703)); + assertThat(e.getMessage(), containsString("user not found")); + } + + } + + @Test + public void test_get_users() throws ArangoException { + + driver.createUser("user1", "pass1", true, null); + driver.createUser("user2", "pass2", false, null); + driver.createUser("user3", "pass3", true, new MapBuilder().put("key", "value").get()); + + // get users + final List users = driver.getUsers(); + Collections.sort(users, new Comparator() { + @Override + public int compare(final UserEntity o1, final UserEntity o2) { + return o1.getUsername().compareTo(o2.getUsername()); + } + }); + + // validate + assertThat(users.size(), is(4)); // user1,2,3 and root + assertThat(users.get(0).getUsername(), is("root")); + + assertThat(users.get(1).getUsername(), is("user1")); + assertThat(users.get(1).isActive(), is(true)); + assertThat(users.get(1).getExtra(), is(notNullValue())); + assertThat(users.get(1).getExtra().size(), is(0)); + + assertThat(users.get(2).getUsername(), is("user2")); + assertThat(users.get(2).isActive(), is(false)); + assertThat(users.get(2).getExtra(), is(notNullValue())); + assertThat(users.get(2).getExtra().size(), is(0)); + + assertThat(users.get(3).getUsername(), is("user3")); + assertThat(users.get(3).isActive(), is(true)); + assertThat(users.get(3).getExtra().size(), is(1)); + assertThat((String) users.get(3).getExtra().get("key"), is("value")); + + } } diff --git a/src/test/java/com/arangodb/BaseDocumentTest.java b/src/test/java/com/arangodb/BaseDocumentTest.java index da74c9526..3c827e44c 100644 --- a/src/test/java/com/arangodb/BaseDocumentTest.java +++ b/src/test/java/com/arangodb/BaseDocumentTest.java @@ -23,19 +23,15 @@ */ public class BaseDocumentTest extends BaseGraphTest { - String graphName = "UnitTestGraph"; - String edgeCollectionName = "edge"; - - public BaseDocumentTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } + private final String graphName = "UnitTestGraph"; + // private final String edgeCollectionName = "edge"; class Blub { public String getBlubStr() { return blubStr; } - public void setBlubStr(String blubStr) { + public void setBlubStr(final String blubStr) { this.blubStr = blubStr; } @@ -43,14 +39,14 @@ public Object getBlubObj() { return blubObj; } - public void setBlubObj(Object blubObj) { + public void setBlubObj(final Object blubObj) { this.blubObj = blubObj; } private String blubStr; private Object blubObj; - public Blub(String blubStr, Object blubObj) { + public Blub(final String blubStr, final Object blubObj) { this.blubStr = blubStr; this.blubObj = blubObj; } @@ -58,8 +54,8 @@ public Blub(String blubStr, Object blubObj) { @Test public void constructor() { - String myKey = "myKey"; - Map myEmptyMap = new HashMap(); + final String myKey = "myKey"; + final Map myEmptyMap = new HashMap(); BaseDocument doc = new BaseDocument(); assertThat(doc, instanceOf(BaseDocument.class)); @@ -70,15 +66,15 @@ public void constructor() { assertEquals(doc.getProperties(), myEmptyMap); assertThat(doc.getDocumentKey(), is(myKey)); - String key1 = "key1"; - String key2 = "key2"; - String key3 = "key3"; - String val1 = "val1"; - int val2 = 2; + final String key1 = "key1"; + final String key2 = "key2"; + final String key3 = "key3"; + final String val1 = "val1"; + final int val2 = 2; - Blub val3 = new Blub("pappnase", 4711); + final Blub val3 = new Blub("pappnase", 4711); - Map myMap = new HashMap(); + final Map myMap = new HashMap(); myMap.put(key1, val1); myMap.put(key2, val2); myMap.put(key3, val3); @@ -108,27 +104,27 @@ public void constructor() { @Test public void save_document() throws ArangoException { - String key1 = "key1"; - String key2 = "key2"; - String key3 = "key3"; - String key4 = "key4"; - String key5 = "key5"; - String key6 = "key6"; - String key7 = "key7"; - - String val1 = "val1"; - double val2 = -20; - Blub val3 = new Blub("pappnase", 4711); - Object[] val4 = new Object[4]; + final String key1 = "key1"; + final String key2 = "key2"; + final String key3 = "key3"; + final String key4 = "key4"; + final String key5 = "key5"; + final String key6 = "key6"; + final String key7 = "key7"; + + final String val1 = "val1"; + final double val2 = -20; + final Blub val3 = new Blub("pappnase", 4711); + final Object[] val4 = new Object[4]; val4[0] = 1; val4[1] = 2; val4[2] = "Hallo"; val4[3] = new Blub("Hallo", 42); - Boolean val5 = true; - Object val6 = null; - Object val7 = 0; + final Boolean val5 = true; + final Object val6 = null; + final Object val7 = 0; - Map myMap = new HashMap(); + final Map myMap = new HashMap(); myMap.put(key1, val1); myMap.put(key2, val2); myMap.put(key3, val3); @@ -137,18 +133,18 @@ public void save_document() throws ArangoException { myMap.put(key6, val6); myMap.put(key7, val7); - BaseDocument baseDocument = new BaseDocument(myMap); + final BaseDocument baseDocument = new BaseDocument(myMap); driver.createCollection("myCollection"); driver.createDocument("myCollection", baseDocument); driver.createGraph(this.graphName, this.createEdgeDefinitions(), null, true); - BaseDocument myDoc1 = new BaseDocument("myKeyFROM", myMap); - Blub myDoc2 = new Blub("myKeyTO", new Blub("blub2", new Blub("blub3", 42))); - DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from", myDoc1, null); + final BaseDocument myDoc1 = new BaseDocument("myKeyFROM", myMap); + final Blub myDoc2 = new Blub("myKeyTO", new Blub("blub2", new Blub("blub3", 42))); + final DocumentEntity v1 = driver.graphCreateVertex(this.graphName, "from", myDoc1, null); driver.graphCreateVertex(this.graphName, "to", myDoc2, null); - DocumentEntity v1DB = driver.getDocument(v1.getDocumentHandle(), BaseDocument.class); + final DocumentEntity v1DB = driver.getDocument(v1.getDocumentHandle(), BaseDocument.class); // DocumentEntity v2DB = // driver.getDocument(v2.getDocumentHandle(), Blub.class); @@ -157,8 +153,9 @@ public void save_document() throws ArangoException { assertThat(v1DB.getDocumentHandle(), is(notNullValue())); assertThat(v1DB.getDocumentRevision(), is(not(0L))); assertThat(v1DB.getDocumentKey(), is(notNullValue())); - Map dbProperties = v1DB.getEntity().getProperties(); - Object x = dbProperties.get(key1); + // final Map dbProperties = + // v1DB.getEntity().getProperties(); + // final Object x = dbProperties.get(key1); assertThat((String) v1DB.getEntity().getProperties().get(key1), is(val1)); assertThat((Double) v1DB.getEntity().getProperties().get(key2), is(val2)); @@ -169,13 +166,13 @@ public void save_document() throws ArangoException { } protected List createEdgeDefinitions() { - List edgeDefinitions = new ArrayList(); - EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); + final List edgeDefinitions = new ArrayList(); + final EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); edgeDefinition.setCollection("edge"); - List from = new ArrayList(); + final List from = new ArrayList(); from.add("from"); edgeDefinition.setFrom(from); - List to = new ArrayList(); + final List to = new ArrayList(); to.add("to"); edgeDefinition.setTo(to); edgeDefinitions.add(edgeDefinition); diff --git a/src/test/java/com/arangodb/BaseGraphTest.java b/src/test/java/com/arangodb/BaseGraphTest.java index b78dbf230..a2c434175 100644 --- a/src/test/java/com/arangodb/BaseGraphTest.java +++ b/src/test/java/com/arangodb/BaseGraphTest.java @@ -32,18 +32,14 @@ */ public abstract class BaseGraphTest extends BaseTest { - public BaseGraphTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() throws ArangoException { - String deleteAllGraphsAndTheirCollections = "var db = require('internal').db;\n" + final String deleteAllGraphsAndTheirCollections = "var db = require('internal').db;\n" + "var graph = require('org/arangodb/general-graph');\n" + "graph._list().forEach(function(g){\n" + " graph._drop(g, true)\n" + "});"; driver.executeScript(deleteAllGraphsAndTheirCollections); - String deleteAllCollections = "var db = require('internal').db;\n" + final String deleteAllCollections = "var db = require('internal').db;\n" + "var cols = db._collections().filter(function(c) { return c.name()[0] !== \"_\" });\n" + "cols.forEach(function(col){db._drop(col.name())});"; driver.executeScript(deleteAllCollections); @@ -51,23 +47,23 @@ public void _before() throws ArangoException { @After public void after() throws ArangoException { - String deleteAllGraphsAndTheirCollections = "var db = require('internal').db;\n" + final String deleteAllGraphsAndTheirCollections = "var db = require('internal').db;\n" + "var graph = require('org/arangodb/general-graph');\n" + "graph._list().forEach(function(g){\n" + " graph._drop(g, true)\n" + "});"; driver.executeScript(deleteAllGraphsAndTheirCollections); } - protected List createEdgeDefinitions(int count, int offset) { - List edgeDefinitions = new ArrayList(); + protected List createEdgeDefinitions(final int count, final int offset) { + final List edgeDefinitions = new ArrayList(); for (int i = 1 + offset; i <= count + offset; i++) { - EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); + final EdgeDefinitionEntity edgeDefinition = new EdgeDefinitionEntity(); edgeDefinition.setCollection("edge-" + i); - List from = new ArrayList(); + final List from = new ArrayList(); from.add("from" + i + "-1"); from.add("from" + i + "-2"); from.add("from" + i + "-3"); edgeDefinition.setFrom(from); - List to = new ArrayList(); + final List to = new ArrayList(); to.add("to" + i + "-1"); to.add("to" + i + "-2"); to.add("to" + i + "-3"); @@ -77,8 +73,8 @@ protected List createEdgeDefinitions(int count, int offset return edgeDefinitions; } - protected List createOrphanCollections(int count) { - List orphanCollections = new ArrayList(); + protected List createOrphanCollections(final int count) { + final List orphanCollections = new ArrayList(); for (int i = 1; i <= count; i++) { orphanCollections.add("orphan" + i); } @@ -86,7 +82,7 @@ protected List createOrphanCollections(int count) { } protected GraphEntity createTestGraph() throws ArangoException { - String createGraph = "var db = require('internal').db;\n" + final String createGraph = "var db = require('internal').db;\n" + "var graphModule = require('org/arangodb/general-graph');\n" + "graphModule._create('CountryGraph', [graphModule._relation('hasBorderWith', ['Country'], ['Country'])]);\n" + "db.Country.save({'_key' : 'Germany'});\n" + "db.Country.save({'_key' : 'Austria'});\n" diff --git a/src/test/java/com/arangodb/BaseTest.java b/src/test/java/com/arangodb/BaseTest.java index 053aa504d..7e0aceb61 100644 --- a/src/test/java/com/arangodb/BaseTest.java +++ b/src/test/java/com/arangodb/BaseTest.java @@ -16,15 +16,8 @@ package com.arangodb; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; import com.arangodb.entity.ArangoVersion; import com.arangodb.util.TestUtils; @@ -33,84 +26,27 @@ * @author tamtam180 - kirscheless at gmail.com * */ -@RunWith(Parameterized.class) public abstract class BaseTest { protected static final String DATABASE_NAME = "unitTestDatabase"; protected static ArangoConfigure configure; - protected static ArangoDriver driver; - // Suite.classを使った場合、Parametersがテストクラスの数だけ最初に一気に連続で呼ばれる。 - // そのため、単純にクラス変数にconfigureを保持すると、AfterClassの時に別のテストケースのものを終了してしまう。 - // Suite時のライフサイクル( Suite{TestClassA, TestClassB} ) - // 1) Parameters(TestClassA) -> Parameters(TestClassB) - // 2) BeforeClass - // 3) A#Constructor -> A#before -> A#test1 -> A#after - // 4) A#Constructor -> A#before -> A#test2 -> A#after - // 5) AfterClass - // 6) BeforeClass - // 7) B#Constructor -> B#before -> B#test1 -> B#after - // 8) B#Constructor -> B#before -> B#test2 -> B#after - // 9) AfterClass - // よって、ParametersとしてConfigureをコンストラクタに渡し(Parametersから渡す術がこれしかない)、 - // コンストラクタ内でクラス変数に戻してあげる。(クラス変数でないとAfterClassから参照できない) - // 各テストは直列で実行されるので、この方法でとりあえず実行はできる。並列テストをすると死ぬ。 - - @Parameters() - public static Collection getParameterizedDrivers() { - - // final ArangoConfigure configure = new ArangoConfigure(); - // configure.setConnectRetryCount(2); - // configure.init(); - // - // final ArangoDriver driver = new ArangoDriver(configure); - // final ArangoDriver driverMDB = new ArangoDriver(configure, - // DATABASE_NAME); - // // create mydb - // try { - // driver.createDatabase(DATABASE_NAME); - // } catch (final ArangoException e) { - // } - - // this is the original list: - // return Arrays.asList( - // new Object[]{ configure, driver }, - // new Object[] { configure, driverMDB }); - - final List result = new ArrayList(); - // result.add(new Object[] { configure, driver }); - // result.add(new Object[] { configure, driverMDB }); - result.add(new Object[] { null, null }); - - return result; - } - - public BaseTest(final ArangoConfigure configure, final ArangoDriver driver) { - // BaseTest.driver = driver; - // BaseTest.configure = configure; - // - // try { - // driver.createDatabase(DATABASE_NAME); - // } catch (final ArangoException e) { - // } - } - @BeforeClass public static void __setup() { final ArangoConfigure configure = new ArangoConfigure(); configure.setConnectRetryCount(2); configure.init(); - final ArangoDriver driver = new ArangoDriver(configure); - final ArangoDriver driverMDB = new ArangoDriver(configure, DATABASE_NAME); - // create mydb + try { driver.createDatabase(DATABASE_NAME); } catch (final ArangoException e) { } - BaseTest.driver = driverMDB; + driver.setDefaultDatabase(DATABASE_NAME); + + BaseTest.driver = driver; BaseTest.configure = configure; } @@ -123,7 +59,7 @@ public static void __shutdown() { configure.shutdown(); } - public boolean isMinimumVersion(final String version) throws ArangoException { + protected boolean isMinimumVersion(final String version) throws ArangoException { final ArangoVersion ver = driver.getVersion(); final int b = TestUtils.compareVersion(ver.getVersion(), version); return b > -1; diff --git a/src/test/java/com/arangodb/NegativeTest.java b/src/test/java/com/arangodb/NegativeTest.java index caaeb8d8c..da53b4844 100644 --- a/src/test/java/com/arangodb/NegativeTest.java +++ b/src/test/java/com/arangodb/NegativeTest.java @@ -35,10 +35,6 @@ */ public class NegativeTest extends BaseTest { - public NegativeTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - /** * 開発途中にあった命令だけど、今は存在しない。 きとんとエラーになること。 * @@ -48,17 +44,17 @@ public NegativeTest(ArangoConfigure configure, ArangoDriver driver) { @Test public void test_collections() throws ArangoException { - ArangoConfigure configure = new ArangoConfigure(); + final ArangoConfigure configure = new ArangoConfigure(); - HttpManager httpManager = new HttpManager(configure); + final HttpManager httpManager = new HttpManager(configure); httpManager.init(); // TODO Create configure of common test. - HttpResponseEntity res = httpManager.doGet("http://" + configure.getArangoHost().getHost() + ":" + final HttpResponseEntity res = httpManager.doGet("http://" + configure.getArangoHost().getHost() + ":" + configure.getArangoHost().getPort() + "/_api/collections", null); - DefaultEntity entity = EntityFactory.createEntity(res.getText(), DefaultEntity.class); + final DefaultEntity entity = EntityFactory.createEntity(res.getText(), DefaultEntity.class); assertThat(entity.isError(), is(true)); assertThat(entity.getCode(), is(501)); assertThat(entity.getErrorNumber(), is(9)); @@ -74,7 +70,7 @@ public String getName() { return name; } - public void setName(String name) { + public void setName(final String name) { this.name = name; } } @@ -82,21 +78,21 @@ public void setName(String name) { @Test public void test_issue_35_and_41() throws Exception { - ArangoConfigure configure = new ArangoConfigure(); + final ArangoConfigure configure = new ArangoConfigure(); configure.init(); - ArangoDriver driver = new ArangoDriver(configure); + final ArangoDriver driver = new ArangoDriver(configure); try { driver.createCollection("unit_test_issue35"); - } catch (ArangoException e) { + } catch (final ArangoException e) { } - TestComplex value = new TestComplex(); + final TestComplex value = new TestComplex(); value.setName("A\"A'@:///A"); // String value = "AAA"; - DocumentEntity doc = driver.createDocument("unit_test_issue35", value, true, true); - String documentHandle = doc.getDocumentHandle(); + final DocumentEntity doc = driver.createDocument("unit_test_issue35", value, true, true); + final String documentHandle = doc.getDocumentHandle(); driver.getDocument(documentHandle, TestComplex.class); configure.shutdown(); @@ -106,22 +102,22 @@ public void test_issue_35_and_41() throws Exception { @Test public void test_primitive() throws Exception { - ArangoConfigure configure = new ArangoConfigure(); + final ArangoConfigure configure = new ArangoConfigure(); configure.init(); - ArangoDriver driver = new ArangoDriver(configure); + final ArangoDriver driver = new ArangoDriver(configure); try { driver.createCollection("unit_test_issue35"); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { - String value = "AAA"; - DocumentEntity doc = driver.createDocument("unit_test_issue35", value, true, true); - String documentHandle = doc.getDocumentHandle(); + final String value = "AAA"; + final DocumentEntity doc = driver.createDocument("unit_test_issue35", value, true, true); + final String documentHandle = doc.getDocumentHandle(); driver.getDocument(documentHandle, String.class); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } diff --git a/src/test/java/com/arangodb/PrimitiveDocumentTest.java b/src/test/java/com/arangodb/PrimitiveDocumentTest.java index e9a77dbb4..f986503a0 100644 --- a/src/test/java/com/arangodb/PrimitiveDocumentTest.java +++ b/src/test/java/com/arangodb/PrimitiveDocumentTest.java @@ -37,15 +37,11 @@ public class PrimitiveDocumentTest extends BaseTest { private static Logger logger = LoggerFactory.getLogger(PrimitiveDocumentTest.class); - public PrimitiveDocumentTest(ArangoConfigure configure, ArangoDriver driver) { - super(configure, driver); - } - @Before public void setUp() { try { driver.createCollection("unit_test_primitive"); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @@ -53,11 +49,11 @@ public void setUp() { @Test public void test_string() throws ArangoException { - String value = "AAA"; + final String value = "AAA"; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } } @@ -65,12 +61,12 @@ public void test_string() throws ArangoException { @Test public void test_string_quote() throws ArangoException { - String value = "AA\"A"; + final String value = "AA\"A"; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } } @@ -78,12 +74,12 @@ public void test_string_quote() throws ArangoException { @Test public void test_string_multibyte1() throws ArangoException { - String value = "AA☆A"; + final String value = "AA☆A"; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } } @@ -91,13 +87,13 @@ public void test_string_multibyte1() throws ArangoException { @Test public void test_string_multibyte2() throws ArangoException { - TestComplexEntity01 value = new TestComplexEntity01("寿司", "", 10); + final TestComplexEntity01 value = new TestComplexEntity01("寿司", "", 10); logger.debug(new Gson().toJson(value)); - DocumentEntity res = driver.createDocument("unit_test_primitive", value, true, true); - String documentHandle = res.getDocumentHandle(); + final DocumentEntity res = driver.createDocument("unit_test_primitive", value, true, true); + final String documentHandle = res.getDocumentHandle(); - DocumentEntity doc = driver.getDocument(documentHandle, TestComplexEntity01.class); + final DocumentEntity doc = driver.getDocument(documentHandle, TestComplexEntity01.class); logger.debug(doc.getEntity().getUser()); logger.debug(doc.getEntity().getDesc()); logger.debug(doc.getEntity().getAge().toString()); @@ -106,11 +102,11 @@ public void test_string_multibyte2() throws ArangoException { @Test public void test_string_escape() throws ArangoException { - String value = "\\\\"; + final String value = "\\\\"; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } } @@ -118,12 +114,12 @@ public void test_string_escape() throws ArangoException { @Test public void test_string_spchar() throws ArangoException { - String value = "AA\t\nA;/@*:='&%$#!~\\"; + final String value = "AA\t\nA;/@*:='&%$#!~\\"; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } } @@ -131,11 +127,11 @@ public void test_string_spchar() throws ArangoException { @Test public void test_null() throws ArangoException { - String value = null; + final String value = null; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } } @@ -143,12 +139,12 @@ public void test_null() throws ArangoException { @Test public void test_boolean_true() throws ArangoException { - boolean value = true; + final boolean value = true; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } @@ -157,11 +153,11 @@ public void test_boolean_true() throws ArangoException { @Test public void test_boolean_false() throws ArangoException { - boolean value = false; + final boolean value = false; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } @@ -170,12 +166,12 @@ public void test_boolean_false() throws ArangoException { @Test public void test_number_int() throws ArangoException { - int value = 1000000; + final int value = 1000000; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } @@ -184,12 +180,12 @@ public void test_number_int() throws ArangoException { @Test public void test_number_long() throws ArangoException { - long value = Long.MAX_VALUE; + final long value = Long.MAX_VALUE; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } @@ -199,12 +195,12 @@ public void test_number_long() throws ArangoException { @Ignore public void test_number_double() throws ArangoException { - double value = Double.MAX_VALUE; + final double value = Double.MAX_VALUE; try { driver.createDocument("unit_test_primitive", value, true, true); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); } diff --git a/src/test/java/com/arangodb/bench/BenchmarkImport.java b/src/test/java/com/arangodb/bench/BenchmarkImport.java index b4daed8b3..cd7f036a8 100644 --- a/src/test/java/com/arangodb/bench/BenchmarkImport.java +++ b/src/test/java/com/arangodb/bench/BenchmarkImport.java @@ -23,8 +23,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.Station; import com.arangodb.example.document.BaseExample; @@ -46,14 +44,6 @@ public class BenchmarkImport extends BaseExample { private static final String DATABASE_NAME = "BenchmarkImport"; private static final String COLLECTION_NAME = "BenchmarkImportCollection"; - /** - * @param configure - * @param driver - */ - public BenchmarkImport(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/TransactionExample.java b/src/test/java/com/arangodb/example/TransactionExample.java index f2ce2b83d..6b7a04e74 100644 --- a/src/test/java/com/arangodb/example/TransactionExample.java +++ b/src/test/java/com/arangodb/example/TransactionExample.java @@ -24,7 +24,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.DocumentEntity; @@ -50,14 +49,6 @@ public class TransactionExample extends BaseExample { // increment counter 10 times private static final int NUMBER_UPDATES = 10; - /** - * @param configure - * @param driver - */ - public TransactionExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java index bf4e0c243..e7f5bfcb2 100644 --- a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java +++ b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java @@ -26,8 +26,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorResult; import com.arangodb.util.AqlQueryOptions; @@ -37,14 +35,6 @@ public class AqlQueryWithSpecialReturnTypesExample extends BaseExample { private static final String DATABASE_NAME = "SimplePersonAqlQueryWithLimitExample"; private static final String COLLECTION_NAME = "SimplePersonAqlQueryWithLimitExample"; - /** - * @param configure - * @param driver - */ - public AqlQueryWithSpecialReturnTypesExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/BaseExample.java b/src/test/java/com/arangodb/example/document/BaseExample.java index 895baa1f0..94a288982 100644 --- a/src/test/java/com/arangodb/example/document/BaseExample.java +++ b/src/test/java/com/arangodb/example/document/BaseExample.java @@ -18,7 +18,6 @@ import org.junit.Assert; -import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.BaseTest; @@ -30,14 +29,6 @@ public class BaseExample extends BaseTest { protected static final String FEMALE = "female"; protected static final String MALE = "male"; - /** - * @param configure - * @param driver - */ - public BaseExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - protected void removeTestDatabase(final String name) { try { driver.deleteDatabase(name); diff --git a/src/test/java/com/arangodb/example/document/CollectionExample.java b/src/test/java/com/arangodb/example/document/CollectionExample.java index 3afc3767c..6810bf1e4 100644 --- a/src/test/java/com/arangodb/example/document/CollectionExample.java +++ b/src/test/java/com/arangodb/example/document/CollectionExample.java @@ -21,8 +21,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.CollectionEntity; import com.arangodb.entity.CollectionsEntity; @@ -31,14 +29,6 @@ public class CollectionExample extends BaseExample { private static final String DATABASE_NAME = "CreateCollectionExample"; - /** - * @param configure - * @param driver - */ - public CollectionExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/CreateAndDeleteDatabaseExample.java b/src/test/java/com/arangodb/example/document/CreateAndDeleteDatabaseExample.java index 7e34103c0..c28cab71c 100644 --- a/src/test/java/com/arangodb/example/document/CreateAndDeleteDatabaseExample.java +++ b/src/test/java/com/arangodb/example/document/CreateAndDeleteDatabaseExample.java @@ -30,14 +30,6 @@ public class CreateAndDeleteDatabaseExample extends BaseExample { private static final String DATABASE_NAME = "CreateDatabaseExample"; - /** - * @param configure - * @param driver - */ - public CreateAndDeleteDatabaseExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/CreateDocumentExample.java b/src/test/java/com/arangodb/example/document/CreateDocumentExample.java index 9f32e5d97..1289760ac 100644 --- a/src/test/java/com/arangodb/example/document/CreateDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/CreateDocumentExample.java @@ -23,8 +23,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.BaseDocument; import com.arangodb.entity.DocumentEntity; @@ -43,14 +41,6 @@ public class CreateDocumentExample extends BaseExample { private static final String KEY4 = "key4"; - /** - * @param configure - * @param driver - */ - public CreateDocumentExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java b/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java index 5821aa863..8575ba00b 100644 --- a/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java @@ -24,8 +24,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.DocumentCursor; import com.arangodb.util.AqlQueryOptions; @@ -35,14 +33,6 @@ public class DocumentPersonAqlQueryExample extends BaseExample { private static final String DATABASE_NAME = "DocumentPersonAqlQueryExample"; private static final String COLLECTION_NAME = "DocumentPersonAqlQueryExample"; - /** - * @param configure - * @param driver - */ - public DocumentPersonAqlQueryExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/RawDocumentExample.java b/src/test/java/com/arangodb/example/document/RawDocumentExample.java index 1055a039b..79daf597f 100644 --- a/src/test/java/com/arangodb/example/document/RawDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/RawDocumentExample.java @@ -26,8 +26,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorRawResult; import com.arangodb.ErrorNums; @@ -38,14 +36,6 @@ public class RawDocumentExample extends BaseExample { private static final String DATABASE_NAME = "RawDocument"; private static final String COLLECTION_NAME = "RawDocument"; - /** - * @param configure - * @param driver - */ - public RawDocumentExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/ReadDocumentExample.java b/src/test/java/com/arangodb/example/document/ReadDocumentExample.java index 1416902ea..25810b6e6 100644 --- a/src/test/java/com/arangodb/example/document/ReadDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/ReadDocumentExample.java @@ -24,8 +24,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.BaseDocument; import com.arangodb.entity.CollectionEntity; @@ -39,14 +37,6 @@ public class ReadDocumentExample extends BaseExample { private static final String KEY1 = "key1"; - /** - * @param configure - * @param driver - */ - public ReadDocumentExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java b/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java index 7d2e77596..0ffa76b57 100644 --- a/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java @@ -23,8 +23,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.ErrorNums; import com.arangodb.entity.DocumentEntity; @@ -38,14 +36,6 @@ public class ReplaceAndUpdateDocumentExample extends BaseExample { private static final String KEY1 = "key1"; - /** - * @param configure - * @param driver - */ - public ReplaceAndUpdateDocumentExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java index 32db2849d..bed79eb83 100644 --- a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java @@ -24,8 +24,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.DocumentCursor; import com.arangodb.entity.DocumentEntity; @@ -37,14 +35,6 @@ public class SimplePersonAqlQueryExample extends BaseExample { private static final String COLLECTION_NAME = "SimplePersonAqlQueryExample"; - /** - * @param configure - * @param driver - */ - public SimplePersonAqlQueryExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java index 9c7f240ce..3bf19bf72 100644 --- a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java +++ b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java @@ -24,8 +24,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.DocumentCursor; import com.arangodb.entity.DocumentEntity; @@ -37,14 +35,6 @@ public class SimplePersonAqlQueryWithLimitExample extends BaseExample { private static final String COLLECTION_NAME = "SimplePersonAqlQueryWithLimitExample"; - /** - * @param configure - * @param driver - */ - public SimplePersonAqlQueryWithLimitExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/graph/BaseExample.java b/src/test/java/com/arangodb/example/graph/BaseExample.java index dbf07c32d..d637673be 100644 --- a/src/test/java/com/arangodb/example/graph/BaseExample.java +++ b/src/test/java/com/arangodb/example/graph/BaseExample.java @@ -21,7 +21,6 @@ import org.junit.Assert; -import com.arangodb.ArangoConfigure; import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.BaseTest; @@ -36,14 +35,6 @@ public class BaseExample extends BaseTest { - /** - * @param configure - * @param driver - */ - public BaseExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - protected void removeTestDatabase(final String name) { try { driver.deleteDatabase(name); diff --git a/src/test/java/com/arangodb/example/graph/CreateGraphExample.java b/src/test/java/com/arangodb/example/graph/CreateGraphExample.java index 762b0f14d..d07eb8e72 100644 --- a/src/test/java/com/arangodb/example/graph/CreateGraphExample.java +++ b/src/test/java/com/arangodb/example/graph/CreateGraphExample.java @@ -24,8 +24,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.CollectionEntity; import com.arangodb.entity.CollectionOptions; @@ -47,14 +45,6 @@ public class CreateGraphExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - /** - * @param configure - * @param driver - */ - public CreateGraphExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/graph/CreateVerticesAndEdgesExample.java b/src/test/java/com/arangodb/example/graph/CreateVerticesAndEdgesExample.java index c3d897975..af6570b21 100644 --- a/src/test/java/com/arangodb/example/graph/CreateVerticesAndEdgesExample.java +++ b/src/test/java/com/arangodb/example/graph/CreateVerticesAndEdgesExample.java @@ -21,8 +21,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.EdgeEntity; import com.arangodb.entity.marker.VertexEntity; @@ -41,14 +39,6 @@ public class CreateVerticesAndEdgesExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - /** - * @param configure - * @param driver - */ - public CreateVerticesAndEdgesExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/graph/DeleteVerticesAndEdgesExample.java b/src/test/java/com/arangodb/example/graph/DeleteVerticesAndEdgesExample.java index b3356f228..161570632 100644 --- a/src/test/java/com/arangodb/example/graph/DeleteVerticesAndEdgesExample.java +++ b/src/test/java/com/arangodb/example/graph/DeleteVerticesAndEdgesExample.java @@ -5,8 +5,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.ErrorNums; import com.arangodb.entity.DeletedEntity; @@ -27,14 +25,6 @@ public class DeleteVerticesAndEdgesExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - /** - * @param configure - * @param driver - */ - public DeleteVerticesAndEdgesExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/graph/GetVerticesAndEdgesExample.java b/src/test/java/com/arangodb/example/graph/GetVerticesAndEdgesExample.java index 257570093..41b1156e4 100644 --- a/src/test/java/com/arangodb/example/graph/GetVerticesAndEdgesExample.java +++ b/src/test/java/com/arangodb/example/graph/GetVerticesAndEdgesExample.java @@ -8,8 +8,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.Direction; import com.arangodb.EdgeCursor; @@ -32,14 +30,6 @@ public class GetVerticesAndEdgesExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - /** - * @param configure - * @param driver - */ - public GetVerticesAndEdgesExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java b/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java index bf10157e4..d246ad7ae 100644 --- a/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java @@ -26,8 +26,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorResult; import com.arangodb.Direction; @@ -53,14 +51,6 @@ public class GraphAqlQueryExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - /** - * @param configure - * @param driver - */ - public GraphAqlQueryExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/graph/GraphAqlTraversalQueryExample.java b/src/test/java/com/arangodb/example/graph/GraphAqlTraversalQueryExample.java index a84af3b8c..5e8e36769 100644 --- a/src/test/java/com/arangodb/example/graph/GraphAqlTraversalQueryExample.java +++ b/src/test/java/com/arangodb/example/graph/GraphAqlTraversalQueryExample.java @@ -24,8 +24,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorResult; import com.arangodb.entity.EdgeEntity; @@ -47,14 +45,6 @@ public class GraphAqlTraversalQueryExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edges"; private static final String VERTEXT_COLLECTION_NAME = "circles"; - /** - * @param configure - * @param driver - */ - public GraphAqlTraversalQueryExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); diff --git a/src/test/java/com/arangodb/example/graph/UpdateAndReplaceVertexExample.java b/src/test/java/com/arangodb/example/graph/UpdateAndReplaceVertexExample.java index 2c2b162f5..c8ea67bdf 100644 --- a/src/test/java/com/arangodb/example/graph/UpdateAndReplaceVertexExample.java +++ b/src/test/java/com/arangodb/example/graph/UpdateAndReplaceVertexExample.java @@ -5,8 +5,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.entity.marker.VertexEntity; @@ -24,14 +22,6 @@ public class UpdateAndReplaceVertexExample extends BaseExample { private static final String EDGE_COLLECTION_NAME = "edgeColl1"; private static final String VERTEXT_COLLECTION_NAME = "vertexColl1"; - /** - * @param configure - * @param driver - */ - public UpdateAndReplaceVertexExample(final ArangoConfigure configure, final ArangoDriver driver) { - super(configure, driver); - } - @Before public void _before() throws ArangoException { removeTestDatabase(DATABASE_NAME); From 34d97dc07249a2802c5326d476baaa845dc8b9b3 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 24 May 2016 13:36:29 +0200 Subject: [PATCH 11/56] optimize tests (too many open http connections) -step 3 --- .../java/com/arangodb/ArangoTestSuite.java | 13 ++++++++++ src/test/java/com/arangodb/BaseTest.java | 26 +++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/arangodb/ArangoTestSuite.java b/src/test/java/com/arangodb/ArangoTestSuite.java index 8408ae112..5b66c19c2 100644 --- a/src/test/java/com/arangodb/ArangoTestSuite.java +++ b/src/test/java/com/arangodb/ArangoTestSuite.java @@ -16,6 +16,8 @@ package com.arangodb; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @@ -121,4 +123,15 @@ public class ArangoTestSuite { + @BeforeClass + public static void setup() { + BaseTest.__setup(); + BaseTest.MANAGE_SETUP = false; + } + + @AfterClass + public static void shutdown() { + BaseTest.MANAGE_SETUP = true; + BaseTest.__shutdown(); + } } diff --git a/src/test/java/com/arangodb/BaseTest.java b/src/test/java/com/arangodb/BaseTest.java index 7e0aceb61..a3abe9c50 100644 --- a/src/test/java/com/arangodb/BaseTest.java +++ b/src/test/java/com/arangodb/BaseTest.java @@ -30,33 +30,37 @@ public abstract class BaseTest { protected static final String DATABASE_NAME = "unitTestDatabase"; + protected static boolean MANAGE_SETUP = true; protected static ArangoConfigure configure; protected static ArangoDriver driver; @BeforeClass public static void __setup() { - final ArangoConfigure configure = new ArangoConfigure(); - configure.setConnectRetryCount(2); - configure.init(); - final ArangoDriver driver = new ArangoDriver(configure); + if (MANAGE_SETUP) { + final ArangoConfigure configure = new ArangoConfigure(); + configure.setConnectRetryCount(2); + configure.init(); + final ArangoDriver driver = new ArangoDriver(configure); + BaseTest.driver = driver; + BaseTest.configure = configure; + } try { driver.createDatabase(DATABASE_NAME); } catch (final ArangoException e) { } driver.setDefaultDatabase(DATABASE_NAME); - - BaseTest.driver = driver; - BaseTest.configure = configure; } @AfterClass public static void __shutdown() { - try { - driver.deleteDatabase(DATABASE_NAME); - } catch (final ArangoException e) { + if (MANAGE_SETUP) { + try { + driver.deleteDatabase(DATABASE_NAME); + } catch (final ArangoException e) { + } + configure.shutdown(); } - configure.shutdown(); } protected boolean isMinimumVersion(final String version) throws ArangoException { From accba9883b567b9d61e6b2b09304e13652a001d6 Mon Sep 17 00:00:00 2001 From: Mark Vollmary Date: Tue, 24 May 2016 13:49:04 +0200 Subject: [PATCH 12/56] close connection in test --- .../com/arangodb/example/ssl/SslExample.java | 158 +++++++++++------- 1 file changed, 96 insertions(+), 62 deletions(-) diff --git a/src/test/java/com/arangodb/example/ssl/SslExample.java b/src/test/java/com/arangodb/example/ssl/SslExample.java index 1ef9cf356..357bb9f94 100644 --- a/src/test/java/com/arangodb/example/ssl/SslExample.java +++ b/src/test/java/com/arangodb/example/ssl/SslExample.java @@ -75,68 +75,95 @@ public class SslExample { @Test public void httpTest() throws ArangoException { - ArangoConfigure configuration = new ArangoConfigure(); - // get host and port from arangodb.properties - // configuration.setArangoHost(new ArangoHost("localhost", 8529)); - configuration.init(); - - ArangoDriver arangoDriver = new ArangoDriver(configuration); - - ArangoVersion version = arangoDriver.getVersion(); - Assert.assertNotNull(version); - + ArangoConfigure configuration = null; + try { + configuration = new ArangoConfigure(); + // get host and port from arangodb.properties + // configuration.setArangoHost(new ArangoHost("localhost", 8529)); + configuration.init(); + + final ArangoDriver arangoDriver = new ArangoDriver(configuration); + + final ArangoVersion version = arangoDriver.getVersion(); + Assert.assertNotNull(version); + } finally { + if (configuration != null) { + configuration.shutdown(); + } + } } @Test public void sslConnectionTest() throws ArangoException { // use HTTPS with java default trust store - - ArangoConfigure configuration = new ArangoConfigure(); - configuration.setArangoHost(new ArangoHost("www.arangodb.com", 443)); - configuration.setUseSsl(true); - configuration.init(); - - ArangoDriver arangoDriver = new ArangoDriver(configuration); - - HttpResponseEntity response = arangoDriver.getHttpManager().doGet("/"); - Assert.assertEquals(200, response.getStatusCode()); + ArangoConfigure configuration = null; + try { + configuration = new ArangoConfigure(); + configuration.setArangoHost(new ArangoHost("www.arangodb.com", 443)); + configuration.setUseSsl(true); + configuration.init(); + + final ArangoDriver arangoDriver = new ArangoDriver(configuration); + + final HttpResponseEntity response = arangoDriver.getHttpManager().doGet("/"); + Assert.assertEquals(200, response.getStatusCode()); + } finally { + if (configuration != null) { + configuration.shutdown(); + } + } } @Test public void sslWithSelfSignedCertificateTest() throws ArangoException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, URISyntaxException { - // create a sslContext for the self signed certificate - URL resource = this.getClass().getResource(SSL_TRUSTSTORE); - SSLContext sslContext = SSLContexts.custom() - .loadTrustMaterial(Paths.get(resource.toURI()).toFile(), SSL_TRUSTSTORE_PASSWORD.toCharArray()).build(); - - ArangoConfigure configuration = new ArangoConfigure("/ssl-arangodb.properties"); - configuration.setSslContext(sslContext); - configuration.init(); - - ArangoDriver arangoDriver = new ArangoDriver(configuration); - - ArangoVersion version = arangoDriver.getVersion(); - Assert.assertNotNull(version); + ArangoConfigure configuration = null; + try { + // create a sslContext for the self signed certificate + final URL resource = this.getClass().getResource(SSL_TRUSTSTORE); + final SSLContext sslContext = SSLContexts.custom() + .loadTrustMaterial(Paths.get(resource.toURI()).toFile(), SSL_TRUSTSTORE_PASSWORD.toCharArray()) + .build(); + + configuration = new ArangoConfigure("/ssl-arangodb.properties"); + configuration.setSslContext(sslContext); + configuration.init(); + + final ArangoDriver arangoDriver = new ArangoDriver(configuration); + + final ArangoVersion version = arangoDriver.getVersion(); + Assert.assertNotNull(version); + } finally { + if (configuration != null) { + configuration.shutdown(); + } + } } @Test public void sslHandshakeExceptionTest() { - ArangoConfigure configuration = new ArangoConfigure("/ssl-arangodb.properties"); - configuration.init(); + ArangoConfigure configuration = null; + try { + configuration = new ArangoConfigure("/ssl-arangodb.properties"); + configuration.init(); - ArangoDriver arangoDriver = new ArangoDriver(configuration); + final ArangoDriver arangoDriver = new ArangoDriver(configuration); - try { - // java do not trust self signed certificates + try { + // java do not trust self signed certificates - arangoDriver.getVersion(); - Assert.fail("this should fail"); + arangoDriver.getVersion(); + Assert.fail("this should fail"); - } catch (ArangoException e) { - Throwable cause = e.getCause(); - Assert.assertTrue(cause instanceof javax.net.ssl.SSLHandshakeException); + } catch (final ArangoException e) { + final Throwable cause = e.getCause(); + Assert.assertTrue(cause instanceof javax.net.ssl.SSLHandshakeException); + } + } finally { + if (configuration != null) { + configuration.shutdown(); + } } } @@ -144,27 +171,34 @@ public void sslHandshakeExceptionTest() { public void sslPeerUnverifiedExceptionTest() throws ArangoException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, URISyntaxException { - // create a sslContext for the self signed certificate - URL resource = this.getClass().getResource(SSL_TRUSTSTORE); - SSLContext sslContext = SSLContexts.custom() - .loadTrustMaterial(Paths.get(resource.toURI()).toFile(), SSL_TRUSTSTORE_PASSWORD.toCharArray()).build(); - - ArangoConfigure configuration = new ArangoConfigure("/ssl-arangodb.properties"); - // 127.0.0.1 is the wrong name - configuration.getArangoHost().setHost("127.0.0.1"); - configuration.setSslContext(sslContext); - configuration.init(); - - ArangoDriver arangoDriver = new ArangoDriver(configuration); - + ArangoConfigure configuration = null; try { - arangoDriver.getVersion(); - Assert.fail("this should fail"); - } catch (ArangoException e) { - Throwable cause = e.getCause(); - Assert.assertTrue(cause instanceof javax.net.ssl.SSLPeerUnverifiedException); + // create a sslContext for the self signed certificate + final URL resource = this.getClass().getResource(SSL_TRUSTSTORE); + final SSLContext sslContext = SSLContexts.custom() + .loadTrustMaterial(Paths.get(resource.toURI()).toFile(), SSL_TRUSTSTORE_PASSWORD.toCharArray()) + .build(); + + configuration = new ArangoConfigure("/ssl-arangodb.properties"); + // 127.0.0.1 is the wrong name + configuration.getArangoHost().setHost("127.0.0.1"); + configuration.setSslContext(sslContext); + configuration.init(); + + final ArangoDriver arangoDriver = new ArangoDriver(configuration); + + try { + arangoDriver.getVersion(); + Assert.fail("this should fail"); + } catch (final ArangoException e) { + final Throwable cause = e.getCause(); + Assert.assertTrue(cause instanceof javax.net.ssl.SSLPeerUnverifiedException); + } + } finally { + if (configuration != null) { + configuration.shutdown(); + } } - } } From 3f99641ff072f14d574ed54ad3358e5b373d6a5a Mon Sep 17 00:00:00 2001 From: Mark Vollmary Date: Tue, 24 May 2016 14:39:49 +0200 Subject: [PATCH 13/56] URL parameter "createCollection" not supported by POST "/_api/document" --- src/main/java/com/arangodb/ArangoDriver.java | 1474 +++++++++-------- .../com/arangodb/InternalDocumentDriver.java | 2 - .../impl/InternalDocumentDriverImpl.java | 173 +- .../com/arangodb/ArangoDriverAsyncTest.java | 8 +- .../com/arangodb/ArangoDriverBatchTest.java | 6 +- .../arangodb/ArangoDriverCollectionTest.java | 13 +- .../ArangoDriverCursorResultSetTest.java | 2 +- .../com/arangodb/ArangoDriverCursorTest.java | 8 +- .../ArangoDriverDocumentCursorEntityTest.java | 2 +- .../ArangoDriverDocumentCursorTest.java | 2 +- .../arangodb/ArangoDriverDocumentKeyTest.java | 50 +- .../arangodb/ArangoDriverDocumentTest.java | 48 +- .../com/arangodb/ArangoDriverIndexTest.java | 8 +- .../arangodb/ArangoDriverReplicationTest.java | 16 +- .../ArangoDriverReplicationTestScenario1.java | 9 +- .../arangodb/ArangoDriverSimpleGeoTest.java | 2 +- .../com/arangodb/ArangoDriverSimpleTest.java | 12 +- .../arangodb/ArangoDriverThreadSafeTest.java | 25 +- src/test/java/com/arangodb/NegativeTest.java | 2 +- .../com/arangodb/PrimitiveDocumentTest.java | 12 +- .../SingleDocumentBenchmarkImporter.java | 8 +- .../arangodb/example/TransactionExample.java | 4 +- ...AqlQueryWithSpecialReturnTypesExample.java | 2 +- .../DocumentPersonAqlQueryExample.java | 2 +- .../example/document/RawDocumentExample.java | 6 +- .../document/SimplePersonAqlQueryExample.java | 2 +- .../SimplePersonAqlQueryWithLimitExample.java | 2 +- 27 files changed, 992 insertions(+), 908 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 5bc48d80f..119c1fb17 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -104,8 +104,8 @@ public class ArangoDriver extends BaseArangoDriver { private static final String GRAPH_NAME = "graphName"; private static final String VERTEX_EXAMPLE = "vertexExample"; - private ArangoConfigure configure; - private BatchHttpManager httpManager; + private final ArangoConfigure configure; + private final BatchHttpManager httpManager; private InternalCursorDriver cursorDriver; private InternalBatchDriverImpl batchDriver; @@ -135,7 +135,7 @@ public class ArangoDriver extends BaseArangoDriver { * @param configure * A configuration object. */ - public ArangoDriver(ArangoConfigure configure) { + public ArangoDriver(final ArangoConfigure configure) { this(configure, null); } @@ -148,7 +148,7 @@ public ArangoDriver(ArangoConfigure configure) { * @param database * the name of the database that will be used. */ - public ArangoDriver(ArangoConfigure configure, String database) { + public ArangoDriver(final ArangoConfigure configure, final String database) { this.database = configure.getDefaultDatabase(); if (database != null) { @@ -199,12 +199,13 @@ public void startBatchMode() throws ArangoException { * @see ArangoDriver#getLastJobId() * @throws com.arangodb.ArangoException */ - public void startAsyncMode(boolean fireAndForget) throws ArangoException { + public void startAsyncMode(final boolean fireAndForget) throws ArangoException { if (this.httpManager.getHttpMode().equals(HttpManager.HttpMode.ASYNC) || this.httpManager.getHttpMode().equals(HttpManager.HttpMode.FIREANDFORGET)) { throw new ArangoException("Arango driver already set to asynchronous mode."); } - HttpManager.HttpMode mode = fireAndForget ? HttpManager.HttpMode.FIREANDFORGET : HttpManager.HttpMode.ASYNC; + final HttpManager.HttpMode mode = fireAndForget ? HttpManager.HttpMode.FIREANDFORGET + : HttpManager.HttpMode.ASYNC; this.httpManager.setHttpMode(mode); this.createModuleDrivers(true); this.httpManager.resetJobs(); @@ -277,7 +278,7 @@ public List getJobIds() { * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int) * @see ArangoDriver#getLastJobId() */ - public List getJobs(JobsEntity.JobState jobState, int count) throws ArangoException { + public List getJobs(final JobsEntity.JobState jobState, final int count) throws ArangoException { return this.jobsDriver.getJobs(getDefaultDatabase(), jobState, count); } @@ -296,7 +297,7 @@ public List getJobs(JobsEntity.JobState jobState, int count) throws Aran * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int) * @see ArangoDriver#getLastJobId() */ - public List getJobs(JobsEntity.JobState jobState) throws ArangoException { + public List getJobs(final JobsEntity.JobState jobState) throws ArangoException { return this.jobsDriver.getJobs(getDefaultDatabase(), jobState); } @@ -327,7 +328,7 @@ public void deleteAllJobs() throws ArangoException { * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int) * @see ArangoDriver#getLastJobId() */ - public void deleteJobById(String jobId) throws ArangoException { + public void deleteJobById(final String jobId) throws ArangoException { this.jobsDriver.deleteJobById(getDefaultDatabase(), jobId); } @@ -343,7 +344,7 @@ public void deleteJobById(String jobId) throws ArangoException { * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int) * @see ArangoDriver#getLastJobId() */ - public void deleteExpiredJobs(int timeStamp) throws ArangoException { + public void deleteExpiredJobs(final int timeStamp) throws ArangoException { this.jobsDriver.deleteExpiredJobs(getDefaultDatabase(), timeStamp); } @@ -360,7 +361,7 @@ public void deleteExpiredJobs(int timeStamp) throws ArangoException { * @see com.arangodb.ArangoDriver#deleteExpiredJobs(int) * @see ArangoDriver#getLastJobId() */ - public T getJobResult(String jobId) throws ArangoException { + public T getJobResult(final String jobId) throws ArangoException { return this.jobsDriver.getJobResult(getDefaultDatabase(), jobId); } @@ -375,7 +376,7 @@ public DefaultEntity executeBatch() throws ArangoException { if (!this.httpManager.isBatchModeActive()) { throw new ArangoException("BatchMode is not active."); } - List callStack = this.httpManager.getCallStack(); + final List callStack = this.httpManager.getCallStack(); this.cancelBatchMode(); return this.batchDriver.executeBatch(callStack, this.getDefaultDatabase()); } @@ -393,22 +394,22 @@ public DefaultEntity executeBatch() throws ArangoException { * @throws com.arangodb.ArangoException */ @SuppressWarnings("unchecked") - public T getBatchResponseByRequestId(String requestId) throws ArangoException { - BatchResponseEntity batchResponseEntity = this.batchDriver.getBatchResponseListEntity() + public T getBatchResponseByRequestId(final String requestId) throws ArangoException { + final BatchResponseEntity batchResponseEntity = this.batchDriver.getBatchResponseListEntity() .getResponseFromRequestId(requestId); try { this.httpManager.setPreDefinedResponse(batchResponseEntity.getHttpResponseEntity()); - T result = (T) batchResponseEntity.getInvocationObject().getMethod().invoke( + final T result = (T) batchResponseEntity.getInvocationObject().getMethod().invoke( batchResponseEntity.getInvocationObject().getArangoDriver(), batchResponseEntity.getInvocationObject().getArgs()); this.httpManager.setPreDefinedResponse(null); return result; - } catch (InvocationTargetException e) { - T result = (T) createEntity(batchResponseEntity.getHttpResponseEntity(), DefaultEntity.class); + } catch (final InvocationTargetException e) { + final T result = (T) createEntity(batchResponseEntity.getHttpResponseEntity(), DefaultEntity.class); this.httpManager.setPreDefinedResponse(null); return result; - } catch (Exception e) { + } catch (final Exception e) { this.httpManager.setPreDefinedResponse(null); throw new ArangoException(e); } @@ -446,7 +447,7 @@ public String getDefaultDatabase() { * * @param database */ - public void setDefaultDatabase(String database) { + public void setDefaultDatabase(final String database) { this.database = database; } @@ -458,7 +459,7 @@ public void setDefaultDatabase(String database) { * @return CollectionEntity - the created collectionEntity. * @throws ArangoException */ - public CollectionEntity createCollection(String name) throws ArangoException { + public CollectionEntity createCollection(final String name) throws ArangoException { return collectionDriver.createCollection(getDefaultDatabase(), name, new CollectionOptions()); } @@ -472,7 +473,8 @@ public CollectionEntity createCollection(String name) throws ArangoException { * @return CollectionEntity - the created collectionEntity. * @throws ArangoException */ - public CollectionEntity createCollection(String name, CollectionOptions collectionOptions) throws ArangoException { + public CollectionEntity createCollection(final String name, final CollectionOptions collectionOptions) + throws ArangoException { return collectionDriver.createCollection(getDefaultDatabase(), name, collectionOptions); } @@ -484,7 +486,7 @@ public CollectionEntity createCollection(String name, CollectionOptions collecti * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollection(long id) throws ArangoException { + public CollectionEntity getCollection(final long id) throws ArangoException { return getCollection(String.valueOf(id)); } @@ -496,7 +498,7 @@ public CollectionEntity getCollection(long id) throws ArangoException { * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollection(String name) throws ArangoException { + public CollectionEntity getCollection(final String name) throws ArangoException { return collectionDriver.getCollection(getDefaultDatabase(), name); } @@ -508,7 +510,7 @@ public CollectionEntity getCollection(String name) throws ArangoException { * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionProperties(long id) throws ArangoException { + public CollectionEntity getCollectionProperties(final long id) throws ArangoException { return getCollectionProperties(String.valueOf(id)); } @@ -520,7 +522,7 @@ public CollectionEntity getCollectionProperties(long id) throws ArangoException * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionProperties(String name) throws ArangoException { + public CollectionEntity getCollectionProperties(final String name) throws ArangoException { return collectionDriver.getCollectionProperties(getDefaultDatabase(), name); } @@ -532,7 +534,7 @@ public CollectionEntity getCollectionProperties(String name) throws ArangoExcept * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionRevision(long id) throws ArangoException { + public CollectionEntity getCollectionRevision(final long id) throws ArangoException { return getCollectionRevision(String.valueOf(id)); } @@ -544,7 +546,7 @@ public CollectionEntity getCollectionRevision(long id) throws ArangoException { * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionRevision(String name) throws ArangoException { + public CollectionEntity getCollectionRevision(final String name) throws ArangoException { return collectionDriver.getCollectionRevision(getDefaultDatabase(), name); } @@ -556,7 +558,7 @@ public CollectionEntity getCollectionRevision(String name) throws ArangoExceptio * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionCount(long id) throws ArangoException { + public CollectionEntity getCollectionCount(final long id) throws ArangoException { return getCollectionCount(String.valueOf(id)); } @@ -568,7 +570,7 @@ public CollectionEntity getCollectionCount(long id) throws ArangoException { * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionCount(String name) throws ArangoException { + public CollectionEntity getCollectionCount(final String name) throws ArangoException { return collectionDriver.getCollectionCount(getDefaultDatabase(), name); } @@ -580,7 +582,7 @@ public CollectionEntity getCollectionCount(String name) throws ArangoException { * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionFigures(long id) throws ArangoException { + public CollectionEntity getCollectionFigures(final long id) throws ArangoException { return getCollectionFigures(String.valueOf(id)); } @@ -593,7 +595,7 @@ public CollectionEntity getCollectionFigures(long id) throws ArangoException { * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionFigures(String name) throws ArangoException { + public CollectionEntity getCollectionFigures(final String name) throws ArangoException { return collectionDriver.getCollectionFigures(getDefaultDatabase(), name); } @@ -610,8 +612,10 @@ public CollectionEntity getCollectionFigures(String name) throws ArangoException * @return CollectionEntity - the requested collectionEntity. * @throws ArangoException */ - public CollectionEntity getCollectionChecksum(String name, Boolean withRevisions, Boolean withData) - throws ArangoException { + public CollectionEntity getCollectionChecksum( + final String name, + final Boolean withRevisions, + final Boolean withData) throws ArangoException { return collectionDriver.getCollectionChecksum(getDefaultDatabase(), name, withRevisions, withData); } @@ -634,7 +638,7 @@ public CollectionsEntity getCollections() throws ArangoException { * @return CollectionsEntity - the CollectionsEntity. * @throws ArangoException */ - public CollectionsEntity getCollections(Boolean excludeSystem) throws ArangoException { + public CollectionsEntity getCollections(final Boolean excludeSystem) throws ArangoException { return collectionDriver.getCollections(getDefaultDatabase(), excludeSystem); } @@ -646,7 +650,7 @@ public CollectionsEntity getCollections(Boolean excludeSystem) throws ArangoExce * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity loadCollection(long id) throws ArangoException { + public CollectionEntity loadCollection(final long id) throws ArangoException { return collectionDriver.loadCollection(getDefaultDatabase(), String.valueOf(id), null); } @@ -658,7 +662,7 @@ public CollectionEntity loadCollection(long id) throws ArangoException { * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity loadCollection(String name) throws ArangoException { + public CollectionEntity loadCollection(final String name) throws ArangoException { return collectionDriver.loadCollection(getDefaultDatabase(), name, null); } @@ -672,7 +676,7 @@ public CollectionEntity loadCollection(String name) throws ArangoException { * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity loadCollection(long id, Boolean count) throws ArangoException { + public CollectionEntity loadCollection(final long id, final Boolean count) throws ArangoException { return collectionDriver.loadCollection(getDefaultDatabase(), String.valueOf(id), count); } @@ -686,7 +690,7 @@ public CollectionEntity loadCollection(long id, Boolean count) throws ArangoExce * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity loadCollection(String name, Boolean count) throws ArangoException { + public CollectionEntity loadCollection(final String name, final Boolean count) throws ArangoException { return collectionDriver.loadCollection(getDefaultDatabase(), name, count); } @@ -698,7 +702,7 @@ public CollectionEntity loadCollection(String name, Boolean count) throws Arango * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity unloadCollection(long id) throws ArangoException { + public CollectionEntity unloadCollection(final long id) throws ArangoException { return unloadCollection(String.valueOf(id)); } @@ -710,7 +714,7 @@ public CollectionEntity unloadCollection(long id) throws ArangoException { * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity unloadCollection(String name) throws ArangoException { + public CollectionEntity unloadCollection(final String name) throws ArangoException { return collectionDriver.unloadCollection(getDefaultDatabase(), name); } @@ -722,7 +726,7 @@ public CollectionEntity unloadCollection(String name) throws ArangoException { * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity truncateCollection(long id) throws ArangoException { + public CollectionEntity truncateCollection(final long id) throws ArangoException { return truncateCollection(String.valueOf(id)); } @@ -734,7 +738,7 @@ public CollectionEntity truncateCollection(long id) throws ArangoException { * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity truncateCollection(String name) throws ArangoException { + public CollectionEntity truncateCollection(final String name) throws ArangoException { return collectionDriver.truncateCollection(getDefaultDatabase(), name); } @@ -750,7 +754,7 @@ public CollectionEntity truncateCollection(String name) throws ArangoException { * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity setCollectionProperties(long id, Boolean newWaitForSync, Long journalSize) + public CollectionEntity setCollectionProperties(final long id, final Boolean newWaitForSync, final Long journalSize) throws ArangoException { return collectionDriver.setCollectionProperties(getDefaultDatabase(), String.valueOf(id), newWaitForSync, journalSize); @@ -768,8 +772,10 @@ public CollectionEntity setCollectionProperties(long id, Boolean newWaitForSync, * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity setCollectionProperties(String name, Boolean newWaitForSync, Long journalSize) - throws ArangoException { + public CollectionEntity setCollectionProperties( + final String name, + final Boolean newWaitForSync, + final Long journalSize) throws ArangoException { return collectionDriver.setCollectionProperties(getDefaultDatabase(), name, newWaitForSync, journalSize); } @@ -783,7 +789,7 @@ public CollectionEntity setCollectionProperties(String name, Boolean newWaitForS * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity renameCollection(long id, String newName) throws ArangoException { + public CollectionEntity renameCollection(final long id, final String newName) throws ArangoException { return renameCollection(String.valueOf(id), newName); } @@ -797,7 +803,7 @@ public CollectionEntity renameCollection(long id, String newName) throws ArangoE * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity renameCollection(String name, String newName) throws ArangoException { + public CollectionEntity renameCollection(final String name, final String newName) throws ArangoException { return collectionDriver.renameCollection(getDefaultDatabase(), name, newName); } @@ -809,7 +815,7 @@ public CollectionEntity renameCollection(String name, String newName) throws Ara * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity deleteCollection(long id) throws ArangoException { + public CollectionEntity deleteCollection(final long id) throws ArangoException { return deleteCollection(String.valueOf(id)); } @@ -821,7 +827,7 @@ public CollectionEntity deleteCollection(long id) throws ArangoException { * @return CollectionEntity - the collectionEntity. * @throws ArangoException */ - public CollectionEntity deleteCollection(String name) throws ArangoException { + public CollectionEntity deleteCollection(final String name) throws ArangoException { return collectionDriver.deleteCollection(getDefaultDatabase(), name); } @@ -835,8 +841,8 @@ public CollectionEntity deleteCollection(String name) throws ArangoException { * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity createDocument(long collectionId, Object value) throws ArangoException { - return createDocument(String.valueOf(collectionId), value, null, null); + public DocumentEntity createDocument(final long collectionId, final Object value) throws ArangoException { + return createDocument(String.valueOf(collectionId), value, null); } /** @@ -849,8 +855,8 @@ public DocumentEntity createDocument(long collectionId, Object value) throws * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity createDocument(String collectionName, T value) throws ArangoException { - return documentDriver.createDocument(getDefaultDatabase(), collectionName, null, value, null, null); + public DocumentEntity createDocument(final String collectionName, final T value) throws ArangoException { + return documentDriver.createDocument(getDefaultDatabase(), collectionName, null, value, null); } /** @@ -868,9 +874,9 @@ public DocumentEntity createDocument(String collectionName, T value) thro * @throws ArangoException * @see CollectionKeyOption#allowUserKeys */ - public DocumentEntity createDocument(long collectionId, String documentKey, Object value) + public DocumentEntity createDocument(final long collectionId, final String documentKey, final Object value) throws ArangoException { - return createDocument(String.valueOf(collectionId), documentKey, value, null, null); + return createDocument(String.valueOf(collectionId), documentKey, value, null); } /** @@ -888,9 +894,9 @@ public DocumentEntity createDocument(long collectionId, String documentKey, O * @throws ArangoException * @see CollectionKeyOption#allowUserKeys */ - public DocumentEntity createDocument(String collectionName, String documentKey, T value) + public DocumentEntity createDocument(final String collectionName, final String documentKey, final T value) throws ArangoException { - return documentDriver.createDocument(getDefaultDatabase(), collectionName, documentKey, value, null, null); + return documentDriver.createDocument(getDefaultDatabase(), collectionName, documentKey, value, null); } /** @@ -900,8 +906,6 @@ public DocumentEntity createDocument(String collectionName, String docume * The id of the collection * @param value * An object containing the documents attributes - * @param createCollection - * if set to true the collection is created if it does not exist * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -909,12 +913,9 @@ public DocumentEntity createDocument(String collectionName, String docume * @throws ArangoException * @see CollectionKeyOption#allowUserKeys */ - public DocumentEntity createDocument( - long collectionId, - T value, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - return createDocument(String.valueOf(collectionId), value, createCollection, waitForSync); + public DocumentEntity createDocument(final long collectionId, final T value, final Boolean waitForSync) + throws ArangoException { + return createDocument(String.valueOf(collectionId), value, waitForSync); } /** @@ -924,8 +925,6 @@ public DocumentEntity createDocument( * The name of the collection * @param value * An object containing the documents attributes - * @param createCollection - * if set to true the collection is created if it does not exist * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -933,13 +932,9 @@ public DocumentEntity createDocument( * @throws ArangoException * @see CollectionKeyOption#allowUserKeys */ - public DocumentEntity createDocument( - String collectionName, - T value, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - return documentDriver.createDocument(getDefaultDatabase(), collectionName, null, value, createCollection, - waitForSync); + public DocumentEntity createDocument(final String collectionName, final T value, final Boolean waitForSync) + throws ArangoException { + return documentDriver.createDocument(getDefaultDatabase(), collectionName, null, value, waitForSync); } /** @@ -963,12 +958,11 @@ public DocumentEntity createDocument( * @see CollectionKeyOption#allowUserKeys */ public DocumentEntity createDocument( - long collectionId, - String documentKey, - Object value, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - return createDocument(String.valueOf(collectionId), documentKey, value, createCollection, waitForSync); + final long collectionId, + final String documentKey, + final Object value, + final Boolean waitForSync) throws ArangoException { + return createDocument(String.valueOf(collectionId), documentKey, value, waitForSync); } /** @@ -992,13 +986,11 @@ public DocumentEntity createDocument( * @see CollectionKeyOption#allowUserKeys */ public DocumentEntity createDocument( - String collectionName, - String documentKey, - T value, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - return documentDriver.createDocument(getDefaultDatabase(), collectionName, documentKey, value, createCollection, - waitForSync); + final String collectionName, + final String documentKey, + final T value, + final Boolean waitForSync) throws ArangoException { + return documentDriver.createDocument(getDefaultDatabase(), collectionName, documentKey, value, waitForSync); } /** @@ -1013,7 +1005,8 @@ public DocumentEntity createDocument( * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity replaceDocument(long collectionId, long documentId, Object value) throws ArangoException { + public DocumentEntity replaceDocument(final long collectionId, final long documentId, final Object value) + throws ArangoException { return replaceDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null, null); } @@ -1029,7 +1022,7 @@ public DocumentEntity replaceDocument(long collectionId, long documentId, Obj * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity replaceDocument(String collectionName, long documentId, T value) + public DocumentEntity replaceDocument(final String collectionName, final long documentId, final T value) throws ArangoException { return replaceDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null, null); @@ -1047,7 +1040,7 @@ public DocumentEntity replaceDocument(String collectionName, long documen * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity replaceDocument(long collectionId, String documentKey, T value) + public DocumentEntity replaceDocument(final long collectionId, final String documentKey, final T value) throws ArangoException { return replaceDocument(createDocumentHandle(collectionId, documentKey), value, null, null, null); } @@ -1064,7 +1057,7 @@ public DocumentEntity replaceDocument(long collectionId, String documentK * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity replaceDocument(String collectionName, String documentKey, T value) + public DocumentEntity replaceDocument(final String collectionName, final String documentKey, final T value) throws ArangoException { return replaceDocument(createDocumentHandle(collectionName, documentKey), value, null, null, null); } @@ -1080,7 +1073,7 @@ public DocumentEntity replaceDocument(String collectionName, String docum * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity replaceDocument(String documentHandle, T value) throws ArangoException { + public DocumentEntity replaceDocument(final String documentHandle, final T value) throws ArangoException { return documentDriver.replaceDocument(getDefaultDatabase(), documentHandle, value, null, null, null); } @@ -1108,12 +1101,12 @@ public DocumentEntity replaceDocument(String documentHandle, T value) thr * @throws ArangoException */ public DocumentEntity replaceDocument( - long collectionId, - long documentId, - T value, - Long rev, - Policy policy, - Boolean waitForSync) throws ArangoException { + final long collectionId, + final long documentId, + final T value, + final Long rev, + final Policy policy, + final Boolean waitForSync) throws ArangoException { return replaceDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, rev, policy, waitForSync); } @@ -1142,12 +1135,12 @@ public DocumentEntity replaceDocument( * @throws ArangoException */ public DocumentEntity replaceDocument( - String collectionName, - long documentId, - Object value, - Long rev, - Policy policy, - Boolean waitForSync) throws ArangoException { + final String collectionName, + final long documentId, + final Object value, + final Long rev, + final Policy policy, + final Boolean waitForSync) throws ArangoException { return replaceDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, rev, policy, waitForSync); } @@ -1176,12 +1169,12 @@ public DocumentEntity replaceDocument( * @throws ArangoException */ public DocumentEntity replaceDocument( - long collectionId, - String documentKey, - Object value, - Long rev, - Policy policy, - Boolean waitForSync) throws ArangoException { + final long collectionId, + final String documentKey, + final Object value, + final Long rev, + final Policy policy, + final Boolean waitForSync) throws ArangoException { return replaceDocument(createDocumentHandle(collectionId, documentKey), value, rev, policy, waitForSync); } @@ -1209,12 +1202,12 @@ public DocumentEntity replaceDocument( * @throws ArangoException */ public DocumentEntity replaceDocument( - String collectionName, - String documentKey, - Object value, - Long rev, - Policy policy, - Boolean waitForSync) throws ArangoException { + final String collectionName, + final String documentKey, + final Object value, + final Long rev, + final Policy policy, + final Boolean waitForSync) throws ArangoException { return replaceDocument(createDocumentHandle(collectionName, documentKey), value, rev, policy, waitForSync); } @@ -1240,11 +1233,11 @@ public DocumentEntity replaceDocument( * @throws ArangoException */ public DocumentEntity replaceDocument( - String documentHandle, - T value, - Long rev, - Policy policy, - Boolean waitForSync) throws ArangoException { + final String documentHandle, + final T value, + final Long rev, + final Policy policy, + final Boolean waitForSync) throws ArangoException { return documentDriver.replaceDocument(getDefaultDatabase(), documentHandle, value, rev, policy, waitForSync); } @@ -1260,7 +1253,8 @@ public DocumentEntity replaceDocument( * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(long collectionId, long documentId, Object value) throws ArangoException { + public DocumentEntity updateDocument(final long collectionId, final long documentId, final Object value) + throws ArangoException { return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null, null, null); } @@ -1277,7 +1271,7 @@ public DocumentEntity updateDocument(long collectionId, long documentId, Obje * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(String collectionName, long documentId, Object value) + public DocumentEntity updateDocument(final String collectionName, final long documentId, final Object value) throws ArangoException { return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null, null, null); @@ -1295,7 +1289,7 @@ public DocumentEntity updateDocument(String collectionName, long documentId, * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(long collectionId, String documentKey, Object value) + public DocumentEntity updateDocument(final long collectionId, final String documentKey, final Object value) throws ArangoException { return updateDocument(createDocumentHandle(collectionId, documentKey), value, null, null, null, null); } @@ -1312,7 +1306,7 @@ public DocumentEntity updateDocument(long collectionId, String documentKey, O * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(String collectionName, String documentKey, Object value) + public DocumentEntity updateDocument(final String collectionName, final String documentKey, final Object value) throws ArangoException { return updateDocument(createDocumentHandle(collectionName, documentKey), value, null, null, null, null); } @@ -1327,7 +1321,7 @@ public DocumentEntity updateDocument(String collectionName, String documentKe * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(String documentHandle, T value) throws ArangoException { + public DocumentEntity updateDocument(final String documentHandle, final T value) throws ArangoException { return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, null, null, null, null); } @@ -1345,8 +1339,11 @@ public DocumentEntity updateDocument(String documentHandle, T value) thro * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(long collectionId, long documentId, Object value, Boolean keepNull) - throws ArangoException { + public DocumentEntity updateDocument( + final long collectionId, + final long documentId, + final Object value, + final Boolean keepNull) throws ArangoException { return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null, null, keepNull); } @@ -1365,8 +1362,11 @@ public DocumentEntity updateDocument(long collectionId, long documentId, Obje * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(String collectionName, long documentId, Object value, Boolean keepNull) - throws ArangoException { + public DocumentEntity updateDocument( + final String collectionName, + final long documentId, + final Object value, + final Boolean keepNull) throws ArangoException { return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null, null, keepNull); } @@ -1385,8 +1385,11 @@ public DocumentEntity updateDocument(String collectionName, long documentId, * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(long collectionId, String documentKey, Object value, Boolean keepNull) - throws ArangoException { + public DocumentEntity updateDocument( + final long collectionId, + final String documentKey, + final Object value, + final Boolean keepNull) throws ArangoException { return updateDocument(createDocumentHandle(collectionId, documentKey), value, null, null, null, keepNull); } @@ -1404,8 +1407,11 @@ public DocumentEntity updateDocument(long collectionId, String documentKey, O * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(String collectionName, String documentKey, Object value, Boolean keepNull) - throws ArangoException { + public DocumentEntity updateDocument( + final String collectionName, + final String documentKey, + final Object value, + final Boolean keepNull) throws ArangoException { return updateDocument(createDocumentHandle(collectionName, documentKey), value, null, null, null, keepNull); } @@ -1421,7 +1427,7 @@ public DocumentEntity updateDocument(String collectionName, String documentKe * @return DocumentEntity * @throws ArangoException */ - public DocumentEntity updateDocument(String documentHandle, T value, Boolean keepNull) + public DocumentEntity updateDocument(final String documentHandle, final T value, final Boolean keepNull) throws ArangoException { return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, null, null, null, keepNull); } @@ -1452,13 +1458,13 @@ public DocumentEntity updateDocument(String documentHandle, T value, Bool * @throws ArangoException */ public DocumentEntity updateDocument( - long collectionId, - long documentId, - Object value, - Long rev, - Policy policy, - Boolean waitForSync, - Boolean keepNull) throws ArangoException { + final long collectionId, + final long documentId, + final Object value, + final Long rev, + final Policy policy, + final Boolean waitForSync, + final Boolean keepNull) throws ArangoException { return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, rev, policy, waitForSync, keepNull); } @@ -1489,13 +1495,13 @@ public DocumentEntity updateDocument( * @throws ArangoException */ public DocumentEntity updateDocument( - String collectionName, - long documentId, - Object value, - Long rev, - Policy policy, - Boolean waitForSync, - Boolean keepNull) throws ArangoException { + final String collectionName, + final long documentId, + final Object value, + final Long rev, + final Policy policy, + final Boolean waitForSync, + final Boolean keepNull) throws ArangoException { return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, rev, policy, waitForSync, keepNull); } @@ -1526,13 +1532,13 @@ public DocumentEntity updateDocument( * @throws ArangoException */ public DocumentEntity updateDocument( - long collectionId, - String documentKey, - Object value, - Long rev, - Policy policy, - Boolean waitForSync, - Boolean keepNull) throws ArangoException { + final long collectionId, + final String documentKey, + final Object value, + final Long rev, + final Policy policy, + final Boolean waitForSync, + final Boolean keepNull) throws ArangoException { return updateDocument(createDocumentHandle(collectionId, documentKey), value, rev, policy, waitForSync, keepNull); } @@ -1563,13 +1569,13 @@ public DocumentEntity updateDocument( * @throws ArangoException */ public DocumentEntity updateDocument( - String collectionName, - String documentKey, - Object value, - Long rev, - Policy policy, - Boolean waitForSync, - Boolean keepNull) throws ArangoException { + final String collectionName, + final String documentKey, + final Object value, + final Long rev, + final Policy policy, + final Boolean waitForSync, + final Boolean keepNull) throws ArangoException { return updateDocument(createDocumentHandle(collectionName, documentKey), value, rev, policy, waitForSync, keepNull); } @@ -1598,12 +1604,12 @@ public DocumentEntity updateDocument( * @throws ArangoException */ public DocumentEntity updateDocument( - String documentHandle, - T value, - Long rev, - Policy policy, - Boolean waitForSync, - Boolean keepNull) throws ArangoException { + final String documentHandle, + final T value, + final Long rev, + final Policy policy, + final Boolean waitForSync, + final Boolean keepNull) throws ArangoException { return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, rev, policy, waitForSync, keepNull); } @@ -1616,7 +1622,7 @@ public DocumentEntity updateDocument( * @return List - The list of document handles * @throws ArangoException */ - public List getDocuments(String collectionName) throws ArangoException { + public List getDocuments(final String collectionName) throws ArangoException { return documentDriver.getDocuments(getDefaultDatabase(), collectionName); } @@ -1633,7 +1639,7 @@ public List getDocuments(String collectionName) throws ArangoException { * @return true, if the document exists * @throws ArangoException */ - public boolean exists(long collectionId, long documentId) throws ArangoException { + public boolean exists(final long collectionId, final long documentId) throws ArangoException { return exists(createDocumentHandle(collectionId, String.valueOf(documentId))); } @@ -1650,7 +1656,7 @@ public boolean exists(long collectionId, long documentId) throws ArangoException * @return true, if the document exists * @throws ArangoException */ - public boolean exists(String collectionName, long documentId) throws ArangoException { + public boolean exists(final String collectionName, final long documentId) throws ArangoException { return exists(createDocumentHandle(collectionName, String.valueOf(documentId))); } @@ -1667,7 +1673,7 @@ public boolean exists(String collectionName, long documentId) throws ArangoExcep * @return true, if the document exists * @throws ArangoException */ - public boolean exists(long collectionId, String documentKey) throws ArangoException { + public boolean exists(final long collectionId, final String documentKey) throws ArangoException { return exists(createDocumentHandle(collectionId, documentKey)); } @@ -1684,7 +1690,7 @@ public boolean exists(long collectionId, String documentKey) throws ArangoExcept * @return true, if the document exists * @throws ArangoException */ - public boolean exists(String collectionName, String documentKey) throws ArangoException { + public boolean exists(final String collectionName, final String documentKey) throws ArangoException { return exists(createDocumentHandle(collectionName, documentKey)); } @@ -1699,10 +1705,10 @@ public boolean exists(String collectionName, String documentKey) throws ArangoEx * @return true, if the document exists * @throws ArangoException */ - public boolean exists(String documentHandle) throws ArangoException { + public boolean exists(final String documentHandle) throws ArangoException { try { documentDriver.checkDocument(getDefaultDatabase(), documentHandle); - } catch (ArangoException e) { + } catch (final ArangoException e) { if (e.getCode() == ErrorNums.ERROR_HTTP_NOT_FOUND) { return false; } @@ -1721,7 +1727,7 @@ public boolean exists(String documentHandle) throws ArangoException { * @return the document revision number * @throws ArangoException */ - public long checkDocument(long collectionId, long documentId) throws ArangoException { + public long checkDocument(final long collectionId, final long documentId) throws ArangoException { return checkDocument(createDocumentHandle(collectionId, String.valueOf(documentId))); } @@ -1735,7 +1741,7 @@ public long checkDocument(long collectionId, long documentId) throws ArangoExcep * @return the document revision number * @throws ArangoException */ - public long checkDocument(String collectionName, long documentId) throws ArangoException { + public long checkDocument(final String collectionName, final long documentId) throws ArangoException { return checkDocument(createDocumentHandle(collectionName, String.valueOf(documentId))); } @@ -1749,7 +1755,7 @@ public long checkDocument(String collectionName, long documentId) throws ArangoE * @return the document revision number * @throws ArangoException */ - public long checkDocument(long collectionId, String documentKey) throws ArangoException { + public long checkDocument(final long collectionId, final String documentKey) throws ArangoException { return checkDocument(createDocumentHandle(collectionId, documentKey)); } @@ -1763,7 +1769,7 @@ public long checkDocument(long collectionId, String documentKey) throws ArangoEx * @return the document revision number * @throws ArangoException */ - public long checkDocument(String collectionName, String documentKey) throws ArangoException { + public long checkDocument(final String collectionName, final String documentKey) throws ArangoException { return checkDocument(createDocumentHandle(collectionName, documentKey)); } @@ -1775,7 +1781,7 @@ public long checkDocument(String collectionName, String documentKey) throws Aran * @return the document revision number * @throws ArangoException */ - public long checkDocument(String documentHandle) throws ArangoException { + public long checkDocument(final String documentHandle) throws ArangoException { return documentDriver.checkDocument(getDefaultDatabase(), documentHandle); } @@ -1792,7 +1798,7 @@ public long checkDocument(String documentHandle) throws ArangoException { * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity getDocument(long collectionId, long documentId, Class clazz) + public DocumentEntity getDocument(final long collectionId, final long documentId, final Class clazz) throws ArangoException { return getDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), clazz); } @@ -1810,7 +1816,7 @@ public DocumentEntity getDocument(long collectionId, long documentId, Cla * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity getDocument(String collectionName, long documentId, Class clazz) + public DocumentEntity getDocument(final String collectionName, final long documentId, final Class clazz) throws ArangoException { return getDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), clazz); } @@ -1828,7 +1834,7 @@ public DocumentEntity getDocument(String collectionName, long documentId, * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity getDocument(long collectionId, String documentKey, Class clazz) + public DocumentEntity getDocument(final long collectionId, final String documentKey, final Class clazz) throws ArangoException { return getDocument(createDocumentHandle(collectionId, documentKey), clazz); } @@ -1846,8 +1852,10 @@ public DocumentEntity getDocument(long collectionId, String documentKey, * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity getDocument(String collectionName, String documentKey, Class clazz) - throws ArangoException { + public DocumentEntity getDocument( + final String collectionName, + final String documentKey, + final Class clazz) throws ArangoException { return getDocument(createDocumentHandle(collectionName, documentKey), clazz); } @@ -1862,7 +1870,7 @@ public DocumentEntity getDocument(String collectionName, String documentK * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity getDocument(String documentHandle, Class clazz) throws ArangoException { + public DocumentEntity getDocument(final String documentHandle, final Class clazz) throws ArangoException { return documentDriver.getDocument(getDefaultDatabase(), documentHandle, clazz, null, null); } @@ -1886,10 +1894,10 @@ public DocumentEntity getDocument(String documentHandle, Class clazz) * @throws ArangoException */ public DocumentEntity getDocument( - String documentHandle, - Class clazz, - Long ifNoneMatchRevision, - Long ifMatchRevision) throws ArangoException { + final String documentHandle, + final Class clazz, + final Long ifNoneMatchRevision, + final Long ifMatchRevision) throws ArangoException { return documentDriver.getDocument(getDefaultDatabase(), documentHandle, clazz, ifNoneMatchRevision, ifMatchRevision); } @@ -1904,7 +1912,7 @@ public DocumentEntity getDocument( * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(long collectionId, long documentId) throws ArangoException { + public DocumentEntity deleteDocument(final long collectionId, final long documentId) throws ArangoException { return deleteDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), null, null); } @@ -1918,7 +1926,7 @@ public DocumentEntity deleteDocument(long collectionId, long documentId) thro * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(String collectionName, long documentId) throws ArangoException { + public DocumentEntity deleteDocument(final String collectionName, final long documentId) throws ArangoException { return deleteDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), null, null); } @@ -1932,7 +1940,7 @@ public DocumentEntity deleteDocument(String collectionName, long documentId) * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(long collectionId, String documentKey) throws ArangoException { + public DocumentEntity deleteDocument(final long collectionId, final String documentKey) throws ArangoException { return deleteDocument(createDocumentHandle(collectionId, documentKey), null, null); } @@ -1946,7 +1954,8 @@ public DocumentEntity deleteDocument(long collectionId, String documentKey) t * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(String collectionName, String documentKey) throws ArangoException { + public DocumentEntity deleteDocument(final String collectionName, final String documentKey) + throws ArangoException { return deleteDocument(createDocumentHandle(collectionName, documentKey), null, null); } @@ -1958,7 +1967,7 @@ public DocumentEntity deleteDocument(String collectionName, String documentKe * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(String documentHandle) throws ArangoException { + public DocumentEntity deleteDocument(final String documentHandle) throws ArangoException { return documentDriver.deleteDocument(getDefaultDatabase(), documentHandle, null, null); } @@ -1980,8 +1989,11 @@ public DocumentEntity deleteDocument(String documentHandle) throws ArangoExce * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(long collectionId, long documentId, Long rev, Policy policy) - throws ArangoException { + public DocumentEntity deleteDocument( + final long collectionId, + final long documentId, + final Long rev, + final Policy policy) throws ArangoException { return deleteDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), rev, policy); } @@ -2003,8 +2015,11 @@ public DocumentEntity deleteDocument(long collectionId, long documentId, Long * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(String collectionName, long documentId, Long rev, Policy policy) - throws ArangoException { + public DocumentEntity deleteDocument( + final String collectionName, + final long documentId, + final Long rev, + final Policy policy) throws ArangoException { return deleteDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), rev, policy); } @@ -2026,8 +2041,11 @@ public DocumentEntity deleteDocument(String collectionName, long documentId, * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(long collectionId, String documentKey, Long rev, Policy policy) - throws ArangoException { + public DocumentEntity deleteDocument( + final long collectionId, + final String documentKey, + final Long rev, + final Policy policy) throws ArangoException { return deleteDocument(createDocumentHandle(collectionId, documentKey), rev, policy); } @@ -2049,8 +2067,11 @@ public DocumentEntity deleteDocument(long collectionId, String documentKey, L * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(String collectionName, String documentKey, Long rev, Policy policy) - throws ArangoException { + public DocumentEntity deleteDocument( + final String collectionName, + final String documentKey, + final Long rev, + final Policy policy) throws ArangoException { return deleteDocument(createDocumentHandle(collectionName, documentKey), rev, policy); } @@ -2070,7 +2091,8 @@ public DocumentEntity deleteDocument(String collectionName, String documentKe * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(String documentHandle, Long rev, Policy policy) throws ArangoException { + public DocumentEntity deleteDocument(final String documentHandle, final Long rev, final Policy policy) + throws ArangoException { return documentDriver.deleteDocument(getDefaultDatabase(), documentHandle, rev, policy); } @@ -2082,7 +2104,7 @@ public DocumentEntity deleteDocument(String documentHandle, Long rev, Policy * @return a CursorEntity object * @throws ArangoException */ - public CursorEntity validateQuery(String query) throws ArangoException { + public CursorEntity validateQuery(final String query) throws ArangoException { return cursorDriver.validateQuery(getDefaultDatabase(), query); } @@ -2111,12 +2133,12 @@ public CursorEntity validateQuery(String query) throws ArangoException { */ @Deprecated public CursorEntity executeQuery( - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize, - Boolean fullCount) throws ArangoException { + final String query, + final Map bindVars, + final Class clazz, + final Boolean calcCount, + final Integer batchSize, + final Boolean fullCount) throws ArangoException { return cursorDriver.executeQuery(getDefaultDatabase(), query, bindVars, clazz, calcCount, batchSize, fullCount); } @@ -2143,11 +2165,11 @@ public CursorEntity executeQuery( */ @Deprecated public CursorEntity executeQuery( - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize) throws ArangoException { + final String query, + final Map bindVars, + final Class clazz, + final Boolean calcCount, + final Integer batchSize) throws ArangoException { return cursorDriver.executeQuery(getDefaultDatabase(), query, bindVars, clazz, calcCount, batchSize, false); } @@ -2163,7 +2185,7 @@ public CursorEntity executeQuery( * @return a CursorEntity object * @throws ArangoException */ - public CursorEntity continueQuery(long cursorId, Class... clazz) throws ArangoException { + public CursorEntity continueQuery(final long cursorId, final Class... clazz) throws ArangoException { return cursorDriver.continueQuery(getDefaultDatabase(), cursorId, clazz); } @@ -2175,7 +2197,7 @@ public CursorEntity continueQuery(long cursorId, Class... clazz) throw * @return a DefaultEntity object * @throws ArangoException */ - public DefaultEntity finishQuery(long cursorId) throws ArangoException { + public DefaultEntity finishQuery(final long cursorId) throws ArangoException { return cursorDriver.finishQuery(getDefaultDatabase(), cursorId); } @@ -2205,12 +2227,12 @@ public DefaultEntity finishQuery(long cursorId) throws ArangoException { */ @Deprecated public CursorResultSet executeQueryWithResultSet( - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize, - Boolean fullCount) throws ArangoException { + final String query, + final Map bindVars, + final Class clazz, + final Boolean calcCount, + final Integer batchSize, + final Boolean fullCount) throws ArangoException { return cursorDriver.executeQueryWithResultSet(getDefaultDatabase(), query, bindVars, clazz, calcCount, batchSize, fullCount); @@ -2238,11 +2260,11 @@ public CursorResultSet executeQueryWithResultSet( */ @Deprecated public CursorResultSet executeQueryWithResultSet( - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize) throws ArangoException { + final String query, + final Map bindVars, + final Class clazz, + final Boolean calcCount, + final Integer batchSize) throws ArangoException { return cursorDriver.executeQueryWithResultSet(getDefaultDatabase(), query, bindVars, clazz, calcCount, batchSize, false); @@ -2270,14 +2292,14 @@ public CursorResultSet executeQueryWithResultSet( * @throws ArangoException */ public CursorEntity executeCursorEntityQuery( - String query, - Map bindVars, - Boolean calcCount, - Integer batchSize, - Boolean fullCount, - Class... clazz) throws ArangoException { - - AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(calcCount).setBatchSize(batchSize) + final String query, + final Map bindVars, + final Boolean calcCount, + final Integer batchSize, + final Boolean fullCount, + final Class... clazz) throws ArangoException { + + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(calcCount).setBatchSize(batchSize) .setFullCount(fullCount); return cursorDriver.executeCursorEntityQuery(getDefaultDatabase(), query, bindVars, aqlQueryOptions, clazz); @@ -2308,13 +2330,13 @@ public AqlQueryOptions getDefaultAqlQueryOptions() { * @throws ArangoException */ public DocumentCursor executeDocumentQuery( - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions, - Class clazz) throws ArangoException { + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions, + final Class clazz) throws ArangoException { @SuppressWarnings("unchecked") - DocumentCursorResult> baseCursor = cursorDriver.executeBaseCursorQuery( + final DocumentCursorResult> baseCursor = cursorDriver.executeBaseCursorQuery( getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions), DocumentEntity.class, clazz); return new DocumentCursor(baseCursor); } @@ -2335,10 +2357,10 @@ public DocumentCursor executeDocumentQuery( * @throws ArangoException */ public CursorResult executeAqlQuery( - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions, - Class clazz) throws ArangoException { + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions, + final Class clazz) throws ArangoException { return cursorDriver.executeAqlQuery(getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions), clazz); @@ -2356,8 +2378,10 @@ public CursorResult executeAqlQuery( * @return A JSON string with the results from server * @throws ArangoException */ - public String executeAqlQueryJSON(String query, Map bindVars, AqlQueryOptions aqlQueryOptions) - throws ArangoException { + public String executeAqlQueryJSON( + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions) throws ArangoException { return cursorDriver.executeAqlQueryJSON(getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions)); @@ -2382,11 +2406,11 @@ public String executeAqlQueryJSON(String query, Map bindVars, Aq * @throws ArangoException */ public > DocumentCursorResult executeAqlQueryWithDocumentCursorResult( - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions, - Class classDocumentEntity, - Class clazz) throws ArangoException { + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions, + final Class classDocumentEntity, + final Class clazz) throws ArangoException { return cursorDriver.executeBaseCursorQuery(getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions), classDocumentEntity, clazz); @@ -2406,8 +2430,11 @@ public > DocumentCursorResult executeAqlQue * @return IndexEntity * @throws ArangoException */ - public IndexEntity createIndex(long collectionId, IndexType type, boolean unique, String... fields) - throws ArangoException { + public IndexEntity createIndex( + final long collectionId, + final IndexType type, + final boolean unique, + final String... fields) throws ArangoException { return createIndex(String.valueOf(collectionId), type, unique, fields); } @@ -2427,8 +2454,12 @@ public IndexEntity createIndex(long collectionId, IndexType type, boolean unique * @return IndexEntity * @throws ArangoException */ - public IndexEntity createIndex(long collectionId, IndexType type, boolean unique, boolean sparse, String... fields) - throws ArangoException { + public IndexEntity createIndex( + final long collectionId, + final IndexType type, + final boolean unique, + final boolean sparse, + final String... fields) throws ArangoException { return createIndex(String.valueOf(collectionId), type, unique, sparse, fields); } @@ -2446,8 +2477,11 @@ public IndexEntity createIndex(long collectionId, IndexType type, boolean unique * @return IndexEntity * @throws ArangoException */ - public IndexEntity createIndex(String collectionName, IndexType type, boolean unique, String... fields) - throws ArangoException { + public IndexEntity createIndex( + final String collectionName, + final IndexType type, + final boolean unique, + final String... fields) throws ArangoException { return indexDriver.createIndex(getDefaultDatabase(), collectionName, type, unique, fields); } @@ -2468,11 +2502,11 @@ public IndexEntity createIndex(String collectionName, IndexType type, boolean un * @throws ArangoException */ public IndexEntity createIndex( - String collectionName, - IndexType type, - boolean unique, - boolean sparse, - String... fields) throws ArangoException { + final String collectionName, + final IndexType type, + final boolean unique, + final boolean sparse, + final String... fields) throws ArangoException { return indexDriver.createIndex(getDefaultDatabase(), collectionName, type, unique, sparse, fields); } @@ -2488,7 +2522,8 @@ public IndexEntity createIndex( * @return IndexEntity * @throws ArangoException */ - public IndexEntity createHashIndex(String collectionName, boolean unique, String... fields) throws ArangoException { + public IndexEntity createHashIndex(final String collectionName, final boolean unique, final String... fields) + throws ArangoException { return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.HASH, unique, fields); } @@ -2506,8 +2541,11 @@ public IndexEntity createHashIndex(String collectionName, boolean unique, String * @return IndexEntity * @throws ArangoException */ - public IndexEntity createHashIndex(String collectionName, boolean unique, boolean sparse, String... fields) - throws ArangoException { + public IndexEntity createHashIndex( + final String collectionName, + final boolean unique, + final boolean sparse, + final String... fields) throws ArangoException { return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.HASH, unique, sparse, fields); } @@ -2523,7 +2561,8 @@ public IndexEntity createHashIndex(String collectionName, boolean unique, boolea * @return IndexEntity * @throws ArangoException */ - public IndexEntity createGeoIndex(String collectionName, boolean unique, String... fields) throws ArangoException { + public IndexEntity createGeoIndex(final String collectionName, final boolean unique, final String... fields) + throws ArangoException { return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.GEO, unique, fields); } @@ -2539,7 +2578,7 @@ public IndexEntity createGeoIndex(String collectionName, boolean unique, String. * @return IndexEntity * @throws ArangoException */ - public IndexEntity createSkipListIndex(String collectionName, boolean unique, String... fields) + public IndexEntity createSkipListIndex(final String collectionName, final boolean unique, final String... fields) throws ArangoException { return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.SKIPLIST, unique, fields); } @@ -2558,8 +2597,11 @@ public IndexEntity createSkipListIndex(String collectionName, boolean unique, St * @return IndexEntity * @throws ArangoException */ - public IndexEntity createSkipListIndex(String collectionName, boolean unique, boolean sparse, String... fields) - throws ArangoException { + public IndexEntity createSkipListIndex( + final String collectionName, + final boolean unique, + final boolean sparse, + final String... fields) throws ArangoException { return indexDriver.createIndex(getDefaultDatabase(), collectionName, IndexType.SKIPLIST, unique, sparse, fields); } @@ -2574,7 +2616,7 @@ public IndexEntity createSkipListIndex(String collectionName, boolean unique, bo * @return IndexEntity * @throws ArangoException */ - public IndexEntity createFulltextIndex(long collectionId, String... fields) throws ArangoException { + public IndexEntity createFulltextIndex(final long collectionId, final String... fields) throws ArangoException { return createFulltextIndex(String.valueOf(collectionId), null, fields); } @@ -2588,7 +2630,7 @@ public IndexEntity createFulltextIndex(long collectionId, String... fields) thro * @return IndexEntity * @throws ArangoException */ - public IndexEntity createFulltextIndex(String collectionName, String... fields) throws ArangoException { + public IndexEntity createFulltextIndex(final String collectionName, final String... fields) throws ArangoException { return createFulltextIndex(collectionName, null, fields); } @@ -2604,7 +2646,7 @@ public IndexEntity createFulltextIndex(String collectionName, String... fields) * @return IndexEntity * @throws ArangoException */ - public IndexEntity createFulltextIndex(long collectionId, Integer minLength, String... fields) + public IndexEntity createFulltextIndex(final long collectionId, final Integer minLength, final String... fields) throws ArangoException { return createFulltextIndex(String.valueOf(collectionId), minLength, fields); } @@ -2621,7 +2663,7 @@ public IndexEntity createFulltextIndex(long collectionId, Integer minLength, Str * @return IndexEntity * @throws ArangoException */ - public IndexEntity createFulltextIndex(String collectionName, Integer minLength, String... fields) + public IndexEntity createFulltextIndex(final String collectionName, final Integer minLength, final String... fields) throws ArangoException { return indexDriver.createFulltextIndex(getDefaultDatabase(), collectionName, minLength, fields); } @@ -2634,7 +2676,7 @@ public IndexEntity createFulltextIndex(String collectionName, Integer minLength, * @return IndexEntity * @throws ArangoException */ - public IndexEntity deleteIndex(String indexHandle) throws ArangoException { + public IndexEntity deleteIndex(final String indexHandle) throws ArangoException { return indexDriver.deleteIndex(getDefaultDatabase(), indexHandle); } @@ -2646,7 +2688,7 @@ public IndexEntity deleteIndex(String indexHandle) throws ArangoException { * @return IndexEntity * @throws ArangoException */ - public IndexEntity getIndex(String indexHandle) throws ArangoException { + public IndexEntity getIndex(final String indexHandle) throws ArangoException { return indexDriver.getIndex(getDefaultDatabase(), indexHandle); } @@ -2658,7 +2700,7 @@ public IndexEntity getIndex(String indexHandle) throws ArangoException { * @return IndexesEntity * @throws ArangoException */ - public IndexesEntity getIndexes(long collectionId) throws ArangoException { + public IndexesEntity getIndexes(final long collectionId) throws ArangoException { return getIndexes(String.valueOf(collectionId)); } @@ -2670,7 +2712,7 @@ public IndexesEntity getIndexes(long collectionId) throws ArangoException { * @return IndexesEntity * @throws ArangoException */ - public IndexesEntity getIndexes(String collectionName) throws ArangoException { + public IndexesEntity getIndexes(final String collectionName) throws ArangoException { return indexDriver.getIndexes(getDefaultDatabase(), collectionName); } @@ -2701,13 +2743,13 @@ public IndexesEntity getIndexes(String collectionName) throws ArangoException { * @throws ArangoException */ public AdminLogEntity getServerLog( - Integer logLevel, - Boolean logLevelUpTo, - Integer start, - Integer size, - Integer offset, - Boolean sortAsc, - String text) throws ArangoException { + final Integer logLevel, + final Boolean logLevelUpTo, + final Integer start, + final Integer size, + final Integer offset, + final Boolean sortAsc, + final String text) throws ArangoException { return adminDriver.getServerLog(logLevel, logLevelUpTo, start, size, offset, sortAsc, text); } @@ -2769,7 +2811,7 @@ public DefaultEntity reloadRouting() throws ArangoException { * @return DefaultEntity * @throws ArangoException */ - public DefaultEntity executeScript(String jsCode) throws ArangoException { + public DefaultEntity executeScript(final String jsCode) throws ArangoException { return adminDriver.executeScript(getDefaultDatabase(), jsCode); } @@ -2796,11 +2838,11 @@ public DefaultEntity executeScript(String jsCode) throws ArangoException { */ @Deprecated public CursorEntity executeSimpleByExample( - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final Map example, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleByExample(getDefaultDatabase(), collectionName, example, skip, limit, clazz); } @@ -2826,11 +2868,11 @@ public CursorEntity executeSimpleByExample( */ @Deprecated public CursorResultSet executeSimpleByExampleWithResusltSet( - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final Map example, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleByExampleWithResultSet(getDefaultDatabase(), collectionName, example, skip, limit, clazz); } @@ -2857,11 +2899,11 @@ public CursorResultSet executeSimpleByExampleWithResusltSet( */ @Deprecated public CursorEntity> executeSimpleByExampleWithDocument( - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final Map example, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleByExampleWithDocument(getDefaultDatabase(), collectionName, example, skip, limit, clazz); } @@ -2888,11 +2930,11 @@ public CursorEntity> executeSimpleByExampleWithDocument( */ @Deprecated public CursorResultSet> executeSimpleByExampleWithDocumentResusltSet( - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final Map example, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleByExampleWithDocumentResultSet(getDefaultDatabase(), collectionName, example, skip, limit, clazz); } @@ -2916,11 +2958,11 @@ public CursorResultSet> executeSimpleByExampleWithDocument * @throws ArangoException */ public DocumentCursor executeSimpleByExampleDocuments( - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final Map example, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleByExampleDocuments(getDefaultDatabase(), collectionName, example, skip, limit, clazz); } @@ -2944,8 +2986,11 @@ public DocumentCursor executeSimpleByExampleDocuments( * {@link #executeSimpleAllDocuments(String, int, int, Class)} */ @Deprecated - public CursorEntity executeSimpleAll(String collectionName, int skip, int limit, Class clazz) - throws ArangoException { + public CursorEntity executeSimpleAll( + final String collectionName, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleAll(getDefaultDatabase(), collectionName, skip, limit, clazz); } @@ -2969,10 +3014,10 @@ public CursorEntity executeSimpleAll(String collectionName, int skip, int */ @Deprecated public CursorResultSet executeSimpleAllWithResultSet( - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleAllWithResultSet(getDefaultDatabase(), collectionName, skip, limit, clazz); } @@ -2996,10 +3041,10 @@ public CursorResultSet executeSimpleAllWithResultSet( */ @Deprecated public CursorEntity> executeSimpleAllWithDocument( - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleAllWithDocument(getDefaultDatabase(), collectionName, skip, limit, clazz); } @@ -3023,10 +3068,10 @@ public CursorEntity> executeSimpleAllWithDocument( */ @Deprecated public CursorResultSet> executeSimpleAllWithDocumentResultSet( - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleAllWithDocumentResultSet(getDefaultDatabase(), collectionName, skip, limit, clazz); } @@ -3047,8 +3092,11 @@ public CursorResultSet> executeSimpleAllWithDocumentResult * @return DocumentCursor * @throws ArangoException */ - public DocumentCursor executeSimpleAllDocuments(String collectionName, int skip, int limit, Class clazz) - throws ArangoException { + public DocumentCursor executeSimpleAllDocuments( + final String collectionName, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleAllDocuments(getDefaultDatabase(), collectionName, skip, limit, clazz); } @@ -3066,9 +3114,9 @@ public DocumentCursor executeSimpleAllDocuments(String collectionName, in * @throws ArangoException */ public ScalarExampleEntity executeSimpleFirstExample( - String collectionName, - Map example, - Class clazz) throws ArangoException { + final String collectionName, + final Map example, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleFirstExample(getDefaultDatabase(), collectionName, example, clazz); } @@ -3083,7 +3131,8 @@ public ScalarExampleEntity executeSimpleFirstExample( * @return a ScalarExampleEntity object * @throws ArangoException */ - public ScalarExampleEntity executeSimpleAny(String collectionName, Class clazz) throws ArangoException { + public ScalarExampleEntity executeSimpleAny(final String collectionName, final Class clazz) + throws ArangoException { return simpleDriver.executeSimpleAny(getDefaultDatabase(), collectionName, clazz); } @@ -3114,14 +3163,14 @@ public ScalarExampleEntity executeSimpleAny(String collectionName, Class< * @throws ArangoException */ public DocumentCursor executeSimpleRangeWithDocuments( - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final Object left, + final Object right, + final Boolean closed, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleRangeWithDocuments(getDefaultDatabase(), collectionName, attribute, left, right, closed, skip, limit, clazz); } @@ -3156,14 +3205,14 @@ public DocumentCursor executeSimpleRangeWithDocuments( */ @Deprecated public CursorResultSet executeSimpleRangeWithResultSet( - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final Object left, + final Object right, + final Boolean closed, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleRangeWithResultSet(getDefaultDatabase(), collectionName, attribute, left, right, closed, skip, limit, clazz); } @@ -3198,14 +3247,14 @@ public CursorResultSet executeSimpleRangeWithResultSet( */ @Deprecated public CursorEntity> executeSimpleRangeWithDocument( - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final Object left, + final Object right, + final Boolean closed, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleRangeWithDocument(getDefaultDatabase(), collectionName, attribute, left, right, closed, skip, limit, clazz); } @@ -3240,14 +3289,14 @@ public CursorEntity> executeSimpleRangeWithDocument( */ @Deprecated public CursorResultSet> executeSimpleRangeWithDocumentResultSet( - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final Object left, + final Object right, + final Boolean closed, + final int skip, + final int limit, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleRangeWithDocumentResultSet(getDefaultDatabase(), collectionName, attribute, left, right, closed, skip, limit, clazz); } @@ -3279,13 +3328,13 @@ public CursorResultSet> executeSimpleRangeWithDocumentResu */ @Deprecated public CursorEntity executeSimpleFulltext( - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final String query, + final int skip, + final int limit, + final String index, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleFulltext(getDefaultDatabase(), collectionName, attribute, query, skip, limit, index, clazz); } @@ -3314,13 +3363,13 @@ public CursorEntity executeSimpleFulltext( * @throws ArangoException */ public DocumentCursor executeSimpleFulltextWithDocuments( - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final String query, + final int skip, + final int limit, + final String index, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleFulltextWithDocuments(getDefaultDatabase(), collectionName, attribute, query, skip, limit, index, clazz); } @@ -3352,13 +3401,13 @@ public DocumentCursor executeSimpleFulltextWithDocuments( */ @Deprecated public CursorResultSet executeSimpleFulltextWithResultSet( - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final String query, + final int skip, + final int limit, + final String index, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleFulltextWithResultSet(getDefaultDatabase(), collectionName, attribute, query, skip, limit, index, clazz); } @@ -3390,13 +3439,13 @@ public CursorResultSet executeSimpleFulltextWithResultSet( */ @Deprecated public CursorEntity> executeSimpleFulltextWithDocument( - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final String query, + final int skip, + final int limit, + final String index, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleFulltextWithDocument(getDefaultDatabase(), collectionName, attribute, query, skip, limit, index, clazz); } @@ -3428,13 +3477,13 @@ public CursorEntity> executeSimpleFulltextWithDocument( */ @Deprecated public CursorResultSet> executeSimpleFulltextWithDocumentResultSet( - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { + final String collectionName, + final String attribute, + final String query, + final int skip, + final int limit, + final String index, + final Class clazz) throws ArangoException { return simpleDriver.executeSimpleFulltextWithDocumentResultSet(getDefaultDatabase(), collectionName, attribute, query, skip, limit, index, clazz); } @@ -3456,10 +3505,10 @@ public CursorResultSet> executeSimpleFulltextWithDocumentR * @throws ArangoException */ public SimpleByResultEntity executeSimpleRemoveByExample( - String collectionName, - Map example, - Boolean waitForSync, - Integer limit) throws ArangoException { + final String collectionName, + final Map example, + final Boolean waitForSync, + final Integer limit) throws ArangoException { return simpleDriver.executeSimpleRemoveByExample(getDefaultDatabase(), collectionName, example, waitForSync, limit); } @@ -3483,11 +3532,11 @@ public SimpleByResultEntity executeSimpleRemoveByExample( * @throws ArangoException */ public SimpleByResultEntity executeSimpleReplaceByExample( - String collectionName, - Map example, - Map newValue, - Boolean waitForSync, - Integer limit) throws ArangoException { + final String collectionName, + final Map example, + final Map newValue, + final Boolean waitForSync, + final Integer limit) throws ArangoException { return simpleDriver.executeSimpleReplaceByExample(getDefaultDatabase(), collectionName, example, newValue, waitForSync, limit); } @@ -3513,12 +3562,12 @@ public SimpleByResultEntity executeSimpleReplaceByExample( * @throws ArangoException */ public SimpleByResultEntity executeSimpleUpdateByExample( - String collectionName, - Map example, - Map newValue, - Boolean keepNull, - Boolean waitForSync, - Integer limit) throws ArangoException { + final String collectionName, + final Map example, + final Map newValue, + final Boolean keepNull, + final Boolean waitForSync, + final Integer limit) throws ArangoException { return simpleDriver.executeSimpleUpdateByExample(getDefaultDatabase(), collectionName, example, newValue, keepNull, waitForSync, limit); } @@ -3537,8 +3586,11 @@ public SimpleByResultEntity executeSimpleUpdateByExample( * @return DefaultEntity * @throws ArangoException */ - public DefaultEntity createUser(String username, String passwd, Boolean active, Map extra) - throws ArangoException { + public DefaultEntity createUser( + final String username, + final String passwd, + final Boolean active, + final Map extra) throws ArangoException { return usersDriver.createUser(getDefaultDatabase(), username, passwd, active, extra); } @@ -3556,8 +3608,11 @@ public DefaultEntity createUser(String username, String passwd, Boolean active, * @return DefaultEntity * @throws ArangoException */ - public DefaultEntity replaceUser(String username, String passwd, Boolean active, Map extra) - throws ArangoException { + public DefaultEntity replaceUser( + final String username, + final String passwd, + final Boolean active, + final Map extra) throws ArangoException { return usersDriver.replaceUser(getDefaultDatabase(), username, passwd, active, extra); } @@ -3575,8 +3630,11 @@ public DefaultEntity replaceUser(String username, String passwd, Boolean active, * @return DefaultEntity * @throws ArangoException */ - public DefaultEntity updateUser(String username, String passwd, Boolean active, Map extra) - throws ArangoException { + public DefaultEntity updateUser( + final String username, + final String passwd, + final Boolean active, + final Map extra) throws ArangoException { return usersDriver.updateUser(getDefaultDatabase(), username, passwd, active, extra); } @@ -3588,7 +3646,7 @@ public DefaultEntity updateUser(String username, String passwd, Boolean active, * @return DefaultEntity * @throws ArangoException */ - public DefaultEntity deleteUser(String username) throws ArangoException { + public DefaultEntity deleteUser(final String username) throws ArangoException { return usersDriver.deleteUser(getDefaultDatabase(), username); } @@ -3600,7 +3658,7 @@ public DefaultEntity deleteUser(String username) throws ArangoException { * @return UserEntity * @throws ArangoException */ - public UserEntity getUser(String username) throws ArangoException { + public UserEntity getUser(final String username) throws ArangoException { return usersDriver.getUser(getDefaultDatabase(), username); } @@ -3611,7 +3669,7 @@ public UserEntity getUser(String username) throws ArangoException { * @throws ArangoException */ public List> getUsersDocument() throws ArangoException { - DocumentCursor documentCursor = executeSimpleAllDocuments("_users", 0, 0, UserEntity.class); + final DocumentCursor documentCursor = executeSimpleAllDocuments("_users", 0, 0, UserEntity.class); return documentCursor.asList(); } @@ -3622,7 +3680,7 @@ public List> getUsersDocument() throws ArangoExceptio * @throws ArangoException */ public List getUsers() throws ArangoException { - DocumentCursor documentCursor = executeSimpleAllDocuments("_users", 0, 0, UserEntity.class); + final DocumentCursor documentCursor = executeSimpleAllDocuments("_users", 0, 0, UserEntity.class); return documentCursor.asEntityList(); } @@ -3636,7 +3694,8 @@ public List getUsers() throws ArangoException { * @return ImportResultEntity * @throws ArangoException */ - public ImportResultEntity importDocuments(String collection, Collection values) throws ArangoException { + public ImportResultEntity importDocuments(final String collection, final Collection values) + throws ArangoException { return importDriver.importDocuments(getDefaultDatabase(), collection, values); } @@ -3651,8 +3710,8 @@ public ImportResultEntity importDocuments(String collection, Collection value * @throws ArangoException */ public ImportResultEntity importDocumentsByHeaderValues( - String collection, - Collection> headerValues) throws ArangoException { + final String collection, + final Collection> headerValues) throws ArangoException { return importDriver.importDocumentsByHeaderValues(getDefaultDatabase(), collection, headerValues); } @@ -3685,7 +3744,7 @@ public StringsResultEntity getDatabases() throws ArangoException { * @return StringsResultEntity * @throws ArangoException */ - public StringsResultEntity getDatabases(boolean currentUserAccessableOnly) throws ArangoException { + public StringsResultEntity getDatabases(final boolean currentUserAccessableOnly) throws ArangoException { return databaseDriver.getDatabases(currentUserAccessableOnly, null, null); } @@ -3699,7 +3758,7 @@ public StringsResultEntity getDatabases(boolean currentUserAccessableOnly) throw * @return StringsResultEntity * @throws ArangoException */ - public StringsResultEntity getDatabases(String username, String password) throws ArangoException { + public StringsResultEntity getDatabases(final String username, final String password) throws ArangoException { return databaseDriver.getDatabases(true, username, password); } @@ -3714,7 +3773,7 @@ public StringsResultEntity getDatabases(String username, String password) throws * @return BooleanResultEntity * @throws ArangoException */ - public BooleanResultEntity createDatabase(String database, UserEntity... users) throws ArangoException { + public BooleanResultEntity createDatabase(final String database, final UserEntity... users) throws ArangoException { return databaseDriver.createDatabase(database, users); } @@ -3726,7 +3785,7 @@ public BooleanResultEntity createDatabase(String database, UserEntity... users) * @return BooleanResultEntity * @throws ArangoException */ - public BooleanResultEntity deleteDatabase(String database) throws ArangoException { + public BooleanResultEntity deleteDatabase(final String database) throws ArangoException { return databaseDriver.deleteDatabase(database); } @@ -3739,7 +3798,7 @@ public BooleanResultEntity deleteDatabase(String database) throws ArangoExceptio * a list of databases that are allowed on this endpoint * @return BooleanResultEntity */ - public BooleanResultEntity createEndpoint(String endpoint, String... databases) throws ArangoException { + public BooleanResultEntity createEndpoint(final String endpoint, final String... databases) throws ArangoException { return endpointDriver.createEndpoint(endpoint, databases); } @@ -3759,7 +3818,7 @@ public List getEndpoints() throws ArangoException { * the endpoint as string * @return BooleanResultEntity */ - public BooleanResultEntity deleteEndpoint(String endpoint) throws ArangoException { + public BooleanResultEntity deleteEndpoint(final String endpoint) throws ArangoException { return endpointDriver.deleteEndpoint(endpoint); } @@ -3785,7 +3844,7 @@ public ReplicationInventoryEntity getReplicationInventory() throws ArangoExcepti * @return ReplicationInventoryEntity * @throws ArangoException */ - public ReplicationInventoryEntity getReplicationInventory(boolean includeSystem) throws ArangoException { + public ReplicationInventoryEntity getReplicationInventory(final boolean includeSystem) throws ArangoException { return replicationDriver.getReplicationInventory(getDefaultDatabase(), includeSystem); } @@ -3811,13 +3870,13 @@ public ReplicationInventoryEntity getReplicationInventory(boolean includeSystem) * @throws ArangoException */ public void getReplicationDump( - String collectionName, - Long from, - Long to, - Integer chunkSize, - Boolean ticks, - Class clazz, - DumpHandler handler) throws ArangoException { + final String collectionName, + final Long from, + final Long to, + final Integer chunkSize, + final Boolean ticks, + final Class clazz, + final DumpHandler handler) throws ArangoException { replicationDriver.getReplicationDump(getDefaultDatabase(), collectionName, from, to, chunkSize, ticks, clazz, handler); @@ -3847,12 +3906,12 @@ public void getReplicationDump( * @throws ArangoException */ public ReplicationSyncEntity syncReplication( - String endpoint, - String database, - String username, - String password, - RestrictType restrictType, - String... restrictCollections) throws ArangoException { + final String endpoint, + final String database, + final String username, + final String password, + final RestrictType restrictType, + final String... restrictCollections) throws ArangoException { return replicationDriver.syncReplication(getDefaultDatabase(), endpoint, database, username, password, restrictType, restrictCollections); } @@ -3926,10 +3985,10 @@ public ReplicationLoggerConfigEntity getReplicationLoggerConfig() throws ArangoE * @throws ArangoException */ public ReplicationLoggerConfigEntity setReplicationLoggerConfig( - Boolean autoStart, - Boolean logRemoteChanges, - Long maxEvents, - Long maxEventsSize) throws ArangoException { + final Boolean autoStart, + final Boolean logRemoteChanges, + final Long maxEvents, + final Long maxEventsSize) throws ArangoException { return replicationDriver.setReplicationLoggerConfig(getDefaultDatabase(), autoStart, logRemoteChanges, maxEvents, maxEventsSize); } @@ -3982,16 +4041,16 @@ public ReplicationApplierConfigEntity getReplicationApplierConfig() throws Arang * @throws ArangoException */ public ReplicationApplierConfigEntity setReplicationApplierConfig( - String endpoint, - String database, - String username, - String password, - Integer maxConnectRetries, - Integer connectTimeout, - Integer requestTimeout, - Integer chunkSize, - Boolean autoStart, - Boolean adaptivePolling) throws ArangoException { + final String endpoint, + final String database, + final String username, + final String password, + final Integer maxConnectRetries, + final Integer connectTimeout, + final Integer requestTimeout, + final Integer chunkSize, + final Boolean autoStart, + final Boolean adaptivePolling) throws ArangoException { return replicationDriver.setReplicationApplierConfig(getDefaultDatabase(), endpoint, database, username, password, maxConnectRetries, connectTimeout, requestTimeout, chunkSize, autoStart, adaptivePolling); } @@ -4006,7 +4065,7 @@ public ReplicationApplierConfigEntity setReplicationApplierConfig( * @throws ArangoException */ public ReplicationApplierConfigEntity setReplicationApplierConfig( - ReplicationApplierConfigEntity replicationApplierConfigEntity) throws ArangoException { + final ReplicationApplierConfigEntity replicationApplierConfigEntity) throws ArangoException { return replicationDriver.setReplicationApplierConfig(getDefaultDatabase(), replicationApplierConfigEntity); } @@ -4019,7 +4078,7 @@ public ReplicationApplierConfigEntity setReplicationApplierConfig( * @return ReplicationApplierStateEntity * @throws ArangoException */ - public ReplicationApplierStateEntity startReplicationApplier(Long from) throws ArangoException { + public ReplicationApplierStateEntity startReplicationApplier(final Long from) throws ArangoException { return replicationDriver.startReplicationApplier(getDefaultDatabase(), from); } @@ -4082,10 +4141,10 @@ public List getGraphList() throws ArangoException { * @throws ArangoException */ public GraphEntity createGraph( - String graphName, - List edgeDefinitions, - List orphanCollections, - Boolean waitForSync) throws ArangoException { + final String graphName, + final List edgeDefinitions, + final List orphanCollections, + final Boolean waitForSync) throws ArangoException { return graphDriver.createGraph(getDefaultDatabase(), graphName, edgeDefinitions, orphanCollections, waitForSync); } @@ -4100,10 +4159,10 @@ public GraphEntity createGraph( * @return GraphEntity The new graph. * @throws ArangoException */ - public GraphEntity createGraph(GraphEntity graph, Boolean waitForSync) throws ArangoException { - String graphName = graph.getName(); - List edgeDefinitions = graph.getEdgeDefinitions(); - List orphanCollections = graph.getOrphanCollections(); + public GraphEntity createGraph(final GraphEntity graph, final Boolean waitForSync) throws ArangoException { + final String graphName = graph.getName(); + final List edgeDefinitions = graph.getEdgeDefinitions(); + final List orphanCollections = graph.getOrphanCollections(); return graphDriver.createGraph(getDefaultDatabase(), graphName, edgeDefinitions, orphanCollections, waitForSync); } @@ -4118,7 +4177,7 @@ public GraphEntity createGraph(GraphEntity graph, Boolean waitForSync) throws Ar * @return GraphEntity The new graph. * @throws ArangoException */ - public GraphEntity createGraph(String graphName, Boolean waitForSync) throws ArangoException { + public GraphEntity createGraph(final String graphName, final Boolean waitForSync) throws ArangoException { return graphDriver.createGraph(getDefaultDatabase(), graphName, waitForSync); } @@ -4131,7 +4190,7 @@ public GraphEntity createGraph(String graphName, Boolean waitForSync) throws Ara * @return GraphEntity The graph. * @throws ArangoException */ - public GraphEntity getGraph(String graphName) throws ArangoException { + public GraphEntity getGraph(final String graphName) throws ArangoException { return graphDriver.getGraph(getDefaultDatabase(), graphName); } @@ -4144,7 +4203,7 @@ public GraphEntity getGraph(String graphName) throws ArangoException { * @return DeletedEntity * @throws ArangoException */ - public DeletedEntity deleteGraph(String graphName) throws ArangoException { + public DeletedEntity deleteGraph(final String graphName) throws ArangoException { return graphDriver.deleteGraph(getDefaultDatabase(), graphName, false); } @@ -4158,7 +4217,7 @@ public DeletedEntity deleteGraph(String graphName) throws ArangoException { * Indicates if the collections of the graph will be dropped * @throws ArangoException */ - public void deleteGraph(String graphName, Boolean dropCollections) throws ArangoException { + public void deleteGraph(final String graphName, final Boolean dropCollections) throws ArangoException { graphDriver.deleteGraph(getDefaultDatabase(), graphName, dropCollections); } @@ -4171,7 +4230,7 @@ public void deleteGraph(String graphName, Boolean dropCollections) throws Arango * @return List List of the names of the vertex collections * @throws ArangoException */ - public List graphGetVertexCollections(String graphName) throws ArangoException { + public List graphGetVertexCollections(final String graphName) throws ArangoException { return graphDriver.getVertexCollections(getDefaultDatabase(), graphName); } @@ -4188,8 +4247,10 @@ public List graphGetVertexCollections(String graphName) throws ArangoExc * Indicates if the collection will be dropped * @throws ArangoException */ - public DeletedEntity graphDeleteVertexCollection(String graphName, String collectionName, Boolean dropCollection) - throws ArangoException { + public DeletedEntity graphDeleteVertexCollection( + final String graphName, + final String collectionName, + final Boolean dropCollection) throws ArangoException { return graphDriver.deleteVertexCollection(getDefaultDatabase(), graphName, collectionName, dropCollection); } @@ -4203,7 +4264,8 @@ public DeletedEntity graphDeleteVertexCollection(String graphName, String collec * @return GraphEntity The graph, including the new collection. * @throws ArangoException */ - public GraphEntity graphCreateVertexCollection(String graphName, String collectionName) throws ArangoException { + public GraphEntity graphCreateVertexCollection(final String graphName, final String collectionName) + throws ArangoException { return graphDriver.createVertexCollection(getDefaultDatabase(), graphName, collectionName); } @@ -4217,7 +4279,7 @@ public GraphEntity graphCreateVertexCollection(String graphName, String collecti * graph. * @throws ArangoException */ - public List graphGetEdgeCollections(String graphName) throws ArangoException { + public List graphGetEdgeCollections(final String graphName) throws ArangoException { return graphDriver.getEdgeCollections(getDefaultDatabase(), graphName); } @@ -4231,7 +4293,7 @@ public List graphGetEdgeCollections(String graphName) throws ArangoExcep * @return GraphEntity The graph, including the new edge definition. * @throws ArangoException */ - public GraphEntity graphCreateEdgeDefinition(String graphName, EdgeDefinitionEntity edgeDefinition) + public GraphEntity graphCreateEdgeDefinition(final String graphName, final EdgeDefinitionEntity edgeDefinition) throws ArangoException { return graphDriver.createEdgeDefinition(getDefaultDatabase(), graphName, edgeDefinition); } @@ -4252,9 +4314,9 @@ public GraphEntity graphCreateEdgeDefinition(String graphName, EdgeDefinitionEnt * @throws ArangoException */ public GraphEntity graphReplaceEdgeDefinition( - String graphName, - String edgeCollectionName, - EdgeDefinitionEntity edgeDefinition) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final EdgeDefinitionEntity edgeDefinition) throws ArangoException { return graphDriver.replaceEdgeDefinition(getDefaultDatabase(), graphName, edgeCollectionName, edgeDefinition); } @@ -4270,8 +4332,10 @@ public GraphEntity graphReplaceEdgeDefinition( * to be deleted. * @return The graph, excluding the deleted edge definition. */ - public GraphEntity graphDeleteEdgeDefinition(String graphName, String edgeCollectionName, Boolean dropCollection) - throws ArangoException { + public GraphEntity graphDeleteEdgeDefinition( + final String graphName, + final String edgeCollectionName, + final Boolean dropCollection) throws ArangoException { return graphDriver.deleteEdgeDefinition(getDefaultDatabase(), graphName, edgeCollectionName, dropCollection); } @@ -4291,8 +4355,11 @@ public GraphEntity graphDeleteEdgeDefinition(String graphName, String edgeCollec * vertex document. * @throws ArangoException */ - public VertexEntity graphCreateVertex(String graphName, String collectionName, T vertex, Boolean waitForSync) - throws ArangoException { + public VertexEntity graphCreateVertex( + final String graphName, + final String collectionName, + final T vertex, + final Boolean waitForSync) throws ArangoException { return graphDriver.createVertex(getDefaultDatabase(), graphName, collectionName, vertex, waitForSync); } @@ -4315,11 +4382,11 @@ public VertexEntity graphCreateVertex(String graphName, String collection * @throws ArangoException */ public VertexEntity graphCreateVertex( - String graphName, - String collectionName, - String key, - T vertex, - Boolean waitForSync) throws ArangoException { + final String graphName, + final String collectionName, + final String key, + final T vertex, + final Boolean waitForSync) throws ArangoException { return graphDriver.createVertex(getDefaultDatabase(), graphName, collectionName, key, vertex, waitForSync); } @@ -4338,8 +4405,11 @@ public VertexEntity graphCreateVertex( * vertex document. * @throws ArangoException */ - public VertexEntity graphGetVertex(String graphName, String collectionName, String key, Class clazz) - throws ArangoException { + public VertexEntity graphGetVertex( + final String graphName, + final String collectionName, + final String key, + final Class clazz) throws ArangoException { return graphDriver.getVertex(getDefaultDatabase(), graphName, collectionName, key, clazz, null, null); } @@ -4365,12 +4435,12 @@ public VertexEntity graphGetVertex(String graphName, String collectionNam * @throws ArangoException */ public VertexEntity graphGetVertex( - String graphName, - String collectionName, - String key, - Class clazz, - Long ifNoneMatchRevision, - Long ifMatchRevision) throws ArangoException { + final String graphName, + final String collectionName, + final String key, + final Class clazz, + final Long ifNoneMatchRevision, + final Long ifMatchRevision) throws ArangoException { return graphDriver.getVertex(getDefaultDatabase(), graphName, collectionName, key, clazz, ifMatchRevision, ifNoneMatchRevision); } @@ -4388,7 +4458,8 @@ public VertexEntity graphGetVertex( * @return DeletedEntity * @throws ArangoException */ - public DeletedEntity graphDeleteVertex(String graphName, String collectionName, String key) throws ArangoException { + public DeletedEntity graphDeleteVertex(final String graphName, final String collectionName, final String key) + throws ArangoException { return graphDriver.deleteVertex(getDefaultDatabase(), graphName, collectionName, key, null, null, null); } @@ -4407,8 +4478,11 @@ public DeletedEntity graphDeleteVertex(String graphName, String collectionName, * @return DeletedEntity * @throws ArangoException */ - public DeletedEntity graphDeleteVertex(String graphName, String collectionName, String key, Boolean waitForSync) - throws ArangoException { + public DeletedEntity graphDeleteVertex( + final String graphName, + final String collectionName, + final String key, + final Boolean waitForSync) throws ArangoException { return graphDriver.deleteVertex(getDefaultDatabase(), graphName, collectionName, key, waitForSync, null, null); } @@ -4434,12 +4508,12 @@ public DeletedEntity graphDeleteVertex(String graphName, String collectionName, * @throws ArangoException */ public DeletedEntity graphDeleteVertex( - String graphName, - String collectionName, - String key, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String graphName, + final String collectionName, + final String key, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { return graphDriver.deleteVertex(getDefaultDatabase(), graphName, collectionName, key, waitForSync, ifMatchRevision, ifNoneMatchRevision); } @@ -4459,8 +4533,11 @@ public DeletedEntity graphDeleteVertex( * @return DocumentEntity * @throws ArangoException */ - public VertexEntity graphReplaceVertex(String graphName, String collectionName, String key, T vertex) - throws ArangoException { + public VertexEntity graphReplaceVertex( + final String graphName, + final String collectionName, + final String key, + final T vertex) throws ArangoException { return graphDriver.replaceVertex(getDefaultDatabase(), graphName, collectionName, key, vertex, null, null, null); } @@ -4489,13 +4566,13 @@ public VertexEntity graphReplaceVertex(String graphName, String collectio * @throws ArangoException */ public VertexEntity graphReplaceVertex( - String graphName, - String collectionName, - String key, - T vertex, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String graphName, + final String collectionName, + final String key, + final T vertex, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { return graphDriver.replaceVertex(getDefaultDatabase(), graphName, collectionName, key, vertex, waitForSync, ifMatchRevision, ifNoneMatchRevision); } @@ -4519,11 +4596,11 @@ public VertexEntity graphReplaceVertex( * @throws ArangoException */ public VertexEntity graphUpdateVertex( - String graphName, - String collectionName, - String key, - T vertex, - Boolean keepNull) throws ArangoException { + final String graphName, + final String collectionName, + final String key, + final T vertex, + final Boolean keepNull) throws ArangoException { return graphDriver.updateVertex(getDefaultDatabase(), graphName, collectionName, key, vertex, keepNull, null, null, null); } @@ -4555,14 +4632,14 @@ public VertexEntity graphUpdateVertex( * @throws ArangoException */ public VertexEntity graphUpdateVertex( - String graphName, - String collectionName, - String key, - T vertex, - Boolean keepNull, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String graphName, + final String collectionName, + final String key, + final T vertex, + final Boolean keepNull, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { return graphDriver.updateVertex(getDefaultDatabase(), graphName, collectionName, key, vertex, keepNull, waitForSync, ifMatchRevision, ifNoneMatchRevision); } @@ -4587,12 +4664,12 @@ public VertexEntity graphUpdateVertex( * @throws ArangoException */ public EdgeEntity graphCreateEdge( - String graphName, - String edgeCollectionName, - String fromHandle, - String toHandle, - T value, - Boolean waitForSync) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String fromHandle, + final String toHandle, + final T value, + final Boolean waitForSync) throws ArangoException { return graphDriver.createEdge(getDefaultDatabase(), graphName, edgeCollectionName, null, fromHandle, toHandle, value, waitForSync); } @@ -4619,13 +4696,13 @@ public EdgeEntity graphCreateEdge( * @throws ArangoException */ public EdgeEntity graphCreateEdge( - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle, - T value, - Boolean waitForSync) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle, + final T value, + final Boolean waitForSync) throws ArangoException { return graphDriver.createEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, value, waitForSync); } @@ -4647,11 +4724,11 @@ public EdgeEntity graphCreateEdge( * @throws ArangoException */ public EdgeEntity graphCreateEdge( - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle) throws ArangoException { return graphDriver.createEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, null, null); } @@ -4677,12 +4754,12 @@ public EdgeEntity graphCreateEdge( * @throws ArangoException */ public EdgeEntity graphGetEdge( - String graphName, - String edgeCollectionName, - String key, - Class clazz, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String key, + final Class clazz, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { return graphDriver.getEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, clazz, ifMatchRevision, ifNoneMatchRevision); } @@ -4701,8 +4778,11 @@ public EdgeEntity graphGetEdge( * @return a EdgeEntity object * @throws ArangoException */ - public EdgeEntity graphGetEdge(String graphName, String edgeCollectionName, String key, Class clazz) - throws ArangoException { + public EdgeEntity graphGetEdge( + final String graphName, + final String edgeCollectionName, + final String key, + final Class clazz) throws ArangoException { return graphDriver.getEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, clazz, null, null); } @@ -4718,7 +4798,7 @@ public EdgeEntity graphGetEdge(String graphName, String edgeCollectionNam * @return DeletedEntity * @throws ArangoException */ - public DeletedEntity graphDeleteEdge(String graphName, String edgeCollectionName, String key) + public DeletedEntity graphDeleteEdge(final String graphName, final String edgeCollectionName, final String key) throws ArangoException { return graphDriver.deleteEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, null, null, null); } @@ -4737,8 +4817,11 @@ public DeletedEntity graphDeleteEdge(String graphName, String edgeCollectionName * @return a DeletedEntity object * @throws ArangoException */ - public DeletedEntity graphDeleteEdge(String graphName, String edgeCollectionName, String key, Boolean waitForSync) - throws ArangoException { + public DeletedEntity graphDeleteEdge( + final String graphName, + final String edgeCollectionName, + final String key, + final Boolean waitForSync) throws ArangoException { return graphDriver.deleteEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, waitForSync, null, null); } @@ -4764,12 +4847,12 @@ public DeletedEntity graphDeleteEdge(String graphName, String edgeCollectionName * @throws ArangoException */ public DeletedEntity graphDeleteEdge( - String graphName, - String edgeCollectionName, - String key, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String key, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { return graphDriver.deleteEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, waitForSync, ifMatchRevision, ifNoneMatchRevision); } @@ -4796,12 +4879,12 @@ public DeletedEntity graphDeleteEdge( * @throws ArangoException */ public EdgeEntity graphReplaceEdge( - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle, - T value) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle, + final T value) throws ArangoException { return graphDriver.replaceEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, value, null, null, null); } @@ -4837,15 +4920,15 @@ public EdgeEntity graphReplaceEdge( * @throws ArangoException */ public EdgeEntity graphReplaceEdge( - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle, - T value, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle, + final T value, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { return graphDriver.replaceEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, value, waitForSync, ifMatchRevision, ifNoneMatchRevision); } @@ -4874,13 +4957,13 @@ public EdgeEntity graphReplaceEdge( * @throws ArangoException */ public EdgeEntity graphUpdateEdge( - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle, - T value, - Boolean keepNull) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle, + final T value, + final Boolean keepNull) throws ArangoException { return graphDriver.updateEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, value, null, keepNull, null, null); } @@ -4917,16 +5000,16 @@ public EdgeEntity graphUpdateEdge( * @throws ArangoException */ public EdgeEntity graphUpdateEdge( - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle, - T value, - Boolean waitForSync, - Boolean keepNull, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle, + final T value, + final Boolean waitForSync, + final Boolean keepNull, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { return graphDriver.updateEdge(getDefaultDatabase(), graphName, edgeCollectionName, key, fromHandle, toHandle, value, waitForSync, keepNull, ifMatchRevision, ifNoneMatchRevision); } @@ -4944,11 +5027,11 @@ public EdgeEntity graphUpdateEdge( * {@link #graphGetEdgeCursor(String, Class, Object, GraphEdgesOptions, AqlQueryOptions)} */ @Deprecated - public CursorEntity graphGetEdges(String graphName) throws ArangoException { + public CursorEntity graphGetEdges(final String graphName) throws ArangoException { validateCollectionName(graphName); - String query = "for i in graph_edges(@graphName, null, { includeData: true }) return i"; - Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName).get(); + final String query = "for i in graph_edges(@graphName, null, { includeData: true }) return i"; + final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName).get(); return this.executeQuery(query, bindVars, PlainEdgeEntity.class, true, 20); } @@ -4968,14 +5051,14 @@ public CursorEntity graphGetEdges(String graphName) throws Aran * @throws ArangoException */ public EdgeCursor executeEdgeQuery( - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions, - Class clazz) throws ArangoException { + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions, + final Class clazz) throws ArangoException { @SuppressWarnings("unchecked") - DocumentCursorResult> baseCursor = cursorDriver.executeBaseCursorQuery(getDefaultDatabase(), - query, bindVars, getAqlQueryOptions(aqlQueryOptions), EdgeEntity.class, clazz); + final DocumentCursorResult> baseCursor = cursorDriver.executeBaseCursorQuery( + getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions), EdgeEntity.class, clazz); return new EdgeCursor(baseCursor); } @@ -4994,14 +5077,14 @@ public EdgeCursor executeEdgeQuery( * @throws ArangoException */ public VertexCursor executeVertexQuery( - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions, - Class clazz) throws ArangoException { + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions, + final Class clazz) throws ArangoException { @SuppressWarnings("unchecked") - DocumentCursorResult> baseCursor = cursorDriver.executeBaseCursorQuery(getDefaultDatabase(), - query, bindVars, getAqlQueryOptions(aqlQueryOptions), VertexEntity.class, clazz); + final DocumentCursorResult> baseCursor = cursorDriver.executeBaseCursorQuery( + getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions), VertexEntity.class, clazz); return new VertexCursor(baseCursor); } @@ -5021,11 +5104,11 @@ public VertexCursor executeVertexQuery( * @throws ArangoException */ public EdgeCursor graphGetEdgeCursor( - String graphName, - Class clazz, - Object vertexExample, - GraphEdgesOptions graphEdgesOptions, - AqlQueryOptions aqlQueryOptions) throws ArangoException { + final String graphName, + final Class clazz, + final Object vertexExample, + final GraphEdgesOptions graphEdgesOptions, + final AqlQueryOptions aqlQueryOptions) throws ArangoException { GraphEdgesOptions tmpGraphEdgesOptions = graphEdgesOptions; if (tmpGraphEdgesOptions == null) { @@ -5034,8 +5117,8 @@ public EdgeCursor graphGetEdgeCursor( validateCollectionName(graphName); - String query = "for i in graph_edges(@graphName, @vertexExample, @options) return i"; - Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) + final String query = "for i in graph_edges(@graphName, @vertexExample, @options) return i"; + final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) .put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)) .put("options", JsonUtils.convertNullToMap(tmpGraphEdgesOptions)).get(); @@ -5063,17 +5146,17 @@ public EdgeCursor graphGetEdgeCursor( * @throws ArangoException */ public VertexCursor graphGetVertexCursor( - String graphName, - Class clazz, - Object vertexExample, - GraphVerticesOptions graphVerticesOptions, - AqlQueryOptions aqlQueryOptions) throws ArangoException { + final String graphName, + final Class clazz, + final Object vertexExample, + final GraphVerticesOptions graphVerticesOptions, + final AqlQueryOptions aqlQueryOptions) throws ArangoException { validateCollectionName(graphName); - String query = "for i in graph_vertices(@graphName , @vertexExample, @options) return i"; + final String query = "for i in graph_vertices(@graphName , @vertexExample, @options) return i"; - Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) + final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) .put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)) .put("options", JsonUtils.convertNullToMap(graphVerticesOptions)).get(); @@ -5088,7 +5171,7 @@ public VertexCursor graphGetVertexCursor( * @return EdgeCursor * @throws ArangoException */ - public EdgeCursor graphGetEdgeCursor(String graphName) throws ArangoException { + public EdgeCursor graphGetEdgeCursor(final String graphName) throws ArangoException { validateCollectionName(graphName); return graphGetEdgeCursor(graphName, PlainEdgeEntity.class, null, new GraphEdgesOptions(), null); @@ -5106,12 +5189,14 @@ public EdgeCursor graphGetEdgeCursor(String graphName) throws A * {@link #graphGetEdgeCursor(String, Class, Object, GraphEdgesOptions, AqlQueryOptions)} */ @Deprecated - public CursorEntity graphGetEdges(String graphName, Class clazz, String vertexDocumentHandle) - throws ArangoException { + public CursorEntity graphGetEdges( + final String graphName, + final Class clazz, + final String vertexDocumentHandle) throws ArangoException { validateCollectionName(graphName); - String query = "for i in graph_edges(@graphName, @vertexDocumentHandle, { includeData: true }) return i"; - Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) + final String query = "for i in graph_edges(@graphName, @vertexDocumentHandle, { includeData: true }) return i"; + final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) .put("vertexDocumentHandle", vertexDocumentHandle).get(); return this.executeQuery(query, bindVars, clazz, true, 20); @@ -5127,8 +5212,10 @@ public CursorEntity graphGetEdges(String graphName, Class clazz, Strin * @return EdgeCursor * @throws ArangoException */ - public EdgeCursor graphGetEdgeCursorByExample(String graphName, Class clazz, Object vertexExample) - throws ArangoException { + public EdgeCursor graphGetEdgeCursorByExample( + final String graphName, + final Class clazz, + final Object vertexExample) throws ArangoException { return graphGetEdgeCursor(graphName, clazz, vertexExample, new GraphEdgesOptions(), null); } @@ -5146,13 +5233,15 @@ public EdgeCursor graphGetEdgeCursorByExample(String graphName, Class * {@link #graphGetEdgeCursorByExample(String, Class, Object)} */ @Deprecated - public CursorEntity graphGetEdgesByExampleObject(String graphName, Class clazz, Object vertexExample) - throws ArangoException { + public CursorEntity graphGetEdgesByExampleObject( + final String graphName, + final Class clazz, + final Object vertexExample) throws ArangoException { validateCollectionName(graphName); - String query = "for i in graph_edges(@graphName, @vertexExample, { includeData: true }) return i"; + final String query = "for i in graph_edges(@graphName, @vertexExample, { includeData: true }) return i"; - Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName).put(VERTEX_EXAMPLE, vertexExample) - .get(); + final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) + .put(VERTEX_EXAMPLE, vertexExample).get(); return this.executeQuery(query, bindVars, clazz, true, 20); } @@ -5173,25 +5262,25 @@ public CursorEntity graphGetEdgesByExampleObject(String graphName, Class< */ @Deprecated public CursorEntity graphGetEdgesByExampleMap( - String graphName, - Class clazz, - Map vertexExample) throws ArangoException { + final String graphName, + final Class clazz, + final Map vertexExample) throws ArangoException { validateCollectionName(graphName); - String query = "for i in graph_edges(@graphName, @vertexExample, { includeData: true }) return i"; + final String query = "for i in graph_edges(@graphName, @vertexExample, { includeData: true }) return i"; - Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName).put(VERTEX_EXAMPLE, vertexExample) - .get(); + final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) + .put(VERTEX_EXAMPLE, vertexExample).get(); return this.executeQuery(query, bindVars, clazz, true, 20, null); } public ShortestPathEntity graphGetShortestPath( - String graphName, - Object startVertexExample, - Object endVertexExample, - ShortestPathOptions shortestPathOptions, - Class vertexClass, - Class edgeClass) throws ArangoException { + final String graphName, + final Object startVertexExample, + final Object endVertexExample, + final ShortestPathOptions shortestPathOptions, + final Class vertexClass, + final Class edgeClass) throws ArangoException { ShortestPathOptions tmpShortestPathOptions = shortestPathOptions; if (tmpShortestPathOptions == null) { @@ -5212,7 +5301,7 @@ public ShortestPathEntity graphGetShortestPath( * @return DefaultEntity * @throws ArangoException */ - public DefaultEntity createAqlFunction(String name, String code) throws ArangoException { + public DefaultEntity createAqlFunction(final String name, final String code) throws ArangoException { return aqlFunctionsDriver.createAqlFunction(name, code); } @@ -5224,7 +5313,7 @@ public DefaultEntity createAqlFunction(String name, String code) throws ArangoEx * @return AqlFunctionsEntity * @throws ArangoException */ - public AqlFunctionsEntity getAqlFunctions(String namespace) throws ArangoException { + public AqlFunctionsEntity getAqlFunctions(final String namespace) throws ArangoException { return aqlFunctionsDriver.getAqlFunctions(namespace); } @@ -5239,7 +5328,7 @@ public AqlFunctionsEntity getAqlFunctions(String namespace) throws ArangoExcepti * @return DefaultEntity * @throws ArangoException */ - public DefaultEntity deleteAqlFunction(String name, boolean isNameSpace) throws ArangoException { + public DefaultEntity deleteAqlFunction(final String name, final boolean isNameSpace) throws ArangoException { return aqlFunctionsDriver.deleteAqlFunction(name, isNameSpace); } @@ -5250,7 +5339,7 @@ public DefaultEntity deleteAqlFunction(String name, boolean isNameSpace) throws * the transaction as javascript code * @return TransactionEntity */ - public TransactionEntity createTransaction(String action) { + public TransactionEntity createTransaction(final String action) { return this.transactionDriver.createTransaction(action); } @@ -5263,7 +5352,8 @@ public TransactionEntity createTransaction(String action) { * @return TransactionResultEntity * @throws ArangoException */ - public TransactionResultEntity executeTransaction(TransactionEntity transactionEntity) throws ArangoException { + public TransactionResultEntity executeTransaction(final TransactionEntity transactionEntity) + throws ArangoException { return this.transactionDriver.executeTransaction(getDefaultDatabase(), transactionEntity); } @@ -5282,9 +5372,9 @@ public TransactionResultEntity executeTransaction(TransactionEntity transactionE * @throws ArangoException */ public TraversalEntity getTraversal( - TraversalQueryOptions traversalQueryOptions, - Class vertexClazz, - Class edgeClazz) throws ArangoException { + final TraversalQueryOptions traversalQueryOptions, + final Class vertexClazz, + final Class edgeClazz) throws ArangoException { return this.traversalDriver.getTraversal(getDefaultDatabase(), traversalQueryOptions, vertexClazz, edgeClazz); } @@ -5316,7 +5406,7 @@ public QueryCachePropertiesEntity getQueryCacheProperties() throws ArangoExcepti * @return QueryCachePropertiesEntity * @throws ArangoException */ - public QueryCachePropertiesEntity setQueryCacheProperties(QueryCachePropertiesEntity properties) + public QueryCachePropertiesEntity setQueryCacheProperties(final QueryCachePropertiesEntity properties) throws ArangoException { return queryCacheDriver.setQueryCacheProperties(properties); } @@ -5339,7 +5429,7 @@ public QueryTrackingPropertiesEntity getQueryTrackingProperties() throws ArangoE * @return the configuration * @throws ArangoException */ - public QueryTrackingPropertiesEntity setQueryTrackingProperties(QueryTrackingPropertiesEntity properties) + public QueryTrackingPropertiesEntity setQueryTrackingProperties(final QueryTrackingPropertiesEntity properties) throws ArangoException { return this.cursorDriver.setQueryTrackingProperties(getDefaultDatabase(), properties); } @@ -5362,7 +5452,7 @@ public QueriesResultEntity getCurrentlyRunningQueries() throws ArangoException { * @return a list of currently running AQL queries * @throws ArangoException */ - public QueriesResultEntity getCurrentlyRunningQueries(String database) throws ArangoException { + public QueriesResultEntity getCurrentlyRunningQueries(final String database) throws ArangoException { return this.cursorDriver.getCurrentlyRunningQueries(database); } @@ -5384,7 +5474,7 @@ public QueriesResultEntity getSlowQueries() throws ArangoException { * @return a list of slow running AQL queries * @throws ArangoException */ - public QueriesResultEntity getSlowQueries(String database) throws ArangoException { + public QueriesResultEntity getSlowQueries(final String database) throws ArangoException { return this.cursorDriver.getSlowQueries(database); } @@ -5406,7 +5496,7 @@ public DefaultEntity deleteSlowQueries() throws ArangoException { * @return * @throws ArangoException */ - public DefaultEntity deleteSlowQueries(String database) throws ArangoException { + public DefaultEntity deleteSlowQueries(final String database) throws ArangoException { return this.cursorDriver.deleteSlowQueries(database); } @@ -5418,7 +5508,7 @@ public DefaultEntity deleteSlowQueries(String database) throws ArangoException { * @return * @throws ArangoException */ - public DefaultEntity killQuery(String id) throws ArangoException { + public DefaultEntity killQuery(final String id) throws ArangoException { return this.cursorDriver.killQuery(getDefaultDatabase(), id); } @@ -5432,7 +5522,7 @@ public DefaultEntity killQuery(String id) throws ArangoException { * @return * @throws ArangoException */ - public DefaultEntity killQuery(String database, String id) throws ArangoException { + public DefaultEntity killQuery(final String database, final String id) throws ArangoException { return this.cursorDriver.killQuery(database, id); } @@ -5461,12 +5551,10 @@ public HttpManager getHttpManager() { * @throws ArangoException */ public DocumentEntity createDocumentRaw( - String collectionName, - String rawJsonString, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - return documentDriver.createDocumentRaw(getDefaultDatabase(), collectionName, rawJsonString, createCollection, - waitForSync); + final String collectionName, + final String rawJsonString, + final Boolean waitForSync) throws ArangoException { + return documentDriver.createDocumentRaw(getDefaultDatabase(), collectionName, rawJsonString, waitForSync); } /** @@ -5487,8 +5575,10 @@ public DocumentEntity createDocumentRaw( * @return a String * @throws ArangoException */ - public String getDocumentRaw(String documentHandle, Long ifNoneMatchRevision, Long ifMatchRevision) - throws ArangoException { + public String getDocumentRaw( + final String documentHandle, + final Long ifNoneMatchRevision, + final Long ifMatchRevision) throws ArangoException { return documentDriver.getDocumentRaw(getDefaultDatabase(), documentHandle, ifNoneMatchRevision, ifMatchRevision); } @@ -5508,9 +5598,9 @@ public String getDocumentRaw(String documentHandle, Long ifNoneMatchRevision, Lo * @throws ArangoException */ public CursorRawResult executeAqlQueryRaw( - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions) throws ArangoException { + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions) throws ArangoException { return cursorDriver.executeAqlQueryRaw(getDefaultDatabase(), query, bindVars, getAqlQueryOptions(aqlQueryOptions)); @@ -5538,11 +5628,11 @@ public CursorRawResult executeAqlQueryRaw( * @throws ArangoException */ public DocumentEntity replaceDocumentRaw( - String documentHandle, - String rawJsonString, - Long rev, - Policy policy, - Boolean waitForSync) throws ArangoException { + final String documentHandle, + final String rawJsonString, + final Long rev, + final Policy policy, + final Boolean waitForSync) throws ArangoException { return documentDriver.replaceDocumentRaw(getDefaultDatabase(), documentHandle, rawJsonString, rev, policy, waitForSync); } @@ -5571,12 +5661,12 @@ public DocumentEntity replaceDocumentRaw( * @throws ArangoException */ public DocumentEntity updateDocumentRaw( - String documentHandle, - String rawJsonString, - Long rev, - Policy policy, - Boolean waitForSync, - Boolean keepNull) throws ArangoException { + final String documentHandle, + final String rawJsonString, + final Long rev, + final Policy policy, + final Boolean waitForSync, + final Boolean keepNull) throws ArangoException { return documentDriver.updateDocumentRaw(getDefaultDatabase(), documentHandle, rawJsonString, rev, policy, waitForSync, keepNull); } @@ -5585,7 +5675,7 @@ public DocumentEntity updateDocumentRaw( // private functions // - private void createModuleDrivers(boolean createProxys) { + private void createModuleDrivers(final boolean createProxys) { if (!createProxys) { this.cursorDriver = ImplFactory.createCursorDriver(configure, this.httpManager); this.batchDriver = ImplFactory.createBatchDriver(configure, this.httpManager); @@ -5655,7 +5745,7 @@ private void createModuleDrivers(boolean createProxys) { } } - private AqlQueryOptions getAqlQueryOptions(AqlQueryOptions aqlQueryOptions) { + private AqlQueryOptions getAqlQueryOptions(final AqlQueryOptions aqlQueryOptions) { if (aqlQueryOptions == null) { return getDefaultAqlQueryOptions(); } diff --git a/src/main/java/com/arangodb/InternalDocumentDriver.java b/src/main/java/com/arangodb/InternalDocumentDriver.java index c251b4104..03c28a3e0 100644 --- a/src/main/java/com/arangodb/InternalDocumentDriver.java +++ b/src/main/java/com/arangodb/InternalDocumentDriver.java @@ -15,14 +15,12 @@ DocumentEntity createDocument( String collectionName, String documentKey, T value, - Boolean createCollection, Boolean waitForSync) throws ArangoException; DocumentEntity createDocumentRaw( String database, String collectionName, String rawJsonString, - Boolean createCollection, Boolean waitForSync) throws ArangoException; DocumentEntity replaceDocument( diff --git a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java index edfe00b82..c0807f1b6 100644 --- a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java @@ -50,18 +50,17 @@ public class InternalDocumentDriverImpl extends BaseArangoDriverImpl implements private static final Pattern pattern = Pattern.compile("^/_db/.*/_api/document/(.*)$"); - InternalDocumentDriverImpl(ArangoConfigure configure, HttpManager httpManager) { + InternalDocumentDriverImpl(final ArangoConfigure configure, final HttpManager httpManager) { super(configure, httpManager); } private DocumentEntity internalCreateDocument( - String database, - String collectionName, - String documentKey, - T value, - Boolean createCollection, - Boolean waitForSync, - boolean raw) throws ArangoException { + final String database, + final String collectionName, + final String documentKey, + final T value, + final Boolean waitForSync, + final boolean raw) throws ArangoException { validateCollectionName(collectionName); @@ -69,7 +68,7 @@ private DocumentEntity internalCreateDocument( if (raw) { body = value.toString(); } else if (documentKey != null) { - JsonElement elem = EntityFactory.toJsonElement(value, false); + final JsonElement elem = EntityFactory.toJsonElement(value, false); if (elem.isJsonObject()) { elem.getAsJsonObject().addProperty(BaseDocument.KEY, documentKey); } @@ -78,13 +77,11 @@ private DocumentEntity internalCreateDocument( body = EntityFactory.toJsonString(value); } - HttpResponseEntity res = httpManager.doPost(createDocumentEndpointUrl(database), - new MapBuilder().put("collection", collectionName).put("createCollection", createCollection) - .put(WAIT_FOR_SYNC, waitForSync).get(), - body); + final HttpResponseEntity res = httpManager.doPost(createDocumentEndpointUrl(database), + new MapBuilder().put("collection", collectionName).put(WAIT_FOR_SYNC, waitForSync).get(), body); @SuppressWarnings("unchecked") - DocumentEntity result = createEntity(res, DocumentEntity.class); + final DocumentEntity result = createEntity(res, DocumentEntity.class); annotationHandler.updateDocumentAttributes(value, result.getDocumentRevision(), result.getDocumentHandle(), result.getDocumentKey()); @@ -95,49 +92,45 @@ private DocumentEntity internalCreateDocument( @Override public DocumentEntity createDocument( - String database, - String collectionName, - String documentKey, - T value, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - return internalCreateDocument(database, collectionName, documentKey, value, createCollection, waitForSync, - false); + final String database, + final String collectionName, + final String documentKey, + final T value, + final Boolean waitForSync) throws ArangoException { + return internalCreateDocument(database, collectionName, documentKey, value, waitForSync, false); } @Override public DocumentEntity createDocumentRaw( - String database, - String collectionName, - String rawJsonObjectString, - Boolean createCollection, - Boolean waitForSync) throws ArangoException { - return internalCreateDocument(database, collectionName, null, rawJsonObjectString, createCollection, - waitForSync, true); + final String database, + final String collectionName, + final String rawJsonObjectString, + final Boolean waitForSync) throws ArangoException { + return internalCreateDocument(database, collectionName, null, rawJsonObjectString, waitForSync, true); } @SuppressWarnings("unchecked") @Override public DocumentEntity replaceDocument( - String database, - String documentHandle, - T value, - Long rev, - Policy policy, - Boolean waitForSync) throws ArangoException { + final String database, + final String documentHandle, + final T value, + final Long rev, + final Policy policy, + final Boolean waitForSync) throws ArangoException { validateDocumentHandle(documentHandle); Map header = null; if (rev != null) { - MapBuilder mapBuilder = new MapBuilder().put("If-Match", rev); + final MapBuilder mapBuilder = new MapBuilder().put("If-Match", rev); header = mapBuilder.get(); } - HttpResponseEntity res = httpManager.doPut(createDocumentEndpointUrl(database, documentHandle), header, + final HttpResponseEntity res = httpManager.doPut(createDocumentEndpointUrl(database, documentHandle), header, new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(value)); - DocumentEntity result = createEntity(res, DocumentEntity.class); + final DocumentEntity result = createEntity(res, DocumentEntity.class); annotationHandler.updateDocumentRev(value, result.getDocumentRevision()); result.setEntity(value); return result; @@ -145,43 +138,43 @@ public DocumentEntity replaceDocument( @Override public DocumentEntity replaceDocumentRaw( - String database, - String documentHandle, - String rawJsonString, - Long rev, - Policy policy, - Boolean waitForSync) throws ArangoException { + final String database, + final String documentHandle, + final String rawJsonString, + final Long rev, + final Policy policy, + final Boolean waitForSync) throws ArangoException { validateDocumentHandle(documentHandle); - HttpResponseEntity res = httpManager.doPut( + final HttpResponseEntity res = httpManager.doPut( createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("rev", rev) .put(POLICY, policy == null ? null : policy.name()).put(WAIT_FOR_SYNC, waitForSync).get(), rawJsonString); @SuppressWarnings("unchecked") - DocumentEntity result = createEntity(res, DocumentEntity.class); + final DocumentEntity result = createEntity(res, DocumentEntity.class); result.setEntity(rawJsonString); return result; } @Override public DocumentEntity updateDocument( - String database, - String documentHandle, - T value, - Long rev, - Policy policy, - Boolean waitForSync, - Boolean keepNull) throws ArangoException { + final String database, + final String documentHandle, + final T value, + final Long rev, + final Policy policy, + final Boolean waitForSync, + final Boolean keepNull) throws ArangoException { validateDocumentHandle(documentHandle); - HttpResponseEntity res = httpManager.doPatch(createDocumentEndpointUrl(database, documentHandle), + final HttpResponseEntity res = httpManager.doPatch(createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("rev", rev).put(POLICY, policy == null ? null : policy.name()) .put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(), EntityFactory.toJsonString(value, keepNull != null && !keepNull)); @SuppressWarnings("unchecked") - DocumentEntity result = createEntity(res, DocumentEntity.class); + final DocumentEntity result = createEntity(res, DocumentEntity.class); annotationHandler.updateDocumentAttributes(value, result.getDocumentRevision(), result.getDocumentHandle(), result.getDocumentKey()); result.setEntity(value); @@ -190,45 +183,45 @@ public DocumentEntity updateDocument( @Override public DocumentEntity updateDocumentRaw( - String database, - String documentHandle, - String rawJsonString, - Long rev, - Policy policy, - Boolean waitForSync, - Boolean keepNull) throws ArangoException { + final String database, + final String documentHandle, + final String rawJsonString, + final Long rev, + final Policy policy, + final Boolean waitForSync, + final Boolean keepNull) throws ArangoException { validateDocumentHandle(documentHandle); - HttpResponseEntity res = httpManager.doPatch(createDocumentEndpointUrl(database, documentHandle), + final HttpResponseEntity res = httpManager.doPatch(createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("rev", rev).put(POLICY, policy == null ? null : policy.name()) .put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(), rawJsonString); @SuppressWarnings("unchecked") - DocumentEntity result = createEntity(res, DocumentEntity.class); + final DocumentEntity result = createEntity(res, DocumentEntity.class); result.setEntity(rawJsonString); return result; } @Override - public List getDocuments(String database, String collectionName) throws ArangoException { - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/all-keys"), null, + public List getDocuments(final String database, final String collectionName) throws ArangoException { + final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/all-keys"), null, EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).put("type", "id").get())); @SuppressWarnings("unchecked") - CursorEntity tmp = createEntity(res, CursorEntity.class, String.class); + final CursorEntity tmp = createEntity(res, CursorEntity.class, String.class); return tmp.getResults(); } - private void updateDocumentHandles(List documents) { - ListIterator lit = documents.listIterator(); + private void updateDocumentHandles(final List documents) { + final ListIterator lit = documents.listIterator(); while (lit.hasNext()) { - String d = lit.next(); + final String d = lit.next(); if (d.startsWith(API_DOCUMENT_PREFIX)) { lit.set(d.substring(API_DOCUMENT_PREFIX.length())); } else { - Matcher matcher = pattern.matcher(d); + final Matcher matcher = pattern.matcher(d); if (matcher.find()) { lit.set(matcher.group(1)); } @@ -237,25 +230,25 @@ private void updateDocumentHandles(List documents) { } @Override - public long checkDocument(String database, String documentHandle) throws ArangoException { + public long checkDocument(final String database, final String documentHandle) throws ArangoException { validateDocumentHandle(documentHandle); - HttpResponseEntity res = httpManager.doHead(createDocumentEndpointUrl(database, documentHandle), null); + final HttpResponseEntity res = httpManager.doHead(createDocumentEndpointUrl(database, documentHandle), null); - DefaultEntity entity = createEntity(res, DefaultEntity.class); + final DefaultEntity entity = createEntity(res, DefaultEntity.class); return entity.getEtag(); } @Override public DocumentEntity getDocument( - String database, - String documentHandle, - Class clazz, - Long ifNoneMatchRevision, - Long ifMatchRevision) throws ArangoException { + final String database, + final String documentHandle, + final Class clazz, + final Long ifNoneMatchRevision, + final Long ifMatchRevision) throws ArangoException { validateDocumentHandle(documentHandle); - HttpResponseEntity res = httpManager.doGet(createDocumentEndpointUrl(database, documentHandle), + final HttpResponseEntity res = httpManager.doGet(createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("If-None-Match", ifNoneMatchRevision, true).put("If-Match", ifMatchRevision).get(), null); @SuppressWarnings("unchecked") @@ -267,16 +260,19 @@ public DocumentEntity getDocument( } @Override - public String getDocumentRaw(String database, String documentHandle, Long ifNoneMatchRevision, Long ifMatchRevision) - throws ArangoException { + public String getDocumentRaw( + final String database, + final String documentHandle, + final Long ifNoneMatchRevision, + final Long ifMatchRevision) throws ArangoException { validateDocumentHandle(documentHandle); - HttpResponseEntity res = httpManager.doGet(createDocumentEndpointUrl(database, documentHandle), + final HttpResponseEntity res = httpManager.doGet(createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("If-None-Match", ifNoneMatchRevision, true).put("If-Match", ifMatchRevision).get(), null); if (res.getStatusCode() >= 400) { - BaseDocument entity = new BaseDocument(); + final BaseDocument entity = new BaseDocument(); entity.setError(true); entity.setCode(res.getStatusCode()); entity.setStatusCode(res.getStatusCode()); @@ -289,11 +285,14 @@ public String getDocumentRaw(String database, String documentHandle, Long ifNone } @Override - public DocumentEntity deleteDocument(String database, String documentHandle, Long rev, Policy policy) - throws ArangoException { + public DocumentEntity deleteDocument( + final String database, + final String documentHandle, + final Long rev, + final Policy policy) throws ArangoException { validateDocumentHandle(documentHandle); - HttpResponseEntity res = httpManager.doDelete(createDocumentEndpointUrl(database, documentHandle), + final HttpResponseEntity res = httpManager.doDelete(createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("rev", rev).put(POLICY, policy == null ? null : policy.name().toLowerCase(Locale.US)) .get()); diff --git a/src/test/java/com/arangodb/ArangoDriverAsyncTest.java b/src/test/java/com/arangodb/ArangoDriverAsyncTest.java index a067baa1c..5545a9e8c 100644 --- a/src/test/java/com/arangodb/ArangoDriverAsyncTest.java +++ b/src/test/java/com/arangodb/ArangoDriverAsyncTest.java @@ -111,7 +111,7 @@ public void test_execAsyncMode() throws ArangoException { for (int i = 0; i < 10; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - driver.createDocument("blub", value, true, false); + driver.createDocument("blub", value, false); assertThat(driver.getJobIds().size(), is(4 + i)); } @@ -163,7 +163,7 @@ public void test_GetJobsMode() throws ArangoException { for (int i = 0; i < 10; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - driver.createDocument("blub", value, true, false); + driver.createDocument("blub", value, false); assertThat(driver.getJobIds().size(), is(4 + i)); } @@ -176,7 +176,7 @@ public void test_GetJobsMode() throws ArangoException { driver.startAsyncMode(false); for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - driver.createDocument("blub", value, true, false); + driver.createDocument("blub", value, false); } driver.stopAsyncMode(); driver.deleteExpiredJobs((int) (System.currentTimeMillis() / 2000L)); @@ -207,7 +207,7 @@ public void test_GetJobsResult() throws ArangoException { final List ids = new ArrayList(); for (int i = 0; i < 10; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - driver.createDocument("blub", value, true, false); + driver.createDocument("blub", value, false); ids.add(driver.getLastJobId()); } diff --git a/src/test/java/com/arangodb/ArangoDriverBatchTest.java b/src/test/java/com/arangodb/ArangoDriverBatchTest.java index f4d8be522..1043dfcee 100644 --- a/src/test/java/com/arangodb/ArangoDriverBatchTest.java +++ b/src/test/java/com/arangodb/ArangoDriverBatchTest.java @@ -128,7 +128,7 @@ public void test_execBatchMode() throws ArangoException { for (int i = 0; i < 10; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - res = driver.createDocument(COLLECTION_NAME, value, true, false); + res = driver.createDocument(COLLECTION_NAME, value, false); assertThat(res.getStatusCode(), is(206)); assertThat(res.getRequestId(), is("request" + (4 + i))); @@ -168,7 +168,7 @@ public void test_execBatchMode_twice() throws ArangoException { for (int i = 0; i < 10; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - res = driver.createDocument(COLLECTION_NAME, value, true, false); + res = driver.createDocument(COLLECTION_NAME, value, false); assertThat(res.getRequestId(), is("request" + (i + 1))); } @@ -180,7 +180,7 @@ public void test_execBatchMode_twice() throws ArangoException { for (int i = 20; i < 30; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "data:" + i, i); - res = driver.createDocument(COLLECTION_NAME, value, true, false); + res = driver.createDocument(COLLECTION_NAME, value, false); assertThat(res.getRequestId(), is("request" + (i + 1 - 20))); } diff --git a/src/test/java/com/arangodb/ArangoDriverCollectionTest.java b/src/test/java/com/arangodb/ArangoDriverCollectionTest.java index f84d816e4..925085bff 100644 --- a/src/test/java/com/arangodb/ArangoDriverCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCollectionTest.java @@ -335,7 +335,7 @@ public void test_getCollectionRevision() throws ArangoException { assertThat(collection.getRevision(), is(0L)); // Create Document - driver.createDocument(collectionName, new TestComplexEntity01("test_user1", "test user 1", 20), false, true); + driver.createDocument(collectionName, new TestComplexEntity01("test_user1", "test user 1", 20), true); // Get Revision again collection = driver.getCollectionRevision(collectionName); @@ -344,7 +344,7 @@ public void test_getCollectionRevision() throws ArangoException { assertThat(rev2, is(not(0L))); // Create Document - driver.createDocument(collectionName, new TestComplexEntity01("test_user2", "test user 2", 21), false, true); + driver.createDocument(collectionName, new TestComplexEntity01("test_user2", "test user 2", 21), true); // Get Revision again collection = driver.getCollectionRevision(collectionName); @@ -385,7 +385,7 @@ public void test_getCollectionCount_01() throws ArangoException { // 100個ほどドキュメントを入れてみる for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "tes user:" + i, 20 + i); - driver.createDocument(collectionName, value, false, true); + driver.createDocument(collectionName, value, true); } // もっかいアクセスして10になっているか確認する @@ -422,8 +422,7 @@ public void test_getCollectionFigures_01() throws ArangoException { // 100個ほどドキュメントを入れてみる for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); - final DocumentEntity entity = driver.createDocument(collectionName, value, false, - true); + final DocumentEntity entity = driver.createDocument(collectionName, value, true); // 1個消す if (i == 50) { driver.deleteDocument(entity.getDocumentHandle(), null, null); @@ -534,7 +533,7 @@ public void test_load_unload() throws ArangoException { assertThat(collection.getCode(), is(200)); // add document, for count parameter test. - driver.createDocument(collectionName, new MapBuilder("hoge", "fuga").put("fuga", "piyoko").get(), false, null); + driver.createDocument(collectionName, new MapBuilder("hoge", "fuga").put("fuga", "piyoko").get(), null); CollectionEntity collection1 = driver.unloadCollection(collectionName); assertThat(collection1, is(notNullValue())); @@ -601,7 +600,7 @@ public void test_truncate() throws ArangoException { // 100個ほどドキュメントを入れてみる for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("test_user" + i, "test user:" + i, 20 + i); - assertThat(driver.createDocument(collectionName, value, false, true).getStatusCode(), is(201)); + assertThat(driver.createDocument(collectionName, value, true).getStatusCode(), is(201)); } // 100個入ったよね? assertThat(driver.getCollectionCount(collectionName).getCount(), is(100L)); diff --git a/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java b/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java index c5be09c5d..1cbe948a6 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java @@ -46,7 +46,7 @@ public void setup() throws ArangoException { // テストデータを作る for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); - driver.createDocument(collectionName, value, null, null); + driver.createDocument(collectionName, value, null); } } diff --git a/src/test/java/com/arangodb/ArangoDriverCursorTest.java b/src/test/java/com/arangodb/ArangoDriverCursorTest.java index 1e0a1b499..8a5821ed5 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorTest.java @@ -90,7 +90,7 @@ public void test_executeQuery() throws ArangoException { // テストデータを作る for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); - driver.createDocument(collectionName, value, null, null); + driver.createDocument(collectionName, value, null); } // String query = @@ -124,7 +124,7 @@ public void test_executeQuery_2() throws ArangoException { // テストデータを作る for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); - driver.createDocument(collectionName, value, null, null); + driver.createDocument(collectionName, value, null); } // String query = @@ -192,7 +192,7 @@ public void test_executeQueryFullCount() throws ArangoException { // テストデータを作る for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); - driver.createDocument(collectionName, value, null, null); + driver.createDocument(collectionName, value, null); } // String query = @@ -227,7 +227,7 @@ public void test_executeQueryUniqueResult() throws ArangoException { // テストデータを作る for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); - driver.createDocument(collectionName, value, null, null); + driver.createDocument(collectionName, value, null); } // String query = diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentCursorEntityTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentCursorEntityTest.java index 6b5a218d9..d2b1bc2c3 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentCursorEntityTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentCursorEntityTest.java @@ -54,7 +54,7 @@ public void before() throws ArangoException { // create some test data for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); - driver.createDocument(COLLECTION_NAME, value, null, null); + driver.createDocument(COLLECTION_NAME, value, null); } } diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java index 2918e6e16..11ca37fbd 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java @@ -58,7 +58,7 @@ public void setup() throws ArangoException { // create some test data for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); - driver.createDocument(COLLECTION_NAME, value, null, null); + driver.createDocument(COLLECTION_NAME, value, null); } } diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentKeyTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentKeyTest.java index 7a20948c3..ed6016549 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentKeyTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentKeyTest.java @@ -58,11 +58,11 @@ public void before() throws ArangoException { try { driver.deleteCollection("unit_test_arango_001"); - } catch (ArangoException e) { + } catch (final ArangoException e) { } try { driver.createCollection("unit_test_arango_001"); - } catch (ArangoException e) { + } catch (final ArangoException e) { } } @@ -87,13 +87,13 @@ private static class DocumentKeyTestEntity2 { @Test public void test_document_key_string() throws ArangoException { - DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); + final DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); obj.S1 = "s1"; obj.S2 = "s2"; obj.X = 123; // create - DocumentEntity doc = driver.createDocument("unit_test_arango_001", obj, true, null); + DocumentEntity doc = driver.createDocument("unit_test_arango_001", obj, null); assertThat(doc.getDocumentKey(), is("s1")); assertThat(doc.getDocumentHandle(), is("unit_test_arango_001/s1")); assertThat(doc.getEntity(), is(notNullValue())); @@ -109,7 +109,7 @@ public void test_document_key_string() throws ArangoException { assertThat(doc.getEntity().X, is(123)); // get as map - DocumentEntity doc2 = driver.getDocument(doc.getDocumentHandle(), Map.class); + final DocumentEntity doc2 = driver.getDocument(doc.getDocumentHandle(), Map.class); assertThat(doc2.getEntity().get("s1"), is(nullValue())); // s1 is not // contains. assertThat((String) doc2.getEntity().get("_key"), is("s1")); @@ -118,16 +118,16 @@ public void test_document_key_string() throws ArangoException { @Test public void test_document_key_integer() throws ArangoException { - DocumentKeyTestEntity2 obj = new DocumentKeyTestEntity2(); + final DocumentKeyTestEntity2 obj = new DocumentKeyTestEntity2(); obj.S1 = "s1"; obj.S2 = "s2"; obj.X = 123; // create try { - driver.createDocument("unit_test_arango_001", obj, true, null); + driver.createDocument("unit_test_arango_001", obj, null); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(400)); assertThat(e.getErrorNumber(), is(1221)); assertThat(e.getErrorMessage(), is("invalid document key")); @@ -138,12 +138,12 @@ public void test_document_key_integer() throws ArangoException { @Test public void test_document_create() throws ArangoException { - DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); + final DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); obj.S1 = "s1"; obj.S2 = "s2"; obj.X = 123; - DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, true, null); + final DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, null); assertThat(doc1.getStatusCode(), is(202)); assertThat(doc1.getDocumentKey(), is("mykey1")); @@ -152,23 +152,23 @@ public void test_document_create() throws ArangoException { @Test public void test_document_replace() throws ArangoException { - DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); + final DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); obj.S1 = "s1"; obj.S2 = "s2"; obj.X = 123; - DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, true, null); + final DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, null); assertThat(doc1.getStatusCode(), is(202)); assertThat(doc1.getDocumentKey(), is("mykey1")); // replace obj.S1 = "s3"; obj.X = 456; - DocumentEntity doc2 = driver.replaceDocument("unit_test_arango_001", "mykey1", obj); + final DocumentEntity doc2 = driver.replaceDocument("unit_test_arango_001", "mykey1", obj); assertThat(doc1.getStatusCode(), is(202)); assertThat(doc1.getDocumentKey(), is("mykey1")); - DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), + final DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), DocumentKeyTestEntity1.class); assertThat(doc3.getEntity().S1, is("mykey1")); assertThat(doc3.getEntity().S2, is("s2")); @@ -179,12 +179,12 @@ public void test_document_replace() throws ArangoException { @Test public void test_document_update() throws ArangoException { - DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); + final DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); obj.S1 = "s1"; obj.S2 = "s2"; obj.X = 123; - DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, true, null); + final DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, null); assertThat(doc1.getStatusCode(), is(202)); assertThat(doc1.getDocumentKey(), is("mykey1")); @@ -192,11 +192,11 @@ public void test_document_update() throws ArangoException { obj.S1 = "s3"; obj.X = 456; obj.S2 = null; - DocumentEntity doc2 = driver.updateDocument("unit_test_arango_001", "mykey1", obj, false); + final DocumentEntity doc2 = driver.updateDocument("unit_test_arango_001", "mykey1", obj, false); assertThat(doc1.getStatusCode(), is(202)); assertThat(doc1.getDocumentKey(), is("mykey1")); - DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), + final DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), DocumentKeyTestEntity1.class); assertThat(doc3.getEntity().S1, is("mykey1")); assertThat(doc3.getEntity().S2, is(nullValue())); @@ -207,12 +207,12 @@ public void test_document_update() throws ArangoException { @Test public void test_document_delete() throws ArangoException { - DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); + final DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); obj.S1 = "s1"; obj.S2 = "s2"; obj.X = 123; - DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, true, null); + final DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, null); assertThat(doc1.getStatusCode(), is(202)); assertThat(doc1.getDocumentKey(), is("mykey1")); @@ -220,14 +220,14 @@ public void test_document_delete() throws ArangoException { obj.S1 = "s3"; obj.X = 456; obj.S2 = null; - DocumentEntity doc2 = driver.deleteDocument("unit_test_arango_001", "mykey1"); + final DocumentEntity doc2 = driver.deleteDocument("unit_test_arango_001", "mykey1"); assertThat(doc1.getStatusCode(), is(202)); assertThat(doc1.getDocumentKey(), is("mykey1")); try { driver.getDocument(doc2.getDocumentHandle(), DocumentKeyTestEntity1.class); fail(); - } catch (ArangoException e) { + } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); assertThat(e.getErrorNumber(), is(1202)); // assertThat(e.isNotFound(), is(true)); @@ -238,17 +238,17 @@ public void test_document_delete() throws ArangoException { @Test public void test_document_check() throws ArangoException { - DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); + final DocumentKeyTestEntity1 obj = new DocumentKeyTestEntity1(); obj.S1 = "s1"; obj.S2 = "s2"; obj.X = 123; - DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, true, null); + final DocumentEntity doc1 = driver.createDocument("unit_test_arango_001", "mykey1", obj, null); assertThat(doc1.getStatusCode(), is(202)); assertThat(doc1.getDocumentKey(), is("mykey1")); // check - long rev = driver.checkDocument(doc1.getDocumentHandle()); + final long rev = driver.checkDocument(doc1.getDocumentHandle()); assertThat(rev, is(doc1.getDocumentRevision())); } diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java index 515ff3263..be5a62879 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java @@ -95,7 +95,7 @@ public void test_create_normal() throws ArangoException { // 適当にドキュメントを作る final TestComplexEntity01 value = new TestComplexEntity01("user-" + 9999, "説明:" + 9999, 9999); - final DocumentEntity doc = driver.createDocument(collectionName, value, null, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, false); assertThat(doc.getDocumentKey(), is(notNullValue())); assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); @@ -109,7 +109,7 @@ public void test_create_normal_with_document_attributes() throws ArangoException // 適当にドキュメントを作る final TestComplexEntity03 value = new TestComplexEntity03("user-" + 9999, "説明:" + 9999, 9999); - final DocumentEntity doc = driver.createDocument(collectionName, value, null, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, false); assertThat(doc.getDocumentKey(), is(notNullValue())); assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); @@ -127,7 +127,7 @@ public void test_create_normal100() throws ArangoException { // 適当にドキュメントを作る for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user-" + i, "説明:" + i, i); - driver.createDocument(collectionName, value, null, false); + driver.createDocument(collectionName, value, false); } // 100個格納できていることを確認する @@ -140,7 +140,7 @@ public void test_create_sameobject() throws ArangoException { // 適当にドキュメントを作る for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user", "説明:", 10); - driver.createDocument(collectionName, value, null, true); + driver.createDocument(collectionName, value, true); } // 100個格納できていることを確認する assertThat(driver.getCollectionCount(collectionName).getCount(), is(100L)); @@ -155,7 +155,7 @@ public void test_create_sameobject() throws ArangoException { public void test_create_404() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); try { - driver.createDocument(collectionName404, value, false, true); + driver.createDocument(collectionName404, value, true); fail("no exception was thrown"); } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); @@ -179,7 +179,7 @@ public void test_create_404_insert() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // 存在しないコレクションに追加しようとする - final DocumentEntity res = driver.createDocument(collectionName404, value, true, true); + final DocumentEntity res = driver.createDocument(collectionName404, value, true); assertThat(res, is(notNullValue())); final CollectionEntity col3 = driver.getCollection(collectionName404); assertThat(col3, is(notNullValue())); @@ -196,7 +196,7 @@ public void test_replace() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // Create Document - final DocumentEntity doc = driver.createDocument(collectionName, value, true, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, false); assertThat(doc, is(notNullValue())); value.setUser(null); value.setDesc("UpdatedDescription"); @@ -236,7 +236,7 @@ public void test_replace_with_document_attributes() throws ArangoException { final TestComplexEntity03 value = new TestComplexEntity03("test-user", "test user", 22); // Create Document - final DocumentEntity doc = driver.createDocument(collectionName, value, true, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, false); assertThat(doc, is(notNullValue())); value.setUser(null); value.setDesc("UpdatedDescription"); @@ -306,7 +306,7 @@ public void test_partial_update() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // Create Document - final DocumentEntity doc = driver.createDocument(collectionName, value, true, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, false); assertThat(doc, is(notNullValue())); // PartialUpdate @@ -341,7 +341,7 @@ public void test_partial_update_with_document_attributes() throws ArangoExceptio final TestComplexEntity03 value = new TestComplexEntity03("test-user", "test user", 22); // Create Document - final DocumentEntity doc = driver.createDocument(collectionName, value, true, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, false); assertThat(doc, is(notNullValue())); // PartialUpdate @@ -384,11 +384,11 @@ public void test_partial_update_with_document_attributes() throws ArangoExceptio public void test_getDocuments() throws ArangoException { // create document final DocumentEntity doc1 = driver.createDocument(collectionName, - new TestComplexEntity01("test-user1", "test-user1-desc", 21), true, false); + new TestComplexEntity01("test-user1", "test-user1-desc", 21), false); final DocumentEntity doc2 = driver.createDocument(collectionName, - new TestComplexEntity01("test-user2", "test-user2-desc", 22), true, false); + new TestComplexEntity01("test-user2", "test-user2-desc", 22), false); final DocumentEntity doc3 = driver.createDocument(collectionName, - new TestComplexEntity01("test-user3", "test-user3-desc", 23), true, false); + new TestComplexEntity01("test-user3", "test-user3-desc", 23), false); assertThat(doc1, is(notNullValue())); assertThat(doc2, is(notNullValue())); assertThat(doc3, is(notNullValue())); @@ -408,11 +408,11 @@ public void test_getDocuments_handle() throws ArangoException { // create document final DocumentEntity doc1 = driver.createDocument(collectionName, - new TestComplexEntity01("test-user1", "test-user1-desc", 21), true, false); + new TestComplexEntity01("test-user1", "test-user1-desc", 21), false); final DocumentEntity doc2 = driver.createDocument(collectionName, - new TestComplexEntity01("test-user2", "test-user2-desc", 22), true, false); + new TestComplexEntity01("test-user2", "test-user2-desc", 22), false); final DocumentEntity doc3 = driver.createDocument(collectionName, - new TestComplexEntity01("test-user3", "test-user3-desc", 23), true, false); + new TestComplexEntity01("test-user3", "test-user3-desc", 23), false); assertThat(doc1, is(notNullValue())); assertThat(doc2, is(notNullValue())); assertThat(doc3, is(notNullValue())); @@ -430,7 +430,7 @@ public void test_getDocuments_handle() throws ArangoException { @Test public void test_get_document() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("user-" + 9999, "説明:" + 9999, 9999); - final DocumentEntity doc = driver.createDocument(collectionName, value, null, false); + final DocumentEntity doc = driver.createDocument(collectionName, value, false); assertThat(doc.getDocumentKey(), is(notNullValue())); assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); @@ -450,7 +450,7 @@ public void test_get_document() throws ArangoException { public void test_get_document_with_instance_creator() throws ArangoException { // save an instance of TestInterfaceImpl with null as "name" final DocumentEntity doc = driver.createDocument(collectionName, new TestInterfaceImpl(null), - null, false); + false); assertThat(doc.getDocumentKey(), is(notNullValue())); assertThat(doc.getDocumentHandle(), is(collectionName + "/" + doc.getDocumentKey())); @@ -570,7 +570,7 @@ public void test_get_as_map() throws ArangoException { public void test_checkDocument() throws ArangoException { final DocumentEntity doc = driver.createDocument(collectionName, - new TestComplexEntity02(1, 2, 3), null, null); + new TestComplexEntity02(1, 2, 3), null); final Long etag = driver.checkDocument(doc.getDocumentHandle()); assertThat(etag, is(doc.getDocumentRevision())); @@ -579,7 +579,7 @@ public void test_checkDocument() throws ArangoException { @Test public void test_check_document_doc_not_found() throws ArangoException { - driver.createDocument(collectionName, new TestComplexEntity02(1, 2, 3), null, null); + driver.createDocument(collectionName, new TestComplexEntity02(1, 2, 3), null); try { driver.checkDocument(collectionName, 1); @@ -593,7 +593,7 @@ public void test_check_document_doc_not_found() throws ArangoException { @Test public void test_check_document_doc_not_exists() throws ArangoException { - driver.createDocument(collectionName, new TestComplexEntity02(1, 2, 3), null, null); + driver.createDocument(collectionName, new TestComplexEntity02(1, 2, 3), null); final boolean b = driver.exists(collectionName, 1); @@ -643,7 +643,7 @@ public void test_BaseDocumentProperties() throws ArangoException { public void createRawDocument() throws ArangoException { final String jsonString = "{\"test\":123}"; logger.debug("jsonString before: " + jsonString); - final DocumentEntity entity = driver.createDocumentRaw(collectionName, jsonString, true, false); + final DocumentEntity entity = driver.createDocumentRaw(collectionName, jsonString, false); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); Assert.assertNotNull(entity.getDocumentKey()); @@ -662,7 +662,7 @@ public void createRawDocumentWithKey() throws ArangoException { final String key = "key1"; final String jsonString = "{\"_key\":\"" + key + "\",\"test\":123}"; logger.debug("jsonString before: " + jsonString); - final DocumentEntity entity = driver.createDocumentRaw(collectionName, jsonString, true, false); + final DocumentEntity entity = driver.createDocumentRaw(collectionName, jsonString, false); Assert.assertNotNull(entity); Assert.assertNotNull(entity.getDocumentHandle()); Assert.assertNotNull(entity.getDocumentKey()); @@ -683,7 +683,7 @@ public void createRawDocumentWithKey() throws ArangoException { public void createRawDocumentFails() throws ArangoException { try { final String jsonString = "no JSON"; - driver.createDocumentRaw(collectionName, jsonString, true, false); + driver.createDocumentRaw(collectionName, jsonString, false); fail(); } catch (final ArangoException e) { Assert.assertEquals(ErrorNums.ERROR_HTTP_BAD_PARAMETER, e.getCode()); diff --git a/src/test/java/com/arangodb/ArangoDriverIndexTest.java b/src/test/java/com/arangodb/ArangoDriverIndexTest.java index c2bd4636c..0d813a429 100644 --- a/src/test/java/com/arangodb/ArangoDriverIndexTest.java +++ b/src/test/java/com/arangodb/ArangoDriverIndexTest.java @@ -230,7 +230,7 @@ public void test_create_hash_index_with_document() throws ArangoException { for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + i, "", i); - assertThat(driver.createDocument(collectionName, value, false, false), is(notNullValue())); + assertThat(driver.createDocument(collectionName, value, false), is(notNullValue())); } final IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "name", "age"); @@ -252,7 +252,7 @@ public void test_create_fulltext_index() throws ArangoException { for (int i = 0; i < 100; i++) { final String desc = i % 2 == 0 ? "寿司" : "天ぷら"; final TestComplexEntity01 value = new TestComplexEntity01("user_" + i, desc, i); - assertThat(driver.createDocument(collectionName, value, false, false), is(notNullValue())); + assertThat(driver.createDocument(collectionName, value, false), is(notNullValue())); } // create fulltext index @@ -326,9 +326,9 @@ public void test_create_hash_index_dup_unique() throws ArangoException { final IndexEntity entity = driver.createIndex(collectionName, IndexType.HASH, true, "user", "age"); - assertThat(driver.createDocument(collectionName, new TestComplexEntity01("寿司天ぷら", "", 18), false, false), + assertThat(driver.createDocument(collectionName, new TestComplexEntity01("寿司天ぷら", "", 18), false), is(notNullValue())); - assertThat(driver.createDocument(collectionName, new TestComplexEntity01("寿司天ぷら", "", 18), false, false), + assertThat(driver.createDocument(collectionName, new TestComplexEntity01("寿司天ぷら", "", 18), false), is(notNullValue())); assertThat(entity, is(notNullValue())); diff --git a/src/test/java/com/arangodb/ArangoDriverReplicationTest.java b/src/test/java/com/arangodb/ArangoDriverReplicationTest.java index c622defc7..3c0401a70 100644 --- a/src/test/java/com/arangodb/ArangoDriverReplicationTest.java +++ b/src/test/java/com/arangodb/ArangoDriverReplicationTest.java @@ -123,7 +123,7 @@ public void test_get_dump() throws ArangoException { // create 10 document for (int i = 0; i < 10; i++) { final TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); - driver.createDocument(collectionName, entity, true, null); + driver.createDocument(collectionName, entity, null); } // truncate try { @@ -132,7 +132,7 @@ public void test_get_dump() throws ArangoException { } // create 1 document final TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); - driver.createDocument(collectionName, entity, true, null); + driver.createDocument(collectionName, entity, null); final AtomicInteger upsertCount = new AtomicInteger(0); final AtomicInteger deleteCount = new AtomicInteger(0); @@ -200,7 +200,7 @@ public void test_get_dump_noticks() throws ArangoException { // create 10 document for (int i = 0; i < 10; i++) { final TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); - driver.createDocument(collectionName, entity, true, null); + driver.createDocument(collectionName, entity, null); } // truncate try { @@ -209,7 +209,7 @@ public void test_get_dump_noticks() throws ArangoException { } // create 1 document final TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); - driver.createDocument(collectionName, entity, true, null); + driver.createDocument(collectionName, entity, null); final AtomicInteger upsertCount = new AtomicInteger(0); final AtomicInteger deleteCount = new AtomicInteger(0); @@ -265,7 +265,7 @@ public void test_get_dump_handler_control_1() throws ArangoException { // create 10 document for (int i = 0; i < 10; i++) { final TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); - driver.createDocument(collectionName, entity, true, null); + driver.createDocument(collectionName, entity, null); } // truncate try { @@ -274,7 +274,7 @@ public void test_get_dump_handler_control_1() throws ArangoException { } // create 1 document final TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); - driver.createDocument(collectionName, entity, true, null); + driver.createDocument(collectionName, entity, null); final AtomicBoolean headCall = new AtomicBoolean(false); driver.getReplicationDump(collectionName, null, null, null, null, TestComplexEntity01.class, @@ -313,7 +313,7 @@ public void test_get_dump_handler_control_2() throws ArangoException { // create 10 document for (int i = 0; i < 10; i++) { final TestComplexEntity01 entity = new TestComplexEntity01("user-" + i, "desc-" + i, 20 + i); - driver.createDocument(collectionName, entity, true, null); + driver.createDocument(collectionName, entity, null); } // truncate try { @@ -322,7 +322,7 @@ public void test_get_dump_handler_control_2() throws ArangoException { } // create 1 document final TestComplexEntity01 entity = new TestComplexEntity01("user-99", "desc-99", 99); - driver.createDocument(collectionName, entity, true, null); + driver.createDocument(collectionName, entity, null); final AtomicInteger handleCount = new AtomicInteger(0); final AtomicBoolean headCall = new AtomicBoolean(false); diff --git a/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java b/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java index a6fb4d694..07b238cd7 100644 --- a/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java +++ b/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java @@ -116,10 +116,10 @@ public void test_scienario() throws ArangoException, InterruptedException { // [Master] add document masterDriver.createCollection(collectionName1); final DocumentEntity> doc1 = masterDriver.createDocument(collectionName1, - new MapBuilder().put("my-key1", "100").get(), false, false); + new MapBuilder().put("my-key1", "100").get(), false); final DocumentEntity> doc2 = masterDriver.createDocument(collectionName1, - new MapBuilder().put("my-key2", "255").get(), false, false); - masterDriver.createDocument(collectionName1, new MapBuilder().put("my-key3", 1234567).get(), false, false); + new MapBuilder().put("my-key2", "255").get(), false); + masterDriver.createDocument(collectionName1, new MapBuilder().put("my-key3", 1234567).get(), false); // [Master] logger property masterDriver.setReplicationLoggerConfig(true, null, 1048576L, 0L); @@ -148,8 +148,7 @@ public void test_scienario() throws ArangoException, InterruptedException { // [Master] create 10 document for (int i = 0; i < 10; i++) { - masterDriver.createDocument(collectionName1, new MapBuilder().put("my-key" + i, 1234567).get(), false, - false); + masterDriver.createDocument(collectionName1, new MapBuilder().put("my-key" + i, 1234567).get(), false); } // [Master] import 290 document diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java index 14115bb71..4f4f60988 100644 --- a/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java +++ b/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java @@ -52,7 +52,7 @@ public void setup() throws ArangoException, IOException { // テストデータを作る final List stations = TestUtils.readStations(); for (final Station station : stations) { - driver.createDocument(collectionName, station, null, null); + driver.createDocument(collectionName, station, null); } } diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java index 342ac596b..40910b0f7 100644 --- a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java +++ b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java @@ -71,7 +71,7 @@ public void setup() throws ArangoException { // add some test data for (int i = 0; i < 100; i++) { final TestComplexEntity01 value = new TestComplexEntity01("user_" + (i % 10), "desc" + (i % 10), i); - driver.createDocument(COLLECTION_NAME, value, null, null); + driver.createDocument(COLLECTION_NAME, value, null); } // delete second test collection @@ -393,10 +393,9 @@ public void test_fulltext() throws ArangoException { // create fulltext index driver.createFulltextIndex(COLLECTION_NAME, 2, "desc"); - driver.createDocument(COLLECTION_NAME, new TestComplexEntity01("xxx1", "this text contains a word", 10), null, - null); + driver.createDocument(COLLECTION_NAME, new TestComplexEntity01("xxx1", "this text contains a word", 10), null); driver.createDocument(COLLECTION_NAME, new TestComplexEntity01("xxx2", "this text also contains a word", 10), - null, null); + null); final DocumentCursor documentCursor = driver.executeSimpleFulltextWithDocuments( COLLECTION_NAME, "desc", "word", 0, 0, null, TestComplexEntity01.class); @@ -421,10 +420,9 @@ public void test_fulltext_with_doc() throws ArangoException { // create fulltext index driver.createFulltextIndex(COLLECTION_NAME, 2, "desc"); - driver.createDocument(COLLECTION_NAME, new TestComplexEntity01("xxx1", "this text contains a word", 10), null, - null); + driver.createDocument(COLLECTION_NAME, new TestComplexEntity01("xxx1", "this text contains a word", 10), null); driver.createDocument(COLLECTION_NAME, new TestComplexEntity01("xxx2", "this text also contains a word", 10), - null, null); + null); final DocumentCursor documentCursor = driver.executeSimpleFulltextWithDocuments( COLLECTION_NAME, "desc", "word", 0, 0, null, TestComplexEntity01.class); diff --git a/src/test/java/com/arangodb/ArangoDriverThreadSafeTest.java b/src/test/java/com/arangodb/ArangoDriverThreadSafeTest.java index dc22cd0ae..8f0a90bc9 100644 --- a/src/test/java/com/arangodb/ArangoDriverThreadSafeTest.java +++ b/src/test/java/com/arangodb/ArangoDriverThreadSafeTest.java @@ -44,7 +44,7 @@ public class ArangoDriverThreadSafeTest { public void story01() throws ArangoException, InterruptedException { // hostやport, connection-poolなどの設定 - ArangoConfigure configure = new ArangoConfigure(); + final ArangoConfigure configure = new ArangoConfigure(); configure.init(); final ArangoDriver driver = new ArangoDriver(configure); @@ -52,9 +52,9 @@ public void story01() throws ArangoException, InterruptedException { final String collectionName = "unit_test_story_01"; try { driver.deleteCollection(collectionName); - } catch (ArangoException e) { + } catch (final ArangoException e) { } - CollectionEntity collection = driver.createCollection(collectionName); + final CollectionEntity collection = driver.createCollection(collectionName); logger.debug("collectionId={}", collection.getId()); // コレクションの中身を削除する @@ -62,24 +62,25 @@ public void story01() throws ArangoException, InterruptedException { // スレッドセーフです try { - ExecutorService svc = Executors.newFixedThreadPool(4); + final ExecutorService svc = Executors.newFixedThreadPool(4); for (int t = 0; t < 4; t++) { final int threadNo = t; svc.execute(new Runnable() { + @Override public void run() { try { for (int i = 0; i < 100; i++) { - TestComplexEntity01 value = new TestComplexEntity01("user" + threadNo + "_" + i, + final TestComplexEntity01 value = new TestComplexEntity01("user" + threadNo + "_" + i, "テスト☆ユーザー:" + threadNo + "_" + i, (int) (100d * Math.random())); // ドキュメントを作る - DocumentEntity ret1 = driver.createDocument(collectionName, value, - null, null); + final DocumentEntity ret1 = driver.createDocument(collectionName, + value, null); - String _id = ret1.getDocumentHandle(); // ドキュメントのID(_id) - long _rev = ret1.getDocumentRevision(); // ドキュメントのリビジョン(_rev) + final String _id = ret1.getDocumentHandle(); // ドキュメントのID(_id) + final long _rev = ret1.getDocumentRevision(); // ドキュメントのリビジョン(_rev) // ドキュメントを取得する - DocumentEntity ret2 = driver.getDocument(_id, + final DocumentEntity ret2 = driver.getDocument(_id, TestComplexEntity01.class); // 取得したドキュメントの確認 assertThat(ret2.getDocumentHandle(), is(_id)); @@ -88,13 +89,13 @@ public void run() { assertThat(ret2.getEntity().getAge(), is(value.getAge())); // ドキュメントを削除する - DocumentEntity ret3 = driver.deleteDocument(_id, null, Policy.LAST); + final DocumentEntity ret3 = driver.deleteDocument(_id, null, Policy.LAST); assertThat(ret3.getDocumentHandle(), is(_id)); assertThat(ret3.getDocumentRevision(), is(_rev)); } - } catch (ArangoException e) { + } catch (final ArangoException e) { logger.error(e.getMessage(), e); fail("だめぽ"); } diff --git a/src/test/java/com/arangodb/NegativeTest.java b/src/test/java/com/arangodb/NegativeTest.java index da53b4844..6b102dbb7 100644 --- a/src/test/java/com/arangodb/NegativeTest.java +++ b/src/test/java/com/arangodb/NegativeTest.java @@ -91,7 +91,7 @@ public void test_issue_35_and_41() throws Exception { value.setName("A\"A'@:///A"); // String value = "AAA"; - final DocumentEntity doc = driver.createDocument("unit_test_issue35", value, true, true); + final DocumentEntity doc = driver.createDocument("unit_test_issue35", value, true); final String documentHandle = doc.getDocumentHandle(); driver.getDocument(documentHandle, TestComplex.class); diff --git a/src/test/java/com/arangodb/PrimitiveDocumentTest.java b/src/test/java/com/arangodb/PrimitiveDocumentTest.java index f986503a0..c42d254fb 100644 --- a/src/test/java/com/arangodb/PrimitiveDocumentTest.java +++ b/src/test/java/com/arangodb/PrimitiveDocumentTest.java @@ -90,7 +90,7 @@ public void test_string_multibyte2() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("寿司", "", 10); logger.debug(new Gson().toJson(value)); - final DocumentEntity res = driver.createDocument("unit_test_primitive", value, true, true); + final DocumentEntity res = driver.createDocument("unit_test_primitive", value, true); final String documentHandle = res.getDocumentHandle(); final DocumentEntity doc = driver.getDocument(documentHandle, TestComplexEntity01.class); @@ -142,7 +142,7 @@ public void test_boolean_true() throws ArangoException { final boolean value = true; try { - driver.createDocument("unit_test_primitive", value, true, true); + driver.createDocument("unit_test_primitive", value, true); fail(); } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); @@ -155,7 +155,7 @@ public void test_boolean_false() throws ArangoException { final boolean value = false; try { - driver.createDocument("unit_test_primitive", value, true, true); + driver.createDocument("unit_test_primitive", value, true); fail(); } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); @@ -169,7 +169,7 @@ public void test_number_int() throws ArangoException { final int value = 1000000; try { - driver.createDocument("unit_test_primitive", value, true, true); + driver.createDocument("unit_test_primitive", value, true); fail(); } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); @@ -183,7 +183,7 @@ public void test_number_long() throws ArangoException { final long value = Long.MAX_VALUE; try { - driver.createDocument("unit_test_primitive", value, true, true); + driver.createDocument("unit_test_primitive", value, true); fail(); } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); @@ -198,7 +198,7 @@ public void test_number_double() throws ArangoException { final double value = Double.MAX_VALUE; try { - driver.createDocument("unit_test_primitive", value, true, true); + driver.createDocument("unit_test_primitive", value, true); fail(); } catch (final ArangoException e) { assertThat(e.getErrorNumber(), is(ErrorNums.ERROR_ARANGO_DOCUMENT_TYPE_INVALID)); diff --git a/src/test/java/com/arangodb/bench/SingleDocumentBenchmarkImporter.java b/src/test/java/com/arangodb/bench/SingleDocumentBenchmarkImporter.java index 929e04718..43d7409c7 100644 --- a/src/test/java/com/arangodb/bench/SingleDocumentBenchmarkImporter.java +++ b/src/test/java/com/arangodb/bench/SingleDocumentBenchmarkImporter.java @@ -12,14 +12,14 @@ */ public class SingleDocumentBenchmarkImporter extends AbstractBenchmarkImporter { - public SingleDocumentBenchmarkImporter(ArangoDriver driver, String collectionName) { + public SingleDocumentBenchmarkImporter(final ArangoDriver driver, final String collectionName) { super(driver, collectionName); } @Override - protected void execute(List values) throws Exception { - for (Object value : values) { - driver.createDocument(collectionName, value, true, false); + protected void execute(final List values) throws Exception { + for (final Object value : values) { + driver.createDocument(collectionName, value, false); } } diff --git a/src/test/java/com/arangodb/example/TransactionExample.java b/src/test/java/com/arangodb/example/TransactionExample.java index 6b7a04e74..8aa64b2a4 100644 --- a/src/test/java/com/arangodb/example/TransactionExample.java +++ b/src/test/java/com/arangodb/example/TransactionExample.java @@ -73,8 +73,8 @@ public void transactionExample() throws ArangoException { final myCounter entity = new myCounter(); entity.setCount(0L); - DocumentEntity documentEntity1 = driver.createDocument(COLLECTION_NAME, entity, true, null); - DocumentEntity documentEntity2 = driver.createDocument(COLLECTION_NAME, entity, true, null); + DocumentEntity documentEntity1 = driver.createDocument(COLLECTION_NAME, entity, null); + DocumentEntity documentEntity2 = driver.createDocument(COLLECTION_NAME, entity, null); // start threads without transaction for (int i = 0; i < NUMBER_THREADS; i++) { diff --git a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java index e7f5bfcb2..74768d826 100644 --- a/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java +++ b/src/test/java/com/arangodb/example/document/AqlQueryWithSpecialReturnTypesExample.java @@ -139,7 +139,7 @@ private void createExamples() throws ArangoException { person.setGender((i % 2) == 0 ? MALE : FEMALE); person.setAge((int) (Math.random() * 100) + 10); - driver.createDocument(COLLECTION_NAME, person, true, null); + driver.createDocument(COLLECTION_NAME, person, null); } } diff --git a/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java b/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java index 8575ba00b..97d3d8d62 100644 --- a/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/document/DocumentPersonAqlQueryExample.java @@ -124,7 +124,7 @@ private void createExamples() throws ArangoException { person.setGender((i % 2) == 0 ? MALE : FEMALE); person.setAge((int) (Math.random() * 100) + 10); - driver.createDocument(COLLECTION_NAME, person, true, null); + driver.createDocument(COLLECTION_NAME, person, null); } } diff --git a/src/test/java/com/arangodb/example/document/RawDocumentExample.java b/src/test/java/com/arangodb/example/document/RawDocumentExample.java index 79daf597f..c64aa881a 100644 --- a/src/test/java/com/arangodb/example/document/RawDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/RawDocumentExample.java @@ -68,7 +68,7 @@ public void ReadDocuments() { String x = "{\"test\":123}"; try { - final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, x, true, false); + final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, x, false); // the DocumentEntity contains the key, document handle and revision System.out.println("Key: " + entity.getDocumentKey()); System.out.println("Id: " + entity.getDocumentHandle()); @@ -95,7 +95,7 @@ public void ReadDocuments() { x = "{\"_key\":\"key2\",\"test\":123}"; try { - final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, x, true, false); + final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, x, false); // the DocumentEntity contains the key, document handle and revision System.out.println("Key: " + entity.getDocumentKey()); System.out.println("Id: " + entity.getDocumentHandle()); @@ -168,7 +168,7 @@ public void ReadDocuments() { System.out.println("Orig XML value: " + string); final JSONObject jsonObject = JSONML.toJSONObject(string); try { - final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, jsonObject.toString(), true, + final DocumentEntity entity = driver.createDocumentRaw(COLLECTION_NAME, jsonObject.toString(), false); // the DocumentEntity contains the key, document handle and revision System.out.println("Key: " + entity.getDocumentKey()); diff --git a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java index bed79eb83..39faa87b4 100644 --- a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryExample.java @@ -148,7 +148,7 @@ private void createExamples() throws ArangoException { person.setGender((i % 2) == 0 ? MALE : FEMALE); person.setAge((int) (Math.random() * 100) + 10); - driver.createDocument(COLLECTION_NAME, person, true, null); + driver.createDocument(COLLECTION_NAME, person, null); } } diff --git a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java index 3bf19bf72..9029cfd2b 100644 --- a/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java +++ b/src/test/java/com/arangodb/example/document/SimplePersonAqlQueryWithLimitExample.java @@ -132,7 +132,7 @@ private void createExamples() throws ArangoException { person.setGender((i % 2) == 0 ? MALE : FEMALE); person.setAge((int) (Math.random() * 100) + 10); - driver.createDocument(COLLECTION_NAME, person, true, null); + driver.createDocument(COLLECTION_NAME, person, null); } } From 4684e0bf91646870d38f4ae98d0e64eaa11301f6 Mon Sep 17 00:00:00 2001 From: Mark Vollmary Date: Tue, 24 May 2016 16:08:19 +0200 Subject: [PATCH 14/56] revision id handling via "If-Match" in HTTP header, not via "rev" and "policy" params --- src/main/java/com/arangodb/ArangoDriver.java | 235 ++++++------------ .../com/arangodb/InternalDocumentDriver.java | 8 +- src/main/java/com/arangodb/entity/Policy.java | 35 --- .../impl/InternalDocumentDriverImpl.java | 51 ++-- .../arangodb/ArangoDriverCollectionTest.java | 2 +- .../arangodb/ArangoDriverDocumentTest.java | 16 +- .../ArangoDriverReplicationTestScenario1.java | 4 +- .../arangodb/ArangoDriverThreadSafeTest.java | 3 +- .../example/document/RawDocumentExample.java | 6 +- .../ReplaceAndUpdateDocumentExample.java | 5 +- 10 files changed, 108 insertions(+), 257 deletions(-) delete mode 100644 src/main/java/com/arangodb/entity/Policy.java diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 119c1fb17..f0c446254 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -49,7 +49,6 @@ import com.arangodb.entity.IndexesEntity; import com.arangodb.entity.JobsEntity; import com.arangodb.entity.PlainEdgeEntity; -import com.arangodb.entity.Policy; import com.arangodb.entity.QueriesResultEntity; import com.arangodb.entity.QueryCachePropertiesEntity; import com.arangodb.entity.QueryTrackingPropertiesEntity; @@ -1007,7 +1006,7 @@ public DocumentEntity createDocument( */ public DocumentEntity replaceDocument(final long collectionId, final long documentId, final Object value) throws ArangoException { - return replaceDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null, null); + return replaceDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null); } /** @@ -1024,8 +1023,7 @@ public DocumentEntity replaceDocument(final long collectionId, final long doc */ public DocumentEntity replaceDocument(final String collectionName, final long documentId, final T value) throws ArangoException { - return replaceDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null, - null); + return replaceDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null); } /** @@ -1042,7 +1040,7 @@ public DocumentEntity replaceDocument(final String collectionName, final */ public DocumentEntity replaceDocument(final long collectionId, final String documentKey, final T value) throws ArangoException { - return replaceDocument(createDocumentHandle(collectionId, documentKey), value, null, null, null); + return replaceDocument(createDocumentHandle(collectionId, documentKey), value, null, null); } /** @@ -1059,7 +1057,7 @@ public DocumentEntity replaceDocument(final long collectionId, final Stri */ public DocumentEntity replaceDocument(final String collectionName, final String documentKey, final T value) throws ArangoException { - return replaceDocument(createDocumentHandle(collectionName, documentKey), value, null, null, null); + return replaceDocument(createDocumentHandle(collectionName, documentKey), value, null, null); } /** @@ -1074,15 +1072,14 @@ public DocumentEntity replaceDocument(final String collectionName, final * @throws ArangoException */ public DocumentEntity replaceDocument(final String documentHandle, final T value) throws ArangoException { - return documentDriver.replaceDocument(getDefaultDatabase(), documentHandle, value, null, null, null); + return documentDriver.replaceDocument(getDefaultDatabase(), documentHandle, value, null, null); } /** * This method replaces the content of the document defined by documentId. * This method offers a parameter rev (revision). If the revision of the - * document on the server does not match the given revision the policy - * parameter is used. If it is set to *last* the operation is performed - * anyway. if it is set to *error* an error is thrown. + * document on the server does not match the given revision an error is + * thrown. * * @param collectionId * The collection's id. @@ -1092,8 +1089,6 @@ public DocumentEntity replaceDocument(final String documentHandle, final * An object containing the new attributes of the document. * @param rev * the desired revision. - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1105,18 +1100,15 @@ public DocumentEntity replaceDocument( final long documentId, final T value, final Long rev, - final Policy policy, final Boolean waitForSync) throws ArangoException { - return replaceDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, rev, policy, - waitForSync); + return replaceDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, rev, waitForSync); } /** * This method replaces the content of the document defined by documentId. * This method offers a parameter rev (revision). If the revision of the - * document on the server does not match the given revision the policy - * parameter is used. If it is set to *last* the operation is performed - * anyway. if it is set to *error* an error is thrown. + * document on the server does not match the given revision an error is + * thrown. * * @param collectionName * The collection's name. @@ -1126,8 +1118,6 @@ public DocumentEntity replaceDocument( * An object containing the new attributes of the document. * @param rev * the desired revision. - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1139,18 +1129,16 @@ public DocumentEntity replaceDocument( final long documentId, final Object value, final Long rev, - final Policy policy, final Boolean waitForSync) throws ArangoException { - return replaceDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, rev, policy, + return replaceDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, rev, waitForSync); } /** * This method replaces the content of the document defined by documentKey. * This method offers a parameter rev (revision). If the revision of the - * document on the server does not match the given revision the policy - * parameter is used. If it is set to *last* the operation is performed - * anyway. if it is set to *error* an error is thrown. + * document on the server does not match the given revision an error is + * thrown. * * @param collectionId * The collection's id. @@ -1160,8 +1148,6 @@ public DocumentEntity replaceDocument( * An object containing the new attributes of the document. * @param rev * the desired revision. - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1173,17 +1159,15 @@ public DocumentEntity replaceDocument( final String documentKey, final Object value, final Long rev, - final Policy policy, final Boolean waitForSync) throws ArangoException { - return replaceDocument(createDocumentHandle(collectionId, documentKey), value, rev, policy, waitForSync); + return replaceDocument(createDocumentHandle(collectionId, documentKey), value, rev, waitForSync); } /** * This method replaces the content of the document defined by documentKey. * This method offers a parameter rev (revision). If the revision of the - * document on the server does not match the given revision the policy - * parameter is used. If it is set to *last* the operation is performed - * anyway. if it is set to *error* an error is thrown. + * document on the server does not match the given revision an error is + * thrown. * * @param collectionName * The collection's name. @@ -1193,8 +1177,6 @@ public DocumentEntity replaceDocument( * An object containing the new attributes of the document. * @param rev * the desired revision. - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1206,17 +1188,15 @@ public DocumentEntity replaceDocument( final String documentKey, final Object value, final Long rev, - final Policy policy, final Boolean waitForSync) throws ArangoException { - return replaceDocument(createDocumentHandle(collectionName, documentKey), value, rev, policy, waitForSync); + return replaceDocument(createDocumentHandle(collectionName, documentKey), value, rev, waitForSync); } /** * This method replaces the content of the document defined by * documentHandle. This method offers a parameter rev (revision). If the * revision of the document on the server does not match the given revision - * the policy parameter is used. If it is set to *last* the operation is - * performed anyway. if it is set to *error* an error is thrown. + * an error is thrown. * * @param documentHandle * The document's handle. @@ -1224,8 +1204,6 @@ public DocumentEntity replaceDocument( * An object containing the new attributes of the document. * @param rev * the desired revision. - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1236,9 +1214,8 @@ public DocumentEntity replaceDocument( final String documentHandle, final T value, final Long rev, - final Policy policy, final Boolean waitForSync) throws ArangoException { - return documentDriver.replaceDocument(getDefaultDatabase(), documentHandle, value, rev, policy, waitForSync); + return documentDriver.replaceDocument(getDefaultDatabase(), documentHandle, value, rev, waitForSync); } /** @@ -1255,8 +1232,7 @@ public DocumentEntity replaceDocument( */ public DocumentEntity updateDocument(final long collectionId, final long documentId, final Object value) throws ArangoException { - return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null, null, - null); + return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null, null); } /** @@ -1273,7 +1249,7 @@ public DocumentEntity updateDocument(final long collectionId, final long docu */ public DocumentEntity updateDocument(final String collectionName, final long documentId, final Object value) throws ArangoException { - return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null, null, + return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null, null); } @@ -1291,7 +1267,7 @@ public DocumentEntity updateDocument(final String collectionName, final long */ public DocumentEntity updateDocument(final long collectionId, final String documentKey, final Object value) throws ArangoException { - return updateDocument(createDocumentHandle(collectionId, documentKey), value, null, null, null, null); + return updateDocument(createDocumentHandle(collectionId, documentKey), value, null, null, null); } /** @@ -1308,7 +1284,7 @@ public DocumentEntity updateDocument(final long collectionId, final String do */ public DocumentEntity updateDocument(final String collectionName, final String documentKey, final Object value) throws ArangoException { - return updateDocument(createDocumentHandle(collectionName, documentKey), value, null, null, null, null); + return updateDocument(createDocumentHandle(collectionName, documentKey), value, null, null, null); } /** @@ -1322,7 +1298,7 @@ public DocumentEntity updateDocument(final String collectionName, final Strin * @throws ArangoException */ public DocumentEntity updateDocument(final String documentHandle, final T value) throws ArangoException { - return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, null, null, null, null); + return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, null, null, null); } /** @@ -1344,7 +1320,7 @@ public DocumentEntity updateDocument( final long documentId, final Object value, final Boolean keepNull) throws ArangoException { - return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null, null, + return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, null, null, keepNull); } @@ -1367,7 +1343,7 @@ public DocumentEntity updateDocument( final long documentId, final Object value, final Boolean keepNull) throws ArangoException { - return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null, null, + return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, null, null, keepNull); } @@ -1390,7 +1366,7 @@ public DocumentEntity updateDocument( final String documentKey, final Object value, final Boolean keepNull) throws ArangoException { - return updateDocument(createDocumentHandle(collectionId, documentKey), value, null, null, null, keepNull); + return updateDocument(createDocumentHandle(collectionId, documentKey), value, null, null, keepNull); } /** @@ -1412,7 +1388,7 @@ public DocumentEntity updateDocument( final String documentKey, final Object value, final Boolean keepNull) throws ArangoException { - return updateDocument(createDocumentHandle(collectionName, documentKey), value, null, null, null, keepNull); + return updateDocument(createDocumentHandle(collectionName, documentKey), value, null, null, keepNull); } /** @@ -1429,15 +1405,13 @@ public DocumentEntity updateDocument( */ public DocumentEntity updateDocument(final String documentHandle, final T value, final Boolean keepNull) throws ArangoException { - return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, null, null, null, keepNull); + return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, null, null, keepNull); } /** * This method updates a document defined by documentId. This method offers * a parameter rev (revision). If the revision of the document on the server - * does not match the given revision the policy parameter is used. If it is - * set to *last* the operation is performed anyway. if it is set to *error* - * an error is thrown. + * does not match the given revision an error is thrown. * * @param collectionId * The collection id. @@ -1447,8 +1421,6 @@ public DocumentEntity updateDocument(final String documentHandle, final T * An object containing the documents attributes * @param rev * The desired revision - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1462,19 +1434,16 @@ public DocumentEntity updateDocument( final long documentId, final Object value, final Long rev, - final Policy policy, final Boolean waitForSync, final Boolean keepNull) throws ArangoException { - return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, rev, policy, - waitForSync, keepNull); + return updateDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), value, rev, waitForSync, + keepNull); } /** * This method updates a document defined by documentId. This method offers * a parameter rev (revision). If the revision of the document on the server - * does not match the given revision the policy parameter is used. If it is - * set to *last* the operation is performed anyway. if it is set to *error* - * an error is thrown. + * does not match the given revision an error is thrown. * * @param collectionName * The collection name. @@ -1484,8 +1453,6 @@ public DocumentEntity updateDocument( * An object containing the documents attributes * @param rev * The desired revision - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1499,19 +1466,16 @@ public DocumentEntity updateDocument( final long documentId, final Object value, final Long rev, - final Policy policy, final Boolean waitForSync, final Boolean keepNull) throws ArangoException { - return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, rev, policy, - waitForSync, keepNull); + return updateDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), value, rev, waitForSync, + keepNull); } /** * This method updates a document defined by documentKey. This method offers * a parameter rev (revision). If the revision of the document on the server - * does not match the given revision the policy parameter is used. If it is - * set to *last* the operation is performed anyway. if it is set to *error* - * an error is thrown. + * does not match the given revision an error is thrown. * * @param collectionId * The collection id. @@ -1521,8 +1485,6 @@ public DocumentEntity updateDocument( * An object containing the documents attributes * @param rev * The desired revision - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1536,19 +1498,15 @@ public DocumentEntity updateDocument( final String documentKey, final Object value, final Long rev, - final Policy policy, final Boolean waitForSync, final Boolean keepNull) throws ArangoException { - return updateDocument(createDocumentHandle(collectionId, documentKey), value, rev, policy, waitForSync, - keepNull); + return updateDocument(createDocumentHandle(collectionId, documentKey), value, rev, waitForSync, keepNull); } /** * This method updates a document defined by documentKey. This method offers * a parameter rev (revision). If the revision of the document on the server - * does not match the given revision the policy parameter is used. If it is - * set to *last* the operation is performed anyway. if it is set to *error* - * an error is thrown. + * does not match the given revision an error is thrown. * * @param collectionName * The collection name. @@ -1558,8 +1516,6 @@ public DocumentEntity updateDocument( * An object containing the documents attributes * @param rev * The desired revision - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1573,19 +1529,15 @@ public DocumentEntity updateDocument( final String documentKey, final Object value, final Long rev, - final Policy policy, final Boolean waitForSync, final Boolean keepNull) throws ArangoException { - return updateDocument(createDocumentHandle(collectionName, documentKey), value, rev, policy, waitForSync, - keepNull); + return updateDocument(createDocumentHandle(collectionName, documentKey), value, rev, waitForSync, keepNull); } /** * This method updates a document defined by documentHandle. This method * offers a parameter rev (revision). If the revision of the document on the - * server does not match the given revision the policy parameter is used. If - * it is set to *last* the operation is performed anyway. if it is set to - * *error* an error is thrown. + * server does not match the given revision an error is thrown. * * @param documentHandle * The document handle. @@ -1593,8 +1545,6 @@ public DocumentEntity updateDocument( * An object containing the documents attributes * @param rev * The desired revision - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -1607,11 +1557,9 @@ public DocumentEntity updateDocument( final String documentHandle, final T value, final Long rev, - final Policy policy, final Boolean waitForSync, final Boolean keepNull) throws ArangoException { - return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, rev, policy, waitForSync, - keepNull); + return documentDriver.updateDocument(getDefaultDatabase(), documentHandle, value, rev, waitForSync, keepNull); } /** @@ -1913,7 +1861,7 @@ public DocumentEntity getDocument( * @throws ArangoException */ public DocumentEntity deleteDocument(final long collectionId, final long documentId) throws ArangoException { - return deleteDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), null, null); + return deleteDocument(createDocumentHandle(collectionId, String.valueOf(documentId))); } /** @@ -1927,7 +1875,7 @@ public DocumentEntity deleteDocument(final long collectionId, final long docu * @throws ArangoException */ public DocumentEntity deleteDocument(final String collectionName, final long documentId) throws ArangoException { - return deleteDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), null, null); + return deleteDocument(createDocumentHandle(collectionName, String.valueOf(documentId))); } /** @@ -1941,7 +1889,7 @@ public DocumentEntity deleteDocument(final String collectionName, final long * @throws ArangoException */ public DocumentEntity deleteDocument(final long collectionId, final String documentKey) throws ArangoException { - return deleteDocument(createDocumentHandle(collectionId, documentKey), null, null); + return deleteDocument(createDocumentHandle(collectionId, documentKey)); } /** @@ -1956,7 +1904,7 @@ public DocumentEntity deleteDocument(final long collectionId, final String do */ public DocumentEntity deleteDocument(final String collectionName, final String documentKey) throws ArangoException { - return deleteDocument(createDocumentHandle(collectionName, documentKey), null, null); + return deleteDocument(createDocumentHandle(collectionName, documentKey)); } /** @@ -1968,15 +1916,13 @@ public DocumentEntity deleteDocument(final String collectionName, final Strin * @throws ArangoException */ public DocumentEntity deleteDocument(final String documentHandle) throws ArangoException { - return documentDriver.deleteDocument(getDefaultDatabase(), documentHandle, null, null); + return documentDriver.deleteDocument(getDefaultDatabase(), documentHandle, null); } /** * Deletes a document from the database. This method offers a parameter rev * (revision). If the revision of the document on the server does not match - * the given revision the policy parameter is used. If it is set to *last* - * the operation is performed anyway. if it is set to *error* an error is - * thrown. + * the given revision an error is thrown. * * @param collectionId * The collection id. @@ -1984,25 +1930,18 @@ public DocumentEntity deleteDocument(final String documentHandle) throws Aran * The document id. * @param rev * The desired revision - * @param policy - * The update policy * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument( - final long collectionId, - final long documentId, - final Long rev, - final Policy policy) throws ArangoException { - return deleteDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), rev, policy); + public DocumentEntity deleteDocument(final long collectionId, final long documentId, final Long rev) + throws ArangoException { + return deleteDocument(createDocumentHandle(collectionId, String.valueOf(documentId)), rev); } /** * Deletes a document from the database. This method offers a parameter rev * (revision). If the revision of the document on the server does not match - * the given revision the policy parameter is used. If it is set to *last* - * the operation is performed anyway. if it is set to *error* an error is - * thrown. + * the given revision an error is thrown. * * @param collectionName * The collection name. @@ -2010,25 +1949,18 @@ public DocumentEntity deleteDocument( * The document id. * @param rev * The desired revision - * @param policy - * The update policy * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument( - final String collectionName, - final long documentId, - final Long rev, - final Policy policy) throws ArangoException { - return deleteDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), rev, policy); + public DocumentEntity deleteDocument(final String collectionName, final long documentId, final Long rev) + throws ArangoException { + return deleteDocument(createDocumentHandle(collectionName, String.valueOf(documentId)), rev); } /** * Deletes a document from the database. This method offers a parameter rev * (revision). If the revision of the document on the server does not match - * the given revision the policy parameter is used. If it is set to *last* - * the operation is performed anyway. if it is set to *error* an error is - * thrown. + * the given revision an error is thrown. * * @param collectionId * The collection id. @@ -2036,25 +1968,18 @@ public DocumentEntity deleteDocument( * The document key. * @param rev * The desired revision - * @param policy - * The update policy * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument( - final long collectionId, - final String documentKey, - final Long rev, - final Policy policy) throws ArangoException { - return deleteDocument(createDocumentHandle(collectionId, documentKey), rev, policy); + public DocumentEntity deleteDocument(final long collectionId, final String documentKey, final Long rev) + throws ArangoException { + return deleteDocument(createDocumentHandle(collectionId, documentKey), rev); } /** * Deletes a document from the database. This method offers a parameter rev * (revision). If the revision of the document on the server does not match - * the given revision the policy parameter is used. If it is set to *last* - * the operation is performed anyway. if it is set to *error* an error is - * thrown. + * the given revision an error is thrown. * * @param collectionName * The collection name. @@ -2062,38 +1987,28 @@ public DocumentEntity deleteDocument( * The document key. * @param rev * The desired revision - * @param policy - * The update policy * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument( - final String collectionName, - final String documentKey, - final Long rev, - final Policy policy) throws ArangoException { - return deleteDocument(createDocumentHandle(collectionName, documentKey), rev, policy); + public DocumentEntity deleteDocument(final String collectionName, final String documentKey, final Long rev) + throws ArangoException { + return deleteDocument(createDocumentHandle(collectionName, documentKey), rev); } /** * Deletes a document from the database. This method offers a parameter rev * (revision). If the revision of the document on the server does not match - * the given revision the policy parameter is used. If it is set to *last* - * the operation is performed anyway. if it is set to *error* an error is - * thrown. + * the given revision an error is thrown. * * @param documentHandle * The document handle. * @param rev * The desired revision - * @param policy - * The update policy * @return a DocumentEntity object * @throws ArangoException */ - public DocumentEntity deleteDocument(final String documentHandle, final Long rev, final Policy policy) - throws ArangoException { - return documentDriver.deleteDocument(getDefaultDatabase(), documentHandle, rev, policy); + public DocumentEntity deleteDocument(final String documentHandle, final Long rev) throws ArangoException { + return documentDriver.deleteDocument(getDefaultDatabase(), documentHandle, rev); } /** @@ -5610,8 +5525,7 @@ public CursorRawResult executeAqlQueryRaw( * This method replaces the content of the document defined by * documentHandle. This method offers a parameter rev (revision). If the * revision of the document on the server does not match the given revision - * the policy parameter is used. If it is set to *last* the operation is - * performed anyway. if it is set to *error* an error is thrown. + * an error is thrown. * * @param documentHandle * The document's handle. @@ -5619,8 +5533,6 @@ public CursorRawResult executeAqlQueryRaw( * A string containing a JSON object * @param rev * the desired revision. - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -5631,18 +5543,14 @@ public DocumentEntity replaceDocumentRaw( final String documentHandle, final String rawJsonString, final Long rev, - final Policy policy, final Boolean waitForSync) throws ArangoException { - return documentDriver.replaceDocumentRaw(getDefaultDatabase(), documentHandle, rawJsonString, rev, policy, - waitForSync); + return documentDriver.replaceDocumentRaw(getDefaultDatabase(), documentHandle, rawJsonString, rev, waitForSync); } /** * This method updates a document defined by documentHandle. This method * offers a parameter rev (revision). If the revision of the document on the - * server does not match the given revision the policy parameter is used. If - * it is set to *last* the operation is performed anyway. if it is set to - * *error* an error is thrown. + * server does not match the given revision an error is thrown. * * @param documentHandle * The document handle. @@ -5650,8 +5558,6 @@ public DocumentEntity replaceDocumentRaw( * A string containing a JSON object * @param rev * The desired revision - * @param policy - * The update policy * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -5664,11 +5570,10 @@ public DocumentEntity updateDocumentRaw( final String documentHandle, final String rawJsonString, final Long rev, - final Policy policy, final Boolean waitForSync, final Boolean keepNull) throws ArangoException { - return documentDriver.updateDocumentRaw(getDefaultDatabase(), documentHandle, rawJsonString, rev, policy, - waitForSync, keepNull); + return documentDriver.updateDocumentRaw(getDefaultDatabase(), documentHandle, rawJsonString, rev, waitForSync, + keepNull); } // diff --git a/src/main/java/com/arangodb/InternalDocumentDriver.java b/src/main/java/com/arangodb/InternalDocumentDriver.java index 03c28a3e0..76f959512 100644 --- a/src/main/java/com/arangodb/InternalDocumentDriver.java +++ b/src/main/java/com/arangodb/InternalDocumentDriver.java @@ -3,7 +3,6 @@ import java.util.List; import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.Policy; import com.arangodb.impl.BaseDriverInterface; /** @@ -28,7 +27,6 @@ DocumentEntity replaceDocument( String documentHandle, T value, Long rev, - Policy policy, Boolean waitForSync) throws ArangoException; DocumentEntity replaceDocumentRaw( @@ -36,7 +34,6 @@ DocumentEntity replaceDocumentRaw( String documentHandle, String rawJsonString, Long rev, - Policy policy, Boolean waitForSync) throws ArangoException; DocumentEntity updateDocument( @@ -44,7 +41,6 @@ DocumentEntity updateDocument( String documentHandle, T value, Long rev, - Policy policy, Boolean waitForSync, Boolean keepNull) throws ArangoException; @@ -53,7 +49,6 @@ DocumentEntity updateDocumentRaw( String documentHandle, String rawJsonString, Long rev, - Policy policy, Boolean waitForSync, Boolean keepNull) throws ArangoException; @@ -71,6 +66,5 @@ DocumentEntity getDocument( String getDocumentRaw(String database, String documentHandle, Long ifNoneMatchRevision, Long ifMatchRevision) throws ArangoException; - DocumentEntity deleteDocument(String database, String documentHandle, Long rev, Policy policy) - throws ArangoException; + DocumentEntity deleteDocument(String database, String documentHandle, Long rev) throws ArangoException; } diff --git a/src/main/java/com/arangodb/entity/Policy.java b/src/main/java/com/arangodb/entity/Policy.java deleted file mode 100644 index c60d9589c..000000000 --- a/src/main/java/com/arangodb/entity/Policy.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2012 tamtam180 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arangodb.entity; - -/** - * Enumeration for update/replace policy - * - * @author tamtam180 - kirscheless at gmail.com - * - */ -public enum Policy { - /** - * if ERROR an error is returned when there is a revision mismatch - */ - ERROR, - - /** - * if LAST the operation is performed even when there is a revision mismatch - */ - LAST -} diff --git a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java index c0807f1b6..a613e96b4 100644 --- a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java @@ -18,7 +18,6 @@ import java.util.List; import java.util.ListIterator; -import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -30,7 +29,6 @@ import com.arangodb.entity.DefaultEntity; import com.arangodb.entity.DocumentEntity; import com.arangodb.entity.EntityFactory; -import com.arangodb.entity.Policy; import com.arangodb.http.HttpManager; import com.arangodb.http.HttpResponseEntity; import com.arangodb.util.MapBuilder; @@ -116,19 +114,13 @@ public DocumentEntity replaceDocument( final String documentHandle, final T value, final Long rev, - final Policy policy, final Boolean waitForSync) throws ArangoException { validateDocumentHandle(documentHandle); - Map header = null; - if (rev != null) { - final MapBuilder mapBuilder = new MapBuilder().put("If-Match", rev); - header = mapBuilder.get(); - } - - final HttpResponseEntity res = httpManager.doPut(createDocumentEndpointUrl(database, documentHandle), header, - new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(value)); + final HttpResponseEntity res = httpManager.doPut(createDocumentEndpointUrl(database, documentHandle), + createRevisionCheckHeader(rev), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), + EntityFactory.toJsonString(value)); final DocumentEntity result = createEntity(res, DocumentEntity.class); annotationHandler.updateDocumentRev(value, result.getDocumentRevision()); @@ -142,14 +134,11 @@ public DocumentEntity replaceDocumentRaw( final String documentHandle, final String rawJsonString, final Long rev, - final Policy policy, final Boolean waitForSync) throws ArangoException { validateDocumentHandle(documentHandle); - final HttpResponseEntity res = httpManager.doPut( - createDocumentEndpointUrl(database, documentHandle), new MapBuilder().put("rev", rev) - .put(POLICY, policy == null ? null : policy.name()).put(WAIT_FOR_SYNC, waitForSync).get(), - rawJsonString); + final HttpResponseEntity res = httpManager.doPut(createDocumentEndpointUrl(database, documentHandle), + createRevisionCheckHeader(rev), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), rawJsonString); @SuppressWarnings("unchecked") final DocumentEntity result = createEntity(res, DocumentEntity.class); @@ -163,14 +152,13 @@ public DocumentEntity updateDocument( final String documentHandle, final T value, final Long rev, - final Policy policy, final Boolean waitForSync, final Boolean keepNull) throws ArangoException { validateDocumentHandle(documentHandle); final HttpResponseEntity res = httpManager.doPatch(createDocumentEndpointUrl(database, documentHandle), - new MapBuilder().put("rev", rev).put(POLICY, policy == null ? null : policy.name()) - .put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(), + createRevisionCheckHeader(rev), + new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(), EntityFactory.toJsonString(value, keepNull != null && !keepNull)); @SuppressWarnings("unchecked") @@ -187,15 +175,13 @@ public DocumentEntity updateDocumentRaw( final String documentHandle, final String rawJsonString, final Long rev, - final Policy policy, final Boolean waitForSync, final Boolean keepNull) throws ArangoException { validateDocumentHandle(documentHandle); final HttpResponseEntity res = httpManager.doPatch(createDocumentEndpointUrl(database, documentHandle), - new MapBuilder().put("rev", rev).put(POLICY, policy == null ? null : policy.name()) - .put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(), - rawJsonString); + createRevisionCheckHeader(rev), + new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(), rawJsonString); @SuppressWarnings("unchecked") final DocumentEntity result = createEntity(res, DocumentEntity.class); @@ -285,18 +271,21 @@ public String getDocumentRaw( } @Override - public DocumentEntity deleteDocument( - final String database, - final String documentHandle, - final Long rev, - final Policy policy) throws ArangoException { + public DocumentEntity deleteDocument(final String database, final String documentHandle, final Long rev) + throws ArangoException { validateDocumentHandle(documentHandle); final HttpResponseEntity res = httpManager.doDelete(createDocumentEndpointUrl(database, documentHandle), - new MapBuilder().put("rev", rev).put(POLICY, policy == null ? null : policy.name().toLowerCase(Locale.US)) - .get()); - + createRevisionCheckHeader(rev), null); return createEntity(res, DocumentEntity.class); } + private Map createRevisionCheckHeader(final Long rev) { + Map header = null; + if (rev != null) { + final MapBuilder mapBuilder = new MapBuilder().put("If-Match", rev); + header = mapBuilder.get(); + } + return header; + } } diff --git a/src/test/java/com/arangodb/ArangoDriverCollectionTest.java b/src/test/java/com/arangodb/ArangoDriverCollectionTest.java index 925085bff..581aff185 100644 --- a/src/test/java/com/arangodb/ArangoDriverCollectionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCollectionTest.java @@ -425,7 +425,7 @@ public void test_getCollectionFigures_01() throws ArangoException { final DocumentEntity entity = driver.createDocument(collectionName, value, true); // 1個消す if (i == 50) { - driver.deleteDocument(entity.getDocumentHandle(), null, null); + driver.deleteDocument(entity.getDocumentHandle()); } } diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java index be5a62879..b4cf05b4f 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java @@ -207,7 +207,7 @@ public void test_replace() throws ArangoException { final Long rev = doc.getDocumentRevision(); final DocumentEntity doc2 = driver.replaceDocument(doc.getDocumentHandle(), value, null, - null, null); + null); assertThat(doc2.getDocumentHandle(), is(id)); assertThat(doc2.getDocumentKey(), is(key)); @@ -247,7 +247,7 @@ public void test_replace_with_document_attributes() throws ArangoException { final Long rev = doc.getDocumentRevision(); final DocumentEntity doc2 = driver.replaceDocument(doc.getDocumentHandle(), value, null, - null, null); + null); TestComplexEntity03 ent = doc2.getEntity(); assertThat(ent.getDocumentHandle(), is(id)); @@ -280,7 +280,7 @@ public void test_replace_404() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // 存在しないコレクションに追加しようとする try { - driver.replaceDocument(collectionName404, 1, value, null, null, null); + driver.replaceDocument(collectionName404, 1, value, null, null); fail("no exception was thrown"); } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); @@ -293,7 +293,7 @@ public void test_replace_404_2() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("test-user", "test user", 22); // 存在するコレクションだが、ドキュメントが存在しない try { - driver.replaceDocument(collectionName, 1, value, null, null, null); + driver.replaceDocument(collectionName, 1, value, null, null); fail("no exception was thrown"); } catch (final ArangoException e) { assertThat(e.getCode(), is(404)); @@ -314,7 +314,7 @@ public void test_partial_update() throws ArangoException { value.setDesc("UpdatedDescription"); value.setAge(15); final DocumentEntity doc2 = driver.updateDocument(doc.getDocumentHandle(), value, null, - null, null, null); + null, null); assertThat(doc2.getStatusCode(), is(202)); // Get final DocumentEntity doc3 = driver.getDocument(doc2.getDocumentHandle(), @@ -325,7 +325,7 @@ public void test_partial_update() throws ArangoException { assertThat(doc3.getEntity().getDesc(), is("UpdatedDescription")); assertThat(doc3.getEntity().getAge(), is(15)); final DocumentEntity doc4 = driver.updateDocument(doc.getDocumentHandle(), value, null, - null, null, false); + null, false); assertThat(doc4.getStatusCode(), is(202)); final DocumentEntity doc5 = driver.getDocument(doc2.getDocumentHandle(), TestComplexEntity01.class); @@ -349,7 +349,7 @@ public void test_partial_update_with_document_attributes() throws ArangoExceptio value.setDesc("UpdatedDescription"); value.setAge(15); final DocumentEntity doc2 = driver.updateDocument(doc.getDocumentHandle(), value, null, - null, null, null); + null, null); assertThat(doc2.getStatusCode(), is(202)); final TestComplexEntity03 en1 = doc2.getEntity(); @@ -369,7 +369,7 @@ public void test_partial_update_with_document_attributes() throws ArangoExceptio assertThat(doc3.getDocumentRevision(), is(rev1)); final DocumentEntity doc4 = driver.updateDocument(doc.getDocumentHandle(), value, null, - null, null, false); + null, false); assertThat(doc4.getStatusCode(), is(202)); final DocumentEntity doc5 = driver.getDocument(doc2.getDocumentHandle(), TestComplexEntity03.class); diff --git a/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java b/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java index 07b238cd7..405c01bb7 100644 --- a/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java +++ b/src/test/java/com/arangodb/ArangoDriverReplicationTestScenario1.java @@ -194,7 +194,7 @@ public void test_scienario() throws ArangoException, InterruptedException { // ------------------------------------------------------------ // [Master] replace document masterDriver.replaceDocument(doc2.getDocumentHandle(), new MapBuilder().put("updatedKey", "あいうえお").get(), null, - null, null); + null); // wait TimeUnit.SECONDS.sleep(2); @@ -213,7 +213,7 @@ public void test_scienario() throws ArangoException, InterruptedException { // ------------------------------------------------------------ // [Master] update document masterDriver.updateDocument(doc2.getDocumentHandle(), new MapBuilder().put("updatedKey2", "ABCDE").get(), null, - null, null, null); + null, null); // wait TimeUnit.SECONDS.sleep(2); diff --git a/src/test/java/com/arangodb/ArangoDriverThreadSafeTest.java b/src/test/java/com/arangodb/ArangoDriverThreadSafeTest.java index 8f0a90bc9..cb8c71b6a 100644 --- a/src/test/java/com/arangodb/ArangoDriverThreadSafeTest.java +++ b/src/test/java/com/arangodb/ArangoDriverThreadSafeTest.java @@ -30,7 +30,6 @@ import com.arangodb.entity.CollectionEntity; import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.Policy; /** * @author tamtam180 - kirscheless at gmail.com @@ -89,7 +88,7 @@ public void run() { assertThat(ret2.getEntity().getAge(), is(value.getAge())); // ドキュメントを削除する - final DocumentEntity ret3 = driver.deleteDocument(_id, null, Policy.LAST); + final DocumentEntity ret3 = driver.deleteDocument(_id); assertThat(ret3.getDocumentHandle(), is(_id)); assertThat(ret3.getDocumentRevision(), is(_rev)); diff --git a/src/test/java/com/arangodb/example/document/RawDocumentExample.java b/src/test/java/com/arangodb/example/document/RawDocumentExample.java index c64aa881a..f7491f1b5 100644 --- a/src/test/java/com/arangodb/example/document/RawDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/RawDocumentExample.java @@ -133,8 +133,8 @@ public void ReadDocuments() { x = "{\"test\":1234}"; try { - final DocumentEntity updateDocumentRaw = driver.updateDocumentRaw(documentHandle2, x, null, null, - false, true); + final DocumentEntity updateDocumentRaw = driver.updateDocumentRaw(documentHandle2, x, null, false, + true); // print new document revision System.out.println("rev: " + updateDocumentRaw.getDocumentRevision()); // show request result (you have to use getDocumentRaw to get @@ -150,7 +150,7 @@ public void ReadDocuments() { x = "{\"hund\":321,\"katze\":321,\"maus\":777}"; try { - final DocumentEntity replaceDocumentRaw = driver.replaceDocumentRaw(documentHandle2, x, null, null, + final DocumentEntity replaceDocumentRaw = driver.replaceDocumentRaw(documentHandle2, x, null, false); // print new document revision System.out.println("rev: " + replaceDocumentRaw.getDocumentRevision()); diff --git a/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java b/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java index 0ffa76b57..f24265767 100644 --- a/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java +++ b/src/test/java/com/arangodb/example/document/ReplaceAndUpdateDocumentExample.java @@ -26,7 +26,6 @@ import com.arangodb.ArangoException; import com.arangodb.ErrorNums; import com.arangodb.entity.DocumentEntity; -import com.arangodb.entity.Policy; public class ReplaceAndUpdateDocumentExample extends BaseExample { @@ -149,7 +148,7 @@ public void replaceAndUpdateDocument() { try { final DocumentPerson dp = new DocumentPerson("Nina", "female", 9); // wrong revision - driver.replaceDocument(documentHandleExample, dp, 22L, Policy.ERROR, true); + driver.replaceDocument(documentHandleExample, dp, 22L, true); Assert.fail("replaceDocument should fail here!"); } catch (final ArangoException e) { Assert.assertEquals(ErrorNums.ERROR_ARANGO_CONFLICT, e.getErrorNumber()); @@ -158,7 +157,7 @@ public void replaceAndUpdateDocument() { try { final DocumentPerson dp = new DocumentPerson("Nina", "female", 9); // current revision - driver.replaceDocument(documentHandleExample, dp, revision, Policy.ERROR, true); + driver.replaceDocument(documentHandleExample, dp, revision, true); } catch (final ArangoException e) { Assert.fail("Failed to replace document. " + e.getMessage()); } From 41c5280ffb2fad69dfb08afa88bfeea997b2d2e7 Mon Sep 17 00:00:00 2001 From: Mark Vollmary Date: Tue, 24 May 2016 16:51:04 +0200 Subject: [PATCH 15/56] remove some attributes from CollectionEntity.Figures as they are not delivered --- .../com/arangodb/entity/CollectionEntity.java | 129 +-- .../arangodb/entity/EntityDeserializers.java | 800 ++++++++++-------- 2 files changed, 484 insertions(+), 445 deletions(-) diff --git a/src/main/java/com/arangodb/entity/CollectionEntity.java b/src/main/java/com/arangodb/entity/CollectionEntity.java index 97ec57926..7c98ae5e3 100644 --- a/src/main/java/com/arangodb/entity/CollectionEntity.java +++ b/src/main/java/com/arangodb/entity/CollectionEntity.java @@ -127,15 +127,15 @@ public long getChecksum() { return checksum; } - public void setIsSystem(Boolean isSystem) { + public void setIsSystem(final Boolean isSystem) { this.isSystem = isSystem; } - public void setIsVolatile(Boolean isVolatile) { + public void setIsVolatile(final Boolean isVolatile) { this.isVolatile = isVolatile; } - public void setChecksum(long checksum) { + public void setChecksum(final long checksum) { this.checksum = checksum; } @@ -167,47 +167,47 @@ public CollectionKeyOption getKeyOptions() { return keyOptions; } - public void setName(String name) { + public void setName(final String name) { this.name = name; } - public void setId(long id) { + public void setId(final long id) { this.id = id; } - public void setType(CollectionType type) { + public void setType(final CollectionType type) { this.type = type; } - public void setStatus(CollectionStatus status) { + public void setStatus(final CollectionStatus status) { this.status = status; } - public void setWaitForSync(Boolean waitForSync) { + public void setWaitForSync(final Boolean waitForSync) { this.waitForSync = waitForSync; } - public void setSystem(Boolean isSystem) { + public void setSystem(final Boolean isSystem) { this.isSystem = isSystem; } - public void setVolatile(Boolean isVolatile) { + public void setVolatile(final Boolean isVolatile) { this.isVolatile = isVolatile; } - public void setJournalSize(long journalSize) { + public void setJournalSize(final long journalSize) { this.journalSize = journalSize; } - public void setCount(long count) { + public void setCount(final long count) { this.count = count; } - public void setFigures(Figures figures) { + public void setFigures(final Figures figures) { this.figures = figures; } - public void setKeyOptions(CollectionKeyOption keyOptions) { + public void setKeyOptions(final CollectionKeyOption keyOptions) { this.keyOptions = keyOptions; } @@ -215,7 +215,7 @@ public long getRevision() { return revision; } - public void setRevision(long revision) { + public void setRevision(final long revision) { this.revision = revision; } @@ -223,7 +223,7 @@ public Boolean getDoCompact() { return doCompact; } - public void setDoCompact(Boolean doCompact) { + public void setDoCompact(final Boolean doCompact) { this.doCompact = doCompact; } @@ -295,37 +295,6 @@ public static class Figures implements Serializable { */ long compactorsFileSize; - /** - * The number of shape files. This value is deprecated and kept for - * compatibility reasons only. The value will always be 0 since ArangoDB - * 2.0 and higher. *figures.shapefiles.fileSize: The total filesize of - * the shape files. This value is deprecated and kept for compatibility - * reasons only. The value will always be 0 in ArangoDB 2.0 and higher. - */ - long shapefilesCount; - - /** - * The total size of all shapes (in bytes). This includes shapes that - * are not in use anymore. Shapes that are contained in the write-ahead - * log only are not reported in this figure. - */ - long shapefilesFileSize; - - /** - * The total number of shapes used in the collection. This includes - * shapes that are not in use anymore. Shapes that are contained in the - * write-ahead log only are not reported in this figure. - */ - long shapesCount; - - /** - * The total number of attributes used in the collection. Note: the - * value includes data of attributes that are not in use anymore. - * Attributes that are contained in the write-ahead log only are not - * reported in this figure. - */ - long attributesCount; - /** * The total number of indexes defined for the collection, including the * pre-defined indexes (e.g. primary index). @@ -394,87 +363,55 @@ public long getCompactorsFileSize() { return compactorsFileSize; } - public long getShapefilesCount() { - return shapefilesCount; - } - - public long getShapefilesFileSize() { - return shapefilesFileSize; - } - - public long getShapesCount() { - return shapesCount; - } - - public long getAttributesCount() { - return attributesCount; - } - - public void setAliveCount(long aliveCount) { + public void setAliveCount(final long aliveCount) { this.aliveCount = aliveCount; } - public void setAliveSize(long aliveSize) { + public void setAliveSize(final long aliveSize) { this.aliveSize = aliveSize; } - public void setDeadCount(long deadCount) { + public void setDeadCount(final long deadCount) { this.deadCount = deadCount; } - public void setDeadSize(long deadSize) { + public void setDeadSize(final long deadSize) { this.deadSize = deadSize; } - public void setDeadDeletion(long deadDeletion) { + public void setDeadDeletion(final long deadDeletion) { this.deadDeletion = deadDeletion; } - public void setDatafileCount(long datafileCount) { + public void setDatafileCount(final long datafileCount) { this.datafileCount = datafileCount; } - public void setDatafileFileSize(long datafileFileSize) { + public void setDatafileFileSize(final long datafileFileSize) { this.datafileFileSize = datafileFileSize; } - public void setJournalsCount(long journalsCount) { + public void setJournalsCount(final long journalsCount) { this.journalsCount = journalsCount; } - public void setJournalsFileSize(long journalsFileSize) { + public void setJournalsFileSize(final long journalsFileSize) { this.journalsFileSize = journalsFileSize; } - public void setCompactorsCount(long compactorsCount) { + public void setCompactorsCount(final long compactorsCount) { this.compactorsCount = compactorsCount; } - public void setCompactorsFileSize(long compactorsFileSize) { + public void setCompactorsFileSize(final long compactorsFileSize) { this.compactorsFileSize = compactorsFileSize; } - public void setShapefilesCount(long shapefilesCount) { - this.shapefilesCount = shapefilesCount; - } - - public void setShapefilesFileSize(long shapefilesFileSize) { - this.shapefilesFileSize = shapefilesFileSize; - } - - public void setShapesCount(long shapesCount) { - this.shapesCount = shapesCount; - } - - public void setAttributesCount(long attributesCount) { - this.attributesCount = attributesCount; - } - public long getIndexesCount() { return indexesCount; } - public void setIndexesCount(long indexesCount) { + public void setIndexesCount(final long indexesCount) { this.indexesCount = indexesCount; } @@ -482,7 +419,7 @@ public long getIndexesSize() { return indexesSize; } - public void setIndexesSize(long indexesSize) { + public void setIndexesSize(final long indexesSize) { this.indexesSize = indexesSize; } @@ -490,7 +427,7 @@ public long getLastTick() { return lastTick; } - public void setLastTick(long lastTick) { + public void setLastTick(final long lastTick) { this.lastTick = lastTick; } @@ -498,7 +435,7 @@ public long getUncollectedLogfileEntries() { return uncollectedLogfileEntries; } - public void setUncollectedLogfileEntries(long uncollectedLogfileEntries) { + public void setUncollectedLogfileEntries(final long uncollectedLogfileEntries) { this.uncollectedLogfileEntries = uncollectedLogfileEntries; } @@ -508,9 +445,7 @@ public String toString() { + ", deadSize=" + deadSize + ", deadDeletion=" + deadDeletion + ", datafileCount=" + datafileCount + ", datafileFileSize=" + datafileFileSize + ", journalsCount=" + journalsCount + ", journalsFileSize=" + journalsFileSize + ", compactorsCount=" + compactorsCount - + ", compactorsFileSize=" + compactorsFileSize + ", shapefilesCount=" + shapefilesCount - + ", shapefilesFileSize=" + shapefilesFileSize + ", shapesCount=" + shapesCount - + ", attributesCount=" + attributesCount + ", indexesCount=" + indexesCount + ", indexesSize=" + + ", compactorsFileSize=" + compactorsFileSize + ", indexesCount=" + indexesCount + ", indexesSize=" + indexesSize + ", lastTick=" + lastTick + ", uncollectedLogfileEntries=" + uncollectedLogfileEntries + "]"; } diff --git a/src/main/java/com/arangodb/entity/EntityDeserializers.java b/src/main/java/com/arangodb/entity/EntityDeserializers.java index 7bdae9b7f..568f684a6 100644 --- a/src/main/java/com/arangodb/entity/EntityDeserializers.java +++ b/src/main/java/com/arangodb/entity/EntityDeserializers.java @@ -172,10 +172,10 @@ public class EntityDeserializers { private static Logger logger = LoggerFactory.getLogger(EntityDeserializers.class); private static class ClassHolder { - private Class[] clazz; + private final Class[] clazz; private int idx; - ClassHolder(Class... clazz) { + ClassHolder(final Class... clazz) { this.clazz = clazz; this.idx = 0; } @@ -228,7 +228,7 @@ private EntityDeserializers() { // this is a helper class } - public static void setParameterized(Class... clazz) { + public static void setParameterized(final Class... clazz) { parameterizedBridger.set(new ClassHolder(clazz)); } @@ -237,7 +237,7 @@ public static void removeParameterized() { } private static Class getParameterized() { - ClassHolder holder = parameterizedBridger.get(); + final ClassHolder holder = parameterizedBridger.get(); if (holder == null) { return null; } @@ -245,7 +245,7 @@ private static Class getParameterized() { } private static boolean hasNextParameterized() { - ClassHolder holder = parameterizedBridger.get(); + final ClassHolder holder = parameterizedBridger.get(); if (holder == null) { return false; } @@ -253,14 +253,14 @@ private static boolean hasNextParameterized() { } private static Class nextParameterized() { - ClassHolder holder = parameterizedBridger.get(); + final ClassHolder holder = parameterizedBridger.get(); if (holder == null) { return null; } return holder.next(); } - private static T deserializeBaseParameter(JsonObject obj, T entity) { + private static T deserializeBaseParameter(final JsonObject obj, final T entity) { if (obj.has(ERROR) && obj.getAsJsonPrimitive(ERROR).isBoolean()) { entity.error = obj.getAsJsonPrimitive(ERROR).getAsBoolean(); } @@ -280,7 +280,7 @@ private static T deserializeBaseParameter(JsonObject obj, return entity; } - private static T deserializeDocumentParameter(JsonObject obj, T entity) { + private static T deserializeDocumentParameter(final JsonObject obj, final T entity) { if (obj.has("_rev")) { entity.setDocumentRevision(obj.getAsJsonPrimitive("_rev").getAsLong()); @@ -297,7 +297,10 @@ private static T deserializeDocumentParameter(JsonObj public static class DefaultEntityDeserializer implements JsonDeserializer { @Override - public DefaultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public DefaultEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } @@ -308,14 +311,17 @@ public DefaultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializa public static class VersionDeserializer implements JsonDeserializer { @Override - public ArangoVersion deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public ArangoVersion deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ArangoVersion entity = deserializeBaseParameter(obj, new ArangoVersion()); + final JsonObject obj = json.getAsJsonObject(); + final ArangoVersion entity = deserializeBaseParameter(obj, new ArangoVersion()); if (obj.has(SERVER)) { entity.server = obj.getAsJsonPrimitive(SERVER).getAsString(); @@ -331,21 +337,24 @@ public ArangoVersion deserialize(JsonElement json, Type typeOfT, JsonDeserializa public static class ArangoUnixTimeDeserializer implements JsonDeserializer { @Override - public ArangoUnixTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public ArangoUnixTime deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ArangoUnixTime entity = deserializeBaseParameter(obj, new ArangoUnixTime()); + final JsonObject obj = json.getAsJsonObject(); + final ArangoUnixTime entity = deserializeBaseParameter(obj, new ArangoUnixTime()); if (obj.has("time")) { entity.time = obj.getAsJsonPrimitive("time").getAsDouble(); - String time = obj.getAsJsonPrimitive("time").getAsString(); // 実際はdoubleだけど精度の問題が心配なので文字列で処理する。 + final String time = obj.getAsJsonPrimitive("time").getAsString(); // 実際はdoubleだけど精度の問題が心配なので文字列で処理する。 entity.second = (int) entity.time; - int pos = time.indexOf('.'); + final int pos = time.indexOf('.'); entity.microsecond = (pos >= 0 && pos + 1 != time.length()) ? Integer.parseInt(time.substring(pos + 1)) : 0; } @@ -357,64 +366,51 @@ public ArangoUnixTime deserialize(JsonElement json, Type typeOfT, JsonDeserializ public static class FiguresDeserializer implements JsonDeserializer { @Override - public Figures deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public Figures deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - Figures entity = new Figures(); + final JsonObject obj = json.getAsJsonObject(); + final Figures entity = new Figures(); if (obj.has(ALIVE)) { - JsonObject alive = obj.getAsJsonObject(ALIVE); + final JsonObject alive = obj.getAsJsonObject(ALIVE); entity.aliveCount = alive.getAsJsonPrimitive(COUNT).getAsLong(); entity.aliveSize = alive.getAsJsonPrimitive(SIZE).getAsLong(); } if (obj.has("dead")) { - JsonObject dead = obj.getAsJsonObject("dead"); + final JsonObject dead = obj.getAsJsonObject("dead"); entity.deadCount = dead.getAsJsonPrimitive(COUNT).getAsLong(); entity.deadSize = dead.getAsJsonPrimitive(SIZE).getAsLong(); entity.deadDeletion = dead.getAsJsonPrimitive("deletion").getAsLong(); } if (obj.has("datafiles")) { - JsonObject datafiles = obj.getAsJsonObject("datafiles"); + final JsonObject datafiles = obj.getAsJsonObject("datafiles"); entity.datafileCount = datafiles.getAsJsonPrimitive(COUNT).getAsLong(); entity.datafileFileSize = datafiles.getAsJsonPrimitive(FILE_SIZE).getAsLong(); } if (obj.has("journals")) { - JsonObject journals = obj.getAsJsonObject("journals"); + final JsonObject journals = obj.getAsJsonObject("journals"); entity.journalsCount = journals.getAsJsonPrimitive(COUNT).getAsLong(); entity.journalsFileSize = journals.getAsJsonPrimitive(FILE_SIZE).getAsLong(); } if (obj.has("compactors")) { - JsonObject compactors = obj.getAsJsonObject("compactors"); + final JsonObject compactors = obj.getAsJsonObject("compactors"); entity.compactorsCount = compactors.getAsJsonPrimitive(COUNT).getAsLong(); entity.compactorsFileSize = compactors.getAsJsonPrimitive(FILE_SIZE).getAsLong(); } - if (obj.has("shapefiles")) { - JsonObject shapefiles = obj.getAsJsonObject("shapefiles"); - entity.shapefilesCount = shapefiles.getAsJsonPrimitive(COUNT).getAsLong(); - entity.shapefilesFileSize = shapefiles.getAsJsonPrimitive(FILE_SIZE).getAsLong(); - } - - if (obj.has("shapes")) { - JsonObject shapes = obj.getAsJsonObject("shapes"); - entity.shapesCount = shapes.getAsJsonPrimitive(COUNT).getAsLong(); - } - - if (obj.has("attributes")) { - JsonObject attributes = obj.getAsJsonObject("attributes"); - entity.attributesCount = attributes.getAsJsonPrimitive(COUNT).getAsLong(); - } - if (obj.has(INDEXES)) { - JsonObject indexes = obj.getAsJsonObject(INDEXES); + final JsonObject indexes = obj.getAsJsonObject(INDEXES); entity.indexesCount = indexes.getAsJsonPrimitive(COUNT).getAsLong(); entity.indexesSize = indexes.getAsJsonPrimitive(SIZE).getAsLong(); } @@ -433,14 +429,17 @@ public Figures deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo public static class CollectionKeyOptionDeserializer implements JsonDeserializer { @Override - public CollectionKeyOption deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public CollectionKeyOption deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - CollectionKeyOption entity = new CollectionKeyOption(); + final JsonObject obj = json.getAsJsonObject(); + final CollectionKeyOption entity = new CollectionKeyOption(); if (obj.has("type")) { entity.type = obj.getAsJsonPrimitive("type").getAsString(); @@ -465,14 +464,17 @@ public CollectionKeyOption deserialize(JsonElement json, Type typeOfT, JsonDeser public static class CollectionEntityDeserializer implements JsonDeserializer { @Override - public CollectionEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public CollectionEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - CollectionEntity entity = deserializeBaseParameter(obj, new CollectionEntity()); + final JsonObject obj = json.getAsJsonObject(); + final CollectionEntity entity = deserializeBaseParameter(obj, new CollectionEntity()); if (obj.has(NAME)) { entity.name = obj.getAsJsonPrimitive(NAME).getAsString(); @@ -535,19 +537,22 @@ public CollectionEntity deserialize(JsonElement json, Type typeOfT, JsonDeserial } public static class CollectionsEntityDeserializer implements JsonDeserializer { - private Type collectionsType = new TypeToken>() { + private final Type collectionsType = new TypeToken>() { }.getType(); @SuppressWarnings("unchecked") @Override - public CollectionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public CollectionsEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - CollectionsEntity entity = deserializeBaseParameter(obj, new CollectionsEntity()); + final JsonObject obj = json.getAsJsonObject(); + final CollectionsEntity entity = deserializeBaseParameter(obj, new CollectionsEntity()); if (obj.has(RESULT)) { entity.setCollections((List) context.deserialize(obj.get(RESULT), collectionsType)); @@ -562,18 +567,21 @@ public CollectionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeseria public static class AqlfunctionsEntityDeserializer implements JsonDeserializer { @Override - public AqlFunctionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public AqlFunctionsEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonArray obj = json.getAsJsonArray(); - Iterator iterator = obj.iterator(); - Map functions = new HashMap(); + final JsonArray obj = json.getAsJsonArray(); + final Iterator iterator = obj.iterator(); + final Map functions = new HashMap(); while (iterator.hasNext()) { - JsonElement e = iterator.next(); - JsonObject o = e.getAsJsonObject(); + final JsonElement e = iterator.next(); + final JsonObject o = e.getAsJsonObject(); functions.put(o.get("name").getAsString(), o.get(CODE).getAsString()); } return new AqlFunctionsEntity(functions); @@ -583,17 +591,20 @@ public AqlFunctionsEntity deserialize(JsonElement json, Type typeOfT, JsonDeseri public static class JobsEntityDeserializer implements JsonDeserializer { @Override - public JobsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public JobsEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonArray obj = json.getAsJsonArray(); - Iterator iterator = obj.iterator(); - List jobs = new ArrayList(); + final JsonArray obj = json.getAsJsonArray(); + final Iterator iterator = obj.iterator(); + final List jobs = new ArrayList(); while (iterator.hasNext()) { - JsonElement e = iterator.next(); + final JsonElement e = iterator.next(); jobs.add(e.getAsString()); } return new JobsEntity(jobs); @@ -602,24 +613,27 @@ public JobsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializatio public static class CursorEntityDeserializer implements JsonDeserializer> { - private Type bindVarsType = new TypeToken>() { + private final Type bindVarsType = new TypeToken>() { }.getType(); - private Type extraType = new TypeToken>() { + private final Type extraType = new TypeToken>() { }.getType(); @Override - public CursorEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public CursorEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - CursorEntity entity = deserializeBaseParameter(obj, new CursorEntity()); + final JsonObject obj = json.getAsJsonObject(); + final CursorEntity entity = deserializeBaseParameter(obj, new CursorEntity()); if (obj.has(RESULT)) { - JsonArray array = obj.getAsJsonArray(RESULT); + final JsonArray array = obj.getAsJsonArray(RESULT); if (array == null || array.isJsonNull() || array.size() == 0) { entity.results = Collections.emptyList(); } else { @@ -658,16 +672,16 @@ public CursorEntity deserialize(JsonElement json, Type typeOfT, JsonDeseriali } private void getResultObjects( - JsonDeserializationContext context, - CursorEntity entity, - JsonArray array) { - Class clazz = getParameterized(); - boolean withDocument = DocumentEntity.class.isAssignableFrom(clazz); + final JsonDeserializationContext context, + final CursorEntity entity, + final JsonArray array) { + final Class clazz = getParameterized(); + final boolean withDocument = DocumentEntity.class.isAssignableFrom(clazz); if (withDocument) { nextParameterized(); } try { - List list = new ArrayList(array.size()); + final List list = new ArrayList(array.size()); for (int i = 0, imax = array.size(); i < imax; i++) { list.add(context.deserialize(array.get(i), clazz)); } @@ -679,42 +693,42 @@ private void getResultObjects( } } - private void getWarnings(CursorEntity entity) { + private void getWarnings(final CursorEntity entity) { if (entity.extra.containsKey(WARNINGS)) { - Object object = entity.extra.get(WARNINGS); + final Object object = entity.extra.get(WARNINGS); if (object instanceof List) { - List l = (List) entity.extra.get(WARNINGS); + final List l = (List) entity.extra.get(WARNINGS); getWarningsFromList(entity, l); } } } - private void getWarningsFromList(CursorEntity entity, List l) { - for (Object o : l) { + private void getWarningsFromList(final CursorEntity entity, final List l) { + for (final Object o : l) { if (o instanceof Map) { - Map m = (Map) o; + final Map m = (Map) o; if (m.containsKey(CODE) && m.get(CODE) instanceof Double && m.containsKey(MESSAGE) && m.get(MESSAGE) instanceof String) { - Long code = ((Double) m.get(CODE)).longValue(); - String message = (String) m.get(MESSAGE); + final Long code = ((Double) m.get(CODE)).longValue(); + final String message = (String) m.get(MESSAGE); entity.warnings.add(new WarningEntity(code, message)); } } } } - private void getFullCount(CursorEntity entity) { + private void getFullCount(final CursorEntity entity) { if (entity.extra.containsKey("stats") && entity.extra.get("stats") instanceof Map) { - Map m = (Map) entity.extra.get("stats"); + final Map m = (Map) entity.extra.get("stats"); if (m.containsKey("fullCount") && m.get("fullCount") instanceof Double) { - Double v = (Double) m.get("fullCount"); + final Double v = (Double) m.get("fullCount"); entity.fullCount = v.intValue(); } } } private Class backParameterized() { - ClassHolder holder = parameterizedBridger.get(); + final ClassHolder holder = parameterizedBridger.get(); if (holder == null) { return null; } @@ -726,7 +740,10 @@ private Class backParameterized() { public static class DocumentEntityDeserializer implements JsonDeserializer> { @Override - public DocumentEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public DocumentEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return new DocumentEntity(); @@ -740,13 +757,13 @@ public DocumentEntity deserialize(JsonElement json, Type typeOfT, JsonDeseria return new DocumentEntity(); } - JsonObject obj = json.getAsJsonObject(); + final JsonObject obj = json.getAsJsonObject(); - DocumentEntity entity = new DocumentEntity(); + final DocumentEntity entity = new DocumentEntity(); deserializeDocumentParameter(obj, entity); // 他のフィールドはリフレクションで。 (TODO: Annotationのサポートと上記パラメータを弾く) - Class clazz = getParameterized(); + final Class clazz = getParameterized(); if (clazz != null) { entity.entity = context.deserialize(obj, clazz); @@ -776,7 +793,7 @@ private DeserializeSingleEntry() { * @param jsonElement * @return a object */ - public static Object deserializeJsonElement(JsonElement jsonElement) { + public static Object deserializeJsonElement(final JsonElement jsonElement) { if (jsonElement.getClass() == JsonPrimitive.class) { return deserializeJsonPrimitive((JsonPrimitive) jsonElement); } else if (jsonElement.getClass() == JsonArray.class) { @@ -794,10 +811,10 @@ public static Object deserializeJsonElement(JsonElement jsonElement) { * a jsonObject * @return the deserialized jsonObject */ - private static Map deserializeJsonObject(JsonObject jsonObject) { - Map result = new HashMap(); - Set> entrySet = jsonObject.entrySet(); - for (Map.Entry entry : entrySet) { + private static Map deserializeJsonObject(final JsonObject jsonObject) { + final Map result = new HashMap(); + final Set> entrySet = jsonObject.entrySet(); + for (final Map.Entry entry : entrySet) { if (!nonProperties.contains(entry.getKey())) { result.put(entry.getKey(), deserializeJsonElement(jsonObject.get(entry.getKey()))); } @@ -805,9 +822,9 @@ private static Map deserializeJsonObject(JsonObject jsonObject) return result; } - private static List deserializeJsonArray(JsonArray jsonArray) { - List tmpObjectList = new ArrayList(); - Iterator iterator = jsonArray.iterator(); + private static List deserializeJsonArray(final JsonArray jsonArray) { + final List tmpObjectList = new ArrayList(); + final Iterator iterator = jsonArray.iterator(); while (iterator.hasNext()) { tmpObjectList.add(deserializeJsonElement(iterator.next())); } @@ -820,7 +837,7 @@ private static List deserializeJsonArray(JsonArray jsonArray) { * @param jsonPrimitive * @return null|String|Double|Boolean */ - private static Object deserializeJsonPrimitive(JsonPrimitive jsonPrimitive) { + private static Object deserializeJsonPrimitive(final JsonPrimitive jsonPrimitive) { if (jsonPrimitive.isBoolean()) { return jsonPrimitive.getAsBoolean(); } else if (jsonPrimitive.isNumber()) { @@ -834,18 +851,21 @@ private static Object deserializeJsonPrimitive(JsonPrimitive jsonPrimitive) { } public static class DocumentsEntityDeserializer implements JsonDeserializer { - private Type documentsType = new TypeToken>() { + private final Type documentsType = new TypeToken>() { }.getType(); @Override - public DocumentsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public DocumentsEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - DocumentsEntity entity = deserializeBaseParameter(obj, new DocumentsEntity()); + final JsonObject obj = json.getAsJsonObject(); + final DocumentsEntity entity = deserializeBaseParameter(obj, new DocumentsEntity()); if (obj.has("documents")) { entity.documents = context.deserialize(obj.get("documents"), documentsType); @@ -857,25 +877,28 @@ public DocumentsEntity deserialize(JsonElement json, Type typeOfT, JsonDeseriali } public static class IndexEntityDeserializer implements JsonDeserializer { - private Type fieldsType = new TypeToken>() { + private final Type fieldsType = new TypeToken>() { }.getType(); @Override - public IndexEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public IndexEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - IndexEntity entity = deserializeBaseParameter(obj, new IndexEntity()); + final JsonObject obj = json.getAsJsonObject(); + final IndexEntity entity = deserializeBaseParameter(obj, new IndexEntity()); if (obj.has(ID)) { entity.id = obj.getAsJsonPrimitive(ID).getAsString(); } if (obj.has("type")) { - String type = obj.getAsJsonPrimitive("type").getAsString().toUpperCase(Locale.US); + final String type = obj.getAsJsonPrimitive("type").getAsString().toUpperCase(Locale.US); if (type.startsWith(IndexType.GEO.name())) { entity.type = IndexType.GEO; } else { @@ -920,20 +943,23 @@ public IndexEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializati } public static class IndexesEntityDeserializer implements JsonDeserializer { - private Type indexesType = new TypeToken>() { + private final Type indexesType = new TypeToken>() { }.getType(); - private Type identifiersType = new TypeToken>() { + private final Type identifiersType = new TypeToken>() { }.getType(); @Override - public IndexesEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public IndexesEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - IndexesEntity entity = deserializeBaseParameter(obj, new IndexesEntity()); + final JsonObject obj = json.getAsJsonObject(); + final IndexesEntity entity = deserializeBaseParameter(obj, new IndexesEntity()); if (obj.has(INDEXES)) { entity.indexes = context.deserialize(obj.get(INDEXES), indexesType); @@ -950,19 +976,22 @@ public IndexesEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializa public static class AdminLogEntryEntityDeserializer implements JsonDeserializer { @Override - public AdminLogEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public AdminLogEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - AdminLogEntity entity = deserializeBaseParameter(obj, new AdminLogEntity()); + final JsonObject obj = json.getAsJsonObject(); + final AdminLogEntity entity = deserializeBaseParameter(obj, new AdminLogEntity()); // 全ての要素は必ずあることが前提なのでhasチェックはしない - int[] lids = context.deserialize(obj.getAsJsonArray("lid"), int[].class); - int[] levels = context.deserialize(obj.getAsJsonArray("level"), int[].class); - long[] timestamps = context.deserialize(obj.getAsJsonArray("timestamp"), long[].class); - String[] texts = context.deserialize(obj.getAsJsonArray("text"), String[].class); + final int[] lids = context.deserialize(obj.getAsJsonArray("lid"), int[].class); + final int[] levels = context.deserialize(obj.getAsJsonArray("level"), int[].class); + final long[] timestamps = context.deserialize(obj.getAsJsonArray("timestamp"), long[].class); + final String[] texts = context.deserialize(obj.getAsJsonArray("text"), String[].class); // 配列のサイズが全て同じであること if (lids.length != levels.length || lids.length != timestamps.length || lids.length != texts.length) { @@ -971,7 +1000,7 @@ public AdminLogEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializ entity.logs = new ArrayList(lids.length); for (int i = 0; i < lids.length; i++) { - AdminLogEntity.LogEntry entry = new AdminLogEntity.LogEntry(); + final AdminLogEntity.LogEntry entry = new AdminLogEntity.LogEntry(); entry.lid = lids[i]; entry.level = levels[i]; entry.timestamp = new Date(timestamps[i] * 1000L); @@ -992,14 +1021,17 @@ public static class StatisticsEntityDeserializer implements JsonDeserializer(); entity.client = cli; - JsonObject client = obj.getAsJsonObject("client"); + final JsonObject client = obj.getAsJsonObject("client"); if (client.has("httpConnections")) { cli.httpConnections = client.getAsJsonPrimitive("httpConnections").getAsInt(); } - for (Entry ent : client.entrySet()) { + for (final Entry ent : client.entrySet()) { if (!"httpConnections".equals(ent.getKey())) { - JsonObject f = ent.getValue().getAsJsonObject(); - FigureValue fv = new FigureValue(); + final JsonObject f = ent.getValue().getAsJsonObject(); + final FigureValue fv = new FigureValue(); fv.sum = f.getAsJsonPrimitive("sum").getAsDouble(); fv.count = f.getAsJsonPrimitive(COUNT).getAsLong(); fv.counts = context.deserialize(f.getAsJsonArray("counts"), countsType); @@ -1045,12 +1080,12 @@ private void deserializeClient(JsonDeserializationContext context, JsonObject ob } } - private void deserializeSystem(JsonObject obj, StatisticsEntity entity) { + private void deserializeSystem(final JsonObject obj, final StatisticsEntity entity) { if (obj.has("system")) { - StatisticsEntity.System sys = new StatisticsEntity.System(); + final StatisticsEntity.System sys = new StatisticsEntity.System(); entity.system = sys; - JsonObject system = obj.getAsJsonObject("system"); + final JsonObject system = obj.getAsJsonObject("system"); if (system.has("minorPageFaults")) { sys.minorPageFaults = system.getAsJsonPrimitive("minorPageFaults").getAsLong(); } @@ -1083,24 +1118,24 @@ public static class StatisticsDescriptionEntityDeserializer @Override public StatisticsDescriptionEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - StatisticsDescriptionEntity entity = deserializeBaseParameter(obj, new StatisticsDescriptionEntity()); + final JsonObject obj = json.getAsJsonObject(); + final StatisticsDescriptionEntity entity = deserializeBaseParameter(obj, new StatisticsDescriptionEntity()); if (obj.has("groups")) { - JsonArray groups = obj.getAsJsonArray("groups"); + final JsonArray groups = obj.getAsJsonArray("groups"); entity.groups = new ArrayList(groups.size()); for (int i = 0, imax = groups.size(); i < imax; i++) { - JsonObject g = groups.get(i).getAsJsonObject(); + final JsonObject g = groups.get(i).getAsJsonObject(); - Group group = new Group(); + final Group group = new Group(); group.group = g.getAsJsonPrimitive("group").getAsString(); group.name = g.getAsJsonPrimitive("name").getAsString(); group.description = g.getAsJsonPrimitive("description").getAsString(); @@ -1110,12 +1145,12 @@ public StatisticsDescriptionEntity deserialize( } if (obj.has(FIGURES)) { - JsonArray figures = obj.getAsJsonArray(FIGURES); + final JsonArray figures = obj.getAsJsonArray(FIGURES); entity.figures = new ArrayList(figures.size()); for (int i = 0, imax = figures.size(); i < imax; i++) { - JsonObject f = figures.get(i).getAsJsonObject(); + final JsonObject f = figures.get(i).getAsJsonObject(); - Figure figure = new Figure(); + final Figure figure = new Figure(); figure.group = f.getAsJsonPrimitive("group").getAsString(); figure.identifier = f.getAsJsonPrimitive("identifier").getAsString(); figure.name = f.getAsJsonPrimitive("name").getAsString(); @@ -1138,14 +1173,17 @@ public StatisticsDescriptionEntity deserialize( public static class ScalarExampleEntityDeserializer implements JsonDeserializer> { @Override - public ScalarExampleEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public ScalarExampleEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ScalarExampleEntity entity = deserializeBaseParameter(obj, new ScalarExampleEntity()); + final JsonObject obj = json.getAsJsonObject(); + final ScalarExampleEntity entity = deserializeBaseParameter(obj, new ScalarExampleEntity()); if (obj.has("document")) { entity.document = context.deserialize(obj.get("document"), DocumentEntity.class); @@ -1159,14 +1197,17 @@ public ScalarExampleEntity deserialize(JsonElement json, Type typeOfT, JsonDe public static class SimpleByResultEntityDeserializer implements JsonDeserializer { @Override - public SimpleByResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public SimpleByResultEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - SimpleByResultEntity entity = deserializeBaseParameter(obj, new SimpleByResultEntity()); + final JsonObject obj = json.getAsJsonObject(); + final SimpleByResultEntity entity = deserializeBaseParameter(obj, new SimpleByResultEntity()); if (obj.has(DELETED)) { entity.count = entity.deleted = obj.getAsJsonPrimitive(DELETED).getAsInt(); @@ -1188,14 +1229,17 @@ public SimpleByResultEntity deserialize(JsonElement json, Type typeOfT, JsonDese public static class TransactionResultEntityDeserializer implements JsonDeserializer { @Override - public TransactionResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public TransactionResultEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - TransactionResultEntity entity = deserializeBaseParameter(obj, new TransactionResultEntity()); + final JsonObject obj = json.getAsJsonObject(); + final TransactionResultEntity entity = deserializeBaseParameter(obj, new TransactionResultEntity()); if (obj.has(RESULT)) { // MEMO: if (obj.get(RESULT) instanceof JsonObject) { @@ -1217,14 +1261,17 @@ public TransactionResultEntity deserialize(JsonElement json, Type typeOfT, JsonD public static class UserEntityDeserializer implements JsonDeserializer { @Override - public UserEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public UserEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - UserEntity entity = deserializeBaseParameter(obj, new UserEntity()); + final JsonObject obj = json.getAsJsonObject(); + final UserEntity entity = deserializeBaseParameter(obj, new UserEntity()); if (obj.has("user")) { // MEMO: // RequestはusernameなのにResponseは何故userなのか。。 @@ -1239,7 +1286,7 @@ public UserEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializatio entity.active = obj.getAsJsonPrimitive(ACTIVE).getAsBoolean(); } else if (obj.has("authData")) { // for simple/all requsts - JsonObject authData = obj.getAsJsonObject("authData"); + final JsonObject authData = obj.getAsJsonObject("authData"); if (authData.has(ACTIVE)) { entity.active = authData.getAsJsonPrimitive(ACTIVE).getAsBoolean(); } @@ -1261,14 +1308,17 @@ public UserEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializatio public static class ImportResultEntityDeserializer implements JsonDeserializer { @Override - public ImportResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public ImportResultEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ImportResultEntity entity = deserializeBaseParameter(obj, new ImportResultEntity()); + final JsonObject obj = json.getAsJsonObject(); + final ImportResultEntity entity = deserializeBaseParameter(obj, new ImportResultEntity()); if (obj.has("created")) { entity.created = obj.getAsJsonPrimitive("created").getAsInt(); @@ -1288,17 +1338,20 @@ public ImportResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeseri public static class DatabaseEntityDeserializer implements JsonDeserializer { @Override - public DatabaseEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public DatabaseEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - DatabaseEntity entity = deserializeBaseParameter(obj, new DatabaseEntity()); + final JsonObject obj = json.getAsJsonObject(); + final DatabaseEntity entity = deserializeBaseParameter(obj, new DatabaseEntity()); if (obj.has(RESULT)) { - JsonObject result = obj.getAsJsonObject(RESULT); + final JsonObject result = obj.getAsJsonObject(RESULT); if (result.has("name")) { entity.name = result.getAsJsonPrimitive("name").getAsString(); } @@ -1322,14 +1375,17 @@ public static class StringsResultEntityDeserializer implements JsonDeserializer< }.getType(); @Override - public StringsResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public StringsResultEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - StringsResultEntity entity = deserializeBaseParameter(obj, new StringsResultEntity()); + final JsonObject obj = json.getAsJsonObject(); + final StringsResultEntity entity = deserializeBaseParameter(obj, new StringsResultEntity()); if (obj.has(RESULT)) { entity.result = context.deserialize(obj.get(RESULT), resultType); @@ -1341,14 +1397,17 @@ public StringsResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeser public static class BooleanResultEntityDeserializer implements JsonDeserializer { @Override - public BooleanResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public BooleanResultEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - BooleanResultEntity entity = deserializeBaseParameter(obj, new BooleanResultEntity()); + final JsonObject obj = json.getAsJsonObject(); + final BooleanResultEntity entity = deserializeBaseParameter(obj, new BooleanResultEntity()); if (obj.has(RESULT)) { entity.result = obj.getAsJsonPrimitive(RESULT).getAsBoolean(); @@ -1364,15 +1423,18 @@ public static class EndpointDeserializer implements JsonDeserializer { @SuppressWarnings("unchecked") @Override - public Endpoint deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public Endpoint deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); + final JsonObject obj = json.getAsJsonObject(); - Endpoint entity = new Endpoint(); + final Endpoint entity = new Endpoint(); entity.setDatabases((List) context.deserialize(obj.getAsJsonArray("databases"), databasesType)); entity.setEndpoint(obj.getAsJsonPrimitive("endpoint").getAsString()); @@ -1385,22 +1447,26 @@ public static class DocumentResultEntityDeserializer implements JsonDeserializer }.getType(); @Override - public DocumentResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public DocumentResultEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - DocumentResultEntity entity = deserializeBaseParameter(obj, new DocumentResultEntity()); + final JsonObject obj = json.getAsJsonObject(); + final DocumentResultEntity entity = deserializeBaseParameter(obj, + new DocumentResultEntity()); if (obj.has(RESULT)) { - JsonElement resultElem = obj.get(RESULT); + final JsonElement resultElem = obj.get(RESULT); if (resultElem.isJsonArray()) { entity.result = context.deserialize(resultElem, documentsType); } else if (resultElem.isJsonObject()) { - DocumentEntity doc = context.deserialize(resultElem, DocumentEntity.class); - List> list = new ArrayList>(1); + final DocumentEntity doc = context.deserialize(resultElem, DocumentEntity.class); + final List> list = new ArrayList>(1); list.add(doc); entity.result = list; } else { @@ -1414,14 +1480,17 @@ public DocumentResultEntity deserialize(JsonElement json, Type typeOfT, JsonD public static class ReplicationStateDeserializer implements JsonDeserializer { @Override - public ReplicationState deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public ReplicationState deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationState entity = new ReplicationState(); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationState entity = new ReplicationState(); entity.running = obj.getAsJsonPrimitive("running").getAsBoolean(); entity.lastLogTick = obj.getAsJsonPrimitive("lastLogTick").getAsLong(); @@ -1434,31 +1503,31 @@ public ReplicationState deserialize(JsonElement json, Type typeOfT, JsonDeserial public static class ReplicationInventoryEntityDeserializer implements JsonDeserializer { - private Type indexesType = new TypeToken>() { + private final Type indexesType = new TypeToken>() { }.getType(); @Override public ReplicationInventoryEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationInventoryEntity entity = deserializeBaseParameter(obj, new ReplicationInventoryEntity()); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationInventoryEntity entity = deserializeBaseParameter(obj, new ReplicationInventoryEntity()); if (obj.has(COLLECTIONS)) { - JsonArray collections = obj.getAsJsonArray(COLLECTIONS); + final JsonArray collections = obj.getAsJsonArray(COLLECTIONS); entity.collections = new ArrayList(collections.size()); for (int i = 0, imax = collections.size(); i < imax; i++) { - JsonObject elem = collections.get(i).getAsJsonObject(); - Collection col = new Collection(); + final JsonObject elem = collections.get(i).getAsJsonObject(); + final Collection col = new Collection(); if (elem.has("parameters")) { - JsonObject parameters = elem.getAsJsonObject("parameters"); + final JsonObject parameters = elem.getAsJsonObject("parameters"); addCollectionParameters(col, parameters); } @@ -1481,7 +1550,7 @@ public ReplicationInventoryEntity deserialize( return entity; } - private void addCollectionParameters(Collection col, JsonObject parameters) { + private void addCollectionParameters(final Collection col, final JsonObject parameters) { col.parameter = new CollectionParameter(); if (parameters.has(VERSION)) { col.parameter.version = parameters.getAsJsonPrimitive(VERSION).getAsInt(); @@ -1519,22 +1588,22 @@ public static class ReplicationDumpRecordDeserializer implements JsonDeserialize @Override public ReplicationDumpRecord deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationDumpRecord> entity = new ReplicationDumpRecord>(); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationDumpRecord> entity = new ReplicationDumpRecord>(); if (obj.has("tick")) { entity.tick = obj.getAsJsonPrimitive("tick").getAsLong(); } if (obj.has("type")) { - int type = obj.getAsJsonPrimitive("type").getAsInt(); + final int type = obj.getAsJsonPrimitive("type").getAsInt(); entity.type = ReplicationEventType.valueOf(type); } if (obj.has("key")) { @@ -1556,14 +1625,17 @@ public static class ReplicationSyncEntityDeserializer implements JsonDeserialize }.getType(); @Override - public ReplicationSyncEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public ReplicationSyncEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationSyncEntity entity = deserializeBaseParameter(obj, new ReplicationSyncEntity()); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationSyncEntity entity = deserializeBaseParameter(obj, new ReplicationSyncEntity()); if (obj.has(COLLECTIONS)) { entity.collections = context.deserialize(obj.getAsJsonArray(COLLECTIONS), collectionsType); @@ -1581,14 +1653,17 @@ public static class MapAsEntityDeserializer implements JsonDeserializer { @Override public ReplicationLoggerConfigEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationLoggerConfigEntity entity = deserializeBaseParameter(obj, new ReplicationLoggerConfigEntity()); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationLoggerConfigEntity entity = deserializeBaseParameter(obj, + new ReplicationLoggerConfigEntity()); if (obj.has(AUTO_START)) { entity.autoStart = obj.getAsJsonPrimitive(AUTO_START).getAsBoolean(); @@ -1633,16 +1709,17 @@ public static class ReplicationApplierConfigEntityDeserializer @Override public ReplicationApplierConfigEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationApplierConfigEntity entity = deserializeBaseParameter(obj, new ReplicationApplierConfigEntity()); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationApplierConfigEntity entity = deserializeBaseParameter(obj, + new ReplicationApplierConfigEntity()); if (obj.has(ENDPOINT)) { entity.endpoint = obj.getAsJsonPrimitive(ENDPOINT).getAsString(); @@ -1691,14 +1768,17 @@ public ReplicationApplierConfigEntity deserialize( public static class ReplicationApplierStateDeserializer implements JsonDeserializer { @Override - public ReplicationApplierState deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public ReplicationApplierState deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationApplierState state = new ReplicationApplierState(); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationApplierState state = new ReplicationApplierState(); if (obj.has("running")) { state.running = obj.getAsJsonPrimitive("running").getAsBoolean(); @@ -1726,7 +1806,7 @@ public ReplicationApplierState deserialize(JsonElement json, Type typeOfT, JsonD return state; } - private void deserializeTicks(JsonObject obj, ReplicationApplierState state) { + private void deserializeTicks(final JsonObject obj, final ReplicationApplierState state) { if (obj.has(LAST_APPLIED_CONTINUOUS_TICK) && !obj.get(LAST_APPLIED_CONTINUOUS_TICK).isJsonNull()) { state.lastAppliedContinuousTick = obj.getAsJsonPrimitive(LAST_APPLIED_CONTINUOUS_TICK).getAsLong(); } @@ -1738,9 +1818,9 @@ private void deserializeTicks(JsonObject obj, ReplicationApplierState state) { } } - private void deserializeProgress(JsonObject obj, ReplicationApplierState state) { + private void deserializeProgress(final JsonObject obj, final ReplicationApplierState state) { if (obj.has("progress")) { - JsonObject progress = obj.getAsJsonObject("progress"); + final JsonObject progress = obj.getAsJsonObject("progress"); state.progress = new Progress(); if (progress.has("failedConnects")) { state.progress.failedConnects = progress.getAsJsonPrimitive("failedConnects").getAsLong(); @@ -1754,9 +1834,9 @@ private void deserializeProgress(JsonObject obj, ReplicationApplierState state) } } - private void deserializeLastError(JsonObject obj, ReplicationApplierState state) { + private void deserializeLastError(final JsonObject obj, final ReplicationApplierState state) { if (obj.has(LAST_ERROR) && !obj.get(LAST_ERROR).isJsonNull()) { - JsonObject lastError = obj.getAsJsonObject(LAST_ERROR); + final JsonObject lastError = obj.getAsJsonObject(LAST_ERROR); state.lastError = new LastError(); if (lastError.has("time")) { state.lastError.setTime(DateUtils.parse(lastError.getAsJsonPrimitive("time").getAsString())); @@ -1775,16 +1855,17 @@ public static class ReplicationApplierStateEntityDeserializer implements JsonDeserializer { @Override public ReplicationApplierStateEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationApplierStateEntity entity = deserializeBaseParameter(obj, new ReplicationApplierStateEntity()); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationApplierStateEntity entity = deserializeBaseParameter(obj, + new ReplicationApplierStateEntity()); if (obj.has(ENDPOINT)) { entity.endpoint = obj.getAsJsonPrimitive(ENDPOINT).getAsString(); @@ -1795,7 +1876,7 @@ public ReplicationApplierStateEntity deserialize( } if (obj.has(SERVER)) { - JsonObject server = obj.getAsJsonObject(SERVER); + final JsonObject server = obj.getAsJsonObject(SERVER); entity.serverVersion = server.getAsJsonPrimitive(VERSION).getAsString(); entity.serverId = server.getAsJsonPrimitive("serverId").getAsString(); } @@ -1810,28 +1891,29 @@ public ReplicationApplierStateEntity deserialize( public static class ReplicationLoggerStateEntityDeserializer implements JsonDeserializer { - private Type clientsType = new TypeToken>() { + private final Type clientsType = new TypeToken>() { }.getType(); @Override public ReplicationLoggerStateEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ReplicationLoggerStateEntity entity = deserializeBaseParameter(obj, new ReplicationLoggerStateEntity()); + final JsonObject obj = json.getAsJsonObject(); + final ReplicationLoggerStateEntity entity = deserializeBaseParameter(obj, + new ReplicationLoggerStateEntity()); if (obj.has(STATE)) { entity.state = context.deserialize(obj.get(STATE), ReplicationState.class); } if (obj.has(SERVER)) { - JsonObject server = obj.getAsJsonObject(SERVER); + final JsonObject server = obj.getAsJsonObject(SERVER); entity.serverVersion = server.getAsJsonPrimitive(VERSION).getAsString(); entity.serverId = server.getAsJsonPrimitive("serverId").getAsString(); } @@ -1848,16 +1930,16 @@ public static class ReplicationLoggerStateEntityClientDeserializer implements JsonDeserializer { @Override public ReplicationLoggerStateEntity.Client deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - Client client = new Client(); + final JsonObject obj = json.getAsJsonObject(); + final Client client = new Client(); if (obj.has("serverId")) { client.serverId = obj.getAsJsonPrimitive("serverId").getAsString(); @@ -1877,16 +1959,19 @@ public ReplicationLoggerStateEntity.Client deserialize( public static class GraphEntityDeserializer implements JsonDeserializer { @Override - public GraphEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public GraphEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - GraphEntity entity = deserializeBaseParameter(obj, new GraphEntity()); + final JsonObject obj = json.getAsJsonObject(); + final GraphEntity entity = deserializeBaseParameter(obj, new GraphEntity()); - JsonObject graph = obj.has("graph") ? obj.getAsJsonObject("graph") : obj; + final JsonObject graph = obj.has("graph") ? obj.getAsJsonObject("graph") : obj; deserializeDocumentParameter(graph, entity); if (graph.has("name")) { @@ -1894,12 +1979,12 @@ public GraphEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializati } if (graph.has("orphanCollections")) { - JsonArray orphanCollections = graph.getAsJsonArray("orphanCollections"); + final JsonArray orphanCollections = graph.getAsJsonArray("orphanCollections"); entity.orphanCollections = new ArrayList(); if (orphanCollections != null) { entity.orphanCollections = new ArrayList(orphanCollections.size()); for (int i = 0, imax = orphanCollections.size(); i < imax; i++) { - String orphanCollection = orphanCollections.get(i).getAsString(); + final String orphanCollection = orphanCollections.get(i).getAsString(); entity.orphanCollections.add(orphanCollection); } @@ -1907,7 +1992,7 @@ public GraphEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializati } if (graph.has("edgeDefinitions")) { - JsonArray edgeDefinitions = graph.getAsJsonArray("edgeDefinitions"); + final JsonArray edgeDefinitions = graph.getAsJsonArray("edgeDefinitions"); entity.edgeDefinitionsEntity = new EdgeDefinitionsEntity(); if (edgeDefinitions != null) { addEdgeDefinitions(entity, edgeDefinitions); @@ -1918,32 +2003,32 @@ public GraphEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializati } - private void addEdgeDefinitions(GraphEntity entity, JsonArray edgeDefinitions) { + private void addEdgeDefinitions(final GraphEntity entity, final JsonArray edgeDefinitions) { for (int i = 0, imax = edgeDefinitions.size(); i < imax; i++) { - EdgeDefinitionEntity edgeDefinitionEntity = new EdgeDefinitionEntity(); - JsonObject edgeDefinition = edgeDefinitions.get(i).getAsJsonObject(); + final EdgeDefinitionEntity edgeDefinitionEntity = new EdgeDefinitionEntity(); + final JsonObject edgeDefinition = edgeDefinitions.get(i).getAsJsonObject(); if (edgeDefinition.has("collection")) { edgeDefinitionEntity.setCollection(edgeDefinition.get("collection").getAsString()); } if (edgeDefinition.has("from")) { - List from = new ArrayList(); - JsonElement fromElem = edgeDefinition.get("from"); - JsonArray fromArray = fromElem.getAsJsonArray(); - Iterator iterator = fromArray.iterator(); + final List from = new ArrayList(); + final JsonElement fromElem = edgeDefinition.get("from"); + final JsonArray fromArray = fromElem.getAsJsonArray(); + final Iterator iterator = fromArray.iterator(); while (iterator.hasNext()) { - JsonElement e = iterator.next(); + final JsonElement e = iterator.next(); from.add(e.getAsString()); } edgeDefinitionEntity.setFrom(from); } if (edgeDefinition.has("to")) { - List to = new ArrayList(); - JsonElement toElem = edgeDefinition.get("to"); - JsonArray toArray = toElem.getAsJsonArray(); - Iterator iterator = toArray.iterator(); + final List to = new ArrayList(); + final JsonElement toElem = edgeDefinition.get("to"); + final JsonArray toArray = toElem.getAsJsonArray(); + final Iterator iterator = toArray.iterator(); while (iterator.hasNext()) { - JsonElement e = iterator.next(); + final JsonElement e = iterator.next(); to.add(e.getAsString()); } edgeDefinitionEntity.setTo(to); @@ -1954,18 +2039,21 @@ private void addEdgeDefinitions(GraphEntity entity, JsonArray edgeDefinitions) { } public static class GraphsEntityDeserializer implements JsonDeserializer { - private Type graphsType = new TypeToken>() { + private final Type graphsType = new TypeToken>() { }.getType(); @Override - public GraphsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public GraphsEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - GraphsEntity entity = deserializeBaseParameter(obj, new GraphsEntity()); + final JsonObject obj = json.getAsJsonObject(); + final GraphsEntity entity = deserializeBaseParameter(obj, new GraphsEntity()); if (obj.has("graphs")) { entity.graphs = context.deserialize(obj.get("graphs"), graphsType); @@ -1978,14 +2066,17 @@ public GraphsEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializat public static class DeleteEntityDeserializer implements JsonDeserializer { @Override - public DeletedEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public DeletedEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - DeletedEntity entity = deserializeBaseParameter(obj, new DeletedEntity()); + final JsonObject obj = json.getAsJsonObject(); + final DeletedEntity entity = deserializeBaseParameter(obj, new DeletedEntity()); if (obj.has(DELETED)) { entity.deleted = obj.getAsJsonPrimitive(DELETED).getAsBoolean(); @@ -2001,19 +2092,22 @@ public DeletedEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializa public static class VertexEntityDeserializer implements JsonDeserializer> { @Override - public VertexEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public VertexEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - VertexEntity entity = deserializeBaseParameter(obj, new VertexEntity()); + final JsonObject obj = json.getAsJsonObject(); + final VertexEntity entity = deserializeBaseParameter(obj, new VertexEntity()); - JsonObject vertex = obj.has("vertex") ? obj.getAsJsonObject("vertex") : obj; + final JsonObject vertex = obj.has("vertex") ? obj.getAsJsonObject("vertex") : obj; deserializeDocumentParameter(vertex, entity); - Class clazz = getParameterized(); + final Class clazz = getParameterized(); if (clazz != null) { entity.setEntity(context.deserialize(vertex, clazz)); } @@ -2024,16 +2118,19 @@ public VertexEntity deserialize(JsonElement json, Type typeOfT, JsonDeseriali public static class EdgeEntityDeserializer implements JsonDeserializer> { @Override - public EdgeEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public EdgeEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - EdgeEntity entity = deserializeBaseParameter(obj, new EdgeEntity()); + final JsonObject obj = json.getAsJsonObject(); + final EdgeEntity entity = deserializeBaseParameter(obj, new EdgeEntity()); - JsonObject edge = obj.has("edge") ? obj.getAsJsonObject("edge") : obj; + final JsonObject edge = obj.has("edge") ? obj.getAsJsonObject("edge") : obj; deserializeDocumentParameter(edge, entity); if (edge.has("_from")) { @@ -2044,7 +2141,7 @@ public EdgeEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializa } // 他のフィールドはリフレクションで。 (TODO: Annotationのサポートと上記パラメータを弾く) - Class clazz = getParameterized(); + final Class clazz = getParameterized(); if (clazz != null) { entity.entity = context.deserialize(edge, clazz); } @@ -2057,22 +2154,25 @@ public EdgeEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializa public static class TraversalEntityDeserializer implements JsonDeserializer> { @Override - public TraversalEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public TraversalEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - TraversalEntity entity = deserializeBaseParameter(obj, + final JsonObject obj = json.getAsJsonObject(); + final TraversalEntity entity = deserializeBaseParameter(obj, new TraversalEntity()); deserializeBaseParameter(obj, entity); - JsonObject result = getFirstResultAsJsonObject(obj); + final JsonObject result = getFirstResultAsJsonObject(obj); if (result != null && result.getAsJsonObject().has("visited")) { - JsonObject visited = result.getAsJsonObject().getAsJsonObject("visited"); + final JsonObject visited = result.getAsJsonObject().getAsJsonObject("visited"); - Class vertexClazz = getParameterized(); + final Class vertexClazz = getParameterized(); Class edgeClazz = null; if (hasNextParameterized()) { @@ -2091,16 +2191,16 @@ public static class TraversalEntityDeserializer implements JsonDeserializer> getPaths( - JsonDeserializationContext context, - JsonObject visited, - Class vertexClazz, - Class edgeClazz) { - List> pathEntities = new ArrayList>(); - JsonArray paths = visited.getAsJsonArray(PATHS); + final JsonDeserializationContext context, + final JsonObject visited, + final Class vertexClazz, + final Class edgeClazz) { + final List> pathEntities = new ArrayList>(); + final JsonArray paths = visited.getAsJsonArray(PATHS); if (paths != null) { for (int i = 0, imax = paths.size(); i < imax; i++) { - JsonObject path = paths.get(i).getAsJsonObject(); - PathEntity pathEntity = new PathEntity(); + final JsonObject path = paths.get(i).getAsJsonObject(); + final PathEntity pathEntity = new PathEntity(); if (path.has(EDGES)) { pathEntity.setEdges(getEdges(edgeClazz, context, path.getAsJsonArray(EDGES))); @@ -2120,22 +2220,22 @@ private List> getPaths( public static class ShortestPathEntityDeserializer implements JsonDeserializer> { @Override public ShortestPathEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - ShortestPathEntity entity = deserializeBaseParameter(obj, + final JsonObject obj = json.getAsJsonObject(); + final ShortestPathEntity entity = deserializeBaseParameter(obj, new ShortestPathEntity()); deserializeBaseParameter(obj, entity); - JsonObject result = getFirstResultAsJsonObject(obj); + final JsonObject result = getFirstResultAsJsonObject(obj); if (result != null) { - Class vertexClazz = getParameterized(); + final Class vertexClazz = getParameterized(); Class edgeClazz = null; if (hasNextParameterized()) { @@ -2167,14 +2267,14 @@ public static class ShortestPathEntityDeserializer implements JsonDeserializer entity, - JsonObject result, - Class vertexClazz, - Class edgeClazz) { - JsonArray paths = result.getAsJsonArray(PATHS); + final JsonDeserializationContext context, + final ShortestPathEntity entity, + final JsonObject result, + final Class vertexClazz, + final Class edgeClazz) { + final JsonArray paths = result.getAsJsonArray(PATHS); if (paths != null && paths.size() > 0) { - JsonObject path = paths.get(0).getAsJsonObject(); + final JsonObject path = paths.get(0).getAsJsonObject(); if (path.has(EDGES)) { entity.setEdges(getEdges(edgeClazz, context, path.getAsJsonArray(EDGES))); @@ -2190,16 +2290,16 @@ public static class QueryCachePropertiesEntityDeserializer implements JsonDeseri @Override public QueryCachePropertiesEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - QueryCachePropertiesEntity entity = deserializeBaseParameter(obj, new QueryCachePropertiesEntity()); + final JsonObject obj = json.getAsJsonObject(); + final QueryCachePropertiesEntity entity = deserializeBaseParameter(obj, new QueryCachePropertiesEntity()); if (obj.has("mode")) { entity.setMode(obj.getAsJsonPrimitive("mode").getAsString()); @@ -2217,19 +2317,22 @@ public QueryCachePropertiesEntity deserialize( public static class QueriesResultEntityDeserializer implements JsonDeserializer { @Override - public QueriesResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + public QueriesResultEntity deserialize( + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonArray array = json.getAsJsonArray(); - Iterator iterator = array.iterator(); - List queries = new ArrayList(); + final JsonArray array = json.getAsJsonArray(); + final Iterator iterator = array.iterator(); + final List queries = new ArrayList(); while (iterator.hasNext()) { - JsonElement element = iterator.next(); - JsonObject obj = element.getAsJsonObject(); - QueryEntity entity = new QueryEntity(); + final JsonElement element = iterator.next(); + final JsonObject obj = element.getAsJsonObject(); + final QueryEntity entity = new QueryEntity(); if (obj.has(ID)) { entity.setId(obj.getAsJsonPrimitive(ID).getAsString()); @@ -2241,12 +2344,12 @@ public QueriesResultEntity deserialize(JsonElement json, Type typeOfT, JsonDeser } if (obj.has("started")) { - String str = obj.getAsJsonPrimitive("started").getAsString(); + final String str = obj.getAsJsonPrimitive("started").getAsString(); - SimpleDateFormat sdf = new SimpleDateFormat(ALT_DATE_TIME_FORMAT); + final SimpleDateFormat sdf = new SimpleDateFormat(ALT_DATE_TIME_FORMAT); try { entity.setStarted(sdf.parse(str)); - } catch (ParseException e) { + } catch (final ParseException e) { logger.debug("got ParseException for date string: " + str); } } @@ -2266,16 +2369,17 @@ public static class QueryTrackingPropertiesEntityDeserializer @Override public QueryTrackingPropertiesEntity deserialize( - JsonElement json, - Type typeOfT, - JsonDeserializationContext context) { + final JsonElement json, + final Type typeOfT, + final JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } - JsonObject obj = json.getAsJsonObject(); - QueryTrackingPropertiesEntity entity = deserializeBaseParameter(obj, new QueryTrackingPropertiesEntity()); + final JsonObject obj = json.getAsJsonObject(); + final QueryTrackingPropertiesEntity entity = deserializeBaseParameter(obj, + new QueryTrackingPropertiesEntity()); if (obj.has("enabled")) { entity.setEnabled(obj.getAsJsonPrimitive("enabled").getAsBoolean()); @@ -2302,7 +2406,7 @@ public QueryTrackingPropertiesEntity deserialize( } - private static JsonObject getFirstResultAsJsonObject(JsonObject obj) { + private static JsonObject getFirstResultAsJsonObject(final JsonObject obj) { if (obj.has(RESULT)) { if (obj.get(RESULT).isJsonArray()) { return getElementAsJsonObject(obj.getAsJsonArray(RESULT)); @@ -2313,9 +2417,9 @@ private static JsonObject getFirstResultAsJsonObject(JsonObject obj) { return null; } - private static JsonObject getElementAsJsonObject(JsonArray arr) { + private static JsonObject getElementAsJsonObject(final JsonArray arr) { if (arr != null && arr.size() > 0) { - JsonElement jsonElement = arr.get(0); + final JsonElement jsonElement = arr.get(0); if (jsonElement.isJsonObject()) { return jsonElement.getAsJsonObject(); } @@ -2324,14 +2428,14 @@ private static JsonObject getElementAsJsonObject(JsonArray arr) { } private static List> getVertices( - Class vertexClazz, - JsonDeserializationContext context, - JsonArray vertices) { - List> list = new ArrayList>(); + final Class vertexClazz, + final JsonDeserializationContext context, + final JsonArray vertices) { + final List> list = new ArrayList>(); if (vertices != null) { for (int i = 0, imax = vertices.size(); i < imax; i++) { - JsonObject vertex = vertices.get(i).getAsJsonObject(); - VertexEntity ve = getVertex(context, vertex, vertexClazz); + final JsonObject vertex = vertices.get(i).getAsJsonObject(); + final VertexEntity ve = getVertex(context, vertex, vertexClazz); list.add(ve); } } @@ -2339,10 +2443,10 @@ private static List> getVertices( } private static VertexEntity getVertex( - JsonDeserializationContext context, - JsonObject vertex, - Class vertexClazz) { - VertexEntity ve = deserializeBaseParameter(vertex, new VertexEntity()); + final JsonDeserializationContext context, + final JsonObject vertex, + final Class vertexClazz) { + final VertexEntity ve = deserializeBaseParameter(vertex, new VertexEntity()); deserializeDocumentParameter(vertex, ve); if (vertexClazz != null) { ve.setEntity(context.deserialize(vertex, vertexClazz)); @@ -2353,14 +2457,14 @@ private static VertexEntity getVertex( } private static List> getEdges( - Class edgeClazz, - JsonDeserializationContext context, - JsonArray edges) { - List> list = new ArrayList>(); + final Class edgeClazz, + final JsonDeserializationContext context, + final JsonArray edges) { + final List> list = new ArrayList>(); if (edges != null) { for (int i = 0, imax = edges.size(); i < imax; i++) { - JsonObject edge = edges.get(i).getAsJsonObject(); - EdgeEntity ve = deserializeBaseParameter(edge, new EdgeEntity()); + final JsonObject edge = edges.get(i).getAsJsonObject(); + final EdgeEntity ve = deserializeBaseParameter(edge, new EdgeEntity()); deserializeDocumentParameter(edge, ve); if (edgeClazz != null) { ve.setEntity(context.deserialize(edge, edgeClazz)); From 706943180ae70dec149a30abf61ea5f23ccf7ff1 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 27 May 2016 09:38:35 +0200 Subject: [PATCH 16/56] refactoring --- .../java/com/arangodb/ArangoConfigure.java | 16 ++++++------- .../java/com/arangodb/http/HttpManager.java | 3 ++- .../impl/InternalDocumentDriverImpl.java | 24 ------------------- .../impl/InternalIndexDriverImpl.java | 1 - .../arangodb/ArangoDriverDocumentTest.java | 6 ++--- 5 files changed, 12 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoConfigure.java b/src/main/java/com/arangodb/ArangoConfigure.java index 34fa09b0e..319b95064 100644 --- a/src/main/java/com/arangodb/ArangoConfigure.java +++ b/src/main/java/com/arangodb/ArangoConfigure.java @@ -95,7 +95,7 @@ public class ArangoConfigure { private boolean enableCURLLogger = false; - private boolean staleConnectionCheck = false; + private int validateAfterInactivity = -1; private boolean useSsl = false; @@ -257,9 +257,9 @@ private void loadProperties(InputStream in) throws IOException { setEnableCURLLogger(Boolean.parseBoolean(enableCURLLoggerProperty)); } - String staleConnectionCheckProperty = prop.getProperty("staleConnectionCheck"); - if (staleConnectionCheckProperty != null) { - setStaleConnectionCheck(Boolean.parseBoolean(staleConnectionCheckProperty)); + String validateAfterInactivityProperty = prop.getProperty("validateAfterInactivity"); + if (validateAfterInactivityProperty != null) { + setValidateAfterInactivity(Integer.parseInt(validateAfterInactivityProperty)); } String batchSizeProperty = prop.getProperty("batchSize"); @@ -562,12 +562,12 @@ public void setEnableCURLLogger(boolean enableCURLLogger) { this.enableCURLLogger = enableCURLLogger; } - public boolean isStaleConnectionCheck() { - return staleConnectionCheck; + public int getValidateAfterInactivity() { + return validateAfterInactivity; } - public void setStaleConnectionCheck(boolean staleConnectionCheck) { - this.staleConnectionCheck = staleConnectionCheck; + public void setValidateAfterInactivity(int validateAfterInactivity) { + this.validateAfterInactivity = validateAfterInactivity; } public int getConnectRetryCount() { diff --git a/src/main/java/com/arangodb/http/HttpManager.java b/src/main/java/com/arangodb/http/HttpManager.java index 0e62818f8..846985d00 100644 --- a/src/main/java/com/arangodb/http/HttpManager.java +++ b/src/main/java/com/arangodb/http/HttpManager.java @@ -139,7 +139,8 @@ public void init() { custom.setConnectionRequestTimeout(configure.getTimeout()); custom.setSocketTimeout(configure.getTimeout()); } - custom.setStaleConnectionCheckEnabled(configure.isStaleConnectionCheck()); + + cm.setValidateAfterInactivity(configure.getValidateAfterInactivity()); final RequestConfig requestConfig = custom.build(); diff --git a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java index a613e96b4..16745a767 100644 --- a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java @@ -17,10 +17,7 @@ package com.arangodb.impl; import java.util.List; -import java.util.ListIterator; import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import com.arangodb.ArangoConfigure; import com.arangodb.ArangoException; @@ -42,12 +39,6 @@ public class InternalDocumentDriverImpl extends BaseArangoDriverImpl implements private static final String WAIT_FOR_SYNC = "waitForSync"; - private static final String POLICY = "policy"; - - private static final String API_DOCUMENT_PREFIX = "/_api/document/"; - - private static final Pattern pattern = Pattern.compile("^/_db/.*/_api/document/(.*)$"); - InternalDocumentDriverImpl(final ArangoConfigure configure, final HttpManager httpManager) { super(configure, httpManager); } @@ -200,21 +191,6 @@ public List getDocuments(final String database, final String collectionN return tmp.getResults(); } - private void updateDocumentHandles(final List documents) { - final ListIterator lit = documents.listIterator(); - while (lit.hasNext()) { - final String d = lit.next(); - if (d.startsWith(API_DOCUMENT_PREFIX)) { - lit.set(d.substring(API_DOCUMENT_PREFIX.length())); - } else { - final Matcher matcher = pattern.matcher(d); - if (matcher.find()) { - lit.set(matcher.group(1)); - } - } - } - } - @Override public long checkDocument(final String database, final String documentHandle) throws ArangoException { validateDocumentHandle(documentHandle); diff --git a/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java b/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java index e897f4e5c..c82b1cc0c 100644 --- a/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java @@ -35,7 +35,6 @@ public class InternalIndexDriverImpl extends BaseArangoDriverWithCursorImpl implements com.arangodb.InternalIndexDriver { - private static final String SIZE = "size"; private static final String FIELDS = "fields"; private static final String SPARSE = "sparse"; private static final String UNIQUE = "unique"; diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java index b4cf05b4f..8fdb97a9f 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentTest.java @@ -52,8 +52,6 @@ public class ArangoDriverDocumentTest extends BaseTest { private final String collectionName2 = "unit_test_arango_002"; private final String collectionName404 = "unit_test_arango_404"; // 存在しないコレクション名 - private CollectionEntity col1; - private CollectionEntity col2; private TestInterfaceInstanceCreator testInstanceCreator; @Before @@ -70,8 +68,8 @@ public void before() throws ArangoException { } // 1と2は作る - col1 = driver.createCollection(collectionName); - col2 = driver.createCollection(collectionName2); + driver.createCollection(collectionName); + driver.createCollection(collectionName2); // configure Gson to use our instance creator whenever documents of // TestInterface are requested From 11ec023d5ebd44d682c063870ca05538adc4453a Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 27 May 2016 10:07:17 +0200 Subject: [PATCH 17/56] changed to nightly --- tests/travis/setup_arangodb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/travis/setup_arangodb.sh b/tests/travis/setup_arangodb.sh index f481be795..a4e50b8b7 100644 --- a/tests/travis/setup_arangodb.sh +++ b/tests/travis/setup_arangodb.sh @@ -3,7 +3,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR -VERSION=3.0.0 +VERSION=devel-nightly NAME=ArangoDB-$VERSION if [ ! -d "$DIR/$NAME" ]; then @@ -31,7 +31,7 @@ ${ARANGOD} \ --configuration none \ --server.endpoint tcp://127.0.0.1:8529 \ --server.endpoint ssl://127.0.0.1:8530 \ - --server.keyfile ./server.pem \ + --ssl.keyfile ./server.pem \ --javascript.app-path ${ARANGODB_DIR}/js/apps \ --javascript.startup-directory ${ARANGODB_DIR}/js \ --server.authentication=true & From 51249039fdef7190cf0fe95fa72952da19c0d506 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 27 May 2016 10:10:19 +0200 Subject: [PATCH 18/56] changed to nightly2 --- tests/travis/setup_arangodb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/travis/setup_arangodb.sh b/tests/travis/setup_arangodb.sh index a4e50b8b7..a4c6ce749 100644 --- a/tests/travis/setup_arangodb.sh +++ b/tests/travis/setup_arangodb.sh @@ -8,8 +8,8 @@ NAME=ArangoDB-$VERSION if [ ! -d "$DIR/$NAME" ]; then # download ArangoDB - echo "wget https://www.arangodb.com/repositories/travisCI/$NAME.tar.gz" - wget https://www.arangodb.com/repositories/travisCI/$NAME.tar.gz + echo "wget https://www.arangodb.com/repositories/nightly/travisCI/$NAME.tar.gz" + wget https://www.arangodb.com/repositories/nightly/travisCI/$NAME.tar.gz echo "tar zxf $NAME.tar.gz" tar zvxf $NAME.tar.gz fi From e4d05cbcb8284d4028abebf31de15283cc0b224c Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 27 May 2016 10:44:34 +0200 Subject: [PATCH 19/56] chnaged docu --- src/main/java/com/arangodb/ArangoDriver.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index f0c446254..948df639a 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -3052,8 +3052,7 @@ public ScalarExampleEntity executeSimpleAny(final String collectionName, } /** - * This will find all documents within a given range. In order to execute a - * range query, a skip-list index on the queried attribute must be present. + * This will find all documents within a given range. * * @param collectionName * The collection name. From d81b50bf95fd460e21a2d0b94756f608d9bebbd1 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 27 May 2016 10:44:54 +0200 Subject: [PATCH 20/56] removed a test --- .../com/arangodb/ArangoDriverSimpleTest.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java index 40910b0f7..f4be258ab 100644 --- a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java +++ b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java @@ -22,7 +22,6 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; import java.io.IOException; import java.util.Iterator; @@ -155,21 +154,6 @@ public void test_any() throws ArangoException { } } - @Test - public void test_range_no_skiplist() throws ArangoException { - - // no suitable index known - try { - driver.executeSimpleRangeWithDocuments(COLLECTION_NAME, "age", 5, 30, null, 0, 0, - TestComplexEntity01.class); - fail("request should fail"); - } catch (final ArangoException e) { - assertThat(e.getErrorNumber(), is(1209)); - assertThat(e.getCode(), is(404)); - } - - } - @Test public void test_range() throws ArangoException { From 1d3fc21fa33010cc18a8ae91859420b2d9c45e51 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 27 May 2016 11:04:30 +0200 Subject: [PATCH 21/56] changed Build Status icon --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 093c7332c..2c3e7d4bb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # arangodb-java-driver -[![Build Status](https://secure.travis-ci.org/arangodb/arangodb-java-driver.png)](http://travis-ci.org/arangodb/arangodb-java-driver) +[![Build Status](https://travis-ci.org/arangodb/arangodb-java-driver.svg?branch=3.0)](https://travis-ci.org/arangodb/arangodb-java-driver) This library is a Java driver for ArangoDB. From ab7ee2075f9bbcfaa6322e3567b1b6a681b814c6 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 7 Jun 2016 15:31:29 +0200 Subject: [PATCH 22/56] Edge Test added --- .../com/arangodb/ArangoDriverEdgeTest.java | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/test/java/com/arangodb/ArangoDriverEdgeTest.java diff --git a/src/test/java/com/arangodb/ArangoDriverEdgeTest.java b/src/test/java/com/arangodb/ArangoDriverEdgeTest.java new file mode 100644 index 000000000..5cc963699 --- /dev/null +++ b/src/test/java/com/arangodb/ArangoDriverEdgeTest.java @@ -0,0 +1,77 @@ +package com.arangodb; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.CollectionOptions; +import com.arangodb.entity.CollectionType; +import com.arangodb.entity.DocumentEntity; + +/** + * @author Mark - mark@arangodb.com + * + */ +public class ArangoDriverEdgeTest extends BaseTest { + + final String collectionName = "unit_test_edge_collection_EdgeTest"; + final String collectionName2 = "unit_test_normal_collection_EdgeTest"; + + @Before + public void before() throws ArangoException { + try { + driver.deleteCollection(collectionName); + } catch (final ArangoException e) { + } + try { + final CollectionOptions collectionOptions = new CollectionOptions(); + collectionOptions.setType(CollectionType.EDGE); + driver.createCollection(collectionName, collectionOptions); + } catch (final ArangoException e) { + } + try { + driver.deleteCollection(collectionName2); + } catch (final ArangoException e) { + } + try { + driver.createCollection(collectionName2); + } catch (final ArangoException e) { + } + } + + @After + public void after() throws ArangoException { + try { + driver.deleteCollection(collectionName); + } catch (final ArangoException e) { + } + try { + driver.deleteCollection(collectionName2); + } catch (final ArangoException e) { + } + } + + @Test + public void test_create_normal() throws ArangoException { + + final TestComplexEntity01 value = new TestComplexEntity01("user", "desc", 42); + final DocumentEntity fromDoc = driver.createDocument(collectionName2, value, true); + final DocumentEntity toDoc = driver.createDocument(collectionName2, value, true); + + final BaseDocument baseDocument = new BaseDocument(); + baseDocument.addAttribute(BaseDocument.FROM, fromDoc.getDocumentHandle()); + baseDocument.addAttribute(BaseDocument.TO, toDoc.getDocumentHandle()); + + final DocumentEntity doc = driver.createDocument(collectionName, baseDocument, true); + + Assert.assertNotNull(doc.getDocumentKey()); + Assert.assertEquals(collectionName + "/" + doc.getDocumentKey(), doc.getDocumentHandle()); + Assert.assertNotEquals(0L, doc.getDocumentRevision()); + Assert.assertEquals(fromDoc.getDocumentHandle(), doc.getEntity().getAttribute(BaseDocument.FROM)); + Assert.assertEquals(toDoc.getDocumentHandle(), doc.getEntity().getAttribute(BaseDocument.TO)); + + } + +} \ No newline at end of file From f445ef55b2214c123e4cef27f186304adad7a1fb Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 7 Jun 2016 16:11:06 +0200 Subject: [PATCH 23/56] remove deprecated methods --- .../java/com/arangodb/ArangoConfigure.java | 196 ++-- src/main/java/com/arangodb/ArangoDriver.java | 865 ++---------------- .../com/arangodb/InternalCursorDriver.java | 29 - .../com/arangodb/InternalGraphDriver.java | 36 - .../com/arangodb/InternalSimpleDriver.java | 158 ---- .../java/com/arangodb/entity/Direction.java | 32 - .../impl/InternalCursorDriverImpl.java | 189 ++-- .../impl/InternalGraphDriverImpl.java | 381 ++++---- .../impl/InternalSimpleDriverImpl.java | 483 +++------- .../com/arangodb/util/ResultSetUtils.java | 50 - .../ArangoDriverCursorResultSetTest.java | 79 +- .../com/arangodb/ArangoDriverCursorTest.java | 53 +- .../ArangoDriverGraphEdgesGetTest.java | 37 +- .../arangodb/ArangoDriverSimpleGeoTest.java | 70 -- .../com/arangodb/ArangoDriverSimpleTest.java | 25 +- 15 files changed, 576 insertions(+), 2107 deletions(-) delete mode 100644 src/main/java/com/arangodb/entity/Direction.java delete mode 100644 src/main/java/com/arangodb/util/ResultSetUtils.java delete mode 100644 src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java diff --git a/src/main/java/com/arangodb/ArangoConfigure.java b/src/main/java/com/arangodb/ArangoConfigure.java index 319b95064..da1080c32 100644 --- a/src/main/java/com/arangodb/ArangoConfigure.java +++ b/src/main/java/com/arangodb/ArangoConfigure.java @@ -114,13 +114,13 @@ public ArangoConfigure() { init(DEFAULT_PROPERTY_FILE); } - public ArangoConfigure(String propertyPath) { + public ArangoConfigure(final String propertyPath) { init(propertyPath); } - private void init(String propertyPath) { + private void init(final String propertyPath) { arangoHosts = new ArrayList(); - ArangoHost defaultHost = new ArangoHost(DEFAULT_HOST, DEFAULT_PORT); + final ArangoHost defaultHost = new ArangoHost(DEFAULT_HOST, DEFAULT_PORT); arangoHosts.add(defaultHost); currentArangoHost = 0; @@ -141,7 +141,7 @@ public void loadProperties() { * * @param propertyPath */ - public void loadProperties(String propertyPath) { + public void loadProperties(final String propertyPath) { InputStream in = null; try { in = getClass().getResourceAsStream(propertyPath); @@ -150,7 +150,7 @@ public void loadProperties(String propertyPath) { loadProperties(in); } - } catch (IOException e) { + } catch (final IOException e) { logger.warn("load property error", e); } finally { if (in != null) { @@ -159,131 +159,131 @@ public void loadProperties(String propertyPath) { } } - private void loadProperties(InputStream in) throws IOException { + private void loadProperties(final InputStream in) throws IOException { - Properties prop = new Properties(); + final Properties prop = new Properties(); prop.load(in); // - String port = prop.getProperty("port"); + final String port = prop.getProperty("port"); if (port != null) { arangoHosts.get(0).setPort(Integer.parseInt(port)); } - String host = prop.getProperty("host"); + final String host = prop.getProperty("host"); if (host != null) { arangoHosts.get(0).setHost(host); } - String arangoHost = prop.getProperty("arangoHost"); + final String arangoHost = prop.getProperty("arangoHost"); if (arangoHost != null) { - ArangoHost ah = parseArangoHost(arangoHost); + final ArangoHost ah = parseArangoHost(arangoHost); if (ah != null) { arangoHosts.get(0).setHost(ah.getHost()); arangoHosts.get(0).setPort(ah.getPort()); } } - String fallbackArangoHost = prop.getProperty("fallbackArangoHost"); + final String fallbackArangoHost = prop.getProperty("fallbackArangoHost"); if (fallbackArangoHost != null) { - ArangoHost ah = parseArangoHost(fallbackArangoHost); + final ArangoHost ah = parseArangoHost(fallbackArangoHost); if (ah != null) { addFallbackArangoHost(ah); } } - String timeoutProperty = prop.getProperty("timeout"); + final String timeoutProperty = prop.getProperty("timeout"); if (timeoutProperty != null) { setTimeout(Integer.parseInt(timeoutProperty)); } - String connectionTimeoutProperty = prop.getProperty("connectionTimeout"); + final String connectionTimeoutProperty = prop.getProperty("connectionTimeout"); if (connectionTimeoutProperty != null) { setConnectionTimeout(Integer.parseInt(connectionTimeoutProperty)); } - String proxyHostProperty = prop.getProperty("proxy.host"); + final String proxyHostProperty = prop.getProperty("proxy.host"); if (proxyHostProperty != null) { setProxyHost(proxyHostProperty); } - String proxyPortProperty = prop.getProperty("proxy.port"); + final String proxyPortProperty = prop.getProperty("proxy.port"); if (proxyPortProperty != null) { setProxyPort(Integer.parseInt(proxyPortProperty)); } - String maxPerConnectionProperty = prop.getProperty("maxPerConnection"); + final String maxPerConnectionProperty = prop.getProperty("maxPerConnection"); if (maxPerConnectionProperty != null) { setMaxPerConnection(Integer.parseInt(maxPerConnectionProperty)); } - String maxTotalConnectionProperty = prop.getProperty("maxTotalConnection"); + final String maxTotalConnectionProperty = prop.getProperty("maxTotalConnection"); if (maxTotalConnectionProperty != null) { setMaxTotalConnection(Integer.parseInt(maxTotalConnectionProperty)); } - String retryCountProperty = prop.getProperty("retryCount"); + final String retryCountProperty = prop.getProperty("retryCount"); if (retryCountProperty != null) { setRetryCount(Integer.parseInt(retryCountProperty)); } - String connnectRetryCount = prop.getProperty("connnectRetryCount"); + final String connnectRetryCount = prop.getProperty("connnectRetryCount"); if (connnectRetryCount != null) { setConnectRetryCount(Integer.parseInt(connnectRetryCount)); } - String connectRetryWaitProperty = prop.getProperty("connectRetryWait"); + final String connectRetryWaitProperty = prop.getProperty("connectRetryWait"); if (connectRetryWaitProperty != null) { setConnectRetryWait(Integer.parseInt(connectRetryWaitProperty)); } - String userProperty = prop.getProperty("user"); + final String userProperty = prop.getProperty("user"); if (userProperty != null) { setUser(userProperty); } - String passwordProperty = prop.getProperty("password"); + final String passwordProperty = prop.getProperty("password"); if (passwordProperty != null) { setPassword(passwordProperty); } - String defaultDatabaseProperty = prop.getProperty("defaultDatabase"); + final String defaultDatabaseProperty = prop.getProperty("defaultDatabase"); if (defaultDatabaseProperty != null) { setDefaultDatabase(defaultDatabaseProperty); } - String enableCURLLoggerProperty = prop.getProperty("enableCURLLogger"); + final String enableCURLLoggerProperty = prop.getProperty("enableCURLLogger"); if (enableCURLLoggerProperty != null) { setEnableCURLLogger(Boolean.parseBoolean(enableCURLLoggerProperty)); } - String validateAfterInactivityProperty = prop.getProperty("validateAfterInactivity"); + final String validateAfterInactivityProperty = prop.getProperty("validateAfterInactivity"); if (validateAfterInactivityProperty != null) { setValidateAfterInactivity(Integer.parseInt(validateAfterInactivityProperty)); } - String batchSizeProperty = prop.getProperty("batchSize"); + final String batchSizeProperty = prop.getProperty("batchSize"); if (batchSizeProperty != null) { setBatchSize(Integer.parseInt(batchSizeProperty)); } - String useSslProperty = prop.getProperty("useSsl"); + final String useSslProperty = prop.getProperty("useSsl"); if (useSslProperty != null) { setUseSsl(Boolean.parseBoolean(useSslProperty)); } - String sslTrustStoreProperty = prop.getProperty("sslTrustStore"); + final String sslTrustStoreProperty = prop.getProperty("sslTrustStore"); if (sslTrustStoreProperty != null) { setSslTrustStore(sslTrustStoreProperty); } } - private ArangoHost parseArangoHost(String str) { + private ArangoHost parseArangoHost(final String str) { if (str == null) { return null; } - String[] split = str.split(":", 2); + final String[] split = str.split(":", 2); if (split.length != 2) { return null; } @@ -304,13 +304,13 @@ public void shutdown() { } public String getBaseUrl() { - ArangoHost currentHost = getCurrentHost(); + final ArangoHost currentHost = getCurrentHost(); return (useSsl ? "https://" : "http://") + currentHost.getHost() + ":" + currentHost.getPort(); } public String getEndpoint() { - ArangoHost currentHost = getCurrentHost(); + final ArangoHost currentHost = getCurrentHost(); return (useSsl ? "ssl://" : "tcp://") + currentHost.getHost() + ":" + currentHost.getPort(); } @@ -345,45 +345,6 @@ public static int getDefaultMaxConnection() { return DEFAULT_MAX_CONNECTION; } - /** - * Get the server port number - * - * Don't use method. Please use {@link #getArangoHost() getArangoHost} - * - * @deprecated - * @return the port number - */ - @Deprecated - public int getClientPort() { - return arangoHosts.get(0).getPort(); - } - - /** - * Get the server port number - * - * Don't use method. Please use {@link #getArangoHost() getArangoHost} - * - * @deprecated - * @return the port number - */ - @Deprecated - public int getPort() { - return arangoHosts.get(0).getPort(); - } - - /** - * Get the database host name - * - * Don't use method. Please use {@link #getArangoHost() getArangoHost} - * - * @deprecated - * @return the host name - */ - @Deprecated - public String getHost() { - return arangoHosts.get(0).getHost(); - } - /** * Get the default database host name and port * @@ -417,59 +378,14 @@ public int getProxyPort() { return proxyPort; } - /** - * Set the port number of the database - * - * Don't use this method. Please use {@link #setArangoHost(ArangoHost) - * setArangoHost} - * - * @param clientPort - * the port number - * @deprecated - */ - @Deprecated - public void setClinetPort(int clientPort) { - arangoHosts.get(0).setPort(clientPort); - } - - /** - * Set the port number of the database - * - * Don't use this method. Please use {@link #setArangoHost(ArangoHost) - * setArangoHost} - * - * @deprecated - * @param port - * the port number - */ - @Deprecated - public void setPort(int port) { - arangoHosts.get(0).setPort(port); - } - - /** - * Set the host name of the database - * - * Don't use this method. Please use {@link #setArangoHost(ArangoHost) - * setArangoHost} - * - * @deprecated - * @param host - * the host name - */ - @Deprecated - public void setHost(String host) { - arangoHosts.get(0).setHost(host); - } - /** * Set the host name and port of the database * * @param arangoHost * the host name and port */ - public void setArangoHost(ArangoHost arangoHost) { - ArangoHost host = arangoHosts.get(0); + public void setArangoHost(final ArangoHost arangoHost) { + final ArangoHost host = arangoHosts.get(0); host.setHost(arangoHost.getHost()); host.setPort(arangoHost.getPort()); } @@ -480,31 +396,31 @@ public void setArangoHost(ArangoHost arangoHost) { * @param arangoHost * the host name and port */ - public void addFallbackArangoHost(ArangoHost arangoHost) { + public void addFallbackArangoHost(final ArangoHost arangoHost) { arangoHosts.add(arangoHost); } - public void setConnectionTimeout(int connectionTimeout) { + public void setConnectionTimeout(final int connectionTimeout) { this.connectionTimeout = connectionTimeout; } - public void setTimeout(int timeout) { + public void setTimeout(final int timeout) { this.timeout = timeout; } - public void setMaxTotalConnection(int maxTotalConnection) { + public void setMaxTotalConnection(final int maxTotalConnection) { this.maxTotalConnection = maxTotalConnection; } - public void setMaxPerConnection(int maxPerConnection) { + public void setMaxPerConnection(final int maxPerConnection) { this.maxPerConnection = maxPerConnection; } - public void setProxyHost(String proxyHost) { + public void setProxyHost(final String proxyHost) { this.proxyHost = proxyHost; } - public void setProxyPort(int proxyPort) { + public void setProxyPort(final int proxyPort) { this.proxyPort = proxyPort; } @@ -512,7 +428,7 @@ public int getRetryCount() { return retryCount; } - public void setRetryCount(int retryCount) { + public void setRetryCount(final int retryCount) { this.retryCount = retryCount; } @@ -520,7 +436,7 @@ public BatchHttpManager getHttpManager() { return httpManager; } - public void setHttpManager(BatchHttpManager httpManager) { + public void setHttpManager(final BatchHttpManager httpManager) { this.httpManager = httpManager; } @@ -532,11 +448,11 @@ public String getPassword() { return password; } - public void setUser(String user) { + public void setUser(final String user) { this.user = user; } - public void setPassword(String password) { + public void setPassword(final String password) { this.password = password; } @@ -550,7 +466,7 @@ public String getDefaultDatabase() { * * @param defaultDatabase */ - public void setDefaultDatabase(String defaultDatabase) { + public void setDefaultDatabase(final String defaultDatabase) { this.defaultDatabase = defaultDatabase; } @@ -558,7 +474,7 @@ public boolean isEnableCURLLogger() { return enableCURLLogger; } - public void setEnableCURLLogger(boolean enableCURLLogger) { + public void setEnableCURLLogger(final boolean enableCURLLogger) { this.enableCURLLogger = enableCURLLogger; } @@ -566,7 +482,7 @@ public int getValidateAfterInactivity() { return validateAfterInactivity; } - public void setValidateAfterInactivity(int validateAfterInactivity) { + public void setValidateAfterInactivity(final int validateAfterInactivity) { this.validateAfterInactivity = validateAfterInactivity; } @@ -580,7 +496,7 @@ public int getConnectRetryCount() { * @param connectRetryCount * number of connect retries */ - public void setConnectRetryCount(int connectRetryCount) { + public void setConnectRetryCount(final int connectRetryCount) { this.connectRetryCount = connectRetryCount; } @@ -594,7 +510,7 @@ public int getConnectRetryWait() { * @param connectRetryWait * milliseconds to wait */ - public void setConnectRetryWait(int connectRetryWait) { + public void setConnectRetryWait(final int connectRetryWait) { this.connectRetryWait = connectRetryWait; } @@ -602,7 +518,7 @@ public int getBatchSize() { return batchSize; } - public void setBatchSize(int batchSize) { + public void setBatchSize(final int batchSize) { this.batchSize = batchSize; } @@ -616,7 +532,7 @@ public boolean getUseSsl() { * @param useSsl * set true to use HTTPS (default false) */ - public void setUseSsl(boolean useSsl) { + public void setUseSsl(final boolean useSsl) { this.useSsl = useSsl; } @@ -631,7 +547,7 @@ public SSLContext getSslContext() { * * @param sslContext */ - public void setSslContext(SSLContext sslContext) { + public void setSslContext(final SSLContext sslContext) { this.sslContext = sslContext; } @@ -646,7 +562,7 @@ public String getSslTrustStore() { * * @param sslTrustStore */ - public void setSslTrustStore(String sslTrustStore) { + public void setSslTrustStore(final String sslTrustStore) { this.sslTrustStore = sslTrustStore; } diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 948df639a..2ff1949b4 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -2023,72 +2023,6 @@ public CursorEntity validateQuery(final String query) throws ArangoException return cursorDriver.validateQuery(getDefaultDatabase(), query); } - /** - * This method executes an AQL query and returns a CursorEntity - * - * @param query - * an AQL query as string - * @param bindVars - * a map containing all bind variables, - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @param calcCount - * if set to true the result count is returned - * @param batchSize - * the batch size of the result cursor (The batch size has to be - * greater than 0) - * @param fullCount - * if set to true, then all results before the final LIMIT will - * be counted - * @return a CursorEntity object - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeDocumentQuery(String, Map, AqlQueryOptions, Class)} - */ - @Deprecated - public CursorEntity executeQuery( - final String query, - final Map bindVars, - final Class clazz, - final Boolean calcCount, - final Integer batchSize, - final Boolean fullCount) throws ArangoException { - - return cursorDriver.executeQuery(getDefaultDatabase(), query, bindVars, clazz, calcCount, batchSize, fullCount); - } - - /** - * This method executes an AQL query and returns a CursorEntity - * - * @param query - * an AQL query as string - * @param bindVars - * a map containing all bind variables, - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @param calcCount - * if set to true the result count is returned - * @param batchSize - * the batch size of the result cursor (The batch size has to be - * greater than 0) - * @return a CursorEntity object - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeDocumentQuery(String, Map, AqlQueryOptions, Class)} - */ - @Deprecated - public CursorEntity executeQuery( - final String query, - final Map bindVars, - final Class clazz, - final Boolean calcCount, - final Integer batchSize) throws ArangoException { - - return cursorDriver.executeQuery(getDefaultDatabase(), query, bindVars, clazz, calcCount, batchSize, false); - } - /** * Continues data retrieval for an existing cursor * @@ -2116,75 +2050,6 @@ public DefaultEntity finishQuery(final long cursorId) throws ArangoException { return cursorDriver.finishQuery(getDefaultDatabase(), cursorId); } - /** - * This method executes an AQL query and returns a CursorResultSet - * - * @param query - * an AQL query as string - * @param bindVars - * a map containing all bind variables, - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @param calcCount - * if set to true the result count is returned - * @param batchSize - * the batch size of the result cursor (The batch size has to be - * greater than 0) - * @param fullCount - * if set to true, then all results before the final LIMIT will - * be counted - * - * @return a CursorResultSet object - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeDocumentQuery(String, Map, AqlQueryOptions, Class)} - */ - @Deprecated - public CursorResultSet executeQueryWithResultSet( - final String query, - final Map bindVars, - final Class clazz, - final Boolean calcCount, - final Integer batchSize, - final Boolean fullCount) throws ArangoException { - - return cursorDriver.executeQueryWithResultSet(getDefaultDatabase(), query, bindVars, clazz, calcCount, - batchSize, fullCount); - } - - /** - * This method executes an AQL query and returns a CursorResultSet - * - * @param query - * an AQL query as string - * @param bindVars - * a map containing all bind variables, - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @param calcCount - * if set to true the result count is returned - * @param batchSize - * the batch size of the result cursor (The batch size has to be - * greater than 0) - * @return CursorResultSet - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeDocumentQuery(String, Map, AqlQueryOptions, Class)} - */ - @Deprecated - public CursorResultSet executeQueryWithResultSet( - final String query, - final Map bindVars, - final Class clazz, - final Boolean calcCount, - final Integer batchSize) throws ArangoException { - - return cursorDriver.executeQueryWithResultSet(getDefaultDatabase(), query, bindVars, clazz, calcCount, - batchSize, false); - } - /** * This method executes an AQL query and returns a CursorEntity. * @@ -2700,494 +2565,43 @@ public ArangoVersion getVersion() throws ArangoException { /** * Returns the current server time - * - * @return ArangoUnixTime - * @throws ArangoException - */ - public ArangoUnixTime getTime() throws ArangoException { - return adminDriver.getTime(); - } - - /** - * Triggers the routes reloading in ArangoDB - * - * @return DefaultEntity - * @throws ArangoException - */ - public DefaultEntity reloadRouting() throws ArangoException { - return adminDriver.reloadRouting(); - } - - /** - * Executes a javascript code. - * - * @param jsCode - * a javascript function as string - * @return DefaultEntity - * @throws ArangoException - */ - public DefaultEntity executeScript(final String jsCode) throws ArangoException { - return adminDriver.executeScript(getDefaultDatabase(), jsCode); - } - - /** - * This will find all documents matching a given example. - * - * @param collectionName - * The collection name. - * @param example - * The example as a map. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * - * @return CursorEntity - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleByExampleDocuments(String, Map, int, int, Class)} - */ - @Deprecated - public CursorEntity executeSimpleByExample( - final String collectionName, - final Map example, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleByExample(getDefaultDatabase(), collectionName, example, skip, limit, clazz); - } - - /** - * This will find all documents matching a given example. - * - * @param collectionName - * The collection name. - * @param example - * The example as a map. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return CursorResultSet - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleByExampleDocuments(String, Map, int, int, Class)} - */ - @Deprecated - public CursorResultSet executeSimpleByExampleWithResusltSet( - final String collectionName, - final Map example, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleByExampleWithResultSet(getDefaultDatabase(), collectionName, example, skip, - limit, clazz); - } - - /** - * This will find all documents matching a given example. - * - * @param collectionName - * - The collection name. - * @param example - * The example as a map. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return CursorEntity> - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleByExampleDocuments(String, Map, int, int, Class)} - */ - @Deprecated - public CursorEntity> executeSimpleByExampleWithDocument( - final String collectionName, - final Map example, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleByExampleWithDocument(getDefaultDatabase(), collectionName, example, skip, - limit, clazz); - } - - /** - * This will find all documents matching a given example. - * - * @param collectionName - * - The collection name. - * @param example - * The example as a map. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return CursorResultSet> - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleByExampleDocuments(String, Map, int, int, Class)} - */ - @Deprecated - public CursorResultSet> executeSimpleByExampleWithDocumentResusltSet( - final String collectionName, - final Map example, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleByExampleWithDocumentResultSet(getDefaultDatabase(), collectionName, example, - skip, limit, clazz); - } - - /** - * This will find all documents matching a given example. - * - * @param collectionName - * - The collection name. - * @param example - * The example as a map. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return DocumentCursor - * @throws ArangoException - */ - public DocumentCursor executeSimpleByExampleDocuments( - final String collectionName, - final Map example, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleByExampleDocuments(getDefaultDatabase(), collectionName, example, skip, limit, - clazz); - } - - /** - * Returns all documents of a collections. - * - * @param collectionName - * - The collection name. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return a CursorEntity object - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleAllDocuments(String, int, int, Class)} - */ - @Deprecated - public CursorEntity executeSimpleAll( - final String collectionName, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleAll(getDefaultDatabase(), collectionName, skip, limit, clazz); - } - - /** - * Returns all documents of a collections. - * - * @param collectionName - * - The collection name. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return CursorResultSet - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleAllDocuments(String, int, int, Class)} - */ - @Deprecated - public CursorResultSet executeSimpleAllWithResultSet( - final String collectionName, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleAllWithResultSet(getDefaultDatabase(), collectionName, skip, limit, clazz); - } - - /** - * Returns all documents of a collections. - * - * @param collectionName - * - The collection name. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return CursorEntity> - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleAllDocuments(String, int, int, Class)} - */ - @Deprecated - public CursorEntity> executeSimpleAllWithDocument( - final String collectionName, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleAllWithDocument(getDefaultDatabase(), collectionName, skip, limit, clazz); - } - - /** - * Returns all documents of a collections. - * - * @param collectionName - * The collection name. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return CursorResultSet> - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleAllDocuments(String, int, int, Class)} - */ - @Deprecated - public CursorResultSet> executeSimpleAllWithDocumentResultSet( - final String collectionName, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleAllWithDocumentResultSet(getDefaultDatabase(), collectionName, skip, limit, - clazz); - } - - /** - * Returns all documents of a collections. - * - * @param collectionName - * The collection name. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return DocumentCursor - * @throws ArangoException - */ - public DocumentCursor executeSimpleAllDocuments( - final String collectionName, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleAllDocuments(getDefaultDatabase(), collectionName, skip, limit, clazz); - } - - /** - * Returns the first document matching the example - * - * @param collectionName - * The collection name. - * @param example - * The example as a map. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return a ScalarExampleEntity object - * @throws ArangoException - */ - public ScalarExampleEntity executeSimpleFirstExample( - final String collectionName, - final Map example, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleFirstExample(getDefaultDatabase(), collectionName, example, clazz); - } - - /** - * Returns a random document from the collection - * - * @param collectionName - * The collection name. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return a ScalarExampleEntity object - * @throws ArangoException - */ - public ScalarExampleEntity executeSimpleAny(final String collectionName, final Class clazz) - throws ArangoException { - return simpleDriver.executeSimpleAny(getDefaultDatabase(), collectionName, clazz); - } - - /** - * This will find all documents within a given range. - * - * @param collectionName - * The collection name. - * @param attribute - * The attribute path to check. - * @param left - * The lower bound - * @param right - * The upper bound - * @param closed - * If true, use interval including left and right, otherwise - * exclude right, but include left. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return DocumentCursor - * @throws ArangoException - */ - public DocumentCursor executeSimpleRangeWithDocuments( - final String collectionName, - final String attribute, - final Object left, - final Object right, - final Boolean closed, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleRangeWithDocuments(getDefaultDatabase(), collectionName, attribute, left, - right, closed, skip, limit, clazz); + * + * @return ArangoUnixTime + * @throws ArangoException + */ + public ArangoUnixTime getTime() throws ArangoException { + return adminDriver.getTime(); } /** - * This will find all documents within a given range. In order to execute a - * range query, a skip-list index on the queried attribute must be present. + * Triggers the routes reloading in ArangoDB * - * @param collectionName - * The collection name. - * @param attribute - * The attribute path to check. - * @param left - * The lower bound - * @param right - * The upper bound - * @param closed - * If true, use interval including left and right, otherwise - * exclude right, but include left. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return CursorResultSet + * @return DefaultEntity * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleRangeWithDocuments(String, String, Object, Object, Boolean, int, int, Class)} */ - @Deprecated - public CursorResultSet executeSimpleRangeWithResultSet( - final String collectionName, - final String attribute, - final Object left, - final Object right, - final Boolean closed, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleRangeWithResultSet(getDefaultDatabase(), collectionName, attribute, left, - right, closed, skip, limit, clazz); + public DefaultEntity reloadRouting() throws ArangoException { + return adminDriver.reloadRouting(); } /** - * This will find all documents within a given range. In order to execute a - * range query, a skip-list index on the queried attribute must be present. + * Executes a javascript code. * - * @param collectionName - * The collection name. - * @param attribute - * The attribute path to check. - * @param left - * The lower bound - * @param right - * The upper bound - * @param closed - * If true, use interval including left and right, otherwise - * exclude right, but include left. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. - * @param clazz - * the expected class, the result from the server request is - * deserialized to an instance of this class. - * @return CursorEntity> + * @param jsCode + * a javascript function as string + * @return DefaultEntity * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleRangeWithDocuments(String, String, Object, Object, Boolean, int, int, Class)} */ - @Deprecated - public CursorEntity> executeSimpleRangeWithDocument( - final String collectionName, - final String attribute, - final Object left, - final Object right, - final Boolean closed, - final int skip, - final int limit, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleRangeWithDocument(getDefaultDatabase(), collectionName, attribute, left, right, - closed, skip, limit, clazz); + public DefaultEntity executeScript(final String jsCode) throws ArangoException { + return adminDriver.executeScript(getDefaultDatabase(), jsCode); } /** - * This will find all documents within a given range. In order to execute a - * range query, a skip-list index on the queried attribute must be present. + * This will find all documents matching a given example. * * @param collectionName - * The collection name. - * @param attribute - * The attribute path to check. - * @param left - * The lower bound - * @param right - * The upper bound - * @param closed - * If true, use interval including left and right, otherwise - * exclude right, but include left. + * - The collection name. + * @param example + * The example as a map. * @param skip * The number of documents to skip in the query. * @param limit @@ -3196,37 +2610,24 @@ public CursorEntity> executeSimpleRangeWithDocument( * @param clazz * the expected class, the result from the server request is * deserialized to an instance of this class. - * @return CursorResultSet> + * @return DocumentCursor * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleRangeWithDocuments(String, String, Object, Object, Boolean, int, int, Class)} */ - @Deprecated - public CursorResultSet> executeSimpleRangeWithDocumentResultSet( + public DocumentCursor executeSimpleByExampleDocuments( final String collectionName, - final String attribute, - final Object left, - final Object right, - final Boolean closed, + final Map example, final int skip, final int limit, final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleRangeWithDocumentResultSet(getDefaultDatabase(), collectionName, attribute, - left, right, closed, skip, limit, clazz); + return simpleDriver.executeSimpleByExampleDocuments(getDefaultDatabase(), collectionName, example, skip, limit, + clazz); } /** - * This will find all documents from the collection that match the fulltext - * query specified in query. In order to use the fulltext operator, a - * fulltext index must be defined for the collection and the specified - * attribute. + * Returns all documents of a collections. * * @param collectionName * The collection name. - * @param attribute - * The attribute path to check. - * @param query - * The fulltext query as string. * @param skip * The number of documents to skip in the query. * @param limit @@ -3235,109 +2636,67 @@ public CursorResultSet> executeSimpleRangeWithDocumentResu * @param clazz * the expected class, the result from the server request is * deserialized to an instance of this class. - * @return a CursorEntity object + * @return DocumentCursor * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleFulltextWithDocuments(String, String, String, int, int, String, Class)} */ - @Deprecated - public CursorEntity executeSimpleFulltext( + public DocumentCursor executeSimpleAllDocuments( final String collectionName, - final String attribute, - final String query, final int skip, final int limit, - final String index, final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleFulltext(getDefaultDatabase(), collectionName, attribute, query, skip, limit, - index, clazz); + return simpleDriver.executeSimpleAllDocuments(getDefaultDatabase(), collectionName, skip, limit, clazz); } /** - * This will find all documents from the collection that match the fulltext - * query specified in query. In order to use the fulltext operator, a - * fulltext index must be defined for the collection and the specified - * attribute. + * Returns the first document matching the example * * @param collectionName * The collection name. - * @param attribute - * The attribute path to check. - * @param query - * The fulltext query as string. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. + * @param example + * The example as a map. * @param clazz * the expected class, the result from the server request is * deserialized to an instance of this class. - * @return DocumentCursor + * @return a ScalarExampleEntity object * @throws ArangoException */ - public DocumentCursor executeSimpleFulltextWithDocuments( + public ScalarExampleEntity executeSimpleFirstExample( final String collectionName, - final String attribute, - final String query, - final int skip, - final int limit, - final String index, + final Map example, final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleFulltextWithDocuments(getDefaultDatabase(), collectionName, attribute, query, - skip, limit, index, clazz); + return simpleDriver.executeSimpleFirstExample(getDefaultDatabase(), collectionName, example, clazz); } /** - * This will find all documents from the collection that match the fulltext - * query specified in query. In order to use the fulltext operator, a - * fulltext index must be defined for the collection and the specified - * attribute. + * Returns a random document from the collection * * @param collectionName * The collection name. - * @param attribute - * The attribute path to check. - * @param query - * The fulltext query as string. - * @param skip - * The number of documents to skip in the query. - * @param limit - * The maximal amount of documents to return. The skip is applied - * before the limit restriction. * @param clazz * the expected class, the result from the server request is * deserialized to an instance of this class. - * @return CursorResultSet + * @return a ScalarExampleEntity object * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleFulltextWithDocuments(String, String, String, int, int, String, Class)} */ - @Deprecated - public CursorResultSet executeSimpleFulltextWithResultSet( - final String collectionName, - final String attribute, - final String query, - final int skip, - final int limit, - final String index, - final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleFulltextWithResultSet(getDefaultDatabase(), collectionName, attribute, query, - skip, limit, index, clazz); + public ScalarExampleEntity executeSimpleAny(final String collectionName, final Class clazz) + throws ArangoException { + return simpleDriver.executeSimpleAny(getDefaultDatabase(), collectionName, clazz); } /** - * This will find all documents from the collection that match the fulltext - * query specified in query. In order to use the fulltext operator, a - * fulltext index must be defined for the collection and the specified - * attribute. + * This will find all documents within a given range. * * @param collectionName * The collection name. * @param attribute * The attribute path to check. - * @param query - * The fulltext query as string. + * @param left + * The lower bound + * @param right + * The upper bound + * @param closed + * If true, use interval including left and right, otherwise + * exclude right, but include left. * @param skip * The number of documents to skip in the query. * @param limit @@ -3346,22 +2705,20 @@ public CursorResultSet executeSimpleFulltextWithResultSet( * @param clazz * the expected class, the result from the server request is * deserialized to an instance of this class. - * @return CursorEntity> + * @return DocumentCursor * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleFulltextWithDocuments(String, String, String, int, int, String, Class)} */ - @Deprecated - public CursorEntity> executeSimpleFulltextWithDocument( + public DocumentCursor executeSimpleRangeWithDocuments( final String collectionName, final String attribute, - final String query, + final Object left, + final Object right, + final Boolean closed, final int skip, final int limit, - final String index, final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleFulltextWithDocument(getDefaultDatabase(), collectionName, attribute, query, - skip, limit, index, clazz); + return simpleDriver.executeSimpleRangeWithDocuments(getDefaultDatabase(), collectionName, attribute, left, + right, closed, skip, limit, clazz); } /** @@ -3384,13 +2741,10 @@ public CursorEntity> executeSimpleFulltextWithDocument( * @param clazz * the expected class, the result from the server request is * deserialized to an instance of this class. - * @return CursorResultSet> + * @return DocumentCursor * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #executeSimpleFulltextWithDocuments(String, String, String, int, int, String, Class)} */ - @Deprecated - public CursorResultSet> executeSimpleFulltextWithDocumentResultSet( + public DocumentCursor executeSimpleFulltextWithDocuments( final String collectionName, final String attribute, final String query, @@ -3398,8 +2752,8 @@ public CursorResultSet> executeSimpleFulltextWithDocumentR final int limit, final String index, final Class clazz) throws ArangoException { - return simpleDriver.executeSimpleFulltextWithDocumentResultSet(getDefaultDatabase(), collectionName, attribute, - query, skip, limit, index, clazz); + return simpleDriver.executeSimpleFulltextWithDocuments(getDefaultDatabase(), collectionName, attribute, query, + skip, limit, index, clazz); } /** @@ -4930,26 +4284,6 @@ public EdgeEntity graphUpdateEdge( // Some methods not using the graph api - /** - * Returns all Edges of a graph, each edge as a PlainEdgeEntity. - * - * @param graphName - * The name of the graph. - * @return CursorEntity - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #graphGetEdgeCursor(String, Class, Object, GraphEdgesOptions, AqlQueryOptions)} - */ - @Deprecated - public CursorEntity graphGetEdges(final String graphName) throws ArangoException { - - validateCollectionName(graphName); - final String query = "for i in graph_edges(@graphName, null, { includeData: true }) return i"; - final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName).get(); - - return this.executeQuery(query, bindVars, PlainEdgeEntity.class, true, 20); - } - /** * Returns edges as an EdgeCursor by a given query * @@ -5091,31 +4425,6 @@ public EdgeCursor graphGetEdgeCursor(final String graphName) th return graphGetEdgeCursor(graphName, PlainEdgeEntity.class, null, new GraphEdgesOptions(), null); } - /** - * Returns all Edges of a given vertex. - * - * @param graphName - * @param clazz - * @param vertexDocumentHandle - * @return a CursorEntity object - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #graphGetEdgeCursor(String, Class, Object, GraphEdgesOptions, AqlQueryOptions)} - */ - @Deprecated - public CursorEntity graphGetEdges( - final String graphName, - final Class clazz, - final String vertexDocumentHandle) throws ArangoException { - - validateCollectionName(graphName); - final String query = "for i in graph_edges(@graphName, @vertexDocumentHandle, { includeData: true }) return i"; - final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) - .put("vertexDocumentHandle", vertexDocumentHandle).get(); - - return this.executeQuery(query, bindVars, clazz, true, 20); - } - /** * Returns all Edges of a given vertex. * @@ -5134,60 +4443,6 @@ public EdgeCursor graphGetEdgeCursorByExample( return graphGetEdgeCursor(graphName, clazz, vertexExample, new GraphEdgesOptions(), null); } - /** - * Returns all Edges of vertices matching the example object (non-primitive - * set to null will not be used for comparing). - * - * @param graphName - * @param clazz - * @param vertexExample - * @return a CursorEntity object - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #graphGetEdgeCursorByExample(String, Class, Object)} - */ - @Deprecated - public CursorEntity graphGetEdgesByExampleObject( - final String graphName, - final Class clazz, - final Object vertexExample) throws ArangoException { - validateCollectionName(graphName); - final String query = "for i in graph_edges(@graphName, @vertexExample, { includeData: true }) return i"; - - final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) - .put(VERTEX_EXAMPLE, vertexExample).get(); - - return this.executeQuery(query, bindVars, clazz, true, 20); - } - - /** - * Returns all Edges of vertices matching the map. - * - * @param graphName - * The name of the graph. - * @param clazz - * Class of returned edge documents. - * @param vertexExample - * Map with example of vertex, where edges start or end. - * @return a CursorEntity object - * @throws ArangoException - * @deprecated As of release 2.5.4, replaced by - * {@link #graphGetEdgeCursorByExample(String, Class, Object)} - */ - @Deprecated - public CursorEntity graphGetEdgesByExampleMap( - final String graphName, - final Class clazz, - final Map vertexExample) throws ArangoException { - validateCollectionName(graphName); - final String query = "for i in graph_edges(@graphName, @vertexExample, { includeData: true }) return i"; - - final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) - .put(VERTEX_EXAMPLE, vertexExample).get(); - - return this.executeQuery(query, bindVars, clazz, true, 20, null); - } - public ShortestPathEntity graphGetShortestPath( final String graphName, final Object startVertexExample, diff --git a/src/main/java/com/arangodb/InternalCursorDriver.java b/src/main/java/com/arangodb/InternalCursorDriver.java index b7bd26c90..4a63287a6 100644 --- a/src/main/java/com/arangodb/InternalCursorDriver.java +++ b/src/main/java/com/arangodb/InternalCursorDriver.java @@ -95,35 +95,6 @@ public ShortestPathEntity getShortestPath( Class vertexClass, Class edgeClass) throws ArangoException; - @Deprecated - CursorEntity executeQuery( - String database, - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize, - Boolean fullCount) throws ArangoException; - - @Deprecated - CursorResultSet executeQueryWithResultSet( - String database, - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize, - Boolean fullCount) throws ArangoException; - - @Deprecated - CursorResultSet executeQueryWithResultSet( - String database, - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize) throws ArangoException; - QueryTrackingPropertiesEntity getQueryTrackingProperties(String database) throws ArangoException; QueryTrackingPropertiesEntity setQueryTrackingProperties(String database, QueryTrackingPropertiesEntity properties) diff --git a/src/main/java/com/arangodb/InternalGraphDriver.java b/src/main/java/com/arangodb/InternalGraphDriver.java index 64dfe6057..8fbc7e9bb 100644 --- a/src/main/java/com/arangodb/InternalGraphDriver.java +++ b/src/main/java/com/arangodb/InternalGraphDriver.java @@ -21,21 +21,16 @@ package com.arangodb; -import java.util.Collection; import java.util.List; -import com.arangodb.entity.CursorEntity; import com.arangodb.entity.DeletedEntity; -import com.arangodb.entity.Direction; import com.arangodb.entity.EdgeDefinitionEntity; import com.arangodb.entity.EdgeEntity; -import com.arangodb.entity.FilterCondition; import com.arangodb.entity.GraphEntity; import com.arangodb.entity.GraphsEntity; import com.arangodb.entity.marker.VertexEntity; import com.arangodb.impl.BaseDriverInterface; -@SuppressWarnings("deprecation") public interface InternalGraphDriver extends BaseDriverInterface { /** @@ -468,35 +463,4 @@ EdgeEntity updateEdge( Long ifMatchRevision, Long ifNoneMatchRevision) throws ArangoException; - /** - * - * - * @param database - * @param graphName - * @param vertexKey - * @param clazz - * @param batchSize - * @param limit - * @param count - * @param direction - * @param labels - * @param driver - * @param properties - * @return a CursorEntity object - * @throws ArangoException - */ - @Deprecated - CursorEntity> getEdges( - String database, - String graphName, - String vertexKey, - Class clazz, - Integer batchSize, - Integer limit, - Boolean count, - Direction direction, - Collection labels, - ArangoDriver driver, - FilterCondition... properties) throws ArangoException; - } diff --git a/src/main/java/com/arangodb/InternalSimpleDriver.java b/src/main/java/com/arangodb/InternalSimpleDriver.java index 2e03ab05c..6adf27cae 100644 --- a/src/main/java/com/arangodb/InternalSimpleDriver.java +++ b/src/main/java/com/arangodb/InternalSimpleDriver.java @@ -2,8 +2,6 @@ import java.util.Map; -import com.arangodb.entity.CursorEntity; -import com.arangodb.entity.DocumentEntity; import com.arangodb.entity.ScalarExampleEntity; import com.arangodb.entity.SimpleByResultEntity; import com.arangodb.impl.BaseDriverInterface; @@ -13,34 +11,6 @@ */ public interface InternalSimpleDriver extends BaseDriverInterface { - @Deprecated - CursorEntity executeSimpleAll(String database, String collectionName, int skip, int limit, Class clazz) - throws ArangoException; - - @Deprecated - CursorResultSet executeSimpleAllWithResultSet( - String database, - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException; - - @Deprecated - CursorEntity> executeSimpleAllWithDocument( - String database, - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException; - - @Deprecated - CursorResultSet> executeSimpleAllWithDocumentResultSet( - String database, - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException; - DocumentCursor executeSimpleAllDocuments( String database, String collectionName, @@ -48,42 +18,6 @@ DocumentCursor executeSimpleAllDocuments( int limit, Class clazz) throws ArangoException; - @Deprecated - CursorEntity executeSimpleByExample( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException; - - @Deprecated - CursorResultSet executeSimpleByExampleWithResultSet( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException; - - @Deprecated - CursorEntity> executeSimpleByExampleWithDocument( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException; - - @Deprecated - CursorResultSet> executeSimpleByExampleWithDocumentResultSet( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException; - DocumentCursor executeSimpleByExampleDocuments( String database, String collectionName, @@ -101,54 +35,6 @@ ScalarExampleEntity executeSimpleFirstExample( ScalarExampleEntity executeSimpleAny(String database, String collectionName, Class clazz) throws ArangoException; - @Deprecated - CursorEntity executeSimpleRange( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException; - - @Deprecated - CursorResultSet executeSimpleRangeWithResultSet( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException; - - @Deprecated - CursorEntity> executeSimpleRangeWithDocument( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException; - - @Deprecated - CursorResultSet> executeSimpleRangeWithDocumentResultSet( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException; - DocumentCursor executeSimpleRangeWithDocuments( String database, String collectionName, @@ -184,50 +70,6 @@ SimpleByResultEntity executeSimpleUpdateByExample( Boolean waitForSync, Integer limit) throws ArangoException; - @Deprecated - CursorEntity executeSimpleFulltext( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException; - - @Deprecated - CursorResultSet executeSimpleFulltextWithResultSet( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException; - - @Deprecated - CursorEntity> executeSimpleFulltextWithDocument( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException; - - @Deprecated - CursorResultSet> executeSimpleFulltextWithDocumentResultSet( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException; - DocumentCursor executeSimpleFulltextWithDocuments( String database, String collectionName, diff --git a/src/main/java/com/arangodb/entity/Direction.java b/src/main/java/com/arangodb/entity/Direction.java deleted file mode 100644 index e04126389..000000000 --- a/src/main/java/com/arangodb/entity/Direction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2012 tamtam180 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arangodb.entity; - -/** - * An enumeration representing the possible directions of graph functions. - * - * @author tamtam180 - kirscheless at gmail.com - * - * @deprecated As of release 2.5.4, replaced by {@link com.arangodb.Direction} - * - */ -@Deprecated -public enum Direction { - ANY, - IN, - OUT -} diff --git a/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java b/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java index dc256b33d..215a0dd04 100644 --- a/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java @@ -23,7 +23,6 @@ import com.arangodb.ArangoException; import com.arangodb.CursorRawResult; import com.arangodb.CursorResult; -import com.arangodb.CursorResultSet; import com.arangodb.DocumentCursorResult; import com.arangodb.entity.CursorEntity; import com.arangodb.entity.DefaultEntity; @@ -44,13 +43,13 @@ */ public class InternalCursorDriverImpl extends BaseArangoDriverImpl implements com.arangodb.InternalCursorDriver { - InternalCursorDriverImpl(ArangoConfigure configure, HttpManager httpManager) { + InternalCursorDriverImpl(final ArangoConfigure configure, final HttpManager httpManager) { super(configure, httpManager); } @Override - public CursorEntity validateQuery(String database, String query) throws ArangoException { - HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/query"), null, + public CursorEntity validateQuery(final String database, final String query) throws ArangoException { + final HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/query"), null, EntityFactory.toJsonString(new MapBuilder("query", query).get())); return createEntity(res, CursorEntity.class); @@ -58,10 +57,10 @@ public CursorEntity validateQuery(String database, String query) throws Arang @Override public String executeAqlQueryJSON( - String database, - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions) throws ArangoException { + final String database, + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions) throws ArangoException { return getJSONResponseText(getCursor(database, query, bindVars, aqlQueryOptions)); } @@ -69,24 +68,24 @@ public String executeAqlQueryJSON( @SuppressWarnings("unchecked") @Override public CursorEntity executeCursorEntityQuery( - String database, - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions, - Class... clazz) throws ArangoException { + final String database, + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions, + final Class... clazz) throws ArangoException { - HttpResponseEntity res = getCursor(database, query, bindVars, aqlQueryOptions); + final HttpResponseEntity res = getCursor(database, query, bindVars, aqlQueryOptions); return createEntity(res, CursorEntity.class, clazz); } private HttpResponseEntity getCursor( - String database, - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions) throws ArangoException { + final String database, + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions) throws ArangoException { - Map map = aqlQueryOptions.toMap(); + final Map map = aqlQueryOptions.toMap(); map.put("query", query); map.put("bindVars", bindVars == null ? Collections.emptyMap() : bindVars); @@ -95,20 +94,23 @@ private HttpResponseEntity getCursor( @SuppressWarnings("unchecked") @Override - public CursorEntity continueQuery(String database, long cursorId, Class... clazz) throws ArangoException { + public CursorEntity continueQuery(final String database, final long cursorId, final Class... clazz) + throws ArangoException { - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/cursor", cursorId), null, null); + final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/cursor", cursorId), null, + null); return createEntity(res, CursorEntity.class, clazz); } @Override - public DefaultEntity finishQuery(String database, long cursorId) throws ArangoException { - HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/cursor/", cursorId), null); + public DefaultEntity finishQuery(final String database, final long cursorId) throws ArangoException { + final HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/cursor/", cursorId), + null); try { return createEntity(res, DefaultEntity.class); - } catch (ArangoException e) { + } catch (final ArangoException e) { // TODO Mode if (e.getErrorNumber() == 1600) { // 既に削除されている @@ -120,14 +122,14 @@ public DefaultEntity finishQuery(String database, long cursorId) throws ArangoEx @Override public > DocumentCursorResult executeBaseCursorQuery( - String database, - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions, - Class classDocumentEntity, - Class clazz) throws ArangoException { - - CursorEntity entity = executeCursorEntityQuery(database, query, bindVars, aqlQueryOptions, + final String database, + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions, + final Class classDocumentEntity, + final Class clazz) throws ArangoException { + + final CursorEntity entity = executeCursorEntityQuery(database, query, bindVars, aqlQueryOptions, classDocumentEntity, clazz); return new DocumentCursorResult(database, this, entity, classDocumentEntity, clazz); @@ -135,25 +137,25 @@ public > DocumentCursorResult executeBaseCu @Override public CursorResult executeAqlQuery( - String database, - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions, - Class clazz) throws ArangoException { + final String database, + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions, + final Class clazz) throws ArangoException { - CursorEntity entity = executeCursorEntityQuery(database, query, bindVars, aqlQueryOptions, clazz); + final CursorEntity entity = executeCursorEntityQuery(database, query, bindVars, aqlQueryOptions, clazz); return new CursorResult(database, this, entity, clazz); } @Override public CursorRawResult executeAqlQueryRaw( - String database, - String query, - Map bindVars, - AqlQueryOptions aqlQueryOptions) throws ArangoException { + final String database, + final String query, + final Map bindVars, + final AqlQueryOptions aqlQueryOptions) throws ArangoException { - CursorEntity entity = executeCursorEntityQuery(database, query, bindVars, aqlQueryOptions, + final CursorEntity entity = executeCursorEntityQuery(database, query, bindVars, aqlQueryOptions, JsonObject.class); return new CursorRawResult(database, this, entity); @@ -162,121 +164,76 @@ public CursorRawResult executeAqlQueryRaw( @SuppressWarnings("unchecked") @Override public ShortestPathEntity getShortestPath( - String database, - String graphName, - Object startVertexExample, - Object endVertexExample, - ShortestPathOptions shortestPathOptions, - AqlQueryOptions aqlQueryOptions, - Class vertexClass, - Class edgeClass) throws ArangoException { + final String database, + final String graphName, + final Object startVertexExample, + final Object endVertexExample, + final ShortestPathOptions shortestPathOptions, + final AqlQueryOptions aqlQueryOptions, + final Class vertexClass, + final Class edgeClass) throws ArangoException { validateCollectionName(graphName); - String query = "for i in graph_shortest_path(@graphName, @startVertexExample, @endVertexExample, @options) return i"; + final String query = "for i in graph_shortest_path(@graphName, @startVertexExample, @endVertexExample, @options) return i"; - Map options = shortestPathOptions == null ? new MapBuilder().get() + final Map options = shortestPathOptions == null ? new MapBuilder().get() : shortestPathOptions.toMap(); - Map bindVars = new MapBuilder().put("graphName", graphName) + final Map bindVars = new MapBuilder().put("graphName", graphName) .put("startVertexExample", startVertexExample).put("endVertexExample", endVertexExample) .put("options", options).get(); - HttpResponseEntity res = getCursor(database, query, bindVars, aqlQueryOptions); + final HttpResponseEntity res = getCursor(database, query, bindVars, aqlQueryOptions); return createEntity(res, ShortestPathEntity.class, vertexClass, edgeClass); } - @Deprecated - @SuppressWarnings("unchecked") - @Override - public CursorEntity executeQuery( - String database, - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize, - Boolean fullCount) throws ArangoException { - - AqlQueryOptions aqlQueryOptions = new AqlQueryOptions().setCount(calcCount).setBatchSize(batchSize) - .setFullCount(fullCount); - - HttpResponseEntity res = getCursor(database, query, bindVars, aqlQueryOptions); - return createEntity(res, CursorEntity.class, clazz); - } - - @Deprecated - @Override - public CursorResultSet executeQueryWithResultSet( - String database, - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize, - Boolean fullCount) throws ArangoException { - - CursorEntity entity = executeQuery(database, query, bindVars, clazz, calcCount, batchSize, fullCount); - return new CursorResultSet(database, this, entity, clazz); - } - - @Deprecated - @Override - public CursorResultSet executeQueryWithResultSet( - String database, - String query, - Map bindVars, - Class clazz, - Boolean calcCount, - Integer batchSize) throws ArangoException { - - CursorEntity entity = executeQuery(database, query, bindVars, clazz, calcCount, batchSize, false); - return new CursorResultSet(database, this, entity, clazz); - } - @Override - public QueryTrackingPropertiesEntity getQueryTrackingProperties(String database) throws ArangoException { + public QueryTrackingPropertiesEntity getQueryTrackingProperties(final String database) throws ArangoException { - HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/properties"), null, null); + final HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/properties"), null, + null); return createEntity(res, QueryTrackingPropertiesEntity.class); } @Override public QueryTrackingPropertiesEntity setQueryTrackingProperties( - String database, - QueryTrackingPropertiesEntity properties) throws ArangoException { - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/query/properties"), null, + final String database, + final QueryTrackingPropertiesEntity properties) throws ArangoException { + final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/query/properties"), null, EntityFactory.toJsonString(properties)); return createEntity(res, QueryTrackingPropertiesEntity.class); } @Override - public QueriesResultEntity getCurrentlyRunningQueries(String database) throws ArangoException { - HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/current"), null, null); + public QueriesResultEntity getCurrentlyRunningQueries(final String database) throws ArangoException { + final HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/current"), null, + null); return createEntity(res, QueriesResultEntity.class); } @Override - public QueriesResultEntity getSlowQueries(String database) throws ArangoException { - HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/slow"), null, null); + public QueriesResultEntity getSlowQueries(final String database) throws ArangoException { + final HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/query/slow"), null, null); return createEntity(res, QueriesResultEntity.class); } @Override - public DefaultEntity deleteSlowQueries(String database) throws ArangoException { - HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/query/slow"), null, null); + public DefaultEntity deleteSlowQueries(final String database) throws ArangoException { + final HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/query/slow"), null, + null); return createEntity(res, DefaultEntity.class); } @Override - public DefaultEntity killQuery(String database, String id) throws ArangoException { - HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/query", id), null, null); + public DefaultEntity killQuery(final String database, final String id) throws ArangoException { + final HttpResponseEntity res = httpManager.doDelete(createEndpointUrl(database, "/_api/query", id), null, null); return createEntity(res, DefaultEntity.class); } diff --git a/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java b/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java index 30c3ef653..00d264be2 100644 --- a/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java @@ -17,22 +17,15 @@ package com.arangodb.impl; import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import java.util.Locale; -import java.util.Map; import com.arangodb.ArangoConfigure; -import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.InternalCursorDriver; -import com.arangodb.entity.CursorEntity; import com.arangodb.entity.DeletedEntity; -import com.arangodb.entity.Direction; import com.arangodb.entity.EdgeDefinitionEntity; import com.arangodb.entity.EdgeEntity; import com.arangodb.entity.EntityFactory; -import com.arangodb.entity.FilterCondition; import com.arangodb.entity.GraphEntity; import com.arangodb.entity.GraphGetCollectionsResultEntity; import com.arangodb.entity.GraphsEntity; @@ -51,7 +44,6 @@ * @author gschwab * @author a-brandt */ -@SuppressWarnings("deprecation") public class InternalGraphDriverImpl extends BaseArangoDriverWithCursorImpl implements com.arangodb.InternalGraphDriver { @@ -62,13 +54,15 @@ public class InternalGraphDriverImpl extends BaseArangoDriverWithCursorImpl private static final String VERTEX = "/vertex"; private static final String EDGE = "/edge"; - InternalGraphDriverImpl(ArangoConfigure configure, InternalCursorDriver cursorDriver, HttpManager httpManager) { + InternalGraphDriverImpl(final ArangoConfigure configure, final InternalCursorDriver cursorDriver, + final HttpManager httpManager) { super(configure, cursorDriver, httpManager); } @Override - public GraphEntity createGraph(String databaseName, String graphName, Boolean waitForSync) throws ArangoException { - HttpResponseEntity response = httpManager.doPost(createGharialEndpointUrl(databaseName), + public GraphEntity createGraph(final String databaseName, final String graphName, final Boolean waitForSync) + throws ArangoException { + final HttpResponseEntity response = httpManager.doPost(createGharialEndpointUrl(databaseName), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(new MapBuilder().put("name", graphName).get())); return createEntity(response, GraphEntity.class); @@ -76,13 +70,13 @@ public GraphEntity createGraph(String databaseName, String graphName, Boolean wa @Override public GraphEntity createGraph( - String databaseName, - String graphName, - List edgeDefinitions, - List orphanCollections, - Boolean waitForSync) throws ArangoException { + final String databaseName, + final String graphName, + final List edgeDefinitions, + final List orphanCollections, + final Boolean waitForSync) throws ArangoException { - HttpResponseEntity response = httpManager + final HttpResponseEntity response = httpManager .doPost(createGharialEndpointUrl(databaseName), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString( new MapBuilder().put("name", graphName).put("edgeDefinitions", edgeDefinitions) @@ -91,13 +85,13 @@ public GraphEntity createGraph( } @Override - public GraphsEntity getGraphs(String databaseName) throws ArangoException { + public GraphsEntity getGraphs(final String databaseName) throws ArangoException { - GraphsEntity graphsEntity = new GraphsEntity(); - List graphEntities = new ArrayList(); - List graphList = this.getGraphList(databaseName); + final GraphsEntity graphsEntity = new GraphsEntity(); + final List graphEntities = new ArrayList(); + final List graphList = this.getGraphList(databaseName); if (CollectionUtils.isNotEmpty(graphList)) { - for (String graphName : graphList) { + for (final String graphName : graphList) { graphEntities.add(this.getGraph(databaseName, graphName)); } } @@ -107,13 +101,13 @@ public GraphsEntity getGraphs(String databaseName) throws ArangoException { } @Override - public List getGraphList(String databaseName) throws ArangoException { - HttpResponseEntity res = httpManager.doGet(createGharialEndpointUrl(databaseName)); - GraphsEntity graphsEntity = createEntity(res, GraphsEntity.class); - List graphList = new ArrayList(); - List graphs = graphsEntity.getGraphs(); + public List getGraphList(final String databaseName) throws ArangoException { + final HttpResponseEntity res = httpManager.doGet(createGharialEndpointUrl(databaseName)); + final GraphsEntity graphsEntity = createEntity(res, GraphsEntity.class); + final List graphList = new ArrayList(); + final List graphs = graphsEntity.getGraphs(); if (CollectionUtils.isNotEmpty(graphs)) { - for (GraphEntity graph : graphs) { + for (final GraphEntity graph : graphs) { graphList.add(graph.getDocumentKey()); } } @@ -121,19 +115,19 @@ public List getGraphList(String databaseName) throws ArangoException { } @Override - public GraphEntity getGraph(String databaseName, String graphName) throws ArangoException { + public GraphEntity getGraph(final String databaseName, final String graphName) throws ArangoException { validateCollectionName(graphName); // ?? - HttpResponseEntity res = httpManager.doGet( + final HttpResponseEntity res = httpManager.doGet( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName)), new MapBuilder().get(), null); return createEntity(res, GraphEntity.class); } @Override - public DeletedEntity deleteGraph(String databaseName, String graphName, Boolean dropCollections) + public DeletedEntity deleteGraph(final String databaseName, final String graphName, final Boolean dropCollections) throws ArangoException { validateCollectionName(graphName); // ?? - HttpResponseEntity res = httpManager.doDelete( + final HttpResponseEntity res = httpManager.doDelete( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName)), new MapBuilder().get(), new MapBuilder().put("dropCollections", dropCollections).get()); @@ -152,9 +146,9 @@ public DeletedEntity deleteGraph(String databaseName, String graphName, Boolean } @Override - public List getVertexCollections(String databaseName, String graphName) throws ArangoException { + public List getVertexCollections(final String databaseName, final String graphName) throws ArangoException { validateCollectionName(graphName); - HttpResponseEntity res = httpManager + final HttpResponseEntity res = httpManager .doGet(createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX)); if (wrongResult(res)) { @@ -182,15 +176,15 @@ public List getVertexCollections(String databaseName, String graphName) */ @Override public DeletedEntity deleteVertexCollection( - String databaseName, - String graphName, - String collectionName, - Boolean dropCollection) throws ArangoException { + final String databaseName, + final String graphName, + final String collectionName, + final Boolean dropCollection) throws ArangoException { validateDatabaseName(databaseName, false); validateCollectionName(collectionName); validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doDelete( + final HttpResponseEntity res = httpManager.doDelete( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX, StringUtils.encodeUrl(collectionName)), new MapBuilder().get(), new MapBuilder().put("dropCollection", dropCollection).get()); @@ -210,12 +204,14 @@ public DeletedEntity deleteVertexCollection( } @Override - public GraphEntity createVertexCollection(String databaseName, String graphName, String collectionName) - throws ArangoException { + public GraphEntity createVertexCollection( + final String databaseName, + final String graphName, + final String collectionName) throws ArangoException { validateCollectionName(graphName); validateCollectionName(collectionName); - HttpResponseEntity res = httpManager.doPost( + final HttpResponseEntity res = httpManager.doPost( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX), null, EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).get())); @@ -234,9 +230,9 @@ public GraphEntity createVertexCollection(String databaseName, String graphName, } @Override - public List getEdgeCollections(String databaseName, String graphName) throws ArangoException { + public List getEdgeCollections(final String databaseName, final String graphName) throws ArangoException { validateCollectionName(graphName); - HttpResponseEntity res = httpManager + final HttpResponseEntity res = httpManager .doGet(createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), EDGE)); if (wrongResult(res)) { @@ -254,15 +250,17 @@ public List getEdgeCollections(String databaseName, String graphName) th } @Override - public GraphEntity createEdgeDefinition(String databaseName, String graphName, EdgeDefinitionEntity edgeDefinition) - throws ArangoException { + public GraphEntity createEdgeDefinition( + final String databaseName, + final String graphName, + final EdgeDefinitionEntity edgeDefinition) throws ArangoException { validateCollectionName(graphName); validateCollectionName(edgeDefinition.getCollection()); - String edgeDefinitionJson = this.convertToString(edgeDefinition); + final String edgeDefinitionJson = this.convertToString(edgeDefinition); - HttpResponseEntity res = httpManager.doPost( + final HttpResponseEntity res = httpManager.doPost( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), EDGE), null, edgeDefinitionJson); if (wrongResult(res)) { @@ -281,17 +279,17 @@ public GraphEntity createEdgeDefinition(String databaseName, String graphName, E @Override public GraphEntity replaceEdgeDefinition( - String databaseName, - String graphName, - String edgeName, - EdgeDefinitionEntity edgeDefinition) throws ArangoException { + final String databaseName, + final String graphName, + final String edgeName, + final EdgeDefinitionEntity edgeDefinition) throws ArangoException { validateCollectionName(graphName); validateCollectionName(edgeDefinition.getCollection()); - String edgeDefinitionJson = this.convertToString(edgeDefinition); + final String edgeDefinitionJson = this.convertToString(edgeDefinition); - HttpResponseEntity res = httpManager.doPut(createGharialEndpointUrl(databaseName, + final HttpResponseEntity res = httpManager.doPut(createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeName)), null, edgeDefinitionJson); if (wrongResult(res)) { @@ -311,14 +309,14 @@ public GraphEntity replaceEdgeDefinition( @Override public GraphEntity deleteEdgeDefinition( - String databaseName, - String graphName, - String edgeName, - Boolean dropCollection) throws ArangoException { + final String databaseName, + final String graphName, + final String edgeName, + final Boolean dropCollection) throws ArangoException { validateCollectionName(graphName); validateCollectionName(edgeName); - HttpResponseEntity res = httpManager.doDelete(createGharialEndpointUrl(databaseName, + final HttpResponseEntity res = httpManager.doDelete(createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeName)), new MapBuilder().put("dropCollection", dropCollection).get()); @@ -338,29 +336,29 @@ public GraphEntity deleteEdgeDefinition( @Override public VertexEntity createVertex( - String database, - String graphName, - String collectionName, - T vertex, - Boolean waitForSync) throws ArangoException { + final String database, + final String graphName, + final String collectionName, + final T vertex, + final Boolean waitForSync) throws ArangoException { return createVertex(database, graphName, collectionName, null, vertex, waitForSync); } @SuppressWarnings("unchecked") @Override public VertexEntity createVertex( - String database, - String graphName, - String collectionName, - String key, - T vertex, - Boolean waitForSync) throws ArangoException { + final String database, + final String graphName, + final String collectionName, + final String key, + final T vertex, + final Boolean waitForSync) throws ArangoException { JsonObject obj; if (vertex == null) { obj = new JsonObject(); } else { - JsonElement elem = EntityFactory.toJsonElement(vertex, false); + final JsonElement elem = EntityFactory.toJsonElement(vertex, false); if (elem.isJsonObject()) { obj = elem.getAsJsonObject(); } else { @@ -372,7 +370,7 @@ public VertexEntity createVertex( } validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doPost( + final HttpResponseEntity res = httpManager.doPost( createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), VERTEX, StringUtils.encodeUrl(collectionName)), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(obj)); @@ -398,7 +396,7 @@ public VertexEntity createVertex( return result; } - private boolean wrongResult(HttpResponseEntity res) { + private boolean wrongResult(final HttpResponseEntity res) { if (res.isJsonResponse()) { return false; } @@ -417,16 +415,16 @@ private boolean isInBatchMode() { @SuppressWarnings("unchecked") @Override public VertexEntity getVertex( - String databaseName, - String graphName, - String collectionName, - String key, - Class clazz, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String databaseName, + final String graphName, + final String collectionName, + final String key, + final Class clazz, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doGet( + final HttpResponseEntity res = httpManager.doGet( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX, StringUtils.encodeUrl(collectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true).get(), @@ -438,17 +436,17 @@ public VertexEntity getVertex( @SuppressWarnings("unchecked") @Override public VertexEntity replaceVertex( - String databaseName, - String graphName, - String collectionName, - String key, - T vertex, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String databaseName, + final String graphName, + final String collectionName, + final String key, + final T vertex, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doPut( + final HttpResponseEntity res = httpManager.doPut( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX, StringUtils.encodeUrl(collectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true).get(), @@ -469,18 +467,18 @@ public VertexEntity replaceVertex( @SuppressWarnings("unchecked") @Override public VertexEntity updateVertex( - String databaseName, - String graphName, - String collectionName, - String key, - T vertex, - Boolean keepNull, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String databaseName, + final String graphName, + final String collectionName, + final String key, + final T vertex, + final Boolean keepNull, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doPatch( + final HttpResponseEntity res = httpManager.doPatch( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX, StringUtils.encodeUrl(collectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true).get(), @@ -501,16 +499,16 @@ public VertexEntity updateVertex( @Override public DeletedEntity deleteVertex( - String databaseName, - String graphName, - String collectionName, - String key, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String databaseName, + final String graphName, + final String collectionName, + final String key, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doDelete( + final HttpResponseEntity res = httpManager.doDelete( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX, StringUtils.encodeUrl(collectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_MATCH, ifMatchRevision, true).put(IF_NONE_MATCH, ifNoneMatchRevision, true).get(), @@ -522,24 +520,24 @@ public DeletedEntity deleteVertex( @SuppressWarnings("unchecked") @Override public EdgeEntity createEdge( - String database, - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle, - T value, - Boolean waitForSync) throws ArangoException { + final String database, + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle, + final T value, + final Boolean waitForSync) throws ArangoException { - JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); + final JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doPost( + final HttpResponseEntity res = httpManager.doPost( createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeCollectionName)), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(obj)); - EdgeEntity entity = createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); + final EdgeEntity entity = createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); if (value != null) { entity.setEntity(value); annotationHandler.updateEdgeAttributes(value, entity.getDocumentRevision(), entity.getDocumentHandle(), @@ -551,12 +549,16 @@ public EdgeEntity createEdge( return entity; } - private JsonObject valueToEdgeJsonObject(String key, String fromHandle, String toHandle, T value) { + private JsonObject valueToEdgeJsonObject( + final String key, + final String fromHandle, + final String toHandle, + final T value) { JsonObject obj; if (value == null) { obj = new JsonObject(); } else { - JsonElement elem = EntityFactory.toJsonElement(value, false); + final JsonElement elem = EntityFactory.toJsonElement(value, false); if (elem.isJsonObject()) { obj = elem.getAsJsonObject(); } else { @@ -578,16 +580,16 @@ private JsonObject valueToEdgeJsonObject(String key, String fromHandle, Stri @SuppressWarnings("unchecked") @Override public EdgeEntity getEdge( - String database, - String graphName, - String edgeCollectionName, - String key, - Class clazz, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String database, + final String graphName, + final String edgeCollectionName, + final String key, + final Class clazz, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doGet( + final HttpResponseEntity res = httpManager.doGet( createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(), @@ -598,16 +600,16 @@ public EdgeEntity getEdge( @Override public DeletedEntity deleteEdge( - String database, - String graphName, - String edgeCollectionName, - String key, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { + final String database, + final String graphName, + final String edgeCollectionName, + final String key, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doDelete( + final HttpResponseEntity res = httpManager.doDelete( createEndpointUrl(database, "/_api/gharial", StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(), @@ -620,27 +622,27 @@ public DeletedEntity deleteEdge( @SuppressWarnings("unchecked") @Override public EdgeEntity replaceEdge( - String database, - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle, - T value, - Boolean waitForSync, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { - - JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); + final String database, + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle, + final T value, + final Boolean waitForSync, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { + + final JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doPut( + final HttpResponseEntity res = httpManager.doPut( createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).get(), EntityFactory.toJsonString(obj)); - EdgeEntity entity = createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); + final EdgeEntity entity = createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); if (value != null) { entity.setEntity(value); annotationHandler.updateEdgeAttributes(entity.getEntity(), entity.getDocumentRevision(), @@ -659,29 +661,29 @@ public EdgeEntity replaceEdge( @SuppressWarnings("unchecked") @Override public EdgeEntity updateEdge( - String database, - String graphName, - String edgeCollectionName, - String key, - String fromHandle, - String toHandle, - T value, - Boolean waitForSync, - Boolean keepNull, - Long ifMatchRevision, - Long ifNoneMatchRevision) throws ArangoException { - - JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); + final String database, + final String graphName, + final String edgeCollectionName, + final String key, + final String fromHandle, + final String toHandle, + final T value, + final Boolean waitForSync, + final Boolean keepNull, + final Long ifMatchRevision, + final Long ifNoneMatchRevision) throws ArangoException { + + final JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); validateCollectionName(graphName); - HttpResponseEntity res = httpManager.doPatch( + final HttpResponseEntity res = httpManager.doPatch( createGharialEndpointUrl(database, StringUtils.encodeUrl(graphName), EDGE, StringUtils.encodeUrl(edgeCollectionName), StringUtils.encodeUrl(key)), new MapBuilder().put(IF_NONE_MATCH, ifNoneMatchRevision, true).put(IF_MATCH, ifMatchRevision, true).get(), new MapBuilder().put(WAIT_FOR_SYNC, waitForSync).put("keepNull", keepNull).get(), EntityFactory.toJsonString(obj)); - EdgeEntity entity = createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); + final EdgeEntity entity = createEntity(res, EdgeEntity.class, value == null ? null : value.getClass()); if (value != null) { entity.setEntity(value); annotationHandler.updateEdgeAttributes(entity.getEntity(), entity.getDocumentRevision(), @@ -698,52 +700,11 @@ public EdgeEntity updateEdge( return entity; } - @SuppressWarnings("unchecked") - @Override - public CursorEntity> getEdges( - String database, - String graphName, - String vertexKey, - Class clazz, - Integer batchSize, - Integer limit, - Boolean count, - Direction direction, - Collection labels, - ArangoDriver driver, - FilterCondition... properties) throws ArangoException { - - validateCollectionName(graphName); - - String getEdges = "var db = require('internal').db;\n" + "var graph = require('org/arangodb/general-graph');\n" - + "var g = graph._graph('" + graphName + "');\n" + "g._edges();"; - driver.executeScript(getEdges); - - Map filter = new MapBuilder().put("direction", toLower(direction)).put("labels", labels) - .put("properties", properties).get(); - - HttpResponseEntity res = httpManager.doPost( - createEndpointUrl(database, "/_api/graph", StringUtils.encodeUrl(graphName), "edges", - StringUtils.encodeUrl(vertexKey)), - null, EntityFactory.toJsonString(new MapBuilder().put("batchSize", batchSize).put("limit", limit) - .put("count", count).put("filter", filter).get())); - - return createEntity(res, CursorEntity.class, EdgeEntity.class, clazz); - - } - - private String convertToString(EdgeDefinitionEntity edgeDefinition) { - JsonObject rawEdgeDefinition = (JsonObject) EntityFactory + private String convertToString(final EdgeDefinitionEntity edgeDefinition) { + final JsonObject rawEdgeDefinition = (JsonObject) EntityFactory .toJsonElement(new MapBuilder().put("edgeDefinition", edgeDefinition).get(), false); - JsonElement edgeDefinitionJson = rawEdgeDefinition.get("edgeDefinition"); + final JsonElement edgeDefinitionJson = rawEdgeDefinition.get("edgeDefinition"); return edgeDefinitionJson.toString(); } - private String toLower(Enum e) { - if (e == null) { - return null; - } - return e.name().toLowerCase(Locale.US); - } - } diff --git a/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java b/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java index b0857c9b8..05402b7e2 100644 --- a/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java @@ -20,7 +20,6 @@ import com.arangodb.ArangoConfigure; import com.arangodb.ArangoException; -import com.arangodb.CursorResultSet; import com.arangodb.DocumentCursor; import com.arangodb.DocumentCursorResult; import com.arangodb.InternalCursorDriver; @@ -45,135 +44,37 @@ public class InternalSimpleDriverImpl extends BaseArangoDriverWithCursorImpl private static final String EXAMPLE = "example"; private static final String COLLECTION = "collection"; - InternalSimpleDriverImpl(ArangoConfigure configure, InternalCursorDriver cursorDriver, HttpManager httpManager) { + InternalSimpleDriverImpl(final ArangoConfigure configure, final InternalCursorDriver cursorDriver, + final HttpManager httpManager) { super(configure, cursorDriver, httpManager); } // ----- all -------------------- - @Override - public CursorEntity executeSimpleAll( - String database, - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException { - - return internalExecuteSimpleAll(database, collectionName, skip, limit, clazz); - } - - @Override - public CursorResultSet executeSimpleAllWithResultSet( - String database, - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException { - - CursorEntity entity = executeSimpleAll(database, collectionName, skip, limit, clazz); - return new CursorResultSet(database, cursorDriver, entity, clazz); - } - - @Override - public CursorEntity> executeSimpleAllWithDocument( - String database, - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException { - - return internalExecuteSimpleAll(database, collectionName, skip, limit, DocumentEntity.class, clazz); - } - - @Override - public CursorResultSet> executeSimpleAllWithDocumentResultSet( - String database, - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException { - - CursorEntity> entity = executeSimpleAllWithDocument(database, collectionName, skip, limit, - clazz); - return new CursorResultSet>(database, cursorDriver, entity, DocumentEntity.class, clazz); - } - @Override public DocumentCursor executeSimpleAllDocuments( - String database, - String collectionName, - int skip, - int limit, - Class clazz) throws ArangoException { + final String database, + final String collectionName, + final int skip, + final int limit, + final Class clazz) throws ArangoException { - HttpResponseEntity res = getSimpleAll(database, collectionName, skip, limit); + final HttpResponseEntity res = getSimpleAll(database, collectionName, skip, limit); return responseToDocumentCursor(database, clazz, res); } // ----- example -------------------- - @Override - public CursorEntity executeSimpleByExample( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { - - return internalExecuteSimpleByExample(database, collectionName, example, skip, limit, clazz); - } - - @Override - public CursorResultSet executeSimpleByExampleWithResultSet( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { - - CursorEntity entity = executeSimpleByExample(database, collectionName, example, skip, limit, clazz); - return new CursorResultSet(database, cursorDriver, entity, clazz); - } - - @Override - public CursorEntity> executeSimpleByExampleWithDocument( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { - - return internalExecuteSimpleByExample(database, collectionName, example, skip, limit, DocumentEntity.class, - clazz); - } - - @Override - public CursorResultSet> executeSimpleByExampleWithDocumentResultSet( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { - - CursorEntity> entity = executeSimpleByExampleWithDocument(database, collectionName, example, - skip, limit, clazz); - return new CursorResultSet>(database, cursorDriver, entity, DocumentEntity.class, clazz); - } - @Override public DocumentCursor executeSimpleByExampleDocuments( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class clazz) throws ArangoException { - - HttpResponseEntity res = getSimpleByExample(database, collectionName, example, skip, limit); + final String database, + final String collectionName, + final Map example, + final int skip, + final int limit, + final Class clazz) throws ArangoException { + + final HttpResponseEntity res = getSimpleByExample(database, collectionName, example, skip, limit); return responseToDocumentCursor(database, clazz, res); } @@ -182,13 +83,14 @@ public DocumentCursor executeSimpleByExampleDocuments( @SuppressWarnings("unchecked") @Override public ScalarExampleEntity executeSimpleFirstExample( - String database, - String collectionName, - Map example, - Class clazz) throws ArangoException { + final String database, + final String collectionName, + final Map example, + final Class clazz) throws ArangoException { validateCollectionName(collectionName); - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/first-example"), null, + final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/first-example"), + null, EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put(EXAMPLE, example).get())); return createEntity(res, ScalarExampleEntity.class, clazz); @@ -198,11 +100,13 @@ public ScalarExampleEntity executeSimpleFirstExample( @SuppressWarnings("unchecked") @Override - public ScalarExampleEntity executeSimpleAny(String database, String collectionName, Class clazz) - throws ArangoException { + public ScalarExampleEntity executeSimpleAny( + final String database, + final String collectionName, + final Class clazz) throws ArangoException { validateCollectionName(collectionName); - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/any"), null, + final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/any"), null, EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).get())); return createEntity(res, ScalarExampleEntity.class, clazz); @@ -210,84 +114,20 @@ public ScalarExampleEntity executeSimpleAny(String database, String colle // ----- range -------------------- - @Override - public CursorEntity executeSimpleRange( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { - - return internalExecuteSimpleRange(database, collectionName, attribute, left, right, closed, skip, limit, clazz); - } - - @Override - public CursorResultSet executeSimpleRangeWithResultSet( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { - - CursorEntity entity = executeSimpleRange(database, collectionName, attribute, left, right, closed, skip, - limit, clazz); - return new CursorResultSet(database, cursorDriver, entity, clazz); - } - - @Override - public CursorEntity> executeSimpleRangeWithDocument( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { - - return internalExecuteSimpleRange(database, collectionName, attribute, left, right, closed, skip, limit, - DocumentEntity.class, clazz); - } - - @Override - public CursorResultSet> executeSimpleRangeWithDocumentResultSet( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { - - CursorEntity> entity = executeSimpleRangeWithDocument(database, collectionName, attribute, - left, right, closed, skip, limit, clazz); - return new CursorResultSet>(database, cursorDriver, entity, DocumentEntity.class, clazz); - } - @Override public DocumentCursor executeSimpleRangeWithDocuments( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class clazz) throws ArangoException { - - HttpResponseEntity res = getSimpleRange(database, collectionName, attribute, left, right, closed, skip, limit); + final String database, + final String collectionName, + final String attribute, + final Object left, + final Object right, + final Boolean closed, + final int skip, + final int limit, + final Class clazz) throws ArangoException { + + final HttpResponseEntity res = getSimpleRange(database, collectionName, attribute, left, right, closed, skip, + limit); return responseToDocumentCursor(database, clazz, res); } @@ -295,14 +135,14 @@ public DocumentCursor executeSimpleRangeWithDocuments( @Override public SimpleByResultEntity executeSimpleRemoveByExample( - String database, - String collectionName, - Map example, - Boolean waitForSync, - Integer limit) throws ArangoException { + final String database, + final String collectionName, + final Map example, + final Boolean waitForSync, + final Integer limit) throws ArangoException { validateCollectionName(collectionName); - HttpResponseEntity res = httpManager + final HttpResponseEntity res = httpManager .doPut(createEndpointUrl(database, "/_api/simple/remove-by-example"), null, EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put(EXAMPLE, example) .put(WAIT_FOR_SYNC, waitForSync) @@ -315,15 +155,16 @@ public SimpleByResultEntity executeSimpleRemoveByExample( @Override public SimpleByResultEntity executeSimpleReplaceByExample( - String database, - String collectionName, - Map example, - Map newValue, - Boolean waitForSync, - Integer limit) throws ArangoException { + final String database, + final String collectionName, + final Map example, + final Map newValue, + final Boolean waitForSync, + final Integer limit) throws ArangoException { validateCollectionName(collectionName); - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/replace-by-example"), null, + final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/replace-by-example"), + null, EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put(EXAMPLE, example) .put("newValue", newValue).put(WAIT_FOR_SYNC, waitForSync) .put(LIMIT, limit != null && limit.intValue() > 0 ? limit : null).get())); @@ -335,16 +176,17 @@ public SimpleByResultEntity executeSimpleReplaceByExample( @Override public SimpleByResultEntity executeSimpleUpdateByExample( - String database, - String collectionName, - Map example, - Map newValue, - Boolean keepNull, - Boolean waitForSync, - Integer limit) throws ArangoException { + final String database, + final String collectionName, + final Map example, + final Map newValue, + final Boolean keepNull, + final Boolean waitForSync, + final Integer limit) throws ArangoException { validateCollectionName(collectionName); - HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/update-by-example"), null, + final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/update-by-example"), + null, EntityFactory.toJsonString( new MapBuilder().put(COLLECTION, collectionName).put(EXAMPLE, example).put("newValue", newValue) .put("keepNull", keepNull).put(WAIT_FOR_SYNC, waitForSync) @@ -356,86 +198,29 @@ public SimpleByResultEntity executeSimpleUpdateByExample( // ----- Fulltext -------------------- - @Override - public CursorEntity executeSimpleFulltext( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { - - return internalExecuteSimpleFulltext(database, collectionName, attribute, query, skip, limit, index, clazz); - } - - @Override - public CursorResultSet executeSimpleFulltextWithResultSet( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { - - CursorEntity entity = executeSimpleFulltext(database, collectionName, attribute, query, skip, limit, index, - clazz); - return new CursorResultSet(database, cursorDriver, entity, clazz); - } - - @Override - public CursorEntity> executeSimpleFulltextWithDocument( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { - - return internalExecuteSimpleFulltext(database, collectionName, attribute, query, skip, limit, index, - DocumentEntity.class, clazz); - } - - @Override - public CursorResultSet> executeSimpleFulltextWithDocumentResultSet( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { - - CursorEntity> entity = executeSimpleFulltextWithDocument(database, collectionName, attribute, - query, skip, limit, index, clazz); - return new CursorResultSet>(database, cursorDriver, entity, DocumentEntity.class, clazz); - } - @Override public DocumentCursor executeSimpleFulltextWithDocuments( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class clazz) throws ArangoException { - - HttpResponseEntity res = getSimpleFulltext(database, collectionName, attribute, query, skip, limit, index); + final String database, + final String collectionName, + final String attribute, + final String query, + final int skip, + final int limit, + final String index, + final Class clazz) throws ArangoException { + + final HttpResponseEntity res = getSimpleFulltext(database, collectionName, attribute, query, skip, limit, + index); return responseToDocumentCursor(database, clazz, res); } // ----- private functions - private HttpResponseEntity getSimpleAll(String database, String collectionName, int skip, int limit) - throws ArangoException { + private HttpResponseEntity getSimpleAll( + final String database, + final String collectionName, + final int skip, + final int limit) throws ArangoException { validateCollectionName(collectionName); return httpManager.doPut(createEndpointUrl(database, "/_api/simple/all"), null, EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName) @@ -443,11 +228,11 @@ private HttpResponseEntity getSimpleAll(String database, String collectionName, } private HttpResponseEntity getSimpleByExample( - String database, - String collectionName, - Map example, - int skip, - int limit) throws ArangoException { + final String database, + final String collectionName, + final Map example, + final int skip, + final int limit) throws ArangoException { validateCollectionName(collectionName); return httpManager.doPut(createEndpointUrl(database, "/_api/simple/by-example"), null, EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put(EXAMPLE, example) @@ -455,14 +240,14 @@ private HttpResponseEntity getSimpleByExample( } private HttpResponseEntity getSimpleRange( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit) throws ArangoException { + final String database, + final String collectionName, + final String attribute, + final Object left, + final Object right, + final Boolean closed, + final int skip, + final int limit) throws ArangoException { validateCollectionName(collectionName); return httpManager.doPut(createEndpointUrl(database, "/_api/simple/range"), null, EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put("attribute", attribute) @@ -471,13 +256,13 @@ private HttpResponseEntity getSimpleRange( } private HttpResponseEntity getSimpleFulltext( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index) throws ArangoException { + final String database, + final String collectionName, + final String attribute, + final String query, + final int skip, + final int limit, + final String index) throws ArangoException { validateCollectionName(collectionName); return httpManager.doPut(createEndpointUrl(database, "/_api/simple/fulltext"), null, EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put("attribute", attribute) @@ -486,72 +271,16 @@ private HttpResponseEntity getSimpleFulltext( } @SuppressWarnings("unchecked") - private CursorEntity internalExecuteSimpleAll( - String database, - String collectionName, - int skip, - int limit, - Class... clazz) throws ArangoException { - - HttpResponseEntity res = getSimpleAll(database, collectionName, skip, limit); + private DocumentCursor responseToDocumentCursor( + final String database, + final Class clazz, + final HttpResponseEntity res) throws ArangoException { - return createEntity(res, CursorEntity.class, clazz); - } - - @SuppressWarnings("unchecked") - private CursorEntity internalExecuteSimpleFulltext( - String database, - String collectionName, - String attribute, - String query, - int skip, - int limit, - String index, - Class... clazz) throws ArangoException { - - HttpResponseEntity res = getSimpleFulltext(database, collectionName, attribute, query, skip, limit, index); - return createEntity(res, CursorEntity.class, clazz); - } - - @SuppressWarnings("unchecked") - private CursorEntity internalExecuteSimpleByExample( - String database, - String collectionName, - Map example, - int skip, - int limit, - Class... clazz) throws ArangoException { - - HttpResponseEntity res = getSimpleByExample(database, collectionName, example, skip, limit); - - return createEntity(res, CursorEntity.class, clazz); - } - - @SuppressWarnings("unchecked") - private CursorEntity internalExecuteSimpleRange( - String database, - String collectionName, - String attribute, - Object left, - Object right, - Boolean closed, - int skip, - int limit, - Class... clazz) throws ArangoException { - - HttpResponseEntity res = getSimpleRange(database, collectionName, attribute, left, right, closed, skip, limit); - return createEntity(res, CursorEntity.class, clazz); - } - - @SuppressWarnings("unchecked") - private DocumentCursor responseToDocumentCursor(String database, Class clazz, HttpResponseEntity res) - throws ArangoException { - - CursorEntity> baseCursorEntity = createEntity(res, CursorEntity.class, DocumentEntity.class, - clazz); + final CursorEntity> baseCursorEntity = createEntity(res, CursorEntity.class, + DocumentEntity.class, clazz); - DocumentCursorResult> baseCursor = new DocumentCursorResult>(database, - cursorDriver, baseCursorEntity, DocumentEntity.class, clazz); + final DocumentCursorResult> baseCursor = new DocumentCursorResult>( + database, cursorDriver, baseCursorEntity, DocumentEntity.class, clazz); return new DocumentCursor(baseCursor); } diff --git a/src/main/java/com/arangodb/util/ResultSetUtils.java b/src/main/java/com/arangodb/util/ResultSetUtils.java deleted file mode 100644 index 89570362e..000000000 --- a/src/main/java/com/arangodb/util/ResultSetUtils.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2012,2013 tamtam180 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arangodb.util; - -import java.util.ArrayList; -import java.util.List; - -import com.arangodb.ArangoException; -import com.arangodb.CursorResultSet; - -/** - * @author tamtam180 - kirscheless at gmail.com - * - */ -public class ResultSetUtils { - - private ResultSetUtils() { - // this is a helper class - } - - public static List toList(CursorResultSet rs) throws ArangoException { - - if (rs == null) { - return new ArrayList(0); - } - - ArrayList result = new ArrayList(rs.getTotalCount()); - while (rs.hasNext()) { - result.add(rs.next()); - } - - return result; - - } - -} diff --git a/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java b/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java index 1cbe948a6..fef8e8352 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorResultSetTest.java @@ -19,11 +19,14 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; +import java.util.Iterator; import java.util.Map; import org.junit.Before; import org.junit.Test; +import com.arangodb.entity.DocumentEntity; +import com.arangodb.util.AqlQueryOptions; import com.arangodb.util.MapBuilder; /** @@ -51,7 +54,6 @@ public void setup() throws ArangoException { } - @SuppressWarnings("deprecation") @Test public void test1() throws ArangoException { @@ -61,11 +63,14 @@ public void test1() throws ArangoException { final Map bindVars = new MapBuilder().put("age", 90).get(); // 全件とれる範囲 - final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, - TestComplexEntity01.class, true, 20); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(20); + aqlQueryOptions.setCount(true); + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, + TestComplexEntity01.class); int count = 0; - for (final TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs.asEntityList()) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -73,7 +78,6 @@ public void test1() throws ArangoException { } - @SuppressWarnings("deprecation") @Test public void test2() throws ArangoException { @@ -82,11 +86,14 @@ public void test2() throws ArangoException { final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; final Map bindVars = new MapBuilder().put("age", 90).get(); - final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, - TestComplexEntity01.class, true, 10); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(10); + aqlQueryOptions.setCount(true); + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, + TestComplexEntity01.class); int count = 0; - for (final TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs.asEntityList()) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -94,7 +101,6 @@ public void test2() throws ArangoException { } - @SuppressWarnings("deprecation") @Test public void test3() throws ArangoException { @@ -103,11 +109,14 @@ public void test3() throws ArangoException { final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; final Map bindVars = new MapBuilder().put("age", 90).get(); - final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, - TestComplexEntity01.class, true, 5); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(5); + aqlQueryOptions.setCount(true); + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, + TestComplexEntity01.class); int count = 0; - for (final TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs.asEntityList()) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -115,7 +124,6 @@ public void test3() throws ArangoException { } - @SuppressWarnings("deprecation") @Test public void test4() throws ArangoException { @@ -124,11 +132,14 @@ public void test4() throws ArangoException { final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; final Map bindVars = new MapBuilder().put("age", 90).get(); - final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, - TestComplexEntity01.class, true, 3); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(3); + aqlQueryOptions.setCount(true); + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, + TestComplexEntity01.class); int count = 0; - for (final TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs.asEntityList()) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -136,7 +147,6 @@ public void test4() throws ArangoException { } - @SuppressWarnings("deprecation") @Test public void test5() throws ArangoException { @@ -145,11 +155,14 @@ public void test5() throws ArangoException { final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; final Map bindVars = new MapBuilder().put("age", 90).get(); - final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, - TestComplexEntity01.class, true, 1); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(1); + aqlQueryOptions.setCount(true); + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, + TestComplexEntity01.class); int count = 0; - for (final TestComplexEntity01 obj : rs) { + for (final TestComplexEntity01 obj : rs.asEntityList()) { assertThat(obj.getAge(), is(90 + count)); count++; } @@ -162,7 +175,6 @@ public void test5() throws ArangoException { * * @throws ArangoException */ - @SuppressWarnings("deprecation") @Test public void test6() throws ArangoException { @@ -171,12 +183,16 @@ public void test6() throws ArangoException { final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; final Map bindVars = new MapBuilder().put("age", 90).get(); - final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, - TestComplexEntity01.class, true, 2); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(2); + aqlQueryOptions.setCount(true); + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, + TestComplexEntity01.class); int count = 0; - while (rs.hasNext()) { - final TestComplexEntity01 obj = rs.next(); + final Iterator> iterator = rs.iterator(); + while (iterator.hasNext()) { + final TestComplexEntity01 obj = iterator.next().getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; } @@ -190,7 +206,6 @@ public void test6() throws ArangoException { * * @throws ArangoException */ - @SuppressWarnings("deprecation") @Test public void test7() throws ArangoException { @@ -199,12 +214,16 @@ public void test7() throws ArangoException { final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; final Map bindVars = new MapBuilder().put("age", 90).get(); - final CursorResultSet rs = driver.executeQueryWithResultSet(query, bindVars, - TestComplexEntity01.class, true, 2); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(2); + aqlQueryOptions.setCount(true); + final DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, + TestComplexEntity01.class); int count = 0; - while (rs.hasNext()) { - final TestComplexEntity01 obj = rs.next(); + final Iterator> iterator = rs.iterator(); + while (iterator.hasNext()) { + final TestComplexEntity01 obj = iterator.next().getEntity(); assertThat(obj.getAge(), is(90 + count)); count++; if (count == 5) { diff --git a/src/test/java/com/arangodb/ArangoDriverCursorTest.java b/src/test/java/com/arangodb/ArangoDriverCursorTest.java index 8a5821ed5..96eb71e66 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorTest.java @@ -31,6 +31,7 @@ import com.arangodb.entity.CursorEntity; import com.arangodb.entity.WarningEntity; +import com.arangodb.util.AqlQueryOptions; import com.arangodb.util.MapBuilder; /** @@ -75,7 +76,6 @@ public void test_validateQuery_400_1() throws ArangoException { public void test_validateQuery_400_2() throws ArangoException { } - @SuppressWarnings("deprecation") @Test public void test_executeQuery() throws ArangoException { @@ -100,16 +100,18 @@ public void test_executeQuery() throws ArangoException { // 全件とれる範囲 { - final CursorEntity result = driver. executeQuery(query, bindVars, - TestComplexEntity01.class, true, 20); - assertThat(result.size(), is(10)); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(20); + aqlQueryOptions.setCount(true); + final DocumentCursor result = driver. executeDocumentQuery(query, + bindVars, aqlQueryOptions, TestComplexEntity01.class); + assertThat(result.asEntityList().size(), is(10)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(false)); } } - @SuppressWarnings("deprecation") @Test public void test_executeQuery_2() throws ArangoException { @@ -135,9 +137,12 @@ public void test_executeQuery_2() throws ArangoException { // ちまちまとる範囲 long cursorId; { - final CursorEntity result = driver.executeQuery(query, bindVars, - TestComplexEntity01.class, true, 3); - assertThat(result.size(), is(3)); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(3); + aqlQueryOptions.setCount(true); + final DocumentCursor result = driver.executeDocumentQuery(query, bindVars, + aqlQueryOptions, TestComplexEntity01.class); + assertThat(result.asEntityList().size(), is(3)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(true)); assertThat(result.getCursorId(), is(not(-1L))); @@ -177,7 +182,6 @@ public void test_executeQuery_2() throws ArangoException { } - @SuppressWarnings("deprecation") @Test public void test_executeQueryFullCount() throws ArangoException { @@ -202,9 +206,13 @@ public void test_executeQueryFullCount() throws ArangoException { // 全件とれる範囲 { - final CursorEntity result = driver. executeQuery(query, bindVars, - TestComplexEntity01.class, true, 1, true); - assertThat(result.size(), is(1)); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(1); + aqlQueryOptions.setCount(true); + aqlQueryOptions.setFullCount(true); + final DocumentCursor result = driver. executeDocumentQuery(query, + bindVars, aqlQueryOptions, TestComplexEntity01.class); + assertThat(result.asEntityList().size(), is(1)); assertThat(result.getCount(), is(2)); assertThat(result.getFullCount(), is(90)); assertThat(result.hasMore(), is(true)); @@ -212,7 +220,6 @@ public void test_executeQueryFullCount() throws ArangoException { } - @SuppressWarnings("deprecation") @Test public void test_executeQueryUniqueResult() throws ArangoException { @@ -237,9 +244,12 @@ public void test_executeQueryUniqueResult() throws ArangoException { // 全件とれる範囲 { - final CursorEntity result = driver. executeQuery(query, bindVars, - TestComplexEntity01.class, true, 2); - assertThat(result.size(), is(2)); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(2); + aqlQueryOptions.setCount(true); + final DocumentCursor result = driver. executeDocumentQuery(query, + bindVars, aqlQueryOptions, TestComplexEntity01.class); + assertThat(result.asEntityList().size(), is(2)); assertThat(result.getCount(), is(2)); String msg = ""; try { @@ -254,11 +264,14 @@ public void test_executeQueryUniqueResult() throws ArangoException { // "SELECT t FROM unit_test_query_test t WHERE t.age >= @age@"; query = "FOR t IN unit_test_query_test FILTER t.age == @age LIMIT 2 RETURN t"; { - final CursorEntity result = driver. executeQuery(query, bindVars, - TestComplexEntity01.class, true, 2); - assertThat(result.size(), is(1)); + final AqlQueryOptions aqlQueryOptions = new AqlQueryOptions(); + aqlQueryOptions.setBatchSize(2); + aqlQueryOptions.setCount(true); + final DocumentCursor result = driver. executeDocumentQuery(query, + bindVars, aqlQueryOptions, TestComplexEntity01.class); + assertThat(result.asEntityList().size(), is(1)); assertThat(result.getCount(), is(1)); - final TestComplexEntity01 entity = result.getUniqueResult(); + final TestComplexEntity01 entity = result.getUniqueResult().getEntity(); assertThat(entity.getAge(), is(10)); } } diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java index 579e88bdd..cf2c5fb91 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetTest.java @@ -26,7 +26,6 @@ import org.junit.Before; import org.junit.Test; -import com.arangodb.entity.CursorEntity; import com.arangodb.entity.GraphEntity; import com.arangodb.entity.PlainEdgeEntity; import com.arangodb.entity.marker.VertexEntity; @@ -47,23 +46,20 @@ public void setup() throws ArangoException { } } - @SuppressWarnings("deprecation") @Test public void test_getEdges_All() throws ArangoException { final GraphEntity graph = this.createTestGraph(); - final CursorEntity cursor = driver.graphGetEdges(graph.getName()); + final EdgeCursor cursor = driver.graphGetEdgeCursor(graph.getName()); assertThat(cursor.getCount(), is(8)); assertThat(cursor.getCode(), is(201)); - assertThat(cursor.isError(), is(false)); assertThat(cursor.hasMore(), is(false)); assertThat(cursor.getCursorId(), is(-1L)); - assertThat(cursor.getResults().size(), is(8)); - assertThat(cursor.get(0).getFromCollection(), startsWith("Country/")); - assertThat(cursor.get(0).getToCollection(), startsWith("Country/")); + assertThat(cursor.asEntityList().size(), is(8)); + assertThat(cursor.asEntityList().get(0).getFromCollection(), startsWith("Country/")); + assertThat(cursor.asEntityList().get(0).getToCollection(), startsWith("Country/")); } - @SuppressWarnings("deprecation") @Test public void test_getEdges_Vertex() throws ArangoException { final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", @@ -81,15 +77,15 @@ public void test_getEdges_Vertex() throws ArangoException { driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), new TestComplexEntity02(4, 5, 6), null); - CursorEntity cursor = driver.graphGetEdges(GRAPH_NAME, TestComplexEntity02.class, - vertex1.getDocumentHandle()); + EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, + vertex1.getDocumentHandle(), null, null); assertThat(cursor.getCount(), is(2)); - cursor = driver.graphGetEdges(GRAPH_NAME, TestComplexEntity02.class, vertex2.getDocumentHandle()); + cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, vertex2.getDocumentHandle(), null, + null); assertThat(cursor.getCount(), is(1)); } - @SuppressWarnings("deprecation") @Test public void test_GetEdgesByExampleObject() throws ArangoException { final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); @@ -114,18 +110,17 @@ public void test_GetEdgesByExampleObject() throws ArangoException { driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), new TestComplexEntity02(7, 8, 9), null); - CursorEntity cursor = driver.graphGetEdgesByExampleObject(GRAPH_NAME, + EdgeCursor cursor = driver.graphGetEdgeCursorByExample(GRAPH_NAME, TestComplexEntity02.class, new TestComplexEntity01(null, null, 38)); assertThat(cursor.getCount(), is(3)); - cursor = driver.graphGetEdgesByExampleObject(GRAPH_NAME, TestComplexEntity02.class, v3); + cursor = driver.graphGetEdgeCursorByExample(GRAPH_NAME, TestComplexEntity02.class, v3); assertThat(cursor.getCount(), is(1)); - assertThat(cursor.get(0).getClass().getName(), is(TestComplexEntity02.class.getName())); - assertThat(cursor.get(0).getX(), is(4)); + assertThat(cursor.asEntityList().get(0).getClass().getName(), is(TestComplexEntity02.class.getName())); + assertThat(cursor.asEntityList().get(0).getX(), is(4)); } - @SuppressWarnings("deprecation") @Test public void test_GetEdgesByExampleMap() throws ArangoException { final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); @@ -153,15 +148,15 @@ public void test_GetEdgesByExampleMap() throws ArangoException { final Map exampleVertex = new HashMap(); exampleVertex.put("user", "Homer"); - CursorEntity cursor = driver.graphGetEdgesByExampleMap(GRAPH_NAME, + EdgeCursor cursor = driver.graphGetEdgeCursorByExample(GRAPH_NAME, TestComplexEntity02.class, exampleVertex); assertThat(cursor.getCount(), is(2)); exampleVertex.put("user", "Bart"); - cursor = driver.graphGetEdgesByExampleMap(GRAPH_NAME, TestComplexEntity02.class, exampleVertex); + cursor = driver.graphGetEdgeCursorByExample(GRAPH_NAME, TestComplexEntity02.class, exampleVertex); assertThat(cursor.getCount(), is(1)); - assertThat(cursor.get(0).getClass().getName(), is(TestComplexEntity02.class.getName())); - assertThat(cursor.get(0).getX(), is(4)); + assertThat(cursor.asEntityList().get(0).getClass().getName(), is(TestComplexEntity02.class.getName())); + assertThat(cursor.asEntityList().get(0).getX(), is(4)); } // diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java deleted file mode 100644 index 4f4f60988..000000000 --- a/src/test/java/com/arangodb/ArangoDriverSimpleGeoTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2012,2013 tamtam180 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arangodb; - -import java.io.IOException; -import java.util.List; - -import org.junit.Before; -import org.junit.Test; - -import com.arangodb.entity.IndexType; -import com.arangodb.util.TestUtils; - -/** - * @author tamtam180 - kirscheless at gmail.com - * - */ -@Deprecated -public class ArangoDriverSimpleGeoTest extends BaseTest { - - private final String collectionName = "unit_test_simple_geo_test"; - - @Before - public void setup() throws ArangoException, IOException { - - // index破棄のために一度削除する - try { - driver.deleteCollection(collectionName); - } catch (final ArangoException e) { - } - // Collectionを作る - try { - driver.createCollection(collectionName); - } catch (final ArangoException e) { - } - driver.truncateCollection(collectionName); - - // テストデータを作る - final List stations = TestUtils.readStations(); - for (final Station station : stations) { - driver.createDocument(collectionName, station, null); - } - - } - - @Test - public void test() throws ArangoException { - - // create geo index - driver.createIndex(collectionName, IndexType.GEO, false, "lat", "lot"); - - // Tokyo Station: lat=35.681391, lon=139.766103 - - } - -} diff --git a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java index f4be258ab..c745324db 100644 --- a/src/test/java/com/arangodb/ArangoDriverSimpleTest.java +++ b/src/test/java/com/arangodb/ArangoDriverSimpleTest.java @@ -38,7 +38,6 @@ import com.arangodb.entity.ScalarExampleEntity; import com.arangodb.entity.SimpleByResultEntity; import com.arangodb.util.MapBuilder; -import com.arangodb.util.ResultSetUtils; import com.arangodb.util.TestUtils; /** @@ -248,7 +247,7 @@ public void test_replace_by_example() throws ArangoException { } - @SuppressWarnings({ "deprecation", "rawtypes", "unchecked" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void test_replace_by_example_with_limit() throws ArangoException { @@ -262,9 +261,9 @@ public void test_replace_by_example_with_limit() throws ArangoException { assertThat(entity.getUpdated(), is(0)); // Get Replaced Document - final CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, + final DocumentCursor rs = driver.executeSimpleByExampleDocuments(COLLECTION_NAME, new MapBuilder().put("abc", "xxx").get(), 0, 0, Map.class); - final List list = ResultSetUtils.toList(rs); + final List list = rs.asEntityList(); assertThat(list.size(), is(3)); for (final Map map : list) { @@ -274,7 +273,7 @@ public void test_replace_by_example_with_limit() throws ArangoException { } - @SuppressWarnings({ "deprecation", "rawtypes", "unchecked" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void test_update_by_example() throws ArangoException { @@ -289,9 +288,9 @@ public void test_update_by_example() throws ArangoException { assertThat(entity.getUpdated(), is(10)); // Get Replaced Document - final CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, + final DocumentCursor rs = driver.executeSimpleByExampleDocuments(COLLECTION_NAME, new MapBuilder().put("abc", "xxx").get(), 0, 0, Map.class); - final List list = ResultSetUtils.toList(rs); + final List list = rs.asEntityList(); assertThat(list.size(), is(10)); for (final Map map : list) { @@ -305,7 +304,7 @@ public void test_update_by_example() throws ArangoException { } - @SuppressWarnings({ "deprecation", "rawtypes", "unchecked" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void test_update_by_example_with_limit() throws ArangoException { @@ -320,9 +319,9 @@ public void test_update_by_example_with_limit() throws ArangoException { assertThat(entity.getUpdated(), is(3)); // Get Replaced Document - final CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, + final DocumentCursor rs = driver.executeSimpleByExampleDocuments(COLLECTION_NAME, new MapBuilder().put("age", 999).get(), 0, 0, Map.class); - final List list = ResultSetUtils.toList(rs); + final List list = rs.asEntityList(); assertThat(list.size(), is(3)); for (final Map map : list) { @@ -336,7 +335,7 @@ public void test_update_by_example_with_limit() throws ArangoException { } - @SuppressWarnings({ "deprecation", "rawtypes", "unchecked" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void test_update_by_example_with_keepnull() throws ArangoException { @@ -351,9 +350,9 @@ public void test_update_by_example_with_keepnull() throws ArangoException { assertThat(entity.getUpdated(), is(10)); // Get Replaced Document - final CursorResultSet rs = driver.executeSimpleByExampleWithResusltSet(COLLECTION_NAME, + final DocumentCursor rs = driver.executeSimpleByExampleDocuments(COLLECTION_NAME, new MapBuilder().put("abc", "xxx").get(), 0, 0, Map.class); - final List list = ResultSetUtils.toList(rs); + final List list = rs.asEntityList(); assertThat(list.size(), is(10)); for (final Map map : list) { From 4e4ed435131eb9ec2d8854c5eebbf630799bf1e3 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 8 Jun 2016 13:13:57 +0200 Subject: [PATCH 24/56] User Post changed (-database), new User-Methode grantDatabaseAccess --- src/main/java/com/arangodb/ArangoDriver.java | 23 +- .../java/com/arangodb/BaseArangoDriver.java | 4 +- .../com/arangodb/InternalUsersDriver.java | 22 +- .../impl/InternalUsersDriverImpl.java | 67 ++-- .../com/arangodb/ArangoDriverAuthTest.java | 352 +++++++++--------- .../com/arangodb/ArangoDriverCursorTest.java | 2 - 6 files changed, 240 insertions(+), 230 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 2ff1949b4..3a4b1e747 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -2859,7 +2859,7 @@ public DefaultEntity createUser( final String passwd, final Boolean active, final Map extra) throws ArangoException { - return usersDriver.createUser(getDefaultDatabase(), username, passwd, active, extra); + return usersDriver.createUser(username, passwd, active, extra); } /** @@ -2881,7 +2881,7 @@ public DefaultEntity replaceUser( final String passwd, final Boolean active, final Map extra) throws ArangoException { - return usersDriver.replaceUser(getDefaultDatabase(), username, passwd, active, extra); + return usersDriver.replaceUser(username, passwd, active, extra); } /** @@ -2903,7 +2903,7 @@ public DefaultEntity updateUser( final String passwd, final Boolean active, final Map extra) throws ArangoException { - return usersDriver.updateUser(getDefaultDatabase(), username, passwd, active, extra); + return usersDriver.updateUser(username, passwd, active, extra); } /** @@ -2915,7 +2915,7 @@ public DefaultEntity updateUser( * @throws ArangoException */ public DefaultEntity deleteUser(final String username) throws ArangoException { - return usersDriver.deleteUser(getDefaultDatabase(), username); + return usersDriver.deleteUser(username); } /** @@ -2927,7 +2927,20 @@ public DefaultEntity deleteUser(final String username) throws ArangoException { * @throws ArangoException */ public UserEntity getUser(final String username) throws ArangoException { - return usersDriver.getUser(getDefaultDatabase(), username); + return usersDriver.getUser(username); + } + + /** + * Grants the User access to the given database. + * + * @param username + * the username as string + * @param database + * @return + * @throws ArangoException + */ + public DefaultEntity grantDatabaseAccess(String username, String database) throws ArangoException { + return usersDriver.grantDatabaseAccess(username, database); } /** diff --git a/src/main/java/com/arangodb/BaseArangoDriver.java b/src/main/java/com/arangodb/BaseArangoDriver.java index 0713c62c5..570ae8324 100644 --- a/src/main/java/com/arangodb/BaseArangoDriver.java +++ b/src/main/java/com/arangodb/BaseArangoDriver.java @@ -407,8 +407,8 @@ protected String createEndpointUrl(String database, String str, Object... paths) return createEndpointUrl(database, newPaths); } - protected String createUserEndpointUrl(String database, Object... paths) throws ArangoException { - return createEndpointUrl(database, "/_api/user", paths); + protected String createUserEndpointUrl(Object... paths) throws ArangoException { + return createEndpointUrl(null, "/_api/user", paths); } protected String createJobEndpointUrl(String database, Object... paths) throws ArangoException { diff --git a/src/main/java/com/arangodb/InternalUsersDriver.java b/src/main/java/com/arangodb/InternalUsersDriver.java index bc8474bc7..6b17d68c7 100644 --- a/src/main/java/com/arangodb/InternalUsersDriver.java +++ b/src/main/java/com/arangodb/InternalUsersDriver.java @@ -10,19 +10,21 @@ /** * Created by fbartels on 10/27/14. */ -public interface InternalUsersDriver extends BaseDriverInterface { - DefaultEntity createUser(String database, String username, String passwd, Boolean active, - Map extra) throws ArangoException; +public interface InternalUsersDriver extends BaseDriverInterface { + DefaultEntity createUser(String username, String passwd, Boolean active, Map extra) + throws ArangoException; - DefaultEntity deleteUser(String database, String username) throws ArangoException; + DefaultEntity deleteUser(String username) throws ArangoException; - UserEntity getUser(String database, String username) throws ArangoException; + UserEntity getUser(String username) throws ArangoException; - UsersEntity getUsers(String database) throws ArangoException; + UsersEntity getUsers() throws ArangoException; - DefaultEntity replaceUser(String database, String username, String passwd, Boolean active, - Map extra) throws ArangoException; + DefaultEntity replaceUser(String username, String passwd, Boolean active, Map extra) + throws ArangoException; - DefaultEntity updateUser(String database, String username, String passwd, Boolean active, - Map extra) throws ArangoException; + DefaultEntity updateUser(String username, String passwd, Boolean active, Map extra) + throws ArangoException; + + DefaultEntity grantDatabaseAccess(final String username, final String database) throws ArangoException; } diff --git a/src/main/java/com/arangodb/impl/InternalUsersDriverImpl.java b/src/main/java/com/arangodb/impl/InternalUsersDriverImpl.java index 739461546..c39827cb1 100644 --- a/src/main/java/com/arangodb/impl/InternalUsersDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalUsersDriverImpl.java @@ -38,80 +38,77 @@ public class InternalUsersDriverImpl extends BaseArangoDriverImpl implements com private static final String EXTRA = "extra"; private static final String ACTIVE = "active"; private static final String PW = "passwd"; - private static final String USERNAME = "username"; + private static final String USERNAME = "user"; + private static final String GRANT = "grant"; + private static final String DATABASE = "database"; + private static final String READ_WRITE = "rw"; InternalUsersDriverImpl(ArangoConfigure configure, HttpManager httpManager) { super(configure, httpManager); } @Override - public DefaultEntity createUser( - String database, - String username, - String passwd, - Boolean active, - Map extra) throws ArangoException { - - HttpResponseEntity res = httpManager.doPost(createUserEndpointUrl(database), null, EntityFactory.toJsonString( + public DefaultEntity createUser(String username, String passwd, Boolean active, Map extra) + throws ArangoException { + + HttpResponseEntity res = httpManager.doPost(createUserEndpointUrl(), null, EntityFactory.toJsonString( new MapBuilder().put(USERNAME, username).put(PW, passwd).put(ACTIVE, active).put(EXTRA, extra).get())); return createEntity(res, DefaultEntity.class); } @Override - public DefaultEntity deleteUser(String database, String username) throws ArangoException { + public DefaultEntity deleteUser(String username) throws ArangoException { - HttpResponseEntity res = httpManager.doDelete(createUserEndpointUrl(database, StringUtils.encodeUrl(username)), - null); + HttpResponseEntity res = httpManager.doDelete(createUserEndpointUrl(StringUtils.encodeUrl(username)), null); return createEntity(res, DefaultEntity.class); } @Override - public UserEntity getUser(String database, String username) throws ArangoException { + public UserEntity getUser(String username) throws ArangoException { - HttpResponseEntity res = httpManager.doGet(createUserEndpointUrl(database, StringUtils.encodeUrl(username)), - null); + HttpResponseEntity res = httpManager.doGet(createUserEndpointUrl(StringUtils.encodeUrl(username)), null); return createEntity(res, UserEntity.class); } @Override - public UsersEntity getUsers(String database) throws ArangoException { + public UsersEntity getUsers() throws ArangoException { - HttpResponseEntity res = httpManager.doGet(createUserEndpointUrl(database), null); + HttpResponseEntity res = httpManager.doGet(createUserEndpointUrl(), null); return createEntity(res, UsersEntity.class); } @Override - public DefaultEntity replaceUser( - String database, - String username, - String passwd, - Boolean active, - Map extra) throws ArangoException { - - HttpResponseEntity res = httpManager.doPut(createUserEndpointUrl(database, StringUtils.encodeUrl(username)), - null, + public DefaultEntity replaceUser(String username, String passwd, Boolean active, Map extra) + throws ArangoException { + + HttpResponseEntity res = httpManager.doPut(createUserEndpointUrl(StringUtils.encodeUrl(username)), null, EntityFactory.toJsonString(new MapBuilder().put(PW, passwd).put(ACTIVE, active).put(EXTRA, extra).get())); return createEntity(res, DefaultEntity.class); } @Override - public DefaultEntity updateUser( - String database, - String username, - String passwd, - Boolean active, - Map extra) throws ArangoException { - - HttpResponseEntity res = httpManager.doPatch(createUserEndpointUrl(database, StringUtils.encodeUrl(username)), - null, + public DefaultEntity updateUser(String username, String passwd, Boolean active, Map extra) + throws ArangoException { + + HttpResponseEntity res = httpManager.doPatch(createUserEndpointUrl(StringUtils.encodeUrl(username)), null, EntityFactory.toJsonString(new MapBuilder().put(PW, passwd).put(ACTIVE, active).put(EXTRA, extra).get())); return createEntity(res, DefaultEntity.class); } + @Override + public DefaultEntity grantDatabaseAccess(String username, String database) throws ArangoException { + + final HttpResponseEntity res = httpManager.doPut( + createUserEndpointUrl(StringUtils.encodeUrl(username), DATABASE, StringUtils.encodeUrl(database)), null, + EntityFactory.toJsonString(new MapBuilder().put(GRANT, READ_WRITE).get())); + + return createEntity(res, DefaultEntity.class); + } + } diff --git a/src/test/java/com/arangodb/ArangoDriverAuthTest.java b/src/test/java/com/arangodb/ArangoDriverAuthTest.java index 9f405a4bb..955d1df37 100644 --- a/src/test/java/com/arangodb/ArangoDriverAuthTest.java +++ b/src/test/java/com/arangodb/ArangoDriverAuthTest.java @@ -31,181 +31,181 @@ */ public class ArangoDriverAuthTest { - @Test - public void test_auth() throws ArangoException { - - ArangoConfigure configure = new ArangoConfigure(); - configure.setUser(null); - configure.setPassword(null); - configure.init(); - - ArangoDriver driver = new ArangoDriver(configure); - try { - driver.getTime(); - fail(); - } catch (ArangoException e) { - assertThat(e.isUnauthorized(), is(true)); - assertThat(e.getEntity().getStatusCode(), is(401)); - assertThat(e.getErrorMessage(), containsString("Unauthorized")); - } - - configure.shutdown(); - } - - @Test - public void test_auth_root() throws ArangoException { - - ArangoConfigure configure = new ArangoConfigure(); - configure.setUser("root"); - configure.setPassword(""); - configure.init(); - - ArangoDriver driver = new ArangoDriver(configure); - driver.getTime(); - - configure.shutdown(); - } - - @Test - public void test_auth_added_user() throws ArangoException { - - ArangoConfigure configure = new ArangoConfigure(); - configure.setUser("root"); - configure.setPassword(""); - configure.init(); - - ArangoDriver driver = new ArangoDriver(configure); - - // Create User - try { - driver.createUser("userA", "passA", true, null); - } catch (ArangoException e) { - driver.replaceUser("userA", "passA", true, null); - } - - configure.shutdown(); - - configure = new ArangoConfigure(); - configure.setUser("userA"); - configure.setPassword("passA"); - configure.init(); - driver = new ArangoDriver(configure); - - driver.getTime(); - configure.shutdown(); - - } - - @Test - public void test_auth_added_user_inactive() throws ArangoException { - - ArangoConfigure configure = new ArangoConfigure(); - configure.setUser("root"); - configure.setPassword(""); - configure.init(); - - ArangoDriver driver = new ArangoDriver(configure); - - // Create User - try { - driver.createUser("userB", "passB", false, null); - } catch (ArangoException e) { - driver.replaceUser("userB", "passB", false, null); - } - - configure.shutdown(); - - configure = new ArangoConfigure(); - configure.setUser("userB"); - configure.setPassword("passB"); - configure.init(); - driver = new ArangoDriver(configure); - - // Memo: Failed version 1.2.3 - try { - driver.getTime(); - fail(""); - } catch (ArangoException e) { - assertThat(e.getCode(), is(401)); - assertThat(e.getErrorNumber(), is(0)); - assertThat(e.getErrorMessage(), containsString("Unauthorized")); - } - configure.shutdown(); - - } - - @Test - public void test_auth_multibyte_username() throws ArangoException { - - ArangoConfigure configure = new ArangoConfigure(); - configure.setUser("root"); - configure.setPassword(""); - configure.init(); - - ArangoDriver driver = new ArangoDriver(configure); - - // Create User - try { - driver.createUser("ゆーざーA", "pass", false, null); - } catch (ArangoException e) { - driver.replaceUser("ゆーざーA", "pass", false, null); - } - - configure.shutdown(); - - ArangoConfigure configure2 = new ArangoConfigure(); - configure2.setUser("ゆーざーA"); - configure2.setPassword("pass"); - configure2.init(); - ArangoDriver driver2 = new ArangoDriver(configure2); - - try { - driver2.getTime(); - fail(""); - } catch (ArangoException e) { - assertThat(e.getCode(), is(401)); - assertThat(e.getErrorNumber(), is(0)); - assertThat(e.getErrorMessage(), containsString("Unauthorized")); - } - - configure2.shutdown(); - } - - @Test - public void test_auth_multibyte_password() throws ArangoException { - - ArangoConfigure configure = new ArangoConfigure(); - configure.setUser("root"); - configure.setPassword(""); - configure.init(); - - ArangoDriver driver = new ArangoDriver(configure); - - // Create User - try { - driver.createUser("user-A", "パスワード", false, null); - } catch (ArangoException e) { - driver.replaceUser("user-A", "パスワード", false, null); - } - - configure.shutdown(); - - configure = new ArangoConfigure(); - configure.setUser("user-A"); - configure.setPassword("パスワード"); - configure.init(); - driver = new ArangoDriver(configure); - - try { - driver.getTime(); - fail(""); - } catch (ArangoException e) { - assertThat(e.getErrorNumber(), is(0)); - assertThat(e.getCode(), is(401)); - assertThat(e.getErrorMessage(), containsString("Unauthorized")); - } - configure.shutdown(); - - } + @Test + public void test_auth() throws ArangoException { + + ArangoConfigure configure = new ArangoConfigure(); + configure.setUser(null); + configure.setPassword(null); + configure.init(); + + ArangoDriver driver = new ArangoDriver(configure); + try { + driver.getTime(); + fail(); + } catch (ArangoException e) { + assertThat(e.isUnauthorized(), is(true)); + assertThat(e.getEntity().getStatusCode(), is(401)); + assertThat(e.getErrorMessage(), containsString("Unauthorized")); + } + + configure.shutdown(); + } + + @Test + public void test_auth_root() throws ArangoException { + + ArangoConfigure configure = new ArangoConfigure(); + configure.setUser("root"); + configure.setPassword(""); + configure.init(); + + ArangoDriver driver = new ArangoDriver(configure); + driver.getTime(); + + configure.shutdown(); + } + + @Test + public void test_auth_added_user() throws ArangoException { + + ArangoConfigure configure = new ArangoConfigure(); + configure.setUser("root"); + configure.setPassword(""); + configure.init(); + + ArangoDriver driver = new ArangoDriver(configure); + + // Create User + final String username = "userA"; + try { + driver.createUser(username, "passA", true, null); + } catch (ArangoException e) { + driver.replaceUser(username, "passA", true, null); + } + driver.grantDatabaseAccess(username, "_system"); + configure.shutdown(); + + configure = new ArangoConfigure(); + configure.setUser(username); + configure.setPassword("passA"); + configure.init(); + driver = new ArangoDriver(configure); + driver.getTime(); + configure.shutdown(); + + } + + @Test + public void test_auth_added_user_inactive() throws ArangoException { + + ArangoConfigure configure = new ArangoConfigure(); + configure.setUser("root"); + configure.setPassword(""); + configure.init(); + + ArangoDriver driver = new ArangoDriver(configure); + + // Create User + try { + driver.createUser("userB", "passB", false, null); + } catch (ArangoException e) { + driver.replaceUser("userB", "passB", false, null); + } + + configure.shutdown(); + + configure = new ArangoConfigure(); + configure.setUser("userB"); + configure.setPassword("passB"); + configure.init(); + driver = new ArangoDriver(configure); + + // Memo: Failed version 1.2.3 + try { + driver.getTime(); + fail(""); + } catch (ArangoException e) { + assertThat(e.getCode(), is(401)); + assertThat(e.getErrorNumber(), is(0)); + assertThat(e.getErrorMessage(), containsString("Unauthorized")); + } + configure.shutdown(); + + } + + @Test + public void test_auth_multibyte_username() throws ArangoException { + + ArangoConfigure configure = new ArangoConfigure(); + configure.setUser("root"); + configure.setPassword(""); + configure.init(); + + ArangoDriver driver = new ArangoDriver(configure); + + // Create User + try { + driver.createUser("ゆーざーA", "pass", false, null); + } catch (ArangoException e) { + driver.replaceUser("ゆーざーA", "pass", false, null); + } + + configure.shutdown(); + + ArangoConfigure configure2 = new ArangoConfigure(); + configure2.setUser("ゆーざーA"); + configure2.setPassword("pass"); + configure2.init(); + ArangoDriver driver2 = new ArangoDriver(configure2); + + try { + driver2.getTime(); + fail(""); + } catch (ArangoException e) { + assertThat(e.getCode(), is(401)); + assertThat(e.getErrorNumber(), is(0)); + assertThat(e.getErrorMessage(), containsString("Unauthorized")); + } + + configure2.shutdown(); + } + + @Test + public void test_auth_multibyte_password() throws ArangoException { + + ArangoConfigure configure = new ArangoConfigure(); + configure.setUser("root"); + configure.setPassword(""); + configure.init(); + + ArangoDriver driver = new ArangoDriver(configure); + + // Create User + try { + driver.createUser("user-A", "パスワード", false, null); + } catch (ArangoException e) { + driver.replaceUser("user-A", "パスワード", false, null); + } + + configure.shutdown(); + + configure = new ArangoConfigure(); + configure.setUser("user-A"); + configure.setPassword("パスワード"); + configure.init(); + driver = new ArangoDriver(configure); + + try { + driver.getTime(); + fail(""); + } catch (ArangoException e) { + assertThat(e.getErrorNumber(), is(0)); + assertThat(e.getCode(), is(401)); + assertThat(e.getErrorMessage(), containsString("Unauthorized")); + } + configure.shutdown(); + + } } diff --git a/src/test/java/com/arangodb/ArangoDriverCursorTest.java b/src/test/java/com/arangodb/ArangoDriverCursorTest.java index 96eb71e66..529d1cad6 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorTest.java @@ -142,7 +142,6 @@ public void test_executeQuery_2() throws ArangoException { aqlQueryOptions.setCount(true); final DocumentCursor result = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, TestComplexEntity01.class); - assertThat(result.asEntityList().size(), is(3)); assertThat(result.getCount(), is(10)); assertThat(result.hasMore(), is(true)); assertThat(result.getCursorId(), is(not(-1L))); @@ -212,7 +211,6 @@ public void test_executeQueryFullCount() throws ArangoException { aqlQueryOptions.setFullCount(true); final DocumentCursor result = driver. executeDocumentQuery(query, bindVars, aqlQueryOptions, TestComplexEntity01.class); - assertThat(result.asEntityList().size(), is(1)); assertThat(result.getCount(), is(2)); assertThat(result.getFullCount(), is(90)); assertThat(result.hasMore(), is(true)); From 6391c6d5bdfe5df6918f116da58db3f5a677376a Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 8 Jun 2016 13:22:47 +0200 Subject: [PATCH 25/56] fix JavaDoc --- src/main/java/com/arangodb/ArangoDriver.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 3a4b1e747..cc5ecbaa3 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -2846,7 +2846,7 @@ public SimpleByResultEntity executeSimpleUpdateByExample( * @param username * the username as string * @param passwd - * the username as string + * the password as string * @param active * if true the user is active * @param extra @@ -2868,7 +2868,7 @@ public DefaultEntity createUser( * @param username * the username as string * @param passwd - * the username as string + * the password as string * @param active * if true the user is active * @param extra @@ -2890,7 +2890,7 @@ public DefaultEntity replaceUser( * @param username * the username as string * @param passwd - * the username as string + * the password as string * @param active * if true the user is active * @param extra From cfa040dffbc7601a0e39763d29f6f269372ec765 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 8 Jun 2016 14:01:30 +0200 Subject: [PATCH 26/56] User Tests fixed, ArangoDriver.getUsers() now works always on _system --- src/main/java/com/arangodb/ArangoDriver.java | 8 ++++++-- .../com/arangodb/ArangoDriverCursorTest.java | 1 + .../ArangoDriverDatabaseAndUserTest.java | 20 ++++++------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index cc5ecbaa3..0b36b346e 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -101,6 +101,8 @@ */ public class ArangoDriver extends BaseArangoDriver { + private static final String DATABASE_SYSTEM = "_system"; + private static final String COLLECTION_USERS = "_users"; private static final String GRAPH_NAME = "graphName"; private static final String VERTEX_EXAMPLE = "vertexExample"; private final ArangoConfigure configure; @@ -2950,7 +2952,8 @@ public DefaultEntity grantDatabaseAccess(String username, String database) throw * @throws ArangoException */ public List> getUsersDocument() throws ArangoException { - final DocumentCursor documentCursor = executeSimpleAllDocuments("_users", 0, 0, UserEntity.class); + final DocumentCursor documentCursor = simpleDriver.executeSimpleAllDocuments(DATABASE_SYSTEM, + COLLECTION_USERS, 0, 0, UserEntity.class); return documentCursor.asList(); } @@ -2961,7 +2964,8 @@ public List> getUsersDocument() throws ArangoExceptio * @throws ArangoException */ public List getUsers() throws ArangoException { - final DocumentCursor documentCursor = executeSimpleAllDocuments("_users", 0, 0, UserEntity.class); + final DocumentCursor documentCursor = simpleDriver.executeSimpleAllDocuments(DATABASE_SYSTEM, + COLLECTION_USERS, 0, 0, UserEntity.class); return documentCursor.asEntityList(); } diff --git a/src/test/java/com/arangodb/ArangoDriverCursorTest.java b/src/test/java/com/arangodb/ArangoDriverCursorTest.java index 529d1cad6..9d34b2ead 100644 --- a/src/test/java/com/arangodb/ArangoDriverCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverCursorTest.java @@ -283,6 +283,7 @@ public void test_warning() throws ArangoException { } driver.truncateCollection(collectionName); + driver.setDefaultDatabase(null); final String query = "return _users + 1"; final Map bindVars = new HashMap(); final CursorResult cursor = driver.executeAqlQuery(query, bindVars, null, Long.class); diff --git a/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java b/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java index 0d5d960c0..e4abfe892 100644 --- a/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java @@ -77,29 +77,19 @@ public void test_create_database_with_users_and_database_user() throws ArangoExc new UserEntity("user3", "pass3", true, new MapBuilder().put("attr1", "value1").get()), new UserEntity("user4", "pass4", false, new MapBuilder().put("attr2", "value2").get())); assertThat(entity.getResult(), is(true)); + driver.grantDatabaseAccess("user1", "_system"); + driver.grantDatabaseAccess("user4", DATABASE); // change default db - try { - driver.createUser("user1", "pass1", true, null); - } catch (final ArangoException e) { - } driver.setDefaultDatabase(DATABASE); - // root user cannot access - try { - driver.getUsers(); - fail(); - } catch (final ArangoException e) { - assertThat(e.isUnauthorized(), is(true)); - } - // user1 can access configure.setUser("user1"); configure.setPassword("pass1"); final StringsResultEntity res2 = driver.getDatabases(true); assertThat(res2.getResult(), is(Arrays.asList("_system", DATABASE))); - // user2 cannot access + // user2 cannot access (inactive) configure.setUser("user2"); configure.setPassword("pass2"); try { @@ -109,9 +99,11 @@ public void test_create_database_with_users_and_database_user() throws ArangoExc assertThat(e.isUnauthorized(), is(true)); } + configure.setUser("root"); + configure.setPassword(""); + final StringsResultEntity res3 = driver.getDatabases("user1", "pass1"); assertThat(res3.getResult(), is(Arrays.asList("_system", DATABASE))); - } } From 4707b56d598f93977235e2f56c9ccd5b3d1331f8 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 8 Jun 2016 14:32:59 +0200 Subject: [PATCH 27/56] User Tests optimized --- .../com/arangodb/ArangoDriverAuthTest.java | 39 +++++++++++----- .../ArangoDriverDatabaseAndUserTest.java | 44 +++++++++++++------ .../com/arangodb/ArangoDriverUsersTest.java | 6 ++- 3 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/test/java/com/arangodb/ArangoDriverAuthTest.java b/src/test/java/com/arangodb/ArangoDriverAuthTest.java index 955d1df37..d31777410 100644 --- a/src/test/java/com/arangodb/ArangoDriverAuthTest.java +++ b/src/test/java/com/arangodb/ArangoDriverAuthTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; +import org.junit.After; import org.junit.Test; /** @@ -31,6 +32,24 @@ */ public class ArangoDriverAuthTest { + private static final String USER_MIN_A = "user-A"; + private static final String USER_A = "userA"; + private static final String USER_B = "userB"; + private static final String USER_JAP_A = "ゆーざーA"; + + @After + public void after() { + ArangoConfigure configure = new ArangoConfigure(); + configure.init(); + ArangoDriver driver = new ArangoDriver(configure); + for (String username : new String[] { USER_A, USER_B, USER_MIN_A, USER_JAP_A }) { + try { + driver.deleteUser(username); + } catch (ArangoException e) { + } + } + } + @Test public void test_auth() throws ArangoException { @@ -77,7 +96,7 @@ public void test_auth_added_user() throws ArangoException { ArangoDriver driver = new ArangoDriver(configure); // Create User - final String username = "userA"; + final String username = USER_A; try { driver.createUser(username, "passA", true, null); } catch (ArangoException e) { @@ -108,15 +127,15 @@ public void test_auth_added_user_inactive() throws ArangoException { // Create User try { - driver.createUser("userB", "passB", false, null); + driver.createUser(USER_B, "passB", false, null); } catch (ArangoException e) { - driver.replaceUser("userB", "passB", false, null); + driver.replaceUser(USER_B, "passB", false, null); } configure.shutdown(); configure = new ArangoConfigure(); - configure.setUser("userB"); + configure.setUser(USER_B); configure.setPassword("passB"); configure.init(); driver = new ArangoDriver(configure); @@ -146,15 +165,15 @@ public void test_auth_multibyte_username() throws ArangoException { // Create User try { - driver.createUser("ゆーざーA", "pass", false, null); + driver.createUser(USER_JAP_A, "pass", false, null); } catch (ArangoException e) { - driver.replaceUser("ゆーざーA", "pass", false, null); + driver.replaceUser(USER_JAP_A, "pass", false, null); } configure.shutdown(); ArangoConfigure configure2 = new ArangoConfigure(); - configure2.setUser("ゆーざーA"); + configure2.setUser(USER_JAP_A); configure2.setPassword("pass"); configure2.init(); ArangoDriver driver2 = new ArangoDriver(configure2); @@ -183,15 +202,15 @@ public void test_auth_multibyte_password() throws ArangoException { // Create User try { - driver.createUser("user-A", "パスワード", false, null); + driver.createUser(USER_MIN_A, "パスワード", false, null); } catch (ArangoException e) { - driver.replaceUser("user-A", "パスワード", false, null); + driver.replaceUser(USER_MIN_A, "パスワード", false, null); } configure.shutdown(); configure = new ArangoConfigure(); - configure.setUser("user-A"); + configure.setUser(USER_MIN_A); configure.setPassword("パスワード"); configure.init(); driver = new ArangoDriver(configure); diff --git a/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java b/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java index e4abfe892..f44def846 100644 --- a/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java @@ -37,6 +37,18 @@ */ public class ArangoDriverDatabaseAndUserTest { + private static final String _SYSTEM = "_system"; + + private static final String USER1 = "user1"; + private static final String USER2 = "user2"; + private static final String USER3 = "user3"; + private static final String USER4 = "user4"; + + private static final String PASS1 = "pass1"; + private static final String PASS2 = "pass2"; + private static final String PASS3 = "pass3"; + private static final String PASS4 = "pass4"; + private ArangoConfigure configure; private ArangoDriver driver; private static final String DATABASE = "db-1"; @@ -56,6 +68,12 @@ public void after() { driver.deleteDatabase(DATABASE); } catch (final ArangoException e) { } + for (String username : new String[] { USER1, USER2, USER3, USER4 }) { + try { + driver.deleteUser(username); + } catch (ArangoException e) { + } + } configure.shutdown(); } @@ -72,26 +90,26 @@ public void test_create_database_with_users_and_database_user() throws ArangoExc } catch (final ArangoException e) { } - final BooleanResultEntity entity = driver.createDatabase(DATABASE, new UserEntity("user1", "pass1", true, null), - new UserEntity("user2", "pass2", false, null), - new UserEntity("user3", "pass3", true, new MapBuilder().put("attr1", "value1").get()), - new UserEntity("user4", "pass4", false, new MapBuilder().put("attr2", "value2").get())); + final BooleanResultEntity entity = driver.createDatabase(DATABASE, new UserEntity(USER1, PASS1, true, null), + new UserEntity(USER2, PASS2, false, null), + new UserEntity(USER3, PASS3, true, new MapBuilder().put("attr1", "value1").get()), + new UserEntity(USER4, PASS4, false, new MapBuilder().put("attr2", "value2").get())); assertThat(entity.getResult(), is(true)); - driver.grantDatabaseAccess("user1", "_system"); - driver.grantDatabaseAccess("user4", DATABASE); + driver.grantDatabaseAccess(USER1, _SYSTEM); + driver.grantDatabaseAccess(USER4, DATABASE); // change default db driver.setDefaultDatabase(DATABASE); // user1 can access - configure.setUser("user1"); - configure.setPassword("pass1"); + configure.setUser(USER1); + configure.setPassword(PASS1); final StringsResultEntity res2 = driver.getDatabases(true); - assertThat(res2.getResult(), is(Arrays.asList("_system", DATABASE))); + assertThat(res2.getResult(), is(Arrays.asList(_SYSTEM, DATABASE))); // user2 cannot access (inactive) - configure.setUser("user2"); - configure.setPassword("pass2"); + configure.setUser(USER2); + configure.setPassword(PASS2); try { driver.getUsers(); fail(); @@ -102,8 +120,8 @@ public void test_create_database_with_users_and_database_user() throws ArangoExc configure.setUser("root"); configure.setPassword(""); - final StringsResultEntity res3 = driver.getDatabases("user1", "pass1"); - assertThat(res3.getResult(), is(Arrays.asList("_system", DATABASE))); + final StringsResultEntity res3 = driver.getDatabases(USER1, PASS1); + assertThat(res3.getResult(), is(Arrays.asList(_SYSTEM, DATABASE))); } } diff --git a/src/test/java/com/arangodb/ArangoDriverUsersTest.java b/src/test/java/com/arangodb/ArangoDriverUsersTest.java index 3ead9b37d..3590f225c 100644 --- a/src/test/java/com/arangodb/ArangoDriverUsersTest.java +++ b/src/test/java/com/arangodb/ArangoDriverUsersTest.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.TreeMap; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -45,6 +46,7 @@ public class ArangoDriverUsersTest extends BaseTest { @Before + @After public void setup() throws ArangoException { // delete user for (final String user : new String[] { "user1", "user2", "user3", "user4", "testuser", "テスト☆ユーザー", "user-A", @@ -312,6 +314,8 @@ public void test_update_user_404() throws ArangoException { @Test public void test_get_users() throws ArangoException { + int expectedUserSize = driver.getUsers().size() + 3; + driver.createUser("user1", "pass1", true, null); driver.createUser("user2", "pass2", false, null); driver.createUser("user3", "pass3", true, new MapBuilder().put("key", "value").get()); @@ -326,7 +330,7 @@ public int compare(final UserEntity o1, final UserEntity o2) { }); // validate - assertThat(users.size(), is(4)); // user1,2,3 and root + assertThat(users.size(), is(expectedUserSize)); // user1,2,3 and root assertThat(users.get(0).getUsername(), is("root")); assertThat(users.get(1).getUsername(), is("user1")); From 2633a002a65d7d346a4d28b1f4b1f48b42f0664c Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 9 Jun 2016 08:47:19 +0200 Subject: [PATCH 28/56] Replace graph_edge function with aql --- src/main/java/com/arangodb/ArangoDriver.java | 32 +++- .../com/arangodb/InternalGraphDriver.java | 3 +- .../impl/InternalGraphDriverImpl.java | 11 +- .../com/arangodb/util/GraphEdgesOptions.java | 26 +-- .../com/arangodb/util/GraphQueryUtil.java | 150 ++++++++++++++++++ .../ArangoDriverGraphEdgesGetCursorTest.java | 64 ++++---- 6 files changed, 220 insertions(+), 66 deletions(-) create mode 100644 src/main/java/com/arangodb/util/GraphQueryUtil.java diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 0b36b346e..00c38905c 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -79,6 +79,7 @@ import com.arangodb.util.AqlQueryOptions; import com.arangodb.util.DumpHandler; import com.arangodb.util.GraphEdgesOptions; +import com.arangodb.util.GraphQueryUtil; import com.arangodb.util.GraphVerticesOptions; import com.arangodb.util.JsonUtils; import com.arangodb.util.MapBuilder; @@ -3516,7 +3517,22 @@ public void deleteGraph(final String graphName, final Boolean dropCollections) t * @throws ArangoException */ public List graphGetVertexCollections(final String graphName) throws ArangoException { - return graphDriver.getVertexCollections(getDefaultDatabase(), graphName); + return graphGetVertexCollections(graphName, false); + } + + /** + * Returns a list of all vertex collection of a graph that are defined in + * the graphs edgeDefinitions (in "from", "to", and "orphanCollections") + * + * @param graphName + * The graph name. + * @param excludeOrphan + * @return List List of the names of the vertex collections + * @throws ArangoException + */ + public List graphGetVertexCollections(final String graphName, final boolean excludeOrphan) + throws ArangoException { + return graphDriver.getVertexCollections(getDefaultDatabase(), graphName, excludeOrphan); } /** @@ -4368,6 +4384,7 @@ public VertexCursor executeVertexQuery( * @return EdgeCursor * @throws ArangoException */ + @SuppressWarnings("unchecked") public EdgeCursor graphGetEdgeCursor( final String graphName, final Class clazz, @@ -4382,17 +4399,20 @@ public EdgeCursor graphGetEdgeCursor( validateCollectionName(graphName); - final String query = "for i in graph_edges(@graphName, @vertexExample, @options) return i"; - final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) - .put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)) - .put("options", JsonUtils.convertNullToMap(tmpGraphEdgesOptions)).get(); + final MapBuilder mapBuilder = new MapBuilder(); + final String query = GraphQueryUtil.createEdgeQuery(this, graphName, clazz, vertexExample, tmpGraphEdgesOptions, + mapBuilder); + final Map bindVars = mapBuilder.get(); AqlQueryOptions tmpAqlQueryOptions = aqlQueryOptions; if (tmpAqlQueryOptions == null) { tmpAqlQueryOptions = getDefaultAqlQueryOptions().setCount(true); } - return executeEdgeQuery(query, bindVars, tmpAqlQueryOptions, clazz); + DocumentCursorResult> cursor = executeAqlQueryWithDocumentCursorResult(query, bindVars, + tmpAqlQueryOptions, EdgeEntity.class, clazz); + + return new EdgeCursor(cursor); } /** diff --git a/src/main/java/com/arangodb/InternalGraphDriver.java b/src/main/java/com/arangodb/InternalGraphDriver.java index 8fbc7e9bb..0bd3cdf68 100644 --- a/src/main/java/com/arangodb/InternalGraphDriver.java +++ b/src/main/java/com/arangodb/InternalGraphDriver.java @@ -112,7 +112,8 @@ GraphEntity createGraph( * @return List * @throws ArangoException */ - List getVertexCollections(String databaseName, String graphName) throws ArangoException; + List getVertexCollections(String databaseName, String graphName, boolean excludeOrphan) + throws ArangoException; /** * diff --git a/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java b/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java index 00d264be2..d2449ef1d 100644 --- a/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java @@ -53,6 +53,7 @@ public class InternalGraphDriverImpl extends BaseArangoDriverWithCursorImpl private static final String UNKNOWN_ERROR = "unknown error"; private static final String VERTEX = "/vertex"; private static final String EDGE = "/edge"; + private static final String EXCLUDE_ORPHAN = "excludeOrphan"; InternalGraphDriverImpl(final ArangoConfigure configure, final InternalCursorDriver cursorDriver, final HttpManager httpManager) { @@ -146,10 +147,14 @@ public DeletedEntity deleteGraph(final String databaseName, final String graphNa } @Override - public List getVertexCollections(final String databaseName, final String graphName) throws ArangoException { + public List getVertexCollections( + final String databaseName, + final String graphName, + final boolean excludeOrphan) throws ArangoException { validateCollectionName(graphName); - final HttpResponseEntity res = httpManager - .doGet(createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX)); + final HttpResponseEntity res = httpManager.doGet( + createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX), + new MapBuilder().put(EXCLUDE_ORPHAN, excludeOrphan).get()); if (wrongResult(res)) { throw new ArangoException(UNKNOWN_ERROR); diff --git a/src/main/java/com/arangodb/util/GraphEdgesOptions.java b/src/main/java/com/arangodb/util/GraphEdgesOptions.java index 63e9f0604..353d26f5d 100644 --- a/src/main/java/com/arangodb/util/GraphEdgesOptions.java +++ b/src/main/java/com/arangodb/util/GraphEdgesOptions.java @@ -15,8 +15,8 @@ public class GraphEdgesOptions extends AbstractOptions implements OptionsInterfa private Object neighborExamples; private Integer minDepth; private Integer maxDepth; - private Integer maxIterations; - private Boolean includeData = Boolean.TRUE; + private Integer limit; + private Boolean includeData = Boolean.TRUE;// false = i._id, true = i /** * The direction of the edges as a string. Possible values are outbound, @@ -194,25 +194,12 @@ public GraphEdgesOptions setMaxDepth(Integer maxDepth) { return this; } - /** - * the maximum number of iterations that the traversal is allowed to - * perform. It is sensible to set this number so unbounded traversals - * - * @return the maximum number of iterations - */ - public Integer getMaxIterations() { - return maxIterations; + public Integer getLimit() { + return limit; } - /** - * the maximum number of iterations that the traversal is allowed to - * perform. It is sensible to set this number so unbounded traversals - * - * @return this - * @param maxIterations - */ - public GraphEdgesOptions setMaxIterations(Integer maxIterations) { - this.maxIterations = maxIterations; + public GraphEdgesOptions setLimit(Integer limit) { + this.limit = limit; return this; } @@ -248,7 +235,6 @@ public Map toMap() { putAttribute(mp, "neighborExamples", neighborExamples); putAttribute(mp, "minDepth", minDepth); putAttribute(mp, "maxDepth", maxDepth); - putAttribute(mp, "maxIterations", maxIterations); putAttribute(mp, "includeData", includeData); return mp.get(); diff --git a/src/main/java/com/arangodb/util/GraphQueryUtil.java b/src/main/java/com/arangodb/util/GraphQueryUtil.java new file mode 100644 index 000000000..b0f2498e6 --- /dev/null +++ b/src/main/java/com/arangodb/util/GraphQueryUtil.java @@ -0,0 +1,150 @@ +package com.arangodb.util; + +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +import com.arangodb.ArangoDriver; +import com.arangodb.ArangoException; +import com.arangodb.Direction; +import com.google.gson.Gson; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +/** + * @author Mark - mark@arangodb.com + * + */ +public class GraphQueryUtil { + + private static final String AND = " && "; + private static final String GRAPH_NAME = "graphName"; + private static final String VERTEX_EXAMPLE = "vertexExample"; + + public static String createEdgeQuery( + final ArangoDriver driver, + final String graphName, + final Class clazz, + final Object vertexExample, + final GraphEdgesOptions graphEdgesOptions, + final MapBuilder bindVars) throws ArangoException { + + final StringBuilder sb = new StringBuilder(); + if (vertexExample != null && String.class.isAssignableFrom(vertexExample.getClass())) { + sb.append("FOR v,i IN "); + appendDepth(graphEdgesOptions, sb); + appendDirection(graphEdgesOptions, sb); + sb.append(" @"); + sb.append(VERTEX_EXAMPLE); + bindVars.put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)); + } else { + final List vertexCollections = driver.graphGetVertexCollections(graphName, true); + if (vertexCollections.size() == 1) { + sb.append("FOR start IN `"); + sb.append(vertexCollections.get(0)); + sb.append("`"); + appendFilter(vertexExample, sb); + } else { + sb.append("FOR start IN UNION ("); + for (String vertexCollection : vertexCollections) { + sb.append("(FOR start IN `"); + sb.append(vertexCollection); + sb.append("`"); + appendFilter(vertexExample, sb); + sb.append(" RETURN start),"); + } + // remove last , + sb.deleteCharAt(sb.length() - 1); + sb.append(")"); + } + sb.append(" FOR v,i IN "); + appendDepth(graphEdgesOptions, sb); + appendDirection(graphEdgesOptions, sb); + sb.append(" start"); + } + sb.append(" "); + final List edgeCollectionRestriction = graphEdgesOptions.getEdgeCollectionRestriction(); + if (edgeCollectionRestriction != null && edgeCollectionRestriction.size() > 0) { + for (String edgeCollection : edgeCollectionRestriction) { + sb.append(edgeCollection); + sb.append(","); + } + // remove last , + sb.deleteCharAt(sb.length() - 1); + } else { + sb.append("GRAPH @"); + sb.append(GRAPH_NAME); + bindVars.put(GRAPH_NAME, graphName); + } + final Integer limit = graphEdgesOptions.getLimit(); + if (limit != null) { + sb.append(" LIMIT "); + sb.append(limit.intValue()); + } + sb.append(" RETURN distinct i"); + if (graphEdgesOptions.getIncludeData() != null && !graphEdgesOptions.getIncludeData().booleanValue()) { + sb.append(".id"); + } + + final String query = sb.toString(); + return query; + } + + private static void appendDepth(final GraphEdgesOptions graphEdgesOptions, final StringBuilder sb) { + final Integer minDepth = graphEdgesOptions.getMinDepth(); + final Integer maxDepth = graphEdgesOptions.getMaxDepth(); + if (minDepth != null || maxDepth != null) { + sb.append(minDepth != null ? minDepth : 1); + sb.append(".."); + sb.append(maxDepth != null ? maxDepth : 1); + sb.append(" "); + } + } + + private static void appendDirection(final GraphEdgesOptions graphEdgesOptions, final StringBuilder sb) { + final String direction = graphEdgesOptions.getDirection() != null ? graphEdgesOptions.getDirection().name() + : Direction.ANY.name(); + sb.append(direction); + } + + private static void appendFilter(final Object vertexExample, final StringBuilder sb) { + Gson gson = new Gson(); + final JsonElement json = gson.toJsonTree(vertexExample); + if (json.isJsonObject()) { + sb.append(" FILTER "); + final JsonObject jsonObject = json.getAsJsonObject(); + final Set> entrySet = jsonObject.entrySet(); + for (Entry entry : entrySet) { + sb.append("start.`"); + sb.append(entry.getKey()); + sb.append("` == "); + sb.append(entry.getValue().toString()); + sb.append(AND); + } + sb.delete(sb.length() - AND.length(), sb.length() - 1); + } + } + + public static String createVerticesQuery( + final ArangoDriver driver, + final String graphName, + final Class clazz, + final Object vertexExample, + final GraphVerticesOptions graphVerticesOptions, + final MapBuilder bindVars) throws ArangoException { + return null; + } + + public static String createShortestPathQuery( + final ArangoDriver driver, + final String database, + final String graphName, + final Object startVertexExample, + final Object endVertexExample, + final ShortestPathOptions shortestPathOptions, + final Class vertexClass, + final Class edgeClass, + final MapBuilder bindVars) { + return null; + } +} diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java index 569988a0a..eac52dbc3 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java @@ -37,7 +37,7 @@ import com.arangodb.entity.ShortestPathEntity; import com.arangodb.entity.marker.VertexEntity; import com.arangodb.util.AqlQueryOptions; -import com.arangodb.util.MapBuilder; +import com.arangodb.util.GraphEdgesOptions; import com.arangodb.util.ShortestPathOptions; /** @@ -228,16 +228,16 @@ public void batchSizeAndLimitTest() throws ArangoException { final Boolean count = true; final Boolean fullCount = true; - final String query = "for i in graph_edges(@graphName, null, {includeData: true}) LIMIT 3 return i"; - final Map bindVars = new MapBuilder().put("graphName", GRAPH_NAME).get(); + GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions(); + graphEdgesOptions.setLimit(3); - final EdgeCursor cursor = driver.executeEdgeQuery(query, bindVars, - getAqlQueryOptions(count, batchSize, fullCount), TestComplexEntity02.class); + final EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, + null, graphEdgesOptions, getAqlQueryOptions(count, batchSize, fullCount)); assertEquals(3, cursor.getCount()); assertEquals(201, cursor.getCode()); assertTrue(cursor.hasMore()); - assertEquals(4, cursor.getFullCount()); + assertEquals(8, cursor.getFullCount()); assertTrue(cursor.getCursorId() > -1L); } @@ -270,36 +270,28 @@ public void edgesAqlTest() throws ArangoException { final Boolean count = true; final Boolean fullCount = true; - // get outbound vertices of vertex1 (the should be 2) - final String query = "for i in graph_edges(@graphName, @vertex, @options) return i"; - - // options bindVars - final Map options = new MapBuilder().put("direction", "outbound").put("includeData", true) - .get(); - - // bindVars - Map bindVars = new MapBuilder().put("graphName", GRAPH_NAME) - .put("vertex", vertex1.getDocumentHandle()).put("options", options).get(); - - EdgeCursor cursor = driver.executeEdgeQuery(query, bindVars, - getAqlQueryOptions(count, batchSize, fullCount), TestComplexEntity02.class); - - assertEquals(2, cursor.getCount()); - assertEquals(201, cursor.getCode()); - assertFalse(cursor.hasMore()); - assertEquals(new Long(-1L), cursor.getCursorId()); - - // get outbound vertices of vertex2 (the should be no) - bindVars = new MapBuilder().put("graphName", GRAPH_NAME).put("vertex", vertex2.getDocumentHandle()) - .put("options", options).get(); - - cursor = driver.executeEdgeQuery(query, bindVars, getAqlQueryOptions(count, batchSize, fullCount), - TestComplexEntity02.class); - - assertEquals(0, cursor.getCount()); - assertEquals(201, cursor.getCode()); - assertFalse(cursor.hasMore()); - assertEquals(new Long(-1L), cursor.getCursorId()); + GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions(); + graphEdgesOptions.setDirection(Direction.OUTBOUND); + graphEdgesOptions.setIncludeData(true); + { + EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, + vertex1.getDocumentHandle(), graphEdgesOptions, getAqlQueryOptions(count, batchSize, fullCount)); + + assertEquals(2, cursor.getCount()); + assertEquals(201, cursor.getCode()); + assertFalse(cursor.hasMore()); + assertEquals(new Long(-1L), cursor.getCursorId()); + } + { + // get outbound vertices of vertex2 (the should be no) + EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, + vertex2.getDocumentHandle(), graphEdgesOptions, getAqlQueryOptions(count, batchSize, fullCount)); + + assertEquals(0, cursor.getCount()); + assertEquals(201, cursor.getCode()); + assertFalse(cursor.hasMore()); + assertEquals(new Long(-1L), cursor.getCursorId()); + } } From 55a8e54fa4f23be2e4ec02addc54a83963c4b6bc Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 9 Jun 2016 10:44:41 +0200 Subject: [PATCH 29/56] Replace graph_edge function with aql --- .../com/arangodb/util/GraphEdgesOptions.java | 22 +--- .../com/arangodb/util/GraphQueryUtil.java | 75 +++++++++--- .../ArangoDriverGraphEdgesGetCursorTest.java | 115 ++++++++++++++++++ 3 files changed, 172 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/arangodb/util/GraphEdgesOptions.java b/src/main/java/com/arangodb/util/GraphEdgesOptions.java index 353d26f5d..be63eb53c 100644 --- a/src/main/java/com/arangodb/util/GraphEdgesOptions.java +++ b/src/main/java/com/arangodb/util/GraphEdgesOptions.java @@ -1,11 +1,10 @@ package com.arangodb.util; import java.util.List; -import java.util.Map; import com.arangodb.Direction; -public class GraphEdgesOptions extends AbstractOptions implements OptionsInterface { +public class GraphEdgesOptions { private Direction direction; private List edgeCollectionRestriction; @@ -16,7 +15,7 @@ public class GraphEdgesOptions extends AbstractOptions implements OptionsInterfa private Integer minDepth; private Integer maxDepth; private Integer limit; - private Boolean includeData = Boolean.TRUE;// false = i._id, true = i + private Boolean includeData = Boolean.TRUE; /** * The direction of the edges as a string. Possible values are outbound, @@ -223,21 +222,4 @@ public void setIncludeData(Boolean includeData) { this.includeData = includeData; } - @Override - public Map toMap() { - MapBuilder mp = new MapBuilder(); - - putAttributeToLower(mp, "direction", direction); - putAttributeCollection(mp, "edgeCollectionRestriction", edgeCollectionRestriction); - putAttributeCollection(mp, "startVertexCollectionRestriction", startVertexCollectionRestriction); - putAttributeCollection(mp, "endVertexCollectionRestriction", endVertexCollectionRestriction); - putAttribute(mp, "edgeExamples", edgeExamples); - putAttribute(mp, "neighborExamples", neighborExamples); - putAttribute(mp, "minDepth", minDepth); - putAttribute(mp, "maxDepth", maxDepth); - putAttribute(mp, "includeData", includeData); - - return mp.get(); - } - } diff --git a/src/main/java/com/arangodb/util/GraphQueryUtil.java b/src/main/java/com/arangodb/util/GraphQueryUtil.java index b0f2498e6..0013b2974 100644 --- a/src/main/java/com/arangodb/util/GraphQueryUtil.java +++ b/src/main/java/com/arangodb/util/GraphQueryUtil.java @@ -8,6 +8,7 @@ import com.arangodb.ArangoException; import com.arangodb.Direction; import com.google.gson.Gson; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -18,6 +19,7 @@ public class GraphQueryUtil { private static final String AND = " && "; + private static final String OR = " || "; private static final String GRAPH_NAME = "graphName"; private static final String VERTEX_EXAMPLE = "vertexExample"; @@ -31,33 +33,37 @@ public static String createEdgeQuery( final StringBuilder sb = new StringBuilder(); if (vertexExample != null && String.class.isAssignableFrom(vertexExample.getClass())) { - sb.append("FOR v,i IN "); + sb.append("FOR v,e IN "); appendDepth(graphEdgesOptions, sb); appendDirection(graphEdgesOptions, sb); sb.append(" @"); sb.append(VERTEX_EXAMPLE); bindVars.put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)); } else { - final List vertexCollections = driver.graphGetVertexCollections(graphName, true); + final List startVertexCollectionRestriction = graphEdgesOptions + .getStartVertexCollectionRestriction(); + final List vertexCollections = startVertexCollectionRestriction != null + && startVertexCollectionRestriction.size() > 0 ? startVertexCollectionRestriction + : driver.graphGetVertexCollections(graphName, true); if (vertexCollections.size() == 1) { sb.append("FOR start IN `"); sb.append(vertexCollections.get(0)); sb.append("`"); - appendFilter(vertexExample, sb); + appendFilter("start", vertexExample, sb); } else { sb.append("FOR start IN UNION ("); for (String vertexCollection : vertexCollections) { sb.append("(FOR start IN `"); sb.append(vertexCollection); sb.append("`"); - appendFilter(vertexExample, sb); + appendFilter("start", vertexExample, sb); sb.append(" RETURN start),"); } // remove last , sb.deleteCharAt(sb.length() - 1); sb.append(")"); } - sb.append(" FOR v,i IN "); + sb.append(" FOR v,e IN "); appendDepth(graphEdgesOptions, sb); appendDirection(graphEdgesOptions, sb); sb.append(" start"); @@ -76,12 +82,14 @@ public static String createEdgeQuery( sb.append(GRAPH_NAME); bindVars.put(GRAPH_NAME, graphName); } + appendFilter("e", graphEdgesOptions.getEdgeExamples(), sb); + appendFilter("v", graphEdgesOptions.getNeighborExamples(), sb); final Integer limit = graphEdgesOptions.getLimit(); if (limit != null) { sb.append(" LIMIT "); sb.append(limit.intValue()); } - sb.append(" RETURN distinct i"); + sb.append(" RETURN distinct e"); if (graphEdgesOptions.getIncludeData() != null && !graphEdgesOptions.getIncludeData().booleanValue()) { sb.append(".id"); } @@ -107,24 +115,51 @@ private static void appendDirection(final GraphEdgesOptions graphEdgesOptions, f sb.append(direction); } - private static void appendFilter(final Object vertexExample, final StringBuilder sb) { - Gson gson = new Gson(); - final JsonElement json = gson.toJsonTree(vertexExample); - if (json.isJsonObject()) { - sb.append(" FILTER "); - final JsonObject jsonObject = json.getAsJsonObject(); - final Set> entrySet = jsonObject.entrySet(); - for (Entry entry : entrySet) { - sb.append("start.`"); - sb.append(entry.getKey()); - sb.append("` == "); - sb.append(entry.getValue().toString()); - sb.append(AND); + private static void appendFilter(final String var, final Object example, final StringBuilder sb) + throws ArangoException { + if (example != null) { + final Gson gson = new Gson(); + final JsonElement json = gson.toJsonTree(example); + if (json.isJsonObject()) { + sb.append(" FILTER "); + appendObjectinFilter(var, json.getAsJsonObject(), sb); + } else if (json.isJsonArray()) { + sb.append(" FILTER "); + final JsonArray jsonArray = json.getAsJsonArray(); + if (jsonArray.size() > 0) { + for (JsonElement jsonElement : jsonArray) { + if (jsonElement.isJsonObject()) { + sb.append("("); + appendObjectinFilter(var, jsonElement.getAsJsonObject(), sb); + sb.append(")"); + sb.append(OR); + } else if (!jsonElement.isJsonNull()) { + throw new ArangoException("invalide format of entry in array example: " + + example.getClass().getSimpleName() + ". only objects in array allowed."); + } + } + sb.delete(sb.length() - OR.length(), sb.length() - 1); + } + } else { + throw new ArangoException("invalide format of example: " + example.getClass().getSimpleName() + + ". only object or array allowed."); } - sb.delete(sb.length() - AND.length(), sb.length() - 1); } } + private static void appendObjectinFilter(final String var, final JsonObject jsonObject, final StringBuilder sb) { + final Set> entrySet = jsonObject.entrySet(); + for (Entry entry : entrySet) { + sb.append(var); + sb.append(".`"); + sb.append(entry.getKey()); + sb.append("` == "); + sb.append(entry.getValue().toString()); + sb.append(AND); + } + sb.delete(sb.length() - AND.length(), sb.length() - 1); + } + public static String createVerticesQuery( final ArangoDriver driver, final String graphName, diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java index eac52dbc3..8a2837b28 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -295,6 +296,120 @@ public void edgesAqlTest() throws ArangoException { } + @Test + public void graphGetEdgeCursorWithEdgeExample() throws ArangoException { + + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + + final TestComplexEntity02 e1 = new TestComplexEntity02(1, 2, 3); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), e1, + null); + + final TestComplexEntity02 e2 = new TestComplexEntity02(4, 5, 6); + EdgeEntity edge2 = driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, + vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), e2, null); + + final TestComplexEntity02 e3 = new TestComplexEntity02(7, 8, 9); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), e3, + null); + + final TestComplexEntity02 e4 = new TestComplexEntity02(10, 11, 12); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex3.getDocumentHandle(), e4, + null); + + GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions(); + graphEdgesOptions.setEdgeExamples(e2); + + EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, + vertex1.getDocumentHandle(), graphEdgesOptions, getAqlQueryOptions(true, 10, true)); + + assertEquals(201, cursor.getCode()); + assertEquals(1, cursor.getCount()); + assertEquals(edge2.getDocumentHandle(), cursor.getUniqueResult().getDocumentHandle()); + } + + @Test + public void graphGetEdgeCursorWithNeighborExample() throws ArangoException { + + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + + final TestComplexEntity02 e1 = new TestComplexEntity02(1, 2, 3); + EdgeEntity edge1 = driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, + vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), e1, null); + + final TestComplexEntity02 e2 = new TestComplexEntity02(4, 5, 6); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), e2, + null); + + final TestComplexEntity02 e3 = new TestComplexEntity02(7, 8, 9); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), e3, + null); + + final TestComplexEntity02 e4 = new TestComplexEntity02(10, 11, 12); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex3.getDocumentHandle(), e4, + null); + + GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions(); + graphEdgesOptions.setNeighborExamples(new TestComplexEntity01(null, null, 36)); + + EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, + vertex1.getDocumentHandle(), graphEdgesOptions, getAqlQueryOptions(true, 10, true)); + + assertEquals(201, cursor.getCode()); + assertEquals(1, cursor.getCount()); + assertEquals(edge1.getDocumentHandle(), cursor.getUniqueResult().getDocumentHandle()); + } + + @Test + public void graphGetEdgeCursorByExampleStartVertexRestriction() throws ArangoException { + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), + new TestComplexEntity02(1, 2, 3), null); + + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), + new TestComplexEntity02(4, 5, 6), null); + + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), + new TestComplexEntity02(7, 8, 9), null); + + GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions(); + List startVertexCollectionRestriction = new ArrayList(); + startVertexCollectionRestriction.add("from1-1"); + graphEdgesOptions.setStartVertexCollectionRestriction(startVertexCollectionRestriction); + + EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, + new TestComplexEntity01(null, "A Simpson", null), graphEdgesOptions, getAqlQueryOptions(true, 10, true)); + assertThat(cursor.getCount(), is(2)); + } + @Test public void shortestPathTest() throws ArangoException { From c64d34786484d6f93eb27a8539ab0c5501984595 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 9 Jun 2016 11:35:22 +0200 Subject: [PATCH 30/56] replace graph_vertices function with aql --- src/main/java/com/arangodb/ArangoDriver.java | 15 ++-- .../com/arangodb/util/GraphQueryUtil.java | 76 ++++++++++++++++--- .../arangodb/util/GraphVerticesOptions.java | 43 +---------- .../arangodb/ArangoDriverGraphVertexTest.java | 14 ++-- 4 files changed, 80 insertions(+), 68 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 00c38905c..c494c72ce 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -81,7 +81,6 @@ import com.arangodb.util.GraphEdgesOptions; import com.arangodb.util.GraphQueryUtil; import com.arangodb.util.GraphVerticesOptions; -import com.arangodb.util.JsonUtils; import com.arangodb.util.MapBuilder; import com.arangodb.util.ShortestPathOptions; import com.arangodb.util.TraversalQueryOptions; @@ -104,8 +103,6 @@ public class ArangoDriver extends BaseArangoDriver { private static final String DATABASE_SYSTEM = "_system"; private static final String COLLECTION_USERS = "_users"; - private static final String GRAPH_NAME = "graphName"; - private static final String VERTEX_EXAMPLE = "vertexExample"; private final ArangoConfigure configure; private final BatchHttpManager httpManager; @@ -4439,11 +4436,15 @@ public VertexCursor graphGetVertexCursor( validateCollectionName(graphName); - final String query = "for i in graph_vertices(@graphName , @vertexExample, @options) return i"; + GraphVerticesOptions tmpGraphVerticesOptions = graphVerticesOptions; + if (tmpGraphVerticesOptions == null) { + tmpGraphVerticesOptions = new GraphVerticesOptions(); + } - final Map bindVars = new MapBuilder().put(GRAPH_NAME, graphName) - .put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)) - .put("options", JsonUtils.convertNullToMap(graphVerticesOptions)).get(); + final MapBuilder mapBuilder = new MapBuilder(); + final String query = GraphQueryUtil.createVerticesQuery(this, graphName, clazz, vertexExample, + tmpGraphVerticesOptions, mapBuilder); + final Map bindVars = mapBuilder.get(); return executeVertexQuery(query, bindVars, aqlQueryOptions, clazz); } diff --git a/src/main/java/com/arangodb/util/GraphQueryUtil.java b/src/main/java/com/arangodb/util/GraphQueryUtil.java index 0013b2974..cb3455d11 100644 --- a/src/main/java/com/arangodb/util/GraphQueryUtil.java +++ b/src/main/java/com/arangodb/util/GraphQueryUtil.java @@ -35,10 +35,10 @@ public static String createEdgeQuery( if (vertexExample != null && String.class.isAssignableFrom(vertexExample.getClass())) { sb.append("FOR v,e IN "); appendDepth(graphEdgesOptions, sb); - appendDirection(graphEdgesOptions, sb); + appendDirection(graphEdgesOptions.getDirection(), sb); sb.append(" @"); sb.append(VERTEX_EXAMPLE); - bindVars.put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)); + bindVars.put(VERTEX_EXAMPLE, vertexExample); } else { final List startVertexCollectionRestriction = graphEdgesOptions .getStartVertexCollectionRestriction(); @@ -65,7 +65,7 @@ public static String createEdgeQuery( } sb.append(" FOR v,e IN "); appendDepth(graphEdgesOptions, sb); - appendDirection(graphEdgesOptions, sb); + appendDirection(graphEdgesOptions.getDirection(), sb); sb.append(" start"); } sb.append(" "); @@ -78,9 +78,7 @@ public static String createEdgeQuery( // remove last , sb.deleteCharAt(sb.length() - 1); } else { - sb.append("GRAPH @"); - sb.append(GRAPH_NAME); - bindVars.put(GRAPH_NAME, graphName); + appendGraphName(graphName, bindVars, sb); } appendFilter("e", graphEdgesOptions.getEdgeExamples(), sb); appendFilter("v", graphEdgesOptions.getNeighborExamples(), sb); @@ -98,6 +96,17 @@ public static String createEdgeQuery( return query; } + /** + * @param graphName + * @param bindVars + * @param sb + */ + private static void appendGraphName(final String graphName, final MapBuilder bindVars, final StringBuilder sb) { + sb.append("GRAPH @"); + sb.append(GRAPH_NAME); + bindVars.put(GRAPH_NAME, graphName); + } + private static void appendDepth(final GraphEdgesOptions graphEdgesOptions, final StringBuilder sb) { final Integer minDepth = graphEdgesOptions.getMinDepth(); final Integer maxDepth = graphEdgesOptions.getMaxDepth(); @@ -109,10 +118,9 @@ private static void appendDepth(final GraphEdgesOptions graphEdgesOptions, final } } - private static void appendDirection(final GraphEdgesOptions graphEdgesOptions, final StringBuilder sb) { - final String direction = graphEdgesOptions.getDirection() != null ? graphEdgesOptions.getDirection().name() - : Direction.ANY.name(); - sb.append(direction); + private static void appendDirection(final Direction direction, final StringBuilder sb) { + final String directionName = direction != null ? direction.name() : Direction.ANY.name(); + sb.append(directionName); } private static void appendFilter(final String var, final Object example, final StringBuilder sb) @@ -167,7 +175,53 @@ public static String createVerticesQuery( final Object vertexExample, final GraphVerticesOptions graphVerticesOptions, final MapBuilder bindVars) throws ArangoException { - return null; + + // final String query = "for i in graph_vertices(@graphName , + // @vertexExample, @options) return i"; + // final Map bindVars = new MapBuilder().put(GRAPH_NAME, + // graphName) + // .put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)) + // .put("options", + // JsonUtils.convertNullToMap(graphVerticesOptions)).get(); + + StringBuilder sb = new StringBuilder(); + final boolean stringVertexExample = vertexExample != null + && String.class.isAssignableFrom(vertexExample.getClass()); + if (stringVertexExample) { + sb.append("RETURN "); + sb.append("DOCUMENT("); + sb.append("@"); + sb.append(VERTEX_EXAMPLE); + bindVars.put(VERTEX_EXAMPLE, vertexExample); + sb.append(")"); + } else { + final List startVertexCollectionRestriction = graphVerticesOptions.getVertexCollectionRestriction(); + final List vertexCollections = startVertexCollectionRestriction != null + && startVertexCollectionRestriction.size() > 0 ? startVertexCollectionRestriction + : driver.graphGetVertexCollections(graphName, true); + if (vertexCollections.size() == 1) { + sb.append("FOR start IN `"); + sb.append(vertexCollections.get(0)); + sb.append("`"); + appendFilter("start", vertexExample, sb); + } else { + sb.append("FOR start IN UNION ("); + for (String vertexCollection : vertexCollections) { + sb.append("(FOR start IN `"); + sb.append(vertexCollection); + sb.append("`"); + appendFilter("start", vertexExample, sb); + sb.append(" RETURN start),"); + } + // remove last , + sb.deleteCharAt(sb.length() - 1); + sb.append(")"); + } + sb.append(" RETURN start"); + } + + String query = sb.toString(); + return query; } public static String createShortestPathQuery( diff --git a/src/main/java/com/arangodb/util/GraphVerticesOptions.java b/src/main/java/com/arangodb/util/GraphVerticesOptions.java index 927da02ea..69106081d 100644 --- a/src/main/java/com/arangodb/util/GraphVerticesOptions.java +++ b/src/main/java/com/arangodb/util/GraphVerticesOptions.java @@ -1,35 +1,11 @@ package com.arangodb.util; import java.util.List; -import java.util.Map; -import com.arangodb.Direction; +public class GraphVerticesOptions { -public class GraphVerticesOptions implements OptionsInterface { - - private Direction direction; private List vertexCollectionRestriction; - /** - * The direction of the edges as a string. Possible values are outbound, - * inbound and any (default). - * - * @return the direction - */ - public Direction getDirection() { - return direction; - } - - /** - * The direction of the edges as a string. Possible values are outbound, - * inbound and any (default). - * - * @param direction - */ - public void setDirection(Direction direction) { - this.direction = direction; - } - /** * One or multiple vertex collections that should be considered. * @@ -48,21 +24,4 @@ public void setVertexCollectionRestriction(List vertexCollectionRestrict this.vertexCollectionRestriction = vertexCollectionRestriction; } - /** - * Returns a map of the options - * - * @return a map - */ - @Override - public Map toMap() { - MapBuilder mp = new MapBuilder(); - if (direction != null) { - mp.put("direction", direction.toString().toLowerCase()); - } - if (CollectionUtils.isNotEmpty(vertexCollectionRestriction)) { - mp.put("vertexCollectionRestriction", vertexCollectionRestriction); - } - return mp.get(); - } - } diff --git a/src/test/java/com/arangodb/ArangoDriverGraphVertexTest.java b/src/test/java/com/arangodb/ArangoDriverGraphVertexTest.java index 75ee41f5d..51b7d054c 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphVertexTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphVertexTest.java @@ -303,22 +303,20 @@ public void graphGetVertexCursorTest() throws ArangoException { assertEquals(201, vertexCursor.getCode()); final GraphVerticesOptions graphVerticesOptions = new GraphVerticesOptions(); - graphVerticesOptions.setDirection(Direction.INBOUND); - - vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, TestComplexEntity01.class, null, graphVerticesOptions, - aqlQueryOptions); - assertEquals(2, vertexCursor.getCount()); - assertEquals(201, vertexCursor.getCode()); - final List vertexCollectionRestriction = new ArrayList(); vertexCollectionRestriction.add("from1-1"); graphVerticesOptions.setVertexCollectionRestriction(vertexCollectionRestriction); vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, TestComplexEntity01.class, null, graphVerticesOptions, aqlQueryOptions); - assertEquals(0, vertexCursor.getCount()); + assertEquals(2, vertexCursor.getCount()); assertEquals(201, vertexCursor.getCode()); + vertexCursor = driver.graphGetVertexCursor(GRAPH_NAME, TestComplexEntity01.class, vertex1.getDocumentHandle(), + null, aqlQueryOptions); + assertEquals(201, vertexCursor.getCode()); + assertEquals(1, vertexCursor.getCount()); + assertEquals(vertex1.getDocumentHandle(), vertexCursor.getUniqueResult().getDocumentHandle()); } @Test From 2fd85471ad7b2e51a2b8262ca1b1ff200d4c0c7c Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 9 Jun 2016 11:38:14 +0200 Subject: [PATCH 31/56] Replace graph_edge function with aql (clean up) --- .../com/arangodb/util/GraphQueryUtil.java | 8 ---- .../example/graph/GraphAqlQueryExample.java | 38 ------------------- 2 files changed, 46 deletions(-) diff --git a/src/main/java/com/arangodb/util/GraphQueryUtil.java b/src/main/java/com/arangodb/util/GraphQueryUtil.java index cb3455d11..0edeef101 100644 --- a/src/main/java/com/arangodb/util/GraphQueryUtil.java +++ b/src/main/java/com/arangodb/util/GraphQueryUtil.java @@ -176,14 +176,6 @@ public static String createVerticesQuery( final GraphVerticesOptions graphVerticesOptions, final MapBuilder bindVars) throws ArangoException { - // final String query = "for i in graph_vertices(@graphName , - // @vertexExample, @options) return i"; - // final Map bindVars = new MapBuilder().put(GRAPH_NAME, - // graphName) - // .put(VERTEX_EXAMPLE, JsonUtils.convertNullToMap(vertexExample)) - // .put("options", - // JsonUtils.convertNullToMap(graphVerticesOptions)).get(); - StringBuilder sb = new StringBuilder(); final boolean stringVertexExample = vertexExample != null && String.class.isAssignableFrom(vertexExample.getClass()); diff --git a/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java b/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java index d246ad7ae..eb8b1289e 100644 --- a/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java +++ b/src/test/java/com/arangodb/example/graph/GraphAqlQueryExample.java @@ -16,10 +16,7 @@ package com.arangodb.example.graph; -import java.util.HashMap; import java.util.Iterator; -import java.util.List; -import java.util.Map; import org.junit.After; import org.junit.Assert; @@ -27,7 +24,6 @@ import org.junit.Test; import com.arangodb.ArangoException; -import com.arangodb.CursorResult; import com.arangodb.Direction; import com.arangodb.EdgeCursor; import com.arangodb.VertexCursor; @@ -177,40 +173,6 @@ public void graphAqlQuery() throws ArangoException { // no path found (distance = -1) Assert.assertEquals(new Long(-1), shortestPath.getDistance()); - // - printHeadline("get all vertex document handles by AQL query"); - // - - String query = "for i in graph_vertices(@graphName , null, null) return i._id"; - Map bindVars = new HashMap(); - bindVars.put("graphName", GRAPH_NAME); - - final CursorResult cursor = driver.executeAqlQuery(query, bindVars, null, String.class); - Assert.assertNotNull(cursor); - final List list = cursor.asList(); - count = 0; - for (final String str : list) { - System.out.printf("%d\t%20s%n", ++count, str); - } - Assert.assertEquals(6, list.size()); - - // - printHeadline("get vertex documents by AQL query and filter"); - // - - query = "for i in graph_vertices(@graphName , null, null) filter i.name != @name return i"; - bindVars = new HashMap(); - bindVars.put("graphName", GRAPH_NAME); - bindVars.put("name", "Boris"); - - final CursorResult cursor2 = driver.executeAqlQuery(query, bindVars, null, Person.class); - Assert.assertNotNull(cursor2); - final List list2 = cursor2.asList(); - count = 0; - for (final Person person : list2) { - System.out.printf("%d\t%20s\t%s%n", ++count, person.getDocumentHandle(), person.getName()); - } - Assert.assertEquals(5, list2.size()); } private void printShortestPath(final ShortestPathEntity shortestPath) { From a97e1ad8238043222e4b127e63ef01bcb2ecd5e0 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 9 Jun 2016 14:07:08 +0200 Subject: [PATCH 32/56] replace graph_shortes_path function with aql --- src/main/java/com/arangodb/ArangoDriver.java | 8 +- .../com/arangodb/InternalCursorDriver.java | 3 +- .../impl/InternalCursorDriverImpl.java | 20 +- .../com/arangodb/util/GraphEdgesOptions.java | 3 +- .../com/arangodb/util/GraphQueryUtil.java | 224 ++++++++++++------ .../arangodb/util/ShortestPathOptions.java | 66 ++---- 6 files changed, 194 insertions(+), 130 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index c494c72ce..19afdd83f 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -4397,7 +4397,7 @@ public EdgeCursor graphGetEdgeCursor( validateCollectionName(graphName); final MapBuilder mapBuilder = new MapBuilder(); - final String query = GraphQueryUtil.createEdgeQuery(this, graphName, clazz, vertexExample, tmpGraphEdgesOptions, + final String query = GraphQueryUtil.createEdgeQuery(this, graphName, vertexExample, tmpGraphEdgesOptions, mapBuilder); final Map bindVars = mapBuilder.get(); @@ -4442,8 +4442,8 @@ public VertexCursor graphGetVertexCursor( } final MapBuilder mapBuilder = new MapBuilder(); - final String query = GraphQueryUtil.createVerticesQuery(this, graphName, clazz, vertexExample, - tmpGraphVerticesOptions, mapBuilder); + final String query = GraphQueryUtil.createVerticesQuery(this, graphName, vertexExample, tmpGraphVerticesOptions, + mapBuilder); final Map bindVars = mapBuilder.get(); return executeVertexQuery(query, bindVars, aqlQueryOptions, clazz); @@ -4495,7 +4495,7 @@ public ShortestPathEntity graphGetShortestPath( } return cursorDriver.getShortestPath(getDefaultDatabase(), graphName, startVertexExample, endVertexExample, - tmpShortestPathOptions, getDefaultAqlQueryOptions(), vertexClass, edgeClass); + tmpShortestPathOptions, getDefaultAqlQueryOptions(), vertexClass, edgeClass, this); } /** diff --git a/src/main/java/com/arangodb/InternalCursorDriver.java b/src/main/java/com/arangodb/InternalCursorDriver.java index 4a63287a6..4b64075f2 100644 --- a/src/main/java/com/arangodb/InternalCursorDriver.java +++ b/src/main/java/com/arangodb/InternalCursorDriver.java @@ -93,7 +93,8 @@ public ShortestPathEntity getShortestPath( ShortestPathOptions shortestPathOptions, AqlQueryOptions aqlQueryOptions, Class vertexClass, - Class edgeClass) throws ArangoException; + Class edgeClass, + ArangoDriver driver) throws ArangoException; QueryTrackingPropertiesEntity getQueryTrackingProperties(String database) throws ArangoException; diff --git a/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java b/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java index 215a0dd04..068f0dcab 100644 --- a/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java @@ -20,6 +20,7 @@ import java.util.Map; import com.arangodb.ArangoConfigure; +import com.arangodb.ArangoDriver; import com.arangodb.ArangoException; import com.arangodb.CursorRawResult; import com.arangodb.CursorResult; @@ -34,6 +35,7 @@ import com.arangodb.http.HttpManager; import com.arangodb.http.HttpResponseEntity; import com.arangodb.util.AqlQueryOptions; +import com.arangodb.util.GraphQueryUtil; import com.arangodb.util.MapBuilder; import com.arangodb.util.ShortestPathOptions; import com.google.gson.JsonObject; @@ -171,19 +173,21 @@ public ShortestPathEntity getShortestPath( final ShortestPathOptions shortestPathOptions, final AqlQueryOptions aqlQueryOptions, final Class vertexClass, - final Class edgeClass) throws ArangoException { + final Class edgeClass, + final ArangoDriver driver) throws ArangoException { validateCollectionName(graphName); - final String query = "for i in graph_shortest_path(@graphName, @startVertexExample, @endVertexExample, @options) return i"; - - final Map options = shortestPathOptions == null ? new MapBuilder().get() - : shortestPathOptions.toMap(); + ShortestPathOptions tmpShortestPathOptions = shortestPathOptions; + if (tmpShortestPathOptions == null) { + tmpShortestPathOptions = new ShortestPathOptions(); + } - final Map bindVars = new MapBuilder().put("graphName", graphName) - .put("startVertexExample", startVertexExample).put("endVertexExample", endVertexExample) - .put("options", options).get(); + MapBuilder mapBuilder = new MapBuilder(); + final String query = GraphQueryUtil.createShortestPathQuery(driver, database, graphName, startVertexExample, + endVertexExample, tmpShortestPathOptions, vertexClass, edgeClass, mapBuilder); + final Map bindVars = mapBuilder.get(); final HttpResponseEntity res = getCursor(database, query, bindVars, aqlQueryOptions); return createEntity(res, ShortestPathEntity.class, vertexClass, edgeClass); diff --git a/src/main/java/com/arangodb/util/GraphEdgesOptions.java b/src/main/java/com/arangodb/util/GraphEdgesOptions.java index be63eb53c..659dc773d 100644 --- a/src/main/java/com/arangodb/util/GraphEdgesOptions.java +++ b/src/main/java/com/arangodb/util/GraphEdgesOptions.java @@ -218,8 +218,9 @@ public Boolean getIncludeData() { * * @since ArangoDB 2.6 */ - public void setIncludeData(Boolean includeData) { + public GraphEdgesOptions setIncludeData(Boolean includeData) { this.includeData = includeData; + return this; } } diff --git a/src/main/java/com/arangodb/util/GraphQueryUtil.java b/src/main/java/com/arangodb/util/GraphQueryUtil.java index 0edeef101..a4f3509d5 100644 --- a/src/main/java/com/arangodb/util/GraphQueryUtil.java +++ b/src/main/java/com/arangodb/util/GraphQueryUtil.java @@ -1,5 +1,6 @@ package com.arangodb.util; +import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; import java.util.Set; @@ -22,11 +23,14 @@ public class GraphQueryUtil { private static final String OR = " || "; private static final String GRAPH_NAME = "graphName"; private static final String VERTEX_EXAMPLE = "vertexExample"; + private static final String START_VERTEX_EXAMPLE = "startVertexExample"; + private static final String END_VERTEX_EXAMPLE = "endVertexExample"; + private static final String SOURCE = "source"; + private static final String TARGET = "target"; public static String createEdgeQuery( final ArangoDriver driver, final String graphName, - final Class clazz, final Object vertexExample, final GraphEdgesOptions graphEdgesOptions, final MapBuilder bindVars) throws ArangoException { @@ -36,50 +40,21 @@ public static String createEdgeQuery( sb.append("FOR v,e IN "); appendDepth(graphEdgesOptions, sb); appendDirection(graphEdgesOptions.getDirection(), sb); - sb.append(" @"); - sb.append(VERTEX_EXAMPLE); - bindVars.put(VERTEX_EXAMPLE, vertexExample); + appendBindVar(VERTEX_EXAMPLE, vertexExample, bindVars, sb); } else { final List startVertexCollectionRestriction = graphEdgesOptions .getStartVertexCollectionRestriction(); final List vertexCollections = startVertexCollectionRestriction != null && startVertexCollectionRestriction.size() > 0 ? startVertexCollectionRestriction : driver.graphGetVertexCollections(graphName, true); - if (vertexCollections.size() == 1) { - sb.append("FOR start IN `"); - sb.append(vertexCollections.get(0)); - sb.append("`"); - appendFilter("start", vertexExample, sb); - } else { - sb.append("FOR start IN UNION ("); - for (String vertexCollection : vertexCollections) { - sb.append("(FOR start IN `"); - sb.append(vertexCollection); - sb.append("`"); - appendFilter("start", vertexExample, sb); - sb.append(" RETURN start),"); - } - // remove last , - sb.deleteCharAt(sb.length() - 1); - sb.append(")"); - } + appendFor("start", vertexExample, sb, vertexCollections); sb.append(" FOR v,e IN "); appendDepth(graphEdgesOptions, sb); appendDirection(graphEdgesOptions.getDirection(), sb); sb.append(" start"); } - sb.append(" "); final List edgeCollectionRestriction = graphEdgesOptions.getEdgeCollectionRestriction(); - if (edgeCollectionRestriction != null && edgeCollectionRestriction.size() > 0) { - for (String edgeCollection : edgeCollectionRestriction) { - sb.append(edgeCollection); - sb.append(","); - } - // remove last , - sb.deleteCharAt(sb.length() - 1); - } else { - appendGraphName(graphName, bindVars, sb); - } + appendEdgeCollectionsOrGraph(graphName, bindVars, sb, edgeCollectionRestriction); appendFilter("e", graphEdgesOptions.getEdgeExamples(), sb); appendFilter("v", graphEdgesOptions.getNeighborExamples(), sb); final Integer limit = graphEdgesOptions.getLimit(); @@ -96,15 +71,72 @@ public static String createEdgeQuery( return query; } - /** - * @param graphName - * @param bindVars - * @param sb - */ + private static void appendEdgeCollectionsOrGraph( + final String graphName, + final MapBuilder bindVars, + final StringBuilder sb, + final List edgeCollectionRestriction) { + sb.append(" "); + if (edgeCollectionRestriction != null && edgeCollectionRestriction.size() > 0) { + for (String edgeCollection : edgeCollectionRestriction) { + sb.append("`"); + sb.append(edgeCollection); + sb.append("`,"); + } + // remove last , + sb.deleteCharAt(sb.length() - 1); + } else { + appendGraphName(graphName, bindVars, sb); + } + } + + private static void appendBindVar( + final String param, + final Object var, + final MapBuilder bindVars, + final StringBuilder sb) { + sb.append(" @"); + sb.append(param); + bindVars.put(param, var); + } + + private static void appendFor( + final String var, + final Object vertexExample, + final StringBuilder sb, + final List vertexCollections) throws ArangoException { + if (vertexCollections.size() == 1) { + sb.append("FOR "); + sb.append(var); + sb.append(" IN `"); + sb.append(vertexCollections.get(0)); + sb.append("`"); + appendFilter(var, vertexExample, sb); + } else { + sb.append("FOR "); + sb.append(var); + sb.append(" IN UNION ("); + for (String vertexCollection : vertexCollections) { + sb.append("(FOR "); + sb.append(var); + sb.append(" IN `"); + sb.append(vertexCollection); + sb.append("`"); + appendFilter(var, vertexExample, sb); + sb.append(" RETURN "); + sb.append(var); + sb.append("),"); + } + // remove last , + sb.deleteCharAt(sb.length() - 1); + sb.append(")"); + } + sb.append(" "); + } + private static void appendGraphName(final String graphName, final MapBuilder bindVars, final StringBuilder sb) { - sb.append("GRAPH @"); - sb.append(GRAPH_NAME); - bindVars.put(GRAPH_NAME, graphName); + sb.append("GRAPH"); + appendBindVar(GRAPH_NAME, graphName, bindVars, sb); } private static void appendDepth(final GraphEdgesOptions graphEdgesOptions, final StringBuilder sb) { @@ -171,7 +203,6 @@ private static void appendObjectinFilter(final String var, final JsonObject json public static String createVerticesQuery( final ArangoDriver driver, final String graphName, - final Class clazz, final Object vertexExample, final GraphVerticesOptions graphVerticesOptions, final MapBuilder bindVars) throws ArangoException { @@ -182,37 +213,18 @@ public static String createVerticesQuery( if (stringVertexExample) { sb.append("RETURN "); sb.append("DOCUMENT("); - sb.append("@"); - sb.append(VERTEX_EXAMPLE); - bindVars.put(VERTEX_EXAMPLE, vertexExample); + appendBindVar(VERTEX_EXAMPLE, vertexExample, bindVars, sb); sb.append(")"); } else { final List startVertexCollectionRestriction = graphVerticesOptions.getVertexCollectionRestriction(); final List vertexCollections = startVertexCollectionRestriction != null && startVertexCollectionRestriction.size() > 0 ? startVertexCollectionRestriction : driver.graphGetVertexCollections(graphName, true); - if (vertexCollections.size() == 1) { - sb.append("FOR start IN `"); - sb.append(vertexCollections.get(0)); - sb.append("`"); - appendFilter("start", vertexExample, sb); - } else { - sb.append("FOR start IN UNION ("); - for (String vertexCollection : vertexCollections) { - sb.append("(FOR start IN `"); - sb.append(vertexCollection); - sb.append("`"); - appendFilter("start", vertexExample, sb); - sb.append(" RETURN start),"); - } - // remove last , - sb.deleteCharAt(sb.length() - 1); - sb.append(")"); - } + appendFor("start", vertexExample, sb, vertexCollections); sb.append(" RETURN start"); } - String query = sb.toString(); + final String query = sb.toString(); return query; } @@ -225,7 +237,87 @@ public static String createShortestPathQuery( final ShortestPathOptions shortestPathOptions, final Class vertexClass, final Class edgeClass, - final MapBuilder bindVars) { - return null; + final MapBuilder bindVars) throws ArangoException { + /* + * + * final String query = + * "for i in graph_shortest_path(@graphName, @startVertexExample, @endVertexExample, @options) return i" + * ; final Map bindVars = mapBuilder.put("graphName", + * graphName) .put("startVertexExample", + * startVertexExample).put("endVertexExample", endVertexExample) + * .put("options", options).get(); + */ + final StringBuilder sb = new StringBuilder(); + final boolean notStringStartVertexExample = startVertexExample != null + && !String.class.isAssignableFrom(startVertexExample.getClass()); + boolean notStringEndVertexExample = endVertexExample != null + && !String.class.isAssignableFrom(endVertexExample.getClass()); + if (notStringStartVertexExample || notStringEndVertexExample) { + final List startVertexCollectionRestriction = shortestPathOptions + .getStartVertexCollectionRestriction(); + final List endVertexCollectionRestriction = shortestPathOptions.getEndVertexCollectionRestriction(); + final boolean startVertexCollectionRestrictionNotEmpty = startVertexCollectionRestriction != null + && startVertexCollectionRestriction.size() > 0; + final boolean endVertexCollectionRestrictionNotEmpty = endVertexCollectionRestriction != null + && endVertexCollectionRestriction.size() > 0; + final List vertexCollections = (!startVertexCollectionRestrictionNotEmpty + || !endVertexCollectionRestrictionNotEmpty) ? driver.graphGetVertexCollections(graphName, true) + : new ArrayList(); + + if (notStringStartVertexExample) { + final List tmpStartVertexCollectionRestriction = startVertexCollectionRestrictionNotEmpty + ? startVertexCollectionRestriction : vertexCollections; + appendFor(SOURCE, startVertexExample, sb, tmpStartVertexCollectionRestriction); + } + if (notStringEndVertexExample) { + final List tmpEndVertexCollectionRestriction = endVertexCollectionRestrictionNotEmpty + ? endVertexCollectionRestriction : vertexCollections; + appendFor(TARGET, endVertexExample, sb, tmpEndVertexCollectionRestriction); + } + if (notStringStartVertexExample && notStringEndVertexExample) { + sb.append("FILTER target != source "); + } + } + {// p + sb.append("LET p = ( FOR v, e IN "); + appendDirection(shortestPathOptions.getDirection(), sb); + sb.append(" SHORTEST_PATH "); + if (notStringStartVertexExample) { + sb.append(SOURCE); + } else { + appendBindVar(START_VERTEX_EXAMPLE, startVertexExample, bindVars, sb); + } + sb.append(" TO "); + if (notStringEndVertexExample) { + sb.append(TARGET); + } else { + appendBindVar(END_VERTEX_EXAMPLE, endVertexExample, bindVars, sb); + } + List edgeCollectionRestriction = shortestPathOptions.getEdgeCollectionRestriction(); + appendEdgeCollectionsOrGraph(graphName, bindVars, sb, edgeCollectionRestriction); + + final String weight = shortestPathOptions.getWeight(); + if (weight != null) { + sb.append(" OPTIONS {weightAttribute: @attribute, defaultWeight: @default} "); + sb.append( + " RETURN { v: v, e: e, d: IS_NULL(e) ? 0 : (IS_NUMBER(e[@attribute]) ? e[@attribute] : @default))}) "); + bindVars.put("attribute", weight); + final Long defaultWeight = shortestPathOptions.getDefaultWeight(); + bindVars.put("default", defaultWeight != null ? defaultWeight : 1); + } else { + sb.append(" RETURN {v: v, e: e, d: IS_NULL(e) ? 0 : 1}) "); + } + } + sb.append("FILTER LENGTH(p) > 0 "); + if (shortestPathOptions.getIncludeData() != null && !shortestPathOptions.getIncludeData().booleanValue()) { + sb.append( + "RETURN { vertices: p[*].v._id, edges: p[* FILTER CURRENT.e != null].e._id, distance: SUM(p[*].d)}"); + } else { + sb.append("RETURN { vertices: p[*].v, edges: p[* FILTER CURRENT.e != null].e, distance: SUM(p[*].d)}"); + } + + final String query = sb.toString(); + System.out.println(query); + return query; } } diff --git a/src/main/java/com/arangodb/util/ShortestPathOptions.java b/src/main/java/com/arangodb/util/ShortestPathOptions.java index 33ba1deb7..fd5d69e59 100644 --- a/src/main/java/com/arangodb/util/ShortestPathOptions.java +++ b/src/main/java/com/arangodb/util/ShortestPathOptions.java @@ -1,18 +1,16 @@ package com.arangodb.util; import java.util.List; -import java.util.Map; import com.arangodb.Direction; -public class ShortestPathOptions extends AbstractOptions implements OptionsInterface { +public class ShortestPathOptions { private Direction direction; private List edgeCollectionRestriction; private List startVertexCollectionRestriction; private List endVertexCollectionRestriction; private Object edgeExamples; - private String algorithm; private String weight; private Long defaultWeight; private Boolean includeData = Boolean.TRUE; @@ -125,30 +123,6 @@ public ShortestPathOptions setEdgeExamples(Object edgeExamples) { return this; } - /** - * The algorithm to calculate the shortest paths. If both start and end - * vertex examples are empty Floyd-Warshall is used, otherwise the default - * is Dijkstra. - * - * @return The algorithm to calculate the shortest paths. - */ - public String getAlgorithm() { - return algorithm; - } - - /** - * The algorithm to calculate the shortest paths. If both start and end - * vertex examples are empty Floyd-Warshall is used, otherwise the default - * is Dijkstra. - * - * @param algorithm - * @return this - */ - public ShortestPathOptions setAlgorithm(String algorithm) { - this.algorithm = algorithm; - return this; - } - /** * The name of the attribute of the edges containing the length as a string. * @@ -196,31 +170,23 @@ public ShortestPathOptions setDefaultWeight(Long defaultWeight) { } /** - * Returns a map of the options + * Get include data * - * @return a map + * @return */ - @Override - public Map toMap() { - MapBuilder mp = new MapBuilder(); - - putAttributeToLower(mp, "direction", direction); - putAttributeCollection(mp, "edgeCollectionRestriction", edgeCollectionRestriction); - putAttributeCollection(mp, "startVertexCollectionRestriction", startVertexCollectionRestriction); - putAttributeCollection(mp, "endVertexCollectionRestriction", endVertexCollectionRestriction); - putAttribute(mp, "edgeExamples", edgeExamples); - putAttribute(mp, "algorithm", algorithm); - putAttribute(mp, "weight", weight); - putAttribute(mp, "defaultWeight", defaultWeight); - - if (includeData != null) { - mp.put("includeData", includeData); - MapBuilder mp2 = new MapBuilder(); - mp2.put("edges", true); - mp2.put("vertices", true); - mp.put("includePath", mp2.get()); - } - return mp.get(); + public Boolean getIncludeData() { + return includeData; } + /** + * set include data to be compatible with older versions of AnrangoDB + * + * @param includeData + * + * @since ArangoDB 2.6 + */ + public ShortestPathOptions setIncludeData(Boolean includeData) { + this.includeData = includeData; + return this; + } } From e72d1602974698591dfe2369acfd887949278f74 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 9 Jun 2016 15:09:49 +0200 Subject: [PATCH 33/56] replace graph_shortes_path function with aql (fixes, tests added) --- .../com/arangodb/util/GraphQueryUtil.java | 3 +- .../arangodb/util/ShortestPathOptions.java | 21 -- .../ArangoDriverGraphShortestPathTest.java | 225 ++++++++++++++++++ .../java/com/arangodb/ArangoTestSuite.java | 4 + 4 files changed, 230 insertions(+), 23 deletions(-) create mode 100644 src/test/java/com/arangodb/ArangoDriverGraphShortestPathTest.java diff --git a/src/main/java/com/arangodb/util/GraphQueryUtil.java b/src/main/java/com/arangodb/util/GraphQueryUtil.java index a4f3509d5..115d280d1 100644 --- a/src/main/java/com/arangodb/util/GraphQueryUtil.java +++ b/src/main/java/com/arangodb/util/GraphQueryUtil.java @@ -300,7 +300,7 @@ public static String createShortestPathQuery( if (weight != null) { sb.append(" OPTIONS {weightAttribute: @attribute, defaultWeight: @default} "); sb.append( - " RETURN { v: v, e: e, d: IS_NULL(e) ? 0 : (IS_NUMBER(e[@attribute]) ? e[@attribute] : @default))}) "); + " RETURN { v: v, e: e, d: IS_NULL(e) ? 0 : (IS_NUMBER(e[@attribute]) ? e[@attribute] : @default)}) "); bindVars.put("attribute", weight); final Long defaultWeight = shortestPathOptions.getDefaultWeight(); bindVars.put("default", defaultWeight != null ? defaultWeight : 1); @@ -317,7 +317,6 @@ public static String createShortestPathQuery( } final String query = sb.toString(); - System.out.println(query); return query; } } diff --git a/src/main/java/com/arangodb/util/ShortestPathOptions.java b/src/main/java/com/arangodb/util/ShortestPathOptions.java index fd5d69e59..360c935bc 100644 --- a/src/main/java/com/arangodb/util/ShortestPathOptions.java +++ b/src/main/java/com/arangodb/util/ShortestPathOptions.java @@ -10,7 +10,6 @@ public class ShortestPathOptions { private List edgeCollectionRestriction; private List startVertexCollectionRestriction; private List endVertexCollectionRestriction; - private Object edgeExamples; private String weight; private Long defaultWeight; private Boolean includeData = Boolean.TRUE; @@ -103,26 +102,6 @@ public ShortestPathOptions setEndVertexCollectionRestriction(List endVer return this; } - /** - * A filter example for the edges - * - * @return A filter example for the edges - */ - public Object getEdgeExamples() { - return edgeExamples; - } - - /** - * A filter example for the edges - * - * @param edgeExamples - * @return this - */ - public ShortestPathOptions setEdgeExamples(Object edgeExamples) { - this.edgeExamples = edgeExamples; - return this; - } - /** * The name of the attribute of the edges containing the length as a string. * diff --git a/src/test/java/com/arangodb/ArangoDriverGraphShortestPathTest.java b/src/test/java/com/arangodb/ArangoDriverGraphShortestPathTest.java new file mode 100644 index 000000000..3b1f61b49 --- /dev/null +++ b/src/test/java/com/arangodb/ArangoDriverGraphShortestPathTest.java @@ -0,0 +1,225 @@ +package com.arangodb; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.arangodb.entity.EdgeEntity; +import com.arangodb.entity.ShortestPathEntity; +import com.arangodb.entity.marker.VertexEntity; +import com.arangodb.util.ShortestPathOptions; + +/** + * @author Mark - mark@arangodb.com + * + */ +public class ArangoDriverGraphShortestPathTest extends BaseGraphTest { + + private static final String GRAPH_NAME = "UnitTestGraph"; + + @Before + public void setup() { + try { + driver.deleteGraph(GRAPH_NAME); + } catch (ArangoException e1) { + } + try { + driver.createGraph(GRAPH_NAME, this.createEdgeDefinitions(1, 0), this.createOrphanCollections(0), true); + } catch (final ArangoException e) { + } + } + + @After + public void cleanup() { + try { + driver.deleteGraph(GRAPH_NAME); + } catch (ArangoException e1) { + } + } + + @Test + public void shortestPath() throws ArangoException { + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + + final TestComplexEntity02 e1 = new TestComplexEntity02(1, 2, 3); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), e1, + null); + + final TestComplexEntity02 e2 = new TestComplexEntity02(4, 5, 6); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), e2, + null); + + final TestComplexEntity02 e3 = new TestComplexEntity02(7, 8, 9); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), e3, + null); + + final TestComplexEntity02 e4 = new TestComplexEntity02(10, 11, 12); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex3.getDocumentHandle(), e4, + null); + + final ShortestPathOptions shortestPathOptions = new ShortestPathOptions(); + { + final ShortestPathEntity entity = driver.graphGetShortestPath( + GRAPH_NAME, v1, v2, shortestPathOptions, TestComplexEntity01.class, TestComplexEntity02.class); + Assert.assertEquals(201, entity.getCode()); + Assert.assertEquals(1, entity.getEdges().size()); + Assert.assertEquals(2, entity.getVertices().size()); + Assert.assertEquals(1L, entity.getDistance().longValue()); + } + { + final ShortestPathEntity entity = driver.graphGetShortestPath( + GRAPH_NAME, v1, v4, shortestPathOptions, TestComplexEntity01.class, TestComplexEntity02.class); + Assert.assertEquals(201, entity.getCode()); + Assert.assertEquals(2, entity.getEdges().size()); + Assert.assertEquals(3, entity.getVertices().size()); + Assert.assertEquals(2L, entity.getDistance().longValue()); + } + } + + @Test + public void shortestPathDirectionOut() throws ArangoException { + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + + final TestComplexEntity02 e1 = new TestComplexEntity02(1, 2, 3); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), e1, + null); + + final TestComplexEntity02 e2 = new TestComplexEntity02(4, 5, 6); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), e2, + null); + + final TestComplexEntity02 e3 = new TestComplexEntity02(7, 8, 9); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), e3, + null); + + final TestComplexEntity02 e4 = new TestComplexEntity02(10, 11, 12); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex3.getDocumentHandle(), e4, + null); + + final ShortestPathOptions shortestPathOptions = new ShortestPathOptions(); + shortestPathOptions.setDirection(Direction.OUTBOUND); + { + final ShortestPathEntity entity = driver.graphGetShortestPath( + GRAPH_NAME, v1, v2, shortestPathOptions, TestComplexEntity01.class, TestComplexEntity02.class); + Assert.assertEquals(201, entity.getCode()); + Assert.assertEquals(1, entity.getEdges().size()); + Assert.assertEquals(2, entity.getVertices().size()); + } + { + final ShortestPathEntity entity = driver.graphGetShortestPath( + GRAPH_NAME, v1, v4, shortestPathOptions, TestComplexEntity01.class, TestComplexEntity02.class); + Assert.assertEquals(201, entity.getCode()); + Assert.assertNull(entity.getEdges()); + Assert.assertNull(entity.getVertices()); + } + } + + @Test + public void shortestPathDirectionIn() throws ArangoException { + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + + final TestComplexEntity02 e1 = new TestComplexEntity02(1, 2, 3); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), e1, + null); + + final TestComplexEntity02 e2 = new TestComplexEntity02(4, 5, 6); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), e2, + null); + + final TestComplexEntity02 e3 = new TestComplexEntity02(7, 8, 9); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), e3, + null); + + final TestComplexEntity02 e4 = new TestComplexEntity02(10, 11, 12); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex3.getDocumentHandle(), e4, + null); + + final ShortestPathOptions shortestPathOptions = new ShortestPathOptions(); + shortestPathOptions.setDirection(Direction.INBOUND); + { + final ShortestPathEntity entity = driver.graphGetShortestPath( + GRAPH_NAME, v1, v2, shortestPathOptions, TestComplexEntity01.class, TestComplexEntity02.class); + Assert.assertEquals(201, entity.getCode()); + Assert.assertNull(entity.getEdges()); + Assert.assertNull(entity.getVertices()); + } + { + final ShortestPathEntity entity = driver.graphGetShortestPath( + GRAPH_NAME, v1, v4, shortestPathOptions, TestComplexEntity01.class, TestComplexEntity02.class); + Assert.assertEquals(201, entity.getCode()); + Assert.assertNull(entity.getEdges()); + Assert.assertNull(entity.getVertices()); + } + } + + @Test + public void shortestPathWeigth() throws ArangoException { + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + + int x1 = 1; + final TestComplexEntity02 e1 = new TestComplexEntity02(x1, 2, 3); + EdgeEntity edge1 = driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, + vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), e1, null); + + final TestComplexEntity02 e2 = new TestComplexEntity02(4, 5, 6); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), e2, + null); + + int x3 = 7; + final TestComplexEntity02 e3 = new TestComplexEntity02(x3, 8, 9); + EdgeEntity edge3 = driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, + vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), e3, null); + + final TestComplexEntity02 e4 = new TestComplexEntity02(10, 11, 12); + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex3.getDocumentHandle(), e4, + null); + + final ShortestPathOptions shortestPathOptions = new ShortestPathOptions(); + shortestPathOptions.setWeight("x"); + { + final ShortestPathEntity entity = driver.graphGetShortestPath( + GRAPH_NAME, v1, v4, shortestPathOptions, TestComplexEntity01.class, TestComplexEntity02.class); + Assert.assertEquals(201, entity.getCode()); + Assert.assertEquals(2, entity.getEdges().size()); + Assert.assertEquals(3, entity.getVertices().size()); + Assert.assertEquals(x1 + x3, entity.getDistance().longValue()); + for (EdgeEntity edge : entity.getEdges()) { + Assert.assertTrue(edge.getDocumentHandle().equals(edge1.getDocumentHandle()) + || edge.getDocumentHandle().equals(edge3.getDocumentHandle())); + } + } + } +} diff --git a/src/test/java/com/arangodb/ArangoTestSuite.java b/src/test/java/com/arangodb/ArangoTestSuite.java index 5b66c19c2..7371e1004 100644 --- a/src/test/java/com/arangodb/ArangoTestSuite.java +++ b/src/test/java/com/arangodb/ArangoTestSuite.java @@ -101,6 +101,10 @@ ArangoDriverGraphEdgeReplaceTest.class, + ArangoDriverGraphEdgeUpdateTest.class, + + ArangoDriverGraphShortestPathTest.class, + ArangoDriverTransactionTest.class, ArangoDriverThreadSafeTest.class, From 9c3324b7aa49543b6168b8249e2471c766d71c4b Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 10 Jun 2016 08:40:07 +0200 Subject: [PATCH 34/56] correct readme (driver.deleteUser) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c3e7d4bb..d03121446 100644 --- a/README.md +++ b/README.md @@ -293,7 +293,7 @@ If you are using [authentication] (http://docs.arangodb.com/ConfigureArango/Auth ##DELETE user ``` Java - arangoDriver.createUser("myUser"); + arangoDriver.deleteUser("myUser"); ``` From cb298bf34fe8dfbbc23d6ab86cc498fe97c744c7 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 10 Jun 2016 11:01:37 +0200 Subject: [PATCH 35/56] fixed docu warnings --- src/main/java/com/arangodb/ArangoDriver.java | 16 +++++----------- .../java/com/arangodb/entity/QueryEntity.java | 2 +- .../com/arangodb/util/GraphEdgesOptions.java | 3 ++- .../com/arangodb/util/ShortestPathOptions.java | 3 ++- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 19afdd83f..272cf650f 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -947,8 +947,6 @@ public DocumentEntity createDocument(final String collectionName, final T * the desired document key * @param value * An object containing the documents attributes - * @param createCollection - * if set to true the collection is created if it does not exist * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -975,8 +973,6 @@ public DocumentEntity createDocument( * the desired document key * @param value * An object containing the documents attributes - * @param createCollection - * if set to true the collection is created if it does not exist * @param waitForSync * if set to true the response is returned when the server has * finished. @@ -2936,7 +2932,7 @@ public UserEntity getUser(final String username) throws ArangoException { * @param username * the username as string * @param database - * @return + * @return a DefaultEntity object * @throws ArangoException */ public DefaultEntity grantDatabaseAccess(String username, String database) throws ArangoException { @@ -4688,7 +4684,7 @@ public QueriesResultEntity getSlowQueries(final String database) throws ArangoEx /** * Clears the list of slow AQL queries of the default database * - * @return + * @return a DefaultEntity object * @throws ArangoException */ public DefaultEntity deleteSlowQueries() throws ArangoException { @@ -4700,7 +4696,7 @@ public DefaultEntity deleteSlowQueries() throws ArangoException { * * @param database * the database name or null - * @return + * @return a DefaultEntity object * @throws ArangoException */ public DefaultEntity deleteSlowQueries(final String database) throws ArangoException { @@ -4712,7 +4708,7 @@ public DefaultEntity deleteSlowQueries(final String database) throws ArangoExcep * * @param id * the identifier of a query - * @return + * @return a DefaultEntity object * @throws ArangoException */ public DefaultEntity killQuery(final String id) throws ArangoException { @@ -4726,7 +4722,7 @@ public DefaultEntity killQuery(final String id) throws ArangoException { * the identifier of a query * @param database * the database name or null - * @return + * @return a DefaultEntity object * @throws ArangoException */ public DefaultEntity killQuery(final String database, final String id) throws ArangoException { @@ -4749,8 +4745,6 @@ public HttpManager getHttpManager() { * The name of the collection * @param rawJsonString * A string containing a JSON object - * @param createCollection - * if set to true the collection is created if it does not exist * @param waitForSync * if set to true the response is returned when the server has * finished. diff --git a/src/main/java/com/arangodb/entity/QueryEntity.java b/src/main/java/com/arangodb/entity/QueryEntity.java index e32fab48e..689f815d8 100644 --- a/src/main/java/com/arangodb/entity/QueryEntity.java +++ b/src/main/java/com/arangodb/entity/QueryEntity.java @@ -46,7 +46,7 @@ public void setId(String id) { /** * Returns the query string (potentially truncated) * - * @return + * @return the query string */ public String getQuery() { return query; diff --git a/src/main/java/com/arangodb/util/GraphEdgesOptions.java b/src/main/java/com/arangodb/util/GraphEdgesOptions.java index 659dc773d..a03b54c23 100644 --- a/src/main/java/com/arangodb/util/GraphEdgesOptions.java +++ b/src/main/java/com/arangodb/util/GraphEdgesOptions.java @@ -205,7 +205,8 @@ public GraphEdgesOptions setLimit(Integer limit) { /** * Get include data * - * @return + * @return returns true, if the return values are compatible with older + * versions of AnrangoDB */ public Boolean getIncludeData() { return includeData; diff --git a/src/main/java/com/arangodb/util/ShortestPathOptions.java b/src/main/java/com/arangodb/util/ShortestPathOptions.java index 360c935bc..c5936e2e2 100644 --- a/src/main/java/com/arangodb/util/ShortestPathOptions.java +++ b/src/main/java/com/arangodb/util/ShortestPathOptions.java @@ -151,7 +151,8 @@ public ShortestPathOptions setDefaultWeight(Long defaultWeight) { /** * Get include data * - * @return + * @return returns true, if the return values are compatible with older + * versions of AnrangoDB */ public Boolean getIncludeData() { return includeData; From 8ae09b9555022a034fc968603a588927f692f284 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 10 Jun 2016 14:06:39 +0200 Subject: [PATCH 36/56] Result in TransactionResultEntity can only be JsonObject, Number, String or boolean --- .../arangodb/entity/TransactionResultEntity.java | 15 ++++++++++++--- .../com/arangodb/ArangoDriverTransactionTest.java | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/arangodb/entity/TransactionResultEntity.java b/src/main/java/com/arangodb/entity/TransactionResultEntity.java index 72d93fd53..550f3dd15 100644 --- a/src/main/java/com/arangodb/entity/TransactionResultEntity.java +++ b/src/main/java/com/arangodb/entity/TransactionResultEntity.java @@ -16,6 +16,8 @@ package com.arangodb.entity; +import com.google.gson.JsonObject; + /** * @author tamtam180 - kirscheless at gmail.com * @author gschwab @@ -28,9 +30,8 @@ public class TransactionResultEntity extends BaseEntity { */ private Object result; - @SuppressWarnings("unchecked") - public T getResult() { - return (T) this.result; + public JsonObject getResultAsJsonObject() { + return (JsonObject) result; } public long getResultAsLong() { @@ -58,6 +59,14 @@ public int getResultAsInt() { return number.intValue(); } + public boolean getResultAsBoolean() { + return (Boolean) result; + } + + public String getResultAsString() { + return (String) result; + } + public void setResult(Object result) { this.result = result; } diff --git a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java index a88ab0745..457ed2e80 100644 --- a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java @@ -122,7 +122,7 @@ public void test_Transaction() throws ArangoException { transaction.setParams(true); result = driver.executeTransaction(transaction); - assertThat(result. getResult(), is(true)); + assertThat(result.getResultAsBoolean(), is(true)); assertThat(result.getStatusCode(), is(200)); assertThat(result.getCode(), is(200)); assertThat(result.isError(), is(false)); @@ -130,7 +130,7 @@ public void test_Transaction() throws ArangoException { transaction.setParams("Hans"); result = driver.executeTransaction(transaction); - assertThat(result. getResult(), is("Hans")); + assertThat(result.getResultAsString(), is("Hans")); assertThat(result.getStatusCode(), is(200)); assertThat(result.getCode(), is(200)); assertThat(result.isError(), is(false)); From 4d0d4a7a7641a1cc11c93069abeb697cc3c6554d Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 10 Jun 2016 14:10:21 +0200 Subject: [PATCH 37/56] Replace graph_edge function with aql --- .../com/arangodb/util/GraphQueryUtil.java | 13 +++++++ .../ArangoDriverGraphEdgesGetCursorTest.java | 34 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/main/java/com/arangodb/util/GraphQueryUtil.java b/src/main/java/com/arangodb/util/GraphQueryUtil.java index 115d280d1..dde6a35b2 100644 --- a/src/main/java/com/arangodb/util/GraphQueryUtil.java +++ b/src/main/java/com/arangodb/util/GraphQueryUtil.java @@ -57,6 +57,19 @@ public static String createEdgeQuery( appendEdgeCollectionsOrGraph(graphName, bindVars, sb, edgeCollectionRestriction); appendFilter("e", graphEdgesOptions.getEdgeExamples(), sb); appendFilter("v", graphEdgesOptions.getNeighborExamples(), sb); + { + final List endVertexCollectionRestriction = graphEdgesOptions.getEndVertexCollectionRestriction(); + if (endVertexCollectionRestriction != null && endVertexCollectionRestriction.size() > 0) { + sb.append(" FILTER "); + for (String endVertexCollection : endVertexCollectionRestriction) { + sb.append("IS_SAME_COLLECTION(`"); + sb.append(endVertexCollection); + sb.append("`,v)"); + sb.append(OR); + } + sb.delete(sb.length() - OR.length(), sb.length() - 1); + } + } final Integer limit = graphEdgesOptions.getLimit(); if (limit != null) { sb.append(" LIMIT "); diff --git a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java index 8a2837b28..7a97fd887 100644 --- a/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverGraphEdgesGetCursorTest.java @@ -410,6 +410,40 @@ public void graphGetEdgeCursorByExampleStartVertexRestriction() throws ArangoExc assertThat(cursor.getCount(), is(2)); } + @Test + public void graphGetEdgeCursorByExampleEndVertexRestriction() throws ArangoException { + final TestComplexEntity01 v1 = new TestComplexEntity01("Homer", "A Simpson", 38); + final TestComplexEntity01 v2 = new TestComplexEntity01("Marge", "A Simpson", 36); + final TestComplexEntity01 v3 = new TestComplexEntity01("Bart", "A Simpson", 10); + final TestComplexEntity01 v4 = new TestComplexEntity01("Remoh", "Homer's twin", 38); + + final VertexEntity vertex1 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v1, true); + + final VertexEntity vertex2 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v2, true); + + final VertexEntity vertex3 = driver.graphCreateVertex(GRAPH_NAME, "to1-1", v3, true); + + final VertexEntity vertex4 = driver.graphCreateVertex(GRAPH_NAME, "from1-1", v4, true); + + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex2.getDocumentHandle(), + new TestComplexEntity02(1, 2, 3), null); + + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex1.getDocumentHandle(), vertex3.getDocumentHandle(), + new TestComplexEntity02(4, 5, 6), null); + + driver.graphCreateEdge(GRAPH_NAME, "edge-1", null, vertex4.getDocumentHandle(), vertex2.getDocumentHandle(), + new TestComplexEntity02(7, 8, 9), null); + + GraphEdgesOptions graphEdgesOptions = new GraphEdgesOptions(); + List endVertexCollectionRestriction = new ArrayList(); + endVertexCollectionRestriction.add("to1-1"); + graphEdgesOptions.setEndVertexCollectionRestriction(endVertexCollectionRestriction); + + EdgeCursor cursor = driver.graphGetEdgeCursor(GRAPH_NAME, TestComplexEntity02.class, + new TestComplexEntity01(null, "A Simpson", null), graphEdgesOptions, getAqlQueryOptions(true, 10, true)); + assertThat(cursor.getCount(), is(2)); + } + @Test public void shortestPathTest() throws ArangoException { From b029b515e87a0e76031a37c6f3e26037beed696a Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 10 Jun 2016 15:00:55 +0200 Subject: [PATCH 38/56] QueryCacheProperties Mode in enum --- .../java/com/arangodb/entity/EntityDeserializers.java | 4 +++- .../arangodb/entity/QueryCachePropertiesEntity.java | 10 +++++++--- .../com/arangodb/ArangoDriverDocumentCursorTest.java | 3 ++- .../java/com/arangodb/ArangoDriverQueryCacheTest.java | 11 +++++------ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/arangodb/entity/EntityDeserializers.java b/src/main/java/com/arangodb/entity/EntityDeserializers.java index 568f684a6..f7c5e4c3c 100644 --- a/src/main/java/com/arangodb/entity/EntityDeserializers.java +++ b/src/main/java/com/arangodb/entity/EntityDeserializers.java @@ -37,6 +37,7 @@ import org.slf4j.LoggerFactory; import com.arangodb.entity.CollectionEntity.Figures; +import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; import com.arangodb.entity.ReplicationApplierState.LastError; import com.arangodb.entity.ReplicationApplierState.Progress; import com.arangodb.entity.ReplicationInventoryEntity.Collection; @@ -2302,7 +2303,8 @@ public QueryCachePropertiesEntity deserialize( final QueryCachePropertiesEntity entity = deserializeBaseParameter(obj, new QueryCachePropertiesEntity()); if (obj.has("mode")) { - entity.setMode(obj.getAsJsonPrimitive("mode").getAsString()); + final String modeAsString = obj.getAsJsonPrimitive("mode").getAsString(); + entity.setMode(CacheMode.valueOf(modeAsString)); } if (obj.has("maxResults")) { diff --git a/src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java b/src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java index 7cc7bf0c9..614b52da4 100644 --- a/src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java +++ b/src/main/java/com/arangodb/entity/QueryCachePropertiesEntity.java @@ -21,11 +21,15 @@ */ public class QueryCachePropertiesEntity extends BaseEntity { + public enum CacheMode { + off, on, demand; + } + /** * The mode the AQL query cache operates in. The mode is one of the * following values: "off", "on" or "demand". */ - private String mode; + private CacheMode mode; /** * The maximum number of query results that will be stored per @@ -41,7 +45,7 @@ public QueryCachePropertiesEntity() { * * @return The mode is one of the following values: "off", "on" or "demand". */ - public String getMode() { + public CacheMode getMode() { return mode; } @@ -52,7 +56,7 @@ public String getMode() { * The mode is one of the following values: "off", "on" or * "demand". */ - public void setMode(String mode) { + public void setMode(CacheMode mode) { this.mode = mode; } diff --git a/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java b/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java index 11ca37fbd..3b7911e9e 100644 --- a/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java +++ b/src/test/java/com/arangodb/ArangoDriverDocumentCursorTest.java @@ -30,6 +30,7 @@ import com.arangodb.entity.DocumentEntity; import com.arangodb.entity.QueryCachePropertiesEntity; +import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; import com.arangodb.util.AqlQueryOptions; import com.arangodb.util.MapBuilder; import com.arangodb.util.TestUtils; @@ -154,7 +155,7 @@ public void test_withCache() throws ArangoException { if (isMinimumVersion(TestUtils.VERSION_2_7)) { // start caching final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity(); - properties.setMode("on"); + properties.setMode(CacheMode.on); driver.setQueryCacheProperties(properties); final String query = "FOR t IN unit_test_query_test FILTER t.age >= @age SORT t.age RETURN t"; diff --git a/src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java b/src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java index c2603b237..54de07958 100644 --- a/src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java +++ b/src/test/java/com/arangodb/ArangoDriverQueryCacheTest.java @@ -23,6 +23,7 @@ import com.arangodb.entity.DefaultEntity; import com.arangodb.entity.QueryCachePropertiesEntity; +import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; import com.arangodb.util.TestUtils; /** @@ -53,25 +54,23 @@ public void test_getQueryCacheProperties() throws ArangoException { @Test public void test_setQueryCacheProperties() throws ArangoException { - final String on = "on"; - final String off = "off"; if (isMinimumVersion(TestUtils.VERSION_2_7)) { final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity(); - properties.setMode(on); + properties.setMode(CacheMode.on); properties.setMaxResults(100L); QueryCachePropertiesEntity ret = driver.setQueryCacheProperties(properties); assertEquals(200, ret.getStatusCode()); - assertEquals(on, ret.getMode()); + assertEquals(CacheMode.on, ret.getMode()); assertEquals(new Long(100L), ret.getMaxResults()); - properties.setMode(off); + properties.setMode(CacheMode.off); properties.setMaxResults(200L); ret = driver.setQueryCacheProperties(properties); assertEquals(200, ret.getStatusCode()); - assertEquals(off, ret.getMode()); + assertEquals(CacheMode.off, ret.getMode()); assertEquals(new Long(200L), ret.getMaxResults()); } } From 4f7cfcefa8804c4ba2a9c5909f78feadbf37d5c4 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 13 Jun 2016 16:13:35 +0200 Subject: [PATCH 39/56] Transaction: add attribute allowImplicit --- .../arangodb/entity/TransactionEntity.java | 23 +++++++++- .../arangodb/ArangoDriverTransactionTest.java | 44 +++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/arangodb/entity/TransactionEntity.java b/src/main/java/com/arangodb/entity/TransactionEntity.java index 16a438979..a5d62b5dd 100644 --- a/src/main/java/com/arangodb/entity/TransactionEntity.java +++ b/src/main/java/com/arangodb/entity/TransactionEntity.java @@ -27,9 +27,19 @@ public class TransactionEntity extends BaseEntity { public static class ReadWriteCollections { - List read = new ArrayList(); + private List read = new ArrayList(); - List write = new ArrayList(); + private List write = new ArrayList(); + + private boolean allowImplicit = true; + + public boolean isAllowImplicit() { + return allowImplicit; + } + + public void setAllowImplicit(boolean allowImplicit) { + this.allowImplicit = allowImplicit; + } } ReadWriteCollections collections = new ReadWriteCollections(); @@ -62,6 +72,15 @@ public void addWriteCollection(String collection) { this.collections.write.add(collection); } + /** + * @param allowImplicit + * allows(true)/ disallows(false) read access to other + * collections than specified. Default is true. + */ + public void setAllowImplicit(final boolean allowImplicit) { + collections.setAllowImplicit(allowImplicit); + } + public String getAction() { return action; } diff --git a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java index 457ed2e80..3979a73de 100644 --- a/src/test/java/com/arangodb/ArangoDriverTransactionTest.java +++ b/src/test/java/com/arangodb/ArangoDriverTransactionTest.java @@ -20,9 +20,11 @@ import static org.junit.Assert.assertThat; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import com.arangodb.entity.BaseEntity; import com.arangodb.entity.TransactionEntity; import com.arangodb.entity.TransactionResultEntity; @@ -33,6 +35,7 @@ public class ArangoDriverTransactionTest extends BaseTest { private static final String SOME_COLLECTION = "someCollection"; + private static final String SOME_OTHER_COLLECTION = "someOtherCollection"; public class ParamObject { private String a = "a"; @@ -77,6 +80,16 @@ public void setup() throws ArangoException { driver.createCollection(SOME_COLLECTION); } catch (final ArangoException e) { + } + try { + driver.deleteCollection(SOME_OTHER_COLLECTION); + } catch (final ArangoException e) { + + } + try { + driver.createCollection(SOME_OTHER_COLLECTION); + } catch (final ArangoException e) { + } } @@ -86,6 +99,11 @@ public void teardown() throws ArangoException { driver.deleteCollection(SOME_COLLECTION); } catch (final ArangoException e) { + } + try { + driver.deleteCollection(SOME_OTHER_COLLECTION); + } catch (final ArangoException e) { + } } @@ -137,4 +155,30 @@ public void test_Transaction() throws ArangoException { } + @Test + public void allowImplicit() throws ArangoException { + TransactionEntity transaction = driver + .createTransaction("function (params) {" + "var db = require('internal').db;" + + "return {'a':db.someCollection.all().toArray()[0], 'b':db.someOtherCollection.all().toArray()[0]};" + + "}"); + transaction.addReadCollection(SOME_COLLECTION); + { + TransactionResultEntity result = driver.executeTransaction(transaction); + assertThat(result.getStatusCode(), is(200)); + assertThat(result.getCode(), is(200)); + assertThat(result.isError(), is(false)); + } + { + transaction.setAllowImplicit(false); + try { + driver.executeTransaction(transaction); + Assert.fail(); + } catch (ArangoException e) { + final BaseEntity result = e.getEntity(); + assertThat(result.getStatusCode(), is(400)); + assertThat(result.getCode(), is(400)); + assertThat(result.isError(), is(true)); + } + } + } } From 9928107f34c096251fe847117b370dbf29bb18ce Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 13 Jun 2016 16:54:52 +0200 Subject: [PATCH 40/56] changelog --- ChangeLog | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 67d67e90f..4c582d8ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,13 @@ -v3.0.0 (2016-XX-XX) +v3.0.0 (2016-06-15) --------------------------- * removed ArangoDriver.EdgeEntity() (/_api/edge withdrawn in Server) * removed CAP-Index (Cap-constraints are withdrawn in Server) +* removed Param database in User-Methods (in 3.0 users are managed in _users Collection in _system Database only) +* added User-Method grantDatabaseAccess(username, database) +* replaced Graph-Functions (graph_edge, graph_vertices, graph_shortes_path) with AQL +* removed deprecated Methods +* added Transaction attribute allowImplicit +* refactored QueryCachePropertiesEntity, TransactionResultEntity v2.7.4 (2016-04-15) --------------------------- From 4c929695efe1e0c2794440bdd7f1ee79df3e9e51 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 14 Jun 2016 10:14:36 +0200 Subject: [PATCH 41/56] restore createEdge() method --- src/main/java/com/arangodb/ArangoDriver.java | 58 +++++++++++++++++++ .../com/arangodb/InternalDocumentDriver.java | 11 ++++ .../arangodb/entity/EntityDeserializers.java | 7 ++- .../arangodb/impl/BaseArangoDriverImpl.java | 1 + .../impl/InternalDocumentDriverImpl.java | 39 ++++++++++++- .../impl/InternalGraphDriverImpl.java | 37 ++---------- .../impl/InternalImportDriverImpl.java | 4 +- .../impl/InternalIndexDriverImpl.java | 1 - .../impl/InternalReplicationDriverImpl.java | 4 +- .../impl/InternalSimpleDriverImpl.java | 1 - .../java/com/arangodb/util/EdgeUtils.java | 45 ++++++++++++++ .../com/arangodb/ArangoDriverEdgeTest.java | 38 +++++++++++- 12 files changed, 203 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/arangodb/util/EdgeUtils.java diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 19afdd83f..2df32c875 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -4564,6 +4564,64 @@ public TransactionResultEntity executeTransaction(final TransactionEntity transa return this.transactionDriver.executeTransaction(getDefaultDatabase(), transactionEntity); } + /** + * Create an edge in an edge collection. + * + * @param collectionName + * name of the edge collection + * @param value + * the edge object + * @param fromHandle + * id of document 'from' + * @param toHandle + * id of document 'to' + * @param waitForSync + * wait for sync + * @return the new created EdgeEntity object + * @throws ArangoException + */ + public EdgeEntity createEdge( + final String collectionName, + final T value, + final String fromHandle, + final String toHandle, + final Boolean waitForSync) throws ArangoException { + + return createEdge(collectionName, null, value, fromHandle, toHandle, waitForSync); + } + + /** + * Create an edge in an edge collection. This method allows to define to + * documents key. Note that the collection's property + * CollectionKeyOption.allowUserKeys has to be set accordingly. + * + * @param collectionName + * name of the edge collection + * @param documentKey + * the desired document key + * @param value + * the edge object + * @param fromHandle + * id of document 'from' + * @param toHandle + * id of document 'to' + * @param waitForSync + * wait for sync + * @return the new created EdgeEntity object + * @throws ArangoException + */ + public EdgeEntity createEdge( + final String collectionName, + final String documentKey, + final T value, + final String fromHandle, + final String toHandle, + final Boolean waitForSync) throws ArangoException { + + return documentDriver.createEdge(getDefaultDatabase(), collectionName, documentKey, value, fromHandle, toHandle, + waitForSync); + } + /** * Do a graph traversal. * diff --git a/src/main/java/com/arangodb/InternalDocumentDriver.java b/src/main/java/com/arangodb/InternalDocumentDriver.java index 76f959512..32885135b 100644 --- a/src/main/java/com/arangodb/InternalDocumentDriver.java +++ b/src/main/java/com/arangodb/InternalDocumentDriver.java @@ -3,6 +3,7 @@ import java.util.List; import com.arangodb.entity.DocumentEntity; +import com.arangodb.entity.EdgeEntity; import com.arangodb.impl.BaseDriverInterface; /** @@ -67,4 +68,14 @@ String getDocumentRaw(String database, String documentHandle, Long ifNoneMatchRe throws ArangoException; DocumentEntity deleteDocument(String database, String documentHandle, Long rev) throws ArangoException; + + EdgeEntity createEdge( + String database, + String collectionName, + String documentKey, + T value, + String fromHandle, + String toHandle, + Boolean waitForSync) throws ArangoException; + } diff --git a/src/main/java/com/arangodb/entity/EntityDeserializers.java b/src/main/java/com/arangodb/entity/EntityDeserializers.java index f7c5e4c3c..e48af9df6 100644 --- a/src/main/java/com/arangodb/entity/EntityDeserializers.java +++ b/src/main/java/com/arangodb/entity/EntityDeserializers.java @@ -1959,6 +1959,9 @@ public ReplicationLoggerStateEntity.Client deserialize( } public static class GraphEntityDeserializer implements JsonDeserializer { + + private static final String COLLECTION = "collection"; + @Override public GraphEntity deserialize( final JsonElement json, @@ -2008,8 +2011,8 @@ private void addEdgeDefinitions(final GraphEntity entity, final JsonArray edgeDe for (int i = 0, imax = edgeDefinitions.size(); i < imax; i++) { final EdgeDefinitionEntity edgeDefinitionEntity = new EdgeDefinitionEntity(); final JsonObject edgeDefinition = edgeDefinitions.get(i).getAsJsonObject(); - if (edgeDefinition.has("collection")) { - edgeDefinitionEntity.setCollection(edgeDefinition.get("collection").getAsString()); + if (edgeDefinition.has(COLLECTION)) { + edgeDefinitionEntity.setCollection(edgeDefinition.get(COLLECTION).getAsString()); } if (edgeDefinition.has("from")) { final List from = new ArrayList(); diff --git a/src/main/java/com/arangodb/impl/BaseArangoDriverImpl.java b/src/main/java/com/arangodb/impl/BaseArangoDriverImpl.java index c55eafcc3..beaca5cc2 100644 --- a/src/main/java/com/arangodb/impl/BaseArangoDriverImpl.java +++ b/src/main/java/com/arangodb/impl/BaseArangoDriverImpl.java @@ -26,6 +26,7 @@ */ class BaseArangoDriverImpl extends BaseArangoDriver implements BaseDriverInterface { + protected static final String COLLECTION = "collection"; protected ArangoConfigure configure; protected HttpManager httpManager; protected AnnotationHandler annotationHandler; diff --git a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java index 16745a767..58af75d51 100644 --- a/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalDocumentDriverImpl.java @@ -25,11 +25,14 @@ import com.arangodb.entity.CursorEntity; import com.arangodb.entity.DefaultEntity; import com.arangodb.entity.DocumentEntity; +import com.arangodb.entity.EdgeEntity; import com.arangodb.entity.EntityFactory; import com.arangodb.http.HttpManager; import com.arangodb.http.HttpResponseEntity; +import com.arangodb.util.EdgeUtils; import com.arangodb.util.MapBuilder; import com.google.gson.JsonElement; +import com.google.gson.JsonObject; /** * @author tamtam180 - kirscheless at gmail.com @@ -67,7 +70,7 @@ private DocumentEntity internalCreateDocument( } final HttpResponseEntity res = httpManager.doPost(createDocumentEndpointUrl(database), - new MapBuilder().put("collection", collectionName).put(WAIT_FOR_SYNC, waitForSync).get(), body); + new MapBuilder().put(COLLECTION, collectionName).put(WAIT_FOR_SYNC, waitForSync).get(), body); @SuppressWarnings("unchecked") final DocumentEntity result = createEntity(res, DocumentEntity.class); @@ -183,7 +186,7 @@ public DocumentEntity updateDocumentRaw( @Override public List getDocuments(final String database, final String collectionName) throws ArangoException { final HttpResponseEntity res = httpManager.doPut(createEndpointUrl(database, "/_api/simple/all-keys"), null, - EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).put("type", "id").get())); + EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).put("type", "id").get())); @SuppressWarnings("unchecked") final CursorEntity tmp = createEntity(res, CursorEntity.class, String.class); @@ -264,4 +267,36 @@ private Map createRevisionCheckHeader(final Long rev) { } return header; } + + @Override + public EdgeEntity createEdge( + String database, + String collectionName, + String documentKey, + T value, + String fromHandle, + String toHandle, + Boolean waitForSync) throws ArangoException { + + validateCollectionName(collectionName); + + JsonObject obj = EdgeUtils.valueToEdgeJsonObject(documentKey, fromHandle, toHandle, value); + + final HttpResponseEntity res = httpManager.doPost(createDocumentEndpointUrl(database), + new MapBuilder().put(COLLECTION, collectionName).put(WAIT_FOR_SYNC, waitForSync).get(), + EntityFactory.toJsonString(obj)); + + @SuppressWarnings("unchecked") + final EdgeEntity entity = createEntity(res, EdgeEntity.class); + + if (value != null) { + entity.setEntity(value); + annotationHandler.updateDocumentAttributes(value, entity.getDocumentRevision(), entity.getDocumentHandle(), + entity.getDocumentKey()); + } + + entity.setFromVertexHandle(fromHandle); + entity.setToVertexHandle(toHandle); + return entity; + } } diff --git a/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java b/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java index d2449ef1d..06c0a93dd 100644 --- a/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalGraphDriverImpl.java @@ -34,6 +34,7 @@ import com.arangodb.http.HttpManager; import com.arangodb.http.HttpResponseEntity; import com.arangodb.util.CollectionUtils; +import com.arangodb.util.EdgeUtils; import com.arangodb.util.MapBuilder; import com.arangodb.util.StringUtils; import com.google.gson.JsonElement; @@ -218,7 +219,7 @@ public GraphEntity createVertexCollection( final HttpResponseEntity res = httpManager.doPost( createGharialEndpointUrl(databaseName, StringUtils.encodeUrl(graphName), VERTEX), null, - EntityFactory.toJsonString(new MapBuilder().put("collection", collectionName).get())); + EntityFactory.toJsonString(new MapBuilder().put(COLLECTION, collectionName).get())); if (wrongResult(res)) { throw new ArangoException(UNKNOWN_ERROR); @@ -534,7 +535,7 @@ public EdgeEntity createEdge( final T value, final Boolean waitForSync) throws ArangoException { - final JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); + final JsonObject obj = EdgeUtils.valueToEdgeJsonObject(key, fromHandle, toHandle, value); validateCollectionName(graphName); final HttpResponseEntity res = httpManager.doPost( @@ -554,34 +555,6 @@ public EdgeEntity createEdge( return entity; } - private JsonObject valueToEdgeJsonObject( - final String key, - final String fromHandle, - final String toHandle, - final T value) { - JsonObject obj; - if (value == null) { - obj = new JsonObject(); - } else { - final JsonElement elem = EntityFactory.toJsonElement(value, false); - if (elem.isJsonObject()) { - obj = elem.getAsJsonObject(); - } else { - throw new IllegalArgumentException("value need object type(not support array, primitive, etc..)."); - } - } - if (key != null) { - obj.addProperty("_key", key); - } - if (fromHandle != null) { - obj.addProperty("_from", fromHandle); - } - if (toHandle != null) { - obj.addProperty("_to", toHandle); - } - return obj; - } - @SuppressWarnings("unchecked") @Override public EdgeEntity getEdge( @@ -638,7 +611,7 @@ public EdgeEntity replaceEdge( final Long ifMatchRevision, final Long ifNoneMatchRevision) throws ArangoException { - final JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); + final JsonObject obj = EdgeUtils.valueToEdgeJsonObject(key, fromHandle, toHandle, value); validateCollectionName(graphName); final HttpResponseEntity res = httpManager.doPut( @@ -678,7 +651,7 @@ public EdgeEntity updateEdge( final Long ifMatchRevision, final Long ifNoneMatchRevision) throws ArangoException { - final JsonObject obj = valueToEdgeJsonObject(key, fromHandle, toHandle, value); + final JsonObject obj = EdgeUtils.valueToEdgeJsonObject(key, fromHandle, toHandle, value); validateCollectionName(graphName); final HttpResponseEntity res = httpManager.doPatch( diff --git a/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java b/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java index 41e1a24d4..dd48c744a 100644 --- a/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java @@ -43,7 +43,7 @@ public ImportResultEntity importDocuments(String database, String collection, Co throws ArangoException { HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), - new MapBuilder().put("collection", collection).put("type", "array").get(), + new MapBuilder().put(COLLECTION, collection).put("type", "array").get(), EntityFactory.toJsonString(values)); return createEntity(res, ImportResultEntity.class); @@ -57,7 +57,7 @@ public ImportResultEntity importDocumentsByHeaderValues( Collection> headerValues) throws ArangoException { HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), - new MapBuilder().put("collection", collection).get(), EntityFactory.toImportHeaderValues(headerValues)); + new MapBuilder().put(COLLECTION, collection).get(), EntityFactory.toImportHeaderValues(headerValues)); return createEntity(res, ImportResultEntity.class); diff --git a/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java b/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java index c82b1cc0c..1e4601dce 100644 --- a/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalIndexDriverImpl.java @@ -39,7 +39,6 @@ public class InternalIndexDriverImpl extends BaseArangoDriverWithCursorImpl private static final String SPARSE = "sparse"; private static final String UNIQUE = "unique"; private static final String TYPE = "type"; - private static final String COLLECTION = "collection"; InternalIndexDriverImpl(ArangoConfigure configure, HttpManager httpManager) { super(configure, null, httpManager); diff --git a/src/main/java/com/arangodb/impl/InternalReplicationDriverImpl.java b/src/main/java/com/arangodb/impl/InternalReplicationDriverImpl.java index 41bf19814..344620046 100644 --- a/src/main/java/com/arangodb/impl/InternalReplicationDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalReplicationDriverImpl.java @@ -77,8 +77,8 @@ public void getReplicationDump( DumpHandler handler) throws ArangoException { HttpResponseEntity res = httpManager.doGet(createEndpointUrl(database, "/_api/replication/dump"), - new MapBuilder().put("collection", collectionName).put("from", from).put("to", to) - .put("chunkSize", chunkSize).put("ticks", ticks).get()); + new MapBuilder().put(COLLECTION, collectionName).put("from", from).put("to", to).put("chunkSize", chunkSize) + .put("ticks", ticks).get()); ReplicationDumpHeader header = toReplicationDumpHeader(res); boolean cont = handler.head(header); diff --git a/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java b/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java index 05402b7e2..a55c23ad0 100644 --- a/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalSimpleDriverImpl.java @@ -42,7 +42,6 @@ public class InternalSimpleDriverImpl extends BaseArangoDriverWithCursorImpl private static final String WAIT_FOR_SYNC = "waitForSync"; private static final String LIMIT = "limit"; private static final String EXAMPLE = "example"; - private static final String COLLECTION = "collection"; InternalSimpleDriverImpl(final ArangoConfigure configure, final InternalCursorDriver cursorDriver, final HttpManager httpManager) { diff --git a/src/main/java/com/arangodb/util/EdgeUtils.java b/src/main/java/com/arangodb/util/EdgeUtils.java new file mode 100644 index 000000000..13e820d94 --- /dev/null +++ b/src/main/java/com/arangodb/util/EdgeUtils.java @@ -0,0 +1,45 @@ +package com.arangodb.util; + +import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.EntityFactory; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +/** + * @author Mark - mark@arangodb.com + * + */ +public class EdgeUtils { + + private EdgeUtils() { + super(); + } + + public static JsonObject valueToEdgeJsonObject( + final String key, + final String fromHandle, + final String toHandle, + final T value) { + JsonObject obj; + if (value == null) { + obj = new JsonObject(); + } else { + final JsonElement elem = EntityFactory.toJsonElement(value, false); + if (elem.isJsonObject()) { + obj = elem.getAsJsonObject(); + } else { + throw new IllegalArgumentException("value need object type(not support array, primitive, etc..)."); + } + } + if (key != null) { + obj.addProperty(BaseDocument.KEY, key); + } + if (fromHandle != null) { + obj.addProperty(BaseDocument.FROM, fromHandle); + } + if (toHandle != null) { + obj.addProperty(BaseDocument.TO, toHandle); + } + return obj; + } +} diff --git a/src/test/java/com/arangodb/ArangoDriverEdgeTest.java b/src/test/java/com/arangodb/ArangoDriverEdgeTest.java index 5cc963699..1c232049c 100644 --- a/src/test/java/com/arangodb/ArangoDriverEdgeTest.java +++ b/src/test/java/com/arangodb/ArangoDriverEdgeTest.java @@ -9,6 +9,7 @@ import com.arangodb.entity.CollectionOptions; import com.arangodb.entity.CollectionType; import com.arangodb.entity.DocumentEntity; +import com.arangodb.entity.EdgeEntity; /** * @author Mark - mark@arangodb.com @@ -54,7 +55,7 @@ public void after() throws ArangoException { } @Test - public void test_create_normal() throws ArangoException { + public void test_createDocument() throws ArangoException { final TestComplexEntity01 value = new TestComplexEntity01("user", "desc", 42); final DocumentEntity fromDoc = driver.createDocument(collectionName2, value, true); @@ -74,4 +75,39 @@ public void test_create_normal() throws ArangoException { } + @Test + public void test_createEdge() throws ArangoException { + + TestComplexEntity01 value = new TestComplexEntity01("user", "desc", 42); + DocumentEntity fromDoc = driver.createDocument(collectionName2, value, true); + DocumentEntity toDoc = driver.createDocument(collectionName2, value, true); + + EdgeEntity doc = driver.createEdge(collectionName, value, fromDoc.getDocumentHandle(), + toDoc.getDocumentHandle(), true); + + Assert.assertNotNull(doc.getDocumentKey()); + Assert.assertEquals(collectionName + "/" + doc.getDocumentKey(), doc.getDocumentHandle()); + Assert.assertNotEquals(0L, doc.getDocumentRevision()); + Assert.assertEquals(fromDoc.getDocumentHandle(), doc.getFromVertexHandle()); + Assert.assertEquals(toDoc.getDocumentHandle(), doc.getToVertexHandle()); + } + + @Test + public void test_createEdgeWithKey() throws ArangoException { + + final TestComplexEntity01 value = new TestComplexEntity01("user", "desc", 42); + final DocumentEntity fromDoc = driver.createDocument(collectionName2, value, true); + final DocumentEntity toDoc = driver.createDocument(collectionName2, value, true); + + final String documentKey = ArangoDriverEdgeTest.class.getSimpleName() + "_test_createEdgeWithKey"; + EdgeEntity doc = driver.createEdge(collectionName, documentKey, value, + fromDoc.getDocumentHandle(), toDoc.getDocumentHandle(), true); + + Assert.assertNotNull(doc.getDocumentKey()); + Assert.assertEquals(collectionName + "/" + documentKey, doc.getDocumentHandle()); + Assert.assertNotEquals(0L, doc.getDocumentRevision()); + Assert.assertEquals(fromDoc.getDocumentHandle(), doc.getFromVertexHandle()); + Assert.assertEquals(toDoc.getDocumentHandle(), doc.getToVertexHandle()); + } + } \ No newline at end of file From f2db9aeba683c668fc91bac543e270f409b71777 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 16 Jun 2016 16:12:57 +0200 Subject: [PATCH 42/56] fixed changelog --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 4c582d8ef..ef9416751 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -v3.0.0 (2016-06-15) +v3.0.0 (2016-06-17) --------------------------- * removed ArangoDriver.EdgeEntity() (/_api/edge withdrawn in Server) * removed CAP-Index (Cap-constraints are withdrawn in Server) From cf7606d56757b7fca5071acd6eb65184a3a988e5 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jun 2016 10:52:28 +0200 Subject: [PATCH 43/56] fixed getter in AqlQueryOptions --- src/main/java/com/arangodb/util/AqlQueryOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/arangodb/util/AqlQueryOptions.java b/src/main/java/com/arangodb/util/AqlQueryOptions.java index 9d0a2fec2..71a959701 100644 --- a/src/main/java/com/arangodb/util/AqlQueryOptions.java +++ b/src/main/java/com/arangodb/util/AqlQueryOptions.java @@ -134,7 +134,7 @@ public AqlQueryOptions setTtl(Integer ttl) { * @return boolean flag */ public Boolean getCache() { - return fullCount; + return cache; } /** From 562e85516e98ffc45dc95310b17d837bdadabd41 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jun 2016 10:52:40 +0200 Subject: [PATCH 44/56] added cache performance test --- .../com/arangodb/ArangoDriverCacheTest.java | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 src/test/java/com/arangodb/ArangoDriverCacheTest.java diff --git a/src/test/java/com/arangodb/ArangoDriverCacheTest.java b/src/test/java/com/arangodb/ArangoDriverCacheTest.java new file mode 100644 index 000000000..f6462718f --- /dev/null +++ b/src/test/java/com/arangodb/ArangoDriverCacheTest.java @@ -0,0 +1,133 @@ +package com.arangodb; + +import java.util.Map; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import com.arangodb.entity.QueryCachePropertiesEntity; +import com.arangodb.entity.QueryCachePropertiesEntity.CacheMode; +import com.arangodb.util.AqlQueryOptions; +import com.arangodb.util.MapBuilder; + +/** + * @author Mark - mark@arangodb.com + * + */ +@Ignore +public class ArangoDriverCacheTest { + + private static final String COLLECTION_NAME = "unitTestCollection"; + private static final String DATABASE_NAME = "unitTestDatabase"; + private static ArangoConfigure configure; + private static ArangoDriver driver; + + @BeforeClass + public static void setup() throws ArangoException { + + configure = new ArangoConfigure(); + configure.init(); + driver = new ArangoDriver(configure); + + // create test database + try { + driver.createDatabase(DATABASE_NAME); + } catch (ArangoException e) { + } + driver.setDefaultDatabase(DATABASE_NAME); + + // create test collection + try { + driver.createCollection(COLLECTION_NAME); + } catch (final ArangoException e) { + } + driver.truncateCollection(COLLECTION_NAME); + + // create some test data + for (int i = 0; i < 1000000; i++) { + final TestEntity value = new TestEntity("user_" + (i % 10), "desc" + (i % 10), i); + driver.createDocument(COLLECTION_NAME, value, null); + } + + } + + @AfterClass + public static void shutdown() { + try { + driver.deleteDatabase(DATABASE_NAME); + } catch (final ArangoException e) { + } + configure.shutdown(); + } + + private AqlQueryOptions createAqlQueryOptions( + final Boolean count, + final Integer batchSize, + final Boolean fullCount, + final Boolean cache) { + return new AqlQueryOptions().setCount(count).setBatchSize(batchSize).setFullCount(fullCount).setCache(cache); + } + + @Test + public void test_withoutCache() throws ArangoException { + // set cache mode off + final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity(); + properties.setMode(CacheMode.off); + driver.setQueryCacheProperties(properties); + + final AqlQueryOptions aqlQueryOptions = createAqlQueryOptions(true, 1000, null, false); + + exceuteQuery(aqlQueryOptions); + } + + @Test + public void test_withCache() throws ArangoException { + // set cache mode on + final QueryCachePropertiesEntity properties = new QueryCachePropertiesEntity(); + properties.setMode(CacheMode.on); + driver.setQueryCacheProperties(properties); + + // set caching to true for the query + final AqlQueryOptions aqlQueryOptions = createAqlQueryOptions(true, 1000, null, true); + + exceuteQuery(aqlQueryOptions); + } + + private void exceuteQuery(AqlQueryOptions aqlQueryOptions) throws ArangoException { + + final String query = "FOR t IN " + COLLECTION_NAME + " FILTER t.age >= @age SORT t.age RETURN t"; + final Map bindVars = new MapBuilder().put("age", 90).get(); + + DocumentCursor rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, TestEntity.class); + // first time, the query isn't cached + Assert.assertEquals(false, rs.isCached()); + + final long start = System.currentTimeMillis(); + + // query the cached value + rs = driver.executeDocumentQuery(query, bindVars, aqlQueryOptions, TestEntity.class); + Assert.assertEquals(aqlQueryOptions.getCache(), rs.isCached()); + + // load all results + rs.asEntityList(); + + final long time = System.currentTimeMillis() - start; + System.out.println(time); + } + + private static class TestEntity { + private String user; + private String desc; + private Integer age; + + public TestEntity(String user, String desc, Integer age) { + super(); + this.user = user; + this.desc = desc; + this.age = age; + } + } +} From 5751d6821b59cf59dbdd7428fd4e6916e2816fda Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jun 2016 10:57:24 +0200 Subject: [PATCH 45/56] set graph methodes to deprecated (support will be end soon) --- src/main/java/com/arangodb/ArangoDriver.java | 8 ++++++++ .../java/com/arangodb/impl/InternalCursorDriverImpl.java | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 2df32c875..7fa2ad3b3 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -4369,6 +4369,7 @@ public VertexCursor executeVertexQuery( /** * Returns an EdgeCursor by a given vertex example and some options * + * @deprecated use AQL instead * @param graphName * The name of the graph. * @param clazz @@ -4381,6 +4382,7 @@ public VertexCursor executeVertexQuery( * @return EdgeCursor * @throws ArangoException */ + @Deprecated @SuppressWarnings("unchecked") public EdgeCursor graphGetEdgeCursor( final String graphName, @@ -4415,6 +4417,7 @@ public EdgeCursor graphGetEdgeCursor( /** * Returns a VertexCursor by a given vertex example and some options * + * @deprecated use AQL instead * @param graphName * The name of the graph. * @param clazz @@ -4427,6 +4430,7 @@ public EdgeCursor graphGetEdgeCursor( * @return VertexCursor * @throws ArangoException */ + @Deprecated public VertexCursor graphGetVertexCursor( final String graphName, final Class clazz, @@ -4481,6 +4485,10 @@ public EdgeCursor graphGetEdgeCursorByExample( return graphGetEdgeCursor(graphName, clazz, vertexExample, new GraphEdgesOptions(), null); } + /** + * @deprecated use AQL instead + */ + @Deprecated public ShortestPathEntity graphGetShortestPath( final String graphName, final Object startVertexExample, diff --git a/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java b/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java index 068f0dcab..7ee5e12e8 100644 --- a/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalCursorDriverImpl.java @@ -163,6 +163,10 @@ public CursorRawResult executeAqlQueryRaw( return new CursorRawResult(database, this, entity); } + /** + * @deprecated use AQL instead + */ + @Deprecated @SuppressWarnings("unchecked") @Override public ShortestPathEntity getShortestPath( From c36b5d49f1b7387a5e4e88a8ccdf71b53b306f7a Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jun 2016 12:26:10 +0200 Subject: [PATCH 46/56] extend ImportResultEntity --- src/main/java/com/arangodb/ArangoClient.java | 3 + .../arangodb/entity/EntityDeserializers.java | 34 ++++++-- .../arangodb/entity/ImportResultEntity.java | 86 ++++++++++++++----- 3 files changed, 94 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoClient.java b/src/main/java/com/arangodb/ArangoClient.java index 664d56743..4735c98e2 100644 --- a/src/main/java/com/arangodb/ArangoClient.java +++ b/src/main/java/com/arangodb/ArangoClient.java @@ -42,6 +42,9 @@ private void importDocumentsImpl(String collectionName, List values, Imp total.setCreated(total.getCreated() + result.getCreated()); total.setErrors(total.getErrors() + result.getErrors()); total.setEmpty(total.getEmpty() + result.getEmpty()); + total.setUpdated(total.getUpdated() + result.getUpdated()); + total.setIgnored(total.getIgnored() + result.getIgnored()); + total.getDetails().addAll(result.getDetails()); } public ImportResultEntity importRawJsonDocuments(String collectionName, Iterator itr, int bufferCount) diff --git a/src/main/java/com/arangodb/entity/EntityDeserializers.java b/src/main/java/com/arangodb/entity/EntityDeserializers.java index e48af9df6..8fa07e68c 100644 --- a/src/main/java/com/arangodb/entity/EntityDeserializers.java +++ b/src/main/java/com/arangodb/entity/EntityDeserializers.java @@ -170,6 +170,12 @@ public class EntityDeserializers { private static final String MESSAGE = "message"; + private static final String CREATED = "created"; + private static final String ERRORS = "errors"; + private static final String EMPTY = "empty"; + private static final String IGNORED = "ignored"; + private static final String DETAILS = "details"; + private static Logger logger = LoggerFactory.getLogger(EntityDeserializers.class); private static class ClassHolder { @@ -1308,6 +1314,7 @@ public UserEntity deserialize( } public static class ImportResultEntityDeserializer implements JsonDeserializer { + @Override public ImportResultEntity deserialize( final JsonElement json, @@ -1321,16 +1328,31 @@ public ImportResultEntity deserialize( final JsonObject obj = json.getAsJsonObject(); final ImportResultEntity entity = deserializeBaseParameter(obj, new ImportResultEntity()); - if (obj.has("created")) { - entity.created = obj.getAsJsonPrimitive("created").getAsInt(); + if (obj.has(CREATED)) { + entity.setCreated(obj.getAsJsonPrimitive(CREATED).getAsInt()); + } + + if (obj.has(ERRORS)) { + entity.setErrors(obj.getAsJsonPrimitive(ERRORS).getAsInt()); + } + + if (obj.has(EMPTY)) { + entity.setEmpty(obj.getAsJsonPrimitive(EMPTY).getAsInt()); } - if (obj.has("errors")) { - entity.errors = obj.getAsJsonPrimitive("errors").getAsInt(); + if (obj.has(UPDATED)) { + entity.setUpdated(obj.getAsJsonPrimitive(UPDATED).getAsInt()); } - if (obj.has("empty")) { - entity.empty = obj.getAsJsonPrimitive("empty").getAsInt(); + if (obj.has(IGNORED)) { + entity.setIgnored(obj.getAsJsonPrimitive(IGNORED).getAsInt()); + } + + if (obj.has(DETAILS)) { + final JsonArray asJsonArray = obj.getAsJsonArray(DETAILS); + for (JsonElement jsonElement : asJsonArray) { + entity.getDetails().add(jsonElement.getAsString()); + } } return entity; diff --git a/src/main/java/com/arangodb/entity/ImportResultEntity.java b/src/main/java/com/arangodb/entity/ImportResultEntity.java index 33081c6ee..dad369886 100644 --- a/src/main/java/com/arangodb/entity/ImportResultEntity.java +++ b/src/main/java/com/arangodb/entity/ImportResultEntity.java @@ -16,33 +16,73 @@ package com.arangodb.entity; +import java.util.ArrayList; +import java.util.List; + /** * @author tamtam180 - kirscheless at gmail.com * */ public class ImportResultEntity extends BaseEntity { - int created; - int errors; - int empty; - - public int getCreated() { - return created; - } - public int getErrors() { - return errors; - } - public int getEmpty() { - return empty; - } - public void setCreated(int created) { - this.created = created; - } - public void setErrors(int errors) { - this.errors = errors; - } - public void setEmpty(int empty) { - this.empty = empty; - } - + private int created; + private int errors; + private int empty; + private int updated; + private int ignored; + private List details; + + public ImportResultEntity() { + super(); + details = new ArrayList(); + } + + public int getCreated() { + return created; + } + + public void setCreated(int created) { + this.created = created; + } + + public int getErrors() { + return errors; + } + + public void setErrors(int errors) { + this.errors = errors; + } + + public int getEmpty() { + return empty; + } + + public void setEmpty(int empty) { + this.empty = empty; + } + + public int getUpdated() { + return updated; + } + + public void setUpdated(int updated) { + this.updated = updated; + } + + public int getIgnored() { + return ignored; + } + + public void setIgnored(int ignored) { + this.ignored = ignored; + } + + public List getDetails() { + return details; + } + + public void setDetails(List details) { + this.details = details; + } + } From 741211ecfed13d912e453f7affcce271c707700e Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 17 Jun 2016 12:49:33 +0200 Subject: [PATCH 47/56] new options --- .../java/com/arangodb/util/ImportOptions.java | 187 ++++++++++++++++++ .../com/arangodb/util/ImportOptionsRaw.java | 66 +++++++ 2 files changed, 253 insertions(+) create mode 100644 src/main/java/com/arangodb/util/ImportOptions.java create mode 100644 src/main/java/com/arangodb/util/ImportOptionsRaw.java diff --git a/src/main/java/com/arangodb/util/ImportOptions.java b/src/main/java/com/arangodb/util/ImportOptions.java new file mode 100644 index 000000000..45bdf6ba9 --- /dev/null +++ b/src/main/java/com/arangodb/util/ImportOptions.java @@ -0,0 +1,187 @@ +package com.arangodb.util; + +import java.util.Map; + +import com.arangodb.entity.CollectionType; + +public class ImportOptions implements OptionsInterface { + + public enum OnDuplicate { + ERROR, UPDATE, REPLACE, IGNORE + } + + private Boolean createCollection; + private CollectionType createCollectionType; + private Boolean overwrite; + private Boolean waitForSync; + private OnDuplicate onDuplicate; + + /** + * (optional) If this parameter has a value of true or yes, then the + * collection is created if it does not yet exist. Other values will be + * ignored so the collection must be present for the operation to succeed. + * + * @return this ImportOptions object + */ + public Boolean getCreateCollection() { + return createCollection; + } + + /** + * (optional) If this parameter has a value of true or yes, then the + * collection is created if it does not yet exist. Other values will be + * ignored so the collection must be present for the operation to succeed. + * + * @param createCollection + * @return this ImportOptions object + */ + public ImportOptions setCreateCollection(Boolean createCollection) { + this.createCollection = createCollection; + return this; + } + + /** + * createCollectionType (optional): If this parameter has a value of + * document or edge, it will determine the type of collection that is going + * to be created when the createCollection option is set to true. The + * default value is document. + * + * @return + */ + public CollectionType getCreateCollectionType() { + return createCollectionType; + } + + /** + * createCollectionType (optional): If this parameter has a value of + * document or edge, it will determine the type of collection that is going + * to be created when the createCollection option is set to true. The + * default value is document. + * + * @param createCollectionType + * @return this ImportOptions object + */ + public ImportOptions setCreateCollectionType(CollectionType createCollectionType) { + this.createCollectionType = createCollectionType; + return this; + } + + /** + * overwrite (optional): If this parameter has a value of true or yes, then + * all data in the collection will be removed prior to the import. Note that + * any existing index definitions will be preseved. + * + * @return + */ + public Boolean getOverwrite() { + return overwrite; + } + + /** + * overwrite (optional): If this parameter has a value of true or yes, then + * all data in the collection will be removed prior to the import. Note that + * any existing index definitions will be preseved. + * + * + * @param overwrite + * @return this ImportOptions object + */ + public ImportOptions setOverwrite(Boolean overwrite) { + this.overwrite = overwrite; + return this; + } + + /** + * (optional) Wait until documents have been synced to disk before + * returning. + * + * @return + */ + public Boolean getWaitForSync() { + return waitForSync; + } + + /** + * (optional) Wait until documents have been synced to disk before + * returning. + * + * @param waitForSync + * @return this ImportOptions object + */ + public ImportOptions setWaitForSync(Boolean waitForSync) { + this.waitForSync = waitForSync; + return this; + } + + /** + * (optional) Controls what action is carried out in case of a unique key + * constraint violation. Possible values are: + * + * OnDuplicate.ERROR: this will not import the current document because of + * the unique key constraint violation. This is the default setting. + * + * OnDuplicate.UPDATE: this will update an existing document in the database + * with the data specified in the request. Attributes of the existing + * document that are not present in the request will be preseved. + * + * OnDuplicate.REPLACE: this will replace an existing document in the + * database with the data specified in the request. + * + * OnDuplicate.IGNORE: this will not update an existing document and simply + * ignore the error caused by the unique key constraint violation. + * + * @return + */ + public OnDuplicate getOnDuplicate() { + return onDuplicate; + } + + /** + * (optional) Controls what action is carried out in case of a unique key + * constraint violation. Possible values are: + * + * OnDuplicate.ERROR: this will not import the current document because of + * the unique key constraint violation. This is the default setting. + * + * OnDuplicate.UPDATE: this will update an existing document in the database + * with the data specified in the request. Attributes of the existing + * document that are not present in the request will be preseved. + * + * OnDuplicate.REPLACE: this will replace an existing document in the + * database with the data specified in the request. + * + * OnDuplicate.IGNORE: this will not update an existing document and simply + * ignore the error caused by the unique key constraint violation. + * + * @param onDuplicate + * @return this ImportOptions object + */ + public ImportOptions setOnDuplicate(OnDuplicate onDuplicate) { + this.onDuplicate = onDuplicate; + return this; + } + + @Override + public Map toMap() { + MapBuilder mp = new MapBuilder(); + + if (createCollection != null) { + mp.put("createCollection", createCollection); + } + if (createCollectionType != null) { + mp.put("createCollectionType", createCollectionType.toString().toLowerCase()); + } + if (overwrite != null) { + mp.put("overwrite", overwrite); + } + if (waitForSync != null) { + mp.put("waitForSync", waitForSync); + } + if (onDuplicate != null) { + mp.put("onDuplicate", onDuplicate.toString().toLowerCase()); + } + + return mp.get(); + } + +} diff --git a/src/main/java/com/arangodb/util/ImportOptionsRaw.java b/src/main/java/com/arangodb/util/ImportOptionsRaw.java new file mode 100644 index 000000000..d780b24d7 --- /dev/null +++ b/src/main/java/com/arangodb/util/ImportOptionsRaw.java @@ -0,0 +1,66 @@ +package com.arangodb.util; + +import java.util.Map; + +public class ImportOptionsRaw extends ImportOptions { + + public enum ImportType { + DOCUMENTS, LIST, AUTO + } + + private ImportType importType; + + /** + * Determines how the body of the request will be interpreted. type can have + * the following values: + * + * ImportType.DOCUMENTS: when this type is used, each line in the request + * body is expected to be an individual JSON-encoded document. Multiple JSON + * objects in the request body need to be separated by newlines. + * + * ImportType.LIST: when this type is used, the request body must contain a + * single JSON-encoded array of individual objects to import. + * + * ImportType.AUTO: if set, this will automatically determine the body type + * (either documents or list). + * + * @return + */ + public ImportType getImportType() { + return importType; + } + + /** + * Determines how the body of the request will be interpreted. type can have + * the following values: + * + * ImportType.DOCUMENTS: when this type is used, each line in the request + * body is expected to be an individual JSON-encoded document. Multiple JSON + * objects in the request body need to be separated by newlines. + * + * ImportType.LIST: when this type is used, the request body must contain a + * single JSON-encoded array of individual objects to import. + * + * ImportType.AUTO: if set, this will automatically determine the body type + * (either documents or list). + * + * @param importType + * @return + */ + public ImportOptionsRaw setImportType(ImportType importType) { + this.importType = importType; + return this; + } + + @Override + public Map toMap() { + Map map = super.toMap(); + + if (importType != null) { + map.put("type", importType.toString().toLowerCase()); + } + + return map; + } + +} From 6b7a49163c14c2b700a830288fed19fc092c34b3 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 17 Jun 2016 12:50:30 +0200 Subject: [PATCH 48/56] added import options and raw import --- src/main/java/com/arangodb/ArangoDriver.java | 44 ++++++++++++++++++- .../com/arangodb/InternalImportDriver.java | 14 +++++- .../impl/InternalImportDriverImpl.java | 38 +++++++++++++--- 3 files changed, 88 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 8cb518a9b..3fbfca8c7 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -81,6 +81,8 @@ import com.arangodb.util.GraphEdgesOptions; import com.arangodb.util.GraphQueryUtil; import com.arangodb.util.GraphVerticesOptions; +import com.arangodb.util.ImportOptions; +import com.arangodb.util.ImportOptionsRaw; import com.arangodb.util.MapBuilder; import com.arangodb.util.ShortestPathOptions; import com.arangodb.util.TraversalQueryOptions; @@ -2964,7 +2966,7 @@ public List getUsers() throws ArangoException { } /** - * Creates documents in the collection. + * Creates documents in a collection. * * @param collection * the collection as a string @@ -2975,7 +2977,45 @@ public List getUsers() throws ArangoException { */ public ImportResultEntity importDocuments(final String collection, final Collection values) throws ArangoException { - return importDriver.importDocuments(getDefaultDatabase(), collection, values); + return importDriver.importDocuments(getDefaultDatabase(), collection, values, new ImportOptions()); + } + + /** + * Creates documents in a collection. + * + * @param collection + * the collection as a string + * @param values + * a list of Objects that will be stored as documents + * @param importOptions + * options for importing documents + * @return ImportResultEntity + * @throws ArangoException + */ + public ImportResultEntity importDocuments( + final String collection, + final Collection values, + final ImportOptions importOptions) throws ArangoException { + return importDriver.importDocuments(getDefaultDatabase(), collection, values, importOptions); + } + + /** + * Creates documents in a collection. + * + * @param collection + * the collection as a string + * @param values + * a raw string containing JSON data + * @param importOptions + * options for importing documents + * @return ImportResultEntity + * @throws ArangoException + */ + public ImportResultEntity importDocumentsRaw( + final String collection, + final String values, + final ImportOptionsRaw importOptionsRaw) throws ArangoException { + return importDriver.importDocumentsRaw(getDefaultDatabase(), collection, values, importOptionsRaw); } /** diff --git a/src/main/java/com/arangodb/InternalImportDriver.java b/src/main/java/com/arangodb/InternalImportDriver.java index ab773307d..27cacb665 100644 --- a/src/main/java/com/arangodb/InternalImportDriver.java +++ b/src/main/java/com/arangodb/InternalImportDriver.java @@ -4,13 +4,25 @@ import com.arangodb.entity.ImportResultEntity; import com.arangodb.impl.BaseDriverInterface; +import com.arangodb.util.ImportOptions; +import com.arangodb.util.ImportOptionsRaw; /** * Created by fbartels on 10/27/14. */ public interface InternalImportDriver extends BaseDriverInterface { - ImportResultEntity importDocuments(String database, String collection, Collection values) throws ArangoException; + ImportResultEntity importDocuments( + String database, + String collection, + Collection values, + ImportOptions importOptions) throws ArangoException; + + ImportResultEntity importDocumentsRaw( + String database, + String collection, + String values, + ImportOptionsRaw importOptionsRaw) throws ArangoException; ImportResultEntity importDocumentsByHeaderValues( String database, diff --git a/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java b/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java index dd48c744a..a19c97d8c 100644 --- a/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java @@ -17,6 +17,7 @@ package com.arangodb.impl; import java.util.Collection; +import java.util.Map; import com.arangodb.ArangoConfigure; import com.arangodb.ArangoException; @@ -24,6 +25,8 @@ import com.arangodb.entity.ImportResultEntity; import com.arangodb.http.HttpManager; import com.arangodb.http.HttpResponseEntity; +import com.arangodb.util.ImportOptions; +import com.arangodb.util.ImportOptionsRaw; import com.arangodb.util.MapBuilder; /** @@ -39,12 +42,37 @@ public class InternalImportDriverImpl extends BaseArangoDriverImpl implements co } @Override - public ImportResultEntity importDocuments(String database, String collection, Collection values) - throws ArangoException { + public ImportResultEntity importDocuments( + String database, + String collection, + Collection values, + ImportOptions importOptions) throws ArangoException { - HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), - new MapBuilder().put(COLLECTION, collection).put("type", "array").get(), - EntityFactory.toJsonString(values)); + Map map = importOptions.toMap(); + map.put("type", "list"); + + return importDocumentsInternal(database, collection, EntityFactory.toJsonString(values), map); + } + + @Override + public ImportResultEntity importDocumentsRaw( + String database, + String collection, + String values, + ImportOptionsRaw importOptionsRaw) throws ArangoException { + + return importDocumentsInternal(database, collection, values, importOptionsRaw.toMap()); + } + + public ImportResultEntity importDocumentsInternal( + String database, + String collection, + String values, + Map importOptions) throws ArangoException { + + importOptions.put(COLLECTION, collection); + + HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), importOptions, values); return createEntity(res, ImportResultEntity.class); From 9d04c7a030fe0318d754d6edfe436c063167324d Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 17 Jun 2016 13:23:36 +0200 Subject: [PATCH 49/56] added new options --- .../com/arangodb/util/ImportOptionsJson.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/main/java/com/arangodb/util/ImportOptionsJson.java diff --git a/src/main/java/com/arangodb/util/ImportOptionsJson.java b/src/main/java/com/arangodb/util/ImportOptionsJson.java new file mode 100644 index 000000000..1d6d46149 --- /dev/null +++ b/src/main/java/com/arangodb/util/ImportOptionsJson.java @@ -0,0 +1,73 @@ +package com.arangodb.util; + +import java.util.Map; + +public class ImportOptionsJson extends ImportOptions { + + private String fromPrefix; + private String toPrefix; + + /** + * An optional prefix for the values in _from attributes. If specified, the + * value is automatically prepended to each _from input value. This allows + * specifying just the keys for _from. + * + * @return prefix for the values in _from attributes + */ + public String getFromPrefix() { + return fromPrefix; + } + + /** + * An optional prefix for the values in _from attributes. If specified, the + * value is automatically prepended to each _from input value. This allows + * specifying just the keys for _from. + * + * @param fromPrefix + * @return this ImportOptionsJson object + */ + public ImportOptionsJson setFromPrefix(String fromPrefix) { + this.fromPrefix = fromPrefix; + return this; + } + + /** + * An optional prefix for the values in _to attributes. If specified, the + * value is automatically prepended to each _to input value. This allows + * specifying just the keys for _to. + * + * @return prefix for the values in _to attributes + */ + public String getToPrefix() { + return toPrefix; + } + + /** + * An optional prefix for the values in _to attributes. If specified, the + * value is automatically prepended to each _to input value. This allows + * specifying just the keys for _to. + * + * @param toPrefix + * @return this ImportOptionsJson object + */ + public ImportOptionsJson setToPrefix(String toPrefix) { + this.toPrefix = toPrefix; + return this; + } + + @Override + public Map toMap() { + Map map = super.toMap(); + + if (fromPrefix != null) { + map.put("fromPrefix", fromPrefix); + } + + if (toPrefix != null) { + map.put("toPrefix", toPrefix); + } + + return map; + } + +} From 7e04b3d8649a7ff5f8fde03f3dfb9a9adcc85917 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 17 Jun 2016 13:24:00 +0200 Subject: [PATCH 50/56] added new options --- src/main/java/com/arangodb/util/ImportOptionsRaw.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/arangodb/util/ImportOptionsRaw.java b/src/main/java/com/arangodb/util/ImportOptionsRaw.java index d780b24d7..4c57a5314 100644 --- a/src/main/java/com/arangodb/util/ImportOptionsRaw.java +++ b/src/main/java/com/arangodb/util/ImportOptionsRaw.java @@ -2,7 +2,7 @@ import java.util.Map; -public class ImportOptionsRaw extends ImportOptions { +public class ImportOptionsRaw extends ImportOptionsJson { public enum ImportType { DOCUMENTS, LIST, AUTO @@ -10,6 +10,10 @@ public enum ImportType { private ImportType importType; + public ImportOptionsRaw(ImportType importType) { + this.importType = importType; + } + /** * Determines how the body of the request will be interpreted. type can have * the following values: From 0f6ec3908da169b60474906cca4851dbcdd1917d Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 17 Jun 2016 13:24:23 +0200 Subject: [PATCH 51/56] added importDocumentsByHeaderValuesRaw --- src/main/java/com/arangodb/ArangoDriver.java | 55 +++++++++++++++++-- .../com/arangodb/InternalImportDriver.java | 11 +++- .../impl/InternalImportDriverImpl.java | 42 ++++++++++---- 3 files changed, 90 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/arangodb/ArangoDriver.java b/src/main/java/com/arangodb/ArangoDriver.java index 4978b92d1..bbaeafd13 100644 --- a/src/main/java/com/arangodb/ArangoDriver.java +++ b/src/main/java/com/arangodb/ArangoDriver.java @@ -82,6 +82,7 @@ import com.arangodb.util.GraphQueryUtil; import com.arangodb.util.GraphVerticesOptions; import com.arangodb.util.ImportOptions; +import com.arangodb.util.ImportOptionsJson; import com.arangodb.util.ImportOptionsRaw; import com.arangodb.util.MapBuilder; import com.arangodb.util.ShortestPathOptions; @@ -2977,7 +2978,7 @@ public List getUsers() throws ArangoException { */ public ImportResultEntity importDocuments(final String collection, final Collection values) throws ArangoException { - return importDriver.importDocuments(getDefaultDatabase(), collection, values, new ImportOptions()); + return importDriver.importDocuments(getDefaultDatabase(), collection, values, new ImportOptionsJson()); } /** @@ -2987,7 +2988,7 @@ public ImportResultEntity importDocuments(final String collection, final Collect * the collection as a string * @param values * a list of Objects that will be stored as documents - * @param importOptions + * @param importOptionsJson * options for importing documents * @return ImportResultEntity * @throws ArangoException @@ -2995,8 +2996,8 @@ public ImportResultEntity importDocuments(final String collection, final Collect public ImportResultEntity importDocuments( final String collection, final Collection values, - final ImportOptions importOptions) throws ArangoException { - return importDriver.importDocuments(getDefaultDatabase(), collection, values, importOptions); + final ImportOptionsJson importOptionsJson) throws ArangoException { + return importDriver.importDocuments(getDefaultDatabase(), collection, values, importOptionsJson); } /** @@ -3019,7 +3020,7 @@ public ImportResultEntity importDocumentsRaw( } /** - * Creates documents in the collection. + * Creates documents in a collection. * * @param collection * the collection as a string @@ -3031,7 +3032,49 @@ public ImportResultEntity importDocumentsRaw( public ImportResultEntity importDocumentsByHeaderValues( final String collection, final Collection> headerValues) throws ArangoException { - return importDriver.importDocumentsByHeaderValues(getDefaultDatabase(), collection, headerValues); + return importDriver.importDocumentsByHeaderValues(getDefaultDatabase(), collection, headerValues, + new ImportOptions()); + } + + /** + * Creates documents in a collection. + * + * @param collection + * the collection as a string + * @param headerValues + * a list of lists that will be stored as documents + * @param importOptions + * options for importing documents + * @return ImportResultEntity + * @throws ArangoException + */ + public ImportResultEntity importDocumentsByHeaderValues( + final String collection, + final Collection> headerValues, + ImportOptions importOptions) throws ArangoException { + return importDriver.importDocumentsByHeaderValues(getDefaultDatabase(), collection, headerValues, + importOptions); + } + + /** + * Creates documents in a collection. + * + * @param collection + * the collection as a string + * @param headerValues + * raw JSON data that contains a list of lists that will be + * stored as documents + * @param importOptions + * options for importing documents + * @return ImportResultEntity + * @throws ArangoException + */ + public ImportResultEntity importDocumentsByHeaderValuesRaw( + final String collection, + String headerValues, + ImportOptions importOptions) throws ArangoException { + return importDriver.importDocumentsByHeaderValuesRaw(getDefaultDatabase(), collection, headerValues, + importOptions); } /** diff --git a/src/main/java/com/arangodb/InternalImportDriver.java b/src/main/java/com/arangodb/InternalImportDriver.java index 27cacb665..8ebeaa23d 100644 --- a/src/main/java/com/arangodb/InternalImportDriver.java +++ b/src/main/java/com/arangodb/InternalImportDriver.java @@ -5,6 +5,7 @@ import com.arangodb.entity.ImportResultEntity; import com.arangodb.impl.BaseDriverInterface; import com.arangodb.util.ImportOptions; +import com.arangodb.util.ImportOptionsJson; import com.arangodb.util.ImportOptionsRaw; /** @@ -16,7 +17,7 @@ ImportResultEntity importDocuments( String database, String collection, Collection values, - ImportOptions importOptions) throws ArangoException; + ImportOptionsJson importOptionsJson) throws ArangoException; ImportResultEntity importDocumentsRaw( String database, @@ -27,6 +28,12 @@ ImportResultEntity importDocumentsRaw( ImportResultEntity importDocumentsByHeaderValues( String database, String collection, - Collection> headerValues) throws ArangoException; + Collection> headerValues, + ImportOptions importOptions) throws ArangoException; + ImportResultEntity importDocumentsByHeaderValuesRaw( + String database, + String collection, + String headerValues, + ImportOptions importOptions) throws ArangoException; } diff --git a/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java b/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java index a19c97d8c..194beeb8c 100644 --- a/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java +++ b/src/main/java/com/arangodb/impl/InternalImportDriverImpl.java @@ -26,8 +26,8 @@ import com.arangodb.http.HttpManager; import com.arangodb.http.HttpResponseEntity; import com.arangodb.util.ImportOptions; +import com.arangodb.util.ImportOptionsJson; import com.arangodb.util.ImportOptionsRaw; -import com.arangodb.util.MapBuilder; /** * @author tamtam180 - kirscheless at gmail.com @@ -46,9 +46,9 @@ public ImportResultEntity importDocuments( String database, String collection, Collection values, - ImportOptions importOptions) throws ArangoException { + ImportOptionsJson importOptionsJson) throws ArangoException { - Map map = importOptions.toMap(); + Map map = importOptionsJson.toMap(); map.put("type", "list"); return importDocumentsInternal(database, collection, EntityFactory.toJsonString(values), map); @@ -64,7 +64,28 @@ public ImportResultEntity importDocumentsRaw( return importDocumentsInternal(database, collection, values, importOptionsRaw.toMap()); } - public ImportResultEntity importDocumentsInternal( + @Override + public ImportResultEntity importDocumentsByHeaderValues( + String database, + String collection, + Collection> headerValues, + ImportOptions importOptions) throws ArangoException { + + return importDocumentsByHeaderValuesInternal(database, collection, + EntityFactory.toImportHeaderValues(headerValues), importOptions); + } + + @Override + public ImportResultEntity importDocumentsByHeaderValuesRaw( + String database, + String collection, + String headerValues, + ImportOptions importOptions) throws ArangoException { + + return importDocumentsByHeaderValuesInternal(database, collection, headerValues, importOptions); + } + + private ImportResultEntity importDocumentsInternal( String database, String collection, String values, @@ -75,17 +96,18 @@ public ImportResultEntity importDocumentsInternal( HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), importOptions, values); return createEntity(res, ImportResultEntity.class); - } - @Override - public ImportResultEntity importDocumentsByHeaderValues( + private ImportResultEntity importDocumentsByHeaderValuesInternal( String database, String collection, - Collection> headerValues) throws ArangoException { + String headerValues, + ImportOptions importOptions) throws ArangoException { + + Map map = importOptions.toMap(); + map.put(COLLECTION, collection); - HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), - new MapBuilder().put(COLLECTION, collection).get(), EntityFactory.toImportHeaderValues(headerValues)); + HttpResponseEntity res = httpManager.doPost(createEndpointUrl(database, "/_api/import"), map, headerValues); return createEntity(res, ImportResultEntity.class); From 9c278802786d385d6efa39483c88f1539dc5a120 Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 17 Jun 2016 13:35:59 +0200 Subject: [PATCH 52/56] removed createCollection --- .../java/com/arangodb/util/ImportOptions.java | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/src/main/java/com/arangodb/util/ImportOptions.java b/src/main/java/com/arangodb/util/ImportOptions.java index 45bdf6ba9..aaae45573 100644 --- a/src/main/java/com/arangodb/util/ImportOptions.java +++ b/src/main/java/com/arangodb/util/ImportOptions.java @@ -10,36 +10,11 @@ public enum OnDuplicate { ERROR, UPDATE, REPLACE, IGNORE } - private Boolean createCollection; private CollectionType createCollectionType; private Boolean overwrite; private Boolean waitForSync; private OnDuplicate onDuplicate; - /** - * (optional) If this parameter has a value of true or yes, then the - * collection is created if it does not yet exist. Other values will be - * ignored so the collection must be present for the operation to succeed. - * - * @return this ImportOptions object - */ - public Boolean getCreateCollection() { - return createCollection; - } - - /** - * (optional) If this parameter has a value of true or yes, then the - * collection is created if it does not yet exist. Other values will be - * ignored so the collection must be present for the operation to succeed. - * - * @param createCollection - * @return this ImportOptions object - */ - public ImportOptions setCreateCollection(Boolean createCollection) { - this.createCollection = createCollection; - return this; - } - /** * createCollectionType (optional): If this parameter has a value of * document or edge, it will determine the type of collection that is going From f50d1afc26ccaf2475f1b76fa84aa10560e15d7c Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 17 Jun 2016 13:36:16 +0200 Subject: [PATCH 53/56] removed createCollection --- src/main/java/com/arangodb/util/ImportOptions.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/arangodb/util/ImportOptions.java b/src/main/java/com/arangodb/util/ImportOptions.java index aaae45573..e00d7af53 100644 --- a/src/main/java/com/arangodb/util/ImportOptions.java +++ b/src/main/java/com/arangodb/util/ImportOptions.java @@ -140,9 +140,6 @@ public ImportOptions setOnDuplicate(OnDuplicate onDuplicate) { public Map toMap() { MapBuilder mp = new MapBuilder(); - if (createCollection != null) { - mp.put("createCollection", createCollection); - } if (createCollectionType != null) { mp.put("createCollectionType", createCollectionType.toString().toLowerCase()); } From 50404c7c2b00b9cdc92b132fe315caf107a6dcd1 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jun 2016 13:52:03 +0200 Subject: [PATCH 54/56] importDocument Tests added --- .../com/arangodb/ArangoDriverImportTest.java | 292 ++++++++++++++++-- 1 file changed, 273 insertions(+), 19 deletions(-) diff --git a/src/test/java/com/arangodb/ArangoDriverImportTest.java b/src/test/java/com/arangodb/ArangoDriverImportTest.java index e6b6cf890..af339ad72 100644 --- a/src/test/java/com/arangodb/ArangoDriverImportTest.java +++ b/src/test/java/com/arangodb/ArangoDriverImportTest.java @@ -23,12 +23,23 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.junit.Before; import org.junit.Test; +import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.CollectionOptions; +import com.arangodb.entity.CollectionType; import com.arangodb.entity.ImportResultEntity; +import com.arangodb.util.ImportOptions; +import com.arangodb.util.ImportOptions.OnDuplicate; +import com.arangodb.util.ImportOptionsJson; +import com.arangodb.util.ImportOptionsRaw; +import com.arangodb.util.ImportOptionsRaw.ImportType; import com.arangodb.util.TestUtils; /** @@ -39,6 +50,7 @@ public class ArangoDriverImportTest extends BaseTest { private static final String UT_IMPORT_TEST = "ut-import-test"; + private static final String UT_IMPORT_TEST_EDGE = "ut-import-test-edge"; @Before public void setUp() { @@ -50,6 +62,16 @@ public void setUp() { driver.createCollection(UT_IMPORT_TEST); } catch (final ArangoException e) { } + try { + driver.deleteCollection(UT_IMPORT_TEST_EDGE); + } catch (final ArangoException e) { + } + try { + CollectionOptions options = new CollectionOptions(); + options.setType(CollectionType.EDGE); + driver.createCollection(UT_IMPORT_TEST_EDGE, options); + } catch (final ArangoException e) { + } } @Test @@ -85,6 +107,244 @@ public void test_import_documents_404() throws ArangoException, IOException { } + @Test + public void test_import_xsv_404() throws ArangoException, IOException { + + try { + driver.deleteCollection(UT_IMPORT_TEST); + } catch (final ArangoException e) { + } + + final List> values = new ArrayList>(); + values.add(Arrays.asList("firstName", "lastName", "age", "gender")); + values.add(Arrays.asList("Joe", "Public", 42, "male", 10)); // error + values.add(Arrays.asList("Jane", "Doe", 31, "female")); + + try { + driver.importDocuments(UT_IMPORT_TEST, values); + fail(); + } catch (final ArangoException e) { + assertThat(e.getCode(), is(404)); + assertThat(e.getErrorNumber(), is(1203)); + } + + } + + @Test + public void test_import_updateOnDuplicate() throws ArangoException, IOException { + + Collection docs = new ArrayList(); + for (int i = 0; i < 100; i++) { + BaseDocument doc = new BaseDocument(); + doc.setDocumentKey(String.valueOf(i)); + docs.add(doc); + } + ImportOptionsJson options = new ImportOptionsJson(); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(docs.size())); + } + options.setOnDuplicate(OnDuplicate.UPDATE); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(0)); + assertThat(result.getUpdated(), is(docs.size())); + } + } + + @Test + public void test_import_ignoreOnDuplicate() throws ArangoException, IOException { + + Collection docs = new ArrayList(); + for (int i = 0; i < 100; i++) { + BaseDocument doc = new BaseDocument(); + doc.setDocumentKey(String.valueOf(i)); + docs.add(doc); + } + ImportOptionsJson options = new ImportOptionsJson(); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(docs.size())); + } + options.setOnDuplicate(OnDuplicate.IGNORE); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(0)); + assertThat(result.getIgnored(), is(docs.size())); + } + } + + @Test + public void test_import_replaceOnDuplicate() throws ArangoException, IOException { + + Collection docs = new ArrayList(); + for (int i = 0; i < 100; i++) { + BaseDocument doc = new BaseDocument(); + doc.setDocumentKey(String.valueOf(i)); + docs.add(doc); + } + ImportOptionsJson options = new ImportOptionsJson(); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(docs.size())); + } + options.setOnDuplicate(OnDuplicate.REPLACE); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(0)); + assertThat(result.getUpdated(), is(docs.size())); + } + } + + @Test + public void test_import_errorOnDuplicate() throws ArangoException, IOException { + + Collection docs = new ArrayList(); + for (int i = 0; i < 100; i++) { + BaseDocument doc = new BaseDocument(); + doc.setDocumentKey(String.valueOf(i)); + docs.add(doc); + } + ImportOptionsJson options = new ImportOptionsJson(); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(docs.size())); + } + options.setOnDuplicate(OnDuplicate.ERROR); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(0)); + assertThat(result.getErrors(), is(docs.size())); + } + } + + @Test + public void test_import_overwrite() throws ArangoException, IOException { + ImportOptionsJson options = new ImportOptionsJson(); + { + Collection docs = new ArrayList(); + for (int i = 0; i < 100; i++) { + BaseDocument doc = new BaseDocument(); + doc.setDocumentKey(String.valueOf(i)); + docs.add(doc); + } + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(docs.size())); + assertThat(docs.size(), is(driver.getDocuments(UT_IMPORT_TEST).size())); + } + } + { + Collection docs2 = new ArrayList(); + for (int i = 0; i < 50; i++) { + BaseDocument doc = new BaseDocument(); + doc.setDocumentKey(String.valueOf(-i)); + docs2.add(doc); + } + options.setOverwrite(true); + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs2, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(docs2.size())); + assertThat(docs2.size(), is(driver.getDocuments(UT_IMPORT_TEST).size())); + } + } + } + + @Test + public void test_import_from_to_Prefix() throws ArangoException, IOException { + ImportOptionsJson options = new ImportOptionsJson(); + { + Collection docs = new ArrayList(); + for (int i = 0; i < 100; i++) { + BaseDocument doc = new BaseDocument(); + doc.setDocumentKey(String.valueOf(i)); + docs.add(doc); + } + { + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST, docs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(docs.size())); + } + } + { + Collection> edgeDocs = new ArrayList>(); + for (int i = 0; i < 100; i++) { + final HashMap doc = new HashMap(); + doc.put(BaseDocument.KEY, String.valueOf(i)); + doc.put(BaseDocument.FROM, String.valueOf(i)); + doc.put(BaseDocument.TO, String.valueOf(i)); + edgeDocs.add(doc); + } + options.setFromPrefix(UT_IMPORT_TEST); + options.setToPrefix(UT_IMPORT_TEST); + final ImportResultEntity result = driver.importDocuments(UT_IMPORT_TEST_EDGE, edgeDocs, options); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(edgeDocs.size())); + } + } + + @Test + public void test_import_rawList() throws ArangoException { + String values = "[{\"_key\":\"a\"},{\"_key\":\"b\"}]"; + ImportOptionsRaw importOptionsRaw = new ImportOptionsRaw(ImportType.LIST); + final ImportResultEntity result = driver.importDocumentsRaw(UT_IMPORT_TEST, values, importOptionsRaw); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(2)); + } + + @Test + public void test_import_rawDocuments() throws ArangoException { + String values = "{\"_key\":\"a\"}\n{\"_key\":\"b\"}"; + ImportOptionsRaw importOptionsRaw = new ImportOptionsRaw(ImportType.DOCUMENTS); + final ImportResultEntity result = driver.importDocumentsRaw(UT_IMPORT_TEST, values, importOptionsRaw); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(2)); + } + + @Test + public void test_import_rawAutoList() throws ArangoException { + String values = "[{\"_key\":\"a\"},{\"_key\":\"b\"}]"; + ImportOptionsRaw importOptionsRaw = new ImportOptionsRaw(ImportType.LIST); + final ImportResultEntity result = driver.importDocumentsRaw(UT_IMPORT_TEST, values, importOptionsRaw); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(2)); + } + + @Test + public void test_import_rawAutoDocuments() throws ArangoException { + String values = "{\"_key\":\"a\"}\n{\"_key\":\"b\"}"; + ImportOptionsRaw importOptionsRaw = new ImportOptionsRaw(ImportType.AUTO); + final ImportResultEntity result = driver.importDocumentsRaw(UT_IMPORT_TEST, values, importOptionsRaw); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(2)); + } + @Test public void test_import_xsv() throws ArangoException, IOException { @@ -100,7 +360,9 @@ public void test_import_xsv() throws ArangoException, IOException { assertThat(result.getCreated(), is(2)); assertThat(result.getErrors(), is(0)); assertThat(result.getEmpty(), is(0)); - + assertThat(result.getUpdated(), is(0)); + assertThat(result.getIgnored(), is(0)); + assertThat(result.getDetails().size(), is(0)); } @Test @@ -118,30 +380,22 @@ public void test_import_xsv_errors() throws ArangoException, IOException { assertThat(result.getCreated(), is(1)); assertThat(result.getErrors(), is(1)); assertThat(result.getEmpty(), is(0)); - + assertThat(result.getUpdated(), is(0)); + assertThat(result.getIgnored(), is(0)); + assertThat(result.getDetails().size(), is(0)); } @Test - public void test_import_xsv_404() throws ArangoException, IOException { - - try { - driver.deleteCollection(UT_IMPORT_TEST); - } catch (final ArangoException e) { - } + public void test_import_xsv_raw() throws ArangoException, IOException { - final List> values = new ArrayList>(); - values.add(Arrays.asList("firstName", "lastName", "age", "gender")); - values.add(Arrays.asList("Joe", "Public", 42, "male", 10)); // error - values.add(Arrays.asList("Jane", "Doe", 31, "female")); + final String values = "[\"firstName\",\"lastName\",\"age\",\"gender\"]\n[\"Joe\",\"Public\",42,\"male\"]\n[\"Jane\",\"Doe\",31,\"female\"]"; - try { - driver.importDocuments(UT_IMPORT_TEST, values); - fail(); - } catch (final ArangoException e) { - assertThat(e.getCode(), is(404)); - assertThat(e.getErrorNumber(), is(1203)); - } + final ImportResultEntity result = driver.importDocumentsByHeaderValuesRaw(UT_IMPORT_TEST, values, + new ImportOptions()); + assertThat(result.getStatusCode(), is(201)); + assertThat(result.isError(), is(false)); + assertThat(result.getCreated(), is(2)); } } From 4b7d3c5fdd6ba8288e42a1fe93cd0a8293081bbe Mon Sep 17 00:00:00 2001 From: a-brandt Date: Fri, 17 Jun 2016 13:52:58 +0200 Subject: [PATCH 55/56] added mpv1989 --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 842252030..d7b2240d7 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,11 @@ a-brandt https://github.com/a-brandt + + mpv1989 + Mark + https://github.com/mpv1989 + From 058138b6864d2d031d221d95aa119f8b2c7feaad Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 17 Jun 2016 13:54:16 +0200 Subject: [PATCH 56/56] version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d7b2240d7..7119b3caa 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.arangodb arangodb-java-driver - 3.0.0-SNAPSHOT + 3.0.0 2012 jar
property-keydescriptiondefault value
arangoHostArangoDB host and port 127.0.0.1:8529
fallbackArangoHostfallback ArangoDB host and port