Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ d0129c1095216d5c830900c8a6223ef5d4274de1
bbe9f971763ca1b27687a6a51067a385a0d23b04
de95c481329aa8b821e6e71ac35c1b8bc67e3e86
78c44064f4ec15091bde7a2dc590aa2b3a99341d
03665b75a1e1c3a3cf28df1dec52e91b308e4368
7e25c796da25ae080a952936de535a1228fed448
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ SHELL := /bin/bash
CHANGES_PENDING := `git status --porcelain -- ':(exclude)*gen.properties' | grep -c ^ || true`
API_RAML ?= $(RAML_FILE)
IMPORT_RAML ?= $(RAML_FILE)
ML_RAML ?= $(RAML_FILE)
CHECKOUT_RAML ?= $(RAML_FILE)
HISTORY_RAML ?= $(RAML_FILE)
CPUS := `./tools/numcpu.sh`

.PHONY: build build_api_sdk build_import_sdk build_import_sdk build_ml_sdk gen_api_sdk gen_import_sdk gen_ml_sdk gen_history_sdk
.PHONY: build build_api_sdk build_import_sdk build_import_sdk build_ml_sdk gen_api_sdk gen_import_sdk gen_ml_sdk gen_history_sdk gen_checkout_sdk

build: codegen_install gen_api_sdk gen_import_sdk gen_history_sdk prettify verify
build: codegen_install gen_api_sdk gen_import_sdk gen_history_sdk gen_checkout_sdk prettify verify
build_api_sdk: codegen_install gen_api_sdk prettify verify
build_import_sdk: codegen_install gen_import_sdk prettify verify
build_ml_sdk: codegen_install gen_ml_sdk prettify verify
build_history_sdk: codegen_install gen_history_sdk prettify verify
build_checkout_sdk: codegen_install gen_checkout_sdk prettify verify

gen_api_sdk: generate_api
gen_import_sdk: generate_import
gen_ml_sdk: generate_ml
gen_history_sdk: generate_history
gen_checkout_sdk: generate_checkout

prettify:
./gradlew spotlessApply
Expand All @@ -40,6 +42,9 @@ generate_ml:
generate_history:
$(MAKE) -C commercetools LIB_NAME="history" GEN_RAML_FILE=../$(HISTORY_RAML) generate_sdk

generate_checkout:
$(MAKE) -C commercetools LIB_NAME="checkout" GEN_RAML_FILE=../$(CHECKOUT_RAML) generate_sdk

check_pending:
git status --porcelain -- ':(exclude)*gen.properties'
@echo "CHANGES_PENDING=$(CHANGES_PENDING)" >> $GITHUB_ENV
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
id 'java'
id 'java-library' // needed to make sure that transitive deps have 'compile' scope

id "com.diffplug.spotless" version "7.0.4"
id "com.diffplug.spotless" version "7.2.1"

id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
id 'com.github.jk1.dependency-license-report' version '2.0'
Expand Down
15 changes: 15 additions & 0 deletions commercetools/commercetools-sdk-java-checkout/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

dependencies {
api project(':rmf:rmf-java-base')
api jackson_core.annotations
api jackson_core.databind
implementation google.findbugs
implementation javax.validation
api commons.lang3

integrationTestImplementation project(':commercetools:commercetools-http-client')
integrationTestImplementation project(':commercetools:commercetools-sdk-java-api')
}

sourceSets.main.java.srcDirs += "src/main/java-generated"
sourceSets.test.java.srcDirs += "src/test/java-generated"
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

package com.commercetools.checkout.client;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.stream.Collectors;

import org.assertj.core.api.Assertions;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;

