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));
}
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));
}
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;
}
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;
}
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);
}
Aggregations