protected static Optional<Properties> getSnapshotProperties(final LoadRunnerVUVisitor visitor, final MethodCall method) { final String snapshotFileName = getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, "Snapshot").orElse(""); if (isNullOrEmpty(snapshotFileName)) { return Optional.empty(); } try{ final Properties properties = new Properties(); properties.load(newInputStream(visitor.getReader().getCurrentScriptDataFolder().resolve(snapshotFileName))); return Optional.of(properties); } catch (final IOException e) { LOGGER.warn("Cannot find snapshot properties files: ", e); } return Optional.empty(); }
@Override public List<Element> getElement(LoadRunnerVUVisitor visitor, MethodCall method, CPP14Parser.MethodcallContext ctx) { visitor.readSupportedFunction(method.getName(), ctx); visitor.getCurrentValidators().add(WebRegFind.toValidator(visitor.getLeftBrace(), visitor.getRightBrace(), method)); return Collections.emptyList(); }
/** * extract the EXTRARES or ITEMDATA part from a web url method * @param parameters the parameters to extract the items from. * @return a List of elements between the typeListName and the end boundary */ protected static Optional<List<String>> extractItemListAsStringList(final LoadRunnerVUVisitor visitor, List<String> parameters, final ITEM_BOUNDARY typeListName, final Optional<ImmutablePage.Builder> pageBuilder) { final boolean containsTypeListName = parameters.contains(typeListName.toString()); pageBuilder.ifPresent(p -> p.isDynamic(!containsTypeListName)); if(!containsTypeListName) { return Optional.empty(); } // split the list to get only the part after the "typeListName" final List<String> result = parameters.subList(parameters.indexOf(typeListName.toString())+1, parameters.size()) .stream().map(param -> MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), param)).collect(Collectors.toList()); // compute last index (end boundaries can be EXTRARES, ITEMDATA, LAST) final MutableInt boundaryIndex = new MutableInt(result.size()); ImmutableList.copyOf(ITEM_BOUNDARY.values()).forEach(itemBoundary -> boundaryIndex.setValue(result.indexOf(itemBoundary.toString())>=0 ? Math.min(boundaryIndex.intValue(), result.indexOf(itemBoundary.toString())) : boundaryIndex)); return Optional.of(result.subList(0, boundaryIndex.getValue())); }
public static Page toElement(final LoadRunnerVUVisitor visitor, final MethodCall method) { Preconditions.checkNotNull(method); ImmutablePage.Builder pageBuilder = ImmutablePage.builder(); final URL mainUrl = Preconditions.checkNotNull(getUrlFromMethodParameters(visitor.getLeftBrace(), visitor.getRightBrace(), method)); final Optional<Properties> snapshotProperties = getSnapshotProperties(visitor, method); final Optional<RecordedFiles> recordedFiles = getRecordedFilesFromSnapshotProperties(visitor, snapshotProperties); final List<Header> recordedHeaders = getHeadersFromRecordedFile(recordedFiles.flatMap(RecordedFiles::recordedRequestHeaderFile)); pageBuilder.addChilds(buildGetRequestFromURL(visitor, mainUrl, recordedFiles, recordedHeaders)); MethodUtils.extractItemListAsStringList(visitor, method.getParameters(), EXTRARES, Optional.of(pageBuilder)).ifPresent(stringList -> pageBuilder.addAllChilds(getUrlList(stringList, mainUrl).stream().map(url -> WebRequest.buildGetRequestFromURL(visitor, url, Optional.empty(), recordedHeaders)).collect(Collectors.toList()))); return pageBuilder.name(MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0))) .thinkTime(0) .build(); } }
private void handleRegExp(final LoadRunnerVUVisitor visitor, final MethodCall method, final WarningCallbBack warningCallback, final Builder extractBuilder) { if (supportRegExp()) { final Optional<String> regExp = MethodUtils.getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, ATTRIBUTE_REGEXP); if (regExp.isPresent()) { extractBuilder.regExp(regExp.get()); } else { logWarn(LOG_THE_ATTRIBUTE + ATTRIBUTE_REGEXP + LOG_IS_MANDATORY + method.getName(), warningCallback); extractBuilder.regExp(DEFAULT_REGEXP_VALUE); } final Optional<String> group = MethodUtils.getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, ATTRIBUTE_GROUP); if (group.isPresent()) { extractBuilder.group(group.get()); } } }
public static Page toElement(final LoadRunnerVUVisitor visitor, final MethodCall method) { Preconditions.checkNotNull(method); ImmutablePage.Builder pageBuilder = ImmutablePage.builder(); final PostRequest postRequest = buildPostFormRequest(visitor, method); 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, getUrl(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 void handleLBRB(final LoadRunnerVUVisitor visitor, final MethodCall method, final Builder extractBuilder) { if (supportLBRB()) { final String startExpression = MethodUtils.getValueAndVerifyRestrictionForBoundary(visitor.getLeftBrace(), visitor.getRightBrace(), method, MethodUtils.getParameterStartingWith(method, ATTRIBUTE_LB)); final String endExpression = MethodUtils.getValueAndVerifyRestrictionForBoundary(visitor.getLeftBrace(), visitor.getRightBrace(), method, MethodUtils.getParameterStartingWith(method, ATTRIBUTE_RB)); extractBuilder.startExpression(startExpression).endExpression(endExpression); } }
@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().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 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(); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); visitor.readUnsupportedFunction(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()); } }
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(); }
@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); 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()); } }
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(); }
public static Page toElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); final ImmutablePage.Builder pageBuilder = ImmutablePage.builder(); visitor.readSupportedFunction(method.getName(), ctx); final String name = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); pageBuilder.addChilds(buildPostSubmitFormRequest(visitor, method, name)).isDynamic(true); return pageBuilder.name(name).thinkTime(0).build(); } }
private void handleXPath(final LoadRunnerVUVisitor visitor, final MethodCall method, final WarningCallbBack warningCallback, final Builder extractBuilder, final SearchAttribute searchAttribute) { if (supportXPath()) { final Optional<String> xpath = MethodUtils.getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, ATTRIBUTE_QUERYSTRING); if (xpath.isPresent()) { extractBuilder.xPath(xpath.get()); extractBuilder.extractType(ExtractType.XPATH); if(searchAttribute != SearchAttribute.BODY){ logWarn(LOG_THE_ATTRIBUTE + ATTRIBUTE_QUERYSTRING + "\" requires to have a Search attribute with " + SearchAttribute.BODY + " instead of " + searchAttribute.toString(), warningCallback); } } else { logWarn(LOG_THE_ATTRIBUTE + ATTRIBUTE_QUERYSTRING + LOG_IS_MANDATORY + method.getName(), warningCallback); extractBuilder.xPath(""); } } }
final Builder parseExtractor(final LoadRunnerVUVisitor visitor, final MethodCall method, final WarningCallbBack warningCallback) { final String leftBrace = visitor.getLeftBrace(); final String rightBrace = visitor.getRightBrace(); String extractorName = MethodUtils.normalizeString(leftBrace, rightBrace, method.getParameters().get(0)); if (extractorName.startsWith(PARAM_NAME_PREFIX)) { extractorName = extractorName.substring(PARAM_NAME_PREFIX.length()); } final Builder extractBuilder = ImmutableVariableExtractor.builder().name(extractorName); final SearchAttribute searchAttribute = handleSearch(method, warningCallback, leftBrace, rightBrace); extractBuilder.extractType(searchAttribute.getExtractType()); handleLBRB(visitor, method, extractBuilder); handleRegExp(visitor, method, warningCallback, extractBuilder); handleXPath(visitor, method, warningCallback, extractBuilder, searchAttribute); handleJsonPath(visitor, method, warningCallback, extractBuilder, searchAttribute); handleNotFound(method, warningCallback, leftBrace, rightBrace, extractBuilder); logUnsupportedAttributes(method, warningCallback, leftBrace, rightBrace); handleOrd(method, warningCallback, leftBrace, rightBrace, extractBuilder); return extractBuilder; }
private void handleJsonPath(final LoadRunnerVUVisitor visitor, final MethodCall method, final WarningCallbBack warningCallback, final Builder extractBuilder, final SearchAttribute searchAttribute) { if (supportJsonPath()) { final Optional<String> jsonPath = MethodUtils.getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, ATTRIBUTE_QUERYSTRING); if (jsonPath.isPresent()) { extractBuilder.jsonPath(jsonPath.get()); extractBuilder.extractType(ExtractType.JSON); if(searchAttribute != SearchAttribute.BODY){ logWarn(LOG_THE_ATTRIBUTE + ATTRIBUTE_QUERYSTRING + "\" requires to have a Search attribute with " + SearchAttribute.BODY + " instead of " + searchAttribute.toString(), warningCallback); } } else { logWarn(LOG_THE_ATTRIBUTE + ATTRIBUTE_QUERYSTRING + LOG_IS_MANDATORY + method.getName(), warningCallback); extractBuilder.jsonPath(""); } } }