public class ProjectApiRootTest {

private static final List<String> ignoreMethods = Lists.newArrayList();

/**
* Retrieves all public methods of the {@link ProjectScopedApiRoot} and the public methods of the {@link ByProjectKeyRequestBuilder} and
* checks if project request builder methods are present in ProjectApiRoot methods
*/
@Test
public void allSubResourcesSupported() {

final List<String> projectApiRootMethods = Lists.newArrayList(ProjectScopedApiRoot.class.getDeclaredMethods())
.stream()
.filter(method -> Modifier.isPublic(method.getModifiers()))
.map(Method::getName)
.distinct()
.collect(Collectors.toList());

final List<String> resourceMethods = Lists.newArrayList(ByProjectKeyRequestBuilder.class.getDeclaredMethods())
.stream()
.filter(method -> Modifier.isPublic(method.getModifiers()))
.map(Method::getName)
.filter(methodName -> !ignoreMethods.contains(methodName))
.filter(methodName -> !projectApiRootMethods.contains(methodName))
.collect(Collectors.toList());

Assertions.assertThat(resourceMethods)
.withFailMessage("missing endpoints in ProjectApiRoot: %s", resourceMethods)
.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@

package com.commercetools.checkout.defaultconfig;

import java.time.Duration;
import java.util.UUID;
import java.util.function.Consumer;

import com.commercetools.checkout.client.ProjectApiRoot;

import io.vrap.rmf.base.client.oauth2.ClientCredentials;

import org.apache.commons.lang3.StringUtils;
import org.assertj.core.api.SoftAssertions;

public class CheckoutApiTestUtils {

private static final ProjectApiRoot projectRoot;

static {
String logLevel = System.getenv("CTP_JVM_SDK_LOG_LEVEL");
if ("OFF".equals(logLevel)) {
projectRoot = CheckoutApiRootBuilder.of()
.defaultClient(
ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(),
ServiceRegion.GCP_EUROPE_WEST1)
.build(getProjectKey());
}
else {
projectRoot = CheckoutApiRootBuilder.of()
.defaultClient(
ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(),
ServiceRegion.GCP_EUROPE_WEST1)
.build(getProjectKey());
}
}

public static String randomString() {
return "random-string-" + UUID.randomUUID().toString();
}

public static String randomId() {
return "random-id-" + UUID.randomUUID().toString();
}

public static String randomKey() {
return "random-key-" + UUID.randomUUID().toString();
}

public static String getProjectKey() {
return System.getenv("CTP_PROJECT_KEY");
}

public static String getClientId() {
return System.getenv("CTP_CLIENT_ID");
}

public static String getClientSecret() {
return System.getenv("CTP_CLIENT_SECRET");
}

public static ProjectApiRoot getProjectRoot() {
return projectRoot;
}

public static void assertEventually(final Duration maxWaitTime, final Duration waitBeforeRetry,
final Runnable block) {
final long timeOutAt = System.currentTimeMillis() + maxWaitTime.toMillis();
while (true) {
try {
block.run();

// the block executed without throwing an exception, return
return;
}
catch (AssertionError e) {
if (System.currentTimeMillis() > timeOutAt) {
throw e;
}
}

try {
Thread.sleep(waitBeforeRetry.toMillis());
}
catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}

public static void assertEventually(final Consumer<SoftAssertions> assertionsConsumer) {
final Runnable block = () -> {
final SoftAssertions softly = new SoftAssertions();
assertionsConsumer.accept(softly);
softly.assertAll();
};
assertEventually(block);
}

public static void assertEventually(final Runnable block) {
final Boolean useLongTimeout = "true".equals(System.getenv("TRAVIS"))
|| StringUtils.isNotEmpty(System.getenv("TEAMCITY_VERSION"))
|| StringUtils.isNoneEmpty(System.getenv("GITHUB_WORKSPACE"));
final Duration maxWaitTime = Duration.ofSeconds(useLongTimeout ? 60 : 30);
final Duration waitBeforeRetry = Duration.ofMillis(100);
assertEventually(maxWaitTime, waitBeforeRetry, block);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

package com.commercetools.checkout.defaultconfig;

import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.defaultconfig.ApiRootBuilder;
import com.commercetools.api.models.cart.CartDraft;
import com.commercetools.checkout.models.transaction.TransactionDraft;

import io.vrap.rmf.base.client.oauth2.ClientCredentials;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CheckoutIntegrationTests {

private static final ProjectApiRoot projectApiRoot;
private static final com.commercetools.checkout.client.ProjectApiRoot checkoutApiRoot;

static {
projectApiRoot = createApiClient();
checkoutApiRoot = createCheckoutClient();
}
public static ProjectApiRoot createApiClient() {
return ApiRootBuilder.ofEnvironmentVariables().buildProjectRoot();
}

public static com.commercetools.checkout.client.ProjectApiRoot createCheckoutClient() {
return CheckoutApiRootBuilder.of()
.defaultClient(ClientCredentials.of()
.withClientId(System.getenv("CTP_CLIENT_ID"))
.withClientSecret(System.getenv("CTP_CLIENT_SECRET"))
.build(),
ServiceRegion.GCP_EUROPE_WEST1)
.build(System.getenv("CTP_PROJECT_KEY"));
}

// create client, then cart, then transaction
@Test
public void createAndGetTransactionTest() {
var newCart = CartDraft.builder().currency("EUR").build();

var cart = projectApiRoot.carts().post(newCart).executeBlocking().getBody();
Assertions.assertNotNull(cart);

var transactionKey = "transaction-" + CheckoutApiTestUtils.randomKey();
var transaction = checkoutApiRoot.with()
.transactions()
.post(TransactionDraft.builder()
.key(transactionKey)
.application(a -> a.key("demo-commercetools-checkout"))
.cart(c -> c.id(cart.getId()))
.plusTransactionItems(t -> t.amount(a -> a.centAmount(100).currencyCode("EUR"))
.paymentIntegration(p -> p.key("ci-payment-integration")))
.build()

)
.executeBlocking()
.getBody();

// Create transaction
Assertions.assertNotNull(transaction);

Assertions.assertNotNull(
checkoutApiRoot.with().transactions().withId(transaction.getId()).get().executeBlocking().getBody());
Assertions.assertEquals(transactionKey, transaction.getKey());
Assertions.assertNotNull(
checkoutApiRoot.with().transactions().withKey(transaction.getKey()).get().executeBlocking().getBody());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<configuration debug="false">
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>

<logger name="commercetools" level="WARN"/>

<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

package com.commercetools.checkout.client;

import java.io.Closeable;

import io.vrap.rmf.base.client.ApiHttpClient;
import io.vrap.rmf.base.client.SerializerOnlyApiHttpClient;
import io.vrap.rmf.base.client.utils.Generated;

/**
* Entrypoint for building requests against the API
*/
@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
public class ApiRoot implements Closeable {

private final ApiHttpClient apiHttpClient;

private ApiRoot(final ApiHttpClient apiHttpClient) {
this.apiHttpClient = apiHttpClient;
}

public static ApiRoot of() {
return new ApiRoot(SerializerOnlyApiHttpClient.of());
}

public static ApiRoot fromClient(final ApiHttpClient apiHttpClient) {
return new ApiRoot(apiHttpClient);
}

public ByProjectKeyRequestBuilder withProjectKey(String projectKey) {
return new ByProjectKeyRequestBuilder(this.apiHttpClient, projectKey);
}

@Override
public void close() {
if (apiHttpClient == null) {
return;
}
try {
apiHttpClient.close();
}
catch (final Throwable ignored) {
}
}

}
Loading
Loading