Skip to content

Commit

Permalink
test(Java): add Keys API test #STRINGS-1005 (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
jablan authored Feb 3, 2025
1 parent 6eda218 commit 7456bd5
Showing 1 changed file with 304 additions and 0 deletions.
304 changes: 304 additions & 0 deletions clients/java/src/test/java/com/phrase/client/api/KeysApiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
/*
* Phrase Strings API Reference
*
* The version of the OpenAPI document: 2.0.0
* Contact: [email protected]
*
* 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 com.phrase.client.model.AffectedResources;
import com.phrase.client.model.KeyCreateParameters;
import com.phrase.client.model.KeyUpdateParameters;
import com.phrase.client.model.KeysExcludeParameters;
import com.phrase.client.model.KeysIncludeParameters;
import com.phrase.client.model.KeysSearchParameters;
import com.phrase.client.model.KeysTagParameters;
import com.phrase.client.model.KeysUntagParameters;
import com.phrase.client.model.TranslationKey;
import com.phrase.client.model.TranslationKeyDetails;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Before;
import org.junit.After;
import org.junit.Assert;

import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;

import java.io.IOException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* API tests for KeysApi
*/
public class KeysApiTest {

MockWebServer mockBackend = new MockWebServer();

private KeysApi 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 KeysApi(defaultClient);
}

@After
public void tearDown() throws IOException {
mockBackend.shutdown();
}

/**
* Create a key
*
* Create a new key.
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void keyCreateTest() throws ApiException, InterruptedException {
String body = "{\"id\":\"id_example\",\"name\":\"test-key-1\",\"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 = "MY_PROJECT_ID";
KeyCreateParameters keyCreateParameters = new KeyCreateParameters()
.name("test-key-1")
.autotranslate(true)
.defaultTranslationContent("some test value which should be created and automatically translated in one call")
.dataType("string")
.maxCharactersAllowed(Integer.MAX_VALUE)
.plural(false);
String xPhraseAppOTP = null;
TranslationKeyDetails response = api.keyCreate(projectId, keyCreateParameters, xPhraseAppOTP);

Assert.assertEquals("valid id returned", "id_example", response.getId());
RecordedRequest recordedRequest = mockBackend.takeRequest();
Assert.assertEquals("Request path", "//projects/MY_PROJECT_ID/keys", recordedRequest.getPath());
String requestBody = recordedRequest.getBody().readUtf8();
Assert.assertEquals("Request body", "{\"name\":\"test-key-1\",\"plural\":false,\"data_type\":\"string\",\"max_characters_allowed\":2147483647,\"default_translation_content\":\"some test value which should be created and automatically translated in one call\",\"autotranslate\":true}", requestBody);
}

/**
* Delete a key
*
* Delete an existing key.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keyDeleteTest() throws ApiException {
String projectId = null;
String id = null;
String xPhraseAppOTP = null;
String branch = null;
api.keyDelete(projectId, id, xPhraseAppOTP, branch);

// TODO: test validations
}

/**
* Get a single key
*
* Get details on a single key for a given project.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keyShowTest() throws ApiException {
String projectId = null;
String id = null;
String xPhraseAppOTP = null;
String branch = null;
TranslationKeyDetails response = api.keyShow(projectId, id, xPhraseAppOTP, branch);

// TODO: test validations
}

/**
* Update a key
*
* Update an existing key.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keyUpdateTest() throws ApiException {
String projectId = null;
String id = null;
KeyUpdateParameters keyUpdateParameters = null;
String xPhraseAppOTP = null;
TranslationKeyDetails response = api.keyUpdate(projectId, id, keyUpdateParameters, xPhraseAppOTP);

// TODO: test validations
}

/**
* Delete collection of keys
*
* Delete all keys matching query. Same constraints as list. Please limit the number of affected keys to about 1,000 as you might experience timeouts otherwise.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keysDeleteCollectionTest() throws ApiException {
String projectId = null;
String xPhraseAppOTP = null;
String branch = null;
String q = null;
String localeId = null;
AffectedResources response = api.keysDeleteCollection(projectId, xPhraseAppOTP, branch, q, localeId);

// TODO: test validations
}

/**
* Exclude a locale on a collection of keys
*
* Exclude a locale on keys matching query. Same constraints as list.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keysExcludeTest() throws ApiException {
String projectId = null;
KeysExcludeParameters keysExcludeParameters = null;
String xPhraseAppOTP = null;
AffectedResources response = api.keysExclude(projectId, keysExcludeParameters, xPhraseAppOTP);

// TODO: test validations
}

/**
* Include a locale on a collection of keys
*
* Include a locale on keys matching query. Same constraints as list.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keysIncludeTest() throws ApiException {
String projectId = null;
KeysIncludeParameters keysIncludeParameters = null;
String xPhraseAppOTP = null;
AffectedResources response = api.keysInclude(projectId, keysIncludeParameters, xPhraseAppOTP);

// TODO: test validations
}

/**
* List keys
*
* List all keys for the given project. Alternatively you can POST requests to /search.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keysListTest() throws ApiException {
String projectId = null;
String xPhraseAppOTP = null;
Integer page = null;
Integer perPage = null;
String branch = null;
String sort = null;
String order = null;
String q = null;
String localeId = null;
List<TranslationKey> response = api.keysList(projectId, xPhraseAppOTP, page, perPage, branch, sort, order, q, localeId);

// TODO: test validations
}

/**
* Search keys
*
* Search keys for the given project matching query.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keysSearchTest() throws ApiException {
String projectId = null;
KeysSearchParameters keysSearchParameters = null;
String xPhraseAppOTP = null;
Integer page = null;
Integer perPage = null;
List<TranslationKey> response = api.keysSearch(projectId, keysSearchParameters, xPhraseAppOTP, page, perPage);

// TODO: test validations
}

/**
* Add tags to collection of keys
*
* Tags all keys matching query. Same constraints as list.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keysTagTest() throws ApiException {
String projectId = null;
KeysTagParameters keysTagParameters = null;
String xPhraseAppOTP = null;
AffectedResources response = api.keysTag(projectId, keysTagParameters, xPhraseAppOTP);

// TODO: test validations
}

/**
* Remove tags from collection of keys
*
* Removes specified tags from keys matching query.
*
* @throws ApiException
* if the Api call fails
*/
@Ignore
public void keysUntagTest() throws ApiException {
String projectId = null;
KeysUntagParameters keysUntagParameters = null;
String xPhraseAppOTP = null;
AffectedResources response = api.keysUntag(projectId, keysUntagParameters, xPhraseAppOTP);

// TODO: test validations
}

}

0 comments on commit 7456bd5

Please sign in to comment.