Search in sources :

Example 6 with UserDto

use of org.eclipse.che.api.user.shared.dto.UserDto in project che by eclipse.

the class UserServiceTest method shouldCreateUserFromEntity.

@Test
public void shouldCreateUserFromEntity() throws Exception {
    final UserDto newUser = newDto(UserDto.class).withName("test").withEmail("test@codenvy.com").withPassword("password12345");
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().body(newUser).contentType("application/json").post(SECURE_PATH + "/user");
    assertEquals(response.statusCode(), 201);
    verify(userManager).create(userCaptor.capture(), anyBoolean());
    final User user = userCaptor.getValue();
    assertEquals(user.getEmail(), "test@codenvy.com");
    assertEquals(user.getName(), "test");
    assertEquals(user.getPassword(), "password12345");
}
Also used : Response(com.jayway.restassured.response.Response) User(org.eclipse.che.api.core.model.user.User) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) Test(org.testng.annotations.Test)

Example 7 with UserDto

use of org.eclipse.che.api.user.shared.dto.UserDto in project che by eclipse.

the class UserServiceTest method shouldBeAbleToGetUserById.

@Test
public void shouldBeAbleToGetUserById() throws Exception {
    final UserImpl testUser = copySubject();
    when(userManager.getById(SUBJECT.getUserId())).thenReturn(testUser);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/user/" + SUBJECT.getUserId());
    assertEquals(response.getStatusCode(), 200);
    final UserDto fetchedUser = unwrapDto(response, UserDto.class);
    assertEquals(fetchedUser.getId(), testUser.getId());
    assertEquals(fetchedUser.getName(), testUser.getName());
    assertEquals(fetchedUser.getEmail(), testUser.getEmail());
}
Also used : Response(com.jayway.restassured.response.Response) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 8 with UserDto

use of org.eclipse.che.api.user.shared.dto.UserDto in project che by eclipse.

the class UserServiceTest method shouldBeAbleToFindUserByName.

@Test
public void shouldBeAbleToFindUserByName() throws Exception {
    final UserImpl testUser = copySubject();
    when(userManager.getByName(testUser.getName())).thenReturn(testUser);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/user/find?name=" + testUser.getName());
    assertEquals(response.getStatusCode(), 200);
    final UserDto fetchedUser = unwrapDto(response, UserDto.class);
    assertEquals(fetchedUser.getId(), testUser.getId());
    assertEquals(fetchedUser.getName(), testUser.getName());
    assertEquals(fetchedUser.getEmail(), testUser.getEmail());
}
Also used : Response(com.jayway.restassured.response.Response) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 9 with UserDto

use of org.eclipse.che.api.user.shared.dto.UserDto in project che by eclipse.

the class UserServiceTest method shouldNotCreateUserFromEntityWhenPasswordIsNotValid.

@Test
public void shouldNotCreateUserFromEntityWhenPasswordIsNotValid() throws Exception {
    final UserDto newUser = newDto(UserDto.class).withName("test").withEmail("test@codenvy.com").withPassword("1");
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().body(newUser).contentType("application/json").post(SECURE_PATH + "/user");
    assertEquals(response.statusCode(), 400);
    assertEquals(unwrapError(response), "Password should contain at least 8 characters");
}
Also used : Response(com.jayway.restassured.response.Response) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) Test(org.testng.annotations.Test)

Aggregations

UserDto (org.eclipse.che.api.user.shared.dto.UserDto)9 Test (org.testng.annotations.Test)9 Response (com.jayway.restassured.response.Response)8 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)3 Sets (com.google.common.collect.Sets)1 Arrays.asList (java.util.Arrays.asList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 User (org.eclipse.che.api.core.model.user.User)1 ServiceContext (org.eclipse.che.api.core.rest.ServiceContext)1 Pair (org.eclipse.che.commons.lang.Pair)1 DtoFactory (org.eclipse.che.dto.server.DtoFactory)1 UriBuilderImpl (org.everrest.core.impl.uri.UriBuilderImpl)1 InjectMocks (org.mockito.InjectMocks)1 Mock (org.mockito.Mock)1 Mockito.when (org.mockito.Mockito.when)1 MockitoTestNGListener (org.mockito.testng.MockitoTestNGListener)1 Assert.assertEquals (org.testng.Assert.assertEquals)1 BeforeMethod (org.testng.annotations.BeforeMethod)1