diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 754248dc98..ebfb0adce2 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -220,15 +220,15 @@ jobs: run: yarn cli build clients ${{ matrix.client.language }} ${{ matrix.client.toRun }} - name: Clean CTS output before generate - run: rm -rf ${{ matrix.client.testsOutputPath }} + run: rm -rf ${{ matrix.client.testsOutputPathToClean }} || true - name: Generate CTS run: yarn cli cts generate ${{ matrix.client.language }} ${{ matrix.client.toRun }} - name: Check diff with pushed CTS run: | - git --no-pager diff - exit $(git diff --name-only --diff-filter=d ${{ matrix.client.testsOutputPath }} | wc -l) + git --no-pager diff -- ${{ matrix.client.testsOutputPathToClean }} + exit $(git diff --name-only --diff-filter=d ${{ matrix.client.testsOutputPathToClean }} | wc -l) - name: Run CTS run: yarn cli cts run ${{ matrix.client.language }} diff --git a/clients/algoliasearch-client-java-2/.openapi-generator-ignore b/clients/algoliasearch-client-java-2/.openapi-generator-ignore index b21c175e33..a7dc62ea7d 100644 --- a/clients/algoliasearch-client-java-2/.openapi-generator-ignore +++ b/clients/algoliasearch-client-java-2/.openapi-generator-ignore @@ -7,6 +7,7 @@ api/** docs/** src/** +gradle/** README.md .travis.yml diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/build.gradle b/clients/algoliasearch-client-java-2/algoliasearch-core/build.gradle index 876a780ea6..f4d91ce3f1 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/build.gradle +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/build.gradle @@ -21,4 +21,5 @@ dependencies { tasks.withType(JavaCompile) { options.encoding = 'UTF-8' + options.compilerArgs += ['-Xlint:deprecation'] } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiCallback.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiCallback.java deleted file mode 100644 index 1c1d61bcff..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiCallback.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.algolia; - -import com.algolia.exceptions.AlgoliaRuntimeException; -import java.util.List; -import java.util.Map; - -/** - * Callback for asynchronous API call. - * - * @param The return type - */ -public interface ApiCallback { - /** - * This is called when the API call fails. - * - * @param e The exception causing the failure - * @param statusCode Status code of the response if available, otherwise it would be 0 - * @param responseHeaders Headers of the response if available, otherwise it would be null - */ - void onFailure( - AlgoliaRuntimeException e, - int statusCode, - Map> responseHeaders - ); - - /** - * This is called when the API call succeeded. - * - * @param result The result deserialized from response - * @param statusCode Status code of the response - * @param responseHeaders Headers of the response - */ - void onSuccess( - T result, - int statusCode, - Map> responseHeaders - ); - - /** - * This is called when the API upload processing. - * - * @param bytesWritten bytes Written - * @param contentLength content length of request body - * @param done write end - */ - void onUploadProgress(long bytesWritten, long contentLength, boolean done); - - /** - * This is called when the API download processing. - * - * @param bytesRead bytes Read - * @param contentLength content length of the response - * @param done Read end - */ - void onDownloadProgress(long bytesRead, long contentLength, boolean done); -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiResponse.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiResponse.java deleted file mode 100644 index 3826fd0754..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ApiResponse.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.algolia; - -import java.util.List; -import java.util.Map; - -/** - * API response returned by API call. - * - * @param The type of data that is deserialized from response body - */ -public class ApiResponse { - - private final int statusCode; - private final Map> headers; - private final T data; - - /** - * @param statusCode The status code of HTTP response - * @param headers The headers of HTTP response - */ - public ApiResponse(int statusCode, Map> headers) { - this(statusCode, headers, null); - } - - /** - * @param statusCode The status code of HTTP response - * @param headers The headers of HTTP response - * @param data The object deserialized from response bod - */ - public ApiResponse( - int statusCode, - Map> headers, - T data - ) { - this.statusCode = statusCode; - this.headers = headers; - this.data = data; - } - - public int getStatusCode() { - return statusCode; - } - - public Map> getHeaders() { - return headers; - } - - public T getData() { - return data; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ProgressRequestBody.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ProgressRequestBody.java deleted file mode 100644 index 42c926955c..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ProgressRequestBody.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.algolia; - -import java.io.IOException; -import okhttp3.MediaType; -import okhttp3.RequestBody; -import okio.Buffer; -import okio.BufferedSink; -import okio.ForwardingSink; -import okio.Okio; -import okio.Sink; - -public class ProgressRequestBody extends RequestBody { - - private final RequestBody requestBody; - - private final ApiCallback callback; - - public ProgressRequestBody(RequestBody requestBody, ApiCallback callback) { - this.requestBody = requestBody; - this.callback = callback; - } - - @Override - public MediaType contentType() { - return requestBody.contentType(); - } - - @Override - public long contentLength() throws IOException { - return requestBody.contentLength(); - } - - @Override - public void writeTo(BufferedSink sink) throws IOException { - BufferedSink bufferedSink = Okio.buffer(sink(sink)); - requestBody.writeTo(bufferedSink); - bufferedSink.flush(); - } - - private Sink sink(Sink sink) { - return new ForwardingSink(sink) { - long bytesWritten = 0L; - long contentLength = 0L; - - @Override - public void write(Buffer source, long byteCount) throws IOException { - super.write(source, byteCount); - if (contentLength == 0) { - contentLength = contentLength(); - } - - bytesWritten += byteCount; - callback.onUploadProgress( - bytesWritten, - contentLength, - bytesWritten == contentLength - ); - } - }; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ProgressResponseBody.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ProgressResponseBody.java deleted file mode 100644 index d5f13aa6e5..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/ProgressResponseBody.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.algolia; - -import java.io.IOException; -import okhttp3.MediaType; -import okhttp3.ResponseBody; -import okio.Buffer; -import okio.BufferedSource; -import okio.ForwardingSource; -import okio.Okio; -import okio.Source; - -public class ProgressResponseBody extends ResponseBody { - - private final ResponseBody responseBody; - private final ApiCallback callback; - private BufferedSource bufferedSource; - - public ProgressResponseBody(ResponseBody responseBody, ApiCallback callback) { - this.responseBody = responseBody; - this.callback = callback; - } - - @Override - public MediaType contentType() { - return responseBody.contentType(); - } - - @Override - public long contentLength() { - return responseBody.contentLength(); - } - - @Override - public BufferedSource source() { - if (bufferedSource == null) { - bufferedSource = Okio.buffer(source(responseBody.source())); - } - return bufferedSource; - } - - private Source source(Source source) { - return new ForwardingSource(source) { - long totalBytesRead = 0L; - - @Override - public long read(Buffer sink, long byteCount) throws IOException { - long bytesRead = super.read(sink, byteCount); - // read() returns the number of bytes read, or -1 if this source is exhausted. - totalBytesRead += bytesRead != -1 ? bytesRead : 0; - callback.onDownloadProgress( - totalBytesRead, - responseBody.contentLength(), - bytesRead == -1 - ); - return bytesRead; - } - }; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaApiException.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaApiException.java index 40ca6e1835..ab8dc91ab9 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaApiException.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaApiException.java @@ -3,6 +3,8 @@ /** Exception thrown in case of API failure such as 4XX, 5XX error. */ public class AlgoliaApiException extends AlgoliaRuntimeException { + public static final long serialVersionUID = -1L; + public int getHttpErrorCode() { return httpErrorCode; } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRetryException.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRetryException.java index bb0668b6e2..3fbb98c608 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRetryException.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRetryException.java @@ -6,6 +6,8 @@ */ public class AlgoliaRetryException extends AlgoliaRuntimeException { + public static final long serialVersionUID = -1L; + public AlgoliaRetryException(String message, Throwable cause) { super(message, cause); } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRuntimeException.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRuntimeException.java index 6ba51537d8..1099fea1c2 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRuntimeException.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/AlgoliaRuntimeException.java @@ -3,6 +3,8 @@ /** Exception thrown when an error occurs during the Serialization/Deserialization process */ public class AlgoliaRuntimeException extends RuntimeException { + public static final long serialVersionUID = -1L; + public AlgoliaRuntimeException(String message, Throwable cause) { super(message, cause); } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/LaunderThrowable.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/LaunderThrowable.java new file mode 100644 index 0000000000..d1187b76d5 --- /dev/null +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/LaunderThrowable.java @@ -0,0 +1,39 @@ +package com.algolia.exceptions; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +@SuppressWarnings("WeakerAccess") +public class LaunderThrowable { + + /** + * Performs a get() on the asynchronous method. Launders both Interrupted and Execution exception + * to business exception + * + * @param f The CompletableFuture to block on. + */ + public static T await(CompletableFuture f) { + try { + return f.get(); + } catch (InterruptedException | ExecutionException e) { + throw LaunderThrowable.launder(e); + } + } + + /** Launders both Interrupted and Execution exception into business exception */ + public static RuntimeException launder(Throwable t) { + if (t.getCause() instanceof AlgoliaApiException) { + throw (AlgoliaApiException) t.getCause(); + } + + if (t.getCause() instanceof AlgoliaRetryException) { + throw (AlgoliaRetryException) t.getCause(); + } + + if (t.getCause() instanceof AlgoliaRuntimeException) { + throw (AlgoliaRuntimeException) t.getCause(); + } + + throw new AlgoliaRuntimeException(t); + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/HttpRequester.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/HttpRequester.java index 07cbae53b4..5b60a89d1d 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/HttpRequester.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/HttpRequester.java @@ -1,14 +1,14 @@ package com.algolia.utils; -import com.algolia.ApiCallback; -import com.algolia.ProgressResponseBody; +import com.algolia.ApiClient; +import com.algolia.exceptions.*; import com.algolia.utils.retry.RetryStrategy; import com.algolia.utils.retry.StatefulHost; import java.io.IOException; +import java.lang.reflect.Type; import java.util.List; import java.util.concurrent.TimeUnit; import okhttp3.Call; -import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -27,7 +27,6 @@ public HttpRequester(List hosts) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.addInterceptor(retryStrategy.getRetryInterceptor()); - builder.addNetworkInterceptor(getProgressInterceptor()); builder.retryOnConnectionFailure(false); httpClient = builder.build(); @@ -37,6 +36,85 @@ public Call newCall(Request request) { return httpClient.newCall(request); } + public T handleResponse(Response response, Type returnType) + throws AlgoliaRuntimeException { + if (response.isSuccessful()) { + if (returnType == null || response.code() == 204) { + // returning null if the returnType is not defined, or the status code is 204 (No Content) + if (response.body() != null) { + try { + response.body().close(); + } catch (Exception e) { + throw new AlgoliaApiException( + response.message(), + e, + response.code() + ); + } + } + return null; + } else { + return deserialize(response, returnType); + } + } else { + if (response.body() != null) { + try { + response.body().string(); + } catch (IOException e) { + throw new AlgoliaApiException(response.message(), e, response.code()); + } + } + throw new AlgoliaApiException(response.message(), response.code()); + } + } + + private T deserialize(Response response, Type returnType) + throws AlgoliaRuntimeException { + if (response == null || returnType == null) { + return null; + } + + if ("byte[]".equals(returnType.toString())) { + // Handle binary response (byte array). + try { + return (T) response.body().bytes(); + } catch (IOException e) { + throw new AlgoliaRuntimeException(e); + } + } + + String respBody; + try { + if (response.body() != null) respBody = + response.body().string(); else respBody = null; + } catch (IOException e) { + throw new AlgoliaRuntimeException(e); + } + + if (respBody == null || "".equals(respBody)) { + return null; + } + + String contentType = response.headers().get("Content-Type"); + if (contentType == null) { + contentType = "application/json"; + } + if (ApiClient.isJsonMime(contentType)) { + return JSON.deserialize(respBody, returnType); + } else if (returnType.equals(String.class)) { + // Expecting string, return the raw response body. + return (T) respBody; + } else { + throw new AlgoliaApiException( + "Content type \"" + + contentType + + "\" is not supported for type: " + + returnType, + response.code() + ); + } + } + public void setDebugging(boolean debugging) { if (debugging != this.debugging) { if (debugging) { @@ -89,26 +167,4 @@ public void setWriteTimeout(int writeTimeout) { .writeTimeout(writeTimeout, TimeUnit.MILLISECONDS) .build(); } - - /** - * Get network interceptor to add it to the httpClient to track download progress for async - * requests. - */ - private Interceptor getProgressInterceptor() { - return new Interceptor() { - @Override - public Response intercept(Interceptor.Chain chain) throws IOException { - final Request request = chain.request(); - final Response originalResponse = chain.proceed(request); - if (request.tag() instanceof ApiCallback) { - final ApiCallback callback = (ApiCallback) request.tag(); - return originalResponse - .newBuilder() - .body(new ProgressResponseBody(originalResponse.body(), callback)) - .build(); - } - return originalResponse; - } - }; - } } diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/JSON.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/JSON.java similarity index 99% rename from clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/JSON.java rename to clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/JSON.java index a924c616e8..7b6cf2f7f7 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/JSON.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/JSON.java @@ -1,4 +1,4 @@ -package com.algolia; +package com.algolia.utils; import com.google.gson.FieldNamingPolicy; import com.google.gson.FieldNamingStrategy; diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/Requester.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/Requester.java index 919dd7c8bb..65793ea63f 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/Requester.java +++ b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/Requester.java @@ -1,11 +1,17 @@ package com.algolia.utils; +import com.algolia.exceptions.AlgoliaRuntimeException; +import java.lang.reflect.Type; import okhttp3.Call; import okhttp3.Request; +import okhttp3.Response; public interface Requester { public Call newCall(Request request); + public T handleResponse(Response response, Type returnType) + throws AlgoliaRuntimeException; + /** * Enable/disable debugging for this API client. * diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/CallEcho.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/CallEcho.java deleted file mode 100644 index 1712669790..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/CallEcho.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.algolia.utils.echo; - -import java.io.IOException; -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.Request; -import okhttp3.Response; -import okio.Timeout; - -public class CallEcho implements Call { - - private Request request; - - public CallEcho(Request request) { - this.request = request; - } - - @Override - public Request request() { - return request; - } - - @Override - public void cancel() {} - - @Override - public Call clone() { - return null; - } - - @Override - public void enqueue(Callback arg0) {} - - @Override - public Response execute() throws IOException { - return null; - } - - @Override - public boolean isExecuted() { - return false; - } - - @Override - public boolean isCanceled() { - return false; - } - - @Override - public Timeout timeout() { - return null; - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseAbtesting.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseAbtesting.java deleted file mode 100644 index 4ad44229ab..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseAbtesting.java +++ /dev/null @@ -1,314 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.model.abtesting.*; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponseAbtesting { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - public static class AddABTests - extends ABTestResponse - implements EchoResponseInterface { - - private Request request; - - public AddABTests(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteABTest - extends ABTestResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteABTest(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetABTest - extends ABTest - implements EchoResponseInterface { - - private Request request; - - public GetABTest(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ListABTests - extends ListABTestsResponse - implements EchoResponseInterface { - - private Request request; - - public ListABTests(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class StopABTest - extends ABTestResponse - implements EchoResponseInterface { - - private Request request; - - public StopABTest(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseAnalytics.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseAnalytics.java deleted file mode 100644 index 7cff6ad71d..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseAnalytics.java +++ /dev/null @@ -1,698 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.model.analytics.*; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponseAnalytics { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetAverageClickPosition - extends GetAverageClickPositionResponse - implements EchoResponseInterface { - - private Request request; - - public GetAverageClickPosition(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetClickPositions - extends GetClickPositionsResponse - implements EchoResponseInterface { - - private Request request; - - public GetClickPositions(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetClickThroughRate - extends GetClickThroughRateResponse - implements EchoResponseInterface { - - private Request request; - - public GetClickThroughRate(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetConversationRate - extends GetConversationRateResponse - implements EchoResponseInterface { - - private Request request; - - public GetConversationRate(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetNoClickRate - extends GetNoClickRateResponse - implements EchoResponseInterface { - - private Request request; - - public GetNoClickRate(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetNoResultsRate - extends GetNoResultsRateResponse - implements EchoResponseInterface { - - private Request request; - - public GetNoResultsRate(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetSearchesCount - extends GetSearchesCountResponse - implements EchoResponseInterface { - - private Request request; - - public GetSearchesCount(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetSearchesNoClicks - extends GetSearchesNoClicksResponse - implements EchoResponseInterface { - - private Request request; - - public GetSearchesNoClicks(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetSearchesNoResults - extends GetSearchesNoResultsResponse - implements EchoResponseInterface { - - private Request request; - - public GetSearchesNoResults(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetStatus - extends GetStatusResponse - implements EchoResponseInterface { - - private Request request; - - public GetStatus(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetTopCountries - extends GetTopCountriesResponse - implements EchoResponseInterface { - - private Request request; - - public GetTopCountries(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetTopFilterAttributes - extends GetTopFilterAttributesResponse - implements EchoResponseInterface { - - private Request request; - - public GetTopFilterAttributes(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetTopFilterForAttribute - extends GetTopFilterForAttributeResponse - implements EchoResponseInterface { - - private Request request; - - public GetTopFilterForAttribute(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetTopFiltersNoResults - extends GetTopFiltersNoResultsResponse - implements EchoResponseInterface { - - private Request request; - - public GetTopFiltersNoResults(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetTopHits - extends GetTopHitsResponse - implements EchoResponseInterface { - - private Request request; - - public GetTopHits(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetTopSearches - extends GetTopSearchesResponse - implements EchoResponseInterface { - - private Request request; - - public GetTopSearches(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetUsersCount - extends GetUsersCountResponse - implements EchoResponseInterface { - - private Request request; - - public GetUsersCount(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseInsights.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseInsights.java deleted file mode 100644 index 0289ca9ead..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseInsights.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.model.insights.*; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponseInsights { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class PushEvents - extends PushEventsResponse - implements EchoResponseInterface { - - private Request request; - - public PushEvents(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseInterface.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseInterface.java deleted file mode 100644 index 7e3e75251f..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseInterface.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.algolia.utils.echo; - -import java.util.Map; - -public interface EchoResponseInterface { - public String getPath(); - - public String getMethod(); - - public String getBody(); - - public Map getQueryParams(); -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponsePersonalization.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponsePersonalization.java deleted file mode 100644 index a3810c129b..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponsePersonalization.java +++ /dev/null @@ -1,282 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.model.personalization.*; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponsePersonalization { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteUserProfile - extends DeleteUserProfileResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteUserProfile(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetPersonalizationStrategy - extends PersonalizationStrategyParams - implements EchoResponseInterface { - - private Request request; - - public GetPersonalizationStrategy(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetUserTokenProfile - extends GetUserTokenResponse - implements EchoResponseInterface { - - private Request request; - - public GetUserTokenProfile(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SetPersonalizationStrategy - extends SetPersonalizationStrategyResponse - implements EchoResponseInterface { - - private Request request; - - public SetPersonalizationStrategy(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponsePredict.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponsePredict.java deleted file mode 100644 index eddb0c833a..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponsePredict.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.model.predict.*; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponsePredict { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class FetchUserProfile - extends FetchUserProfileResponse - implements EchoResponseInterface { - - private Request request; - - public FetchUserProfile(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseQuerySuggestions.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseQuerySuggestions.java deleted file mode 100644 index d45cdf8862..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseQuerySuggestions.java +++ /dev/null @@ -1,379 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.model.querySuggestions.*; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponseQuerySuggestions { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - public static class CreateConfig - extends SucessResponse - implements EchoResponseInterface { - - private Request request; - - public CreateConfig(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteConfig - extends SucessResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteConfig(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetAllConfigs - extends ArrayList - implements EchoResponseInterface { - - private Request request; - - public GetAllConfigs(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetConfig - extends QuerySuggestionsIndex - implements EchoResponseInterface { - - private Request request; - - public GetConfig(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetConfigStatus - extends Status - implements EchoResponseInterface { - - private Request request; - - public GetConfigStatus(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetLogFile - extends ArrayList - implements EchoResponseInterface { - - private Request request; - - public GetLogFile(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class UpdateConfig - extends SucessResponse - implements EchoResponseInterface { - - private Request request; - - public UpdateConfig(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseRecommend.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseRecommend.java deleted file mode 100644 index c291de625d..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseRecommend.java +++ /dev/null @@ -1,186 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.model.recommend.*; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponseRecommend { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetRecommendations - extends GetRecommendationsResponse - implements EchoResponseInterface { - - private Request request; - - public GetRecommendations(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } -} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseSearch.java b/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseSearch.java deleted file mode 100644 index 58ac23d832..0000000000 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseSearch.java +++ /dev/null @@ -1,1975 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.model.search.*; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - -public class EchoResponseSearch { - - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - public static class AddApiKey - extends AddApiKeyResponse - implements EchoResponseInterface { - - private Request request; - - public AddApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class AddOrUpdateObject - extends UpdatedAtWithObjectIdResponse - implements EchoResponseInterface { - - private Request request; - - public AddOrUpdateObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class AppendSource - extends CreatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public AppendSource(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class AssignUserId - extends CreatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public AssignUserId(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Batch - extends BatchResponse - implements EchoResponseInterface { - - private Request request; - - public Batch(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class BatchAssignUserIds - extends CreatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public BatchAssignUserIds(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class BatchDictionaryEntries - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public BatchDictionaryEntries(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class BatchRules - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public BatchRules(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Browse - extends BrowseResponse - implements EchoResponseInterface { - - private Request request; - - public Browse(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ClearAllSynonyms - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public ClearAllSynonyms(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ClearObjects - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public ClearObjects(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ClearRules - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public ClearRules(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Del extends Object implements EchoResponseInterface { - - private Request request; - - public Del(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteApiKey - extends DeleteApiKeyResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteBy - extends DeletedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteBy(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteIndex - extends DeletedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteIndex(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteObject - extends DeletedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteRule - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteRule(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteSource - extends DeleteSourceResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteSource(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class DeleteSynonym - extends DeletedAtResponse - implements EchoResponseInterface { - - private Request request; - - public DeleteSynonym(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Get extends Object implements EchoResponseInterface { - - private Request request; - - public Get(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetApiKey extends Key implements EchoResponseInterface { - - private Request request; - - public GetApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetDictionaryLanguages - extends HashMap - implements EchoResponseInterface { - - private Request request; - - public GetDictionaryLanguages(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetDictionarySettings - extends GetDictionarySettingsResponse - implements EchoResponseInterface { - - private Request request; - - public GetDictionarySettings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetLogs - extends GetLogsResponse - implements EchoResponseInterface { - - private Request request; - - public GetLogs(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetObject - extends HashMap - implements EchoResponseInterface { - - private Request request; - - public GetObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetObjects - extends GetObjectsResponse - implements EchoResponseInterface { - - private Request request; - - public GetObjects(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetRule extends Rule implements EchoResponseInterface { - - private Request request; - - public GetRule(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetSettings - extends IndexSettings - implements EchoResponseInterface { - - private Request request; - - public GetSettings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetSources - extends ArrayList - implements EchoResponseInterface { - - private Request request; - - public GetSources(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetSynonym - extends SynonymHit - implements EchoResponseInterface { - - private Request request; - - public GetSynonym(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetTask - extends GetTaskResponse - implements EchoResponseInterface { - - private Request request; - - public GetTask(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetTopUserIds - extends GetTopUserIdsResponse - implements EchoResponseInterface { - - private Request request; - - public GetTopUserIds(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class GetUserId - extends UserId - implements EchoResponseInterface { - - private Request request; - - public GetUserId(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class HasPendingMappings - extends CreatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public HasPendingMappings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ListApiKeys - extends ListApiKeysResponse - implements EchoResponseInterface { - - private Request request; - - public ListApiKeys(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ListClusters - extends ListClustersResponse - implements EchoResponseInterface { - - private Request request; - - public ListClusters(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ListIndices - extends ListIndicesResponse - implements EchoResponseInterface { - - private Request request; - - public ListIndices(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ListUserIds - extends ListUserIdsResponse - implements EchoResponseInterface { - - private Request request; - - public ListUserIds(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class MultipleBatch - extends MultipleBatchResponse - implements EchoResponseInterface { - - private Request request; - - public MultipleBatch(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class MultipleQueries - extends MultipleQueriesResponse - implements EchoResponseInterface { - - private Request request; - - public MultipleQueries(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class OperationIndex - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public OperationIndex(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class PartialUpdateObject - extends UpdatedAtWithObjectIdResponse - implements EchoResponseInterface { - - private Request request; - - public PartialUpdateObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Post extends Object implements EchoResponseInterface { - - private Request request; - - public Post(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Put extends Object implements EchoResponseInterface { - - private Request request; - - public Put(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class RemoveUserId - extends RemoveUserIdResponse - implements EchoResponseInterface { - - private Request request; - - public RemoveUserId(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class ReplaceSources - extends ReplaceSourceResponse - implements EchoResponseInterface { - - private Request request; - - public ReplaceSources(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class RestoreApiKey - extends AddApiKeyResponse - implements EchoResponseInterface { - - private Request request; - - public RestoreApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SaveObject - extends SaveObjectResponse - implements EchoResponseInterface { - - private Request request; - - public SaveObject(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SaveRule - extends UpdatedRuleResponse - implements EchoResponseInterface { - - private Request request; - - public SaveRule(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SaveSynonym - extends SaveSynonymResponse - implements EchoResponseInterface { - - private Request request; - - public SaveSynonym(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SaveSynonyms - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public SaveSynonyms(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class Search - extends SearchResponse - implements EchoResponseInterface { - - private Request request; - - public Search(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SearchDictionaryEntries - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public SearchDictionaryEntries(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SearchForFacetValues - extends SearchForFacetValuesResponse - implements EchoResponseInterface { - - private Request request; - - public SearchForFacetValues(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SearchRules - extends SearchRulesResponse - implements EchoResponseInterface { - - private Request request; - - public SearchRules(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SearchSynonyms - extends SearchSynonymsResponse - implements EchoResponseInterface { - - private Request request; - - public SearchSynonyms(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SearchUserIds - extends SearchUserIdsResponse - implements EchoResponseInterface { - - private Request request; - - public SearchUserIds(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SetDictionarySettings - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public SetDictionarySettings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class SetSettings - extends UpdatedAtResponse - implements EchoResponseInterface { - - private Request request; - - public SetSettings(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - - public static class UpdateApiKey - extends UpdateApiKeyResponse - implements EchoResponseInterface { - - private Request request; - - public UpdateApiKey(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } -} diff --git a/config/generation.config.js b/config/generation.config.js index 7cba74f46c..7fe777d97d 100644 --- a/config/generation.config.js +++ b/config/generation.config.js @@ -12,11 +12,10 @@ module.exports = { // Java '!clients/algoliasearch-client-java-2/*.gradle', '!clients/algoliasearch-client-java-2/.gitignore', + '!clients/algoliasearch-client-java-2/gradle/wrapper/**', '!clients/algoliasearch-client-java-2/algoliasearch-core/build.gradle', - '!clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/*', - '!clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/*', - 'clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponse*.java', - '!clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoResponseInterface.java', + '!clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/**', + '!clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/**', // JavaScript '!clients/algoliasearch-client-javascript/*', diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java index 95bb636487..05c6ce43d2 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java @@ -87,41 +87,6 @@ public Map postProcessAllModels(Map objs) { return models; } - @Override - public Map postProcessSupportingFileData( - Map objs - ) { - Map bundle = super.postProcessSupportingFileData(objs); - List> apis = - ((Map>>) bundle.get("apiInfo")).get( - "apis" - ); - - for (Map api : apis) { - String clientName = (String) api.get("baseName"); - supportingFiles.add( - new SupportingFile( - "EchoResponse.mustache", - sourceFolder + "/com/algolia/utils/echo", - "EchoResponse" + clientName + ".java" - ) - ); - - List operations = - ((Map>) api.get("operations")).get( - "operation" - ); - - for (CodegenOperation ope : operations) { - ope.returnType = - ope.returnType - .replace("Map<", "HashMap<") - .replace("List<", "ArrayList<"); - } - } - return bundle; - } - /** * Returns human-friendly help for the generator. Provide the consumer with help tips, parameters * here @@ -153,6 +118,11 @@ public void processOpts() { file.getTemplateFile().equals("build.gradle.mustache") || file.getTemplateFile().equals("settings.gradle.mustache") || file.getTemplateFile().equals("gitignore.mustache") || + file.getTemplateFile().equals("ApiCallback.mustache") || + file.getTemplateFile().equals("ApiResponse.mustache") || + file.getTemplateFile().equals("JSON.mustache") || + file.getTemplateFile().equals("ProgressRequestBody.mustache") || + file.getTemplateFile().equals("ProgressResponseBody.mustache") || file.getTemplateFile().equals("Pair.mustache") ); } diff --git a/playground/java/build.gradle b/playground/java/build.gradle index 35b0a9183a..e15b9dd01e 100644 --- a/playground/java/build.gradle +++ b/playground/java/build.gradle @@ -22,5 +22,5 @@ tasks.withType(JavaCompile) { } application { - mainClass = "com.algolia.playground.App" + mainClass = project.hasProperty("mainClass") ? project.getProperty("mainClass") : "NULL" } diff --git a/playground/java/src/main/java/com/algolia/playground/Insights.java b/playground/java/src/main/java/com/algolia/playground/Insights.java new file mode 100644 index 0000000000..3c47c16d13 --- /dev/null +++ b/playground/java/src/main/java/com/algolia/playground/Insights.java @@ -0,0 +1,52 @@ +package com.algolia.playground; + +import com.algolia.exceptions.AlgoliaApiException; +import com.algolia.exceptions.AlgoliaRetryException; +import com.algolia.exceptions.AlgoliaRuntimeException; +import com.algolia.model.insights.*; +import com.algolia.api.InsightsClient; +import com.algolia.utils.UserAgent; +import io.github.cdimascio.dotenv.Dotenv; + +public class Insights { + public static void main(String[] args) { + Dotenv dotenv = Dotenv.configure().directory("../").load(); + + InsightsClient client = new InsightsClient( + dotenv.get("ALGOLIA_APPLICATION_ID"), + dotenv.get("ALGOLIA_SEARCH_KEY"), + new UserAgent.Segment[] { + new UserAgent.Segment("test", "8.0.0"), + new UserAgent.Segment("JVM", "11.0.14"), + new UserAgent.Segment("no version"), + } + ); + + String indexName = dotenv.get("SEARCH_INDEX"); + InsightEvents params = new InsightEvents(); + InsightEvent event = new InsightEvent(); + event.setEventType(EventType.CLICK); + event.setUserToken("user"); + event.setIndex("test_what"); + event.setEventName("test"); + params.addEvents(event); + + try { + PushEventsResponse result = client.pushEvents(params); + System.out.println(result); + } catch (AlgoliaApiException e) { + // the API failed + System.err.println("Exception when calling InsightsClient#pushEvents"); + System.err.println("Status code: " + e.getHttpErrorCode()); + System.err.println("Reason: " + e.getMessage()); + e.printStackTrace(); + } catch (AlgoliaRetryException e) { + // the retry failed + System.err.println("Exception in the retry strategy"); + e.printStackTrace(); + } catch (AlgoliaRuntimeException e) { + // the serialization or something else failed + e.printStackTrace(); + } + } +} diff --git a/playground/java/src/main/java/com/algolia/playground/App.java b/playground/java/src/main/java/com/algolia/playground/Search.java similarity index 74% rename from playground/java/src/main/java/com/algolia/playground/App.java rename to playground/java/src/main/java/com/algolia/playground/Search.java index 5ecbc9f662..c650ab5f50 100644 --- a/playground/java/src/main/java/com/algolia/playground/App.java +++ b/playground/java/src/main/java/com/algolia/playground/Search.java @@ -7,9 +7,12 @@ import com.algolia.api.SearchClient; import com.algolia.utils.UserAgent; import io.github.cdimascio.dotenv.Dotenv; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.lang.InterruptedException; -public class App { - +public class Search { + public static void main(String[] args) { Dotenv dotenv = Dotenv.configure().directory("../").load(); @@ -29,11 +32,18 @@ public static void main(String[] args) { params.setQuery(dotenv.get("SEARCH_QUERY")); try { - SearchResponse result = client.search( + CompletableFuture result = client.searchAsync( indexName, SearchParams.ofSearchParamsObject(params) ); - System.out.println(result); + SearchResponse sr = result.get(); + System.out.println(sr); + } catch(InterruptedException e) { + System.err.println("InterrupedException" + e.getMessage()); + e.printStackTrace(); + } catch(ExecutionException e) { + System.err.println("ExecutionException" + e.getMessage()); + e.printStackTrace(); } catch (AlgoliaApiException e) { // the API failed System.err.println("Exception when calling SearchClient#search"); diff --git a/scripts/ci/githubActions/createMatrix.ts b/scripts/ci/githubActions/createMatrix.ts index 1c3a2b13ae..e62642e8c4 100644 --- a/scripts/ci/githubActions/createMatrix.ts +++ b/scripts/ci/githubActions/createMatrix.ts @@ -83,6 +83,10 @@ async function getClientMatrix(baseBranch: string): Promise { continue; } + const testOutputBase = `./tests/output/${language}/${getTestOutputFolder( + language + )}`; + clientMatrix.client.push({ language, path: matrix[language].path, @@ -93,9 +97,7 @@ async function getClientMatrix(baseBranch: string): Promise { `templates/${language}`, `generators/src`, ]), - testsOutputPath: `./tests/output/${language}/${getTestOutputFolder( - language - )}`, + testsOutputPathToClean: `${testOutputBase}/client ${testOutputBase}/methods`, }); console.log(`::set-output name=RUN_GEN_${language.toUpperCase()}::true`); } diff --git a/scripts/ci/githubActions/types.ts b/scripts/ci/githubActions/types.ts index 648eb92c50..781e1177d7 100644 --- a/scripts/ci/githubActions/types.ts +++ b/scripts/ci/githubActions/types.ts @@ -32,7 +32,7 @@ export type ClientMatrix = BaseMatrix & { /** * The test output path to clean. */ - testsOutputPath: string; + testsOutputPathToClean: string; }; export type SpecMatrix = BaseMatrix & { diff --git a/scripts/playground.ts b/scripts/playground.ts index 65c7d402dd..6069bb7686 100644 --- a/scripts/playground.ts +++ b/scripts/playground.ts @@ -1,4 +1,5 @@ import { run } from './common'; +import { capitalize } from './cts/utils'; import type { Language } from './types'; export async function playground({ @@ -16,9 +17,14 @@ export async function playground({ }); break; case 'java': - await run(`./gradle/gradlew -p playground/java run`, { - verbose, - }); + await run( + `./gradle/gradlew -p playground/java -PmainClass=com.algolia.playground.${capitalize( + client + )} run`, + { + verbose, + } + ); break; case 'php': await run( diff --git a/templates/java/EchoResponse.mustache b/templates/java/EchoResponse.mustache deleted file mode 100644 index 1d6a6714eb..0000000000 --- a/templates/java/EchoResponse.mustache +++ /dev/null @@ -1,71 +0,0 @@ -package com.algolia.utils.echo; - -import com.algolia.Pair; -import {{#apiInfo}}{{#apis}}{{{modelPackage}}}{{/apis}}{{/apiInfo}}.*; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import okhttp3.HttpUrl; -import okhttp3.Request; -import okio.Buffer; - - -public class EchoResponse{{#apiInfo}}{{#apis}}{{{baseName}}}{{/apis}}{{/apiInfo}} { - private static String parseRequestBody(Request req) { - try { - final Request copy = req.newBuilder().build(); - final Buffer buffer = new Buffer(); - copy.body().writeTo(buffer); - return buffer.readUtf8(); - } catch (final IOException e) { - return "error"; - } - } - - private static Map buildQueryParams(Request req) { - Map params = new HashMap(); - HttpUrl url = req.url(); - for (String name : url.queryParameterNames()) { - for (String value : url.queryParameterValues(name)) { - params.put(name, value); - } - } - return params; - } - - {{#apiInfo}}{{#apis}} - {{#operations}}{{#operation}} - public static class {{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}} extends {{{returnType}}} implements EchoResponseInterface { - private Request request; - - public {{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}}(Request request) { - this.request = request; - } - - public String getPath() { - return request.url().encodedPath(); - } - - public String getMethod() { - return request.method(); - } - - public String getBody() { - return parseRequestBody(request); - } - - public Map getQueryParams() { - return buildQueryParams(request); - } - - // to satisfy CompoundType in case it's a parent - public Object getInsideValue() { - return null; - } - } - {{/operation}}{{/operations}} - {{/apis}}{{/apiInfo}} -} diff --git a/templates/java/JSON.mustache b/templates/java/JSON.mustache deleted file mode 100644 index a8b85f3384..0000000000 --- a/templates/java/JSON.mustache +++ /dev/null @@ -1,560 +0,0 @@ -package {{invokerPackage}}; - -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.lang.reflect.Field; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.text.ParseException; -import java.text.ParsePosition; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.IdentityHashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.TreeMap; -import java.util.WeakHashMap; -import java.util.concurrent.ConcurrentHashMap; - -import com.google.gson.FieldNamingPolicy; -import com.google.gson.FieldNamingStrategy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.InstanceCreator; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSyntaxException; -import com.google.gson.TypeAdapter; -import com.google.gson.TypeAdapterFactory; -import com.google.gson.annotations.SerializedName; -import com.google.gson.internal.$Gson$Types; -import com.google.gson.internal.ConstructorConstructor; -import com.google.gson.internal.Excluder; -import com.google.gson.internal.LinkedTreeMap; -import com.google.gson.internal.ObjectConstructor; -import com.google.gson.internal.Primitives; -import com.google.gson.internal.bind.MapTypeAdapterFactory; -import com.google.gson.internal.bind.util.ISO8601Utils; -import com.google.gson.reflect.TypeToken; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonToken; -import com.google.gson.stream.JsonWriter; - -import io.gsonfire.GsonFireBuilder; -import okio.ByteString; - -public class JSON { - private static Gson gson; - private static final ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter(); - private static final RetainFieldMapFactory mapAdapter = new RetainFieldMapFactory(); - - static { - gson = createGson() - .registerTypeAdapter(byte[].class, byteArrayAdapter) - .registerTypeAdapterFactory(mapAdapter) - .create(); - } - - public static GsonBuilder createGson() { - GsonFireBuilder fireBuilder = new GsonFireBuilder() - {{#models}} - {{#model}} - {{#discriminator}} - .registerTypeSelector({{classname}}.class, new TypeSelector<{{classname}}>() { - @Override - public Class getClassForElement(JsonElement readElement) { - Map classByDiscriminatorValue = new HashMap(); - {{#mappedModels}} - classByDiscriminatorValue.put("{{mappingName}}"{{^discriminatorCaseSensitive}}.toUpperCase(Locale.ROOT){{/discriminatorCaseSensitive}}, {{modelName}}.class); - {{/mappedModels}} - classByDiscriminatorValue.put("{{name}}"{{^discriminatorCaseSensitive}}.toUpperCase(Locale.ROOT){{/discriminatorCaseSensitive}}, {{classname}}.class); - return getClassByDiscriminator(classByDiscriminatorValue, - getDiscriminatorValue(readElement, "{{{propertyBaseName}}}")); - } - }) - {{/discriminator}} - {{/model}} - {{/models}}; - return fireBuilder.createGsonBuilder(); - } - - // Suppress default constructor for noninstantiability - private JSON() { - throw new AssertionError(); - } - - /** - * Get Gson. - * - * @return Gson - */ - public static Gson getGson() { - return gson; - } - - /** - * Set Gson. - * - * @param gson Gson - * @return JSON - */ - public static void setGson(Gson gon) { - gson = gon; - } - - /** - * Serialize the given Java object into JSON string. - * - * @param obj Object - * @return String representation of the JSON - */ - public static String serialize(Object obj) { - return gson.toJson(obj); - } - - /** - * Deserialize the given JSON string to Java object. - * - * @param Type - * @param body The JSON string - * @param returnType The type to deserialize into - * @return The deserialized Java object - */ - public static T deserialize(String body, Type returnType) { - try { - return gson.fromJson(body, returnType); - } catch (JsonParseException e) { - // Fallback processing when failed to parse JSON form response body: - // return the response body string directly for the String return type; - if (returnType != null && returnType.equals(String.class)) { - return (T) body; - } else { - throw (e); - } - } - } -} - -/** -* Gson TypeAdapter for Byte Array type -*/ -class ByteArrayAdapter extends TypeAdapter { - @Override - public void write(JsonWriter out, byte[] value) throws IOException { - if (value == null) { - out.nullValue(); - } else { - out.value(ByteString.of(value).base64()); - } - } - - @Override - public byte[] read(JsonReader in) throws IOException { - if (in.peek() == JsonToken.NULL) { - in.nextNull(); - return null; - } - String bytesAsBase64 = in.nextString(); - ByteString byteString = ByteString.decodeBase64(bytesAsBase64); - return byteString != null ? byteString.toByteArray() : new byte[0]; - } -} - -// https://stackoverflow.com/questions/21458468/gson-wont-properly-serialise-a-class-that-extends-hashmap -class RetainFieldMapFactory implements TypeAdapterFactory { - - FieldNamingPolicy fieldNamingPolicy = FieldNamingPolicy.IDENTITY; - ConstructorConstructor constructorConstructor = new ConstructorConstructor( - Collections.>emptyMap()); - MapTypeAdapterFactory defaultMapFactory = new MapTypeAdapterFactory( - constructorConstructor, - false); - ReflectiveFilterMapFieldFactory defaultObjectFactory = new ReflectiveFilterMapFieldFactory( - constructorConstructor, - fieldNamingPolicy, - Excluder.DEFAULT); - - @Override - public TypeAdapter create(Gson gson, TypeToken type) { - final TypeAdapter mapAdapter = defaultMapFactory.create(gson, type); - if (mapAdapter != null) { - return (TypeAdapter) new RetainFieldMapAdapter( - mapAdapter, - defaultObjectFactory.create(gson, type)); - } - return mapAdapter; - } - - class RetainFieldMapAdapter extends TypeAdapter> { - - TypeAdapter> mapAdapter; - ReflectiveTypeAdapterFactory.Adapter> objectAdapter; - - RetainFieldMapAdapter( - TypeAdapter mapAdapter, - ReflectiveTypeAdapterFactory.Adapter objectAdapter) { - this.mapAdapter = mapAdapter; - this.objectAdapter = objectAdapter; - } - - @Override - public void write(final JsonWriter out, Map value) - throws IOException { - if (value == null) { - out.nullValue(); - return; - } - // 1.write object - StringWriter sw = new StringWriter(); - objectAdapter.write(new JsonWriter(sw), value); - - // 2.convert object to a map - Map objectMap = mapAdapter.fromJson(sw.toString()); - - // 3.overwrite fields in object to a copy map - value = new LinkedHashMap(value); - value.putAll(objectMap); - - // 4.write the copy map - mapAdapter.write(out, value); - } - - @Override - public Map read(JsonReader in) throws IOException { - // 1.create map, all key-value retain in map - Map map = mapAdapter.read(in); - - // 2.create object from created map - Map object = objectAdapter.fromJsonTree( - mapAdapter.toJsonTree(map)); - - // 3.remove fields in object from map - for (String field : objectAdapter.boundFields.keySet()) { - map.remove(field); - } - // 4.put map to object - object.putAll(map); - return object; - } - } - - static class ReflectiveFilterMapFieldFactory - extends ReflectiveTypeAdapterFactory { - - public ReflectiveFilterMapFieldFactory( - ConstructorConstructor constructorConstructor, - FieldNamingStrategy fieldNamingPolicy, - Excluder excluder) { - super(constructorConstructor, fieldNamingPolicy, excluder); - } - - @Override - protected boolean shouldFindFieldInClass( - Class willFindClass, - Class originalRaw) { - Class[] endClasses = new Class[] { - Object.class, - HashMap.class, - LinkedHashMap.class, - LinkedTreeMap.class, - Hashtable.class, - TreeMap.class, - ConcurrentHashMap.class, - IdentityHashMap.class, - WeakHashMap.class, - EnumMap.class, - }; - for (Class c : endClasses) { - if (willFindClass == c) - return false; - } - - return super.shouldFindFieldInClass(willFindClass, originalRaw); - } - } - - /** - * below code copy from - * {@link com.google.gson.internal.bind.ReflectiveTypeAdapterFactory} (little - * modify, in source this class is final) Type adapter that reflects over the - * fields and methods - * of a class. - */ - static class ReflectiveTypeAdapterFactory implements TypeAdapterFactory { - - private final ConstructorConstructor constructorConstructor; - private final FieldNamingStrategy fieldNamingPolicy; - private final Excluder excluder; - - public ReflectiveTypeAdapterFactory( - ConstructorConstructor constructorConstructor, - FieldNamingStrategy fieldNamingPolicy, - Excluder excluder) { - this.constructorConstructor = constructorConstructor; - this.fieldNamingPolicy = fieldNamingPolicy; - this.excluder = excluder; - } - - public boolean excludeField(Field f, boolean serialize) { - return (!excluder.excludeClass(f.getType(), serialize) && - !excluder.excludeField(f, serialize)); - } - - private String getFieldName(Field f) { - SerializedName serializedName = f.getAnnotation(SerializedName.class); - return serializedName == null - ? fieldNamingPolicy.translateName(f) - : serializedName.value(); - } - - public Adapter create(Gson gson, final TypeToken type) { - Class raw = type.getRawType(); - - if (!Object.class.isAssignableFrom(raw)) { - return null; // it's a primitive! - } - - ObjectConstructor constructor = constructorConstructor.get(type); - return new Adapter(constructor, getBoundFields(gson, type, raw)); - } - - private ReflectiveTypeAdapterFactory.BoundField createBoundField( - final Gson context, - final Field field, - final String name, - final TypeToken fieldType, - boolean serialize, - boolean deserialize) { - final boolean isPrimitive = Primitives.isPrimitive( - fieldType.getRawType()); - - // special casing primitives here saves ~5% on Android... - return new ReflectiveTypeAdapterFactory.BoundField( - name, - serialize, - deserialize) { - final TypeAdapter typeAdapter = context.getAdapter(fieldType); - - @SuppressWarnings({ "unchecked", "rawtypes" }) // the type adapter and field type always agree - @Override - void write(JsonWriter writer, Object value) - throws IOException, IllegalAccessException { - Object fieldValue = field.get(value); - TypeAdapter t = new TypeAdapterRuntimeTypeWrapper( - context, - this.typeAdapter, - fieldType.getType()); - t.write(writer, fieldValue); - } - - @Override - void read(JsonReader reader, Object value) - throws IOException, IllegalAccessException { - Object fieldValue = typeAdapter.read(reader); - if (fieldValue != null || !isPrimitive) { - field.set(value, fieldValue); - } - } - }; - } - - private Map getBoundFields( - Gson context, - TypeToken type, - Class raw) { - Map result = new LinkedHashMap(); - if (raw.isInterface()) { - return result; - } - - Type declaredType = type.getType(); - Class originalRaw = type.getRawType(); - while (shouldFindFieldInClass(raw, originalRaw)) { - Field[] fields = raw.getDeclaredFields(); - for (Field field : fields) { - boolean serialize = excludeField(field, true); - boolean deserialize = excludeField(field, false); - if (!serialize && !deserialize) { - continue; - } - field.setAccessible(true); - Type fieldType = $Gson$Types.resolve( - type.getType(), - raw, - field.getGenericType()); - BoundField boundField = createBoundField( - context, - field, - getFieldName(field), - TypeToken.get(fieldType), - serialize, - deserialize); - BoundField previous = result.put(boundField.name, boundField); - if (previous != null) { - throw new IllegalArgumentException( - declaredType + - " declares multiple JSON fields named " + - previous.name); - } - } - type = TypeToken.get( - $Gson$Types.resolve(type.getType(), raw, raw.getGenericSuperclass())); - raw = type.getRawType(); - } - return result; - } - - protected boolean shouldFindFieldInClass( - Class willFindClass, - Class originalRaw) { - return willFindClass != Object.class; - } - - abstract static class BoundField { - final String name; - final boolean serialized; - final boolean deserialized; - - protected BoundField( - String name, - boolean serialized, - boolean deserialized) { - this.name = name; - this.serialized = serialized; - this.deserialized = deserialized; - } - - abstract void write(JsonWriter writer, Object value) - throws IOException, IllegalAccessException; - - abstract void read(JsonReader reader, Object value) - throws IOException, IllegalAccessException; - } - - public static final class Adapter extends TypeAdapter { - private final ObjectConstructor constructor; - private final Map boundFields; - - private Adapter( - ObjectConstructor constructor, - Map boundFields) { - this.constructor = constructor; - this.boundFields = boundFields; - } - - @Override - public T read(JsonReader in) throws IOException { - if (in.peek() == JsonToken.NULL) { - in.nextNull(); - return null; - } - - T instance = constructor.construct(); - - try { - in.beginObject(); - while (in.hasNext()) { - String name = in.nextName(); - BoundField field = boundFields.get(name); - if (field == null || !field.deserialized) { - in.skipValue(); - } else { - field.read(in, instance); - } - } - } catch (IllegalStateException e) { - throw new JsonSyntaxException(e); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } - in.endObject(); - return instance; - } - - @Override - public void write(JsonWriter out, T value) throws IOException { - if (value == null) { - out.nullValue(); - return; - } - - out.beginObject(); - try { - for (BoundField boundField : boundFields.values()) { - if (boundField.serialized) { - out.name(boundField.name); - boundField.write(out, value); - } - } - } catch (IllegalAccessException e) { - throw new AssertionError(); - } - out.endObject(); - } - } - } - - static class TypeAdapterRuntimeTypeWrapper extends TypeAdapter { - - private final Gson context; - private final TypeAdapter delegate; - private final Type type; - - TypeAdapterRuntimeTypeWrapper( - Gson context, - TypeAdapter delegate, - Type type) { - this.context = context; - this.delegate = delegate; - this.type = type; - } - - @Override - public T read(JsonReader in) throws IOException { - return delegate.read(in); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void write(JsonWriter out, T value) throws IOException { - // Order of preference for choosing type adapters - // First preference: a type adapter registered for the runtime type - // Second preference: a type adapter registered for the declared type - // Third preference: reflective type adapter for the runtime type (if it is a - // sub class of the declared type) - // Fourth preference: reflective type adapter for the declared type - - TypeAdapter chosen = delegate; - Type runtimeType = getRuntimeTypeIfMoreSpecific(type, value); - if (runtimeType != type) { - TypeAdapter runtimeTypeAdapter = context.getAdapter( - TypeToken.get(runtimeType)); - if (!(runtimeTypeAdapter instanceof ReflectiveTypeAdapterFactory.Adapter)) { - // The user registered a type adapter for the runtime type, so we will use that - chosen = runtimeTypeAdapter; - } else if (!(delegate instanceof ReflectiveTypeAdapterFactory.Adapter)) { - // The user registered a type adapter for Base class, so we prefer it over the - // reflective type adapter for the runtime type - chosen = delegate; - } else { - // Use the type adapter for runtime type - chosen = runtimeTypeAdapter; - } - } - chosen.write(out, value); - } - - /** Finds a compatible runtime type if it is more specific */ - private Type getRuntimeTypeIfMoreSpecific(Type type, Object value) { - if (value != null && - (type == Object.class || - type instanceof TypeVariable || - type instanceof Class)) { - type = value.getClass(); - } - return type; - } - } -} diff --git a/templates/java/JavaTimeFormatter.mustache b/templates/java/JavaTimeFormatter.mustache deleted file mode 100644 index 5850c6425e..0000000000 --- a/templates/java/JavaTimeFormatter.mustache +++ /dev/null @@ -1,58 +0,0 @@ -package {{invokerPackage}}; - -{{^threetenbp}} -import java.time.OffsetDateTime; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; -{{/threetenbp}} -{{#threetenbp}} -import org.threeten.bp.OffsetDateTime; -import org.threeten.bp.format.DateTimeFormatter; -import org.threeten.bp.format.DateTimeParseException; -{{/threetenbp}} - -/** - * Class that add parsing/formatting support for Java 8+ {@code OffsetDateTime} class. - * It's generated for java clients when {@code AbstractJavaCodegen#dateLibrary} specified as {@code java8}. - */ -public class JavaTimeFormatter { - - private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; - - /** - * Get the date format used to parse/format {@code OffsetDateTime} parameters. - * @return DateTimeFormatter - */ - public DateTimeFormatter getOffsetDateTimeFormatter() { - return offsetDateTimeFormatter; - } - - /** - * Set the date format used to parse/format {@code OffsetDateTime} parameters. - * @param offsetDateTimeFormatter {@code DateTimeFormatter} - */ - public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { - this.offsetDateTimeFormatter = offsetDateTimeFormatter; - } - - /** - * Parse the given string into {@code OffsetDateTime} object. - * @param str String - * @return {@code OffsetDateTime} - */ - public OffsetDateTime parseOffsetDateTime(String str) { - try { - return OffsetDateTime.parse(str, offsetDateTimeFormatter); - } catch (DateTimeParseException e) { - throw new RuntimeException(e); - } - } - /** - * Format the given {@code OffsetDateTime} object into string. - * @param offsetDateTime {@code OffsetDateTime} - * @return {@code OffsetDateTime} in string format - */ - public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { - return offsetDateTimeFormatter.format(offsetDateTime); - } -} diff --git a/templates/java/gradle-wrapper.jar.mustache b/templates/java/gradle-wrapper.jar.mustache deleted file mode 100644 index 7454180f2a..0000000000 Binary files a/templates/java/gradle-wrapper.jar.mustache and /dev/null differ diff --git a/templates/java/gradle-wrapper.properties.mustache b/templates/java/gradle-wrapper.properties.mustache deleted file mode 100644 index aa991fceae..0000000000 --- a/templates/java/gradle-wrapper.properties.mustache +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/templates/java/libraries/okhttp-gson/ApiCallback.mustache b/templates/java/libraries/okhttp-gson/ApiCallback.mustache deleted file mode 100644 index abaab5a917..0000000000 --- a/templates/java/libraries/okhttp-gson/ApiCallback.mustache +++ /dev/null @@ -1,49 +0,0 @@ -package {{invokerPackage}}; - -import java.util.Map; -import java.util.List; - -import com.algolia.exceptions.AlgoliaRuntimeException; - -/** - * Callback for asynchronous API call. - * - * @param The return type - */ -public interface ApiCallback { - /** - * This is called when the API call fails. - * - * @param e The exception causing the failure - * @param statusCode Status code of the response if available, otherwise it would be 0 - * @param responseHeaders Headers of the response if available, otherwise it would be null - */ - void onFailure(AlgoliaRuntimeException e, int statusCode, Map> responseHeaders); - - /** - * This is called when the API call succeeded. - * - * @param result The result deserialized from response - * @param statusCode Status code of the response - * @param responseHeaders Headers of the response - */ - void onSuccess(T result, int statusCode, Map> responseHeaders); - - /** - * This is called when the API upload processing. - * - * @param bytesWritten bytes Written - * @param contentLength content length of request body - * @param done write end - */ - void onUploadProgress(long bytesWritten, long contentLength, boolean done); - - /** - * This is called when the API download processing. - * - * @param bytesRead bytes Read - * @param contentLength content length of the response - * @param done Read end - */ - void onDownloadProgress(long bytesRead, long contentLength, boolean done); -} diff --git a/templates/java/libraries/okhttp-gson/ApiClient.mustache b/templates/java/libraries/okhttp-gson/ApiClient.mustache index 17d9573122..c6b1efb11a 100644 --- a/templates/java/libraries/okhttp-gson/ApiClient.mustache +++ b/templates/java/libraries/okhttp-gson/ApiClient.mustache @@ -3,25 +3,24 @@ package {{invokerPackage}}; import com.algolia.utils.Requester; import com.algolia.exceptions.*; import com.algolia.utils.UserAgent; +import com.algolia.utils.JSON; import okhttp3.*; import okhttp3.internal.http.HttpMethod; import okhttp3.logging.HttpLoggingInterceptor; import okhttp3.logging.HttpLoggingInterceptor.Level; - import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.reflect.Type; import java.net.URLConnection; import java.net.URLEncoder; import java.text.DateFormat; -{{#java8}} import java.time.LocalDate; import java.time.OffsetDateTime; -{{/java8}} import java.util.*; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.concurrent.CompletableFuture; public class ApiClient { @@ -201,7 +200,7 @@ public class ApiClient { * @param mime MIME (Multipurpose Internet Mail Extensions) * @return True if the given MIME is JSON, false otherwise. */ - public boolean isJsonMime(String mime) { + public static boolean isJsonMime(String mime) { String jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"; return mime != null && (mime.matches(jsonMime) || mime.equals("*/*")); } @@ -220,62 +219,6 @@ public class ApiClient { } } - /** - * Deserialize response body to Java object, according to the return type and - * the Content-Type response header. - * - * @param Type - * @param response HTTP response - * @param returnType The type of the Java object - * @return The deserialized Java object - * @throws AlgoliaRuntimeException If fail to deserialize response body, i.e. cannot read response body - * or the Content-Type of the response is not supported. - */ - public T deserialize(Response response, Type returnType) throws AlgoliaRuntimeException { - if (response == null || returnType == null) { - return null; - } - - if ("byte[]".equals(returnType.toString())) { - // Handle binary response (byte array). - try { - return (T) response.body().bytes(); - } catch (IOException e) { - throw new AlgoliaRuntimeException(e); - } - } - - String respBody; - try { - if (response.body() != null) - respBody = response.body().string(); - else - respBody = null; - } catch (IOException e) { - throw new AlgoliaRuntimeException(e); - } - - if (respBody == null || "".equals(respBody)) { - return null; - } - - String contentType = response.headers().get("Content-Type"); - if (contentType == null) { - // ensuring a default content type - contentType = "application/json"; - } - if (isJsonMime(contentType)) { - return JSON.deserialize(respBody, returnType); - } else if (returnType.equals(String.class)) { - // Expecting string, return the raw response body. - return (T) respBody; - } else { - throw new AlgoliaApiException( - "Content type \"" + contentType + "\" is not supported for type: " + returnType, - response.code()); - } - } - /** * Serialize the given Java object into request body according to the object's * class and the request Content-Type. @@ -302,119 +245,37 @@ public class ApiClient { } } - /** - * {@link #execute(Call, Type)} - * - * @param Type - * @param call An instance of the Call object - * @return ApiResponse<T> - * @throws AlgoliaRuntimeException If fail to execute the call - */ - public ApiResponse execute(Call call) throws AlgoliaRuntimeException { - return execute(call, null); - } - - /** - * Execute HTTP call and deserialize the HTTP response body into the given return type. - * - * @param returnType The return type used to deserialize HTTP response body - * @param The return type corresponding to (same with) returnType - * @param call Call - * @return ApiResponse object containing response status, headers and - * data, which is a Java object deserialized from response body and would be null - * when returnType is null. - * @throws AlgoliaRuntimeException If fail to execute the call - */ - public ApiResponse execute(Call call, Type returnType) throws AlgoliaRuntimeException { - try { - Response response = call.execute(); - T data = handleResponse(response, returnType); - return new ApiResponse(response.code(), response.headers().toMultimap(), data); - } catch (IOException e) { - throw new AlgoliaRuntimeException(e); - } - } - - /** - * {@link #executeAsync(Call, Type, ApiCallback)} - * - * @param Type - * @param call An instance of the Call object - * @param callback ApiCallback<T> - */ - public void executeAsync(Call call, ApiCallback callback) { - executeAsync(call, null, callback); - } - /** * Execute HTTP call asynchronously. * * @param Type - * @param call The callback to be executed when the API call finishes * @param returnType Return type - * @param callback ApiCallback * @see #execute(Call, Type) */ - public void executeAsync(Call call, final Type returnType, final ApiCallback callback) { - call.enqueue(new Callback() { - @Override - public void onFailure(Call call, IOException e) { - callback.onFailure(new AlgoliaRuntimeException(e), 0, null); - } - - @Override - public void onResponse(Call call, Response response) throws IOException { - T result; - try { - result = (T) handleResponse(response, returnType); - } catch (AlgoliaRuntimeException e) { - callback.onFailure(e, response.code(), response.headers().toMultimap()); - return; - } catch (Exception e) { - callback.onFailure(new AlgoliaRuntimeException(e), response.code(), response.headers().toMultimap()); - return; - } - callback.onSuccess(result, response.code(), response.headers().toMultimap()); - } - }); - } + public CompletableFuture executeAsync(Call call, final Type returnType) { + final CompletableFuture future = new CompletableFuture<>(); + call.enqueue( + new Callback() { + @Override + public void onFailure(Call call, IOException e) { + future.completeExceptionally(new AlgoliaRuntimeException(e)); + } - /** - * Handle the given response, return the deserialized object when the response is successful. - * - * @param Type - * @param response Response - * @param returnType Return type - * @return Type - * @throws AlgoliaRuntimeException If the response has an unsuccessful status code or - * fail to deserialize the response body - */ - public T handleResponse(Response response, Type returnType) throws AlgoliaRuntimeException { - if (response.isSuccessful()) { - if (returnType == null || response.code() == 204) { - // returning null if the returnType is not defined, - // or the status code is 204 (No Content) - if (response.body() != null) { - try { - response.body().close(); - } catch (Exception e) { - throw new AlgoliaApiException(response.message(), e, response.code()); - } - } - return null; - } else { - return deserialize(response, returnType); - } - } else { - if (response.body() != null) { - try { - response.body().string(); - } catch (IOException e) { - throw new AlgoliaApiException(response.message(), e, response.code()); - } + @Override + public void onResponse(Call call, Response response) + throws IOException { + try { + T result = requester.handleResponse(response, returnType); + future.complete(result); + } catch (AlgoliaRuntimeException e) { + future.completeExceptionally(e); + } catch (Exception e) { + future.completeExceptionally(new AlgoliaRuntimeException(e)); } - throw new AlgoliaApiException(response.message(), response.code()); + } } + ); + return future; } /** @@ -425,12 +286,11 @@ public class ApiClient { * @param queryParams The query parameters * @param body The request body object * @param headerParams The header parameters - * @param callback Callback for upload/download progress * @return The HTTP call * @throws AlgoliaRuntimeException If fail to serialize the request body object */ - public Call buildCall(String path, String method, Map queryParams, Object body, Map headerParams, ApiCallback callback) throws AlgoliaRuntimeException { - Request request = buildRequest(path, method, queryParams, body, headerParams, callback); + public Call buildCall(String path, String method, Map queryParams, Object body, Map headerParams) throws AlgoliaRuntimeException { + Request request = buildRequest(path, method, queryParams, body, headerParams); return requester.newCall(request); } @@ -443,22 +303,23 @@ public class ApiClient { * @param queryParams The query parameters * @param body The request body object * @param headerParams The header parameters - * @param callback Callback for upload/download progress * @return The HTTP request * @throws AlgoliaRuntimeException If fail to serialize the request body object */ - public Request buildRequest(String path, String method, Map queryParams, Object body, Map headerParams, ApiCallback callback) throws AlgoliaRuntimeException { + public Request buildRequest(String path, String method, Map queryParams, Object body, Map headerParams) throws AlgoliaRuntimeException { headerParams.put("X-Algolia-Application-Id", this.appId); headerParams.put("X-Algolia-API-Key", this.apiKey); headerParams.put("Accept", "application/json"); headerParams.put("Content-Type", "application/json"); + String contentType = "application/json"; + headerParams.put("Accept", contentType); + headerParams.put("Content-Type", contentType); + final String url = buildUrl(path, queryParams); final Request.Builder reqBuilder = new Request.Builder().url(url); processHeaderParams(headerParams, reqBuilder); - - String contentType = (String) headerParams.get("Content-Type"); - + RequestBody reqBody; if (!HttpMethod.permitsRequestBody(method)) { reqBody = null; @@ -474,20 +335,7 @@ public class ApiClient { reqBody = serialize(body, contentType); } - // Associate callback with request (if not null) so interceptor can - // access it when creating ProgressResponseBody - reqBuilder.tag(callback); - - Request request = null; - - if (callback != null && reqBody != null) { - ProgressRequestBody progressRequestBody = new ProgressRequestBody(reqBody, callback); - request = reqBuilder.method(method, progressRequestBody).build(); - } else { - request = reqBuilder.method(method, reqBody).build(); - } - - return request; + return reqBuilder.method(method, reqBody).build(); } /** diff --git a/templates/java/libraries/okhttp-gson/ApiResponse.mustache b/templates/java/libraries/okhttp-gson/ApiResponse.mustache deleted file mode 100644 index 0d2c7b1cd7..0000000000 --- a/templates/java/libraries/okhttp-gson/ApiResponse.mustache +++ /dev/null @@ -1,56 +0,0 @@ -package {{invokerPackage}}; - -import java.util.List; -import java.util.Map; -{{#caseInsensitiveResponseHeaders}} -import java.util.Map.Entry; -import java.util.TreeMap; -{{/caseInsensitiveResponseHeaders}} - -/** - * API response returned by API call. - * - * @param The type of data that is deserialized from response body - */ -public class ApiResponse { - final private int statusCode; - final private Map> headers; - final private T data; - - /** - * @param statusCode The status code of HTTP response - * @param headers The headers of HTTP response - */ - public ApiResponse(int statusCode, Map> headers) { - this(statusCode, headers, null); - } - - /** - * @param statusCode The status code of HTTP response - * @param headers The headers of HTTP response - * @param data The object deserialized from response bod - */ - public ApiResponse(int statusCode, Map> headers, T data) { - this.statusCode = statusCode; - {{#caseInsensitiveResponseHeaders}} - Map> responseHeaders = new TreeMap>(String.CASE_INSENSITIVE_ORDER); - for(Entry> entry : headers.entrySet()){ - responseHeaders.put(entry.getKey().toLowerCase(), entry.getValue()); - } - {{/caseInsensitiveResponseHeaders}} - this.headers = {{#caseInsensitiveResponseHeaders}}responseHeaders{{/caseInsensitiveResponseHeaders}}{{^caseInsensitiveResponseHeaders}}headers{{/caseInsensitiveResponseHeaders}}; - this.data = data; - } - - public int getStatusCode() { - return statusCode; - } - - public Map> getHeaders() { - return headers; - } - - public T getData() { - return data; - } -} diff --git a/templates/java/libraries/okhttp-gson/ProgressRequestBody.mustache b/templates/java/libraries/okhttp-gson/ProgressRequestBody.mustache deleted file mode 100644 index b0ac8180e4..0000000000 --- a/templates/java/libraries/okhttp-gson/ProgressRequestBody.mustache +++ /dev/null @@ -1,60 +0,0 @@ -package {{invokerPackage}}; - -import okhttp3.MediaType; -import okhttp3.RequestBody; - -import java.io.IOException; - -import okio.Buffer; -import okio.BufferedSink; -import okio.ForwardingSink; -import okio.Okio; -import okio.Sink; - -public class ProgressRequestBody extends RequestBody { - - private final RequestBody requestBody; - - private final ApiCallback callback; - - public ProgressRequestBody(RequestBody requestBody, ApiCallback callback) { - this.requestBody = requestBody; - this.callback = callback; - } - - @Override - public MediaType contentType() { - return requestBody.contentType(); - } - - @Override - public long contentLength() throws IOException { - return requestBody.contentLength(); - } - - @Override - public void writeTo(BufferedSink sink) throws IOException { - BufferedSink bufferedSink = Okio.buffer(sink(sink)); - requestBody.writeTo(bufferedSink); - bufferedSink.flush(); - } - - private Sink sink(Sink sink) { - return new ForwardingSink(sink) { - - long bytesWritten = 0L; - long contentLength = 0L; - - @Override - public void write(Buffer source, long byteCount) throws IOException { - super.write(source, byteCount); - if (contentLength == 0) { - contentLength = contentLength(); - } - - bytesWritten += byteCount; - callback.onUploadProgress(bytesWritten, contentLength, bytesWritten == contentLength); - } - }; - } -} diff --git a/templates/java/libraries/okhttp-gson/ProgressResponseBody.mustache b/templates/java/libraries/okhttp-gson/ProgressResponseBody.mustache deleted file mode 100644 index 2db7b35157..0000000000 --- a/templates/java/libraries/okhttp-gson/ProgressResponseBody.mustache +++ /dev/null @@ -1,57 +0,0 @@ -package {{invokerPackage}}; - -import okhttp3.MediaType; -import okhttp3.ResponseBody; - -import java.io.IOException; - -import okio.Buffer; -import okio.BufferedSource; -import okio.ForwardingSource; -import okio.Okio; -import okio.Source; - -public class ProgressResponseBody extends ResponseBody { - - private final ResponseBody responseBody; - private final ApiCallback callback; - private BufferedSource bufferedSource; - - public ProgressResponseBody(ResponseBody responseBody, ApiCallback callback) { - this.responseBody = responseBody; - this.callback = callback; - } - - @Override - public MediaType contentType() { - return responseBody.contentType(); - } - - @Override - public long contentLength() { - return responseBody.contentLength(); - } - - @Override - public BufferedSource source() { - if (bufferedSource == null) { - bufferedSource = Okio.buffer(source(responseBody.source())); - } - return bufferedSource; - } - - private Source source(Source source) { - return new ForwardingSource(source) { - long totalBytesRead = 0L; - - @Override - public long read(Buffer sink, long byteCount) throws IOException { - long bytesRead = super.read(sink, byteCount); - // read() returns the number of bytes read, or -1 if this source is exhausted. - totalBytesRead += bytesRead != -1 ? bytesRead : 0; - callback.onDownloadProgress(totalBytesRead, responseBody.contentLength(), bytesRead == -1); - return bytesRead; - } - }; - } -} diff --git a/templates/java/libraries/okhttp-gson/api.mustache b/templates/java/libraries/okhttp-gson/api.mustache index 0da44e2c86..6510ed1f78 100644 --- a/templates/java/libraries/okhttp-gson/api.mustache +++ b/templates/java/libraries/okhttp-gson/api.mustache @@ -1,9 +1,6 @@ package {{package}}; -import {{invokerPackage}}.ApiCallback; import {{invokerPackage}}.ApiClient; -import {{invokerPackage}}.ApiResponse; -import {{invokerPackage}}.Pair; import com.google.gson.reflect.TypeToken; @@ -11,7 +8,6 @@ import okhttp3.Call; import okhttp3.Request; import com.algolia.utils.*; -import com.algolia.utils.echo.*; import {{modelPackage}}.*; import com.algolia.exceptions.*; import com.algolia.utils.retry.CallType; @@ -29,6 +25,7 @@ import java.util.Map; {{/fullJavaUtil}} import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.concurrent.CompletableFuture; {{#operations}} public class {{classname}} extends ApiClient { @@ -37,6 +34,10 @@ public class {{classname}} extends ApiClient { public {{classname}}(String appId, String apiKey) { this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), null); } + + public {{classname}}(String appId, String apiKey, UserAgent.Segment[] userAgentSegments) { + this(appId, apiKey, new HttpRequester(getDefaultHosts(null)), userAgentSegments); + } {{/fallbackToAliasHost}} public {{classname}}(String appId, String apiKey, String region) { @@ -95,71 +96,6 @@ public class {{classname}} extends ApiClient { {{/hasRegionalHost}} {{#operation}} - /** - * Build call for {{operationId}} - * @param callback Callback for upload/download progress - * @return Call to execute - * @throws AlgoliaRuntimeException If fail to serialize the request body object - {{#isDeprecated}} - * @deprecated - {{/isDeprecated}} - {{#externalDocs}} - * {{&description}} - * @see {{&summary}} Documentation - {{/externalDocs}} - */ - {{#isDeprecated}} - @Deprecated - {{/isDeprecated}} - private Call {{operationId}}Call({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{{returnType}}}> callback) throws AlgoliaRuntimeException { - Object bodyObj = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; - - // create path and map variables - String requestPath = "{{{path}}}"{{#vendorExtensions}}{{#pathParams}}.replaceAll( - {{=<% %>=}}"\\{<%baseName%>\\}"<%={{ }}=%>, - {{#x-is-custom-request}}{{{paramName}}}.toString(){{/x-is-custom-request}}{{^x-is-custom-request}}this.escapeString({{{paramName}}}.toString()){{/x-is-custom-request}} - ){{/pathParams}}{{/vendorExtensions}}; - - {{javaUtilPrefix}}Map queryParams = new {{javaUtilPrefix}}HashMap(); - {{javaUtilPrefix}}Map headers = new {{javaUtilPrefix}}HashMap(); - - {{#vendorExtensions}}{{#queryParams}} - if ({{paramName}} != null) { - {{^x-is-custom-request}} - queryParams.put("{{baseName}}", parameterToString({{paramName}})); - {{/x-is-custom-request}} - {{#x-is-custom-request}} - for (Map.Entry parameter : parameters.entrySet()) { - queryParams.put(parameter.getKey().toString(), parameterToString(parameter.getValue())); - } - {{/x-is-custom-request}} - } - - {{/queryParams}}{{/vendorExtensions}} - {{#headerParams}} - if ({{paramName}} != null) { - headers.put("{{baseName}}", this.parameterToString({{paramName}})); - } - - {{/headerParams}} - - return this.buildCall(requestPath, "{{httpMethod}}", queryParams, bodyObj, headers, callback); - } - - {{#isDeprecated}} - @Deprecated - {{/isDeprecated}} - private Call {{operationId}}ValidateBeforeCall({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{{returnType}}}> callback) throws AlgoliaRuntimeException { - {{#allParams}}{{#required}} - // verify the required parameter '{{paramName}}' is set - if ({{paramName}} == null) { - throw new AlgoliaRuntimeException("Missing the required parameter '{{paramName}}' when calling {{operationId}}(Async)"); - } - {{/required}}{{/allParams}} - - return {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}callback); - } - /** * {{¬es}}{{#allParams}} * @param {{paramName}} {{&description}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}}{{/allParams}}{{#returnType}} @@ -177,14 +113,7 @@ public class {{classname}} extends ApiClient { @Deprecated {{/isDeprecated}} public {{#returnType}}{{{.}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) throws AlgoliaRuntimeException { - Call req = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}null); - if (req instanceof CallEcho) { - {{#returnType}}return new EchoResponse{{baseName}}.{{#lambda.titlecase}}{{{operationId}}}{{/lambda.titlecase}}(((CallEcho)req).request());{{/returnType}} - } - Call call = (Call)req; - {{#returnType}}Type returnType = new TypeToken<{{{.}}}>(){}.getType(); - ApiResponse<{{{.}}}> res = this.execute(call, returnType); - return res.getData();{{/returnType}}{{^returnType}}this.execute(call).getData();{{/returnType}} + return LaunderThrowable.await({{operationId}}Async({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}})); } {{#optionalParams.0}} @@ -197,8 +126,7 @@ public class {{classname}} extends ApiClient { * (asynchronously) * {{notes}}{{#allParams}} * @param {{paramName}} {{{description}}}{{#required}} (required){{/required}}{{^required}} (optional{{^isContainer}}{{#defaultValue}}, default to {{.}}{{/defaultValue}}{{/isContainer}}){{/required}}{{/allParams}} - * @param callback The callback to be executed when the API call finishes - * @return The request call + * @return The awaitable future * @throws AlgoliaRuntimeException If fail to process the API call, e.g. serializing the request body object {{#isDeprecated}} * @deprecated @@ -211,11 +139,46 @@ public class {{classname}} extends ApiClient { {{#isDeprecated}} @Deprecated {{/isDeprecated}} - public Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{{returnType}}}{{^returnType}}Void{{/returnType}}> callback) throws AlgoliaRuntimeException { - Call call = {{operationId}}ValidateBeforeCall({{#allParams}}{{paramName}}, {{/allParams}}callback); - {{#returnType}}Type returnType = new TypeToken<{{{returnType}}}>(){}.getType(); - this.executeAsync(call, returnType, callback);{{/returnType}}{{^returnType}}this.executeAsync(call, callback);{{/returnType}} - return call; + public CompletableFuture<{{{returnType}}}> {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}},{{/-last}} {{/allParams}}) throws AlgoliaRuntimeException { + {{#allParams}}{{#required}} + if ({{paramName}} == null) { + throw new AlgoliaRuntimeException("Missing the required parameter '{{paramName}}' when calling {{operationId}}(Async)"); + } + {{/required}}{{/allParams}} + + Object bodyObj = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; + + // create path and map variables + String requestPath = "{{{path}}}"{{#vendorExtensions}}{{#pathParams}}.replaceAll( + {{=<% %>=}}"\\{<%baseName%>\\}"<%={{ }}=%>, + {{#x-is-custom-request}}{{{paramName}}}.toString(){{/x-is-custom-request}}{{^x-is-custom-request}}this.escapeString({{{paramName}}}.toString()){{/x-is-custom-request}} + ){{/pathParams}}{{/vendorExtensions}}; + + {{javaUtilPrefix}}Map queryParams = new {{javaUtilPrefix}}HashMap(); + {{javaUtilPrefix}}Map headers = new {{javaUtilPrefix}}HashMap(); + + {{#vendorExtensions}}{{#queryParams}} + if ({{paramName}} != null) { + {{^x-is-custom-request}} + queryParams.put("{{baseName}}", parameterToString({{paramName}})); + {{/x-is-custom-request}} + {{#x-is-custom-request}} + for (Map.Entry parameter : parameters.entrySet()) { + queryParams.put(parameter.getKey().toString(), parameterToString(parameter.getValue())); + } + {{/x-is-custom-request}} + } + + {{/queryParams}}{{/vendorExtensions}} + {{#headerParams}} + if ({{paramName}} != null) { + headers.put("{{baseName}}", this.parameterToString({{paramName}})); + } + + {{/headerParams}} + Call call = this.buildCall(requestPath, "{{httpMethod}}", queryParams, bodyObj, headers); + Type returnType = new TypeToken<{{{returnType}}}>() {}.getType(); + return this.executeAsync(call, returnType); } {{/operation}} } diff --git a/templates/java/manifest.mustache b/templates/java/manifest.mustache deleted file mode 100644 index f44bd07d0a..0000000000 --- a/templates/java/manifest.mustache +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/templates/java/oneof_interface.mustache b/templates/java/oneof_interface.mustache index 790a0409c1..954f5687a0 100644 --- a/templates/java/oneof_interface.mustache +++ b/templates/java/oneof_interface.mustache @@ -1,5 +1,5 @@ import com.algolia.utils.CompoundType; -import com.algolia.JSON; +import com.algolia.utils.JSON; import com.google.gson.TypeAdapter; import com.google.gson.reflect.TypeToken; diff --git a/templates/java/pojo.mustache b/templates/java/pojo.mustache index 105d3aa1ff..dd2ed4f44a 100644 --- a/templates/java/pojo.mustache +++ b/templates/java/pojo.mustache @@ -61,7 +61,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{ } {{#isArray}} - public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) { + public {{classname}} add{{nameInCamelCase}}({{{items.datatypeWithEnum}}} {{name}}Item) { {{^required}} if (this.{{name}} == null) { this.{{name}} = {{{defaultValue}}}; @@ -73,7 +73,7 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{ {{/isArray}} {{#isMap}} - public {{classname}} put{{nameInCamelCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { + public {{classname}} put{{nameInCamelCase}}(String key, {{{items.datatypeWithEnum}}} {{name}}Item) { {{^required}} if (this.{{name}} == null) { this.{{name}} = {{{defaultValue}}}; diff --git a/tests/CTS/methods/requests/templates/java/requests.mustache b/tests/CTS/methods/requests/templates/java/requests.mustache index 7cc7ce7b23..06b7f1708c 100644 --- a/tests/CTS/methods/requests/templates/java/requests.mustache +++ b/tests/CTS/methods/requests/templates/java/requests.mustache @@ -12,21 +12,24 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.BeforeAll; import com.google.gson.reflect.TypeToken; -import com.algolia.JSON; -import com.algolia.Pair; +import com.algolia.utils.JSON; 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; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; + @TestInstance(TestInstance.Lifecycle.PER_CLASS) class {{client}}Tests { private {{client}} client; + private EchoRequester requester; @BeforeAll void init() { - client = new {{client}}("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new {{client}}("appId", "apiKey", requester); } {{#blocks}} @@ -36,22 +39,24 @@ class {{client}}Tests { void {{method}}Test{{testIndex}}() { {{#parametersWithDataType}}{{> generateParams}}{{/parametersWithDataType}} - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.{{method}}({{#parametersWithDataType}}{{> maybeConvertOneOf}}{{^-last}},{{/-last}}{{/parametersWithDataType}}); + assertDoesNotThrow(() -> { + client.{{method}}({{#parametersWithDataType}}{{> maybeConvertOneOf}}{{^-last}},{{/-last}}{{/parametersWithDataType}}); }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "{{{request.path}}}"); - assertEquals(req.getMethod(), "{{{request.method}}}"); + assertEquals(req.path, "{{{request.path}}}"); + assertEquals(req.method, "{{{request.method}}}"); {{#request.body}} assertDoesNotThrow(() -> { - JSONAssert.assertEquals("{{#lambda.escapequotes}}{{{request.body}}}{{/lambda.escapequotes}}", req.getBody(), JSONCompareMode.STRICT_ORDER); + JSONAssert.assertEquals("{{#lambda.escapequotes}}{{{request.body}}}{{/lambda.escapequotes}}", req.body, JSONCompareMode.STRICT_ORDER); }); {{/request.body}} {{#request.queryParameters}} Map expectedQuery = JSON.deserialize("{{#lambda.escapequotes}}{{{request.queryParameters}}}{{/lambda.escapequotes}}", new TypeToken>() {}.getType()); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); diff --git a/tests/output/java/src/test/java/com/algolia/CallEcho.java b/tests/output/java/src/test/java/com/algolia/CallEcho.java new file mode 100644 index 0000000000..14f94d683b --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/CallEcho.java @@ -0,0 +1,108 @@ +package com.algolia; + +import com.algolia.utils.JSON; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.HttpUrl; +import okhttp3.MediaType; +import okhttp3.Protocol; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; +import okio.Buffer; +import okio.Timeout; + +public class CallEcho implements Call { + + private final Request request; + + public CallEcho(Request request) { + this.request = request; + } + + @Override + public Request request() { + return request; + } + + @Override + public void cancel() {} + + @Override + public Call clone() { + return null; + } + + private String processResponseBody() { + try { + final Request copy = request.newBuilder().build(); + final Buffer buffer = new Buffer(); + if (copy.body() == null) { + return ""; + } + copy.body().writeTo(buffer); + return buffer.readUtf8(); + } catch (final IOException e) { + return "error"; + } + } + + private Map buildQueryParams() { + Map params = new HashMap<>(); + HttpUrl url = request.url(); + for (String name : url.queryParameterNames()) { + for (String value : url.queryParameterValues(name)) { + params.put(name, value); + } + } + return params; + } + + @Override + public void enqueue(Callback callback) { + Response.Builder builder = new Response.Builder(); + builder.code(200); + builder.request(request); + builder.protocol(Protocol.HTTP_2); + builder.message("EchoRequest"); + try { + EchoResponse body = new EchoResponse(); + body.path = request.url().encodedPath(); + body.method = request.method(); + body.body = processResponseBody(); + body.queryParameters = buildQueryParams(); + builder.body( + ResponseBody.create( + JSON.serialize(body), + MediaType.parse("application/json") + ) + ); + callback.onResponse(this, builder.build()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public Response execute() throws IOException { + return null; + } + + @Override + public boolean isExecuted() { + return false; + } + + @Override + public boolean isCanceled() { + return false; + } + + @Override + public Timeout timeout() { + return null; + } +} diff --git a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoRequester.java b/tests/output/java/src/test/java/com/algolia/EchoRequester.java similarity index 62% rename from clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoRequester.java rename to tests/output/java/src/test/java/com/algolia/EchoRequester.java index 8e49cf5b13..30f1fd9c7d 100644 --- a/clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/echo/EchoRequester.java +++ b/tests/output/java/src/test/java/com/algolia/EchoRequester.java @@ -1,12 +1,19 @@ -package com.algolia.utils.echo; +package com.algolia; +import com.algolia.exceptions.*; +import com.algolia.utils.JSON; import com.algolia.utils.Requester; +import java.io.IOException; +import java.lang.reflect.Type; import okhttp3.Request; +import okhttp3.Response; public class EchoRequester implements Requester { private int connectionTimeout, readTimeout, writeTimeout; + private Response lastResponse; + public EchoRequester() { this.connectionTimeout = 100; this.readTimeout = 100; @@ -17,6 +24,21 @@ public CallEcho newCall(Request request) { return new CallEcho(request); } + public T handleResponse(Response response, Type returnType) + throws AlgoliaRuntimeException { + lastResponse = response; + return null; + } + + public EchoResponse getLastEchoResponse() { + try { + return JSON.deserialize(lastResponse.body().string(), EchoResponse.class); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + // NO-OP for now public void setDebugging(boolean debugging) {} diff --git a/tests/output/java/src/test/java/com/algolia/EchoResponse.java b/tests/output/java/src/test/java/com/algolia/EchoResponse.java new file mode 100644 index 0000000000..c49f8f9d4f --- /dev/null +++ b/tests/output/java/src/test/java/com/algolia/EchoResponse.java @@ -0,0 +1,11 @@ +package com.algolia; + +import java.util.Map; + +public class EchoResponse { + + public String path; + public String method; + public String body; + public Map queryParameters; +} 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 index c839864144..04dd1b0414 100644 --- 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 @@ -3,10 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.algolia.JSON; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; import com.algolia.api.AbtestingClient; import com.algolia.model.abtesting.*; -import com.algolia.utils.echo.*; +import com.algolia.utils.JSON; import com.google.gson.reflect.TypeToken; import java.util.*; import org.junit.jupiter.api.BeforeAll; @@ -20,10 +21,12 @@ class AbtestingClientTests { private AbtestingClient client; + private EchoRequester requester; @BeforeAll void init() { - client = new AbtestingClient("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new AbtestingClient("appId", "apiKey", requester); } @Test @@ -57,18 +60,18 @@ void addABTestsTest0() { addABTestsRequest0.setVariant(variant1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.addABTests(addABTestsRequest0); - } - ); + assertDoesNotThrow(() -> { + client.addABTests(addABTestsRequest0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/abtests"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/2/abtests"); + assertEquals(req.method, "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(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -79,13 +82,13 @@ void addABTestsTest0() { void delTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "DELETE"); } @Test @@ -98,19 +101,20 @@ void delTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "DELETE"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -122,13 +126,13 @@ void delTest1() { void deleteABTestTest0() { int id0 = 42; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteABTest(id0); - } - ); + assertDoesNotThrow(() -> { + client.deleteABTest(id0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/abtests/42"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/2/abtests/42"); + assertEquals(req.method, "DELETE"); } @Test @@ -136,13 +140,13 @@ void deleteABTestTest0() { void getTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "GET"); } @Test @@ -155,19 +159,20 @@ void getTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -179,13 +184,13 @@ void getTest1() { void getABTestTest0() { int id0 = 42; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getABTest(id0); - } - ); + assertDoesNotThrow(() -> { + client.getABTest(id0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/abtests/42"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/abtests/42"); + assertEquals(req.method, "GET"); } @Test @@ -194,19 +199,20 @@ void listABTestsTest0() { int offset0 = 42; int limit0 = 21; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.listABTests(offset0, limit0); - } - ); + assertDoesNotThrow(() -> { + client.listABTests(offset0, limit0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/abtests"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/abtests"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"offset\":\"42\",\"limit\":\"21\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -218,13 +224,13 @@ void listABTestsTest0() { void postTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "POST"); } @Test @@ -242,18 +248,18 @@ void postTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -262,7 +268,8 @@ void postTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -274,13 +281,13 @@ void postTest1() { void putTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "PUT"); } @Test @@ -298,18 +305,18 @@ void putTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -318,7 +325,8 @@ void putTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -330,12 +338,12 @@ void putTest1() { void stopABTestTest0() { int id0 = 42; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.stopABTest(id0); - } - ); + assertDoesNotThrow(() -> { + client.stopABTest(id0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/abtests/42/stop"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/2/abtests/42/stop"); + assertEquals(req.method, "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 index d5b6fd7602..ddac920238 100644 --- 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 @@ -3,10 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.algolia.JSON; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; import com.algolia.api.AnalyticsClient; import com.algolia.model.analytics.*; -import com.algolia.utils.echo.*; +import com.algolia.utils.JSON; import com.google.gson.reflect.TypeToken; import java.util.*; import org.junit.jupiter.api.BeforeAll; @@ -20,10 +21,12 @@ class AnalyticsClientTests { private AnalyticsClient client; + private EchoRequester requester; @BeforeAll void init() { - client = new AnalyticsClient("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new AnalyticsClient("appId", "apiKey", requester); } @Test @@ -31,13 +34,13 @@ void init() { void delTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "DELETE"); } @Test @@ -50,19 +53,20 @@ void delTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "DELETE"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -74,13 +78,13 @@ void delTest1() { void getTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "GET"); } @Test @@ -93,19 +97,20 @@ void getTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -117,19 +122,20 @@ void getTest1() { void getAverageClickPositionTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getAverageClickPosition(index0); - } - ); + assertDoesNotThrow(() -> { + client.getAverageClickPosition(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/clicks/averageClickPosition"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/clicks/averageClickPosition"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -144,24 +150,20 @@ void getAverageClickPositionTest1() { String endDate0 = "2001-01-01"; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getAverageClickPosition( - index0, - startDate0, - endDate0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getAverageClickPosition(index0, startDate0, endDate0, tags0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/clicks/averageClickPosition"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/clicks/averageClickPosition"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -173,19 +175,20 @@ void getAverageClickPositionTest1() { void getClickPositionsTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getClickPositions(index0); - } - ); + assertDoesNotThrow(() -> { + client.getClickPositions(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/clicks/positions"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/clicks/positions"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -200,19 +203,20 @@ void getClickPositionsTest1() { String endDate0 = "2001-01-01"; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getClickPositions(index0, startDate0, endDate0, tags0); - } - ); + assertDoesNotThrow(() -> { + client.getClickPositions(index0, startDate0, endDate0, tags0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/clicks/positions"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/clicks/positions"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -224,19 +228,20 @@ void getClickPositionsTest1() { void getClickThroughRateTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getClickThroughRate(index0); - } - ); + assertDoesNotThrow(() -> { + client.getClickThroughRate(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/clicks/clickThroughRate"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/clicks/clickThroughRate"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -251,19 +256,20 @@ void getClickThroughRateTest1() { String endDate0 = "2001-01-01"; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getClickThroughRate(index0, startDate0, endDate0, tags0); - } - ); + assertDoesNotThrow(() -> { + client.getClickThroughRate(index0, startDate0, endDate0, tags0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/clicks/clickThroughRate"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/clicks/clickThroughRate"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -275,19 +281,20 @@ void getClickThroughRateTest1() { void getConversationRateTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getConversationRate(index0); - } - ); + assertDoesNotThrow(() -> { + client.getConversationRate(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/conversions/conversionRate"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/conversions/conversionRate"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -302,19 +309,20 @@ void getConversationRateTest1() { String endDate0 = "2001-01-01"; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getConversationRate(index0, startDate0, endDate0, tags0); - } - ); + assertDoesNotThrow(() -> { + client.getConversationRate(index0, startDate0, endDate0, tags0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/conversions/conversionRate"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/conversions/conversionRate"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -326,19 +334,20 @@ void getConversationRateTest1() { void getNoClickRateTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getNoClickRate(index0); - } - ); + assertDoesNotThrow(() -> { + client.getNoClickRate(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/noClickRate"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/noClickRate"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -353,19 +362,20 @@ void getNoClickRateTest1() { String endDate0 = "2001-01-01"; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getNoClickRate(index0, startDate0, endDate0, tags0); - } - ); + assertDoesNotThrow(() -> { + client.getNoClickRate(index0, startDate0, endDate0, tags0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/noClickRate"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/noClickRate"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -377,19 +387,20 @@ void getNoClickRateTest1() { void getNoResultsRateTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getNoResultsRate(index0); - } - ); + assertDoesNotThrow(() -> { + client.getNoResultsRate(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/noResultRate"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/noResultRate"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -404,19 +415,20 @@ void getNoResultsRateTest1() { String endDate0 = "2001-01-01"; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getNoResultsRate(index0, startDate0, endDate0, tags0); - } - ); + assertDoesNotThrow(() -> { + client.getNoResultsRate(index0, startDate0, endDate0, tags0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/noResultRate"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/noResultRate"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -428,19 +440,20 @@ void getNoResultsRateTest1() { void getSearchesCountTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSearchesCount(index0); - } - ); + assertDoesNotThrow(() -> { + client.getSearchesCount(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/count"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/count"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -455,19 +468,20 @@ void getSearchesCountTest1() { String endDate0 = "2001-01-01"; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSearchesCount(index0, startDate0, endDate0, tags0); - } - ); + assertDoesNotThrow(() -> { + client.getSearchesCount(index0, startDate0, endDate0, tags0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/count"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/count"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -479,19 +493,20 @@ void getSearchesCountTest1() { void getSearchesNoClicksTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSearchesNoClicks(index0); - } - ); + assertDoesNotThrow(() -> { + client.getSearchesNoClicks(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/noClicks"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/noClicks"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -508,26 +523,27 @@ void getSearchesNoClicksTest1() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSearchesNoClicks( - index0, - startDate0, - endDate0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getSearchesNoClicks( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/noClicks"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/noClicks"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -539,19 +555,20 @@ void getSearchesNoClicksTest1() { void getSearchesNoResultsTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSearchesNoResults(index0); - } - ); + assertDoesNotThrow(() -> { + client.getSearchesNoResults(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/noResults"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/noResults"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -568,26 +585,27 @@ void getSearchesNoResultsTest1() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSearchesNoResults( - index0, - startDate0, - endDate0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getSearchesNoResults( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches/noResults"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches/noResults"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -599,19 +617,20 @@ void getSearchesNoResultsTest1() { void getStatusTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getStatus(index0); - } - ); + assertDoesNotThrow(() -> { + client.getStatus(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/status"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/status"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -623,19 +642,20 @@ void getStatusTest0() { void getTopCountriesTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopCountries(index0); - } - ); + assertDoesNotThrow(() -> { + client.getTopCountries(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/countries"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/countries"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -652,26 +672,27 @@ void getTopCountriesTest1() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopCountries( - index0, - startDate0, - endDate0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getTopCountries( + index0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/countries"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/countries"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"limit\":\"21\",\"offset\":\"42\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -683,19 +704,20 @@ void getTopCountriesTest1() { void getTopFilterAttributesTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopFilterAttributes(index0); - } - ); + assertDoesNotThrow(() -> { + client.getTopFilterAttributes(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/filters"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/filters"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -713,27 +735,28 @@ void getTopFilterAttributesTest1() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopFilterAttributes( - index0, - search0, - startDate0, - endDate0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getTopFilterAttributes( + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/filters"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/filters"); + assertEquals(req.method, "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() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -746,19 +769,20 @@ void getTopFilterForAttributeTest0() { String attribute0 = "myAttribute"; String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopFilterForAttribute(attribute0, index0); - } - ); + assertDoesNotThrow(() -> { + client.getTopFilterForAttribute(attribute0, index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/filters/myAttribute"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/filters/myAttribute"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -773,19 +797,20 @@ void getTopFilterForAttributeTest1() { String attribute0 = "myAttribute1,myAttribute2"; String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopFilterForAttribute(attribute0, index0); - } - ); + assertDoesNotThrow(() -> { + client.getTopFilterForAttribute(attribute0, index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/filters/myAttribute1%2CmyAttribute2"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/filters/myAttribute1%2CmyAttribute2"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -804,28 +829,29 @@ void getTopFilterForAttributeTest2() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopFilterForAttribute( - attribute0, - index0, - search0, - startDate0, - endDate0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getTopFilterForAttribute( + attribute0, + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/filters/myAttribute"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/filters/myAttribute"); + assertEquals(req.method, "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() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -846,28 +872,29 @@ void getTopFilterForAttributeTest3() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopFilterForAttribute( - attribute0, - index0, - search0, - startDate0, - endDate0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getTopFilterForAttribute( + attribute0, + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/filters/myAttribute1%2CmyAttribute2"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/filters/myAttribute1%2CmyAttribute2"); + assertEquals(req.method, "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() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -879,19 +906,20 @@ void getTopFilterForAttributeTest3() { void getTopFiltersNoResultsTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopFiltersNoResults(index0); - } - ); + assertDoesNotThrow(() -> { + client.getTopFiltersNoResults(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/filters/noResults"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/filters/noResults"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -909,27 +937,28 @@ void getTopFiltersNoResultsTest1() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopFiltersNoResults( - index0, - search0, - startDate0, - endDate0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getTopFiltersNoResults( + index0, + search0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/filters/noResults"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/filters/noResults"); + assertEquals(req.method, "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() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -941,19 +970,20 @@ void getTopFiltersNoResultsTest1() { void getTopHitsTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopHits(index0); - } - ); + assertDoesNotThrow(() -> { + client.getTopHits(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/hits"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/hits"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -972,28 +1002,29 @@ void getTopHitsTest1() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopHits( - index0, - search0, - clickAnalytics0, - startDate0, - endDate0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getTopHits( + index0, + search0, + clickAnalytics0, + startDate0, + endDate0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/hits"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/hits"); + assertEquals(req.method, "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() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1005,19 +1036,20 @@ void getTopHitsTest1() { void getTopSearchesTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopSearches(index0); - } - ); + assertDoesNotThrow(() -> { + client.getTopSearches(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1037,29 +1069,30 @@ void getTopSearchesTest1() { int offset0 = 42; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopSearches( - index0, - clickAnalytics0, - startDate0, - endDate0, - orderBy0, - direction0, - limit0, - offset0, - tags0 - ); - } - ); + assertDoesNotThrow(() -> { + client.getTopSearches( + index0, + clickAnalytics0, + startDate0, + endDate0, + orderBy0, + direction0, + limit0, + offset0, + tags0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/searches"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/searches"); + assertEquals(req.method, "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() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1071,19 +1104,20 @@ void getTopSearchesTest1() { void getUsersCountTest0() { String index0 = "index"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getUsersCount(index0); - } - ); + assertDoesNotThrow(() -> { + client.getUsersCount(index0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/users/count"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/users/count"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1098,19 +1132,20 @@ void getUsersCountTest1() { String endDate0 = "2001-01-01"; String tags0 = "tag"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getUsersCount(index0, startDate0, endDate0, tags0); - } - ); + assertDoesNotThrow(() -> { + client.getUsersCount(index0, startDate0, endDate0, tags0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/2/users/count"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/2/users/count"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"index\":\"index\",\"startDate\":\"1999-09-19\",\"endDate\":\"2001-01-01\",\"tags\":\"tag\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1122,13 +1157,13 @@ void getUsersCountTest1() { void postTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "POST"); } @Test @@ -1146,18 +1181,18 @@ void postTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1166,7 +1201,8 @@ void postTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1178,13 +1214,13 @@ void postTest1() { void putTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "PUT"); } @Test @@ -1202,18 +1238,18 @@ void putTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1222,7 +1258,8 @@ void putTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); 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 index 9ca9852016..18b1727b65 100644 --- 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 @@ -3,10 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.algolia.JSON; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; import com.algolia.api.InsightsClient; import com.algolia.model.insights.*; -import com.algolia.utils.echo.*; +import com.algolia.utils.JSON; import com.google.gson.reflect.TypeToken; import java.util.*; import org.junit.jupiter.api.BeforeAll; @@ -20,10 +21,12 @@ class InsightsClientTests { private InsightsClient client; + private EchoRequester requester; @BeforeAll void init() { - client = new InsightsClient("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new InsightsClient("appId", "apiKey", requester); } @Test @@ -31,13 +34,13 @@ void init() { void delTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "DELETE"); } @Test @@ -50,19 +53,20 @@ void delTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "DELETE"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -74,13 +78,13 @@ void delTest1() { void getTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "GET"); } @Test @@ -93,19 +97,20 @@ void getTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -117,13 +122,13 @@ void getTest1() { void postTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "POST"); } @Test @@ -141,18 +146,18 @@ void postTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -161,7 +166,8 @@ void postTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -257,13 +263,13 @@ void pushEventsTest0() { insightEvents0.setEvents(events1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.pushEvents(insightEvents0); - } - ); + assertDoesNotThrow(() -> { + client.pushEvents(insightEvents0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/events"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/events"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( @@ -272,7 +278,7 @@ void pushEventsTest0() { " 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(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -283,13 +289,13 @@ void pushEventsTest0() { void putTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "PUT"); } @Test @@ -307,18 +313,18 @@ void putTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -327,7 +333,8 @@ void putTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); 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 index 1c8bfcc984..6cfd4b7aae 100644 --- 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 @@ -3,10 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.algolia.JSON; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; import com.algolia.api.PersonalizationClient; import com.algolia.model.personalization.*; -import com.algolia.utils.echo.*; +import com.algolia.utils.JSON; import com.google.gson.reflect.TypeToken; import java.util.*; import org.junit.jupiter.api.BeforeAll; @@ -20,10 +21,12 @@ class PersonalizationClientTests { private PersonalizationClient client; + private EchoRequester requester; @BeforeAll void init() { - client = new PersonalizationClient("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new PersonalizationClient("appId", "apiKey", requester); } @Test @@ -31,13 +34,13 @@ void init() { void delTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "DELETE"); } @Test @@ -50,19 +53,20 @@ void delTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "DELETE"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -74,13 +78,13 @@ void delTest1() { void deleteUserProfileTest0() { String userToken0 = "UserToken"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteUserProfile(userToken0); - } - ); + assertDoesNotThrow(() -> { + client.deleteUserProfile(userToken0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/profiles/UserToken"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/profiles/UserToken"); + assertEquals(req.method, "DELETE"); } @Test @@ -88,13 +92,13 @@ void deleteUserProfileTest0() { void getTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "GET"); } @Test @@ -107,19 +111,20 @@ void getTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -129,13 +134,13 @@ void getTest1() { @Test @DisplayName("get getPersonalizationStrategy") void getPersonalizationStrategyTest0() { - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getPersonalizationStrategy(); - } - ); + assertDoesNotThrow(() -> { + client.getPersonalizationStrategy(); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/strategies/personalization"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/strategies/personalization"); + assertEquals(req.method, "GET"); } @Test @@ -143,13 +148,13 @@ void getPersonalizationStrategyTest0() { void getUserTokenProfileTest0() { String userToken0 = "UserToken"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getUserTokenProfile(userToken0); - } - ); + assertDoesNotThrow(() -> { + client.getUserTokenProfile(userToken0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/profiles/personalization/UserToken"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/profiles/personalization/UserToken"); + assertEquals(req.method, "GET"); } @Test @@ -157,13 +162,13 @@ void getUserTokenProfileTest0() { void postTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "POST"); } @Test @@ -181,18 +186,18 @@ void postTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -201,7 +206,8 @@ void postTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -213,13 +219,13 @@ void postTest1() { void putTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "PUT"); } @Test @@ -237,18 +243,18 @@ void putTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -257,7 +263,8 @@ void putTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -301,20 +308,18 @@ void setPersonalizationStrategyTest0() { ); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.setPersonalizationStrategy( - personalizationStrategyParams0 - ); - } - ); + assertDoesNotThrow(() -> { + client.setPersonalizationStrategy(personalizationStrategyParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/strategies/personalization"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/strategies/personalization"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"eventScoring\":[{\"score\":42,\"eventName\":\"Algolia\",\"eventType\":\"Event\"}],\"facetScoring\":[{\"score\":42,\"facetName\":\"Event\"}],\"personalizationImpact\":42}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); diff --git a/tests/output/java/src/test/java/com/algolia/methods/requests/predict.test.java b/tests/output/java/src/test/java/com/algolia/methods/requests/predict.test.java index 6daba6a264..cc8f6f3ada 100644 --- a/tests/output/java/src/test/java/com/algolia/methods/requests/predict.test.java +++ b/tests/output/java/src/test/java/com/algolia/methods/requests/predict.test.java @@ -3,10 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.algolia.JSON; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; import com.algolia.api.PredictClient; import com.algolia.model.predict.*; -import com.algolia.utils.echo.*; +import com.algolia.utils.JSON; import com.google.gson.reflect.TypeToken; import java.util.*; import org.junit.jupiter.api.BeforeAll; @@ -20,10 +21,12 @@ class PredictClientTests { private PredictClient client; + private EchoRequester requester; @BeforeAll void init() { - client = new PredictClient("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new PredictClient("appId", "apiKey", requester); } @Test @@ -31,13 +34,13 @@ void init() { void delTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "DELETE"); } @Test @@ -50,19 +53,20 @@ void delTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "DELETE"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -93,21 +97,18 @@ void fetchUserProfileTest0() { params0.setModelsToRetrieve(modelsToRetrieve1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.fetchUserProfile( - userID0, - Params.ofModelsToRetrieve(params0) - ); - } - ); + assertDoesNotThrow(() -> { + client.fetchUserProfile(userID0, Params.ofModelsToRetrieve(params0)); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/users/user1/fetch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/users/user1/fetch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"modelsToRetrieve\":[\"funnel_stage\",\"order_value\",\"affinities\"]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -133,21 +134,18 @@ void fetchUserProfileTest1() { params0.setTypesToRetrieve(typesToRetrieve1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.fetchUserProfile( - userID0, - Params.ofTypesToRetrieve(params0) - ); - } - ); + assertDoesNotThrow(() -> { + client.fetchUserProfile(userID0, Params.ofTypesToRetrieve(params0)); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/users/user1/fetch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/users/user1/fetch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"typesToRetrieve\":[\"properties\",\"segments\"]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -189,18 +187,18 @@ void fetchUserProfileTest2() { params0.setTypesToRetrieve(typesToRetrieve1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.fetchUserProfile(userID0, Params.ofAllParams(params0)); - } - ); + assertDoesNotThrow(() -> { + client.fetchUserProfile(userID0, Params.ofAllParams(params0)); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/users/user1/fetch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/users/user1/fetch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"modelsToRetrieve\":[\"funnel_stage\",\"order_value\",\"affinities\"],\"typesToRetrieve\":[\"properties\",\"segments\"]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -211,13 +209,13 @@ void fetchUserProfileTest2() { void getTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "GET"); } @Test @@ -230,19 +228,20 @@ void getTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -254,13 +253,13 @@ void getTest1() { void postTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "POST"); } @Test @@ -278,18 +277,18 @@ void postTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -298,7 +297,8 @@ void postTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -310,13 +310,13 @@ void postTest1() { void putTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "PUT"); } @Test @@ -334,18 +334,18 @@ void putTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -354,7 +354,8 @@ void putTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); 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 index 1c06e36d0b..1be838fa51 100644 --- 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 @@ -3,10 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.algolia.JSON; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; import com.algolia.api.QuerySuggestionsClient; import com.algolia.model.querySuggestions.*; -import com.algolia.utils.echo.*; +import com.algolia.utils.JSON; import com.google.gson.reflect.TypeToken; import java.util.*; import org.junit.jupiter.api.BeforeAll; @@ -20,10 +21,12 @@ class QuerySuggestionsClientTests { private QuerySuggestionsClient client; + private EchoRequester requester; @BeforeAll void init() { - client = new QuerySuggestionsClient("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new QuerySuggestionsClient("appId", "apiKey", requester); } @Test @@ -85,18 +88,18 @@ void createConfigTest0() { querySuggestionsIndexWithIndexParam0.setExclude(exclude1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.createConfig(querySuggestionsIndexWithIndexParam0); - } - ); + assertDoesNotThrow(() -> { + client.createConfig(querySuggestionsIndexWithIndexParam0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/configs"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/configs"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"indexName\":\"theIndexName\",\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attributes\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -107,13 +110,13 @@ void createConfigTest0() { void delTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "DELETE"); } @Test @@ -126,19 +129,20 @@ void delTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "DELETE"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -150,13 +154,13 @@ void delTest1() { void deleteConfigTest0() { String indexName0 = "theIndexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteConfig(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.deleteConfig(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/configs/theIndexName"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/configs/theIndexName"); + assertEquals(req.method, "DELETE"); } @Test @@ -164,13 +168,13 @@ void deleteConfigTest0() { void getTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "GET"); } @Test @@ -183,19 +187,20 @@ void getTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -205,13 +210,13 @@ void getTest1() { @Test @DisplayName("getAllConfigs") void getAllConfigsTest0() { - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getAllConfigs(); - } - ); + assertDoesNotThrow(() -> { + client.getAllConfigs(); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/configs"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/configs"); + assertEquals(req.method, "GET"); } @Test @@ -219,13 +224,13 @@ void getAllConfigsTest0() { void getConfigTest0() { String indexName0 = "theIndexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getConfig(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.getConfig(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/configs/theIndexName"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/configs/theIndexName"); + assertEquals(req.method, "GET"); } @Test @@ -233,13 +238,13 @@ void getConfigTest0() { void getConfigStatusTest0() { String indexName0 = "theIndexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getConfigStatus(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.getConfigStatus(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/configs/theIndexName/status"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/configs/theIndexName/status"); + assertEquals(req.method, "GET"); } @Test @@ -247,13 +252,13 @@ void getConfigStatusTest0() { void getLogFileTest0() { String indexName0 = "theIndexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getLogFile(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.getLogFile(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/logs/theIndexName"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/logs/theIndexName"); + assertEquals(req.method, "GET"); } @Test @@ -261,13 +266,13 @@ void getLogFileTest0() { void postTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "POST"); } @Test @@ -285,18 +290,18 @@ void postTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -305,7 +310,8 @@ void postTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -317,13 +323,13 @@ void postTest1() { void putTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "PUT"); } @Test @@ -341,18 +347,18 @@ void putTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -361,7 +367,8 @@ void putTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -426,18 +433,18 @@ void updateConfigTest0() { querySuggestionsIndexParam0.setExclude(exclude1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.updateConfig(indexName0, querySuggestionsIndexParam0); - } - ); + assertDoesNotThrow(() -> { + client.updateConfig(indexName0, querySuggestionsIndexParam0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/configs/theIndexName"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/configs/theIndexName"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"sourceIndices\":[{\"indexName\":\"testIndex\",\"facets\":[{\"attributes\":\"test\"}],\"generate\":[[\"facetA\",\"facetB\"],[\"facetC\"]]}],\"languages\":[\"french\"],\"exclude\":[\"test\"]}", - req.getBody(), + req.body, 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 index 43247c414d..b49a410ae9 100644 --- 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 @@ -3,10 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.algolia.JSON; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; import com.algolia.api.RecommendClient; import com.algolia.model.recommend.*; -import com.algolia.utils.echo.*; +import com.algolia.utils.JSON; import com.google.gson.reflect.TypeToken; import java.util.*; import org.junit.jupiter.api.BeforeAll; @@ -20,10 +21,12 @@ class RecommendClientTests { private RecommendClient client; + private EchoRequester requester; @BeforeAll void init() { - client = new RecommendClient("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new RecommendClient("appId", "apiKey", requester); } @Test @@ -31,13 +34,13 @@ void init() { void delTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "DELETE"); } @Test @@ -50,19 +53,20 @@ void delTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "DELETE"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -74,13 +78,13 @@ void delTest1() { void getTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "GET"); } @Test @@ -93,19 +97,20 @@ void getTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -141,18 +146,18 @@ void getRecommendationsTest0() { getRecommendationsParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getRecommendations(getRecommendationsParams0); - } - ); + assertDoesNotThrow(() -> { + client.getRecommendations(getRecommendationsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/recommendations"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/recommendations"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"indexName\":\"indexName\",\"objectID\":\"objectID\",\"model\":\"related-products\",\"threshold\":42}]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -215,18 +220,18 @@ void getRecommendationsTest1() { getRecommendationsParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getRecommendations(getRecommendationsParams0); - } - ); + assertDoesNotThrow(() -> { + client.getRecommendations(getRecommendationsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/recommendations"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/recommendations"); + assertEquals(req.method, "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(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -253,18 +258,18 @@ void getRecommendationsTest2() { getRecommendationsParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getRecommendations(getRecommendationsParams0); - } - ); + assertDoesNotThrow(() -> { + client.getRecommendations(getRecommendationsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/recommendations"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/recommendations"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"indexName\":\"indexName\",\"model\":\"trending-items\",\"threshold\":42}]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -325,18 +330,18 @@ void getRecommendationsTest3() { getRecommendationsParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getRecommendations(getRecommendationsParams0); - } - ); + assertDoesNotThrow(() -> { + client.getRecommendations(getRecommendationsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/recommendations"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/recommendations"); + assertEquals(req.method, "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(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -385,18 +390,18 @@ void getRecommendationsTest4() { getRecommendationsParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getRecommendations(getRecommendationsParams0); - } - ); + assertDoesNotThrow(() -> { + client.getRecommendations(getRecommendationsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/recommendations"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/recommendations"); + assertEquals(req.method, "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(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -505,18 +510,18 @@ void getRecommendationsTest5() { getRecommendationsParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getRecommendations(getRecommendationsParams0); - } - ); + assertDoesNotThrow(() -> { + client.getRecommendations(getRecommendationsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/recommendations"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/recommendations"); + assertEquals(req.method, "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(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -549,18 +554,18 @@ void getRecommendationsTest6() { getRecommendationsParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getRecommendations(getRecommendationsParams0); - } - ); + assertDoesNotThrow(() -> { + client.getRecommendations(getRecommendationsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/recommendations"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/recommendations"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"indexName\":\"indexName1\",\"objectID\":\"objectID1\",\"model\":\"bought-together\",\"threshold\":42}]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -571,13 +576,13 @@ void getRecommendationsTest6() { void postTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "POST"); } @Test @@ -595,18 +600,18 @@ void postTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -615,7 +620,8 @@ void postTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -627,13 +633,13 @@ void postTest1() { void putTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "PUT"); } @Test @@ -651,18 +657,18 @@ void putTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -671,7 +677,8 @@ void putTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); 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 73d688edd7..7e5b516497 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 @@ -3,10 +3,11 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; -import com.algolia.JSON; +import com.algolia.EchoRequester; +import com.algolia.EchoResponse; import com.algolia.api.SearchClient; import com.algolia.model.search.*; -import com.algolia.utils.echo.*; +import com.algolia.utils.JSON; import com.google.gson.reflect.TypeToken; import java.util.*; import org.junit.jupiter.api.BeforeAll; @@ -20,10 +21,12 @@ class SearchClientTests { private SearchClient client; + private EchoRequester requester; @BeforeAll void init() { - client = new SearchClient("appId", "apiKey", new EchoRequester()); + requester = new EchoRequester(); + client = new SearchClient("appId", "apiKey", requester); } @Test @@ -49,19 +52,19 @@ void addApiKeyTest0() { apiKey0.setMaxHitsPerQuery(maxHitsPerQuery1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.addApiKey(apiKey0); - } - ); + assertDoesNotThrow(() -> { + client.addApiKey(apiKey0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/keys"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/keys"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"acl\":[\"search\",\"addObject\"],\"description\":\"my new api" + " key\",\"validity\":300,\"maxQueriesPerIPPerHour\":100,\"maxHitsPerQuery\":20}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -78,18 +81,18 @@ void addOrUpdateObjectTest0() { body0.put("key", key1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.addOrUpdateObject(indexName0, objectID0, body0); - } - ); + assertDoesNotThrow(() -> { + client.addOrUpdateObject(indexName0, objectID0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/uniqueID"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/indexes/indexName/uniqueID"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"key\":\"value\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -106,18 +109,18 @@ void appendSourceTest0() { source0.setDescription(description1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.appendSource(source0); - } - ); + assertDoesNotThrow(() -> { + client.appendSource(source0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/security/sources/append"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/security/sources/append"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"source\":\"theSource\",\"description\":\"theDescription\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -133,18 +136,18 @@ void assignUserIdTest0() { assignUserIdParams0.setCluster(cluster1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.assignUserId(xAlgoliaUserID0, assignUserIdParams0); - } - ); + assertDoesNotThrow(() -> { + client.assignUserId(xAlgoliaUserID0, assignUserIdParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters/mapping"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/clusters/mapping"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"cluster\":\"theCluster\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -153,7 +156,8 @@ void assignUserIdTest0() { "{\"X-Algolia-User-ID\":\"userID\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -184,18 +188,18 @@ void batchTest0() { batchWriteParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.batch(indexName0, batchWriteParams0); - } - ); + assertDoesNotThrow(() -> { + client.batch(indexName0, batchWriteParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/batch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/theIndexName/batch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"action\":\"delete\",\"body\":{\"key\":\"value\"}}]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -219,21 +223,18 @@ void batchAssignUserIdsTest0() { batchAssignUserIdsParams0.setUsers(users1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.batchAssignUserIds( - xAlgoliaUserID0, - batchAssignUserIdsParams0 - ); - } - ); + assertDoesNotThrow(() -> { + client.batchAssignUserIds(xAlgoliaUserID0, batchAssignUserIdsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters/mapping/batch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/clusters/mapping/batch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"cluster\":\"theCluster\",\"users\":[\"user1\",\"user2\"]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -242,7 +243,8 @@ void batchAssignUserIdsTest0() { "{\"X-Algolia-User-ID\":\"userID\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -289,21 +291,21 @@ void batchDictionaryEntriesTest0() { batchDictionaryEntriesParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.batchDictionaryEntries( - dictionaryName0, - batchDictionaryEntriesParams0 - ); - } - ); + assertDoesNotThrow(() -> { + client.batchDictionaryEntries( + dictionaryName0, + batchDictionaryEntriesParams0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/dictionaries/compounds/batch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/dictionaries/compounds/batch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"action\":\"addEntry\",\"body\":{\"objectID\":\"1\",\"language\":\"en\"}},{\"action\":\"deleteEntry\",\"body\":{\"objectID\":\"2\",\"language\":\"fr\"}}]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -397,21 +399,21 @@ void batchDictionaryEntriesTest1() { batchDictionaryEntriesParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.batchDictionaryEntries( - dictionaryName0, - batchDictionaryEntriesParams0 - ); - } - ); + assertDoesNotThrow(() -> { + client.batchDictionaryEntries( + dictionaryName0, + batchDictionaryEntriesParams0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/dictionaries/compounds/batch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/dictionaries/compounds/batch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"clearExistingDictionaryEntries\":false,\"requests\":[{\"action\":\"addEntry\",\"body\":{\"objectID\":\"1\",\"language\":\"en\",\"word\":\"fancy\",\"words\":[\"believe\",\"algolia\"],\"decomposition\":[\"trust\",\"algolia\"],\"state\":\"enabled\"}},{\"action\":\"deleteEntry\",\"body\":{\"objectID\":\"2\",\"language\":\"fr\",\"word\":\"humility\",\"words\":[\"candor\",\"algolia\"],\"decomposition\":[\"grit\",\"algolia\"],\"state\":\"enabled\"}}]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -483,23 +485,23 @@ void batchRulesTest0() { boolean forwardToReplicas0 = true; boolean clearExistingRules0 = true; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.batchRules( - indexName0, - rule0, - forwardToReplicas0, - clearExistingRules0 - ); - } - ); + assertDoesNotThrow(() -> { + client.batchRules( + indexName0, + rule0, + forwardToReplicas0, + clearExistingRules0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/rules/batch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/rules/batch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "[{\"objectID\":\"a-rule-id\",\"conditions\":[{\"pattern\":\"smartphone\",\"anchoring\":\"contains\"}],\"consequence\":{\"params\":{\"filters\":\"category:smartphone\"}}},{\"objectID\":\"a-second-rule-id\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\"}],\"consequence\":{\"params\":{\"filters\":\"brand:apple\"}}}]", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -508,7 +510,8 @@ void batchRulesTest0() { "{\"forwardToReplicas\":\"true\",\"clearExistingRules\":\"true\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -520,13 +523,13 @@ void batchRulesTest0() { void browseTest0() { String indexName0 = "indexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.browse(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.browse(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/browse"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/browse"); + assertEquals(req.method, "POST"); } @Test @@ -541,18 +544,18 @@ void browseTest1() { browseRequest0.setCursor(cursor1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.browse(indexName0, browseRequest0); - } - ); + assertDoesNotThrow(() -> { + client.browse(indexName0, browseRequest0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/browse"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/browse"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"params\":\"query=foo&facetFilters=['bar']\",\"cursor\":\"cts\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -563,13 +566,13 @@ void browseTest1() { void clearAllSynonymsTest0() { String indexName0 = "indexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.clearAllSynonyms(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.clearAllSynonyms(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/synonyms/clear"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/synonyms/clear"); + assertEquals(req.method, "POST"); } @Test @@ -577,13 +580,13 @@ void clearAllSynonymsTest0() { void clearObjectsTest0() { String indexName0 = "theIndexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.clearObjects(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.clearObjects(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/clear"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/theIndexName/clear"); + assertEquals(req.method, "POST"); } @Test @@ -591,13 +594,13 @@ void clearObjectsTest0() { void clearRulesTest0() { String indexName0 = "indexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.clearRules(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.clearRules(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/rules/clear"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/rules/clear"); + assertEquals(req.method, "POST"); } @Test @@ -605,13 +608,13 @@ void clearRulesTest0() { void delTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "DELETE"); } @Test @@ -624,19 +627,20 @@ void delTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.del(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.del(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "DELETE"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -648,13 +652,13 @@ void delTest1() { void deleteApiKeyTest0() { String key0 = "myTestApiKey"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteApiKey(key0); - } - ); + assertDoesNotThrow(() -> { + client.deleteApiKey(key0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/keys/myTestApiKey"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/keys/myTestApiKey"); + assertEquals(req.method, "DELETE"); } @Test @@ -667,21 +671,21 @@ void deleteByTest0() { searchParams0.setQuery(query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteBy( - indexName0, - SearchParams.ofSearchParamsObject(searchParams0) - ); - } - ); + assertDoesNotThrow(() -> { + client.deleteBy( + indexName0, + SearchParams.ofSearchParamsObject(searchParams0) + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/deleteByQuery"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/theIndexName/deleteByQuery"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"query\":\"testQuery\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -692,13 +696,13 @@ void deleteByTest0() { void deleteIndexTest0() { String indexName0 = "theIndexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteIndex(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.deleteIndex(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/indexes/theIndexName"); + assertEquals(req.method, "DELETE"); } @Test @@ -707,13 +711,13 @@ void deleteObjectTest0() { String indexName0 = "theIndexName"; String objectID0 = "uniqueID"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteObject(indexName0, objectID0); - } - ); + assertDoesNotThrow(() -> { + client.deleteObject(indexName0, objectID0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/uniqueID"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/indexes/theIndexName/uniqueID"); + assertEquals(req.method, "DELETE"); } @Test @@ -722,13 +726,13 @@ void deleteRuleTest0() { String indexName0 = "indexName"; String objectID0 = "id1"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteRule(indexName0, objectID0); - } - ); + assertDoesNotThrow(() -> { + client.deleteRule(indexName0, objectID0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/rules/id1"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/indexes/indexName/rules/id1"); + assertEquals(req.method, "DELETE"); } @Test @@ -736,13 +740,13 @@ void deleteRuleTest0() { void deleteSourceTest0() { String source0 = "theSource"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteSource(source0); - } - ); + assertDoesNotThrow(() -> { + client.deleteSource(source0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/security/sources/theSource"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/security/sources/theSource"); + assertEquals(req.method, "DELETE"); } @Test @@ -751,13 +755,13 @@ void deleteSynonymTest0() { String indexName0 = "indexName"; String objectID0 = "id1"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.deleteSynonym(indexName0, objectID0); - } - ); + assertDoesNotThrow(() -> { + client.deleteSynonym(indexName0, objectID0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/synonyms/id1"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/indexes/indexName/synonyms/id1"); + assertEquals(req.method, "DELETE"); } @Test @@ -765,13 +769,13 @@ void deleteSynonymTest0() { void getTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "GET"); } @Test @@ -784,19 +788,20 @@ void getTest1() { parameters0.put("query", query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.get(path0, parameters0); - } - ); + assertDoesNotThrow(() -> { + client.get(path0, parameters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -808,37 +813,37 @@ void getTest1() { void getApiKeyTest0() { String key0 = "myTestApiKey"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getApiKey(key0); - } - ); + assertDoesNotThrow(() -> { + client.getApiKey(key0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/keys/myTestApiKey"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/keys/myTestApiKey"); + assertEquals(req.method, "GET"); } @Test @DisplayName("get getDictionaryLanguages") void getDictionaryLanguagesTest0() { - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getDictionaryLanguages(); - } - ); + assertDoesNotThrow(() -> { + client.getDictionaryLanguages(); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/dictionaries/*/languages"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/dictionaries/*/languages"); + assertEquals(req.method, "GET"); } @Test @DisplayName("get getDictionarySettings results") void getDictionarySettingsTest0() { - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getDictionarySettings(); - } - ); + assertDoesNotThrow(() -> { + client.getDictionarySettings(); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/dictionaries/*/settings"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/dictionaries/*/settings"); + assertEquals(req.method, "GET"); } @Test @@ -849,19 +854,20 @@ void getLogsTest0() { String indexName0 = "theIndexName"; LogType type0 = LogType.fromValue("all"); - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getLogs(offset0, length0, indexName0, type0); - } - ); + assertDoesNotThrow(() -> { + client.getLogs(offset0, length0, indexName0, type0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/logs"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/logs"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"offset\":\"5\",\"length\":\"10\",\"indexName\":\"theIndexName\",\"type\":\"all\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -881,19 +887,20 @@ void getObjectTest0() { attributesToRetrieve0.add(attributesToRetrieve_11); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getObject(indexName0, objectID0, attributesToRetrieve0); - } - ); + assertDoesNotThrow(() -> { + client.getObject(indexName0, objectID0, attributesToRetrieve0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/uniqueID"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/indexes/theIndexName/uniqueID"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"attributesToRetrieve\":\"attr1,attr2\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -927,18 +934,18 @@ void getObjectsTest0() { getObjectsParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getObjects(getObjectsParams0); - } - ); + assertDoesNotThrow(() -> { + client.getObjects(getObjectsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/objects"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/objects"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"attributesToRetrieve\":[\"attr1\",\"attr2\"],\"objectID\":\"uniqueID\",\"indexName\":\"theIndexName\"}]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -950,13 +957,13 @@ void getRuleTest0() { String indexName0 = "indexName"; String objectID0 = "id1"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getRule(indexName0, objectID0); - } - ); + assertDoesNotThrow(() -> { + client.getRule(indexName0, objectID0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/rules/id1"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/indexes/indexName/rules/id1"); + assertEquals(req.method, "GET"); } @Test @@ -964,25 +971,25 @@ void getRuleTest0() { void getSettingsTest0() { String indexName0 = "theIndexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSettings(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.getSettings(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/settings"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/indexes/theIndexName/settings"); + assertEquals(req.method, "GET"); } @Test @DisplayName("getSources") void getSourcesTest0() { - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSources(); - } - ); + assertDoesNotThrow(() -> { + client.getSources(); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/security/sources"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/security/sources"); + assertEquals(req.method, "GET"); } @Test @@ -991,13 +998,13 @@ void getSynonymTest0() { String indexName0 = "indexName"; String objectID0 = "id1"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getSynonym(indexName0, objectID0); - } - ); + assertDoesNotThrow(() -> { + client.getSynonym(indexName0, objectID0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/synonyms/id1"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/indexes/indexName/synonyms/id1"); + assertEquals(req.method, "GET"); } @Test @@ -1006,25 +1013,25 @@ void getTaskTest0() { String indexName0 = "theIndexName"; int taskID0 = 123; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTask(indexName0, taskID0); - } - ); + assertDoesNotThrow(() -> { + client.getTask(indexName0, taskID0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/task/123"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/indexes/theIndexName/task/123"); + assertEquals(req.method, "GET"); } @Test @DisplayName("getTopUserIds") void getTopUserIdsTest0() { - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getTopUserIds(); - } - ); + assertDoesNotThrow(() -> { + client.getTopUserIds(); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters/mapping/top"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/clusters/mapping/top"); + assertEquals(req.method, "GET"); } @Test @@ -1032,13 +1039,13 @@ void getTopUserIdsTest0() { void getUserIdTest0() { String userID0 = "uniqueID"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.getUserId(userID0); - } - ); + assertDoesNotThrow(() -> { + client.getUserId(userID0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters/mapping/uniqueID"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/clusters/mapping/uniqueID"); + assertEquals(req.method, "GET"); } @Test @@ -1046,19 +1053,20 @@ void getUserIdTest0() { void hasPendingMappingsTest0() { boolean getClusters0 = true; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.hasPendingMappings(getClusters0); - } - ); + assertDoesNotThrow(() -> { + client.hasPendingMappings(getClusters0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters/mapping/pending"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/clusters/mapping/pending"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"getClusters\":\"true\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1068,25 +1076,25 @@ void hasPendingMappingsTest0() { @Test @DisplayName("listApiKeys") void listApiKeysTest0() { - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.listApiKeys(); - } - ); + assertDoesNotThrow(() -> { + client.listApiKeys(); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/keys"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/keys"); + assertEquals(req.method, "GET"); } @Test @DisplayName("listClusters") void listClustersTest0() { - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.listClusters(); - } - ); + assertDoesNotThrow(() -> { + client.listClusters(); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/clusters"); + assertEquals(req.method, "GET"); } @Test @@ -1094,19 +1102,20 @@ void listClustersTest0() { void listIndicesTest0() { int page0 = 8; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.listIndices(page0); - } - ); + assertDoesNotThrow(() -> { + client.listIndices(page0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/indexes"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"page\":\"8\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1119,19 +1128,20 @@ void listUserIdsTest0() { int page0 = 8; int hitsPerPage0 = 100; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.listUserIds(page0, hitsPerPage0); - } - ); + assertDoesNotThrow(() -> { + client.listUserIds(page0, hitsPerPage0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters/mapping"); - assertEquals(req.getMethod(), "GET"); + assertEquals(req.path, "/1/clusters/mapping"); + assertEquals(req.method, "GET"); Map expectedQuery = JSON.deserialize( "{\"page\":\"8\",\"hitsPerPage\":\"100\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1163,18 +1173,18 @@ void multipleBatchTest0() { batchParams0.setRequests(requests1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.multipleBatch(batchParams0); - } - ); + assertDoesNotThrow(() -> { + client.multipleBatch(batchParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/batch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/batch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"action\":\"addObject\",\"body\":{\"key\":\"value\"},\"indexName\":\"theIndexName\"}]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1201,18 +1211,18 @@ void multipleQueriesTest0() { multipleQueriesParams0.setStrategy(strategy1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.multipleQueries(multipleQueriesParams0); - } - ); + assertDoesNotThrow(() -> { + client.multipleQueries(multipleQueriesParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/queries"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/queries"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"indexName\":\"theIndexName\"}],\"strategy\":\"stopIfEnoughMatches\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1259,18 +1269,18 @@ void multipleQueriesTest1() { multipleQueriesParams0.setStrategy(strategy1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.multipleQueries(multipleQueriesParams0); - } - ); + assertDoesNotThrow(() -> { + client.multipleQueries(multipleQueriesParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/*/queries"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/*/queries"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"requests\":[{\"indexName\":\"theIndexName\",\"query\":\"test\",\"type\":\"facet\",\"facet\":\"theFacet\",\"params\":\"testParam\"},{\"indexName\":\"theIndexName\",\"query\":\"test\",\"type\":\"default\",\"params\":\"testParam\"}],\"strategy\":\"stopIfEnoughMatches\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1296,18 +1306,18 @@ void operationIndexTest0() { operationIndexParams0.setScope(scope1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.operationIndex(indexName0, operationIndexParams0); - } - ); + assertDoesNotThrow(() -> { + client.operationIndex(indexName0, operationIndexParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/operation"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/theIndexName/operation"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"operation\":\"copy\",\"destination\":\"dest\",\"scope\":[\"rules\",\"settings\"]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1345,23 +1355,23 @@ void partialUpdateObjectTest0() { } boolean createIfNotExists0 = true; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.partialUpdateObject( - indexName0, - objectID0, - attributeOrBuiltInOperation0, - createIfNotExists0 - ); - } - ); + assertDoesNotThrow(() -> { + client.partialUpdateObject( + indexName0, + objectID0, + attributeOrBuiltInOperation0, + createIfNotExists0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/uniqueID/partial"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/theIndexName/uniqueID/partial"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "[{\"id1\":\"test\",\"id2\":{\"_operation\":\"AddUnique\",\"value\":\"test2\"}}]", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1370,7 +1380,8 @@ void partialUpdateObjectTest0() { "{\"createIfNotExists\":\"true\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1382,13 +1393,13 @@ void partialUpdateObjectTest0() { void postTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "POST"); } @Test @@ -1406,18 +1417,18 @@ void postTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.post(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.post(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1426,7 +1437,8 @@ void postTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1438,13 +1450,13 @@ void postTest1() { void putTest0() { String path0 = "/test/minimal"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/minimal"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/minimal"); + assertEquals(req.method, "PUT"); } @Test @@ -1462,18 +1474,18 @@ void putTest1() { body0.put("body", body1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.put(path0, parameters0, body0); - } - ); + assertDoesNotThrow(() -> { + client.put(path0, parameters0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/test/all"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/test/all"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"body\":\"parameters\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1482,7 +1494,8 @@ void putTest1() { "{\"query\":\"parameters\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1494,13 +1507,13 @@ void putTest1() { void removeUserIdTest0() { String userID0 = "uniqueID"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.removeUserId(userID0); - } - ); + assertDoesNotThrow(() -> { + client.removeUserId(userID0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters/mapping/uniqueID"); - assertEquals(req.getMethod(), "DELETE"); + assertEquals(req.path, "/1/clusters/mapping/uniqueID"); + assertEquals(req.method, "DELETE"); } @Test @@ -1518,18 +1531,18 @@ void replaceSourcesTest0() { source0.add(source_01); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.replaceSources(source0); - } - ); + assertDoesNotThrow(() -> { + client.replaceSources(source0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/security/sources"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/security/sources"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "[{\"source\":\"theSource\",\"description\":\"theDescription\"}]", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1540,13 +1553,13 @@ void replaceSourcesTest0() { void restoreApiKeyTest0() { String key0 = "myApiKey"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.restoreApiKey(key0); - } - ); + assertDoesNotThrow(() -> { + client.restoreApiKey(key0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/keys/myApiKey/restore"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/keys/myApiKey/restore"); + assertEquals(req.method, "POST"); } @Test @@ -1561,18 +1574,18 @@ void saveObjectTest0() { body0.put("test", test1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.saveObject(indexName0, body0); - } - ); + assertDoesNotThrow(() -> { + client.saveObject(indexName0, body0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/theIndexName"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"objectID\":\"id\",\"test\":\"val\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1612,23 +1625,18 @@ void saveRuleTest0() { } boolean forwardToReplicas0 = true; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.saveRule( - indexName0, - objectID0, - rule0, - forwardToReplicas0 - ); - } - ); + assertDoesNotThrow(() -> { + client.saveRule(indexName0, objectID0, rule0, forwardToReplicas0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/rules/id1"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/indexes/indexName/rules/id1"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"objectID\":\"id1\",\"conditions\":[{\"pattern\":\"apple\",\"anchoring\":\"contains\"}],\"consequence\":{\"params\":{\"filters\":\"brand:apple\"}}}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1637,7 +1645,8 @@ void saveRuleTest0() { "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1668,23 +1677,23 @@ void saveSynonymTest0() { } boolean forwardToReplicas0 = true; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.saveSynonym( - indexName0, - objectID0, - synonymHit0, - forwardToReplicas0 - ); - } - ); + assertDoesNotThrow(() -> { + client.saveSynonym( + indexName0, + objectID0, + synonymHit0, + forwardToReplicas0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/synonyms/id1"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/indexes/indexName/synonyms/id1"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"objectID\":\"id1\",\"type\":\"synonym\",\"synonyms\":[\"car\",\"vehicule\",\"auto\"]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1693,7 +1702,8 @@ void saveSynonymTest0() { "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1748,23 +1758,23 @@ void saveSynonymsTest0() { boolean forwardToReplicas0 = true; boolean replaceExistingSynonyms0 = false; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.saveSynonyms( - indexName0, - synonymHit0, - forwardToReplicas0, - replaceExistingSynonyms0 - ); - } - ); + assertDoesNotThrow(() -> { + client.saveSynonyms( + indexName0, + synonymHit0, + forwardToReplicas0, + replaceExistingSynonyms0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/synonyms/batch"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/synonyms/batch"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "[{\"objectID\":\"id1\",\"type\":\"synonym\",\"synonyms\":[\"car\",\"vehicule\",\"auto\"]},{\"objectID\":\"id2\",\"type\":\"onewaysynonym\",\"input\":\"iphone\",\"synonyms\":[\"ephone\",\"aphone\",\"yphone\"]}]", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1773,7 +1783,8 @@ void saveSynonymsTest0() { "{\"forwardToReplicas\":\"true\",\"replaceExistingSynonyms\":\"false\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -1790,21 +1801,21 @@ void searchTest0() { searchParams0.setQuery(query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.search( - indexName0, - SearchParams.ofSearchParamsObject(searchParams0) - ); - } - ); + assertDoesNotThrow(() -> { + client.search( + indexName0, + SearchParams.ofSearchParamsObject(searchParams0) + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/query"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/query"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"query\":\"myQuery\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1826,21 +1837,21 @@ void searchTest1() { searchParams0.setFacetFilters(FacetFilters.ofListString(facetFilters1)); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.search( - indexName0, - SearchParams.ofSearchParamsObject(searchParams0) - ); - } - ); + assertDoesNotThrow(() -> { + client.search( + indexName0, + SearchParams.ofSearchParamsObject(searchParams0) + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/query"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/query"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"query\":\"myQuery\",\"facetFilters\":[\"tags:algolia\"]}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1856,21 +1867,21 @@ void searchDictionaryEntriesTest0() { searchDictionaryEntriesParams0.setQuery(query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.searchDictionaryEntries( - dictionaryName0, - searchDictionaryEntriesParams0 - ); - } - ); + assertDoesNotThrow(() -> { + client.searchDictionaryEntries( + dictionaryName0, + searchDictionaryEntriesParams0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/dictionaries/compounds/search"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/dictionaries/compounds/search"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"query\":\"foo\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1892,21 +1903,21 @@ void searchDictionaryEntriesTest1() { searchDictionaryEntriesParams0.setLanguage(language1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.searchDictionaryEntries( - dictionaryName0, - searchDictionaryEntriesParams0 - ); - } - ); + assertDoesNotThrow(() -> { + client.searchDictionaryEntries( + dictionaryName0, + searchDictionaryEntriesParams0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/dictionaries/compounds/search"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/dictionaries/compounds/search"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"query\":\"foo\",\"page\":4,\"hitsPerPage\":2,\"language\":\"fr\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1918,13 +1929,13 @@ void searchForFacetValuesTest0() { String indexName0 = "indexName"; String facetName0 = "facetName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.searchForFacetValues(indexName0, facetName0); - } - ); + assertDoesNotThrow(() -> { + client.searchForFacetValues(indexName0, facetName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/facets/facetName/query"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/facets/facetName/query"); + assertEquals(req.method, "POST"); } @Test @@ -1942,22 +1953,22 @@ void searchForFacetValuesTest1() { searchForFacetValuesRequest0.setMaxFacetHits(maxFacetHits1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.searchForFacetValues( - indexName0, - facetName0, - searchForFacetValuesRequest0 - ); - } - ); + assertDoesNotThrow(() -> { + client.searchForFacetValues( + indexName0, + facetName0, + searchForFacetValuesRequest0 + ); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/facets/facetName/query"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/facets/facetName/query"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"params\":\"query=foo&facetFilters=['bar']\",\"facetQuery\":\"foo\",\"maxFacetHits\":42}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1973,18 +1984,18 @@ void searchRulesTest0() { searchRulesParams0.setQuery(query1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.searchRules(indexName0, searchRulesParams0); - } - ); + assertDoesNotThrow(() -> { + client.searchRules(indexName0, searchRulesParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/rules/search"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/rules/search"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"query\":\"something\"}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -1995,13 +2006,13 @@ void searchRulesTest0() { void searchSynonymsTest0() { String indexName0 = "indexName"; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.searchSynonyms(indexName0); - } - ); + assertDoesNotThrow(() -> { + client.searchSynonyms(indexName0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/indexName/synonyms/search"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/indexes/indexName/synonyms/search"); + assertEquals(req.method, "POST"); } @Test @@ -2019,18 +2030,18 @@ void searchUserIdsTest0() { searchUserIdsParams0.setHitsPerPage(hitsPerPage1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.searchUserIds(searchUserIdsParams0); - } - ); + assertDoesNotThrow(() -> { + client.searchUserIds(searchUserIdsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/clusters/mapping/search"); - assertEquals(req.getMethod(), "POST"); + assertEquals(req.path, "/1/clusters/mapping/search"); + assertEquals(req.method, "POST"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"query\":\"test\",\"clusterName\":\"theClusterName\",\"page\":5,\"hitsPerPage\":10}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -2059,18 +2070,18 @@ void setDictionarySettingsTest0() { ); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.setDictionarySettings(dictionarySettingsParams0); - } - ); + assertDoesNotThrow(() -> { + client.setDictionarySettings(dictionarySettingsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/dictionaries/*/settings"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/dictionaries/*/settings"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"disableStandardEntries\":{\"plurals\":{\"fr\":false,\"en\":false,\"ru\":true}}}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -2111,18 +2122,18 @@ void setDictionarySettingsTest1() { ); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.setDictionarySettings(dictionarySettingsParams0); - } - ); + assertDoesNotThrow(() -> { + client.setDictionarySettings(dictionarySettingsParams0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/dictionaries/*/settings"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/dictionaries/*/settings"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"disableStandardEntries\":{\"plurals\":{\"fr\":false,\"en\":false,\"ru\":true},\"stopwords\":{\"fr\":false},\"compounds\":{\"ru\":true}}}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -2139,22 +2150,18 @@ void setSettingsTest0() { } boolean forwardToReplicas0 = true; - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.setSettings( - indexName0, - indexSettings0, - forwardToReplicas0 - ); - } - ); + assertDoesNotThrow(() -> { + client.setSettings(indexName0, indexSettings0, forwardToReplicas0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/indexes/theIndexName/settings"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/indexes/theIndexName/settings"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"paginationLimitedTo\":10}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); }); @@ -2163,7 +2170,8 @@ void setSettingsTest0() { "{\"forwardToReplicas\":\"true\"}", new TypeToken>() {}.getType() ); - Map actualQuery = req.getQueryParams(); + Map actualQuery = req.queryParameters; + assertEquals(expectedQuery.size(), actualQuery.size()); for (Map.Entry p : actualQuery.entrySet()) { assertEquals(expectedQuery.get(p.getKey()), p.getValue()); @@ -2192,18 +2200,18 @@ void updateApiKeyTest0() { apiKey0.setMaxHitsPerQuery(maxHitsPerQuery1); } - EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> { - return client.updateApiKey(key0, apiKey0); - } - ); + assertDoesNotThrow(() -> { + client.updateApiKey(key0, apiKey0); + }); + EchoResponse req = requester.getLastEchoResponse(); - assertEquals(req.getPath(), "/1/keys/myApiKey"); - assertEquals(req.getMethod(), "PUT"); + assertEquals(req.path, "/1/keys/myApiKey"); + assertEquals(req.method, "PUT"); assertDoesNotThrow(() -> { JSONAssert.assertEquals( "{\"acl\":[\"search\",\"addObject\"],\"validity\":300,\"maxQueriesPerIPPerHour\":100,\"maxHitsPerQuery\":20}", - req.getBody(), + req.body, JSONCompareMode.STRICT_ORDER ); });