Search in sources :

Example 1 with UserDto

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

the class UserServiceTest method shouldNotCreateUserFromEntityIfPasswordIsNotValid.

@Test
public void shouldNotCreateUserFromEntityIfPasswordIsNotValid() throws Exception {
    final UserDto newUser = newDto(UserDto.class).withEmail("test@codenvy.com").withName("test").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)

Example 2 with UserDto

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

the class UserServiceTest method shouldNotCreateUserFromEntityIfEmailIsNull.

@Test
public void shouldNotCreateUserFromEntityIfEmailIsNull() throws Exception {
    final UserDto newUser = newDto(UserDto.class).withName("test").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(), 400);
    assertEquals(unwrapError(response), "User email required");
}
Also used : Response(com.jayway.restassured.response.Response) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) Test(org.testng.annotations.Test)

Example 3 with UserDto

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

the class UserLinksInjectorTest method shouldInjectLinks.

@Test
public void shouldInjectLinks() throws Exception {
    final UserDto userDto = DtoFactory.newDto(UserDto.class).withId("user123").withEmail("user@codenvy.com").withName("user");
    linksInjector.injectLinks(userDto, serviceContext);
    // [rel, method] pairs links
    final Set<Pair<String, String>> links = userDto.getLinks().stream().map(link -> Pair.of(link.getMethod(), link.getRel())).collect(Collectors.toSet());
    final Set<Pair<String, String>> expectedLinks = new HashSet<>(asList(Pair.of("GET", Constants.LINK_REL_SELF), Pair.of("GET", Constants.LINK_REL_CURRENT_USER), Pair.of("GET", Constants.LINK_REL_PROFILE), Pair.of("GET", Constants.LINK_REL_CURRENT_USER_SETTINGS), Pair.of("GET", Constants.LINK_REL_PREFERENCES), Pair.of("POST", Constants.LINK_REL_CURRENT_USER_PASSWORD)));
    assertEquals(links, expectedLinks, "Difference " + Sets.symmetricDifference(links, expectedLinks) + "\n");
}
Also used : InjectMocks(org.mockito.InjectMocks) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) Listeners(org.testng.annotations.Listeners) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ServiceContext(org.eclipse.che.api.core.rest.ServiceContext) Mock(org.mockito.Mock) BeforeMethod(org.testng.annotations.BeforeMethod) Set(java.util.Set) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Mockito.when(org.mockito.Mockito.when) Pair(org.eclipse.che.commons.lang.Pair) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) UriBuilderImpl(org.everrest.core.impl.uri.UriBuilderImpl) HashSet(java.util.HashSet) Arrays.asList(java.util.Arrays.asList) DtoFactory(org.eclipse.che.dto.server.DtoFactory) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) Pair(org.eclipse.che.commons.lang.Pair) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with UserDto

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

the class UserServiceTest method shouldNotCreateUserFromEntityIfNameIsNull.

@Test
public void shouldNotCreateUserFromEntityIfNameIsNull() throws Exception {
    final UserDto newUser = newDto(UserDto.class).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(), 400);
    assertEquals(unwrapError(response), "User name required");
}
Also used : Response(com.jayway.restassured.response.Response) UserDto(org.eclipse.che.api.user.shared.dto.UserDto) Test(org.testng.annotations.Test)

Example 5 with UserDto

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

the class UserServiceTest method shouldBeAbleToFindUserByEmail.

@Test
public void shouldBeAbleToFindUserByEmail() throws Exception {
    final UserImpl testUser = copySubject();
    when(userManager.getByEmail(testUser.getEmail())).thenReturn(testUser);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/user/find?email=" + testUser.getEmail());
    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)

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