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/get-specifications/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
code: true
type: page
title: getSpecifications
description: Returns the validation specifications
---

# getSpecifications

Returns the validation specifications associated to the given index and collection.

<br/>

```java
public CompletableFuture<ConcurrentHashMap<String, Object>> getSpecifications(
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 `ConcurrentHashMap<String, Object>` representing the collection specifications.

## Usage

<<< ./snippets/get-specifications.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ConcurrentHashMap<String, Object> result = kuzzle
.getCollectionController()
.getSpecifications("nyc-open-data", "yellow-taxi")
.get();

/*
{
collection="yellow-taxi",
index="nyc-open-data",
validation={
fields={
age={
defaultValue=42,
mandatory=true,
type="integer"
}
},
strict=true
}
}
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: collection#getSpecifications
description: Returns the validation specifications
hooks:
before: |
curl -X DELETE kuzzle:7512/nyc-open-data
curl -X POST kuzzle:7512/nyc-open-data/_create
curl -X PUT kuzzle:7512/nyc-open-data/yellow-taxi
curl -X PUT -H "Content-Type: application/json" -d '{ "strict": false, "fields": {"license": {"type": "string"} } }' kuzzle:7512/nyc-open-data/yellow-taxi/_specifications
after:
template: print-result
expected: 'fields'
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,31 @@ public CompletableFuture<ConcurrentHashMap<String, Object>> getMapping(
.thenApplyAsync(
(response) -> (ConcurrentHashMap<String, Object>) response.result);
}

/**
* Gets the validation specifications associated to the given index and collection.
*
* @param index
* @param collection
* @return a CompletableFuture
* @throws NotConnectedException
* @throws InternalException
*/
public CompletableFuture<ConcurrentHashMap<String, Object>> getSpecifications(
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", "getSpecifications");

return kuzzle
.query(query)
.thenApplyAsync(
(response) -> (ConcurrentHashMap<String, Object>) response.result);
}
}
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 @@ -178,4 +178,35 @@ public void getMappingShouldThrowWhenNotConnected() throws NotConnectedException

kuzzleMock.getCollectionController().getMapping(index, collection);
}

@Test
public void getSpecificationsCollectionTest() 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().getSpecifications(index, collection);
Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture());

assertEquals((arg.getValue()).getString("controller"), "collection");
assertEquals((arg.getValue()).getString("action"), "getSpecifications");
assertEquals((arg.getValue()).getString("index"), "nyc-open-data");
assertEquals((arg.getValue()).getString("collection"), "yellow-taxi");
}

@Test(expected = NotConnectedException.class)
public void getSpecificationsCollectionThrowWhenNotConnected() 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().getSpecifications(index, collection);
}
}