Class Compatibility

java.lang.Object
com.commercetools.docs.meta.Compatibility

public class Compatibility extends Object
Table of content

Compatibility layer for JVM SDK

The module commercetools-sdk-compat-v1 allows the usage of the SDK in conjunction with the JVM SDK (v1)

Creating a SphereClient with the v2 SDK

The CompatSphereClient acts as a replacement SphereClient for applications using the JVM SDK (v1).

public class CompatSphereClientUsageTest {
    @Test
    public void sphereCompatClient() throws ExecutionException, InterruptedException {
        final String projectKey = CommercetoolsTestUtils.getProjectKey();
        final ProjectApiRoot apiRoot = ApiRootBuilder.of()
                .defaultClient(ClientCredentials.of()
                        .withClientId(CommercetoolsTestUtils.getClientId())
                        .withClientSecret(CommercetoolsTestUtils.getClientSecret())
                        .build())
                .build(projectKey);

        SphereClient client = CompatSphereClient.of(apiRoot);

        Project project = client.execute(ProjectGet.of()).toCompletableFuture().get();

        Assertions.assertThat(project).isInstanceOf(Project.class);
    }
}

See the test code.

Using Requests from the JVM SDK (v1)

The CompatClient can be used to execute a SphereRequest with an ApiHttpClient

public class CompatClientUsageTest {
    @Test
    public void compatClient() {
        final ApiHttpClient apiHttpClient = ApiRootBuilder.of()
                .defaultClient(ClientCredentials.of()
                        .withClientId(CommercetoolsTestUtils.getClientId())
                        .withClientSecret(CommercetoolsTestUtils.getClientSecret())
                        .build())
                .buildClient();
        final String projectKey = CommercetoolsTestUtils.getProjectKey();

        CompatClient client = CompatClient.of(apiHttpClient, projectKey);

        Project project = client.executeBlocking(ProjectGet.of(), Project.class).getBody();

        Assertions.assertThat(project).isInstanceOf(Project.class);
        Assertions.assertThat(project.getKey()).isEqualTo(projectKey);
    }
}

See the test code.

  • Constructor Details

    • Compatibility

      public Compatibility()