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
45 changes: 45 additions & 0 deletions doc/3/controllers/collection/list/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
code: true
type: page
title: list
description: Returns the collection list of an index
---

# list

Returns the list of collections associated to a provided index.
The returned list is sorted in alphanumerical order.

<br/>

```java
public CompletableFuture<ConcurrentHashMap<String, Object>> list(
final String index) throws NotConnectedException, InternalException
```


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

## Returns

Returns a `ConcurrentHashMap<String, Object>` containing the following properties:

| Property | Type | Description |
| ------------- | ------------------- | ------------------------------------------------------------------ |
| `type` | <pre>String</pre> | Types of returned collections <br/>(`all`, `realtime` or `stored`) |
| `collections` | <pre>ArrayList<Object></pre> | List of collections |
| `from` | <pre>Integer</pre> | Offset of the first result |
| `size` | <pre>Integer</pre> | Maximum number of returned results |

Each object in the `collections` array contains the following properties:

| Property | Type | Description |
| -------- | ----------------- | ---------------------------------------- |
| `name` | <pre>String</pre> | Collection name |
| `type` | <pre>String</pre> | Collection type (`realtime` or `stored`) |

## Usage

<<< ./snippets/list.java
22 changes: 22 additions & 0 deletions doc/3/controllers/collection/list/snippets/list.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ConcurrentHashMap<String, Object> result = kuzzle
.getCollectionController()
.list("nyc-open-data")
.get();

/*
{
size=10,
collections=[
{
name=dark-taxi,
type=stored
},
{
name=pink-taxi,
type=stored
}
],
from=0,
type=all
}
*/
7 changes: 7 additions & 0 deletions doc/3/controllers/collection/list/snippets/list.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: collection#list
description: Returns the collection list of an index
hooks:
before: curl -X POST kuzzle:7512/nyc-open-data/_create && curl -X PUT kuzzle:7512/nyc-open-data/pink-taxi && curl -X PUT kuzzle:7512/nyc-open-data/dark-taxi
after:
template: default
expected: Success
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,27 @@ public CompletableFuture<ConcurrentHashMap<String, Object>> updateSpecifications
.thenApplyAsync(
(response) -> (ConcurrentHashMap<String, Object>) response.result);
}

/**
* List collections.
*
* @param index
* @return a CompletableFuture
* @throws NotConnectedException
* @throws InternalException
*/
public CompletableFuture<ConcurrentHashMap<String, Object>> list(
final String index) throws NotConnectedException, InternalException {

final KuzzleMap query = new KuzzleMap();
query
.put("index", index)
.put("controller", "collection")
.put("action", "list");

return kuzzle
.query(query)
.thenApplyAsync(
(response) -> (ConcurrentHashMap<String, Object>) response.result);
}
}
28 changes: 27 additions & 1 deletion src/test/java/io/kuzzle/test/API/Controllers/CollectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public void getMappingCollectionTest() throws NotConnectedException, InternalExc
String index = "nyc-open-data";
String collection = "yellow-taxi";


ArgumentCaptor<KuzzleMap> arg = ArgumentCaptor.forClass(KuzzleMap.class);

kuzzleMock.getCollectionController().getMapping(index, collection);
Expand Down Expand Up @@ -374,4 +373,31 @@ public void updateSpecificationsCollectionThrowWhenNotConnected() throws NotConn

kuzzleMock.getCollectionController().updateSpecifications(index, collection, specifications);
}

@Test
public void listCollectionTest() throws NotConnectedException, InternalException {

Kuzzle kuzzleMock = spy(new Kuzzle(networkProtocol));
String index = "nyc-open-data";

ArgumentCaptor<KuzzleMap> arg = ArgumentCaptor.forClass(KuzzleMap.class);

kuzzleMock.getCollectionController().list(index);
Mockito.verify(kuzzleMock, Mockito.times(1)).query(arg.capture());

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

@Test(expected = NotConnectedException.class)
public void listCollectionShouldThrowWhenNotConnected() 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";

kuzzleMock.getCollectionController().list(index);
}
}