Search in sources :

Example 11 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class ProjectServiceTest method validateFileLinks.

private void validateFileLinks(ItemReference item) {
    Link link = item.getLink("delete");
    assertNotNull(link);
    assertEquals(link.getMethod(), DELETE);
    assertEquals(link.getHref(), "http://localhost:8080/api/project" + item.getPath());
    link = item.getLink("update content");
    assertNotNull(link);
    assertEquals(link.getMethod(), PUT);
    assertEquals(link.getConsumes(), "*/*");
    assertEquals(link.getHref(), "http://localhost:8080/api/project" + "/file" + item.getPath());
}
Also used : Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Example 12 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class ProjectServiceLinksInjectorTest method verifyFileLinks.

@Test
public void verifyFileLinks() throws Exception {
    ItemReference itemReference = DtoFactory.newDto(ItemReference.class);
    itemReference.withPath(FILE_PATH);
    ItemReference result = projectServiceLinksInjector.injectFileLinks(itemReference, serviceContext);
    assertEquals(3, result.getLinks().size());
    Link updateLink = result.getLink("update content");
    assertNotNull(updateLink);
    assertEquals("localhost:8080/project/file/project1/folder/file", updateLink.getHref());
    assertEquals(HttpMethod.PUT, updateLink.getMethod());
    assertEquals(LINK_REL_UPDATE_CONTENT, updateLink.getRel());
    assertEquals(null, updateLink.getProduces());
    assertEquals(MediaType.WILDCARD, updateLink.getConsumes());
    Link getContentLink = result.getLink("get content");
    assertNotNull(getContentLink);
    assertEquals("localhost:8080/project/file/project1/folder/file", getContentLink.getHref());
    assertEquals(HttpMethod.GET, getContentLink.getMethod());
    assertEquals(LINK_REL_GET_CONTENT, getContentLink.getRel());
    assertEquals(APPLICATION_JSON, getContentLink.getProduces());
    Link deleteLink = result.getLink("delete");
    assertNotNull(deleteLink);
    assertEquals("localhost:8080/project/project1/folder/file", deleteLink.getHref());
    assertEquals(HttpMethod.DELETE, deleteLink.getMethod());
    assertEquals(LINK_REL_DELETE, deleteLink.getRel());
}
Also used : ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) Link(org.eclipse.che.api.core.rest.shared.dto.Link) Test(org.testng.annotations.Test)

Example 13 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class RecipeWidgetImplTest method recipeURLShouldBeReturned.

@Test
public void recipeURLShouldBeReturned() {
    Link link = mock(Link.class);
    when(descriptor.getLink(anyString())).thenReturn(link);
    tag.getRecipeUrl();
    verify(descriptor).getLink("get recipe script");
    verify(link).getHref();
}
Also used : Link(org.eclipse.che.api.core.rest.shared.dto.Link) Test(org.junit.Test)

Example 14 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class ProjectServiceLinksInjector method injectFolderLinks.

/**
     * Adds links for working with a folder.
     * Operations which are supported:
     * <p>get children</p>
     * <p>get tree</p>
     * <p>delete</p>
     *
     * @param itemReference
     *         information about node
     * @param serviceContext
     *         context of {@link ProjectService}
     * @return node with injected folder's links
     */
public ItemReference injectFolderLinks(ItemReference itemReference, ServiceContext serviceContext) {
    final UriBuilder uriBuilder = getUriBuilder(serviceContext);
    final List<Link> links = new ArrayList<>();
    final String relPath = itemReference.getPath().substring(1);
    links.add(createLink(GET, tuneUrl(uriBuilder.clone().path(ProjectService.class).path(ProjectService.class, "getChildren").build(new String[] { relPath }, false)), APPLICATION_JSON, LINK_REL_CHILDREN));
    links.add(createLink(GET, tuneUrl(uriBuilder.clone().path(ProjectService.class).path(ProjectService.class, "getTree").build(new String[] { relPath }, false)), APPLICATION_JSON, LINK_REL_TREE));
    links.add(createLink(DELETE, tuneUrl(uriBuilder.clone().path(ProjectService.class).path(ProjectService.class, "delete").build(new String[] { relPath }, false)), LINK_REL_DELETE));
    return itemReference.withLinks(links);
}
Also used : ArrayList(java.util.ArrayList) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link) LinksHelper.createLink(org.eclipse.che.api.core.util.LinksHelper.createLink)

Example 15 with Link

use of org.eclipse.che.api.core.rest.shared.dto.Link in project che by eclipse.

the class RemoteOAuthTokenProviderTest method shouldConstructCorrectUrl.

@Test
public void shouldConstructCorrectUrl() throws Exception {
    //given
    OAuthToken expected = DtoFactory.newDto(OAuthToken.class).withScope("scope").withToken("token");
    when(httpJsonResponse.asDto(any(Class.class))).thenReturn(expected);
    when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
    //when
    tokenProvider.getToken("google", "id");
    //then
    ArgumentCaptor<Link> argumentCaptor = ArgumentCaptor.forClass(Link.class);
    verify(httpJsonRequestFactory).fromLink(argumentCaptor.capture());
    Link link = argumentCaptor.getValue();
    assertEquals(link.getMethod(), "GET");
    assertEquals(link.getHref(), "http://dev.box.com/api/oauth/token?oauth_provider=google");
    assertEquals(link.getParameters().size(), 0);
}
Also used : OAuthToken(org.eclipse.che.api.auth.shared.dto.OAuthToken) Link(org.eclipse.che.api.core.rest.shared.dto.Link) Test(org.testng.annotations.Test)

Aggregations

Link (org.eclipse.che.api.core.rest.shared.dto.Link)40 UriBuilder (javax.ws.rs.core.UriBuilder)15 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)13 ArrayList (java.util.ArrayList)11 Test (org.testng.annotations.Test)11 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)7 LinkParameter (org.eclipse.che.api.core.rest.shared.dto.LinkParameter)7 LinkedList (java.util.LinkedList)4 HttpMethod (javax.ws.rs.HttpMethod)2 Produces (javax.ws.rs.Produces)2 Description (org.eclipse.che.api.core.rest.annotations.Description)2 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)2 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1