Search in sources :

Example 11 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserService method create.

@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@GenerateLink(rel = LINK_REL_USER)
@ApiOperation(value = "Create a new user", response = UserDto.class)
@ApiResponses({ @ApiResponse(code = 201, message = "User successfully created, response contains created entity"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 401, message = "Missed token parameter"), @ApiResponse(code = 500, message = "Couldn't create user due to internal server error") })
public Response create(@ApiParam("New user") UserDto userDto, @ApiParam("Authentication token") @QueryParam("token") String token, @ApiParam("User type") @QueryParam("temporary") @DefaultValue("false") Boolean isTemporary) throws BadRequestException, UnauthorizedException, ConflictException, ServerException {
    if (userDto != null) {
        //should be generated by userManager
        userDto.setId(null);
    }
    final User newUser = token == null ? userDto : tokenValidator.validateToken(token);
    userValidator.checkUser(newUser);
    return Response.status(CREATED).entity(linksInjector.injectLinks(asDto(userManager.create(newUser, isTemporary)), getServiceContext())).build();
}
Also used : User(org.eclipse.che.api.core.model.user.User) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserManagerTest method shouldGetUserById.

@Test
public void shouldGetUserById() throws Exception {
    final User user = new UserImpl("identifier", "test@email.com", "testName", "password", Collections.singletonList("alias"));
    when(manager.getById(user.getId())).thenReturn(user);
    assertEquals(manager.getById(user.getId()), user);
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 13 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserManagerTest method shouldThrowConflictExceptionOnCreationIfUserNameIsReserved.

@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionOnCreationIfUserNameIsReserved() throws Exception {
    final User user = new UserImpl("id", "test@email.com", "reserved");
    manager.create(user, false);
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 14 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserManagerTest method shouldUpdateUser.

@Test
public void shouldUpdateUser() throws Exception {
    final User user = new UserImpl("identifier", "test@email.com", "testName", "password", Collections.emptyList());
    manager.update(user);
    verify(userDao).update(new UserImpl(user));
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 15 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserManagerTest method shouldGetUserByAlias.

@Test
public void shouldGetUserByAlias() throws Exception {
    final User user = new UserImpl("identifier", "test@email.com", "testName", "password", Collections.singletonList("alias"));
    when(manager.getByAlias("alias")).thenReturn(user);
    assertEquals(manager.getByAlias("alias"), user);
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Aggregations

User (org.eclipse.che.api.core.model.user.User)17 Test (org.testng.annotations.Test)15 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)14 Response (com.jayway.restassured.response.Response)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Inject (javax.inject.Inject)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 Page (org.eclipse.che.api.core.Page)2 ServerException (org.eclipse.che.api.core.ServerException)2 EventService (org.eclipse.che.api.core.notification.EventService)2 EventSubscriber (org.eclipse.che.api.core.notification.EventSubscriber)2 Constants (org.eclipse.che.api.user.server.Constants)2 BeforeUserRemovedEvent (org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent)2 PostUserPersistedEvent (org.eclipse.che.api.user.server.event.PostUserPersistedEvent)2 UserRemovedEvent (org.eclipse.che.api.user.server.event.UserRemovedEvent)2