DynamicProxyBasePathFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { String dynamicApplicationPath = getDynamicBasePath(); if (dynamicApplicationPath != null && !dynamicApplicationPath.isEmpty()) { UriInfo uriInfo = requestContext.getUriInfo(); URI baseUri = uriInfo.getBaseUriBuilder() .path(dynamicApplicationPath) .path("/") .build(); URI requestUri = uriInfo.getRequestUri(); requestContext.setRequestUri(baseUri, requestUri); } }  @Override void filter(ContainerRequestContext requestContext);  }
@Test public void filter_NoProxyResourceGiven_ShouldNotUpdateBaseUri() throws IOException { DynamicProxyBasePathFilter filter = createFilter("/a"); filter.filter(null); ContainerRequestContext containerRequest = createContainerRequest("/", "/a"); filter.filter(containerRequest); verifyZeroInteractions(containerRequest); }
@Test public void filter_NullResourceGiven_ShouldNotUpdateBaseUri() throws IOException { DynamicProxyBasePathFilter filter = createFilter(null); filter.filter(null); ContainerRequestContext containerRequest = createContainerRequest("/", "/a"); filter.filter(containerRequest); verifyZeroInteractions(containerRequest); }
@Test public void filter_EmptyResourceGiven_ShouldNotUpdateBaseUri() throws IOException { DynamicProxyBasePathFilter filter = createFilter(""); filter.filter(null); ContainerRequestContext containerRequest = createContainerRequest("/", ""); filter.filter(containerRequest); verifyZeroInteractions(containerRequest); }
@Test public void filter_InvalidResourceGiven_ShouldNotUpdateBaseUri() throws IOException { DynamicProxyBasePathFilter filter = createFilter("/proxy+}"); filter.filter(null); ContainerRequestContext containerRequest = createContainerRequest("/", "/whatever"); filter.filter(containerRequest); verifyZeroInteractions(containerRequest); }
@Test public void filter_RootProxyResourceGiven_ShouldNotUpdateBaseUri() throws IOException { DynamicProxyBasePathFilter filter = createFilter("/{proxy+}"); filter.filter(null); ContainerRequestContext containerRequest = createContainerRequest("/", "/whatever"); filter.filter(containerRequest); verifyZeroInteractions(containerRequest); }
@Test public void filter_PrefixedProxyResourceGiven_ShouldNotUpdateBaseUri() throws IOException { DynamicProxyBasePathFilter filter = createFilter("/base-path/{proxy+}"); ContainerRequestContext containerRequest = createContainerRequest("/", "/whatever"); filter.filter(containerRequest); verify(containerRequest).setRequestUri(URI.create("/base-path/"), URI.create("/whatever")); }