Skip to content

Commit d7c4c15

Browse files
committed
Add maven example projects and CI smoketest
1 parent e59e347 commit d7c4c15

6 files changed

Lines changed: 194 additions & 0 deletions

File tree

.gitlab-ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ include:
1010
image: eclipse-temurin:17
1111

1212
variables:
13+
DOCKER_IMAGE_PREFIX: ${CONTAINER_REGISTRY}/oss-client-libraries/${CI_PROJECT_NAME}-build
1314
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
1415
JAVA_TOOL_OPTIONS: ""
1516

@@ -76,6 +77,27 @@ test:
7677
- deepl-java/build/reports/tests/test/index.html
7778
when: always
7879

80+
test_examples:
81+
stage: test
82+
extends: .test
83+
parallel:
84+
matrix:
85+
- DOCKER_IMAGE: "maven:3.8"
86+
- DOCKER_IMAGE: "maven:3.8-openjdk-18"
87+
- DOCKER_IMAGE: "maven:3.8-openjdk-8"
88+
- DOCKER_IMAGE: "maven:3.8-sapmachine-17"
89+
- DOCKER_IMAGE: "maven:3.8-eclipse-temurin-8"
90+
- DOCKER_IMAGE: "maven:3.8-eclipse-temurin-18"
91+
image: ${DOCKER_IMAGE}
92+
script:
93+
- cd examples/maven/deepl-test-app
94+
- mvn install -B -PbuildProject -l mvn_build.log
95+
- mvn verify -PrunIntegrationTests
96+
artifacts:
97+
paths:
98+
- examples/maven/deepl-test-app/mvn_build.log
99+
when: always
100+
79101
# stage: publish -------------------------
80102

81103
publish:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
### Added
9+
* Add example maven project using this library.
10+
711

812
## [1.0.1] - 2023-01-02
913
### Fixed
@@ -60,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6064
Initial version.
6165

6266

67+
[Unreleased]: https://github.com/DeepLcom/deepl-java/compare/v1.0.1...HEAD
6368
[1.0.1]: https://github.com/DeepLcom/deepl-java/compare/v1.0.0...v1.0.1
6469
[1.0.0]: https://github.com/DeepLcom/deepl-java/compare/v0.2.1...v1.0.0
6570
[0.2.1]: https://github.com/DeepLcom/deepl-java/compare/v0.2.0...v0.2.1
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.deepl.deeplTestApp</groupId>
5+
<artifactId>deepl-test-app</artifactId>
6+
<packaging>jar</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<name>deepl-test-app</name>
9+
<url>http://maven.apache.org</url>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>junit</groupId>
19+
<artifactId>junit</artifactId>
20+
<version>4.13.2</version>
21+
<scope>test</scope>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.deepl.api</groupId>
25+
<artifactId>deepl-java</artifactId>
26+
<version>1.0.1</version>
27+
</dependency>
28+
</dependencies>
29+
30+
31+
<profiles>
32+
<profile>
33+
<id>buildProject</id>
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-surefire-plugin</artifactId>
39+
<version>3.0.0-M8</version>
40+
<configuration>
41+
<excludedGroups>com.deepl.deepltestapp.annotation.IntegrationTest</excludedGroups>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
</profile>
47+
<profile>
48+
<id>runIntegrationTests</id>
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<artifactId>maven-surefire-plugin</artifactId>
53+
<version>3.0.0-M8</version>
54+
<executions>
55+
<execution>
56+
<phase>integration-test</phase>
57+
<configuration>
58+
<includes>
59+
<include>**/*</include>
60+
</includes>
61+
<groups>com.deepl.deepltestapp.annotation.IntegrationTest</groups>
62+
</configuration>
63+
</execution>
64+
</executions>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</profile>
69+
</profiles>
70+
</project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2023 DeepL SE (https://www.deepl.com)
2+
// Use of this source code is governed by an MIT
3+
// license that can be found in the LICENSE file.
4+
package com.deepl.deepltestapp;
5+
import com.deepl.api.*;
6+
import java.lang.System.*;
7+
8+
/**
9+
* Hello world translation example
10+
*
11+
*/
12+
public class App {
13+
/**
14+
* Hello world example - insert your API key to test the library.
15+
*/
16+
public static void main( String[] args ) throws InterruptedException, DeepLException {
17+
String authKey = "f63c02c5-f056-..."; // Replace with your key
18+
Translator translator = new Translator(authKey);
19+
TextResult result =
20+
translator.translateText("Hello, world!", null, "fr");
21+
System.out.println(result.getText()); // "Bonjour, le monde !"
22+
}
23+
24+
/////////////////////////////////////////////////////////////////////////////////////
25+
/// These methods are for a test using DeepLs CI pipeline, ignore.
26+
27+
public static String getEnvironmentVariableValue(String envVar) {
28+
return System.getenv(envVar);
29+
}
30+
31+
public static String getAuthKeyFromEnvironmentVariables() {
32+
return getEnvironmentVariableValue("DEEPL_AUTH_KEY");
33+
}
34+
35+
public static String getServerUrlFromEnvironmentVariables() {
36+
return getEnvironmentVariableValue("DEEPL_SERVER_URL");
37+
}
38+
39+
public static String translateHelloWorld() throws InterruptedException, DeepLException {
40+
Translator translator = new Translator(getAuthKeyFromEnvironmentVariables(),
41+
(new TranslatorOptions()).setServerUrl(getServerUrlFromEnvironmentVariables()));
42+
TextResult result =
43+
translator.translateText("Hello, world!", null, "fr");
44+
String translatedText = result.getText();
45+
return translatedText;
46+
}
47+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2023 DeepL SE (https://www.deepl.com)
2+
// Use of this source code is governed by an MIT
3+
// license that can be found in the LICENSE file.
4+
package com.deepl.deepltestapp.annotation;
5+
6+
/**
7+
* Marks tests as Integration tests, used for DeepLs internal CI pipeline.
8+
*/
9+
public interface IntegrationTest {}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2023 DeepL SE (https://www.deepl.com)
2+
// Use of this source code is governed by an MIT
3+
// license that can be found in the LICENSE file.
4+
package com.deepl.deepltestapp;
5+
6+
import com.deepl.api.*;
7+
import com.deepl.deepltestapp.*;
8+
import com.deepl.deepltestapp.annotation.IntegrationTest;
9+
import junit.framework.Test;
10+
import junit.framework.TestCase;
11+
import junit.framework.TestSuite;
12+
import org.junit.Assert.*;
13+
import org.junit.experimental.categories.Category;
14+
15+
/**
16+
* Internal DeepL Integration Test
17+
*/
18+
@Category(IntegrationTest.class)
19+
public class DeepLIntegrationTest extends TestCase {
20+
public DeepLIntegrationTest(String testName) {
21+
super(testName);
22+
}
23+
24+
public static Test suite() {
25+
return new TestSuite(DeepLIntegrationTest.class);
26+
}
27+
28+
/**
29+
* Runs the hello world example. Requires a DeepL auth key via the DEEPL_AUTH_KEY
30+
* environment variable.
31+
*/
32+
public void testApp() throws InterruptedException, DeepLException {
33+
String result = App.translateHelloWorld();
34+
String[] wordsToCheck = {"Hello", "World"};
35+
for (String wordToCheck : wordsToCheck) {
36+
assertFalse(String.format("Expected translation to no longer contain the english %s, received %s",
37+
wordToCheck, result), result.contains(wordToCheck)
38+
);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)