Skip to content

Commit 0acda3b

Browse files
authored
Merge pull request #162 from commercetools/image_upload
2 parents d8a9609 + fd2a6ba commit 0acda3b

File tree

13 files changed

+240
-11
lines changed

13 files changed

+240
-11
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ jobs:
4848
SOURCE_TAG: ${{ steps.branch_name.outputs.SOURCE_TAG }}
4949
CTP_JVM_SDK_LOG_LEVEL: OFF
5050

51+
- name: Test examples
52+
run: |
53+
cd examples/maven-okhttp3 && mvn verify --no-transfer-progress -q
54+
cd ../maven-okhttp4 && mvn verify --no-transfer-progress -q
55+
5156
- name: Collect code coverage
5257
run: ./gradlew codeCoverageReport
5358

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ plugins {
99

1010
id 'idea'
1111

12-
id 'maven'
1312
id 'maven-publish'
1413
id 'signing'
1514

@@ -155,7 +154,6 @@ subprojects { project ->
155154

156155
apply plugin: 'idea'
157156

158-
apply plugin: 'maven'
159157
apply plugin: 'maven-publish'
160158
apply plugin: 'signing'
161159

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

22
dependencies {
33
api project(":rmf:rmf-java-base")
4-
api "com.squareup.okhttp3:okhttp:3.14.9"
4+
api("com.squareup.okhttp3:okhttp") {
5+
version {
6+
strictly "[3.0,4.0["
7+
prefer "3.14.9"
8+
}
9+
}
510

611
implementation "javax.validation:validation-api:${versions.validation}"
712
}

commercetools/commercetools-okhttp-client4/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

22
dependencies {
33
api project(":rmf:rmf-java-base")
4-
api "com.squareup.okhttp3:okhttp:4.9.1"
4+
api("com.squareup.okhttp3:okhttp") {
5+
version {
6+
strictly '[4.0,5.0['
7+
prefer "4.9.1"
8+
}
9+
}
510

611
implementation "javax.validation:validation-api:${versions.validation}"
712

commercetools/commercetools-sdk-java-api/src/integrationTest/java/commercetools/product/ProductIntegrationTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11

22
package commercetools.product;
33

4+
import java.io.File;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
47
import java.util.ArrayList;
58
import java.util.List;
69

10+
import com.commercetools.api.client.ByProjectKeyRequestBuilder;
711
import com.commercetools.api.models.common.LocalizedString;
812
import com.commercetools.api.models.product.*;
913
import commercetools.utils.CommercetoolsTestUtils;
1014

15+
import org.apache.commons.io.IOUtils;
1116
import org.junit.Assert;
1217
import org.junit.Test;
1318

@@ -103,4 +108,32 @@ public void query() {
103108
Assert.assertEquals(response.getResults().get(0).getId(), product.getId());
104109
});
105110
}
111+
112+
@Test
113+
public void upload() {
114+
ProductFixtures.withProduct(product -> {
115+
File imageFile;
116+
try {
117+
imageFile = File.createTempFile("ct_logo_farbe", ".gif");
118+
imageFile.deleteOnExit();
119+
byte[] fileBytes = IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("ct_logo_farbe.gif"));
120+
FileOutputStream outStream = new FileOutputStream(imageFile);
121+
outStream.write(fileBytes);
122+
outStream.close();
123+
124+
}
125+
catch (IOException e) {
126+
imageFile = new File("src/integrationTest/resources/ct_logo_farbe.gif");
127+
}
128+
129+
final ByProjectKeyRequestBuilder projectRoot = CommercetoolsTestUtils.getProjectRoot();
130+
projectRoot.products()
131+
.withId(product.getId())
132+
.images()
133+
.post(imageFile)
134+
.contentType("image/gif")
135+
.withSku(product.getMasterData().getCurrent().getMasterVariant().getSku())
136+
.executeBlocking();
137+
});
138+
}
106139
}

commercetools/commercetools-sdk-java-api/src/integrationTest/java/commercetools/utils/CommercetoolsTestUtils.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ public class CommercetoolsTestUtils {
1919
private static final ByProjectKeyRequestBuilder projectRoot;
2020

2121
static {
22-
ServiceRegion region = System.getenv("CTP_REGION") == null ? ServiceRegion.GCP_EUROPE_WEST1 : ServiceRegion.valueOf(System.getenv("CTP_REGION"));
23-
String authURL = System.getenv("CTP_AUTH_URL") == null ? region.getOAuthTokenUrl() : System.getenv("CTP_AUTH_URL");
22+
ServiceRegion region = System.getenv("CTP_REGION") == null ? ServiceRegion.GCP_EUROPE_WEST1
23+
: ServiceRegion.valueOf(System.getenv("CTP_REGION"));
24+
String authURL = System.getenv("CTP_AUTH_URL") == null ? region.getOAuthTokenUrl()
25+
: System.getenv("CTP_AUTH_URL");
2426
String apiUrl = System.getenv("CTP_API_URL") == null ? region.getApiUrl() : System.getenv("CTP_API_URL");
2527
String logLevel = System.getenv("CTP_JVM_SDK_LOG_LEVEL");
2628
if ("OFF".equals(logLevel)) {
2729
client = ApiFactory.defaultClient(
28-
ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(),
29-
authURL, apiUrl);
30+
ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(), authURL,
31+
apiUrl);
3032
projectRoot = ApiFactory.createForProject(getProjectKey(), () -> client);
3133
}
3234
else {
3335
client = ApiFactory.defaultClient(
34-
ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(),
35-
authURL, apiUrl);
36+
ClientCredentials.of().withClientId(getClientId()).withClientSecret(getClientSecret()).build(), authURL,
37+
apiUrl);
3638
projectRoot = ApiFactory.createForProject(getProjectKey(), () -> client);
3739
}
3840
}
3.54 KB
Loading

