@Test public void testFallbackToClassName() { Properties props = new Properties(); props.setProperty(API_VERSION_PREFIX + "VersionedApi", "classversion"); ApiVersionFilter filter = new ApiVersionFilter(config, filterStringsBoundToInjectorByName(props)); HttpRequest request = GeneratedHttpRequest.builder().method("GET").endpoint("http: .invocation(noName).addQueryParam("api-version", "original", "original2").build(); HttpRequest filtered = filter.filter(request); assertEquals(filtered.getEndpoint().getQuery(), "api-version=classversion"); request = GeneratedHttpRequest.builder().method("GET").endpoint("http: .addQueryParam("api-version", "original", "original2").build(); filtered = filter.filter(request); assertEquals(filtered.getEndpoint().getQuery(), "api-version=classversion"); }
@Override public HttpRequest filter(HttpRequest request) throws HttpException { checkArgument(request instanceof GeneratedHttpRequest, "This filter can only be applied to GeneratedHttpRequest objects"); GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; String commandName = config.getCommandName(generatedRequest.getInvocation()); String customApiVersion = versions.get(commandName); if (customApiVersion == null) { Invokable<?, ?> invoked = generatedRequest.getInvocation().getInvokable(); String className = invoked.getOwnerType().getRawType().getSimpleName(); customApiVersion = versions.get(className); } if (customApiVersion != null) { return request.toBuilder().replaceQueryParam("api-version", customApiVersion).build(); } return request; }
ApiVersionFilter implements HttpRequestFilter { @Override public HttpRequest filter(HttpRequest request) throws HttpException { checkArgument(request instanceof GeneratedHttpRequest, "This filter can only be applied to GeneratedHttpRequest objects"); GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; String commandName = config.getCommandName(generatedRequest.getInvocation()); String customApiVersion = versions.get(commandName); if (customApiVersion == null) { Invokable<?, ?> invoked = generatedRequest.getInvocation().getInvokable(); String className = invoked.getOwnerType().getRawType().getSimpleName(); customApiVersion = versions.get(className); } if (customApiVersion != null) { return request.toBuilder().replaceQueryParam("api-version", customApiVersion).build(); } return request; } }
ApiVersionFilter implements HttpRequestFilter { @Override public HttpRequest filter(HttpRequest request) throws HttpException { checkArgument(request instanceof GeneratedHttpRequest, "This filter can only be applied to GeneratedHttpRequest objects"); GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; String commandName = config.getCommandName(generatedRequest.getInvocation()); String customApiVersion = versions.get(commandName); if (customApiVersion == null) { Invokable<?, ?> invoked = generatedRequest.getInvocation().getInvokable(); String className = invoked.getOwnerType().getRawType().getSimpleName(); customApiVersion = versions.get(className); } if (customApiVersion != null) { return request.toBuilder().replaceQueryParam("api-version", customApiVersion).build(); } return request; } @Inject  ApiVersionFilter(InvocationConfig config, Function<Predicate<String>, Map<String, String>> filterStringsBoundByName); }
ApiVersionFilter implements HttpRequestFilter { @Override public HttpRequest filter(HttpRequest request) throws HttpException { checkArgument(request instanceof GeneratedHttpRequest, "This filter can only be applied to GeneratedHttpRequest objects"); GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; String commandName = config.getCommandName(generatedRequest.getInvocation()); String customApiVersion = versions.get(commandName); if (customApiVersion == null) { Invokable<?, ?> invoked = generatedRequest.getInvocation().getInvokable(); String className = invoked.getOwnerType().getRawType().getSimpleName(); customApiVersion = versions.get(className); } if (customApiVersion != null) { return request.toBuilder().replaceQueryParam("api-version", customApiVersion).build(); } return request; } @Inject  ApiVersionFilter(InvocationConfig config, Function<Predicate<String>, Map<String, String>> filterStringsBoundByName); @Override HttpRequest filter(HttpRequest request); }
ApiVersionFilter implements HttpRequestFilter { @Override public HttpRequest filter(HttpRequest request) throws HttpException { checkArgument(request instanceof GeneratedHttpRequest, "This filter can only be applied to GeneratedHttpRequest objects"); GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; String commandName = config.getCommandName(generatedRequest.getInvocation()); String customApiVersion = versions.get(commandName); if (customApiVersion == null) { Invokable<?, ?> invoked = generatedRequest.getInvocation().getInvokable(); String className = invoked.getOwnerType().getRawType().getSimpleName(); customApiVersion = versions.get(className); } if (customApiVersion != null) { return request.toBuilder().replaceQueryParam("api-version", customApiVersion).build(); } return request; } @Inject  ApiVersionFilter(InvocationConfig config, Function<Predicate<String>, Map<String, String>> filterStringsBoundByName); @Override HttpRequest filter(HttpRequest request);  }