Search in sources :

Example 1 with ServiceDescriptor

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

the class RemoteServiceDescriptorTest method shouldBeAbleToReturnServiceDescriptors.

@Test
public void shouldBeAbleToReturnServiceDescriptors() throws Exception {
    remoteServiceDescriptor = new RemoteServiceDescriptor(serverUrl + SERVICE_PATH, requestFactory);
    final ServiceDescriptor serviceDescriptor = remoteServiceDescriptor.getServiceDescriptor();
    assertNotNull(serviceDescriptor);
    assertEquals(serviceDescriptor.getHref(), serverUrl + SERVICE_PATH);
    assertEquals(serviceDescriptor.getDescription(), SERVICE_DESCRIPTION);
    assertEquals(serviceDescriptor.getLinks().size(), 1);
}
Also used : ServiceDescriptor(org.eclipse.che.api.core.rest.shared.dto.ServiceDescriptor) Test(org.testng.annotations.Test)

Example 2 with ServiceDescriptor

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

the class Service method generateServiceDescriptor.

private ServiceDescriptor generateServiceDescriptor(UriInfo uriInfo, Class<? extends Service> service) {
    final List<Link> links = new ArrayList<>();
    for (Method method : service.getMethods()) {
        final GenerateLink generateLink = method.getAnnotation(GenerateLink.class);
        if (generateLink != null) {
            try {
                links.add(generateLinkForMethod(uriInfo, generateLink.rel(), method));
            } catch (RuntimeException ignored) {
            }
        }
    }
    final Description description = service.getAnnotation(Description.class);
    final ServiceDescriptor dto = createServiceDescriptor().withHref(uriInfo.getRequestUriBuilder().replaceQuery(null).build().toString()).withLinks(links).withVersion(Constants.API_VERSION);
    if (description != null) {
        dto.setDescription(description.value());
    }
    return dto;
}
Also used : Description(org.eclipse.che.api.core.rest.annotations.Description) ServiceDescriptor(org.eclipse.che.api.core.rest.shared.dto.ServiceDescriptor) ArrayList(java.util.ArrayList) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) HttpMethod(javax.ws.rs.HttpMethod) Method(java.lang.reflect.Method) Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Example 3 with ServiceDescriptor

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

the class ServiceDescriptorTest method getDescriptor.

private ServiceDescriptor getDescriptor() throws Exception {
    String path = SERVICE_URI;
    ContainerResponse response = launcher.service(HttpMethod.OPTIONS, path, BASE_URI, null, null, null, null);
    Assert.assertEquals(response.getStatus(), 200);
    return (ServiceDescriptor) response.getEntity();
}
Also used : ContainerResponse(org.everrest.core.impl.ContainerResponse) ServiceDescriptor(org.eclipse.che.api.core.rest.shared.dto.ServiceDescriptor)

Aggregations

ServiceDescriptor (org.eclipse.che.api.core.rest.shared.dto.ServiceDescriptor)3 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HttpMethod (javax.ws.rs.HttpMethod)1 Description (org.eclipse.che.api.core.rest.annotations.Description)1 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)1 Link (org.eclipse.che.api.core.rest.shared.dto.Link)1 ContainerResponse (org.everrest.core.impl.ContainerResponse)1 Test (org.testng.annotations.Test)1