Search in sources :

Example 46 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class WorkspaceConfigurationFilterTest method filterWhenWorkspaceExists.

@Test
public void filterWhenWorkspaceExists() throws ServletException, IOException {
    CloudbreakUser cbUser = createCbUserWithCrn();
    when(authenticatedUserService.getCbUser()).thenReturn(cbUser);
    when(userService.getOrCreate(any())).thenReturn(new User());
    when(workspaceService.getByName(anyString(), any())).thenReturn(Optional.of(createWorkspace()));
    underTest.doFilterInternal(request, response, filterChain);
    verify(workspaceService, times(1)).getByName(eq(Crn.fromString(cbUser.getUserCrn()).getAccountId()), any());
    verify(workspaceService, times(0)).getByName(eq(cbUser.getTenant()), any());
}
Also used : CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Test(org.junit.Test)

Example 47 with CloudbreakUser

use of com.sequenceiq.cloudbreak.common.user.CloudbreakUser in project cloudbreak by hortonworks.

the class WorkspaceConfigurationFilterTest method filterWhenWorkspaceDoesntExist.

@Test
public void filterWhenWorkspaceDoesntExist() throws ServletException, IOException {
    CloudbreakUser cbUser = createCbUserWithCrn();
    when(authenticatedUserService.getCbUser()).thenReturn(cbUser);
    when(userService.getOrCreate(any())).thenReturn(new User());
    when(workspaceService.getByName(anyString(), any())).thenReturn(Optional.empty());
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Tenant default workspace does not exist!");
    underTest.doFilterInternal(request, response, filterChain);
    verify(workspaceService, times(1)).getByName(eq(Crn.fromString(cbUser.getUserCrn()).getAccountId()), any());
    verify(workspaceService, times(0)).getByName(eq(cbUser.getTenant()), any());
}
Also used : CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) Test(org.junit.Test)

Aggregations

CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)47 User (com.sequenceiq.cloudbreak.workspace.model.User)24 Test (org.junit.jupiter.api.Test)10 Workspace (com.sequenceiq.cloudbreak.workspace.model.Workspace)8 Optional (java.util.Optional)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 Test (org.junit.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)3 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)3 Collection (java.util.Collection)3 UserManagementProto (com.cloudera.thunderhead.service.usermanagement.UserManagementProto)2 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 TransactionRuntimeExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2