From 68e0d06f2f34ce396d46f19f92821aefc830914f Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Fri, 21 Feb 2020 15:30:21 +0100 Subject: [PATCH 01/16] document:mCreate --- doc/3/controllers/document/m-create/index.md | 61 ++++++++++++++++ .../document/m-create/snippets/m-create.java | 13 ++++ .../m-create/snippets/m-create.test.yml | 10 +++ .../API/Controllers/DocumentController.java | 67 +++++++++++++++++ src/main/java/io/kuzzle/sdk/Kuzzle.java | 5 ++ .../DocumentTest/DocumentTest.java | 73 +++++++++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 doc/3/controllers/document/m-create/index.md create mode 100644 doc/3/controllers/document/m-create/snippets/m-create.java create mode 100644 doc/3/controllers/document/m-create/snippets/m-create.test.yml create mode 100644 src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java create mode 100644 src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java diff --git a/doc/3/controllers/document/m-create/index.md b/doc/3/controllers/document/m-create/index.md new file mode 100644 index 00000000..c5fcc981 --- /dev/null +++ b/doc/3/controllers/document/m-create/index.md @@ -0,0 +1,61 @@ +--- +code: true +type: page +title: mCreate +description: Creates multiple documents +--- + +# create + +Creates multiple documents in the provided index and collection. + +--- + +## Arguments + +```java +public CompletableFuture> mCreate( + final String index, + final String collection, + final ArrayList> documents) +throws NotConnectedException, InternalException + +public CompletableFuture> mCreate( + final String index, + final String collection, + final ArrayList> documents, + final Boolean waitForRefresh) +throws NotConnectedException, InternalException +``` + +| Arguments | Type | Description | +| ------------------ | ------------------------------------------------------- | --------------------------------- | +| `index` |
String
| Index | +| `collection` |
String
| Collection | +| `documents` |
ArrayList>
| ArrayList containing the documents to create | +| `waitForRefresh` |
Boolean
| Optional parameters | + +--- + +### documents + +Each document has the following properties: + +| Arguments | Type | Description | +| ------------------ | -------------------------------------------- | --------------------------------- | +| `_id` |
String
(optional) | Optional document ID. Will be auto-generated if not defined. | +| `body` |
boolean
(optional) | Document body | + +## Return + +A `ConcurrentHashMap` which has the following properties: + +| Property | Type | Description | +|------------- |----------------------------- |--------------------------------- | +| `_source` |
ConcurrentHashMap
| Created document | +| `_id` |
String
| ID of the newly created document | +| `_version` |
Integer
| Version of the document in the persistent data storage | + +## Usage + +<<< ./snippets/m-create.java diff --git a/doc/3/controllers/document/m-create/snippets/m-create.java b/doc/3/controllers/document/m-create/snippets/m-create.java new file mode 100644 index 00000000..c8cfe5ba --- /dev/null +++ b/doc/3/controllers/document/m-create/snippets/m-create.java @@ -0,0 +1,13 @@ + ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + + document1.put("name", "Yoann"); + document2.put("nickname", "El angel de la muerte que hace el JAVA"); + + ArrayList> documents = new ArrayList<>(); + + documents.add(document1); + documents.add(document2); + + kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents) + .get(); diff --git a/doc/3/controllers/document/m-create/snippets/m-create.test.yml b/doc/3/controllers/document/m-create/snippets/m-create.test.yml new file mode 100644 index 00000000..d814cd75 --- /dev/null +++ b/doc/3/controllers/document/m-create/snippets/m-create.test.yml @@ -0,0 +1,10 @@ +name: document#mCreate +description: Creates multiple documents +hooks: + before: | + curl -XDELETE kuzzle:7512/nyc-open-data + curl -XPOST kuzzle:7512/nyc-open-data/_create + curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi + after: +template: default +expected: Success \ No newline at end of file diff --git a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java new file mode 100644 index 00000000..485b338c --- /dev/null +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java @@ -0,0 +1,67 @@ +package io.kuzzle.sdk.API.Controllers; + +import io.kuzzle.sdk.CoreClasses.Maps.KuzzleMap; +import io.kuzzle.sdk.Exceptions.InternalException; +import io.kuzzle.sdk.Exceptions.NotConnectedException; +import io.kuzzle.sdk.Kuzzle; + +import java.util.ArrayList; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; + +public class DocumentController extends BaseController { + public DocumentController(final Kuzzle kuzzle) { + super(kuzzle); + } + + /** + * Creates multiple documents in a given collection and index. + * + * @param index + * @param collection + * @param documents + * @param waitForRefresh + * @return a CompletableFuture + * @throws NotConnectedException + * @throws InternalException + */ + public CompletableFuture> mCreate( + final String index, + final String collection, + final ArrayList> documents, + final Boolean waitForRefresh) throws NotConnectedException, InternalException { + + final KuzzleMap query = new KuzzleMap(); + + query + .put("index", index) + .put("collection", collection) + .put("controller", "document") + .put("action", "mCreate") + .put("body", documents) + .put("waitForRefresh", waitForRefresh); + + return kuzzle + .query(query) + .thenApplyAsync( + (response) -> (ConcurrentHashMap) response.result); + } + + /** + * Creates multiple documents in a given collection and index. + * + * @param index + * @param collection + * @param documents + * @return a CompletableFuture + * @throws NotConnectedException + * @throws InternalException + */ + public CompletableFuture> mCreate( + final String index, + final String collection, + final ArrayList> documents) throws NotConnectedException, InternalException { + + return this.mCreate(index, collection, documents, false); + } +} diff --git a/src/main/java/io/kuzzle/sdk/Kuzzle.java b/src/main/java/io/kuzzle/sdk/Kuzzle.java index 3acb9446..3f20cbca 100644 --- a/src/main/java/io/kuzzle/sdk/Kuzzle.java +++ b/src/main/java/io/kuzzle/sdk/Kuzzle.java @@ -1,5 +1,6 @@ package io.kuzzle.sdk; +import io.kuzzle.sdk.API.Controllers.DocumentController; import io.kuzzle.sdk.CoreClasses.Json.JsonSerializer; import io.kuzzle.sdk.CoreClasses.Maps.KuzzleMap; import io.kuzzle.sdk.API.Controllers.AuthController; @@ -70,6 +71,10 @@ public AuthController getAuthController() { return new AuthController(this); } + public DocumentController getDocumentController() { + return new DocumentController(this); + } + /** * Initialize a new instance of Kuzzle * diff --git a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java new file mode 100644 index 00000000..1cd1ace4 --- /dev/null +++ b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java @@ -0,0 +1,73 @@ +package io.kuzzle.test.API.Controllers.DocumentTest; + +import io.kuzzle.sdk.CoreClasses.Maps.KuzzleMap; +import io.kuzzle.sdk.Exceptions.InternalException; +import io.kuzzle.sdk.Exceptions.NotConnectedException; +import io.kuzzle.sdk.Kuzzle; +import io.kuzzle.sdk.Protocol.AbstractProtocol; +import io.kuzzle.sdk.Protocol.ProtocolState; +import io.kuzzle.sdk.Protocol.WebSocket; + +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.mockito.stubbing.Answer; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.*; + +public class DocumentTest { + + private AbstractProtocol networkProtocol = Mockito.mock(WebSocket.class); + + @Test + public void mCreateDocumentTest() throws NotConnectedException, InternalException { + + Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); + String index = "nyc-open-data"; + String collection = "yellow-taxi"; + + ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + document1.put("name", "Yoann"); + document2.put("nickname", "El angel de la muerte que hace el JAVA"); + ArrayList> documents = new ArrayList<>(); + documents.add(document1); + documents.add(document2); + + ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); + + kuzzleMock.getDocumentController().mCreate(index, collection, documents); + Mockito.verify(kuzzleMock, Mockito.times(1)).query((KuzzleMap) arg.capture()); + + assertEquals(((KuzzleMap) arg.getValue()).getString("controller"), "document"); + assertEquals(((KuzzleMap) arg.getValue()).getString("action"), "mCreate"); + assertEquals(((KuzzleMap) arg.getValue()).getString("index"), "nyc-open-data"); + assertEquals(((ArrayList>)(((KuzzleMap) arg.getValue()).get("body"))).get(0).get("name").toString(), "Yoann"); + assertEquals(((ArrayList>)(((KuzzleMap) arg.getValue()).get("body"))).get(1).get("nickname").toString(), "El angel de la muerte que hace el JAVA"); + } + + @Test(expected = NotConnectedException.class) + public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { + AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); + Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); + + Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); + String index = "nyc-open-data"; + String collection = "yellow-taxi"; + + ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + document1.put("name", "Yoann"); + document2.put("nickname", "El angel de la muerte que hace el JAVA"); + + ArrayList> documents = new ArrayList<>(); + documents.add(document1); + documents.add(document2); + + kuzzleMock.getDocumentController().mCreate(index, collection, documents); + } +} From a92c048fa2d30f274d9b505facceec7ce83a9740 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Fri, 21 Feb 2020 16:58:56 +0100 Subject: [PATCH 02/16] fix and doc --- doc/3/controllers/document/m-create/index.md | 11 ++++- .../document/m-create/snippets/m-create.java | 15 ++++--- .../API/Controllers/DocumentController.java | 4 +- .../DocumentTest/DocumentTest.java | 43 +++++++++++++------ 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/doc/3/controllers/document/m-create/index.md b/doc/3/controllers/document/m-create/index.md index c5fcc981..c8c6d6fb 100644 --- a/doc/3/controllers/document/m-create/index.md +++ b/doc/3/controllers/document/m-create/index.md @@ -48,7 +48,8 @@ Each document has the following properties: ## Return -A `ConcurrentHashMap` which has the following properties: +A `ConcurrentHashMap` which has a `successes` and `errors` array: +Each created document is an object of the `successes` array with the following properties: | Property | Type | Description | |------------- |----------------------------- |--------------------------------- | @@ -56,6 +57,14 @@ A `ConcurrentHashMap` which has the following properties: | `_id` |
String
| ID of the newly created document | | `_version` |
Integer
| Version of the document in the persistent data storage | +Each errored document is an object of the `errors` array with the following properties: + +| Property | Type | Description | +|------------- |----------------------------- |--------------------------------- | +| `document` |
ConcurrentHashMap
| Document that causes the error | +| `status` |
Integer
| HTTP error status | +| `reason` |
String
| Human readable reason | + ## Usage <<< ./snippets/m-create.java diff --git a/doc/3/controllers/document/m-create/snippets/m-create.java b/doc/3/controllers/document/m-create/snippets/m-create.java index c8cfe5ba..aeb0d5a3 100644 --- a/doc/3/controllers/document/m-create/snippets/m-create.java +++ b/doc/3/controllers/document/m-create/snippets/m-create.java @@ -1,13 +1,18 @@ ConcurrentHashMap document1 = new ConcurrentHashMap<>(); ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + ConcurrentHashMap body = new ConcurrentHashMap<>(); - document1.put("name", "Yoann"); - document2.put("nickname", "El angel de la muerte que hace el JAVA"); + document1.put("_id", "some-id1"); + body1.put("key1", "value1"); + document1.put("body", body); - ArrayList> documents = new ArrayList<>(); + document2.put("_id", "some-id2"); + body2.put("key2", "value2"); + document2.put("body", body); + final ArrayList> documents = new ArrayList<>(); documents.add(document1); documents.add(document2); - kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents) - .get(); + kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents) + .get(); diff --git a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java index 485b338c..0abb540b 100644 --- a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java @@ -31,14 +31,14 @@ public CompletableFuture> mCreate( final ArrayList> documents, final Boolean waitForRefresh) throws NotConnectedException, InternalException { - final KuzzleMap query = new KuzzleMap(); + final KuzzleMap query = new KuzzleMap(); query .put("index", index) .put("collection", collection) .put("controller", "document") .put("action", "mCreate") - .put("body", documents) + .put("body", new KuzzleMap().put("documents", documents)) .put("waitForRefresh", waitForRefresh); return kuzzle diff --git a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java index 1cd1ace4..c8da7674 100644 --- a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java +++ b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java @@ -32,22 +32,31 @@ public void mCreateDocumentTest() throws NotConnectedException, InternalExceptio ConcurrentHashMap document1 = new ConcurrentHashMap<>(); ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - document1.put("name", "Yoann"); - document2.put("nickname", "El angel de la muerte que hace el JAVA"); - ArrayList> documents = new ArrayList<>(); + ConcurrentHashMap body1 = new ConcurrentHashMap<>(); + ConcurrentHashMap body2 = new ConcurrentHashMap<>(); + + document1.put("_id", "some-id1"); + body1.put("key1", "value1"); + document1.put("body", body1); + + document2.put("_id", "some-id2"); + body2.put("key2", "value2"); + document2.put("body", body2); + + final ArrayList> documents = new ArrayList<>(); documents.add(document1); documents.add(document2); - ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); + ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); kuzzleMock.getDocumentController().mCreate(index, collection, documents); - Mockito.verify(kuzzleMock, Mockito.times(1)).query((KuzzleMap) arg.capture()); + Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); - assertEquals(((KuzzleMap) arg.getValue()).getString("controller"), "document"); - assertEquals(((KuzzleMap) arg.getValue()).getString("action"), "mCreate"); - assertEquals(((KuzzleMap) arg.getValue()).getString("index"), "nyc-open-data"); - assertEquals(((ArrayList>)(((KuzzleMap) arg.getValue()).get("body"))).get(0).get("name").toString(), "Yoann"); - assertEquals(((ArrayList>)(((KuzzleMap) arg.getValue()).get("body"))).get(1).get("nickname").toString(), "El angel de la muerte que hace el JAVA"); + assertEquals((arg.getValue()).getString("controller"), "document"); + assertEquals((arg.getValue()).getString("action"), "mCreate"); + assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); + assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); + assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); } @Test(expected = NotConnectedException.class) @@ -61,10 +70,18 @@ public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedExce ConcurrentHashMap document1 = new ConcurrentHashMap<>(); ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - document1.put("name", "Yoann"); - document2.put("nickname", "El angel de la muerte que hace el JAVA"); + ConcurrentHashMap body1 = new ConcurrentHashMap<>(); + ConcurrentHashMap body2 = new ConcurrentHashMap<>(); + + document1.put("_id", "some-id1"); + body1.put("key1", "value1"); + document1.put("body", body1); + + document2.put("_id", "some-id2"); + body2.put("key2", "value2"); + document2.put("body", body2); - ArrayList> documents = new ArrayList<>(); + final ArrayList> documents = new ArrayList<>(); documents.add(document1); documents.add(document2); From df916384e2681f37a2b67ad3671716021ecbe87c Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Fri, 21 Feb 2020 17:06:43 +0100 Subject: [PATCH 03/16] doc --- doc/3/controllers/document/m-create/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/3/controllers/document/m-create/index.md b/doc/3/controllers/document/m-create/index.md index c8c6d6fb..377f16e4 100644 --- a/doc/3/controllers/document/m-create/index.md +++ b/doc/3/controllers/document/m-create/index.md @@ -5,7 +5,7 @@ title: mCreate description: Creates multiple documents --- -# create +# mCreate Creates multiple documents in the provided index and collection. @@ -44,7 +44,7 @@ Each document has the following properties: | Arguments | Type | Description | | ------------------ | -------------------------------------------- | --------------------------------- | | `_id` |
String
(optional) | Optional document ID. Will be auto-generated if not defined. | -| `body` |
boolean
(optional) | Document body | +| `body` |
Boolean
(optional) | Document body | ## Return From 1bf539f379ac078669e1d0d7340faff5048e6cdb Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 26 Feb 2020 16:39:25 +0100 Subject: [PATCH 04/16] requested changes --- doc/3/controllers/document/m-create/index.md | 32 ++++++------ .../document/m-create/snippets/m-create.java | 11 ++-- .../m-create/snippets/m-create.test.yml | 2 +- .../API/Controllers/DocumentController.java | 8 +-- .../DocumentTest/DocumentTest.java | 50 ++++++++++++++++--- 5 files changed, 72 insertions(+), 31 deletions(-) diff --git a/doc/3/controllers/document/m-create/index.md b/doc/3/controllers/document/m-create/index.md index 377f16e4..77c61c83 100644 --- a/doc/3/controllers/document/m-create/index.md +++ b/doc/3/controllers/document/m-create/index.md @@ -14,13 +14,13 @@ Creates multiple documents in the provided index and collection. ## Arguments ```java -public CompletableFuture> mCreate( +public CompletableFuture>> mCreate( final String index, final String collection, final ArrayList> documents) throws NotConnectedException, InternalException -public CompletableFuture> mCreate( +public CompletableFuture>> mCreate( final String index, final String collection, final ArrayList> documents, @@ -33,7 +33,7 @@ throws NotConnectedException, InternalException | `index` |
String
| Index | | `collection` |
String
| Collection | | `documents` |
ArrayList>
| ArrayList containing the documents to create | -| `waitForRefresh` |
Boolean
| Optional parameters | +| `waitForRefresh` |
Boolean
| If set to `true`, Kuzzle will wait for the persistence layer to finish indexing | --- @@ -43,27 +43,27 @@ Each document has the following properties: | Arguments | Type | Description | | ------------------ | -------------------------------------------- | --------------------------------- | -| `_id` |
String
(optional) | Optional document ID. Will be auto-generated if not defined. | -| `body` |
Boolean
(optional) | Document body | +| `_id` |
String
| Optional document ID. Will be auto-generated if not defined. | +| `body` |
ConcurrentHashMap
| Document body | ## Return -A `ConcurrentHashMap` which has a `successes` and `errors` array: +A `ConcurrentHashMap>` which has a `successes` and `errors` `ArrayList`: Each created document is an object of the `successes` array with the following properties: -| Property | Type | Description | -|------------- |----------------------------- |--------------------------------- | -| `_source` |
ConcurrentHashMap
| Created document | -| `_id` |
String
| ID of the newly created document | -| `_version` |
Integer
| Version of the document in the persistent data storage | +| Property | Type | Description | +|------------- |--------------------------------------------- |--------------------------------- | +| `_source` |
ConcurrentHashMap
| Created document | +| `_id` |
String
| ID of the newly created document | +| `_version` |
Integer
| Version of the document in the persistent data storage | Each errored document is an object of the `errors` array with the following properties: -| Property | Type | Description | -|------------- |----------------------------- |--------------------------------- | -| `document` |
ConcurrentHashMap
| Document that causes the error | -| `status` |
Integer
| HTTP error status | -| `reason` |
String
| Human readable reason | +| Property | Type | Description | +|------------- |--------------------------------------------- |--------------------------------- | +| `document` |
ConcurrentHashMap
| Document that causes the error | +| `status` |
Integer
| HTTP error status | +| `reason` |
String
| Human readable reason | ## Usage diff --git a/doc/3/controllers/document/m-create/snippets/m-create.java b/doc/3/controllers/document/m-create/snippets/m-create.java index aeb0d5a3..3ef42946 100644 --- a/doc/3/controllers/document/m-create/snippets/m-create.java +++ b/doc/3/controllers/document/m-create/snippets/m-create.java @@ -1,18 +1,23 @@ + + + ConcurrentHashMap document1 = new ConcurrentHashMap<>(); ConcurrentHashMap document2 = new ConcurrentHashMap<>(); ConcurrentHashMap body = new ConcurrentHashMap<>(); + body.put("key1", "value1"); + document1.put("_id", "some-id1"); - body1.put("key1", "value1"); document1.put("body", body); document2.put("_id", "some-id2"); - body2.put("key2", "value2"); document2.put("body", body); final ArrayList> documents = new ArrayList<>(); documents.add(document1); documents.add(document2); - kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents) + ConcurrentHashMap> response = kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents) .get(); + + System.out.println("Successfully created " + response.get("successes").size() + " documents"); diff --git a/doc/3/controllers/document/m-create/snippets/m-create.test.yml b/doc/3/controllers/document/m-create/snippets/m-create.test.yml index d814cd75..0e3ec93f 100644 --- a/doc/3/controllers/document/m-create/snippets/m-create.test.yml +++ b/doc/3/controllers/document/m-create/snippets/m-create.test.yml @@ -7,4 +7,4 @@ hooks: curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi after: template: default -expected: Success \ No newline at end of file +expected: Successfully created 2 documents \ No newline at end of file diff --git a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java index 0abb540b..30951872 100644 --- a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java @@ -25,7 +25,7 @@ public DocumentController(final Kuzzle kuzzle) { * @throws NotConnectedException * @throws InternalException */ - public CompletableFuture> mCreate( + public CompletableFuture>> mCreate( final String index, final String collection, final ArrayList> documents, @@ -44,7 +44,7 @@ public CompletableFuture> mCreate( return kuzzle .query(query) .thenApplyAsync( - (response) -> (ConcurrentHashMap) response.result); + (response) -> (ConcurrentHashMap>) response.result); } /** @@ -57,11 +57,11 @@ public CompletableFuture> mCreate( * @throws NotConnectedException * @throws InternalException */ - public CompletableFuture> mCreate( + public CompletableFuture>> mCreate( final String index, final String collection, final ArrayList> documents) throws NotConnectedException, InternalException { - return this.mCreate(index, collection, documents, false); + return this.mCreate(index, collection, documents, null); } } diff --git a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java index c8da7674..488001ad 100644 --- a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java +++ b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java @@ -24,7 +24,7 @@ public class DocumentTest { private AbstractProtocol networkProtocol = Mockito.mock(WebSocket.class); @Test - public void mCreateDocumentTest() throws NotConnectedException, InternalException { + public void mCreateDocumentTestA() throws NotConnectedException, InternalException { Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); String index = "nyc-open-data"; @@ -55,6 +55,43 @@ public void mCreateDocumentTest() throws NotConnectedException, InternalExceptio assertEquals((arg.getValue()).getString("controller"), "document"); assertEquals((arg.getValue()).getString("action"), "mCreate"); assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); + assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); + assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); + assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); + } + + @Test + public void mCreateDocumentTestB() throws NotConnectedException, InternalException { + + Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); + String index = "nyc-open-data"; + String collection = "yellow-taxi"; + + ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + ConcurrentHashMap body = new ConcurrentHashMap<>(); + + document1.put("_id", "some-id1"); + body.put("key1", "value1"); + document1.put("body", body); + + document2.put("_id", "some-id2"); + body.put("key2", "value2"); + document2.put("body", body); + + final ArrayList> documents = new ArrayList<>(); + documents.add(document1); + documents.add(document2); + + ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); + + kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); + Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); + + assertEquals((arg.getValue()).getString("controller"), "document"); + assertEquals((arg.getValue()).getString("action"), "mCreate"); + assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); + assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); } @@ -70,16 +107,15 @@ public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedExce ConcurrentHashMap document1 = new ConcurrentHashMap<>(); ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body1 = new ConcurrentHashMap<>(); - ConcurrentHashMap body2 = new ConcurrentHashMap<>(); + ConcurrentHashMap body = new ConcurrentHashMap<>(); document1.put("_id", "some-id1"); - body1.put("key1", "value1"); - document1.put("body", body1); + body.put("key1", "value1"); + document1.put("body", body); document2.put("_id", "some-id2"); - body2.put("key2", "value2"); - document2.put("body", body2); + body.put("key2", "value2"); + document2.put("body", body); final ArrayList> documents = new ArrayList<>(); documents.add(document1); From 3db75e5df801bf31300fd3bb4c911c1ecb3962c2 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 26 Feb 2020 16:40:11 +0100 Subject: [PATCH 05/16] add ArrayList to default template --- .ci/doc/templates/default.tpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.ci/doc/templates/default.tpl.java b/.ci/doc/templates/default.tpl.java index bb86e2d1..6b069cc1 100644 --- a/.ci/doc/templates/default.tpl.java +++ b/.ci/doc/templates/default.tpl.java @@ -1,4 +1,6 @@ import io.kuzzle.sdk.Kuzzle; +import java.util.ArrayList; +import java.lang.reflect.Array; import io.kuzzle.sdk.Protocol.WebSocket; import io.kuzzle.sdk.Options.Protocol.WebSocketOptions; import io.kuzzle.sdk.Options.KuzzleOptions; From 08aff15a18f77860265d3e3268fe3deee8ce1fc4 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 26 Feb 2020 16:43:07 +0100 Subject: [PATCH 06/16] template useless import --- .ci/doc/templates/default.tpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/doc/templates/default.tpl.java b/.ci/doc/templates/default.tpl.java index 64e50ba5..03d84d23 100644 --- a/.ci/doc/templates/default.tpl.java +++ b/.ci/doc/templates/default.tpl.java @@ -1,6 +1,5 @@ import io.kuzzle.sdk.Kuzzle; import java.util.ArrayList; -import java.lang.reflect.Array; import io.kuzzle.sdk.Protocol.WebSocket; import io.kuzzle.sdk.Options.Protocol.WebSocketOptions; import io.kuzzle.sdk.Options.KuzzleOptions; From 4786ff7a9c6f4d86fbaa6c8849d8aabe16e73377 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Fri, 28 Feb 2020 15:00:26 +0100 Subject: [PATCH 07/16] @aschen requested change --- .../document/m-create/snippets/m-create.java | 45 ++++++++++++++++--- .../m-create/snippets/m-create.test.yml | 6 ++- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/doc/3/controllers/document/m-create/snippets/m-create.java b/doc/3/controllers/document/m-create/snippets/m-create.java index 3ef42946..c612c552 100644 --- a/doc/3/controllers/document/m-create/snippets/m-create.java +++ b/doc/3/controllers/document/m-create/snippets/m-create.java @@ -4,20 +4,53 @@ ConcurrentHashMap document1 = new ConcurrentHashMap<>(); ConcurrentHashMap document2 = new ConcurrentHashMap<>(); ConcurrentHashMap body = new ConcurrentHashMap<>(); + ConcurrentHashMap body2 = new ConcurrentHashMap<>(); - body.put("key1", "value1"); + body.put("Agent", "Smith"); + body2.put("Gordon", "Freeman"); - document1.put("_id", "some-id1"); + document1.put("_id", "some-id"); document1.put("body", body); document2.put("_id", "some-id2"); - document2.put("body", body); + document2.put("body", body2); final ArrayList> documents = new ArrayList<>(); documents.add(document1); documents.add(document2); - ConcurrentHashMap> response = kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents) + ConcurrentHashMap> result = kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents) .get(); - - System.out.println("Successfully created " + response.get("successes").size() + " documents"); + +/* + result = + { + successes= + [ + { + result=created, + _source= + { + Agent=Smith, + _kuzzle_info={createdAt=1582892842099, author=-1} + }, + _id=some-id, + _version=1, + status=201 + }, + { + result=created, + _source= + { + Gordon=Freeman, + _kuzzle_info={createdAt=1582892842099, author=-1} + }, + _id=some-id2, + _version=1, + status=201 + } + ], + errors=[] + } + +*/ \ No newline at end of file diff --git a/doc/3/controllers/document/m-create/snippets/m-create.test.yml b/doc/3/controllers/document/m-create/snippets/m-create.test.yml index 0e3ec93f..a513ed5a 100644 --- a/doc/3/controllers/document/m-create/snippets/m-create.test.yml +++ b/doc/3/controllers/document/m-create/snippets/m-create.test.yml @@ -6,5 +6,7 @@ hooks: curl -XPOST kuzzle:7512/nyc-open-data/_create curl -XPUT kuzzle:7512/nyc-open-data/yellow-taxi after: -template: default -expected: Successfully created 2 documents \ No newline at end of file +template: print-result-array +expected: + - "id=some-id, _version=1, status=201" + - "id=some-id2, _version=1, status=201" \ No newline at end of file From b1f37ab544385bc2ef1ab0ad0514c92f1305a71e Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Fri, 28 Feb 2020 15:01:15 +0100 Subject: [PATCH 08/16] template print array --- .ci/doc/templates/print-result-array.tpl.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .ci/doc/templates/print-result-array.tpl.java diff --git a/.ci/doc/templates/print-result-array.tpl.java b/.ci/doc/templates/print-result-array.tpl.java new file mode 100644 index 00000000..9c751d0b --- /dev/null +++ b/.ci/doc/templates/print-result-array.tpl.java @@ -0,0 +1,29 @@ +import io.kuzzle.sdk.Kuzzle; +import io.kuzzle.sdk.Protocol.WebSocket; +import io.kuzzle.sdk.Options.Protocol.WebSocketOptions; +import io.kuzzle.sdk.Options.KuzzleOptions; +import io.kuzzle.sdk.CoreClasses.Responses.Response; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.ArrayList; + +public class SnippetTest { + private static Kuzzle kuzzle; + + public static void main(String[] argv) { + try { + kuzzle = new Kuzzle(new WebSocket("kuzzle")); + kuzzle.connect(); + [snippet-code] + for (Object o : result.get("successes")) { + System.out.println(o); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (kuzzle != null) { + kuzzle.disconnect(); + } + } + } +} \ No newline at end of file From f2d2208bb7215eac77703572c6c802c8d0bebe3d Mon Sep 17 00:00:00 2001 From: Yoann Date: Mon, 2 Mar 2020 09:54:35 +0100 Subject: [PATCH 09/16] doc --- doc/3/controllers/document/m-create/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/3/controllers/document/m-create/index.md b/doc/3/controllers/document/m-create/index.md index 77c61c83..f26864fa 100644 --- a/doc/3/controllers/document/m-create/index.md +++ b/doc/3/controllers/document/m-create/index.md @@ -7,7 +7,7 @@ description: Creates multiple documents # mCreate -Creates multiple documents in the provided index and collection. +Creates multiple documents. --- From 0948b71445a2cac88a74d7c68e013553dc22af3e Mon Sep 17 00:00:00 2001 From: Yoann Date: Mon, 2 Mar 2020 13:12:02 +0100 Subject: [PATCH 10/16] conflict [ci skip] --- .../API/Controllers/DocumentController.java | 90 ++++---- src/main/java/io/kuzzle/sdk/Kuzzle.java | 4 - .../DocumentTest/DocumentTest.java | 200 +++++++++--------- 3 files changed, 145 insertions(+), 149 deletions(-) diff --git a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java index 30951872..f28f127f 100644 --- a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java @@ -14,54 +14,54 @@ public DocumentController(final Kuzzle kuzzle) { super(kuzzle); } - /** - * Creates multiple documents in a given collection and index. - * - * @param index - * @param collection - * @param documents - * @param waitForRefresh - * @return a CompletableFuture - * @throws NotConnectedException - * @throws InternalException - */ - public CompletableFuture>> mCreate( - final String index, - final String collection, - final ArrayList> documents, - final Boolean waitForRefresh) throws NotConnectedException, InternalException { + // /** + // * Creates multiple documents in a given collection and index. + // * + // * @param index + // * @param collection + // * @param documents + // * @param waitForRefresh + // * @return a CompletableFuture + // * @throws NotConnectedException + // * @throws InternalException + // */ + // public CompletableFuture>> mCreate( + // final String index, + // final String collection, + // final ArrayList> documents, + // final Boolean waitForRefresh) throws NotConnectedException, InternalException { - final KuzzleMap query = new KuzzleMap(); - query - .put("index", index) - .put("collection", collection) - .put("controller", "document") - .put("action", "mCreate") - .put("body", new KuzzleMap().put("documents", documents)) - .put("waitForRefresh", waitForRefresh); + // final KuzzleMap query = new KuzzleMap(); + // query + // .put("index", index) + // .put("collection", collection) + // .put("controller", "document") + // .put("action", "mCreate") + // .put("body", new KuzzleMap().put("documents", documents)) + // .put("waitForRefresh", waitForRefresh); - return kuzzle - .query(query) - .thenApplyAsync( - (response) -> (ConcurrentHashMap>) response.result); - } + // return kuzzle + // .query(query) + // .thenApplyAsync( + // (response) -> (ConcurrentHashMap>) response.result); + // } - /** - * Creates multiple documents in a given collection and index. - * - * @param index - * @param collection - * @param documents - * @return a CompletableFuture - * @throws NotConnectedException - * @throws InternalException - */ - public CompletableFuture>> mCreate( - final String index, - final String collection, - final ArrayList> documents) throws NotConnectedException, InternalException { + // /** + // * Creates multiple documents in a given collection and index. + // * + // * @param index + // * @param collection + // * @param documents + // * @return a CompletableFuture + // * @throws NotConnectedException + // * @throws InternalException + // */ + // public CompletableFuture>> mCreate( + // final String index, + // final String collection, + // final ArrayList> documents) throws NotConnectedException, InternalException { - return this.mCreate(index, collection, documents, null); - } + // return this.mCreate(index, collection, documents, null); + // } } diff --git a/src/main/java/io/kuzzle/sdk/Kuzzle.java b/src/main/java/io/kuzzle/sdk/Kuzzle.java index 00289727..0f753bc8 100644 --- a/src/main/java/io/kuzzle/sdk/Kuzzle.java +++ b/src/main/java/io/kuzzle/sdk/Kuzzle.java @@ -78,10 +78,6 @@ public AuthController getAuthController() { return new AuthController(this); } - public DocumentController getDocumentController() { - return new DocumentController(this); - } - /** * @return The IndexController */ diff --git a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java index 488001ad..30ba4947 100644 --- a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java +++ b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java @@ -23,104 +23,104 @@ public class DocumentTest { private AbstractProtocol networkProtocol = Mockito.mock(WebSocket.class); - @Test - public void mCreateDocumentTestA() throws NotConnectedException, InternalException { - - Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body1 = new ConcurrentHashMap<>(); - ConcurrentHashMap body2 = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body1.put("key1", "value1"); - document1.put("body", body1); - - document2.put("_id", "some-id2"); - body2.put("key2", "value2"); - document2.put("body", body2); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents); - Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); - - assertEquals((arg.getValue()).getString("controller"), "document"); - assertEquals((arg.getValue()).getString("action"), "mCreate"); - assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); - assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); - } - - @Test - public void mCreateDocumentTestB() throws NotConnectedException, InternalException { - - Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body.put("key1", "value1"); - document1.put("body", body); - - document2.put("_id", "some-id2"); - body.put("key2", "value2"); - document2.put("body", body); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); - Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); - - assertEquals((arg.getValue()).getString("controller"), "document"); - assertEquals((arg.getValue()).getString("action"), "mCreate"); - assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); - assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); - } - - @Test(expected = NotConnectedException.class) - public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { - AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); - Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); - - Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body.put("key1", "value1"); - document1.put("body", body); - - document2.put("_id", "some-id2"); - body.put("key2", "value2"); - document2.put("body", body); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents); - } + // @Test + // public void mCreateDocumentTestA() throws NotConnectedException, InternalException { + + // Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); + // String index = "nyc-open-data"; + // String collection = "yellow-taxi"; + + // ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + // ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + // ConcurrentHashMap body1 = new ConcurrentHashMap<>(); + // ConcurrentHashMap body2 = new ConcurrentHashMap<>(); + + // document1.put("_id", "some-id1"); + // body1.put("key1", "value1"); + // document1.put("body", body1); + + // document2.put("_id", "some-id2"); + // body2.put("key2", "value2"); + // document2.put("body", body2); + + // final ArrayList> documents = new ArrayList<>(); + // documents.add(document1); + // documents.add(document2); + + // ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); + + // kuzzleMock.getDocumentController().mCreate(index, collection, documents); + // Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); + + // assertEquals((arg.getValue()).getString("controller"), "document"); + // assertEquals((arg.getValue()).getString("action"), "mCreate"); + // assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); + // assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); + // assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); + // assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); + // } + + // @Test + // public void mCreateDocumentTestB() throws NotConnectedException, InternalException { + + // Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); + // String index = "nyc-open-data"; + // String collection = "yellow-taxi"; + + // ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + // ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + // ConcurrentHashMap body = new ConcurrentHashMap<>(); + + // document1.put("_id", "some-id1"); + // body.put("key1", "value1"); + // document1.put("body", body); + + // document2.put("_id", "some-id2"); + // body.put("key2", "value2"); + // document2.put("body", body); + + // final ArrayList> documents = new ArrayList<>(); + // documents.add(document1); + // documents.add(document2); + + // ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); + + // kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); + // Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); + + // assertEquals((arg.getValue()).getString("controller"), "document"); + // assertEquals((arg.getValue()).getString("action"), "mCreate"); + // assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); + // assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); + // assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); + // assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); + // } + + // @Test(expected = NotConnectedException.class) + // public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { + // AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); + // Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); + + // Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); + // String index = "nyc-open-data"; + // String collection = "yellow-taxi"; + + // ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + // ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + // ConcurrentHashMap body = new ConcurrentHashMap<>(); + + // document1.put("_id", "some-id1"); + // body.put("key1", "value1"); + // document1.put("body", body); + + // document2.put("_id", "some-id2"); + // body.put("key2", "value2"); + // document2.put("body", body); + + // final ArrayList> documents = new ArrayList<>(); + // documents.add(document1); + // documents.add(document2); + + // kuzzleMock.getDocumentController().mCreate(index, collection, documents); + // } } From 62f6fc515d403ff6774ebf0d900ba5c3bbec3284 Mon Sep 17 00:00:00 2001 From: Yoann Date: Mon, 2 Mar 2020 13:22:50 +0100 Subject: [PATCH 11/16] doc --- doc/3/controllers/document/replace/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/3/controllers/document/replace/index.md b/doc/3/controllers/document/replace/index.md index 43dde4e7..08d1f804 100644 --- a/doc/3/controllers/document/replace/index.md +++ b/doc/3/controllers/document/replace/index.md @@ -35,7 +35,7 @@ throws NotConnectedException, InternalException | `index` |
String
| Index | | `collection` |
String
| Collection | | `id` |
String
| Document ID | -| `document` |
ConcurrentHashMap
| Updated ocument content | +| `document` |
ConcurrentHashMap
| New content of the document to update | | `waitForRefresh` |
Boolean
| If set to `true`, Kuzzle will wait for the persistence layer to finish indexing| --- From f81f44af1bdcfc6d10658e1cce2fc67efe9287f3 Mon Sep 17 00:00:00 2001 From: Yoann Date: Mon, 2 Mar 2020 15:49:37 +0100 Subject: [PATCH 12/16] nit --- .../java/io/kuzzle/sdk/API/Controllers/DocumentController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java index 77c1dea1..ca342e24 100644 --- a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java @@ -31,7 +31,6 @@ public CompletableFuture>> mCreate( final ArrayList> documents, final Boolean waitForRefresh) throws NotConnectedException, InternalException { - final KuzzleMap query = new KuzzleMap(); query .put("index", index) From fbc223210c74e553fe79ca1b7781b49c37815ecd Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 4 Mar 2020 17:01:01 +0100 Subject: [PATCH 13/16] conflict [ci skip] --- .../API/Controllers/DocumentController.java | 100 ++++----- .../DocumentTest/DocumentTest.java | 200 +++++++++--------- 2 files changed, 150 insertions(+), 150 deletions(-) diff --git a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java index 30951872..9faed7bf 100644 --- a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java @@ -14,54 +14,54 @@ public DocumentController(final Kuzzle kuzzle) { super(kuzzle); } - /** - * Creates multiple documents in a given collection and index. - * - * @param index - * @param collection - * @param documents - * @param waitForRefresh - * @return a CompletableFuture - * @throws NotConnectedException - * @throws InternalException - */ - public CompletableFuture>> mCreate( - final String index, - final String collection, - final ArrayList> documents, - final Boolean waitForRefresh) throws NotConnectedException, InternalException { - - - final KuzzleMap query = new KuzzleMap(); - query - .put("index", index) - .put("collection", collection) - .put("controller", "document") - .put("action", "mCreate") - .put("body", new KuzzleMap().put("documents", documents)) - .put("waitForRefresh", waitForRefresh); - - return kuzzle - .query(query) - .thenApplyAsync( - (response) -> (ConcurrentHashMap>) response.result); - } - - /** - * Creates multiple documents in a given collection and index. - * - * @param index - * @param collection - * @param documents - * @return a CompletableFuture - * @throws NotConnectedException - * @throws InternalException - */ - public CompletableFuture>> mCreate( - final String index, - final String collection, - final ArrayList> documents) throws NotConnectedException, InternalException { - - return this.mCreate(index, collection, documents, null); - } +// /** +// * Creates multiple documents in a given collection and index. +// * +// * @param index +// * @param collection +// * @param documents +// * @param waitForRefresh +// * @return a CompletableFuture +// * @throws NotConnectedException +// * @throws InternalException +// */ +// public CompletableFuture>> mCreate( +// final String index, +// final String collection, +// final ArrayList> documents, +// final Boolean waitForRefresh) throws NotConnectedException, InternalException { +// +// +// final KuzzleMap query = new KuzzleMap(); +// query +// .put("index", index) +// .put("collection", collection) +// .put("controller", "document") +// .put("action", "mCreate") +// .put("body", new KuzzleMap().put("documents", documents)) +// .put("waitForRefresh", waitForRefresh); +// +// return kuzzle +// .query(query) +// .thenApplyAsync( +// (response) -> (ConcurrentHashMap>) response.result); +// } +// +// /** +// * Creates multiple documents in a given collection and index. +// * +// * @param index +// * @param collection +// * @param documents +// * @return a CompletableFuture +// * @throws NotConnectedException +// * @throws InternalException +// */ +// public CompletableFuture>> mCreate( +// final String index, +// final String collection, +// final ArrayList> documents) throws NotConnectedException, InternalException { +// +// return this.mCreate(index, collection, documents, null); +// } } diff --git a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java index 488001ad..7336eb5b 100644 --- a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java +++ b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java @@ -23,104 +23,104 @@ public class DocumentTest { private AbstractProtocol networkProtocol = Mockito.mock(WebSocket.class); - @Test - public void mCreateDocumentTestA() throws NotConnectedException, InternalException { - - Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body1 = new ConcurrentHashMap<>(); - ConcurrentHashMap body2 = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body1.put("key1", "value1"); - document1.put("body", body1); - - document2.put("_id", "some-id2"); - body2.put("key2", "value2"); - document2.put("body", body2); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents); - Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); - - assertEquals((arg.getValue()).getString("controller"), "document"); - assertEquals((arg.getValue()).getString("action"), "mCreate"); - assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); - assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); - } - - @Test - public void mCreateDocumentTestB() throws NotConnectedException, InternalException { - - Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body.put("key1", "value1"); - document1.put("body", body); - - document2.put("_id", "some-id2"); - body.put("key2", "value2"); - document2.put("body", body); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); - Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); - - assertEquals((arg.getValue()).getString("controller"), "document"); - assertEquals((arg.getValue()).getString("action"), "mCreate"); - assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); - assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); - } - - @Test(expected = NotConnectedException.class) - public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { - AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); - Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); - - Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body.put("key1", "value1"); - document1.put("body", body); - - document2.put("_id", "some-id2"); - body.put("key2", "value2"); - document2.put("body", body); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents); - } +// @Test +// public void mCreateDocumentTestA() throws NotConnectedException, InternalException { +// +// Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); +// String index = "nyc-open-data"; +// String collection = "yellow-taxi"; +// +// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); +// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); +// ConcurrentHashMap body1 = new ConcurrentHashMap<>(); +// ConcurrentHashMap body2 = new ConcurrentHashMap<>(); +// +// document1.put("_id", "some-id1"); +// body1.put("key1", "value1"); +// document1.put("body", body1); +// +// document2.put("_id", "some-id2"); +// body2.put("key2", "value2"); +// document2.put("body", body2); +// +// final ArrayList> documents = new ArrayList<>(); +// documents.add(document1); +// documents.add(document2); +// +// ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); +// +// kuzzleMock.getDocumentController().mCreate(index, collection, documents); +// Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); +// +// assertEquals((arg.getValue()).getString("controller"), "document"); +// assertEquals((arg.getValue()).getString("action"), "mCreate"); +// assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); +// assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); +// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); +// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); +// } +// +// @Test +// public void mCreateDocumentTestB() throws NotConnectedException, InternalException { +// +// Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); +// String index = "nyc-open-data"; +// String collection = "yellow-taxi"; +// +// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); +// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); +// ConcurrentHashMap body = new ConcurrentHashMap<>(); +// +// document1.put("_id", "some-id1"); +// body.put("key1", "value1"); +// document1.put("body", body); +// +// document2.put("_id", "some-id2"); +// body.put("key2", "value2"); +// document2.put("body", body); +// +// final ArrayList> documents = new ArrayList<>(); +// documents.add(document1); +// documents.add(document2); +// +// ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); +// +// kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); +// Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); +// +// assertEquals((arg.getValue()).getString("controller"), "document"); +// assertEquals((arg.getValue()).getString("action"), "mCreate"); +// assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); +// assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); +// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); +// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); +// } +// +// @Test(expected = NotConnectedException.class) +// public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { +// AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); +// Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); +// +// Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); +// String index = "nyc-open-data"; +// String collection = "yellow-taxi"; +// +// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); +// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); +// ConcurrentHashMap body = new ConcurrentHashMap<>(); +// +// document1.put("_id", "some-id1"); +// body.put("key1", "value1"); +// document1.put("body", body); +// +// document2.put("_id", "some-id2"); +// body.put("key2", "value2"); +// document2.put("body", body); +// +// final ArrayList> documents = new ArrayList<>(); +// documents.add(document1); +// documents.add(document2); +// +// kuzzleMock.getDocumentController().mCreate(index, collection, documents); +// } } From 6e398baf17b8e7a6ee0cc2fd2cd9cb749d041769 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 4 Mar 2020 17:07:21 +0100 Subject: [PATCH 14/16] conflict [ci skip] --- .../API/Controllers/DocumentController.java | 98 ++++----- .../DocumentTest/DocumentTest.java | 200 +++++++++--------- 2 files changed, 149 insertions(+), 149 deletions(-) diff --git a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java index ca342e24..c0c38451 100644 --- a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java @@ -14,55 +14,55 @@ public DocumentController(final Kuzzle kuzzle) { super(kuzzle); } - /** - * Creates multiple documents in a given collection and index. - * - * @param index - * @param collection - * @param documents - * @param waitForRefresh - * @return a CompletableFuture - * @throws NotConnectedException - * @throws InternalException - */ - public CompletableFuture>> mCreate( - final String index, - final String collection, - final ArrayList> documents, - final Boolean waitForRefresh) throws NotConnectedException, InternalException { - - final KuzzleMap query = new KuzzleMap(); - query - .put("index", index) - .put("collection", collection) - .put("controller", "document") - .put("action", "mCreate") - .put("body", new KuzzleMap().put("documents", documents)) - .put("waitForRefresh", waitForRefresh); - - return kuzzle - .query(query) - .thenApplyAsync( - (response) -> (ConcurrentHashMap>) response.result); - } - - /** - * Creates multiple documents in a given collection and index. - * - * @param index - * @param collection - * @param documents - * @return a CompletableFuture - * @throws NotConnectedException - * @throws InternalException - */ - public CompletableFuture>> mCreate( - final String index, - final String collection, - final ArrayList> documents) throws NotConnectedException, InternalException { - - return this.mCreate(index, collection, documents, null); - } +// /** +// * Creates multiple documents in a given collection and index. +// * +// * @param index +// * @param collection +// * @param documents +// * @param waitForRefresh +// * @return a CompletableFuture +// * @throws NotConnectedException +// * @throws InternalException +// */ +// public CompletableFuture>> mCreate( +// final String index, +// final String collection, +// final ArrayList> documents, +// final Boolean waitForRefresh) throws NotConnectedException, InternalException { +// +// final KuzzleMap query = new KuzzleMap(); +// query +// .put("index", index) +// .put("collection", collection) +// .put("controller", "document") +// .put("action", "mCreate") +// .put("body", new KuzzleMap().put("documents", documents)) +// .put("waitForRefresh", waitForRefresh); +// +// return kuzzle +// .query(query) +// .thenApplyAsync( +// (response) -> (ConcurrentHashMap>) response.result); +// } +// +// /** +// * Creates multiple documents in a given collection and index. +// * +// * @param index +// * @param collection +// * @param documents +// * @return a CompletableFuture +// * @throws NotConnectedException +// * @throws InternalException +// */ +// public CompletableFuture>> mCreate( +// final String index, +// final String collection, +// final ArrayList> documents) throws NotConnectedException, InternalException { +// +// return this.mCreate(index, collection, documents, null); +// } /** * Replace a document in a given collection and index. diff --git a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java index 4a663ab9..c092fc87 100644 --- a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java +++ b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java @@ -23,106 +23,106 @@ public class DocumentTest { private AbstractProtocol networkProtocol = Mockito.mock(WebSocket.class); - @Test - public void mCreateDocumentTestA() throws NotConnectedException, InternalException { - - Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body1 = new ConcurrentHashMap<>(); - ConcurrentHashMap body2 = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body1.put("key1", "value1"); - document1.put("body", body1); - - document2.put("_id", "some-id2"); - body2.put("key2", "value2"); - document2.put("body", body2); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents); - Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); - - assertEquals((arg.getValue()).getString("controller"), "document"); - assertEquals((arg.getValue()).getString("action"), "mCreate"); - assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); - assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); - } - - @Test - public void mCreateDocumentTestB() throws NotConnectedException, InternalException { - - Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body.put("key1", "value1"); - document1.put("body", body); - - document2.put("_id", "some-id2"); - body.put("key2", "value2"); - document2.put("body", body); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); - Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); - - assertEquals((arg.getValue()).getString("controller"), "document"); - assertEquals((arg.getValue()).getString("action"), "mCreate"); - assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); - assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); - assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); - } - - @Test(expected = NotConnectedException.class) - public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { - AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); - Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); - - Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); - String index = "nyc-open-data"; - String collection = "yellow-taxi"; - - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body = new ConcurrentHashMap<>(); - - document1.put("_id", "some-id1"); - body.put("key1", "value1"); - document1.put("body", body); - - document2.put("_id", "some-id2"); - body.put("key2", "value2"); - document2.put("body", body); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - kuzzleMock.getDocumentController().mCreate(index, collection, documents); - } +// @Test +// public void mCreateDocumentTestA() throws NotConnectedException, InternalException { +// +// Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); +// String index = "nyc-open-data"; +// String collection = "yellow-taxi"; +// +// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); +// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); +// ConcurrentHashMap body1 = new ConcurrentHashMap<>(); +// ConcurrentHashMap body2 = new ConcurrentHashMap<>(); +// +// document1.put("_id", "some-id1"); +// body1.put("key1", "value1"); +// document1.put("body", body1); +// +// document2.put("_id", "some-id2"); +// body2.put("key2", "value2"); +// document2.put("body", body2); +// +// final ArrayList> documents = new ArrayList<>(); +// documents.add(document1); +// documents.add(document2); +// +// ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); +// +// kuzzleMock.getDocumentController().mCreate(index, collection, documents); +// Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); +// +// assertEquals((arg.getValue()).getString("controller"), "document"); +// assertEquals((arg.getValue()).getString("action"), "mCreate"); +// assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); +// assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); +// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); +// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); +// } +// +// @Test +// public void mCreateDocumentTestB() throws NotConnectedException, InternalException { +// +// Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); +// String index = "nyc-open-data"; +// String collection = "yellow-taxi"; +// +// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); +// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); +// ConcurrentHashMap body = new ConcurrentHashMap<>(); +// +// document1.put("_id", "some-id1"); +// body.put("key1", "value1"); +// document1.put("body", body); +// +// document2.put("_id", "some-id2"); +// body.put("key2", "value2"); +// document2.put("body", body); +// +// final ArrayList> documents = new ArrayList<>(); +// documents.add(document1); +// documents.add(document2); +// +// ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); +// +// kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); +// Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); +// +// assertEquals((arg.getValue()).getString("controller"), "document"); +// assertEquals((arg.getValue()).getString("action"), "mCreate"); +// assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); +// assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); +// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); +// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); +// } +// +// @Test(expected = NotConnectedException.class) +// public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { +// AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); +// Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); +// +// Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); +// String index = "nyc-open-data"; +// String collection = "yellow-taxi"; +// +// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); +// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); +// ConcurrentHashMap body = new ConcurrentHashMap<>(); +// +// document1.put("_id", "some-id1"); +// body.put("key1", "value1"); +// document1.put("body", body); +// +// document2.put("_id", "some-id2"); +// body.put("key2", "value2"); +// document2.put("body", body); +// +// final ArrayList> documents = new ArrayList<>(); +// documents.add(document1); +// documents.add(document2); +// +// kuzzleMock.getDocumentController().mCreate(index, collection, documents); +// } @Test public void replaceDocumentTestA() throws NotConnectedException, InternalException { From e42224bcbf0ebeae73e062c294e2eba2390df3c3 Mon Sep 17 00:00:00 2001 From: Yoann Abbes Date: Wed, 4 Mar 2020 17:08:51 +0100 Subject: [PATCH 15/16] conflict --- .../API/Controllers/DocumentController.java | 98 ++++----- .../DocumentTest/DocumentTest.java | 200 +++++++++--------- 2 files changed, 149 insertions(+), 149 deletions(-) diff --git a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java index c049bb00..d322d2df 100644 --- a/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/DocumentController.java @@ -14,55 +14,55 @@ public DocumentController(final Kuzzle kuzzle) { super(kuzzle); } -// /** -// * Creates multiple documents in a given collection and index. -// * -// * @param index -// * @param collection -// * @param documents -// * @param waitForRefresh -// * @return a CompletableFuture -// * @throws NotConnectedException -// * @throws InternalException -// */ -// public CompletableFuture>> mCreate( -// final String index, -// final String collection, -// final ArrayList> documents, -// final Boolean waitForRefresh) throws NotConnectedException, InternalException { -// -// final KuzzleMap query = new KuzzleMap(); -// query -// .put("index", index) -// .put("collection", collection) -// .put("controller", "document") -// .put("action", "mCreate") -// .put("body", new KuzzleMap().put("documents", documents)) -// .put("waitForRefresh", waitForRefresh); -// -// return kuzzle -// .query(query) -// .thenApplyAsync( -// (response) -> (ConcurrentHashMap>) response.result); -// } -// -// /** -// * Creates multiple documents in a given collection and index. -// * -// * @param index -// * @param collection -// * @param documents -// * @return a CompletableFuture -// * @throws NotConnectedException -// * @throws InternalException -// */ -// public CompletableFuture>> mCreate( -// final String index, -// final String collection, -// final ArrayList> documents) throws NotConnectedException, InternalException { -// -// return this.mCreate(index, collection, documents, null); -// } + /** + * Creates multiple documents in a given collection and index. + * + * @param index + * @param collection + * @param documents + * @param waitForRefresh + * @return a CompletableFuture + * @throws NotConnectedException + * @throws InternalException + */ + public CompletableFuture>> mCreate( + final String index, + final String collection, + final ArrayList> documents, + final Boolean waitForRefresh) throws NotConnectedException, InternalException { + + final KuzzleMap query = new KuzzleMap(); + query + .put("index", index) + .put("collection", collection) + .put("controller", "document") + .put("action", "mCreate") + .put("body", new KuzzleMap().put("documents", documents)) + .put("waitForRefresh", waitForRefresh); + + return kuzzle + .query(query) + .thenApplyAsync( + (response) -> (ConcurrentHashMap>) response.result); + } + + /** + * Creates multiple documents in a given collection and index. + * + * @param index + * @param collection + * @param documents + * @return a CompletableFuture + * @throws NotConnectedException + * @throws InternalException + */ + public CompletableFuture>> mCreate( + final String index, + final String collection, + final ArrayList> documents) throws NotConnectedException, InternalException { + + return this.mCreate(index, collection, documents, null); + } /** * Deletes multiple documents. diff --git a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java index 344d7312..c394ce60 100644 --- a/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java +++ b/src/test/java/io/kuzzle/test/API/Controllers/DocumentTest/DocumentTest.java @@ -23,106 +23,106 @@ public class DocumentTest { private AbstractProtocol networkProtocol = Mockito.mock(WebSocket.class); -// @Test -// public void mCreateDocumentTestA() throws NotConnectedException, InternalException { -// -// Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); -// String index = "nyc-open-data"; -// String collection = "yellow-taxi"; -// -// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); -// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); -// ConcurrentHashMap body1 = new ConcurrentHashMap<>(); -// ConcurrentHashMap body2 = new ConcurrentHashMap<>(); -// -// document1.put("_id", "some-id1"); -// body1.put("key1", "value1"); -// document1.put("body", body1); -// -// document2.put("_id", "some-id2"); -// body2.put("key2", "value2"); -// document2.put("body", body2); -// -// final ArrayList> documents = new ArrayList<>(); -// documents.add(document1); -// documents.add(document2); -// -// ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); -// -// kuzzleMock.getDocumentController().mCreate(index, collection, documents); -// Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); -// -// assertEquals((arg.getValue()).getString("controller"), "document"); -// assertEquals((arg.getValue()).getString("action"), "mCreate"); -// assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); -// assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); -// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); -// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); -// } -// -// @Test -// public void mCreateDocumentTestB() throws NotConnectedException, InternalException { -// -// Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); -// String index = "nyc-open-data"; -// String collection = "yellow-taxi"; -// -// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); -// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); -// ConcurrentHashMap body = new ConcurrentHashMap<>(); -// -// document1.put("_id", "some-id1"); -// body.put("key1", "value1"); -// document1.put("body", body); -// -// document2.put("_id", "some-id2"); -// body.put("key2", "value2"); -// document2.put("body", body); -// -// final ArrayList> documents = new ArrayList<>(); -// documents.add(document1); -// documents.add(document2); -// -// ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); -// -// kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); -// Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); -// -// assertEquals((arg.getValue()).getString("controller"), "document"); -// assertEquals((arg.getValue()).getString("action"), "mCreate"); -// assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); -// assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); -// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); -// assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); -// } -// -// @Test(expected = NotConnectedException.class) -// public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { -// AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); -// Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); -// -// Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); -// String index = "nyc-open-data"; -// String collection = "yellow-taxi"; -// -// ConcurrentHashMap document1 = new ConcurrentHashMap<>(); -// ConcurrentHashMap document2 = new ConcurrentHashMap<>(); -// ConcurrentHashMap body = new ConcurrentHashMap<>(); -// -// document1.put("_id", "some-id1"); -// body.put("key1", "value1"); -// document1.put("body", body); -// -// document2.put("_id", "some-id2"); -// body.put("key2", "value2"); -// document2.put("body", body); -// -// final ArrayList> documents = new ArrayList<>(); -// documents.add(document1); -// documents.add(document2); -// -// kuzzleMock.getDocumentController().mCreate(index, collection, documents); -// } + @Test + public void mCreateDocumentTestA() throws NotConnectedException, InternalException { + + Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); + String index = "nyc-open-data"; + String collection = "yellow-taxi"; + + ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + ConcurrentHashMap body1 = new ConcurrentHashMap<>(); + ConcurrentHashMap body2 = new ConcurrentHashMap<>(); + + document1.put("_id", "some-id1"); + body1.put("key1", "value1"); + document1.put("body", body1); + + document2.put("_id", "some-id2"); + body2.put("key2", "value2"); + document2.put("body", body2); + + final ArrayList> documents = new ArrayList<>(); + documents.add(document1); + documents.add(document2); + + ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); + + kuzzleMock.getDocumentController().mCreate(index, collection, documents); + Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); + + assertEquals((arg.getValue()).getString("controller"), "document"); + assertEquals((arg.getValue()).getString("action"), "mCreate"); + assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); + assertEquals((arg.getValue()).getBoolean("waitForRefresh"), null); + assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); + assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); + } + + @Test + public void mCreateDocumentTestB() throws NotConnectedException, InternalException { + + Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); + String index = "nyc-open-data"; + String collection = "yellow-taxi"; + + ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + ConcurrentHashMap body = new ConcurrentHashMap<>(); + + document1.put("_id", "some-id1"); + body.put("key1", "value1"); + document1.put("body", body); + + document2.put("_id", "some-id2"); + body.put("key2", "value2"); + document2.put("body", body); + + final ArrayList> documents = new ArrayList<>(); + documents.add(document1); + documents.add(document2); + + ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); + + kuzzleMock.getDocumentController().mCreate(index, collection, documents, false); + Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); + + assertEquals((arg.getValue()).getString("controller"), "document"); + assertEquals((arg.getValue()).getString("action"), "mCreate"); + assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); + assertEquals((arg.getValue()).getBoolean("waitForRefresh"), false); + assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(0).get("_id").toString(), "some-id1"); + assertEquals(((ArrayList>)(((KuzzleMap)(arg.getValue()).get("body"))).get("documents")).get(1).get("_id").toString(), "some-id2"); + } + + @Test(expected = NotConnectedException.class) + public void mCreateDocumentShouldThrowWhenNotConnected() throws NotConnectedException, InternalException { + AbstractProtocol fakeNetworkProtocol = Mockito.mock(WebSocket.class); + Mockito.when(fakeNetworkProtocol.getState()).thenAnswer((Answer) invocation -> ProtocolState.CLOSE); + + Kuzzle kuzzleMock = spy(new Kuzzle(fakeNetworkProtocol)); + String index = "nyc-open-data"; + String collection = "yellow-taxi"; + + ConcurrentHashMap document1 = new ConcurrentHashMap<>(); + ConcurrentHashMap document2 = new ConcurrentHashMap<>(); + ConcurrentHashMap body = new ConcurrentHashMap<>(); + + document1.put("_id", "some-id1"); + body.put("key1", "value1"); + document1.put("body", body); + + document2.put("_id", "some-id2"); + body.put("key2", "value2"); + document2.put("body", body); + + final ArrayList> documents = new ArrayList<>(); + documents.add(document1); + documents.add(document2); + + kuzzleMock.getDocumentController().mCreate(index, collection, documents); + } @Test public void mDeleteDocumentTestA() throws NotConnectedException, InternalException { From 4e8a0b3ec43c9a7f351708cbb9bdea1a15474daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Cottinet?= Date: Fri, 6 Mar 2020 10:22:29 +0100 Subject: [PATCH 16/16] Wrapped code Makes it easier to read in documentation pages --- .../document/m-create/snippets/m-create.java | 96 +++++++++---------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/doc/3/controllers/document/m-create/snippets/m-create.java b/doc/3/controllers/document/m-create/snippets/m-create.java index c612c552..24f9696f 100644 --- a/doc/3/controllers/document/m-create/snippets/m-create.java +++ b/doc/3/controllers/document/m-create/snippets/m-create.java @@ -1,56 +1,54 @@ +ConcurrentHashMap document1 = new ConcurrentHashMap<>(); +ConcurrentHashMap document2 = new ConcurrentHashMap<>(); +ConcurrentHashMap body = new ConcurrentHashMap<>(); +ConcurrentHashMap body2 = new ConcurrentHashMap<>(); +body.put("Agent", "Smith"); +body2.put("Gordon", "Freeman"); +document1.put("_id", "some-id"); +document1.put("body", body); - ConcurrentHashMap document1 = new ConcurrentHashMap<>(); - ConcurrentHashMap document2 = new ConcurrentHashMap<>(); - ConcurrentHashMap body = new ConcurrentHashMap<>(); - ConcurrentHashMap body2 = new ConcurrentHashMap<>(); +document2.put("_id", "some-id2"); +document2.put("body", body2); - body.put("Agent", "Smith"); - body2.put("Gordon", "Freeman"); +final ArrayList> documents = new ArrayList<>(); +documents.add(document1); +documents.add(document2); - document1.put("_id", "some-id"); - document1.put("body", body); +ConcurrentHashMap> result = kuzzle + .getDocumentController() + .mCreate("nyc-open-data", "yellow-taxi", documents) + .get(); - document2.put("_id", "some-id2"); - document2.put("body", body2); - - final ArrayList> documents = new ArrayList<>(); - documents.add(document1); - documents.add(document2); - - ConcurrentHashMap> result = kuzzle.getDocumentController().mCreate("nyc-open-data", "yellow-taxi", documents) - .get(); - /* - result = - { - successes= - [ - { - result=created, - _source= - { - Agent=Smith, - _kuzzle_info={createdAt=1582892842099, author=-1} - }, - _id=some-id, - _version=1, - status=201 - }, - { - result=created, - _source= - { - Gordon=Freeman, - _kuzzle_info={createdAt=1582892842099, author=-1} - }, - _id=some-id2, - _version=1, - status=201 - } - ], - errors=[] - } - -*/ \ No newline at end of file +result = + { + successes= + [ + { + result=created, + _source= + { + Agent=Smith, + _kuzzle_info={createdAt=1582892842099, author=-1} + }, + _id=some-id, + _version=1, + status=201 + }, + { + result=created, + _source= + { + Gordon=Freeman, + _kuzzle_info={createdAt=1582892842099, author=-1} + }, + _id=some-id2, + _version=1, + status=201 + } + ], + errors=[] + } +*/