Package com.commercetools.docs.meta
Class Compatibility
java.lang.Object
com.commercetools.docs.meta.Compatibility
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).
import java.util.concurrent.ExecutionException;
import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.defaultconfig.ApiRootBuilder;
import io.sphere.sdk.client.SphereClient;
import io.sphere.sdk.projects.Project;
import io.sphere.sdk.projects.queries.ProjectGet;
import io.vrap.rmf.base.client.oauth2.ClientCredentials;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
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
import com.commercetools.api.defaultconfig.ApiRootBuilder;
import com.commercetools.api.models.project.Project;
import io.sphere.sdk.projects.queries.ProjectGet;
import io.vrap.rmf.base.client.ApiHttpClient;
import io.vrap.rmf.base.client.oauth2.ClientCredentials;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
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 Summary
-
Method Summary
-
Constructor Details
-
Compatibility
public Compatibility()
-