diff --git a/.github/workflows/test-java.yml b/.github/workflows/test-java.yml new file mode 100644 index 00000000..332bf1bb --- /dev/null +++ b/.github/workflows/test-java.yml @@ -0,0 +1,21 @@ +name: Run Java Tests +on: [push] +jobs: + gradle: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: | + npm install + npm run generate.java + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 11 + - name: Run Gradle Tests + uses: gradle/gradle-build-action@v2 + with: + gradle-version: 7.1.1 + build-root-directory: ./clients/java + arguments: test diff --git a/.github/workflows/test.yml b/.github/workflows/test-ruby.yml similarity index 92% rename from .github/workflows/test.yml rename to .github/workflows/test-ruby.yml index 010d81cb..6e9dd0c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test-ruby.yml @@ -1,7 +1,7 @@ -name: Run RSpec tests +name: Run Ruby Tests on: [push] jobs: - run-rspec-tests: + rspec: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 7bcc9c19..e781fb6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ clients/go/ -clients/java/ clients/php/ clients/python/ @@ -19,6 +18,22 @@ clients/ruby/spec/api/* !clients/ruby/spec/api/locales_api_spec.rb !clients/ruby/spec/api/uploads_api_spec.rb +clients/java/.* +clients/java/gradle* +clients/java/build* +clients/java/docs +clients/java/git_push.sh +clients/java/pom.xml +clients/java/README.md +clients/java/openapitools.json +clients/java/settings.gradle +clients/java/api +clients/java/src/main +clients/java/src/test/java/com/phrase/client/model +clients/java/src/test/java/com/phrase/client/api/* +!clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java +!clients/java/src/test/java/com/phrase/client/api/UploadsApiTest.java + clients/typescript/ clients/cli/cmd/api_*.go clients/cli/phrase-cli diff --git a/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java new file mode 100644 index 00000000..6d6a732c --- /dev/null +++ b/clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java @@ -0,0 +1,241 @@ +/* + * Phrase Strings API Reference + * + * The version of the OpenAPI document: 2.0.0 + * Contact: support@phrase.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.phrase.client.api; + +import com.phrase.client.ApiException; +import java.io.File; +import java.io.IOException; +import com.phrase.client.model.Locale; +import com.phrase.client.model.LocaleCreateParameters; +import com.phrase.client.model.LocaleDetails; +import com.phrase.client.model.LocalePreview1; +import com.phrase.client.model.LocaleUpdateParameters; + +import com.phrase.client.ApiClient; +import com.phrase.client.ApiException; +import com.phrase.client.Configuration; +import com.phrase.client.auth.HttpBasicAuth; + +import org.junit.Test; +import org.junit.Ignore; +import org.junit.Assert; +import org.junit.Before; +import org.junit.After; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + +/** + * API tests for LocalesApi + */ +public class LocalesApiTest { + + MockWebServer mockBackend = new MockWebServer(); + + private LocalesApi api; + + @Before + public void setUp() throws IOException { + mockBackend.start(); + + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath(mockBackend.url("/").toString()); + + // Configure HTTP basic authorization: Basic + HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic"); + Basic.setUsername("TOKEN"); + Basic.setPassword(""); + + api = new LocalesApi(defaultClient); + } + + @After + public void tearDown() throws IOException { + mockBackend.shutdown(); + } + + /** + * List locales used in account + * + * List all locales unique by locale code used across all projects within an account. + * + * @throws ApiException + * if the Api call fails + */ + @Ignore + public void accountLocalesTest() throws ApiException { + } + + /** + * Create a locale + * + * Create a new locale. + * + * @throws ApiException + * if the Api call fails + */ + @Ignore + public void localeCreateTest() throws ApiException { + String projectId = null; + LocaleCreateParameters localeCreateParameters = null; + String xPhraseAppOTP = null; + LocaleDetails response = api.localeCreate(projectId, localeCreateParameters, xPhraseAppOTP); + + // TODO: test validations + } + + /** + * Delete a locale + * + * Delete an existing locale. + * + * @throws ApiException + * if the Api call fails + */ + @Ignore + public void localeDeleteTest() throws ApiException { + String projectId = null; + String id = null; + String xPhraseAppOTP = null; + String branch = null; + api.localeDelete(projectId, id, xPhraseAppOTP, branch); + + // TODO: test validations + } + + /** + * Download a locale + * + * Download a locale in a specific file format. + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void localeDownloadTest() throws ApiException, IOException, InterruptedException { + String body = "{\"key\":\"value\"}"; + + MockResponse mockResponse = new MockResponse() + .addHeader("Content-Type", "application/json; charset=utf-8") + .setBody(body); + + mockBackend.enqueue(mockResponse); + + String projectId = "MY_PROJECT_ID"; + String id = "MY_ID"; + String xPhraseAppOTP = null; + String ifModifiedSince = null; + String ifNoneMatch = null; + String branch = null; + String fileFormat = null; + String tags = null; + String tag = null; + Boolean includeEmptyTranslations = null; + Boolean excludeEmptyZeroForms = null; + Boolean includeTranslatedKeys = null; + Boolean keepNotranslateTags = null; + Boolean convertEmoji = null; + Object formatOptions = null; + String encoding = null; + Boolean skipUnverifiedTranslations = null; + Boolean includeUnverifiedTranslations = null; + Boolean useLastReviewedVersion = null; + String fallbackLocaleId = null; + String sourceLocaleId = null; + File response = api.localeDownload(projectId, id, xPhraseAppOTP, ifModifiedSince, ifNoneMatch, branch, fileFormat, tags, tag, includeEmptyTranslations, excludeEmptyZeroForms, includeTranslatedKeys, keepNotranslateTags, convertEmoji, formatOptions, encoding, skipUnverifiedTranslations, includeUnverifiedTranslations, useLastReviewedVersion, fallbackLocaleId, sourceLocaleId); + + String fileContents = new String(java.nio.file.Files.readAllBytes(response.toPath())); + Assert.assertEquals("Correct file contents", fileContents, body); + + RecordedRequest recordedRequest = mockBackend.takeRequest(); + Assert.assertEquals("Request path", "//projects/MY_PROJECT_ID/locales/MY_ID/download", recordedRequest.getPath()); + } + + /** + * Get a single locale + * + * Get details on a single locale for a given project. + * + * @throws ApiException + * if the Api call fails + */ + @Ignore + public void localeShowTest() throws ApiException { + String projectId = null; + String id = null; + String xPhraseAppOTP = null; + String branch = null; + LocaleDetails response = api.localeShow(projectId, id, xPhraseAppOTP, branch); + + // TODO: test validations + } + + /** + * Update a locale + * + * Update an existing locale. + * + * @throws ApiException + * if the Api call fails + */ + @Ignore + public void localeUpdateTest() throws ApiException { + String projectId = null; + String id = null; + LocaleUpdateParameters localeUpdateParameters = null; + String xPhraseAppOTP = null; + LocaleDetails response = api.localeUpdate(projectId, id, localeUpdateParameters, xPhraseAppOTP); + + // TODO: test validations + } + + /** + * List locales + * + * List all locales for the given project. + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void localesListTest() throws ApiException, InterruptedException { + String body = "[{\"id\": \"ae0ce77b64dbf7e8315b5da8ecbb42c0\",\"name\": \"de-DE\",\"code\": \"de-DE\",\"default\": false,\"main\": false,\"rtl\": false,\"plural_forms\": [\"zero\",\"one\",\"other\"],\"created_at\": \"2022-10-27T11:03:39Z\",\"updated_at\": \"2023-10-05T09:49:28Z\",\"source_locale\": null,\"fallback_locale\": null},{\"id\": \"95060c3b178252e0c5d1936493e93108\",\"name\": \"en-US\",\"code\": \"en-US\",\"default\": true,\"main\": false,\"rtl\": false,\"plural_forms\": [\"zero\",\"one\",\"other\"],\"created_at\": \"2022-10-27T11:03:39Z\",\"updated_at\": \"2023-10-05T09:50:20Z\",\"source_locale\": null,\"fallback_locale\": null},{\"id\": \"97b4b258d9000f256a97276561294b5b\",\"name\": \"sh\",\"code\": \"sr-Latn-RS\",\"default\": false,\"main\": false,\"rtl\": false,\"plural_forms\": [\"zero\",\"one\",\"few\",\"other\"],\"created_at\": \"2022-10-27T11:03:39Z\",\"updated_at\": \"2023-05-10T08:22:18Z\",\"source_locale\": null,\"fallback_locale\": null}]"; + + MockResponse mockResponse = new MockResponse() + .addHeader("Content-Type", "application/json; charset=utf-8") + .setBody(body); + + mockBackend.enqueue(mockResponse); + + String projectId = "MY_PROJECT_ID"; + String xPhraseAppOTP = null; + Integer page = null; + Integer perPage = null; + String sortBy = null; + String branch = "MY_BRANCH"; + List response = api.localesList(projectId, xPhraseAppOTP, page, perPage, sortBy, branch); + + Assert.assertEquals("Correct number of elements", response.size(), 3); + Assert.assertEquals("Correct locale name", response.get(0).getName(), "de-DE"); + + RecordedRequest recordedRequest = mockBackend.takeRequest(); + Assert.assertEquals("Request path", "//projects/MY_PROJECT_ID/locales?branch=MY_BRANCH", recordedRequest.getPath()); + } + +} diff --git a/clients/java/src/test/java/com/phrase/client/api/UploadsApiTest.java b/clients/java/src/test/java/com/phrase/client/api/UploadsApiTest.java new file mode 100644 index 00000000..1e986410 --- /dev/null +++ b/clients/java/src/test/java/com/phrase/client/api/UploadsApiTest.java @@ -0,0 +1,158 @@ +/* + * Phrase Strings API Reference + * + * The version of the OpenAPI document: 2.0.0 + * Contact: support@phrase.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.phrase.client.api; + +import com.phrase.client.ApiClient; +import com.phrase.client.ApiException; +import com.phrase.client.Configuration; +import com.phrase.client.auth.HttpBasicAuth; + +import java.io.File; +import java.io.IOException; +import java.time.OffsetDateTime; + +import com.phrase.client.model.Upload; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + +import org.junit.Test; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * API tests for UploadsApi + */ +public class UploadsApiTest { + + MockWebServer mockBackend = new MockWebServer(); + + private UploadsApi api; + + @Before + public void setUp() throws IOException { + mockBackend.start(); + + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath(mockBackend.url("/").toString()); + + // Configure HTTP basic authorization: Basic + HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic"); + Basic.setUsername("TOKEN"); + Basic.setPassword(""); + + api = new UploadsApi(defaultClient); + } + + @After + public void tearDown() throws IOException { + mockBackend.shutdown(); + } + + /** + * Upload a new file + * + * Upload a new language file. Creates necessary resources in your project. + * + * @throws ApiException + * if the Api call fails + * @throws IOException + * @throws InterruptedException + */ + @Test + public void uploadCreateTest() throws ApiException, IOException, InterruptedException { + String body = "{\"id\":\"id_example\",\"created_at\": \"2015-01-28T09:52:53Z\"}"; + + MockResponse mockResponse = new MockResponse() + .addHeader("Content-Type", "application/json; charset=utf-8") + .setBody(body); + + mockBackend.enqueue(mockResponse); + + String projectId = "projectId_example"; + String xPhraseAppOTP = null; + String branch = "branch_example"; + File file = File.createTempFile("test", "test"); + file.deleteOnExit(); + String fileFormat = null; + String localeId = null; + String tags = null; + Boolean updateTranslations = null; + Boolean updateDescriptions = null; + Boolean convertEmoji = null; + Boolean skipUploadTags = null; + Boolean skipUnverification = null; + String fileEncoding = null; + Object localeMapping = null; + Object formatOptions = null; + Boolean autotranslate = null; + Boolean markReviewed = null; + Boolean tagOnlyAffectedKeys = null; + Upload response = api.uploadCreate(projectId, xPhraseAppOTP, branch, file, fileFormat, localeId, tags, updateTranslations, updateDescriptions, convertEmoji, skipUploadTags, skipUnverification, fileEncoding, localeMapping, formatOptions, autotranslate, markReviewed, tagOnlyAffectedKeys); + + Assert.assertEquals("valid id returned", "id_example", response.getId()); + Assert.assertEquals("valid creation date returned", OffsetDateTime.parse("2015-01-28T09:52:53Z"), response.getCreatedAt()); + + RecordedRequest recordedRequest = mockBackend.takeRequest(); + Assert.assertEquals("Request path", "//projects/projectId_example/uploads", recordedRequest.getPath()); + Assert.assertTrue("Request payload", recordedRequest.getBody().readUtf8().contains("Content-Disposition: form-data; name=\"file\"")); + } + + /** + * Get a single upload + * + * View details and summary for a single upload. + * + * @throws ApiException + * if the Api call fails + */ + @Ignore + public void uploadShowTest() throws ApiException { + String projectId = null; + String id = null; + String xPhraseAppOTP = null; + String branch = null; + Upload response = api.uploadShow(projectId, id, xPhraseAppOTP, branch); + + // TODO: test validations + } + + /** + * List uploads + * + * List all uploads for the given project. + * + * @throws ApiException + * if the Api call fails + */ + @Ignore + public void uploadsListTest() throws ApiException { + String projectId = null; + String xPhraseAppOTP = null; + Integer page = null; + Integer perPage = null; + String branch = null; + List response = api.uploadsList(projectId, xPhraseAppOTP, page, perPage, branch); + + // TODO: test validations + } + +} diff --git a/openapi-generator/templates/java/libraries/okhttp-gson/build.gradle.mustache b/openapi-generator/templates/java/libraries/okhttp-gson/build.gradle.mustache index 6d7e8f2e..0ecd4095 100644 --- a/openapi-generator/templates/java/libraries/okhttp-gson/build.gradle.mustache +++ b/openapi-generator/templates/java/libraries/okhttp-gson/build.gradle.mustache @@ -153,6 +153,7 @@ dependencies { implementation 'org.threeten:threetenbp:1.4.3' {{/threetenbp}} testImplementation 'junit:junit:4.13' + testImplementation 'com.squareup.okhttp3:mockwebserver:3.14.7' } javadoc {