
io.ingenieux.lambada.testing.ImmutableLambadaContext Maven / Gradle / Ivy
package io.ingenieux.lambada.testing;
import com.amazonaws.services.lambda.runtime.ClientContext;
import com.amazonaws.services.lambda.runtime.CognitoIdentity;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Generated;
/**
* Immutable implementation of {@link LambadaContext}.
*
* Use the builder to create immutable instances:
* {@code ImmutableLambadaContext.builder()}.
*/
@SuppressWarnings("all")
@Generated({"Immutables.generator", "LambadaContext"})
public final class ImmutableLambadaContext implements LambadaContext {
private final String awsRequestId;
private final String logGroupName;
private final String logStreamName;
private final String functionName;
private final String functionVersion;
private final String invokedFunctionArn;
private final CognitoIdentity identity;
private final ClientContext clientContext;
private final int remainingTimeInMillis;
private final int memoryLimitInMB;
private final LambdaLogger logger;
private ImmutableLambadaContext(
String awsRequestId,
String logGroupName,
String logStreamName,
String functionName,
String functionVersion,
String invokedFunctionArn,
CognitoIdentity identity,
ClientContext clientContext,
int remainingTimeInMillis,
int memoryLimitInMB,
LambdaLogger logger) {
this.awsRequestId = awsRequestId;
this.logGroupName = logGroupName;
this.logStreamName = logStreamName;
this.functionName = functionName;
this.functionVersion = functionVersion;
this.invokedFunctionArn = invokedFunctionArn;
this.identity = identity;
this.clientContext = clientContext;
this.remainingTimeInMillis = remainingTimeInMillis;
this.memoryLimitInMB = memoryLimitInMB;
this.logger = logger;
}
/**
* @return The value of the {@code awsRequestId} attribute
*/
@Override
public String getAwsRequestId() {
return awsRequestId;
}
/**
* @return The value of the {@code logGroupName} attribute
*/
@Override
public String getLogGroupName() {
return logGroupName;
}
/**
* @return The value of the {@code logStreamName} attribute
*/
@Override
public String getLogStreamName() {
return logStreamName;
}
/**
* @return The value of the {@code functionName} attribute
*/
@Override
public String getFunctionName() {
return functionName;
}
/**
* @return The value of the {@code functionVersion} attribute
*/
@Override
public String getFunctionVersion() {
return functionVersion;
}
/**
* @return The value of the {@code invokedFunctionArn} attribute
*/
@Override
public String getInvokedFunctionArn() {
return invokedFunctionArn;
}
/**
* @return The value of the {@code identity} attribute
*/
@Override
public CognitoIdentity getIdentity() {
return identity;
}
/**
* @return The value of the {@code clientContext} attribute
*/
@Override
public ClientContext getClientContext() {
return clientContext;
}
/**
* @return The value of the {@code remainingTimeInMillis} attribute
*/
@Override
public int getRemainingTimeInMillis() {
return remainingTimeInMillis;
}
/**
* @return The value of the {@code memoryLimitInMB} attribute
*/
@Override
public int getMemoryLimitInMB() {
return memoryLimitInMB;
}
/**
* @return The value of the {@code logger} attribute
*/
@Override
public LambdaLogger getLogger() {
return logger;
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getAwsRequestId() awsRequestId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for awsRequestId
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withAwsRequestId(String value) {
if (this.awsRequestId.equals(value)) return this;
return new ImmutableLambadaContext(
Objects.requireNonNull(value, "awsRequestId"),
this.logGroupName,
this.logStreamName,
this.functionName,
this.functionVersion,
this.invokedFunctionArn,
this.identity,
this.clientContext,
this.remainingTimeInMillis,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getLogGroupName() logGroupName} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for logGroupName
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withLogGroupName(String value) {
if (this.logGroupName.equals(value)) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
Objects.requireNonNull(value, "logGroupName"),
this.logStreamName,
this.functionName,
this.functionVersion,
this.invokedFunctionArn,
this.identity,
this.clientContext,
this.remainingTimeInMillis,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getLogStreamName() logStreamName} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for logStreamName
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withLogStreamName(String value) {
if (this.logStreamName.equals(value)) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
Objects.requireNonNull(value, "logStreamName"),
this.functionName,
this.functionVersion,
this.invokedFunctionArn,
this.identity,
this.clientContext,
this.remainingTimeInMillis,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getFunctionName() functionName} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for functionName
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withFunctionName(String value) {
if (this.functionName.equals(value)) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
this.logStreamName,
Objects.requireNonNull(value, "functionName"),
this.functionVersion,
this.invokedFunctionArn,
this.identity,
this.clientContext,
this.remainingTimeInMillis,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getFunctionVersion() functionVersion} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for functionVersion
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withFunctionVersion(String value) {
if (this.functionVersion.equals(value)) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
this.logStreamName,
this.functionName,
Objects.requireNonNull(value, "functionVersion"),
this.invokedFunctionArn,
this.identity,
this.clientContext,
this.remainingTimeInMillis,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getInvokedFunctionArn() invokedFunctionArn} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for invokedFunctionArn
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withInvokedFunctionArn(String value) {
if (this.invokedFunctionArn.equals(value)) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
this.logStreamName,
this.functionName,
this.functionVersion,
Objects.requireNonNull(value, "invokedFunctionArn"),
this.identity,
this.clientContext,
this.remainingTimeInMillis,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getIdentity() identity} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for identity
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withIdentity(CognitoIdentity value) {
if (this.identity == value) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
this.logStreamName,
this.functionName,
this.functionVersion,
this.invokedFunctionArn,
Objects.requireNonNull(value, "identity"),
this.clientContext,
this.remainingTimeInMillis,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getClientContext() clientContext} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for clientContext
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withClientContext(ClientContext value) {
if (this.clientContext == value) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
this.logStreamName,
this.functionName,
this.functionVersion,
this.invokedFunctionArn,
this.identity,
Objects.requireNonNull(value, "clientContext"),
this.remainingTimeInMillis,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getRemainingTimeInMillis() remainingTimeInMillis} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for remainingTimeInMillis
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withRemainingTimeInMillis(int value) {
if (this.remainingTimeInMillis == value) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
this.logStreamName,
this.functionName,
this.functionVersion,
this.invokedFunctionArn,
this.identity,
this.clientContext,
value,
this.memoryLimitInMB,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getMemoryLimitInMB() memoryLimitInMB} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for memoryLimitInMB
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withMemoryLimitInMB(int value) {
if (this.memoryLimitInMB == value) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
this.logStreamName,
this.functionName,
this.functionVersion,
this.invokedFunctionArn,
this.identity,
this.clientContext,
this.remainingTimeInMillis,
value,
this.logger);
}
/**
* Copy the current immutable object by setting a value for the {@link LambadaContext#getLogger() logger} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for logger
* @return A modified copy of the {@code this} object
*/
public final ImmutableLambadaContext withLogger(LambdaLogger value) {
if (this.logger == value) return this;
return new ImmutableLambadaContext(
this.awsRequestId,
this.logGroupName,
this.logStreamName,
this.functionName,
this.functionVersion,
this.invokedFunctionArn,
this.identity,
this.clientContext,
this.remainingTimeInMillis,
this.memoryLimitInMB,
Objects.requireNonNull(value, "logger"));
}
/**
* This instance is equal to all instances of {@code ImmutableLambadaContext} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof ImmutableLambadaContext
&& equalTo((ImmutableLambadaContext) another);
}
private boolean equalTo(ImmutableLambadaContext another) {
return awsRequestId.equals(another.awsRequestId)
&& logGroupName.equals(another.logGroupName)
&& logStreamName.equals(another.logStreamName)
&& functionName.equals(another.functionName)
&& functionVersion.equals(another.functionVersion)
&& invokedFunctionArn.equals(another.invokedFunctionArn)
&& identity.equals(another.identity)
&& clientContext.equals(another.clientContext)
&& remainingTimeInMillis == another.remainingTimeInMillis
&& memoryLimitInMB == another.memoryLimitInMB
&& logger.equals(another.logger);
}
/**
* Computes a hash code from attributes: {@code awsRequestId}, {@code logGroupName}, {@code logStreamName}, {@code functionName}, {@code functionVersion}, {@code invokedFunctionArn}, {@code identity}, {@code clientContext}, {@code remainingTimeInMillis}, {@code memoryLimitInMB}, {@code logger}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + awsRequestId.hashCode();
h = h * 17 + logGroupName.hashCode();
h = h * 17 + logStreamName.hashCode();
h = h * 17 + functionName.hashCode();
h = h * 17 + functionVersion.hashCode();
h = h * 17 + invokedFunctionArn.hashCode();
h = h * 17 + identity.hashCode();
h = h * 17 + clientContext.hashCode();
h = h * 17 + remainingTimeInMillis;
h = h * 17 + memoryLimitInMB;
h = h * 17 + logger.hashCode();
return h;
}
/**
* Prints the immutable value {@code LambadaContext} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "LambadaContext{"
+ "awsRequestId=" + awsRequestId
+ ", logGroupName=" + logGroupName
+ ", logStreamName=" + logStreamName
+ ", functionName=" + functionName
+ ", functionVersion=" + functionVersion
+ ", invokedFunctionArn=" + invokedFunctionArn
+ ", identity=" + identity
+ ", clientContext=" + clientContext
+ ", remainingTimeInMillis=" + remainingTimeInMillis
+ ", memoryLimitInMB=" + memoryLimitInMB
+ ", logger=" + logger
+ "}";
}
/**
* Creates an immutable copy of a {@link LambadaContext} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance The instance to copy
* @return A copied immutable LambadaContext instance
*/
public static ImmutableLambadaContext copyOf(LambadaContext instance) {
if (instance instanceof ImmutableLambadaContext) {
return (ImmutableLambadaContext) instance;
}
return ImmutableLambadaContext.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableLambadaContext ImmutableLambadaContext}.
* @return A new ImmutableLambadaContext builder
*/
public static ImmutableLambadaContext.Builder builder() {
return new ImmutableLambadaContext.Builder();
}
/**
* Builds instances of type {@link ImmutableLambadaContext ImmutableLambadaContext}.
* Initialize attributes and then invoke the {@link #build()} method to create an
* immutable instance.
*
{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
* but instead used immediately to create instances.
*/
public static final class Builder {
private static final long INIT_BIT_AWS_REQUEST_ID = 0x1L;
private static final long INIT_BIT_LOG_GROUP_NAME = 0x2L;
private static final long INIT_BIT_LOG_STREAM_NAME = 0x4L;
private static final long INIT_BIT_FUNCTION_NAME = 0x8L;
private static final long INIT_BIT_FUNCTION_VERSION = 0x10L;
private static final long INIT_BIT_INVOKED_FUNCTION_ARN = 0x20L;
private static final long INIT_BIT_IDENTITY = 0x40L;
private static final long INIT_BIT_CLIENT_CONTEXT = 0x80L;
private static final long INIT_BIT_REMAINING_TIME_IN_MILLIS = 0x100L;
private static final long INIT_BIT_MEMORY_LIMIT_IN_M_B = 0x200L;
private static final long INIT_BIT_LOGGER = 0x400L;
private long initBits = 0x7ff;
private String awsRequestId;
private String logGroupName;
private String logStreamName;
private String functionName;
private String functionVersion;
private String invokedFunctionArn;
private CognitoIdentity identity;
private ClientContext clientContext;
private int remainingTimeInMillis;
private int memoryLimitInMB;
private LambdaLogger logger;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.amazonaws.services.lambda.runtime.Context} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(Context instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code io.ingenieux.lambada.testing.LambadaContext} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(LambadaContext instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof Context) {
Context instance = (Context) object;
clientContext(instance.getClientContext());
logGroupName(instance.getLogGroupName());
functionVersion(instance.getFunctionVersion());
functionName(instance.getFunctionName());
memoryLimitInMB(instance.getMemoryLimitInMB());
awsRequestId(instance.getAwsRequestId());
logStreamName(instance.getLogStreamName());
identity(instance.getIdentity());
logger(instance.getLogger());
invokedFunctionArn(instance.getInvokedFunctionArn());
remainingTimeInMillis(instance.getRemainingTimeInMillis());
}
}
/**
* Initializes the value for the {@link LambadaContext#getAwsRequestId() awsRequestId} attribute.
* @param awsRequestId The value for awsRequestId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder awsRequestId(String awsRequestId) {
this.awsRequestId = Objects.requireNonNull(awsRequestId, "awsRequestId");
initBits &= ~INIT_BIT_AWS_REQUEST_ID;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getLogGroupName() logGroupName} attribute.
* @param logGroupName The value for logGroupName
* @return {@code this} builder for use in a chained invocation
*/
public final Builder logGroupName(String logGroupName) {
this.logGroupName = Objects.requireNonNull(logGroupName, "logGroupName");
initBits &= ~INIT_BIT_LOG_GROUP_NAME;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getLogStreamName() logStreamName} attribute.
* @param logStreamName The value for logStreamName
* @return {@code this} builder for use in a chained invocation
*/
public final Builder logStreamName(String logStreamName) {
this.logStreamName = Objects.requireNonNull(logStreamName, "logStreamName");
initBits &= ~INIT_BIT_LOG_STREAM_NAME;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getFunctionName() functionName} attribute.
* @param functionName The value for functionName
* @return {@code this} builder for use in a chained invocation
*/
public final Builder functionName(String functionName) {
this.functionName = Objects.requireNonNull(functionName, "functionName");
initBits &= ~INIT_BIT_FUNCTION_NAME;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getFunctionVersion() functionVersion} attribute.
* @param functionVersion The value for functionVersion
* @return {@code this} builder for use in a chained invocation
*/
public final Builder functionVersion(String functionVersion) {
this.functionVersion = Objects.requireNonNull(functionVersion, "functionVersion");
initBits &= ~INIT_BIT_FUNCTION_VERSION;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getInvokedFunctionArn() invokedFunctionArn} attribute.
* @param invokedFunctionArn The value for invokedFunctionArn
* @return {@code this} builder for use in a chained invocation
*/
public final Builder invokedFunctionArn(String invokedFunctionArn) {
this.invokedFunctionArn = Objects.requireNonNull(invokedFunctionArn, "invokedFunctionArn");
initBits &= ~INIT_BIT_INVOKED_FUNCTION_ARN;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getIdentity() identity} attribute.
* @param identity The value for identity
* @return {@code this} builder for use in a chained invocation
*/
public final Builder identity(CognitoIdentity identity) {
this.identity = Objects.requireNonNull(identity, "identity");
initBits &= ~INIT_BIT_IDENTITY;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getClientContext() clientContext} attribute.
* @param clientContext The value for clientContext
* @return {@code this} builder for use in a chained invocation
*/
public final Builder clientContext(ClientContext clientContext) {
this.clientContext = Objects.requireNonNull(clientContext, "clientContext");
initBits &= ~INIT_BIT_CLIENT_CONTEXT;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getRemainingTimeInMillis() remainingTimeInMillis} attribute.
* @param remainingTimeInMillis The value for remainingTimeInMillis
* @return {@code this} builder for use in a chained invocation
*/
public final Builder remainingTimeInMillis(int remainingTimeInMillis) {
this.remainingTimeInMillis = remainingTimeInMillis;
initBits &= ~INIT_BIT_REMAINING_TIME_IN_MILLIS;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getMemoryLimitInMB() memoryLimitInMB} attribute.
* @param memoryLimitInMB The value for memoryLimitInMB
* @return {@code this} builder for use in a chained invocation
*/
public final Builder memoryLimitInMB(int memoryLimitInMB) {
this.memoryLimitInMB = memoryLimitInMB;
initBits &= ~INIT_BIT_MEMORY_LIMIT_IN_M_B;
return this;
}
/**
* Initializes the value for the {@link LambadaContext#getLogger() logger} attribute.
* @param logger The value for logger
* @return {@code this} builder for use in a chained invocation
*/
public final Builder logger(LambdaLogger logger) {
this.logger = Objects.requireNonNull(logger, "logger");
initBits &= ~INIT_BIT_LOGGER;
return this;
}
/**
* Builds a new {@link ImmutableLambadaContext ImmutableLambadaContext}.
* @return An immutable instance of LambadaContext
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableLambadaContext build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableLambadaContext(
awsRequestId,
logGroupName,
logStreamName,
functionName,
functionVersion,
invokedFunctionArn,
identity,
clientContext,
remainingTimeInMillis,
memoryLimitInMB,
logger);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_AWS_REQUEST_ID) != 0) attributes.add("awsRequestId");
if ((initBits & INIT_BIT_LOG_GROUP_NAME) != 0) attributes.add("logGroupName");
if ((initBits & INIT_BIT_LOG_STREAM_NAME) != 0) attributes.add("logStreamName");
if ((initBits & INIT_BIT_FUNCTION_NAME) != 0) attributes.add("functionName");
if ((initBits & INIT_BIT_FUNCTION_VERSION) != 0) attributes.add("functionVersion");
if ((initBits & INIT_BIT_INVOKED_FUNCTION_ARN) != 0) attributes.add("invokedFunctionArn");
if ((initBits & INIT_BIT_IDENTITY) != 0) attributes.add("identity");
if ((initBits & INIT_BIT_CLIENT_CONTEXT) != 0) attributes.add("clientContext");
if ((initBits & INIT_BIT_REMAINING_TIME_IN_MILLIS) != 0) attributes.add("remainingTimeInMillis");
if ((initBits & INIT_BIT_MEMORY_LIMIT_IN_M_B) != 0) attributes.add("memoryLimitInMB");
if ((initBits & INIT_BIT_LOGGER) != 0) attributes.add("logger");
return "Cannot build LambadaContext, some of required attributes are not set " + attributes;
}
}
}