public static Validator toValidator(final String leftBrace, final String rightBrace, final MethodCall method) { Preconditions.checkNotNull(method); MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "Search").ifPresent(value -> { if ("Headers".equals(value) || "Body".equals(value)) logger.error("The value \"" + value + "\" for the \"Search\" option has not been taken under account for the LR function with name : " + method.getName()); }); MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "SaveCount").ifPresent(value -> logger.warn( "The option \"" + value + "\" for the the LR function with name \"" + method.getName() + "\" has not been taken under account")); Optional<String> textPfx = MethodUtils.getParameterStartingWith(method, "TextPfx"); if (textPfx.isPresent()) { String prefix = MethodUtils.getValueAndVerifyRestrictionForBoundary(leftBrace, rightBrace, method, textPfx); String suffix = MethodUtils.getValueAndVerifyRestrictionForBoundary(leftBrace, rightBrace, method, MethodUtils.getParameterStartingWith(method, "TextSfx")); String regex = "\\Q" + prefix + "\\E.*\\Q" + suffix + "\\E"; return ImmutableRegexpValidator.builder().name(method.getName() + "_" + Integer.toString(currentID++)).haveToContains( NOTFOUND.equals(MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "Fail").orElse( NOTFOUND))).validationRegex(regex).build(); } String exactMatch = MethodUtils.getValueAndVerifyRestrictionForBoundary(leftBrace, rightBrace, method, MethodUtils.getParameterStartingWith(method, "Text")); return ImmutableTextValidator.builder().name(method.getName() + "_" + Integer.toString(currentID++)).haveToContains(NOTFOUND.equals( MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "Fail").orElse(NOTFOUND))).validationText( exactMatch).build(); } }
/** * Builds a new {@link ImmutableTextValidator ImmutableTextValidator}. * @return An immutable instance of TextValidator * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableTextValidator build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableTextValidator(validationText, name, haveToContains); }
/** * Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.Validator} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Validator instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; }
/** * Creates an immutable copy of a {@link TextValidator} 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 TextValidator instance */ public static ImmutableTextValidator copyOf(TextValidator instance) { if (instance instanceof ImmutableTextValidator) { return (ImmutableTextValidator) instance; } return ImmutableTextValidator.builder() .from(instance) .build(); }
/** * Creates a builder for {@link ImmutableTextValidator ImmutableTextValidator}. * @return A new ImmutableTextValidator builder */ public static ImmutableTextValidator.Builder builder() { return new ImmutableTextValidator.Builder(); }
/** * Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.TextValidator} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(TextValidator instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; }
private void from(Object object) { if (object instanceof TextValidator) { TextValidator instance = (TextValidator) object; validationText(instance.getValidationText()); } if (object instanceof Validator) { Validator instance = (Validator) object; name(instance.getName()); haveToContains(instance.getHaveToContains()); } }