Skip to content

Commit

Permalink
Merge pull request #1595 from gentics/hotfix-1.10.x-sup-16397
Browse files Browse the repository at this point in the history
Add option to not reset database between test cases
  • Loading branch information
npomaroli authored Mar 5, 2024
2 parents a7ed904 + 6ea1da4 commit 62a3ada
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 107 deletions.
7 changes: 7 additions & 0 deletions LTS-CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ include::content/docs/variables.adoc-include[]
The LTS changelog lists releases which are only accessible via a commercial subscription.
All fixes and changes in LTS releases will be released the next minor release. Changes from LTS 1.4.x will be included in release 1.5.0.

[[v1.10.29]]
== 1.10.29 (TBD)

icon:check[] REST client: The configuration now allows adding default parameter provider for query parameters, that should be added to every request (unless overwritten).

icon:check[] Tests: The tests API has been extended to allow tests which do not reset the database between test cases.

[[v1.10.28]]
== 1.10.28 (27.02.2024)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class LocalActionContextImpl<T> extends AbstractInternalActionContext imp
public LocalActionContextImpl(BootstrapInitializer boot, MeshAuthUser user, Class<? extends T> classOfResponse,
ParameterProvider... requestParameters) {
this.boot = boot;
this.query = getQuery(requestParameters);
this.query = getQuery(null, requestParameters);
this.user = user;
this.classOfResponse = classOfResponse;
data.put(SecurityLoggingHandler.SECURITY_LOGGER_CONTEXT_KEY, securityLogger);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.gentics.mesh.rest.client;

import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.lang.StringUtils;

import com.gentics.mesh.core.rest.common.GenericMessageResponse;
import com.gentics.mesh.core.rest.common.RestModel;
Expand Down Expand Up @@ -143,21 +149,31 @@ abstract public <T> MeshRequest<T> prepareRequest(HttpMethod method, String path

/**
* Return the query aggregated parameter string for the given providers.
*
* @param config configuration object (may be null)
* @param parameters
*
* @return
*/
public static String getQuery(ParameterProvider... parameters) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < parameters.length; i++) {
ParameterProvider provider = parameters[i];
builder.append(provider.getQueryParameters());
if (i != parameters.length - 1) {
builder.append("&");
}
public static String getQuery(MeshRestClientConfig config, ParameterProvider... parameters) {
Map<String, String> params = new LinkedHashMap<>();
if (config != null) {
// get the default parameters from the configuration (if any)
ParameterProvider[] defaultParameters = config.getDefaultParameters();
// put all non-blank parameters to the map
Stream.of(defaultParameters).flatMap(provider -> provider.getParameters().entrySet().stream())
.filter(entry -> StringUtils.isNotBlank(entry.getKey()) && StringUtils.isNotBlank(entry.getValue()))
.forEach(entry -> params.put(entry.getKey(), entry.getValue()));
}
if (builder.length() > 0) {
return "?" + builder.toString();

// put all non-blank parameters from the given providers to the map
Stream.of(parameters).flatMap(provider -> provider.getParameters().entrySet().stream())
.filter(entry -> StringUtils.isNotBlank(entry.getKey()) && StringUtils.isNotBlank(entry.getValue()))
.forEach(entry -> params.put(entry.getKey(), entry.getValue()));

// combine all parameters to a query string
String query = params.entrySet().stream().map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())).collect(Collectors.joining("&"));
if (query.length() > 0) {
return "?" + query;
} else {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import org.apache.commons.io.IOUtils;

import com.gentics.mesh.parameter.ParameterProvider;

/**
* Gentics Mesh REST client configuration.
*/
Expand All @@ -27,6 +29,7 @@ public class MeshRestClientConfig {
private final boolean hostnameVerification;
private final int maxRetries;
private final int retryDelayMs;
private final ParameterProvider[] defaultParameters;

public MeshRestClientConfig(Builder builder) {
this.host = Objects.requireNonNull(builder.host);
Expand All @@ -41,6 +44,7 @@ public MeshRestClientConfig(Builder builder) {
this.clientKey = builder.clientKey;
this.maxRetries = builder.maxRetries;
this.retryDelayMs = builder.retryDelayMs;
this.defaultParameters = builder.defaultParameters;
}

/**
Expand Down Expand Up @@ -106,6 +110,10 @@ public int getRetryDelayMs() {
return retryDelayMs;
}

public ParameterProvider[] getDefaultParameters() {
return defaultParameters;
}

/**
* Create a fresh config builder.
*
Expand Down Expand Up @@ -135,6 +143,8 @@ public static class Builder {
// max call timeout.
private int retryDelayMs = -1;

private ParameterProvider[] defaultParameters = new ParameterProvider[0];

public Builder() {
trustedCAs = new HashSet<>();
}
Expand Down Expand Up @@ -401,6 +411,16 @@ public Builder setRetryDelayMs(int retryDelayMs) {
return this;
}

/**
* Set default parameters, which should be added to every request (unless overwritten)
* @param defaultParameters default parameters
* @return fluent API
*/
public Builder setDefaultParameters(ParameterProvider... defaultParameters) {
this.defaultParameters = defaultParameters;
return this;
}

private static byte[] readFile(String path) {
Objects.requireNonNull(path);
File keyFile = new File(path);
Expand Down
Loading

0 comments on commit 62a3ada

Please sign in to comment.