examples/maven-okhttp3/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.commercetools.sdk.examples</groupId>
7+
<artifactId>maven-okhttp3</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<groupId>org.apache.maven.plugins</groupId>
13+
<artifactId>maven-compiler-plugin</artifactId>
14+
<configuration>
15+
<source>8</source>
16+
<target>8</target>
17+
</configuration>
18+
</plugin>
19+
<plugin>
20+
<artifactId>maven-surefire-plugin</artifactId>
21+
<version>2.22.2</version>
22+
</plugin>
23+
<plugin>
24+
<artifactId>maven-failsafe-plugin</artifactId>
25+
<version>2.22.2</version>
26+
</plugin>
27+
</plugins>
28+
</build>
29+
<properties>
30+
<commercetools.version>5.0.0</commercetools.version>
31+
</properties>
32+
<dependencies>
33+
<dependency>
34+
<groupId>com.commercetools.sdk</groupId>
35+
<artifactId>commercetools-sdk-java-api</artifactId>
36+
<version>${commercetools.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.commercetools.sdk</groupId>
40+
<artifactId>commercetools-okhttp-client3</artifactId>
41+
<version>${commercetools.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.junit.jupiter</groupId>
45+
<artifactId>junit-jupiter-api</artifactId>
46+
<version>5.7.2</version>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter-engine</artifactId>
52+
<version>5.7.2</version>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.commercetools.sdk.examples;
2+
3+
import com.commercetools.api.client.ApiRoot;
4+
import com.commercetools.api.defaultconfig.ApiFactory;
5+
import com.commercetools.api.defaultconfig.ServiceRegion;
6+
import com.commercetools.api.models.project.Project;
7+
import io.vrap.rmf.base.client.oauth2.ClientCredentials;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Test;
10+
11+
public class GettingStarted {
12+
13+
@Test
14+
public void project() {
15+
ApiRoot apiRoot = ApiFactory.create(
16+
ClientCredentials.of().withClientId(System.getenv("CTP_CLIENT_ID"))
17+
.withClientSecret(System.getenv("CTP_CLIENT_SECRET"))
18+
.build(),
19+
ServiceRegion.GCP_EUROPE_WEST1.getOAuthTokenUrl(),
20+
ServiceRegion.GCP_EUROPE_WEST1.getApiUrl());
21+
22+
Project response = apiRoot.withProjectKey(System.getenv("CTP_PROJECT_KEY"))
23+
.get()
24+
.executeBlocking().getBody();
25+
26+
Assertions.assertEquals(System.getenv("CTP_PROJECT_KEY"), response.getKey());
27+
}
28+
}

examples/maven-okhttp4/pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.commercetools.sdk.examples</groupId>
7+
<artifactId>maven</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<build>
10+
<plugins>
11+
<plugin>
12+
<groupId>org.apache.maven.plugins</groupId>
13+
<artifactId>maven-compiler-plugin</artifactId>
14+
<configuration>
15+
<source>8</source>
16+
<target>8</target>
17+
</configuration>
18+
</plugin>
19+
<plugin>
20+
<artifactId>maven-surefire-plugin</artifactId>
21+
<version>2.22.2</version>
22+
</plugin>
23+
<plugin>
24+
<artifactId>maven-failsafe-plugin</artifactId>
25+
<version>2.22.2</version>
26+
</plugin>
27+
</plugins>
28+
</build>
29+
<properties>
30+
<commercetools.version>5.0.0</commercetools.version>
31+
</properties>
32+
<dependencies>
33+
<dependency>
34+
<groupId>com.commercetools.sdk</groupId>
35+
<artifactId>commercetools-sdk-java-api</artifactId>
36+
<version>${commercetools.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.commercetools.sdk</groupId>
40+
<artifactId>commercetools-http-client</artifactId>
41+
<version>${commercetools.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.junit.jupiter</groupId>
45+
<artifactId>junit-jupiter-api</artifactId>
46+
<version>5.7.2</version>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter-engine</artifactId>
52+
<version>5.7.2</version>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
</project>

0 commit comments

Comments
 (0)