diff --git a/.github/actions/cache/action.yml b/.github/actions/cache/action.yml index 348e879b8b..e244fc110b 100644 --- a/.github/actions/cache/action.yml +++ b/.github/actions/cache/action.yml @@ -355,13 +355,118 @@ runs: key: | ${{ env.CACHE_VERSION }}-${{ hashFiles( - 'clients/algoliasearch-client-java-2/search/**', + 'clients/algoliasearch-client-java-2/api/SearchApi.java', 'clients/algoliasearch-client-java-2/model/search/**', 'specs/bundled/search.yml', 'templates/java/**', 'generators/src/**' )}} + - name: Restore built Java recommend client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/RecommendApi.java', + 'clients/algoliasearch-client-java-2/model/recommend/**', + 'specs/bundled/recommend.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java personalization client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/PersonalizationApi.java', + 'clients/algoliasearch-client-java-2/model/personalization/**', + 'specs/bundled/personalization.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java analytics client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/AnalyticsApi.java', + 'clients/algoliasearch-client-java-2/model/analytics/**', + 'specs/bundled/analytics.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java insights client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/Insights.java', + 'clients/algoliasearch-client-java-2/model/insights/**', + 'specs/bundled/insights.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java abtesting client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/AbtestingApi.java', + 'clients/algoliasearch-client-java-2/model/abtesting/**', + 'specs/bundled/abtesting.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java query-suggestions client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/QuerySuggestionsApi.java', + 'clients/algoliasearch-client-java-2/model/querySuggestions/**', + 'specs/bundled/query-suggestions.yml', + 'templates/java/**', + 'generators/src/**' + )}} + + - name: Restore built Java predict client + if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} + uses: actions/cache@v2 + with: + path: clients/algoliasearch-client-java-2 + key: | + ${{ env.CACHE_VERSION }}-${{ + hashFiles( + 'clients/algoliasearch-client-java-2/api/PredictApi.java', + 'clients/algoliasearch-client-java-2/model/predict/**', + 'specs/bundled/predict.yml', + 'templates/java/**', + 'generators/src/**' + )}} + # Restore PHP clients: used during 'cts' or 'codegen' - name: Restore built PHP search client if: ${{ inputs.job == 'cts' || inputs.job == 'codegen' }} diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java index bfc8fd126e..48a5602ec1 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCtsGenerator.java @@ -132,7 +132,7 @@ public Map postProcessSupportingFileData( // We can put whatever we want in the bundle, and it will be accessible in the // template bundle.put("client", createClientName()); - bundle.put("import", packageName); + bundle.put("import", createImportName()); bundle.put("hasRegionalHost", hasRegionalHost); bundle.put("lambda", lambda); @@ -252,6 +252,20 @@ private String createClientName() { return clientName + "Api"; } + private String createImportName() { + if (!language.equals("java")) { + return this.packageName; + } + String[] clientParts = client.split("-"); + // do not capitalize the first part + String name = clientParts[0]; + for (int i = 1; i < clientParts.length; i++) { + name += Utils.capitalize(clientParts[i]); + } + + return name; + } + /** * override with any special text escaping logic to handle unsafe characters so as to avoid code * injection diff --git a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java index 9c247f4c83..bf93cade72 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java +++ b/generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java @@ -138,7 +138,7 @@ private Map traverseParams( // free key but only one type handleMap(paramName, param, testOutput, spec, suffix); } else { - handlePrimitive(param, testOutput); + handlePrimitive(param, testOutput, spec); } return testOutput; } @@ -151,11 +151,15 @@ private Map createDefaultOutput() { testOutput.put("isObject", false); testOutput.put("isArray", false); testOutput.put("isFreeFormObject", false); + testOutput.put("isAnyType", false); testOutput.put("isString", false); testOutput.put("isInteger", false); + testOutput.put("isLong", false); testOutput.put("isDouble", false); testOutput.put("isBoolean", false); testOutput.put("isEnum", false); + testOutput.put("isSimpleObject", false); + testOutput.put("oneOfModel", false); return testOutput; } @@ -219,15 +223,14 @@ private void handleModel( traverseParams(paramName, param, match, parent, suffix) ); - HashMap hashMapOneOfModel = new HashMap(); + HashMap oneOfModel = new HashMap<>(); - hashMapOneOfModel.put("classname", baseType); - hashMapOneOfModel.put( + oneOfModel.put("classname", Utils.capitalize(baseType)); + oneOfModel.put( "name", getTypeName(match).replace("<", "").replace(">", "") ); - - testOutput.put("oneOfModel", hashMapOneOfModel); + testOutput.put("oneOfModel", oneOfModel); return; } @@ -298,6 +301,10 @@ private void handleObject( ) ); } + // sometimes it's really just an object + if (testOutput.get("objectName").equals("Object")) { + testOutput.put("isSimpleObject", true); + } testOutput.put("isFreeFormObject", true); testOutput.put("value", values); @@ -324,7 +331,8 @@ private void handleMap( IJsonSchemaValidationProperties itemType = items; // The generator consider a free form object type as an `object`, which - // is wrong in our case, so we infer it. + // is wrong in our case, so we infer it to explore the right path in the traverseParams + // function, but we keep the any type for the CTS. if ( items == null || (items.openApiType.equals("object") && items.isFreeFormObject) @@ -333,6 +341,7 @@ private void handleMap( String paramType = inferDataType(entry.getValue(), maybeMatch, null); maybeMatch.dataType = paramType; + maybeMatch.isAnyType = true; itemType = maybeMatch; } @@ -351,9 +360,17 @@ private void handleMap( testOutput.put("value", values); } - private void handlePrimitive(Object param, Map testOutput) - throws CTSException { + private void handlePrimitive( + Object param, + Map testOutput, + IJsonSchemaValidationProperties spec + ) throws CTSException { inferDataType(param, null, testOutput); + if ( + spec instanceof CodegenParameter && ((CodegenParameter) spec).isAnyType + ) { + testOutput.put("isAnyType", true); + } testOutput.put("value", param); } @@ -402,7 +419,7 @@ private String inferDataType( return "Integer"; case "Long": if (spec != null) spec.setIsNumber(true); - if (output != null) output.put("isInteger", true); + if (output != null) output.put("isLong", true); return "Long"; case "Double": if (spec != null) spec.setIsNumber(true); diff --git a/specs/insights/paths/pushEvents.yml b/specs/insights/paths/pushEvents.yml index 6638edff9b..135c27f538 100644 --- a/specs/insights/paths/pushEvents.yml +++ b/specs/insights/paths/pushEvents.yml @@ -36,6 +36,7 @@ post: description: A user identifier. Depending if the user is logged-in or not, several strategies can be used from a sessionId to a technical identifier. timestamp: type: integer + format: int64 description: Time of the event expressed in milliseconds since the Unix epoch. queryID: type: string diff --git a/templates/java/libraries/okhttp-gson/ApiClient.mustache b/templates/java/libraries/okhttp-gson/ApiClient.mustache index 863f87b632..62943e4399 100644 --- a/templates/java/libraries/okhttp-gson/ApiClient.mustache +++ b/templates/java/libraries/okhttp-gson/ApiClient.mustache @@ -180,12 +180,9 @@ public class ApiClient { String jsonStr = JSON.serialize(param); return jsonStr.substring(1, jsonStr.length() - 1); } else if (param instanceof Collection) { - StringBuilder b = new StringBuilder(); + StringJoiner b = new StringJoiner(","); for (Object o : (Collection) param) { - if (b.length() > 0) { - b.append(","); - } - b.append(String.valueOf(o)); + b.add(String.valueOf(o)); } return b.toString(); } else { @@ -206,7 +203,7 @@ public class ApiClient { List params = new ArrayList(); // preconditions - if (name == null || name.isEmpty() || value == null || value instanceof Collection) { + if (name == null || name.isEmpty() || value == null) { return params; } diff --git a/templates/java/libraries/okhttp-gson/api.mustache b/templates/java/libraries/okhttp-gson/api.mustache index 15b6803258..7006bc5b8e 100644 --- a/templates/java/libraries/okhttp-gson/api.mustache +++ b/templates/java/libraries/okhttp-gson/api.mustache @@ -135,7 +135,7 @@ public class {{classname}} extends ApiClient { {{/x-is-custom-request}} {{#x-is-custom-request}} for (Map.Entry parameter : parameters.entrySet()) { - queryParams.addAll(this.parameterToPair(parameter.getKey(), parameter.getValue().toString())); + queryParams.addAll(this.parameterToPair(parameter.getKey(), parameter.getValue())); } {{/x-is-custom-request}} } diff --git a/tests/CTS/methods/requests/templates/java/forceMapGenerics.mustache b/tests/CTS/methods/requests/templates/java/forceMapGenerics.mustache new file mode 100644 index 0000000000..9280166d56 --- /dev/null +++ b/tests/CTS/methods/requests/templates/java/forceMapGenerics.mustache @@ -0,0 +1 @@ +{{#isFreeFormObject}} generateGenerics}}{{/isAnyType}}{{/value.0}}>{{/isFreeFormObject}} \ No newline at end of file diff --git a/tests/CTS/methods/requests/templates/java/generateGenerics.mustache b/tests/CTS/methods/requests/templates/java/generateGenerics.mustache new file mode 100644 index 0000000000..c3642bbaac --- /dev/null +++ b/tests/CTS/methods/requests/templates/java/generateGenerics.mustache @@ -0,0 +1,2 @@ +{{#isArray}}{{#value.0}}<{{#oneOfModel}}{{classname}}{{/oneOfModel}}{{^oneOfModel}}{{objectName}}{{/oneOfModel}}{{> generateGenerics}}>{{/value.0}}{{/isArray}} +{{#isFreeFormObject}}{{^isSimpleObject}} generateGenerics}}{{/isAnyType}}{{/value.0}}>{{/isSimpleObject}}{{/isFreeFormObject}} \ No newline at end of file diff --git a/tests/CTS/methods/requests/templates/java/generateParams.mustache b/tests/CTS/methods/requests/templates/java/generateParams.mustache index 539c774dbc..f2bc7d9062 100644 --- a/tests/CTS/methods/requests/templates/java/generateParams.mustache +++ b/tests/CTS/methods/requests/templates/java/generateParams.mustache @@ -1,11 +1,12 @@ {{#isString}}String {{{key}}}{{suffix}} = "{{{value}}}";{{/isString}} {{#isInteger}}int {{{key}}}{{suffix}} = {{{value}}};{{/isInteger}} +{{#isLong}}long {{{key}}}{{suffix}} = {{{value}}}L;{{/isLong}} {{#isDouble}}double {{{key}}}{{suffix}} = {{{value}}};{{/isDouble}} {{#isBoolean}}boolean {{{key}}}{{suffix}} = {{{value}}};{{/isBoolean}} {{#isEnum}}{{{objectName}}} {{{key}}}{{suffix}} = {{{objectName}}}.fromValue("{{{value}}}");{{/isEnum}} -{{#isArray}}List {{{key}}}{{suffix}} = new ArrayList(); { {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.add({{{key}}}{{suffix}});{{/value}} }{{/isArray}} +{{#isArray}}List{{> generateGenerics}} {{{key}}}{{suffix}} = new ArrayList<>(); { {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.add({{> maybeConvertOneOf}});{{/value}} }{{/isArray}} {{#isObject}}{{{objectName}}} {{{key}}}{{suffix}} = new {{{objectName}}}(); -{ {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.set{{#lambda.titlecase}}{{{key}}}{{/lambda.titlecase}}({{{key}}}{{suffix}}); -{{/value}} }{{/isObject}}{{#isFreeFormObject}}HashMap {{{key}}}{{suffix}} = new HashMap(); -{ {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.put("{{{key}}}", {{{key}}}{{suffix}}); -{{/value}} }{{/isFreeFormObject}} +{ {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.set{{#lambda.titlecase}}{{{key}}}{{/lambda.titlecase}}({{> maybeConvertOneOf}}); +{{/value}} }{{/isObject}}{{#isFreeFormObject}}Map{{> forceMapGenerics}} {{{key}}}{{suffix}} = new HashMap<>(); +{ {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.put("{{{key}}}", {{> maybeConvertOneOf}}); +{{/value}} }{{/isFreeFormObject}} \ No newline at end of file diff --git a/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache b/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache new file mode 100644 index 0000000000..8fbf61e976 --- /dev/null +++ b/tests/CTS/methods/requests/templates/java/maybeConvertOneOf.mustache @@ -0,0 +1 @@ +{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}} \ No newline at end of file diff --git a/tests/CTS/methods/requests/templates/java/requests.mustache b/tests/CTS/methods/requests/templates/java/requests.mustache index 47318abbe7..255e83dea0 100644 --- a/tests/CTS/methods/requests/templates/java/requests.mustache +++ b/tests/CTS/methods/requests/templates/java/requests.mustache @@ -1,6 +1,7 @@ package com.algolia.methods.requests; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import java.util.*; @@ -13,8 +14,8 @@ import com.google.gson.reflect.TypeToken; import com.algolia.JSON; import com.algolia.Pair; -import com.algolia.model.search.*; -import com.algolia.search.{{client}}; +import com.algolia.model.{{import}}.*; +import com.algolia.api.{{client}}; import com.algolia.utils.echo.*; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -36,7 +37,7 @@ class {{client}}Tests { {{#parametersWithDataType}}{{> generateParams}}{{/parametersWithDataType}} EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.{{method}}({{#parametersWithDataType}}{{#oneOfModel}}{{{classname}}}.of{{{name}}}({{{key}}}{{suffix}}){{/oneOfModel}}{{^oneOfModel}}{{{key}}}{{suffix}}{{/oneOfModel}}{{^-last}},{{/-last}}{{/parametersWithDataType}}); + return client.{{method}}({{#parametersWithDataType}}{{> maybeConvertOneOf}}{{^-last}},{{/-last}}{{/parametersWithDataType}}); }); assertEquals(req.getPath(), "{{{request.path}}}"); @@ -49,10 +50,16 @@ class {{client}}Tests { {{/request.data}} {{#request.searchParams}} - HashMap expectedQuery = JSON.deserialize("{{#lambda.escapequotes}}{{{request.searchParams}}}{{/lambda.escapequotes}}", new TypeToken>() {}.getType()); + Map expectedQuery = JSON.deserialize("{{#lambda.escapequotes}}{{{request.searchParams}}}{{/lambda.escapequotes}}", new TypeToken>() {}.getType()); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if (p.getName().equals(entry.getKey()) && p.getValue().equals(entry.getValue())) { + found = true; + } + } + assertTrue(found, "Query parameter " + entry.getKey() + " not found in the actual query"); } {{/request.searchParams}} } diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java new file mode 100644 index 0000000000..d7ae7ac106 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/abtesting.test.java @@ -0,0 +1,421 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.AbtestingApi; +import com.algolia.model.abtesting.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class AbtestingApiTests { + + private AbtestingApi client; + + @BeforeAll + void init() { + client = new AbtestingApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("addABTests with minimal parameters") + void addABTestsTest0() { + AddABTestsRequest addABTestsRequest0 = new AddABTestsRequest(); + { + String endAt1 = "2022-12-31T00:00:00.000Z"; + + addABTestsRequest0.setEndAt(endAt1); + String name1 = "myABTest"; + + addABTestsRequest0.setName(name1); + + List variant1 = new ArrayList<>(); + { + AbTestsVariant variant_02 = new AbTestsVariant(); + { + String index3 = "AB_TEST_1"; + + variant_02.setIndex(index3); + + int trafficPercentage3 = 30; + + variant_02.setTrafficPercentage(trafficPercentage3); + } + variant1.add(AddABTestsVariant.ofAbTestsVariant(variant_02)); + + AbTestsVariant variant_12 = new AbTestsVariant(); + { + String index3 = "AB_TEST_2"; + + variant_12.setIndex(index3); + + int trafficPercentage3 = 50; + + variant_12.setTrafficPercentage(trafficPercentage3); + } + variant1.add(AddABTestsVariant.ofAbTestsVariant(variant_12)); + } + addABTestsRequest0.setVariant(variant1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.addABTests(addABTestsRequest0); + } + ); + + assertEquals(req.getPath(), "/2/abtests"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variant\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("deleteABTest") + void deleteABTestTest0() { + int id0 = 42; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.deleteABTest(id0); + } + ); + + assertEquals(req.getPath(), "/2/abtests/42"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("getABTest") + void getABTestTest0() { + int id0 = 42; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getABTest(id0); + } + ); + + assertEquals(req.getPath(), "/2/abtests/42"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("listABTests with minimal parameters") + void listABTestsTest0() { + int offset0 = 42; + + int limit0 = 21; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.listABTests(offset0, limit0); + } + ); + + assertEquals(req.getPath(), "/2/abtests"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"offset\":\"42\",\"limit\":\"21\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("stopABTest") + void stopABTestTest0() { + int id0 = 42; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.stopABTest(id0); + } + ); + + assertEquals(req.getPath(), "/2/abtests/42/stop"); + assertEquals(req.getMethod(), "POST"); + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java new file mode 100644 index 0000000000..c10e9c5147 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/analytics.test.java @@ -0,0 +1,1756 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.AnalyticsApi; +import com.algolia.model.analytics.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class AnalyticsApiTests { + + private AnalyticsApi client; + + @BeforeAll + void init() { + client = new AnalyticsApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getAverageClickPosition with minimal parameters") + void getAverageClickPositionTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getAverageClickPosition(index0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/averageClickPosition"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getAverageClickPosition with all parameters") + void getAverageClickPositionTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getAverageClickPosition( + index0, + startDate0, + endDate0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/clicks/averageClickPosition"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getClickPositions with minimal parameters") + void getClickPositionsTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getClickPositions(index0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/positions"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getClickPositions with all parameters") + void getClickPositionsTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getClickPositions(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/positions"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getClickThroughRate with minimal parameters") + void getClickThroughRateTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getClickThroughRate(index0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/clickThroughRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getClickThroughRate with all parameters") + void getClickThroughRateTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getClickThroughRate(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/clicks/clickThroughRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getConversationRate with minimal parameters") + void getConversationRateTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getConversationRate(index0); + } + ); + + assertEquals(req.getPath(), "/2/conversions/conversionRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getConversationRate with all parameters") + void getConversationRateTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getConversationRate(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/conversions/conversionRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getNoClickRate with minimal parameters") + void getNoClickRateTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getNoClickRate(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noClickRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getNoClickRate with all parameters") + void getNoClickRateTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getNoClickRate(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noClickRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getNoResultsRate with minimal parameters") + void getNoResultsRateTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getNoResultsRate(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noResultRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getNoResultsRate with all parameters") + void getNoResultsRateTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getNoResultsRate(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noResultRate"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesCount with minimal parameters") + void getSearchesCountTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesCount(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/count"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesCount with all parameters") + void getSearchesCountTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesCount(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/searches/count"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesNoClicks with minimal parameters") + void getSearchesNoClicksTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesNoClicks(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noClicks"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesNoClicks with all parameters") + void getSearchesNoClicksTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesNoClicks( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/searches/noClicks"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesNoResults with minimal parameters") + void getSearchesNoResultsTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesNoResults(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches/noResults"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getSearchesNoResults with all parameters") + void getSearchesNoResultsTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getSearchesNoResults( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/searches/noResults"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getStatus with minimal parameters") + void getStatusTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getStatus(index0); + } + ); + + assertEquals(req.getPath(), "/2/status"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopCountries with minimal parameters") + void getTopCountriesTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopCountries(index0); + } + ); + + assertEquals(req.getPath(), "/2/countries"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopCountries with all parameters") + void getTopCountriesTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopCountries( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/countries"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFilterAttributes with minimal parameters") + void getTopFilterAttributesTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterAttributes(index0); + } + ); + + assertEquals(req.getPath(), "/2/filters"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFilterAttributes with all parameters") + void getTopFilterAttributesTest1() { + String index0 = "index"; + + String search0 = "mySearch"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterAttributes( + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/filters"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFilterForAttribute with minimal parameters") + void getTopFilterForAttributeTest0() { + String attribute0 = "myAttribute"; + + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterForAttribute(attribute0, index0); + } + ); + + assertEquals(req.getPath(), "/2/filters/myAttribute"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName( + "get getTopFilterForAttribute with minimal parameters and multiple attributes" + ) + void getTopFilterForAttributeTest1() { + String attribute0 = "myAttribute1,myAttribute2"; + + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterForAttribute(attribute0, index0); + } + ); + + assertEquals(req.getPath(), "/2/filters/myAttribute1%2CmyAttribute2"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFilterForAttribute with all parameters") + void getTopFilterForAttributeTest2() { + String attribute0 = "myAttribute"; + + String index0 = "index"; + + String search0 = "mySearch"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterForAttribute( + attribute0, + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/filters/myAttribute"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName( + "get getTopFilterForAttribute with all parameters and multiple attributes" + ) + void getTopFilterForAttributeTest3() { + String attribute0 = "myAttribute1,myAttribute2"; + + String index0 = "index"; + + String search0 = "mySearch"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFilterForAttribute( + attribute0, + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/filters/myAttribute1%2CmyAttribute2"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFiltersNoResults with minimal parameters") + void getTopFiltersNoResultsTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFiltersNoResults(index0); + } + ); + + assertEquals(req.getPath(), "/2/filters/noResults"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopFiltersNoResults with all parameters") + void getTopFiltersNoResultsTest1() { + String index0 = "index"; + + String search0 = "mySearch"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopFiltersNoResults( + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/filters/noResults"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopHits with minimal parameters") + void getTopHitsTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopHits(index0); + } + ); + + assertEquals(req.getPath(), "/2/hits"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopHits with all parameters") + void getTopHitsTest1() { + String index0 = "index"; + + String search0 = "mySearch"; + + boolean clickAnalytics0 = true; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopHits( + index0, + search0, + clickAnalytics0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/hits"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"search\":\"mySearch\",\"clickAnalytics\":\"true\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopSearches with minimal parameters") + void getTopSearchesTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopSearches(index0); + } + ); + + assertEquals(req.getPath(), "/2/searches"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getTopSearches with all parameters") + void getTopSearchesTest1() { + String index0 = "index"; + + boolean clickAnalytics0 = true; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + OrderBy orderBy0 = OrderBy.fromValue("searchCount"); + + Direction direction0 = Direction.fromValue("asc"); + + int limit0 = 21; + + int offset0 = 42; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getTopSearches( + index0, + clickAnalytics0, + startDate0, + endDate0, + orderBy0, + direction0, + limit0, + offset0, + tags0 + ); + } + ); + + assertEquals(req.getPath(), "/2/searches"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"clickAnalytics\":\"true\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"orderBy\":\"searchCount\",\"direction\":\"asc\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getUsersCount with minimal parameters") + void getUsersCountTest0() { + String index0 = "index"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getUsersCount(index0); + } + ); + + assertEquals(req.getPath(), "/2/users/count"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getUsersCount with all parameters") + void getUsersCountTest1() { + String index0 = "index"; + + String startDate0 = "1999-09-19"; + + String endDate0 = "2001-01-01"; + + String tags0 = "tag"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getUsersCount(index0, startDate0, endDate0, tags0); + } + ); + + assertEquals(req.getPath(), "/2/users/count"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java new file mode 100644 index 0000000000..f211036175 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/insights.test.java @@ -0,0 +1,428 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.InsightsApi; +import com.algolia.model.insights.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class InsightsApiTests { + + private InsightsApi client; + + @BeforeAll + void init() { + client = new InsightsApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("pushEvents") + void pushEventsTest0() { + InsightEvents insightEvents0 = new InsightEvents(); + { + List events1 = new ArrayList<>(); + { + InsightEvent events_02 = new InsightEvent(); + { + EventType eventType3 = EventType.fromValue("click"); + + events_02.setEventType(eventType3); + String eventName3 = "Product Clicked"; + + events_02.setEventName(eventName3); + String index3 = "products"; + + events_02.setIndex(index3); + String userToken3 = "user-123456"; + + events_02.setUserToken(userToken3); + + long timestamp3 = 1641290601962L; + + events_02.setTimestamp(timestamp3); + + List objectIDs3 = new ArrayList<>(); + { + String objectIDs_04 = "9780545139700"; + + objectIDs3.add(objectIDs_04); + String objectIDs_14 = "9780439784542"; + + objectIDs3.add(objectIDs_14); + } + events_02.setObjectIDs(objectIDs3); + String queryID3 = "43b15df305339e827f0ac0bdc5ebcaa7"; + + events_02.setQueryID(queryID3); + + List positions3 = new ArrayList<>(); + { + int positions_04 = 7; + + positions3.add(positions_04); + int positions_14 = 6; + + positions3.add(positions_14); + } + events_02.setPositions(positions3); + } + events1.add(events_02); + + InsightEvent events_12 = new InsightEvent(); + { + EventType eventType3 = EventType.fromValue("view"); + + events_12.setEventType(eventType3); + String eventName3 = "Product Detail Page Viewed"; + + events_12.setEventName(eventName3); + String index3 = "products"; + + events_12.setIndex(index3); + String userToken3 = "user-123456"; + + events_12.setUserToken(userToken3); + + long timestamp3 = 1641290601962L; + + events_12.setTimestamp(timestamp3); + + List objectIDs3 = new ArrayList<>(); + { + String objectIDs_04 = "9780545139700"; + + objectIDs3.add(objectIDs_04); + String objectIDs_14 = "9780439784542"; + + objectIDs3.add(objectIDs_14); + } + events_12.setObjectIDs(objectIDs3); + } + events1.add(events_12); + + InsightEvent events_22 = new InsightEvent(); + { + EventType eventType3 = EventType.fromValue("conversion"); + + events_22.setEventType(eventType3); + String eventName3 = "Product Purchased"; + + events_22.setEventName(eventName3); + String index3 = "products"; + + events_22.setIndex(index3); + String userToken3 = "user-123456"; + + events_22.setUserToken(userToken3); + + long timestamp3 = 1641290601962L; + + events_22.setTimestamp(timestamp3); + + List objectIDs3 = new ArrayList<>(); + { + String objectIDs_04 = "9780545139700"; + + objectIDs3.add(objectIDs_04); + String objectIDs_14 = "9780439784542"; + + objectIDs3.add(objectIDs_14); + } + events_22.setObjectIDs(objectIDs3); + String queryID3 = "43b15df305339e827f0ac0bdc5ebcaa7"; + + events_22.setQueryID(queryID3); + } + events1.add(events_22); + } + insightEvents0.setEvents(events1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.pushEvents(insightEvents0); + } + ); + + assertEquals(req.getPath(), "/1/events"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"events\":[{\"eventType\":\"click\",\"eventName\":\"Product" + + " Clicked\",\"index\":\"products\",\"userToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\",\"positions\":[7,6]},{\"eventType\":\"view\",\"eventName\":\"Product" + + " Detail Page" + + " Viewed\",\"index\":\"products\",\"userToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"]},{\"eventType\":\"conversion\",\"eventName\":\"Product" + + " Purchased\",\"index\":\"products\",\"userToken\":\"user-123456\",\"timestamp\":1641290601962,\"objectIDs\":[\"9780545139700\",\"9780439784542\"],\"queryID\":\"43b15df305339e827f0ac0bdc5ebcaa7\"}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java new file mode 100644 index 0000000000..f29ff3dc48 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/personalization.test.java @@ -0,0 +1,388 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.PersonalizationApi; +import com.algolia.model.personalization.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class PersonalizationApiTests { + + private PersonalizationApi client; + + @BeforeAll + void init() { + client = new PersonalizationApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("delete deleteUserProfile") + void deleteUserProfileTest0() { + String userToken0 = "UserToken"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.deleteUserProfile(userToken0); + } + ); + + assertEquals(req.getPath(), "/1/profiles/UserToken"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("get getPersonalizationStrategy") + void getPersonalizationStrategyTest0() { + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getPersonalizationStrategy(); + } + ); + + assertEquals(req.getPath(), "/1/strategies/personalization"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("get getUserTokenProfile") + void getUserTokenProfileTest0() { + String userToken0 = "UserToken"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getUserTokenProfile(userToken0); + } + ); + + assertEquals(req.getPath(), "/1/profiles/personalization/UserToken"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("set setPersonalizationStrategy") + void setPersonalizationStrategyTest0() { + PersonalizationStrategyParams personalizationStrategyParams0 = new PersonalizationStrategyParams(); + { + List eventScoring1 = new ArrayList<>(); + { + EventScoring eventScoring_02 = new EventScoring(); + { + int score3 = 42; + + eventScoring_02.setScore(score3); + String eventName3 = "Algolia"; + + eventScoring_02.setEventName(eventName3); + String eventType3 = "Event"; + + eventScoring_02.setEventType(eventType3); + } + eventScoring1.add(eventScoring_02); + } + personalizationStrategyParams0.setEventScoring(eventScoring1); + + List facetScoring1 = new ArrayList<>(); + { + FacetScoring facetScoring_02 = new FacetScoring(); + { + int score3 = 42; + + facetScoring_02.setScore(score3); + String facetName3 = "Event"; + + facetScoring_02.setFacetName(facetName3); + } + facetScoring1.add(facetScoring_02); + } + personalizationStrategyParams0.setFacetScoring(facetScoring1); + + int personalizationImpact1 = 42; + + personalizationStrategyParams0.setPersonalizationImpact( + personalizationImpact1 + ); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.setPersonalizationStrategy( + personalizationStrategyParams0 + ); + } + ); + + assertEquals(req.getPath(), "/1/strategies/personalization"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"eventScoring\":[{\"score\":42,\"eventName\":\"Algolia\",\"eventType\":\"Event\"}],\"facetScoring\":[{\"score\":42,\"facetName\":\"Event\"}],\"personalizationImpact\":42}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java new file mode 100644 index 0000000000..a709f46f24 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/query-suggestions.test.java @@ -0,0 +1,530 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.QuerySuggestionsApi; +import com.algolia.model.querySuggestions.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class QuerySuggestionsApiTests { + + private QuerySuggestionsApi client; + + @BeforeAll + void init() { + client = new QuerySuggestionsApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("createConfig") + void createConfigTest0() { + QuerySuggestionsIndexWithIndexParam querySuggestionsIndexWithIndexParam0 = new QuerySuggestionsIndexWithIndexParam(); + { + String indexName1 = "theIndexName"; + + querySuggestionsIndexWithIndexParam0.setIndexName(indexName1); + + List sourceIndices1 = new ArrayList<>(); + { + SourceIndex sourceIndices_02 = new SourceIndex(); + { + String indexName3 = "testIndex"; + + sourceIndices_02.setIndexName(indexName3); + + List facets3 = new ArrayList<>(); + { + Map facets_04 = new HashMap<>(); + { + String attributes5 = "test"; + + facets_04.put("attributes", attributes5); + } + facets3.add(facets_04); + } + sourceIndices_02.setFacets(facets3); + + List> generate3 = new ArrayList<>(); + { + List generate_04 = new ArrayList<>(); + { + String generate_0_05 = "facetA"; + + generate_04.add(generate_0_05); + String generate_0_15 = "facetB"; + + generate_04.add(generate_0_15); + } + generate3.add(generate_04); + + List generate_14 = new ArrayList<>(); + { + String generate_1_05 = "facetC"; + + generate_14.add(generate_1_05); + } + generate3.add(generate_14); + } + sourceIndices_02.setGenerate(generate3); + } + sourceIndices1.add(sourceIndices_02); + } + querySuggestionsIndexWithIndexParam0.setSourceIndices(sourceIndices1); + + List languages1 = new ArrayList<>(); + { + String languages_02 = "french"; + + languages1.add(languages_02); + } + querySuggestionsIndexWithIndexParam0.setLanguages(languages1); + + List exclude1 = new ArrayList<>(); + { + String exclude_02 = "test"; + + exclude1.add(exclude_02); + } + querySuggestionsIndexWithIndexParam0.setExclude(exclude1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.createConfig(querySuggestionsIndexWithIndexParam0); + } + ); + + assertEquals(req.getPath(), "/1/configs"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"indexName\":\"theIndexName\",\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attributes\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("deleteConfig") + void deleteConfigTest0() { + String indexName0 = "theIndexName"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.deleteConfig(indexName0); + } + ); + + assertEquals(req.getPath(), "/1/configs/theIndexName"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("getAllConfigs") + void getAllConfigsTest0() { + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getAllConfigs(); + } + ); + + assertEquals(req.getPath(), "/1/configs"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("getConfig") + void getConfigTest0() { + String indexName0 = "theIndexName"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getConfig(indexName0); + } + ); + + assertEquals(req.getPath(), "/1/configs/theIndexName"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("getConfigStatus") + void getConfigStatusTest0() { + String indexName0 = "theIndexName"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getConfigStatus(indexName0); + } + ); + + assertEquals(req.getPath(), "/1/configs/theIndexName/status"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("getLogFile") + void getLogFileTest0() { + String indexName0 = "theIndexName"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getLogFile(indexName0); + } + ); + + assertEquals(req.getPath(), "/1/logs/theIndexName"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("updateConfig") + void updateConfigTest0() { + String indexName0 = "theIndexName"; + + QuerySuggestionsIndexParam querySuggestionsIndexParam0 = new QuerySuggestionsIndexParam(); + { + List sourceIndices1 = new ArrayList<>(); + { + SourceIndex sourceIndices_02 = new SourceIndex(); + { + String indexName3 = "testIndex"; + + sourceIndices_02.setIndexName(indexName3); + + List facets3 = new ArrayList<>(); + { + Map facets_04 = new HashMap<>(); + { + String attributes5 = "test"; + + facets_04.put("attributes", attributes5); + } + facets3.add(facets_04); + } + sourceIndices_02.setFacets(facets3); + + List> generate3 = new ArrayList<>(); + { + List generate_04 = new ArrayList<>(); + { + String generate_0_05 = "facetA"; + + generate_04.add(generate_0_05); + String generate_0_15 = "facetB"; + + generate_04.add(generate_0_15); + } + generate3.add(generate_04); + + List generate_14 = new ArrayList<>(); + { + String generate_1_05 = "facetC"; + + generate_14.add(generate_1_05); + } + generate3.add(generate_14); + } + sourceIndices_02.setGenerate(generate3); + } + sourceIndices1.add(sourceIndices_02); + } + querySuggestionsIndexParam0.setSourceIndices(sourceIndices1); + + List languages1 = new ArrayList<>(); + { + String languages_02 = "french"; + + languages1.add(languages_02); + } + querySuggestionsIndexParam0.setLanguages(languages1); + + List exclude1 = new ArrayList<>(); + { + String exclude_02 = "test"; + + exclude1.add(exclude_02); + } + querySuggestionsIndexParam0.setExclude(exclude1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.updateConfig(indexName0, querySuggestionsIndexParam0); + } + ); + + assertEquals(req.getPath(), "/1/configs/theIndexName"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attributes\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java new file mode 100644 index 0000000000..9352bd6b17 --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/recommend.test.java @@ -0,0 +1,818 @@ +package com.algolia.methods.requests; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.algolia.JSON; +import com.algolia.Pair; +import com.algolia.api.RecommendApi; +import com.algolia.model.recommend.*; +import com.algolia.utils.echo.*; +import com.google.gson.reflect.TypeToken; +import java.util.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class RecommendApiTests { + + private RecommendApi client; + + @BeforeAll + void init() { + client = new RecommendApi("appId", "apiKey", new EchoRequester()); + } + + @Test + @DisplayName("allow del method for a custom path with minimal parameters") + void delTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "DELETE"); + } + + @Test + @DisplayName("allow del method for a custom path with all parameters") + void delTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.del(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "DELETE"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow get method for a custom path with minimal parameters") + void getTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "GET"); + } + + @Test + @DisplayName("allow get method for a custom path with all parameters") + void getTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.get(path0, parameters0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "GET"); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName( + "get recommendations for recommend model with minimal parameters" + ) + void getRecommendationsTest0() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get recommendations for recommend model with all parameters") + void getRecommendationsTest1() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + + int maxRecommendations3 = 10; + + requests_02.setMaxRecommendations(maxRecommendations3); + + SearchParamsObject queryParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + queryParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "query"; + + facetFilters4.add(facetFilters_05); + } + queryParameters3.setFacetFilters(facetFilters4); + } + requests_02.setQueryParameters(queryParameters3); + + SearchParamsObject fallbackParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + fallbackParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "fallback"; + + facetFilters4.add(facetFilters_05); + } + fallbackParameters3.setFacetFilters(facetFilters4); + } + requests_02.setFallbackParameters(fallbackParameters3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback\"]}}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get recommendations for trending model with minimal parameters") + void getRecommendationsTest2() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + TrendingRequest requests_02 = new TrendingRequest(); + { + String indexName3 = "indexName"; + + requests_02.setIndexName(indexName3); + + TrendingModels model3 = TrendingModels.fromValue("trending-items"); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + } + requests1.add(RecommendationsRequest.ofTrendingRequest(requests_02)); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get recommendations for trending model with all parameters") + void getRecommendationsTest3() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + TrendingRequest requests_02 = new TrendingRequest(); + { + String indexName3 = "indexName"; + + requests_02.setIndexName(indexName3); + + TrendingModels model3 = TrendingModels.fromValue("trending-items"); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + + int maxRecommendations3 = 10; + + requests_02.setMaxRecommendations(maxRecommendations3); + String facetName3 = "myFacetName"; + + requests_02.setFacetName(facetName3); + String facetValue3 = "myFacetValue"; + + requests_02.setFacetValue(facetValue3); + + SearchParamsObject queryParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + queryParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "query"; + + facetFilters4.add(facetFilters_05); + } + queryParameters3.setFacetFilters(facetFilters4); + } + requests_02.setQueryParameters(queryParameters3); + + SearchParamsObject fallbackParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + fallbackParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "fallback"; + + facetFilters4.add(facetFilters_05); + } + fallbackParameters3.setFacetFilters(facetFilters4); + } + requests_02.setFallbackParameters(fallbackParameters3); + } + requests1.add(RecommendationsRequest.ofTrendingRequest(requests_02)); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42,\"maxRecommendations\":10,\"facetName\":\"myFacetName\",\"facetValue\":\"myFacetValue\",\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback\"]}}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get multiple recommendations with minimal parameters") + void getRecommendationsTest4() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName1"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID1"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_02.setModel(model3); + + int threshold3 = 21; + + requests_02.setThreshold(threshold3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + + RecommendationRequest requests_12 = new RecommendationRequest(); + { + String indexName3 = "indexName2"; + + requests_12.setIndexName(indexName3); + String objectID3 = "objectID2"; + + requests_12.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_12.setModel(model3); + + int threshold3 = 21; + + requests_12.setThreshold(threshold3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_12) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"related-products\",\"threshold\":21},{\"indexName\":\"indexName2\",\"objectID\":\"objectID2\",\"model\":\"related-products\",\"threshold\":21}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get multiple recommendations with all parameters") + void getRecommendationsTest5() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName1"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID1"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_02.setModel(model3); + + int threshold3 = 21; + + requests_02.setThreshold(threshold3); + + int maxRecommendations3 = 10; + + requests_02.setMaxRecommendations(maxRecommendations3); + + SearchParamsObject queryParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + queryParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "query1"; + + facetFilters4.add(facetFilters_05); + } + queryParameters3.setFacetFilters(facetFilters4); + } + requests_02.setQueryParameters(queryParameters3); + + SearchParamsObject fallbackParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + fallbackParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "fallback1"; + + facetFilters4.add(facetFilters_05); + } + fallbackParameters3.setFacetFilters(facetFilters4); + } + requests_02.setFallbackParameters(fallbackParameters3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + + RecommendationRequest requests_12 = new RecommendationRequest(); + { + String indexName3 = "indexName2"; + + requests_12.setIndexName(indexName3); + String objectID3 = "objectID2"; + + requests_12.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "related-products" + ); + + requests_12.setModel(model3); + + int threshold3 = 21; + + requests_12.setThreshold(threshold3); + + int maxRecommendations3 = 10; + + requests_12.setMaxRecommendations(maxRecommendations3); + + SearchParamsObject queryParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + queryParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "query2"; + + facetFilters4.add(facetFilters_05); + } + queryParameters3.setFacetFilters(facetFilters4); + } + requests_12.setQueryParameters(queryParameters3); + + SearchParamsObject fallbackParameters3 = new SearchParamsObject(); + { + String query4 = "myQuery"; + + fallbackParameters3.setQuery(query4); + + List facetFilters4 = new ArrayList<>(); + { + String facetFilters_05 = "fallback2"; + + facetFilters4.add(facetFilters_05); + } + fallbackParameters3.setFacetFilters(facetFilters4); + } + requests_12.setFallbackParameters(fallbackParameters3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_12) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"related-products\",\"threshold\":21,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query1\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback1\"]}},{\"indexName\":\"indexName2\",\"objectID\":\"objectID2\",\"model\":\"related-products\",\"threshold\":21,\"maxRecommendations\":10,\"queryParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"query2\"]},\"fallbackParameters\":{\"query\":\"myQuery\",\"facetFilters\":[\"fallback2\"]}}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("get frequently bought together recommendations") + void getRecommendationsTest6() { + GetRecommendationsParams getRecommendationsParams0 = new GetRecommendationsParams(); + { + List requests1 = new ArrayList<>(); + { + RecommendationRequest requests_02 = new RecommendationRequest(); + { + String indexName3 = "indexName1"; + + requests_02.setIndexName(indexName3); + String objectID3 = "objectID1"; + + requests_02.setObjectID(objectID3); + + RecommendationModels model3 = RecommendationModels.fromValue( + "bought-together" + ); + + requests_02.setModel(model3); + + int threshold3 = 42; + + requests_02.setThreshold(threshold3); + } + requests1.add( + RecommendationsRequest.ofRecommendationRequest(requests_02) + ); + } + getRecommendationsParams0.setRequests(requests1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.getRecommendations(getRecommendationsParams0); + } + ); + + assertEquals(req.getPath(), "/1/indexes/*/recommendations"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"bought-together\",\"threshold\":42}]}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + } + + @Test + @DisplayName("allow post method for a custom path with minimal parameters") + void postTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "POST"); + } + + @Test + @DisplayName("allow post method for a custom path with all parameters") + void postTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.post(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "POST"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } + + @Test + @DisplayName("allow put method for a custom path with minimal parameters") + void putTest0() { + String path0 = "/test/minimal"; + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0); + } + ); + + assertEquals(req.getPath(), "/1/test/minimal"); + assertEquals(req.getMethod(), "PUT"); + } + + @Test + @DisplayName("allow put method for a custom path with all parameters") + void putTest1() { + String path0 = "/test/all"; + + Map parameters0 = new HashMap<>(); + { + String query1 = "parameters"; + + parameters0.put("query", query1); + } + + Map body0 = new HashMap<>(); + { + String body1 = "parameters"; + + body0.put("body", body1); + } + + EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { + return client.put(path0, parameters0, body0); + } + ); + + assertEquals(req.getPath(), "/1/test/all"); + assertEquals(req.getMethod(), "PUT"); + + assertDoesNotThrow(() -> { + JSONAssert.assertEquals( + "{\"body\":\"parameters\"}", + req.getBody(), + JSONCompareMode.STRICT_ORDER + ); + }); + + Map expectedQuery = JSON.deserialize( + "{\"query\":\"parameters\"}", + new TypeToken>() {}.getType() + ); + List actualQuery = req.getQueryParams(); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); + } + } +} diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java index 07978e2488..c6c1b1ec31 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/search.test.java @@ -2,11 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.algolia.JSON; import com.algolia.Pair; +import com.algolia.api.SearchApi; import com.algolia.model.search.*; -import com.algolia.search.SearchApi; import com.algolia.utils.echo.*; import com.google.gson.reflect.TypeToken; import java.util.*; @@ -32,7 +33,7 @@ void init() { void addApiKeyTest0() { ApiKey apiKey0 = new ApiKey(); { - List acl1 = new ArrayList(); + List acl1 = new ArrayList<>(); { Acl acl_02 = Acl.fromValue("search"); @@ -42,7 +43,6 @@ void addApiKeyTest0() { acl1.add(acl_12); } - apiKey0.setAcl(acl1); String description1 = "my new api key"; @@ -86,7 +86,7 @@ void addOrUpdateObjectTest0() { String objectID0 = "uniqueID"; - HashMap body0 = new HashMap(); + Map body0 = new HashMap<>(); { String key1 = "value"; @@ -168,13 +168,25 @@ void assignUserIdTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"X-Algolia-User-ID\":\"userID\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -185,7 +197,7 @@ void batchTest0() { BatchWriteParams batchWriteParams0 = new BatchWriteParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { BatchOperation requests_02 = new BatchOperation(); { @@ -193,7 +205,7 @@ void batchTest0() { requests_02.setAction(action3); - HashMap body3 = new HashMap(); + Map body3 = new HashMap<>(); { String key4 = "value"; @@ -203,7 +215,6 @@ void batchTest0() { } requests1.add(requests_02); } - batchWriteParams0.setRequests(requests1); } @@ -235,7 +246,7 @@ void batchAssignUserIdsTest0() { batchAssignUserIdsParams0.setCluster(cluster1); - List users1 = new ArrayList(); + List users1 = new ArrayList<>(); { String users_02 = "user1"; @@ -244,7 +255,6 @@ void batchAssignUserIdsTest0() { users1.add(users_12); } - batchAssignUserIdsParams0.setUsers(users1); } @@ -267,13 +277,25 @@ void batchAssignUserIdsTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"X-Algolia-User-ID\":\"userID\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -284,7 +306,7 @@ void batchDictionaryEntriesTest0() { BatchDictionaryEntriesParams batchDictionaryEntriesParams0 = new BatchDictionaryEntriesParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { BatchDictionaryEntriesRequest requests_02 = new BatchDictionaryEntriesRequest(); { @@ -324,7 +346,6 @@ void batchDictionaryEntriesTest0() { } requests1.add(requests_12); } - batchDictionaryEntriesParams0.setRequests(requests1); } @@ -361,7 +382,7 @@ void batchDictionaryEntriesTest1() { clearExistingDictionaryEntries1 ); - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { BatchDictionaryEntriesRequest requests_02 = new BatchDictionaryEntriesRequest(); { @@ -381,7 +402,7 @@ void batchDictionaryEntriesTest1() { body3.setWord(word4); - List words4 = new ArrayList(); + List words4 = new ArrayList<>(); { String words_05 = "believe"; @@ -390,10 +411,9 @@ void batchDictionaryEntriesTest1() { words4.add(words_15); } - body3.setWords(words4); - List decomposition4 = new ArrayList(); + List decomposition4 = new ArrayList<>(); { String decomposition_05 = "trust"; @@ -402,7 +422,6 @@ void batchDictionaryEntriesTest1() { decomposition4.add(decomposition_15); } - body3.setDecomposition(decomposition4); DictionaryEntryState state4 = DictionaryEntryState.fromValue( @@ -433,7 +452,7 @@ void batchDictionaryEntriesTest1() { body3.setWord(word4); - List words4 = new ArrayList(); + List words4 = new ArrayList<>(); { String words_05 = "candor"; @@ -442,10 +461,9 @@ void batchDictionaryEntriesTest1() { words4.add(words_15); } - body3.setWords(words4); - List decomposition4 = new ArrayList(); + List decomposition4 = new ArrayList<>(); { String decomposition_05 = "grit"; @@ -454,7 +472,6 @@ void batchDictionaryEntriesTest1() { decomposition4.add(decomposition_15); } - body3.setDecomposition(decomposition4); DictionaryEntryState state4 = DictionaryEntryState.fromValue( @@ -467,7 +484,6 @@ void batchDictionaryEntriesTest1() { } requests1.add(requests_12); } - batchDictionaryEntriesParams0.setRequests(requests1); } @@ -496,7 +512,7 @@ void batchDictionaryEntriesTest1() { void batchRulesTest0() { String indexName0 = "indexName"; - List rule0 = new ArrayList(); + List rule0 = new ArrayList<>(); { Rule rule_01 = new Rule(); { @@ -504,7 +520,7 @@ void batchRulesTest0() { rule_01.setObjectID(objectID2); - List conditions2 = new ArrayList(); + List conditions2 = new ArrayList<>(); { Condition conditions_03 = new Condition(); { @@ -518,7 +534,6 @@ void batchRulesTest0() { } conditions2.add(conditions_03); } - rule_01.setConditions(conditions2); Consequence consequence2 = new Consequence(); @@ -541,7 +556,7 @@ void batchRulesTest0() { rule_11.setObjectID(objectID2); - List conditions2 = new ArrayList(); + List conditions2 = new ArrayList<>(); { Condition conditions_03 = new Condition(); { @@ -555,7 +570,6 @@ void batchRulesTest0() { } conditions2.add(conditions_03); } - rule_11.setConditions(conditions2); Consequence consequence2 = new Consequence(); @@ -598,13 +612,25 @@ void batchRulesTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\",\"clearExistingRules\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -715,7 +741,7 @@ void delTest0() { void delTest1() { String path0 = "/test/all"; - HashMap parameters0 = new HashMap(); + Map parameters0 = new HashMap<>(); { String query1 = "parameters"; @@ -730,13 +756,25 @@ void delTest1() { assertEquals(req.getPath(), "/1/test/all"); assertEquals(req.getMethod(), "DELETE"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -881,7 +919,7 @@ void getTest0() { void getTest1() { String path0 = "/test/all"; - HashMap parameters0 = new HashMap(); + Map parameters0 = new HashMap<>(); { String query1 = "parameters"; @@ -896,13 +934,25 @@ void getTest1() { assertEquals(req.getPath(), "/1/test/all"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -963,13 +1013,25 @@ void getLogsTest0() { assertEquals(req.getPath(), "/1/logs"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"offset\":\"5\",\"length\":\"10\",\"indexName\":\"theIndexName\",\"type\":\"all\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -980,7 +1042,7 @@ void getObjectTest0() { String objectID0 = "uniqueID"; - List attributesToRetrieve0 = new ArrayList(); + List attributesToRetrieve0 = new ArrayList<>(); { String attributesToRetrieve_01 = "attr1"; @@ -998,13 +1060,25 @@ void getObjectTest0() { assertEquals(req.getPath(), "/1/indexes/theIndexName/uniqueID"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"attributesToRetrieve\":\"attr1,attr2\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1013,11 +1087,11 @@ void getObjectTest0() { void getObjectsTest0() { GetObjectsParams getObjectsParams0 = new GetObjectsParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { MultipleGetObjectsParams requests_02 = new MultipleGetObjectsParams(); { - List attributesToRetrieve3 = new ArrayList(); + List attributesToRetrieve3 = new ArrayList<>(); { String attributesToRetrieve_04 = "attr1"; @@ -1026,7 +1100,6 @@ void getObjectsTest0() { attributesToRetrieve3.add(attributesToRetrieve_14); } - requests_02.setAttributesToRetrieve(attributesToRetrieve3); String objectID3 = "uniqueID"; @@ -1037,7 +1110,6 @@ void getObjectsTest0() { } requests1.add(requests_02); } - getObjectsParams0.setRequests(requests1); } @@ -1171,13 +1243,25 @@ void hasPendingMappingsTest0() { assertEquals(req.getPath(), "/1/clusters/mapping/pending"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"getClusters\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1218,13 +1302,25 @@ void listIndicesTest0() { assertEquals(req.getPath(), "/1/indexes"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"page\":\"8\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1243,13 +1339,25 @@ void listUserIdsTest0() { assertEquals(req.getPath(), "/1/clusters/mapping"); assertEquals(req.getMethod(), "GET"); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"page\":\"8\",\"hitsPerPage\":\"100\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1258,7 +1366,7 @@ void listUserIdsTest0() { void multipleBatchTest0() { BatchParams batchParams0 = new BatchParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { MultipleBatchOperation requests_02 = new MultipleBatchOperation(); { @@ -1266,7 +1374,7 @@ void multipleBatchTest0() { requests_02.setAction(action3); - HashMap body3 = new HashMap(); + Map body3 = new HashMap<>(); { String key4 = "value"; @@ -1279,7 +1387,6 @@ void multipleBatchTest0() { } requests1.add(requests_02); } - batchParams0.setRequests(requests1); } @@ -1305,7 +1412,7 @@ void multipleBatchTest0() { void multipleQueriesTest0() { MultipleQueriesParams multipleQueriesParams0 = new MultipleQueriesParams(); { - List requests1 = new ArrayList(); + List requests1 = new ArrayList<>(); { MultipleQueries requests_02 = new MultipleQueries(); { @@ -1328,7 +1435,6 @@ void multipleQueriesTest0() { } requests1.add(requests_02); } - multipleQueriesParams0.setRequests(requests1); MultipleQueriesStrategy strategy1 = MultipleQueriesStrategy.fromValue( @@ -1369,7 +1475,7 @@ void operationIndexTest0() { operationIndexParams0.setDestination(destination1); - List scope1 = new ArrayList(); + List scope1 = new ArrayList<>(); { ScopeType scope_02 = ScopeType.fromValue("rules"); @@ -1379,7 +1485,6 @@ void operationIndexTest0() { scope1.add(scope_12); } - operationIndexParams0.setScope(scope1); } @@ -1407,13 +1512,16 @@ void partialUpdateObjectTest0() { String objectID0 = "uniqueID"; - List attributeOrBuiltInOperation0 = new ArrayList(); + List> attributeOrBuiltInOperation0 = new ArrayList<>(); { - HashMap attributeOrBuiltInOperation_01 = new HashMap(); + Map attributeOrBuiltInOperation_01 = new HashMap<>(); { String id12 = "test"; - attributeOrBuiltInOperation_01.put("id1", id12); + attributeOrBuiltInOperation_01.put( + "id1", + AttributeOrBuiltInOperation.ofString(id12) + ); BuiltInOperation id22 = new BuiltInOperation(); { @@ -1426,7 +1534,10 @@ void partialUpdateObjectTest0() { id22.setValue(value3); } - attributeOrBuiltInOperation_01.put("id2", id22); + attributeOrBuiltInOperation_01.put( + "id2", + AttributeOrBuiltInOperation.ofBuiltInOperation(id22) + ); } attributeOrBuiltInOperation0.add(attributeOrBuiltInOperation_01); } @@ -1454,13 +1565,25 @@ void partialUpdateObjectTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"createIfNotExists\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1483,14 +1606,14 @@ void postTest0() { void postTest1() { String path0 = "/test/all"; - HashMap parameters0 = new HashMap(); + Map parameters0 = new HashMap<>(); { String query1 = "parameters"; parameters0.put("query", query1); } - HashMap body0 = new HashMap(); + Map body0 = new HashMap<>(); { String body1 = "parameters"; @@ -1513,13 +1636,25 @@ void postTest1() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1542,14 +1677,14 @@ void putTest0() { void putTest1() { String path0 = "/test/all"; - HashMap parameters0 = new HashMap(); + Map parameters0 = new HashMap<>(); { String query1 = "parameters"; parameters0.put("query", query1); } - HashMap body0 = new HashMap(); + Map body0 = new HashMap<>(); { String body1 = "parameters"; @@ -1572,13 +1707,25 @@ void putTest1() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1599,7 +1746,7 @@ void removeUserIdTest0() { @Test @DisplayName("replaceSources") void replaceSourcesTest0() { - List source0 = new ArrayList(); + List source0 = new ArrayList<>(); { Source source_01 = new Source(); { @@ -1649,7 +1796,7 @@ void restoreApiKeyTest0() { void saveObjectTest0() { String indexName0 = "theIndexName"; - HashMap body0 = new HashMap(); + Map body0 = new HashMap<>(); { String objectID1 = "id"; @@ -1689,7 +1836,7 @@ void saveRuleTest0() { rule0.setObjectID(objectID1); - List conditions1 = new ArrayList(); + List conditions1 = new ArrayList<>(); { Condition conditions_02 = new Condition(); { @@ -1703,7 +1850,6 @@ void saveRuleTest0() { } conditions1.add(conditions_02); } - rule0.setConditions(conditions1); Consequence consequence1 = new Consequence(); @@ -1742,13 +1888,25 @@ void saveRuleTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1769,7 +1927,7 @@ void saveSynonymTest0() { synonymHit0.setType(type1); - List synonyms1 = new ArrayList(); + List synonyms1 = new ArrayList<>(); { String synonyms_02 = "car"; @@ -1781,7 +1939,6 @@ void saveSynonymTest0() { synonyms1.add(synonyms_22); } - synonymHit0.setSynonyms(synonyms1); } @@ -1808,13 +1965,25 @@ void saveSynonymTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -1823,7 +1992,7 @@ void saveSynonymTest0() { void saveSynonymsTest0() { String indexName0 = "indexName"; - List synonymHit0 = new ArrayList(); + List synonymHit0 = new ArrayList<>(); { SynonymHit synonymHit_01 = new SynonymHit(); { @@ -1835,7 +2004,7 @@ void saveSynonymsTest0() { synonymHit_01.setType(type2); - List synonyms2 = new ArrayList(); + List synonyms2 = new ArrayList<>(); { String synonyms_03 = "car"; @@ -1847,7 +2016,6 @@ void saveSynonymsTest0() { synonyms2.add(synonyms_23); } - synonymHit_01.setSynonyms(synonyms2); } synonymHit0.add(synonymHit_01); @@ -1865,7 +2033,7 @@ void saveSynonymsTest0() { synonymHit_11.setInput(input2); - List synonyms2 = new ArrayList(); + List synonyms2 = new ArrayList<>(); { String synonyms_03 = "ephone"; @@ -1877,7 +2045,6 @@ void saveSynonymsTest0() { synonyms2.add(synonyms_23); } - synonymHit_11.setSynonyms(synonyms2); } synonymHit0.add(synonymHit_11); @@ -1908,13 +2075,25 @@ void saveSynonymsTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\",\"replaceExistingSynonyms\":\"false\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -2171,7 +2350,7 @@ void setDictionarySettingsTest0() { { StandardEntries disableStandardEntries1 = new StandardEntries(); { - HashMap plurals2 = new HashMap(); + Map plurals2 = new HashMap<>(); { boolean fr3 = false; @@ -2216,7 +2395,7 @@ void setDictionarySettingsTest1() { { StandardEntries disableStandardEntries1 = new StandardEntries(); { - HashMap plurals2 = new HashMap(); + Map plurals2 = new HashMap<>(); { boolean fr3 = false; @@ -2232,7 +2411,7 @@ void setDictionarySettingsTest1() { } disableStandardEntries1.setPlurals(plurals2); - HashMap stopwords2 = new HashMap(); + Map stopwords2 = new HashMap<>(); { boolean fr3 = false; @@ -2240,7 +2419,7 @@ void setDictionarySettingsTest1() { } disableStandardEntries1.setStopwords(stopwords2); - HashMap compounds2 = new HashMap(); + Map compounds2 = new HashMap<>(); { boolean ru3 = true; @@ -2304,13 +2483,25 @@ void setSettingsTest0() { ); }); - HashMap expectedQuery = JSON.deserialize( + Map expectedQuery = JSON.deserialize( "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); List actualQuery = req.getQueryParams(); - for (Pair p : actualQuery) { - assertEquals(expectedQuery.get(p.getName()), p.getValue()); + for (Map.Entry entry : expectedQuery.entrySet()) { + boolean found = false; + for (Pair p : actualQuery) { + if ( + p.getName().equals(entry.getKey()) && + p.getValue().equals(entry.getValue()) + ) { + found = true; + } + } + assertTrue( + found, + "Query parameter " + entry.getKey() + " not found in the actual query" + ); } } @@ -2321,7 +2512,7 @@ void updateApiKeyTest0() { ApiKey apiKey0 = new ApiKey(); { - List acl1 = new ArrayList(); + List acl1 = new ArrayList<>(); { Acl acl_02 = Acl.fromValue("search"); @@ -2331,7 +2522,6 @@ void updateApiKeyTest0() { acl1.add(acl_12); } - apiKey0.setAcl(acl1); int validity1 = 300;