private static SphereClient withMaybeDeprecationWarnTool(final SphereClient underlying) { if ("true".equals(System.getenv("JVM_SDK_IT_DEPRECATION"))) { return DeprecationExceptionSphereClientDecorator.of(underlying); } else { LoggerFactory.getLogger(IntegrationTest.class).info("Deprecation client deactivated."); return underlying; } }
@Test public void execution() throws Exception { final HttpHeaders headers = HttpHeaders.of((SphereHttpHeaders.X_DEPRECATION_NOTICE), DEPRECATION_MESSAGE); HttpResponse response = HttpResponse.of(200, DummySphereRequest.DEFAULT_RESPONSE_OBJECT, headers); final SphereClient sphereClient = clientWithResponse(response); assertThat(sphereClient.execute(DummySphereRequest.of()).toCompletableFuture().join()) .overridingErrorMessage("normal sphere client ignores deprecation header") .isEqualTo(DummySphereRequest.DEFAULT_RESPONSE_OBJECT); final SphereClient decoratedClient = DeprecationExceptionSphereClientDecorator.of(sphereClient); thrown.expect(new CustomTypeSafeMatcher<ExecutionException>("") { @Override protected boolean matchesSafely(final ExecutionException e) { return e.getCause() != null && e.getCause() instanceof SphereException && e.getCause().getMessage().contains("deprecation warning: " + DEPRECATION_MESSAGE); } }); decoratedClient.execute(DummySphereRequest.of()).toCompletableFuture().get(); }
protected synchronized static TestClient client() { if (client == null) { final SphereClientFactory factory = SphereClientFactory.of(); final SphereClientConfig config = SphereClientConfig.of(projectKey(), clientId(), clientSecret(), authUrl(), apiUrl()); final SphereAccessTokenSupplier tokenSupplier = SphereAccessTokenSupplierFactory.of().createSupplierOfOneTimeFetchingToken(config); final SphereClient underlying = factory.createClient(config, tokenSupplier); final SphereClient underlyingWithDeprecationExceptions = DeprecationExceptionSphereClientDecorator.of(underlying); client = new TestClient(underlyingWithDeprecationExceptions); } return client; }