Search in sources :

Example 1 with ServiceContext

use of org.eclipse.che.api.core.rest.ServiceContext in project che by eclipse.

the class ProfileLinksInjectorTest method shouldInjectProfileLinks.

@Test
public void shouldInjectProfileLinks() throws Exception {
    final ProfileDto profileDto = DtoFactory.newDto(ProfileDto.class).withUserId("user123").withEmail("user@codenvy.com");
    linksInjector.injectLinks(profileDto, serviceContext);
    // [rel, method] pairs links
    final Set<Pair<String, String>> links = profileDto.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_PROFILE), Pair.of("PUT", Constants.LINK_REL_PROFILE_ATTRIBUTES), Pair.of("PUT", Constants.LINK_REL_CURRENT_PROFILE_ATTRIBUTES), Pair.of("DELETE", Constants.LINK_REL_CURRENT_PROFILE_ATTRIBUTES)));
    assertEquals(links, expectedLinks, "Difference " + Sets.symmetricDifference(links, expectedLinks) + "\n");
}
Also used : InjectMocks(org.mockito.InjectMocks) Listeners(org.testng.annotations.Listeners) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ServiceContext(org.eclipse.che.api.core.rest.ServiceContext) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) 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) ProfileDto(org.eclipse.che.api.user.shared.dto.ProfileDto) Pair(org.eclipse.che.commons.lang.Pair) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with ServiceContext

use of org.eclipse.che.api.core.rest.ServiceContext 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)

Aggregations

Sets (com.google.common.collect.Sets)2 Arrays.asList (java.util.Arrays.asList)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ServiceContext (org.eclipse.che.api.core.rest.ServiceContext)2 Pair (org.eclipse.che.commons.lang.Pair)2 DtoFactory (org.eclipse.che.dto.server.DtoFactory)2 UriBuilderImpl (org.everrest.core.impl.uri.UriBuilderImpl)2 InjectMocks (org.mockito.InjectMocks)2 Mock (org.mockito.Mock)2 Mockito.when (org.mockito.Mockito.when)2 MockitoTestNGListener (org.mockito.testng.MockitoTestNGListener)2 Assert.assertEquals (org.testng.Assert.assertEquals)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Listeners (org.testng.annotations.Listeners)2 Test (org.testng.annotations.Test)2 ProfileDto (org.eclipse.che.api.user.shared.dto.ProfileDto)1 UserDto (org.eclipse.che.api.user.shared.dto.UserDto)1