Skip to content

Commit

Permalink
Merge branch 'master' into tsi-1874-update-generator-v7
Browse files Browse the repository at this point in the history
  • Loading branch information
jablan committed Oct 11, 2023
2 parents e835843 + ca1f575 commit 61daf2b
Show file tree
Hide file tree
Showing 6 changed files with 439 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/test-java.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 16 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
clients/go/
clients/java/
clients/php/
clients/python/

Expand All @@ -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
Expand Down
241 changes: 241 additions & 0 deletions clients/java/src/test/java/com/phrase/client/api/LocalesApiTest.java
Original file line number Diff line number Diff line change
@@ -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<Locale> 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());
}

}
Loading

0 comments on commit 61daf2b

Please sign in to comment.