ProfileLinksInjector { public ProfileDto injectLinks(ProfileDto profileDto, ServiceContext serviceContext) { final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder(); final List<Link> links = new ArrayList<>(5); links.add( createLink( HttpMethod.GET, uriBuilder.clone().path(ProfileService.class, "getCurrent").build().toString(), null, APPLICATION_JSON, LINK_REL_CURRENT_PROFILE)); links.add( createLink( HttpMethod.GET, uriBuilder .clone() .path(ProfileService.class, "getById") .build(profileDto.getUserId()) .toString(), null, APPLICATION_JSON, LINK_REL_SELF)); links.add( createLink( HttpMethod.PUT, uriBuilder.clone().path(ProfileService.class, "updateAttributes").build().toString(), APPLICATION_JSON, APPLICATION_JSON, LINK_REL_CURRENT_PROFILE_ATTRIBUTES)); links.add( createLink( HttpMethod.DELETE, uriBuilder .clone() .path(ProfileService.class, "removeAttributes") .build(profileDto.getUserId()) .toString(), APPLICATION_JSON, APPLICATION_JSON, LINK_REL_CURRENT_PROFILE_ATTRIBUTES)); links.add( createLink( HttpMethod.PUT, uriBuilder .clone() .path(ProfileService.class, "updateAttributesById") .build(profileDto.getUserId()) .toString(), APPLICATION_JSON, APPLICATION_JSON, LINK_REL_PROFILE_ATTRIBUTES)); return profileDto.withLinks(links); }  ProfileDto injectLinks(ProfileDto profileDto, ServiceContext serviceContext);  }
@Test public void shouldInjectProfileLinks() throws Exception { final ProfileDto profileDto = DtoFactory.newDto(ProfileDto.class).withUserId("user123").withEmail("user@codenvy.com"); linksInjector.injectLinks(profileDto, serviceContext); 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"); }