Search in sources :

Example 6 with ScopesList

use of io.pravega.controller.server.rest.generated.model.ScopesList in project pravega by pravega.

the class StreamMetaDataAuthFocusedTests method testListScopesReturnsFilteredResults.

@Test
public void testListScopesReturnsFilteredResults() throws ExecutionException, InterruptedException {
    // Arrange
    final String resourceURI = getURI() + "v1/scopes";
    when(mockControllerService.listScopes(anyLong())).thenReturn(CompletableFuture.completedFuture(Arrays.asList("scope1", "scope2", "scope3")));
    Invocation requestInvocation = this.invocationBuilder(resourceURI, USER_ACCESS_TO_SUBSET_OF_SCOPES, DEFAULT_PASSWORD).buildGet();
    // Act
    Response response = requestInvocation.invoke();
    ScopesList scopes = response.readEntity(ScopesList.class);
    // Assert
    assertEquals(1, scopes.getScopes().size());
    assertEquals("scope3", scopes.getScopes().get(0).getScopeName());
    response.close();
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) ScopesList(io.pravega.controller.server.rest.generated.model.ScopesList) AuthFileUtils.credentialsAndAclAsString(io.pravega.auth.AuthFileUtils.credentialsAndAclAsString) Test(org.junit.Test)

Example 7 with ScopesList

use of io.pravega.controller.server.rest.generated.model.ScopesList in project pravega by pravega.

the class StreamMetaDataTests method testlistScopes.

/**
 * Test for listScopes REST API.
 *
 * @throws ExecutionException
 * @throws InterruptedException
 */
@Test(timeout = 30000)
public void testlistScopes() throws ExecutionException, InterruptedException {
    final String resourceURI = getURI() + "v1/scopes";
    // Test to list scopes.
    List<String> scopesList = Arrays.asList("scope1", "scope2", "scope3");
    when(mockControllerService.listScopes(anyLong())).thenReturn(CompletableFuture.completedFuture(scopesList));
    Response response = addAuthHeaders(client.target(resourceURI).request()).buildGet().invoke();
    assertEquals("List Scopes response code", 200, response.getStatus());
    assertTrue(response.bufferEntity());
    verifyScopes(response.readEntity(ScopesList.class));
    response.close();
    // Test for list scopes failure.
    final CompletableFuture<List<String>> completableFuture = new CompletableFuture<>();
    completableFuture.completeExceptionally(new Exception());
    when(mockControllerService.listScopes(anyLong())).thenReturn(completableFuture);
    response = addAuthHeaders(client.target(resourceURI).request()).buildGet().invoke();
    assertEquals("List Scopes response code", 500, response.getStatus());
    response.close();
}
Also used : Response(javax.ws.rs.core.Response) CompletableFuture(java.util.concurrent.CompletableFuture) ScopesList(io.pravega.controller.server.rest.generated.model.ScopesList) StreamsList(io.pravega.controller.server.rest.generated.model.StreamsList) List(java.util.List) ScopesList(io.pravega.controller.server.rest.generated.model.ScopesList) ArrayList(java.util.ArrayList) ReaderGroupsList(io.pravega.controller.server.rest.generated.model.ReaderGroupsList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StoreException(io.pravega.controller.store.stream.StoreException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

ScopesList (io.pravega.controller.server.rest.generated.model.ScopesList)7 Response (javax.ws.rs.core.Response)6 Test (org.junit.Test)5 AuthFileUtils.credentialsAndAclAsString (io.pravega.auth.AuthFileUtils.credentialsAndAclAsString)4 ReaderGroupsList (io.pravega.controller.server.rest.generated.model.ReaderGroupsList)3 StreamsList (io.pravega.controller.server.rest.generated.model.StreamsList)3 StoreException (io.pravega.controller.store.stream.StoreException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Invocation (javax.ws.rs.client.Invocation)3 AuthException (io.pravega.auth.AuthException)1 READ (io.pravega.auth.AuthHandler.Permissions.READ)1 READ_UPDATE (io.pravega.auth.AuthHandler.Permissions.READ_UPDATE)1 ClientConfig (io.pravega.client.ClientConfig)1 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)1 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)1 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)1 ReaderGroup (io.pravega.client.stream.ReaderGroup)1 ReaderGroupNotFoundException (io.pravega.client.stream.ReaderGroupNotFoundException)1