protected static List<Item> parseItemList(final List<String> attributes) { final List<Item> items = new ArrayList<>(); final Item item = new Item(); attributes.stream().forEach(attribute -> { if("ENDITEM".equals(attribute)){ addItem(items,item); } else { item.getAttributes().add(unescape(unquote(attribute))); } }); return items; }
protected static String normalizeVariables(final String leftBrace, final String rightBrace, final String param) { if(param.startsWith(NL_VARIABLE_START) && param.endsWith(NL_VARIABLE_END)){ return param; } final Matcher m = getVariablePatternWithBrace(leftBrace, rightBrace).matcher(param); final StringBuilder sb = new StringBuilder(); int lastIndex = 0; while (m.find()) { String paramName = param.substring(m.start() + leftBrace.length(), m.end() - rightBrace.length()); sb.append(param.substring(lastIndex, m.start())).append(NL_VARIABLE_START).append(getCorrespondingVariableNameForNL(paramName)).append(NL_VARIABLE_END); lastIndex = m.end(); } if (lastIndex == 0) { return param; } return sb.append(param.substring(lastIndex)).toString(); }
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(); } }
public static Optional<String> getParameterValueWithName(final String leftBrace, final String rightBrace, MethodCall method, String name) { Optional<String> parameter = getParameterWithName(method, name); return parameter.map(param -> MethodUtils.normalizeString(leftBrace, rightBrace, param)).map(s -> s.substring((name+"=").length())); }
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(); } }
@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 byte[] extractBinaryBody(final String leftBrace, final String rightBrace, final MethodCall method) { return hexStringToByteArray(MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, "BodyBinary").orElse("")); }
if (MethodUtils.getParameterWithName(method, "Body").isPresent()) { final ImmutablePostTextRequest.Builder builder = ImmutablePostTextRequest.builder() .name(mainUrl.getPath()) .server(visitor.getReader().getServer(mainUrl)) .httpMethod(getMethod(visitor.getLeftBrace(), visitor.getRightBrace(), method)) .contentType(MethodUtils.getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, "EncType")) .data(MethodUtils.getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, "Body").get()) .addAllExtractors(visitor.getCurrentExtractors()) .addAllValidators(visitor.getCurrentValidators()) .addAllHeaders(visitor.getGlobalHeaders()) .addAllHeaders(recordedHeaders) .addAllParameters(MethodUtils.queryToParameterList(mainUrl.getQuery())) .recordedFiles(recordedFiles); visitor.getCurrentHeaders().clear(); return builder.build(); if(MethodUtils.getParameterWithName(method, "BodyBinary").isPresent()) { final ImmutablePostBinaryRequest.Builder builder = ImmutablePostBinaryRequest.builder() .name(mainUrl.getPath()) .server(visitor.getReader().getServer(mainUrl)) .httpMethod(getMethod(visitor.getLeftBrace(), visitor.getRightBrace(), method)) .contentType(MethodUtils.getParameterValueWithName(visitor.getLeftBrace(), visitor.getRightBrace(), method, "EncType")) .binaryData(extractBinaryBody(visitor.getLeftBrace(), visitor.getRightBrace(), method)) .addAllExtractors(visitor.getCurrentExtractors()) .addAllHeaders(visitor.getGlobalHeaders())
/** * Find the url in the LR function and parse it to an URL Object * @param method represent the LR function * @param urlTag tag used to find the correct keywords in the function (also used for parsing) */ @VisibleForTesting protected static URL getUrlFromMethodParameters(final String leftBrace, final String rightBrace, MethodCall method, String urlTag) { Optional<String> urlParam = MethodUtils.getParameterWithName(method, urlTag); try { String urlString = MethodUtils.unquote(urlParam.orElseThrow(IllegalArgumentException::new)); //the +1 is for the "=" that follows the url tag return getUrlFromParameterString(leftBrace, rightBrace, urlString.substring(urlTag.length()+1)); }catch (IllegalArgumentException e) { LOGGER.error("Cannot find URL in WebUrl Node:"+method.getName() + "\nThe error is : " + e); } return null; }
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 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()); } }
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(); }
/** * * @param method represent the LR "web_submit_data" function * @return the associate POST_REQUEST */ public static PostRequest buildPostFormRequest(final LoadRunnerVUVisitor visitor, final MethodCall method) { final URL mainUrl = Preconditions.checkNotNull(getUrl(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)); final ImmutablePostFormRequest.Builder requestBuilder = ImmutablePostFormRequest.builder() .name(mainUrl.getPath()) .path(mainUrl.getPath()) .server(visitor.getReader().getServer(mainUrl)) .httpMethod(getMethod(visitor.getLeftBrace(), visitor.getRightBrace(), method)) .recordedFiles(recordedFiles); getContentType(snapshotProperties).ifPresent(requestBuilder::contentType); requestBuilder.addAllExtractors(visitor.getCurrentExtractors()); requestBuilder.addAllValidators(visitor.getCurrentValidators()); requestBuilder.addAllHeaders(visitor.getCurrentHeaders()); visitor.getCurrentHeaders().clear(); requestBuilder.addAllHeaders(visitor.getGlobalHeaders()); requestBuilder.addAllHeaders(recordedHeaders); MethodUtils.extractItemListAsStringList(visitor, method.getParameters(), ITEMDATA, Optional.empty()) .ifPresent(stringList -> buildPostParamsFromExtract(stringList).forEach(requestBuilder::addPostParameters)); MethodUtils.queryToParameterList(mainUrl.getQuery()).forEach(requestBuilder::addParameters); return requestBuilder.build(); }
private static String getVariableSyntax(final CustomAction customAction) { for(final CustomActionParameter parameter : customAction.getParameters()){ if(CUSTOM_ACTION_VARIABLE_PARAMETER.equals(parameter.getName())){ return MethodUtils.getVariableSyntax(parameter.getValue()); } } return ""; } }
protected static Optional<String> getParameterWithName(MethodCall method, String name) { return getParameterStartingWith(method, name+"="); }
/** * Generate an immutable request of type Submit form */ @VisibleForTesting protected static PostSubmitFormRequest buildPostSubmitFormRequest(final LoadRunnerVUVisitor visitor, final MethodCall method, final String name) { final Optional<Properties> snapshotProperties = getSnapshotProperties(visitor, method); final Optional<RecordedFiles> recordedFiles = getRecordedFilesFromSnapshotProperties(visitor, snapshotProperties); final List<Header> recordedHeaders = getHeadersFromRecordedFile(recordedFiles.flatMap(RecordedFiles::recordedRequestHeaderFile)); final ImmutablePostSubmitFormRequest.Builder requestBuilder = ImmutablePostSubmitFormRequest.builder() .name(name) .path(name) .httpMethod(Request.HttpMethod.POST) .recordedFiles(recordedFiles); getContentType(snapshotProperties).ifPresent(requestBuilder::contentType); requestBuilder.addAllExtractors(visitor.getCurrentExtractors()); requestBuilder.addAllValidators(visitor.getCurrentValidators()); requestBuilder.addAllHeaders(visitor.getCurrentHeaders()); visitor.getCurrentHeaders().clear(); requestBuilder.addAllHeaders(visitor.getGlobalHeaders()); requestBuilder.addAllHeaders(recordedHeaders); visitor.getCurrentRequest().ifPresent(requestBuilder::referer); visitor.getCurrentRequest().ifPresent(cr -> requestBuilder.server(cr.getServer())); requestBuilder.path(buildExtractorPath(snapshotProperties)); MethodUtils.extractItemListAsStringList(visitor, method.getParameters(), ITEMDATA, Optional.empty()) .ifPresent(stringList -> buildPostParamsFromExtract(stringList).forEach(requestBuilder::addPostParameters)); return requestBuilder.build(); }
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 SearchAttribute handleSearch(final MethodCall method, final WarningCallbBack warningCallback, final String leftBrace, final String rightBrace) { final SearchAttribute searchAttribute = SearchAttribute.from( MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, ATTRIBUTE_SEARCH).orElse(MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, ATTRIBUTE_SCOPE).orElse(ATTRIBUTE_VALUE_ALL))); if (searchAttribute == SearchAttribute.COOKIES) { logWarn("The option \"Search=Cookies\" is not supported in NeoLoad. The extractor type has been set to \"Headers\".", warningCallback); } else if (searchAttribute == SearchAttribute.NORESOURCE) { logWarn("The option \"Search=Noresource\" is not supported in NeoLoad. The extractor type has been set to \"Body\".", warningCallback); } return searchAttribute; }
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"; } }
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(); }