Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions doc/3/controllers/collection/delete-specifications/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
code: true
type: page
title: deleteSpecifications
description: Delete validation specifications for a collection
---

# deleteSpecifications

Deletes validation specifications for a collection.

<br/>

```java
public CompletableFuture<Void> deleteSpecifications(
final String index,
final String collection)
```

<br/>

| Arguments | Type | Description |
| ------------ | ----------------- | --------------- |
| `index` | <pre>String</pre> | Index name |
| `collection` | <pre>String</pre> | Collection name |

## Returns

Returns a `CompletableFuture<Void>`.

## Usage

<<< ./snippets/delete-specifications.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kuzzle
.getCollectionController()
.deleteSpecifications("nyc-open-data", "yellow-taxi")
.get();
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ public CompletableFuture<ConcurrentHashMap<String, Object>> getMapping(
(response) -> (ConcurrentHashMap<String, Object>) 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<Void> 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.
*
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/io/kuzzle/test/API/Controllers/CollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<KuzzleMap> 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<ProtocolState>) 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 {

Expand Down