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 ""; } }
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) { 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()!=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()); } }