@Test public void testRewriteNoQuery() throws URISyntaxException { UriBuilder builder = mock(UriBuilder.class); when(builder.path(anyString())).thenReturn(builder); URI uri = new URI("http: PathSegment segment1 = mock(PathSegment.class); when(segment1.getPath()).thenReturn("v1"); PathSegment segment2 = mock(PathSegment.class); when(segment2.getPath()).thenReturn("students"); List<PathSegment> segments = new ArrayList<PathSegment>(); segments.add(segment1); segments.add(segment2); when(containerRequest.getPathSegments()).thenReturn(segments); when(containerRequest.getBaseUriBuilder()).thenReturn(builder); when(containerRequest.getRequestUri()).thenReturn(uri); when(containerRequest.getPath()).thenReturn("http: when(containerRequest.getProperties()).thenReturn(new HashMap<String, Object>()); ContainerRequest request = versionFilter.filter(containerRequest); verify(containerRequest).setUris((URI) any(), (URI) any()); verify(builder).build(); verify(builder, times(1)).path("v1.5"); verify(builder, times(1)).path("students"); assertEquals("Should match", "http: }
@Override public ContainerRequest filter(ContainerRequest containerRequest) { List<PathSegment> segments = containerRequest.getPathSegments(); if (!segments.isEmpty()) { String version = segments.get(0).getPath(); boolean isBulkNonVersion = version.equals("bulk"); SortedSet<String> minorVersions = resourceEndPoint.getNameSpaceMappings().get(version); String newVersion = null; if(isBulkNonVersion || (segments.size() > 1 && segments.get(1).getPath().equals("bulk"))) { if (!isBulkNonVersion) { segments.remove(0); } else { version = ""; } newVersion = getLatestApiVersion(version); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } else if ((minorVersions != null) && !minorVersions.isEmpty()) { segments.remove(0); newVersion = version + "." + minorVersions.last(); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } } return containerRequest; }
VersionFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { List<PathSegment> segments = containerRequest.getPathSegments(); if (!segments.isEmpty()) { String version = segments.get(0).getPath(); boolean isBulkNonVersion = version.equals("bulk"); SortedSet<String> minorVersions = resourceEndPoint.getNameSpaceMappings().get(version); String newVersion = null; if(isBulkNonVersion || (segments.size() > 1 && segments.get(1).getPath().equals("bulk"))) { if (!isBulkNonVersion) { segments.remove(0); } else { version = ""; } newVersion = getLatestApiVersion(version); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } else if ((minorVersions != null) && !minorVersions.isEmpty()) { segments.remove(0); newVersion = version + "." + minorVersions.last(); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } } return containerRequest; } }
VersionFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { List<PathSegment> segments = containerRequest.getPathSegments(); if (!segments.isEmpty()) { String version = segments.get(0).getPath(); boolean isBulkNonVersion = version.equals("bulk"); SortedSet<String> minorVersions = resourceEndPoint.getNameSpaceMappings().get(version); String newVersion = null; if(isBulkNonVersion || (segments.size() > 1 && segments.get(1).getPath().equals("bulk"))) { if (!isBulkNonVersion) { segments.remove(0); } else { version = ""; } newVersion = getLatestApiVersion(version); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } else if ((minorVersions != null) && !minorVersions.isEmpty()) { segments.remove(0); newVersion = version + "." + minorVersions.last(); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } } return containerRequest; }  }
VersionFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { List<PathSegment> segments = containerRequest.getPathSegments(); if (!segments.isEmpty()) { String version = segments.get(0).getPath(); boolean isBulkNonVersion = version.equals("bulk"); SortedSet<String> minorVersions = resourceEndPoint.getNameSpaceMappings().get(version); String newVersion = null; if(isBulkNonVersion || (segments.size() > 1 && segments.get(1).getPath().equals("bulk"))) { if (!isBulkNonVersion) { segments.remove(0); } else { version = ""; } newVersion = getLatestApiVersion(version); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } else if ((minorVersions != null) && !minorVersions.isEmpty()) { segments.remove(0); newVersion = version + "." + minorVersions.last(); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } } return containerRequest; }  @Override ContainerRequest filter(ContainerRequest containerRequest); String getLatestApiVersion(String requestedVersion); }
VersionFilter implements ContainerRequestFilter { @Override public ContainerRequest filter(ContainerRequest containerRequest) { List<PathSegment> segments = containerRequest.getPathSegments(); if (!segments.isEmpty()) { String version = segments.get(0).getPath(); boolean isBulkNonVersion = version.equals("bulk"); SortedSet<String> minorVersions = resourceEndPoint.getNameSpaceMappings().get(version); String newVersion = null; if(isBulkNonVersion || (segments.size() > 1 && segments.get(1).getPath().equals("bulk"))) { if (!isBulkNonVersion) { segments.remove(0); } else { version = ""; } newVersion = getLatestApiVersion(version); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } else if ((minorVersions != null) && !minorVersions.isEmpty()) { segments.remove(0); newVersion = version + "." + minorVersions.last(); updateContainerRequest(containerRequest, segments, newVersion); LOG.info("Version Rewrite: {} --> {}", new Object[] { version, newVersion }); } } return containerRequest; }  @Override ContainerRequest filter(ContainerRequest containerRequest); String getLatestApiVersion(String requestedVersion);  }