Search in sources :

Example 41 with PathSegment

use of javax.ws.rs.core.PathSegment in project microservice_framework by CJSCommonPlatform.

the class UrlLinkFactoryTest method shouldReturnEventStreamsHeadUrlLink.

@SuppressWarnings("unchecked")
@Test
public void shouldReturnEventStreamsHeadUrlLink() throws Exception {
    final UUID streamId = UUID.randomUUID();
    final String eventStreamPathSegmentValue = "eventstreams";
    final String baseURI = "http://localhost:8080/context/";
    final String urlString = baseURI + "/HEAD/BACKWARD/2";
    final int pageSize = 2;
    final UriInfo uriInfo = mock(UriInfo.class);
    final UriBuilder uriBuilder = mock(UriBuilder.class);
    final List<PathSegment> pathSegmentList = mock(List.class);
    final PathSegment eventStreamPathSegment = mock(PathSegment.class);
    final PathSegment streamIdPathSegment = mock(PathSegment.class);
    when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
    when(uriInfo.getPathSegments()).thenReturn(pathSegmentList);
    when(pathSegmentList.get(0)).thenReturn(eventStreamPathSegment);
    when(eventStreamPathSegment.getPath()).thenReturn(eventStreamPathSegmentValue);
    when(pathSegmentList.get(1)).thenReturn(streamIdPathSegment);
    when(streamIdPathSegment.getPath()).thenReturn(streamId.toString());
    when(uriBuilder.path(eventStreamPathSegmentValue)).thenReturn(uriBuilder);
    when(uriBuilder.path(streamId.toString())).thenReturn(uriBuilder);
    when(uriBuilder.path(HEAD)).thenReturn(uriBuilder);
    when(uriBuilder.path("BACKWARD")).thenReturn(uriBuilder);
    when(uriBuilder.path("2")).thenReturn(uriBuilder);
    when(uriBuilder.build()).thenReturn(new URL(urlString).toURI());
    when(positionValueFactory.getPositionValue(head())).thenReturn(HEAD);
    final URL link = urlLinkFactory.createHeadEventStreamsUrlLink(pageSize, uriInfo);
    assertThat(link.toString(), is(urlString));
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UUID(java.util.UUID) UriBuilder(javax.ws.rs.core.UriBuilder) UriInfo(javax.ws.rs.core.UriInfo) URL(java.net.URL) Test(org.junit.Test)

Example 42 with PathSegment

use of javax.ws.rs.core.PathSegment in project microservice_framework by CJSCommonPlatform.

the class UrlLinkFactoryTest method shouldReturnEventStreamsFirstUrlLink.

@SuppressWarnings("unchecked")
@Test
public void shouldReturnEventStreamsFirstUrlLink() throws Exception {
    final UUID streamId = UUID.randomUUID();
    final String eventStreamPathSegmentValue = "eventstreams";
    final String baseURI = "http://localhost:8080/context/";
    final String urlString = baseURI + "/1/FORWARD/2";
    final int pageSize = 2;
    final UriInfo uriInfo = mock(UriInfo.class);
    final UriBuilder uriBuilder = mock(UriBuilder.class);
    final List<PathSegment> pathSegmentList = mock(List.class);
    final PathSegment eventStreamPathSegment = mock(PathSegment.class);
    final PathSegment streamIdPathSegment = mock(PathSegment.class);
    when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
    when(uriInfo.getPathSegments()).thenReturn(pathSegmentList);
    when(pathSegmentList.get(0)).thenReturn(eventStreamPathSegment);
    when(eventStreamPathSegment.getPath()).thenReturn(eventStreamPathSegmentValue);
    when(pathSegmentList.get(1)).thenReturn(streamIdPathSegment);
    when(streamIdPathSegment.getPath()).thenReturn(streamId.toString());
    when(uriBuilder.path(eventStreamPathSegmentValue)).thenReturn(uriBuilder);
    when(uriBuilder.path(streamId.toString())).thenReturn(uriBuilder);
    when(uriBuilder.path(FIRST)).thenReturn(uriBuilder);
    when(uriBuilder.path("FORWARD")).thenReturn(uriBuilder);
    when(uriBuilder.path("2")).thenReturn(uriBuilder);
    when(uriBuilder.build()).thenReturn(new URL(urlString).toURI());
    when(positionValueFactory.getPositionValue(first())).thenReturn(FIRST);
    final URL link = urlLinkFactory.createFirstEventStreamsUrlLink(pageSize, uriInfo);
    assertThat(link.toString(), is(urlString));
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UUID(java.util.UUID) UriBuilder(javax.ws.rs.core.UriBuilder) UriInfo(javax.ws.rs.core.UriInfo) URL(java.net.URL) Test(org.junit.Test)

Example 43 with PathSegment

use of javax.ws.rs.core.PathSegment in project narayana by jbosstm.

the class TxSupport method getUriBuilder.

public static UriBuilder getUriBuilder(UriInfo info, int npaths, String... paths) {
    UriBuilder builder = info.getBaseUriBuilder();
    if (npaths > 0) {
        List<PathSegment> segments = info.getPathSegments();
        for (int i = 0; i < npaths; i++) builder.path(segments.get(i).getPath());
    } else {
        String basePath = info.getMatchedURIs().get(0);
        builder.path(basePath);
    }
    for (String path : paths) builder.path(path);
    return builder;
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) UriBuilder(javax.ws.rs.core.UriBuilder)

Example 44 with PathSegment

use of javax.ws.rs.core.PathSegment in project ovirt-engine by oVirt.

the class UsageFinder method getUsageLink.

private String getUsageLink(UriInfo uriInfo, String httpMethod) {
    List<PathSegment> pathSegments = uriInfo.getPathSegments();
    ServiceTreeNode node = ServiceTree.getTree();
    // step into the Service tree according to the URL.
    for (PathSegment pathSegment : pathSegments) {
        node = step(node, pathSegment);
    }
    // check whether the last step in the URL represent an 'action'.
    PathSegment lastPathSegment = pathSegments.get(pathSegments.size() - 1);
    // Get the prefix of the link, with or without 's' appended to the
    // entity name, according to whether this action is on a single entity
    // or on the collection context, e.g:
    // .../apidoc#services/vm/methods/start    //action on *vm*
    // .../apidoc#services/vms/methods/add     //action on *vms*
    // .../apidoc#services/vm/methods/update   //action on *vm*
    // .../apidoc#services/vm/methods/remove   //action on *vm*
    String link = getLinkPrefix(node);
    if (isAction(node, lastPathSegment.getPath())) {
        link += camelCaseToUnderscore(getAction(node, lastPathSegment.getPath()));
    } else {
        link += getMethodName(httpMethod);
    }
    return link;
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) ServiceTreeNode(org.ovirt.engine.api.rsdl.ServiceTreeNode)

Example 45 with PathSegment

use of javax.ws.rs.core.PathSegment in project ovirt-engine by oVirt.

the class V3UsageFinder method isMatch.

private boolean isMatch(V3DetailedLink link, UriInfo uriInfo, String httpMethod) {
    int baseUriLength = uriInfo.getBaseUri().getPath().length();
    // e.g: [vms, {vm:id}, start]
    Current current = CurrentManager.get();
    int charsToTruncate = current.getVersionSource() == VersionSource.URL ? 0 : current.getVersion().length() + 2;
    String[] linkPathSegments = link.getHref().substring(baseUriLength - charsToTruncate).split("/");
    // e.g: [vms, f26b0918-8e16-4915-b1c2-7f39e568de23, start]
    List<PathSegment> uriPathSegments = uriInfo.getPathSegments();
    return isMatchLength(linkPathSegments, uriPathSegments) && isMatchPath(linkPathSegments, uriPathSegments) && isMatchRel(link.getRel(), httpMethod);
}
Also used : PathSegment(javax.ws.rs.core.PathSegment) Current(org.ovirt.engine.api.restapi.invocation.Current)

Aggregations

PathSegment (javax.ws.rs.core.PathSegment)67 UriInfo (javax.ws.rs.core.UriInfo)18 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)13 UriBuilder (javax.ws.rs.core.UriBuilder)11 Map (java.util.Map)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)10 VFSItem (org.olat.core.util.vfs.VFSItem)10 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)10 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)9 Response (javax.ws.rs.core.Response)8 HashMap (java.util.HashMap)7 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)7 List (java.util.List)6 URI (java.net.URI)5 URL (java.net.URL)5 UUID (java.util.UUID)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)5 Date (java.util.Date)4