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 ImmutableRegexpValidator ImmutableRegexpValidator}. * @return An immutable instance of RegexpValidator * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableRegexpValidator build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableRegexpValidator(validationRegex, 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 RegexpValidator} 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 RegexpValidator instance */ public static ImmutableRegexpValidator copyOf(RegexpValidator instance) { if (instance instanceof ImmutableRegexpValidator) { return (ImmutableRegexpValidator) instance; } return ImmutableRegexpValidator.builder() .from(instance) .build(); }
private void from(Object object) { if (object instanceof Validator) { Validator instance = (Validator) object; name(instance.getName()); haveToContains(instance.getHaveToContains()); } if (object instanceof RegexpValidator) { RegexpValidator instance = (RegexpValidator) object; validationRegex(instance.getValidationRegex()); } }
/** * Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.RegexpValidator} 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(RegexpValidator instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; }
/** * Creates a builder for {@link ImmutableRegexpValidator ImmutableRegexpValidator}. * @return A new ImmutableRegexpValidator builder */ public static ImmutableRegexpValidator.Builder builder() { return new ImmutableRegexpValidator.Builder(); }