diff --git a/doc/3/controllers/collection/delete-specifications/index.md b/doc/3/controllers/collection/delete-specifications/index.md new file mode 100644 index 00000000..e07a9d8f --- /dev/null +++ b/doc/3/controllers/collection/delete-specifications/index.md @@ -0,0 +1,33 @@ +--- +code: true +type: page +title: deleteSpecifications +description: Delete validation specifications for a collection +--- + +# deleteSpecifications + +Deletes validation specifications for a collection. + +
+ +```java + public CompletableFuture deleteSpecifications( + final String index, + final String collection) +``` + +
+ +| Arguments | Type | Description | +| ------------ | ----------------- | --------------- | +| `index` |
String
| Index name | +| `collection` |
String
| Collection name | + +## Returns + +Returns a `CompletableFuture`. + +## Usage + +<<< ./snippets/delete-specifications.java \ No newline at end of file diff --git a/doc/3/controllers/collection/delete-specifications/snippets/delete-specifications.java b/doc/3/controllers/collection/delete-specifications/snippets/delete-specifications.java new file mode 100644 index 00000000..bff98d89 --- /dev/null +++ b/doc/3/controllers/collection/delete-specifications/snippets/delete-specifications.java @@ -0,0 +1,4 @@ + kuzzle + .getCollectionController() + .deleteSpecifications("nyc-open-data", "yellow-taxi") + .get(); \ No newline at end of file diff --git a/doc/3/controllers/collection/delete-specifications/snippets/delete-specifications.test.yml b/doc/3/controllers/collection/delete-specifications/snippets/delete-specifications.test.yml new file mode 100644 index 00000000..56cd44ca --- /dev/null +++ b/doc/3/controllers/collection/delete-specifications/snippets/delete-specifications.test.yml @@ -0,0 +1,7 @@ +name: collection#deleteSpecifications +description: Delete validation specifications for a collection +hooks: + before: curl -X POST kuzzle:7512/nyc-open-data/_create && curl -X PUT 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/CollectionController.java b/src/main/java/io/kuzzle/sdk/API/Controllers/CollectionController.java index 224c9d4d..b59ca011 100644 --- a/src/main/java/io/kuzzle/sdk/API/Controllers/CollectionController.java +++ b/src/main/java/io/kuzzle/sdk/API/Controllers/CollectionController.java @@ -137,6 +137,33 @@ public CompletableFuture> getMapping( (response) -> (ConcurrentHashMap) response.result); } + /** + * Deletes the validation specifications associated to the given index and collection. + * + * @param index + * @param collection + * @return a CompletableFuture + * @throws NotConnectedException + * @throws InternalException + */ + public CompletableFuture deleteSpecifications( + final String index, + final String collection) throws NotConnectedException, InternalException { + + final KuzzleMap query = new KuzzleMap(); + + query + .put("index", index) + .put("collection", collection) + .put("controller", "collection") + .put("action", "deleteSpecifications"); + + return kuzzle + .query(query) + .thenApplyAsync( + (response) -> null); + } + /** * Gets the validation specifications associated to the given index and collection. * diff --git a/src/test/java/io/kuzzle/test/API/Controllers/CollectionTest.java b/src/test/java/io/kuzzle/test/API/Controllers/CollectionTest.java index 30c3a876..4594be41 100644 --- a/src/test/java/io/kuzzle/test/API/Controllers/CollectionTest.java +++ b/src/test/java/io/kuzzle/test/API/Controllers/CollectionTest.java @@ -179,6 +179,37 @@ public void getMappingShouldThrowWhenNotConnected() throws NotConnectedException kuzzleMock.getCollectionController().getMapping(index, collection); } + @Test + public void deleteSpecificationsCollectionTest() throws NotConnectedException, InternalException { + + Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol)); + String index = "nyc-open-data"; + String collection = "yellow-taxi"; + + ArgumentCaptor arg = ArgumentCaptor.forClass(KuzzleMap.class); + + kuzzleMock.getCollectionController().deleteSpecifications(index, collection); + Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture()); + + assertEquals((arg.getValue()).getString("controller"), "collection"); + assertEquals((arg.getValue()).getString("action"), "deleteSpecifications"); + assertEquals((arg.getValue()).getString("index"), "nyc-open-data"); + assertEquals((arg.getValue()).getString("collection"), "yellow-taxi"); + } + + @Test(expected = NotConnectedException.class) + public void deleteSpecificationsCollectionThrowWhenNotConnected() 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"; + + kuzzleMock.getCollectionController().deleteSpecifications(index, collection); + } + @Test public void getSpecificationsCollectionTest() throws NotConnectedException, InternalException {