private static String parseDelay(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx, final String delayInS) { final Pattern pattern = Pattern.compile("[a-z-_]", Pattern.CASE_INSENSITIVE); if(pattern.matcher(delayInS).find() && !delayInS.contains("{") && !delayInS.contains("}")){ visitor.readSupportedFunction(method.getName(), ctx); return MethodUtils.getVariableSyntax(delayInS)+"000"; } try { final String delayInMs = String.valueOf(Math.round(Double.parseDouble(delayInS) * 1000)); visitor.readSupportedFunction(method.getName(), ctx); return delayInMs; } catch (final NumberFormatException nfe) { final String warning = "A think time cannot be converted in milli seconds"; visitor.readSupportedFunctionWithWarn(method.getName(), ctx, warning); return delayInS + "000"; } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { final int size = visitor.getCurrentContainers().size(); if (size <= 1) { visitor.readSupportedFunctionWithWarn(method.getName(), ctx, "Cannot end non existing transaction."); return Collections.emptyList(); } final Object last = visitor.getCurrentContainers().get(size - 1); if(last instanceof ImmutableContainerForMulti.Builder){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, "Cannot end a transaction that has not be started in current block."); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of(LoadRunnerVUVisitor.toContainer(visitor.getCurrentContainers().remove(size - 1))); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { if (method == null) { return Collections.emptyList(); } if (method.getParameters() == null || method.getParameters().isEmpty()) { visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " must have a parameter."); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String firstParameter = method.getParameters().get(0); final String transactionName = MethodUtils.normalizeName(firstParameter); final ImmutableContainer.Builder currentContainer = ImmutableContainer.builder().name(transactionName); visitor.getCurrentContainers().add(currentContainer); return Collections.emptyList(); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size()!=1){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have a parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String arg0 = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); final List<String> args = ImmutableList.of(arg0); final String name = "atoi_" + counter.incrementAndGet(); return ImmutableList.of(ImmutableAtoi.builder().name(name).args(args).returnValue(MethodUtils.getVariableSyntax(name)).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size()!=2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have 2 parameters"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String s0 = method.getParameters().get(0); final String s1 = method.getParameters().get(1); final List<String> args = ImmutableList.of(s0, s1); final String name = "strcmp_" + counter.incrementAndGet(); return ImmutableList.of(ImmutableStrcmp.builder() .name(name) .args(args) .returnValue(MethodUtils.getVariableSyntax(name)) .build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size()!=2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have 2 parameters"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String variableValue = MethodUtils.unquote(method.getParameters().get(0)); final String variableName = MethodUtils.unquote(method.getParameters().get(1)); final String name = "Set variable " + MethodUtils.normalizeName(variableName); return ImmutableList.of(ImmutableSaveString.builder().name(name).variableName(variableName).variableValue(variableValue).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); Preconditions.checkNotNull(method.getParameters(), method.getName() + " method must have a parameter"); if(method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have a parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String returnValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); return ImmutableList.of(ImmutableEvalString.builder().name(MethodUtils.unquote(method.getName())).returnValue(returnValue).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size() < 4){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 4 parameters"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of( createUsername(method), createPassword(method), createClientNum(method), createLanguage(method), createPressEnter()); }
@Override public final List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { final WarningCallbBack warningCallback = new WarningCallbBack(); Preconditions.checkNotNull(method); try { final Builder extractBuilder = parseExtractor(visitor, method, warningCallback); visitor.getCurrentExtractors().add(extractBuilder.build()); } finally { if (warningCallback.isWarning()) { visitor.readSupportedFunctionWithWarn(method.getName(), ctx, warningCallback.getMessage()); } else { visitor.readSupportedFunction(method.getName(), ctx); } } return Collections.emptyList(); }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); Preconditions.checkNotNull(method.getParameters(), method.getName() + " method must have a parameter"); if(method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have a parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String returnValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); return ImmutableList.of(ImmutableEvalString.builder().name(MethodUtils.unquote(method.getName())).returnValue(returnValue).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size()<2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 2 parameters"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String variableName = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); final String format = method.getParameters().get(1); final List<String> args = new ArrayList<>(); for(int index = 2; index < method.getParameters().size(); index++){ args.add(MethodUtils.getVariableName(method.getParameters().get(index))); } return ImmutableList.of(ImmutableSprintf.builder().name(MethodUtils.unquote(method.getName())).variableName(variableName).format(format).args(args).build()); } }
@Override public final List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size() != 2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, METHOD + method.getName() + " should have 2 parameters: " + method.getName() + "(const char *Header, const char *Content)"); return Collections.emptyList(); } final String headerName = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); final String headerValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(1)); final Header header = ImmutableHeader.builder().headerName(headerName).headerValue(headerValue).build(); visitor.getGlobalHeaders().add(header); visitor.readSupportedFunction(method.getName(), ctx); return Collections.emptyList(); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 1 parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of(ImmutableSaveString.builder() .name(MethodUtils.unquote(method.getName())) .variableName(SAP_ACTIVE_SESSION) .variableValue(MethodUtils.unquote(method.getParameters().get(0))) .build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 1 parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of(ImmutableSaveString.builder() .name(MethodUtils.unquote(method.getName())) .variableName(SAP_ACTIVE_WINDOW) .variableValue(MethodUtils.unquote(method.getParameters().get(0))) .build()); } }
@Override public final List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size() != 2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, METHOD + method.getName() + " should have 2 parameters: " + method.getName() + "(const char *Header, const char *Content)"); return Collections.emptyList(); } final String headerName = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); final String headerValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(1)); final Header header = ImmutableHeader.builder().headerName(headerName).headerValue(headerValue).build(); visitor.getCurrentHeaders().add(header); visitor.readSupportedFunction(method.getName(), ctx); return Collections.emptyList(); } }
public static Page toElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); final ImmutablePage.Builder pageBuilder = ImmutablePage.builder(); final Optional<String> text = MethodUtils.getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, TEXT_PARAM); if(!text.isPresent()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, LoadRunnerMethod.METHOD + method.getName() + " should have a parameter " + TEXT_PARAM); return null; } visitor.readSupportedFunction(method.getName(), ctx); final String name = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); pageBuilder.addChilds(buildGetFollowLinkRequest(visitor, method, name, text.get())).isDynamic(true); return pageBuilder.name(name).thinkTime(0).build(); }
Preconditions.checkNotNull(method); if (method.getParameters() == null || method.getParameters().size() < 2) { visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 2 parameters"); return ImmutableList.of(); visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " has 2 not supported parameters, continuationOption: " + continuationOptionString + ", exitStatus: " + exitStatusString);
public static Page toElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); ImmutablePage.Builder pageBuilder = ImmutablePage.builder(); final PostRequest postRequest = buildRequest(visitor, method); if(postRequest == null) { visitor.readSupportedFunctionWithWarn(method.getName(), ctx, "There is not any body parameter for the following LR function"); return null; } visitor.readSupportedFunction(method.getName(), ctx); pageBuilder.addChilds(postRequest); // we use the request headers of the main request for the resources. final List<Header> recordedHeaders = getHeadersFromRecordedFile(postRequest.getRecordedFiles().flatMap(RecordedFiles::recordedRequestHeaderFile)); MethodUtils.extractItemListAsStringList(visitor, method.getParameters(), EXTRARES, Optional.of(pageBuilder)) .ifPresent(stringList -> getUrlList(stringList, getUrlFromMethodParameters(visitor.getLeftBrace(), visitor.getRightBrace(), method)) .forEach(url -> pageBuilder.addChilds(buildGetRequestFromURL(visitor, url, Optional.empty(), recordedHeaders)))); return pageBuilder.name(MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0))) .thinkTime(0) .build(); }
private Conditions readConditions(final SelectionstatementContext selectionstatementContext) { final ParseTree conditionTree = selectionstatementContext.getChild(2); final Element element = conditionTree.accept(new ConditionContextVisitor(visitor)); final Optional<String> conditionString = extractCondition(conditionTree); if(element == null){ visitor.readSupportedFunctionWithWarn(LR_METHOD_IF, selectionstatementContext.getParent(), "Condition not supported " + conditionString.orElse("")); } else { visitor.readSupportedFunction(LR_METHOD_IF, selectionstatementContext.getParent()); } final String operand1; if(element instanceof CustomAction){ operand1 = getVariableSyntax((CustomAction)element); } else { operand1 = extractBooleanCondition(conditionTree); } final Condition condition = ImmutableCondition.builder() .operand1(operand1) .operator(Condition.Operator.EQUALS) .operand2(conditionString.orElse("").startsWith("!") ? Boolean.FALSE.toString() : Boolean.TRUE.toString()) .build(); final ImmutableConditions.Builder conditionsBuilder = ImmutableConditions.builder(); conditionsBuilder.addConditions(condition); conditionsBuilder.description(conditionString); conditionsBuilder.matchType(Conditions.MatchType.ANY); return conditionsBuilder.build(); }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { final ImmutableMappingMethod methodMapping = visitor.getCustomActionMappingMethod(method.getName()); if (methodMapping == null) { visitor.readSupportedFunctionWithWarn(method.getName(), ctx, "Cannot find mapping for method " + method.getName()); return Collections.emptyList(); } final Set<Integer> readIndex = new HashSet<>(); final Builder builder = ImmutableCustomAction.builder(); builder.type(methodMapping.getType()); builder.isHit(methodMapping.isHit()); builder.name(MappingValueUtil.parseMappingValue(visitor, method.getParameters(), methodMapping.getName(), method.getName(), counter, readIndex)); methodMapping.getParameters().forEach(p -> { final ImmutableCustomActionParameter.Builder paramBuilder = ImmutableCustomActionParameter.builder(); paramBuilder.name(p.getName()); paramBuilder.value(MappingValueUtil.parseMappingValue(visitor, method.getParameters(), p.getValue(), method.getName(), counter, readIndex)); paramBuilder.type(p.getType()); builder.addParameters(paramBuilder.build()); }); final CustomAction customAction = builder.build(); readIndex.addAll(methodMapping.getIgnoreArgs()); final Set<String> unreadParameters = getUnreadParameters(method.getParameters(), readIndex); if(unreadParameters.isEmpty()){ visitor.readSupportedFunction(method.getName(), ctx); } else { visitor.readSupportedFunctionWithWarn(method.getName(), ctx, "Unread parameter: " + unreadParameters.toString()); } return ImmutableList.of(customAction); }