io.gatling.javaapi.http.HttpDsl Maven / Gradle / Ivy
/*
* Copyright 2011-2023 GatlingCorp (https://gatling.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gatling.javaapi.http;
import static io.gatling.javaapi.core.internal.Expressions.*;
import io.gatling.commons.validation.Validation;
import io.gatling.core.action.builder.SessionHookBuilder;
import io.gatling.javaapi.core.ActionBuilder;
import io.gatling.javaapi.core.CheckBuilder;
import io.gatling.javaapi.core.FeederBuilder;
import io.gatling.javaapi.core.Session;
import io.gatling.javaapi.http.internal.HttpCheckBuilder;
import io.gatling.javaapi.http.internal.HttpCheckBuilders;
import io.gatling.javaapi.http.internal.HttpCheckType;
import java.util.function.Function;
import javax.annotation.Nonnull;
import scala.Function1;
/** The entrypoint of the Gatling HTTP DSL */
public final class HttpDsl {
private HttpDsl() {}
////////// HttpDsl
/** Bootstrap a HTTP protocol configuration */
public static final HttpProtocolBuilder http =
new HttpProtocolBuilder(
io.gatling.http.protocol.HttpProtocolBuilder.apply(
io.gatling.core.Predef.configuration()));
/**
* Bootstrap a HTTP request configuration
*
* @param name the HTTP request name, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static Http http(@Nonnull String name) {
return new Http(toStringExpression(name));
}
/**
* Bootstrap a HTTP request configuration
*
* @param name the HTTP request name, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static Http http(@Nonnull Function name) {
return new Http(javaFunctionToExpression(name));
}
/**
* Bootstrap a WebSocket request configuration
*
* @param name the WebSocket request name, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static Ws ws(@Nonnull String name) {
return new Ws(io.gatling.http.action.ws.Ws.apply(toStringExpression(name)));
}
/**
* Bootstrap a WebSocket request configuration
*
* @param name the WebSocket request name, expressed as a Gatling Expression Language String
* @param wsName the name of the WebSocket so multiple WebSockets for the same virtual users don't
* conflict, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static Ws ws(@Nonnull String name, @Nonnull String wsName) {
return new Ws(
io.gatling.http.action.ws.Ws.apply(toStringExpression(name), toStringExpression(wsName)));
}
public static final Ws.Prefix ws = Ws.Prefix.INSTANCE;
/**
* Bootstrap a SSE request
* configuration
*
* @param name the SSE request name, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static Sse sse(@Nonnull String name) {
return new Sse(io.gatling.http.action.sse.Sse.apply(toStringExpression(name)));
}
/**
* Bootstrap a SSE request
* configuration
*
* @param name the SSE request name, expressed as a Gatling Expression Language String
* @param sseName the name of the SSE stream so multiple SSE streams for the same virtual users
* don't conflict, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static Sse sse(@Nonnull String name, @Nonnull String sseName) {
return new Sse(
io.gatling.http.action.sse.Sse.apply(
toStringExpression(name), toStringExpression(sseName)));
}
/** The prefix to bootstrap SSE specific DSL */
public static final Sse.Prefix sse = Sse.Prefix.INSTANCE;
/** The prefix to bootstrap polling specific DSL */
public static Polling poll() {
return Polling.DEFAULT;
}
////////// HttpCheckSupport
/**
* Bootstrap a check that capture the response HTTP status code
*
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.Find status() {
return HttpCheckBuilders.status();
}
/**
* Bootstrap a check that capture the response location, eg the landing url in a chain of
* redirects
*
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.Find currentLocation() {
return new CheckBuilder.Find.Default<>(
io.gatling.http.Predef.currentLocation(),
HttpCheckType.CurrentLocation,
String.class,
null);
}
/**
* Bootstrap a check that capture some Java Regular
* Expression capture groups on the response location, eg the landing url in a chain of
* redirects
*
* @param pattern the regular expression, expressed as a Gatling Expression Language String
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.CaptureGroupCheckBuilder currentLocationRegex(
@Nonnull String pattern) {
return new HttpCheckBuilder.CurrentLocationRegex(
io.gatling.http.Predef.currentLocationRegex(
toStringExpression(pattern), io.gatling.core.Predef.defaultPatterns()));
}
/**
* Bootstrap a check that capture some Java Regular
* Expression capture groups on the response location, eg the landing url in a chain of
* redirects
*
* @param pattern the regular expression, expressed as a function
* @return the next step in the check DSL
*/
@Nonnull
public static HttpCheckBuilder.CurrentLocationRegex currentLocationRegex(
@Nonnull Function pattern) {
return new HttpCheckBuilder.CurrentLocationRegex(
io.gatling.http.Predef.currentLocationRegex(
javaFunctionToExpression(pattern), io.gatling.core.Predef.defaultPatterns()));
}
/**
* Bootstrap a check that capture the value of a HTTP header
*
* @param name the static name of the HTTP header
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.MultipleFind header(@Nonnull CharSequence name) {
return new CheckBuilder.MultipleFind.Default<>(
io.gatling.http.Predef.header(toStaticValueExpression(name)),
HttpCheckType.Header,
String.class,
null);
}
/**
* Bootstrap a check that capture the value of a HTTP header
*
* @param name the name of the HTTP header, expressed as a Gatling Expression Language String
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.MultipleFind header(@Nonnull String name) {
return new CheckBuilder.MultipleFind.Default<>(
io.gatling.http.Predef.header(toExpression(name, CharSequence.class)),
HttpCheckType.Header,
String.class,
null);
}
/**
* Bootstrap a check that capture the value of a HTTP header
*
* @param name the name of the HTTP header, expressed as a function
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.MultipleFind header(
@Nonnull Function name) {
return new CheckBuilder.MultipleFind.Default<>(
io.gatling.http.Predef.header(javaFunctionToExpression(name)),
HttpCheckType.Header,
String.class,
null);
}
/**
* Bootstrap a check that capture some Java Regular
* Expression capture groups on a response header
*
* @param name the static name of the HTTP header
* @param pattern the regular expression, expressed as a Gatling Expression Language String
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.CaptureGroupCheckBuilder headerRegex(
CharSequence name, String pattern) {
return new HttpCheckBuilder.HeaderRegexCheck(
io.gatling.http.Predef.headerRegex(
toStaticValueExpression(name),
toStringExpression(pattern),
io.gatling.core.Predef.defaultPatterns()));
}
/**
* Bootstrap a check that capture some Java Regular
* Expression capture groups on a response header
*
* @param name the name of the HTTP header, expressed as a Gatling Expression Language String
* @param pattern the regular expression, expressed as a Gatling Expression Language String
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.CaptureGroupCheckBuilder headerRegex(
@Nonnull String name, @Nonnull String pattern) {
return new HttpCheckBuilder.HeaderRegexCheck(
io.gatling.http.Predef.headerRegex(
toExpression(name, CharSequence.class),
toStringExpression(pattern),
io.gatling.core.Predef.defaultPatterns()));
}
/**
* Bootstrap a check that capture some Java Regular
* Expression capture groups on a response header
*
* @param name the name of the HTTP header, expressed as a function
* @param pattern the regular expression, expressed as a Gatling Expression Language String
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.CaptureGroupCheckBuilder headerRegex(
@Nonnull Function name, @Nonnull String pattern) {
return new HttpCheckBuilder.HeaderRegexCheck(
io.gatling.http.Predef.headerRegex(
javaFunctionToExpression(name),
toStringExpression(pattern),
io.gatling.core.Predef.defaultPatterns()));
}
/**
* Bootstrap a check that capture some Java Regular
* Expression capture groups on a response header
*
* @param name the static name of the HTTP header
* @param pattern the regular expression, expressed as a function
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.CaptureGroupCheckBuilder headerRegex(
@Nonnull CharSequence name, @Nonnull Function pattern) {
return new HttpCheckBuilder.HeaderRegexCheck(
io.gatling.http.Predef.headerRegex(
toStaticValueExpression(name),
javaFunctionToExpression(pattern),
io.gatling.core.Predef.defaultPatterns()));
}
/**
* Bootstrap a check that capture some Java Regular
* Expression capture groups on a response header
*
* @param name the name of the HTTP header, expressed as a Gatling Expression Language String
* @param pattern the regular expression, expressed as a function
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.CaptureGroupCheckBuilder headerRegex(
@Nonnull String name, @Nonnull Function pattern) {
return new HttpCheckBuilder.HeaderRegexCheck(
io.gatling.http.Predef.headerRegex(
toExpression(name, CharSequence.class),
javaFunctionToExpression(pattern),
io.gatling.core.Predef.defaultPatterns()));
}
/**
* Bootstrap a check that capture some Java Regular
* Expression capture groups on a response header
*
* @param name the name of the HTTP header, expressed as a function
* @param pattern the regular expression, expressed as a function
* @return the next step in the check DSL
*/
@Nonnull
public static CheckBuilder.CaptureGroupCheckBuilder headerRegex(
@Nonnull Function name, @Nonnull Function pattern) {
return new HttpCheckBuilder.HeaderRegexCheck(
io.gatling.http.Predef.headerRegex(
javaFunctionToExpression(name),
javaFunctionToExpression(pattern),
io.gatling.core.Predef.defaultPatterns()));
}
////////// SitemapFeederSupport
/**
* Bootstrap a feeder that reads from a sitemap XML file
*
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static FeederBuilder.FileBased sitemap(@Nonnull String filePath) {
return new FeederBuilder.Impl<>(
io.gatling.http.Predef.sitemap(filePath, io.gatling.core.Predef.configuration()));
}
////////// BodyPartSupport
/**
* Bootstrap a {@link BodyPart} backed by a file whose text context will be interpreted as a
* Gatling Expression Language String. The name of the part is equal to the file name.
*
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart ElFileBodyPart(@Nonnull String filePath) {
return ElFileBodyPart(toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file whose text context will be interpreted as a
* Gatling Expression Language String The name of the part is equal to the file name.
*
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart ElFileBodyPart(@Nonnull Function filePath) {
return ElFileBodyPart(javaFunctionToExpression(filePath));
}
private static BodyPart ElFileBodyPart(
@Nonnull Function1> filePath) {
return new BodyPart(
io.gatling.http.Predef.ElFileBodyPart(
filePath,
io.gatling.core.Predef.configuration(),
io.gatling.core.Predef.elFileBodies()));
}
/**
* Bootstrap a {@link BodyPart} backed by a file whose text context will be interpreted as a
* Gatling Expression Language String.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart ElFileBodyPart(@Nonnull String name, @Nonnull String filePath) {
return ElFileBodyPart(toStringExpression(name), toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file whose text context will be interpreted as a
* Gatling Expression Language String.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart ElFileBodyPart(
@Nonnull String name, @Nonnull Function filePath) {
return ElFileBodyPart(toStringExpression(name), javaFunctionToExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file whose text context will be interpreted as a
* Gatling Expression Language String.
*
* @param name the name of the part, expressed as a function
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart ElFileBodyPart(
@Nonnull Function name, @Nonnull String filePath) {
return ElFileBodyPart(javaFunctionToExpression(name), toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file whose text context will be interpreted as a
* Gatling Expression Language String.
*
* @param name the name of the part, expressed as a function
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart ElFileBodyPart(
@Nonnull Function name, @Nonnull Function filePath) {
return ElFileBodyPart(javaFunctionToExpression(name), javaFunctionToExpression(filePath));
}
private static BodyPart ElFileBodyPart(
@Nonnull Function1> name,
@Nonnull Function1> filePath) {
return new BodyPart(
io.gatling.http.Predef.ElFileBodyPart(
name,
filePath,
io.gatling.core.Predef.configuration(),
io.gatling.core.Predef.elFileBodies()));
}
/**
* Bootstrap a {@link BodyPart} backed by a String
*
* @param string the string, interpreted as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart StringBodyPart(@Nonnull String string) {
return new BodyPart(
io.gatling.http.Predef.StringBodyPart(
toStringExpression(string), io.gatling.core.Predef.configuration()));
}
/**
* Bootstrap a {@link BodyPart} backed by a String
*
* @param string the string, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart StringBodyPart(@Nonnull Function string) {
return ElFileBodyPart(javaFunctionToExpression(string));
}
/**
* Bootstrap a {@link BodyPart} backed by a String
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param string the string, interpreted as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart StringBodyPart(@Nonnull String name, @Nonnull String string) {
return StringBodyPart(toStringExpression(name), toStringExpression(string));
}
/**
* Bootstrap a {@link BodyPart} backed by a String
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param string the string, interpreted as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart StringBodyPart(
@Nonnull String name, @Nonnull Function string) {
return StringBodyPart(toStringExpression(name), javaFunctionToExpression(string));
}
/**
* Bootstrap a {@link BodyPart} backed by a String
*
* @param name the name of the part, expressed as a function
* @param string the string, interpreted as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart StringBodyPart(
@Nonnull Function name, @Nonnull String string) {
return StringBodyPart(javaFunctionToExpression(name), toStringExpression(string));
}
/**
* Bootstrap a {@link BodyPart} backed by a String
*
* @param name the name of the part, expressed as a function
* @param string the string, interpreted as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart StringBodyPart(
@Nonnull Function name, @Nonnull Function string) {
return StringBodyPart(javaFunctionToExpression(name), javaFunctionToExpression(string));
}
private static BodyPart StringBodyPart(
Function1> name,
Function1> string) {
return new BodyPart(
io.gatling.http.Predef.StringBodyPart(
name, string, io.gatling.core.Predef.configuration()));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose bytes will be sent as is. The name of the
* part is equal to the name of the file.
*
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart RawFileBodyPart(@Nonnull String filePath) {
return RawFileBodyPart(toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose bytes will be sent as is. The name of the
* part is equal to the name of the file.
*
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart RawFileBodyPart(@Nonnull Function filePath) {
return RawFileBodyPart(javaFunctionToExpression(filePath));
}
private static BodyPart RawFileBodyPart(
Function1> filePath) {
return new BodyPart(
io.gatling.http.Predef.RawFileBodyPart(filePath, io.gatling.core.Predef.rawFileBodies()));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose bytes will be sent as is.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart RawFileBodyPart(@Nonnull String name, @Nonnull String filePath) {
return RawFileBodyPart(toStringExpression(name), toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose bytes will be sent as is.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart RawFileBodyPart(
@Nonnull String name, @Nonnull Function filePath) {
return RawFileBodyPart(toStringExpression(name), javaFunctionToExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose bytes will be sent as is.
*
* @param name the name of the part, expressed as a function
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart RawFileBodyPart(
@Nonnull Function name, @Nonnull String filePath) {
return RawFileBodyPart(javaFunctionToExpression(name), toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose bytes will be sent as is.
*
* @param name the name of the part, expressed as a function
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart RawFileBodyPart(
@Nonnull Function name, @Nonnull Function filePath) {
return RawFileBodyPart(javaFunctionToExpression(name), javaFunctionToExpression(filePath));
}
private static BodyPart RawFileBodyPart(
Function1> name,
Function1> filePath) {
return new BodyPart(
io.gatling.http.Predef.RawFileBodyPart(
name, filePath, io.gatling.core.Predef.rawFileBodies()));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose content is interpreted as a Pebble template. The name of the part is equal to the
* name of the file.
*
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleFileBodyPart(@Nonnull String filePath) {
return PebbleFileBodyPart(toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose content is interpreted as a Pebble template. The name of the part is equal to the
* name of the file.
*
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleFileBodyPart(@Nonnull Function filePath) {
return PebbleFileBodyPart(javaFunctionToExpression(filePath));
}
private static BodyPart PebbleFileBodyPart(
Function1> filePath) {
return new BodyPart(
io.gatling.http.Predef.PebbleFileBodyPart(
filePath,
io.gatling.core.Predef.configuration(),
io.gatling.core.Predef.pebbleFileBodies()));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose content is interpreted as a Pebble template.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleFileBodyPart(@Nonnull String name, @Nonnull String filePath) {
return PebbleFileBodyPart(toStringExpression(name), toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose content is interpreted as a Pebble template.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleFileBodyPart(
@Nonnull String name, @Nonnull Function filePath) {
return PebbleFileBodyPart(toStringExpression(name), javaFunctionToExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose content is interpreted as a Pebble template.
*
* @param name the name of the part, expressed as a function
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleFileBodyPart(
@Nonnull Function name, @Nonnull String filePath) {
return PebbleFileBodyPart(javaFunctionToExpression(name), toStringExpression(filePath));
}
/**
* Bootstrap a {@link BodyPart} backed by a file, whose content is interpreted as a Pebble template.
*
* @param name the name of the part, expressed as a function
* @param filePath the path of the file, either relative to the root of the classpath, or
* absolute, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleFileBodyPart(
@Nonnull Function name, @Nonnull Function filePath) {
return PebbleFileBodyPart(javaFunctionToExpression(name), javaFunctionToExpression(filePath));
}
private static BodyPart PebbleFileBodyPart(
Function1> name,
Function1> filePath) {
return new BodyPart(
io.gatling.http.Predef.PebbleFileBodyPart(
name,
filePath,
io.gatling.core.Predef.configuration(),
io.gatling.core.Predef.pebbleFileBodies()));
}
/**
* Bootstrap a {@link BodyPart} backed by a String, whose content is interpreted as a Pebble template.
*
* @param string the Pebble String template
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleStringBodyPart(@Nonnull String string) {
return new BodyPart(
io.gatling.http.Predef.PebbleStringBodyPart(
string, io.gatling.core.Predef.configuration()));
}
/**
* Bootstrap a {@link BodyPart} backed by a String, whose content is interpreted as a Pebble template.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param string the Pebble String template
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleStringBodyPart(@Nonnull String name, @Nonnull String string) {
return PebbleStringBodyPart(toStringExpression(name), string);
}
/**
* Bootstrap a {@link BodyPart} backed by a String, whose content is interpreted as a Pebble template.
*
* @param name the name of the part, expressed as a function
* @param string the Pebble String template
* @return the next DSL step
*/
@Nonnull
public static BodyPart PebbleStringBodyPart(
@Nonnull Function name, @Nonnull String string) {
return PebbleStringBodyPart(javaFunctionToExpression(name), string);
}
private static BodyPart PebbleStringBodyPart(
Function1> name, String string) {
return new BodyPart(
io.gatling.http.Predef.PebbleStringBodyPart(
name, string, io.gatling.core.Predef.configuration()));
}
/**
* Bootstrap a {@link BodyPart} backed by a byte array. Bytes are sent as is.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param bytes the static bytes
* @return the next DSL step
*/
@Nonnull
public static BodyPart ByteArrayBodyPart(@Nonnull String name, @Nonnull byte[] bytes) {
return ByteArrayBodyPart(toStringExpression(name), toStaticValueExpression(bytes));
}
/**
* Bootstrap a {@link BodyPart} backed by a byte array. Bytes are sent as is.
*
* @param name the name of the part, expressed as a function
* @param bytes the static bytes
* @return the next DSL step
*/
@Nonnull
public static BodyPart ByteArrayBodyPart(
@Nonnull Function name, @Nonnull byte[] bytes) {
return ByteArrayBodyPart(javaFunctionToExpression(name), toStaticValueExpression(bytes));
}
/**
* Bootstrap a {@link BodyPart} backed by a byte array. Bytes are sent as is.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param bytes the bytes, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart ByteArrayBodyPart(@Nonnull String name, @Nonnull String bytes) {
return ByteArrayBodyPart(toStringExpression(name), toBytesExpression(bytes));
}
/**
* Bootstrap a {@link BodyPart} backed by a byte array. Bytes are sent as is.
*
* @param name the name of the part, expressed as a function
* @param bytes the bytes, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static BodyPart ByteArrayBodyPart(
@Nonnull Function name, @Nonnull String bytes) {
return ByteArrayBodyPart(javaFunctionToExpression(name), toBytesExpression(bytes));
}
/**
* Bootstrap a {@link BodyPart} backed by a byte array. Bytes are sent as is.
*
* @param name the name of the part, expressed as a Gatling Expression Language String
* @param bytes the bytes, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart ByteArrayBodyPart(
@Nonnull String name, @Nonnull Function bytes) {
return ByteArrayBodyPart(toStringExpression(name), javaFunctionToExpression(bytes));
}
/**
* Bootstrap a {@link BodyPart} backed by a byte array. Bytes are sent as is.
*
* @param name the name of the part, expressed as a function
* @param bytes the bytes, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static BodyPart ByteArrayBodyPart(
@Nonnull Function name, @Nonnull Function bytes) {
return ByteArrayBodyPart(javaFunctionToExpression(name), javaFunctionToExpression(bytes));
}
private static BodyPart ByteArrayBodyPart(
Function1> name,
Function1> bytes) {
return new BodyPart(io.gatling.http.Predef.ByteArrayBodyPart(name, bytes));
}
////////// CookieSupport
/**
* Create an action to add a Cookie
*
* @param cookie the DSL for adding a cookie
* @return an ActionBuilder
*/
@Nonnull
public static ActionBuilder addCookie(@Nonnull AddCookie cookie) {
return () -> io.gatling.http.action.cookie.AddCookieBuilder.apply(cookie.asScala());
}
/**
* Create an action to get a Cookie value into the Session
*
* @param cookie the DSL for getting a cookie
* @return an ActionBuilder
*/
@Nonnull
public static ActionBuilder getCookieValue(@Nonnull GetCookie cookie) {
return () -> io.gatling.http.action.cookie.GetCookieBuilder.apply(cookie.asScala());
}
/**
* Create an action to flush the Session (non-persistent) Cookies of the user
*
* @return an ActionBuilder
*/
@Nonnull
public static ActionBuilder flushSessionCookies() {
return () -> new SessionHookBuilder(io.gatling.http.Predef.flushSessionCookies(), true);
}
/**
* Create an action to flush all the Cookies of the user
*
* @return an ActionBuilder
*/
@Nonnull
public static ActionBuilder flushCookieJar() {
return () -> new SessionHookBuilder(io.gatling.http.Predef.flushCookieJar(), true);
}
/**
* Create an action to flush the HTTP cache of the user
*
* @return an ActionBuilder
*/
@Nonnull
public static ActionBuilder flushHttpCache() {
return () -> new SessionHookBuilder(io.gatling.http.Predef.flushHttpCache(), true);
}
/**
* Bootstrap the DSL for defining a Cookie to add
*
* @param name the name of the cookie, expressed as a Gatling Expression Language String
* @param value the value of the cookie, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static AddCookie Cookie(@Nonnull String name, @Nonnull String value) {
return new AddCookie(
io.gatling.http.Predef.Cookie(toStringExpression(name), toStringExpression(value)));
}
/**
* Bootstrap the DSL for defining a Cookie to add
*
* @param name the name of the cookie, expressed as a function
* @param value the value of the cookie, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static AddCookie Cookie(@Nonnull Function name, @Nonnull String value) {
return new AddCookie(
io.gatling.http.Predef.Cookie(javaFunctionToExpression(name), toStringExpression(value)));
}
/**
* Bootstrap the DSL for defining a Cookie to add
*
* @param name the name of the cookie, expressed as a Gatling Expression Language String
* @param value the value of the cookie, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static AddCookie Cookie(@Nonnull String name, @Nonnull Function value) {
return new AddCookie(
io.gatling.http.Predef.Cookie(toStringExpression(name), javaFunctionToExpression(value)));
}
/**
* Bootstrap the DSL for defining a Cookie to add
*
* @param name the name of the cookie, expressed as a function
* @param value the value of the cookie, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static AddCookie Cookie(
@Nonnull Function name, @Nonnull Function value) {
return new AddCookie(
io.gatling.http.Predef.Cookie(
javaFunctionToExpression(name), javaFunctionToExpression(value)));
}
/**
* Bootstrap the DSL for defining a Cookie to get
*
* @param name the name of the cookie, expressed as a Gatling Expression Language String
* @return the next DSL step
*/
@Nonnull
public static GetCookie CookieKey(@Nonnull String name) {
return new GetCookie(io.gatling.http.Predef.CookieKey(toStringExpression(name)));
}
/**
* Bootstrap the DSL for defining a Cookie to get
*
* @param name the name of the cookie, expressed as a function
* @return the next DSL step
*/
@Nonnull
public static GetCookie CookieKey(@Nonnull Function name) {
return new GetCookie(io.gatling.http.Predef.CookieKey(javaFunctionToExpression(name)));
}
////////// ProxySupport
/**
* Bootstrap the DSL for defining a Proxy
*
* @param host the proxy host
* @param port the proxy prot
* @return the next DSL step
*/
@Nonnull
public static Proxy Proxy(@Nonnull String host, int port) {
return new Proxy(io.gatling.http.Predef.Proxy(host, port));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy