org.apache.el.ExpressionFactoryImpl Java Examples

The following examples show how to use org.apache.el.ExpressionFactoryImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestStandardTestChooser.java    From proctor with Apache License 2.0 6 votes vote down vote up
@Before
public void setupMocks() throws Exception {
    expressionFactory = new ExpressionFactoryImpl();
    functionMapper = RuleEvaluator.FUNCTION_MAPPER;
    testName = "testName";
    testDefinition = new ConsumableTestDefinition();
    testDefinition.setConstants(Collections.<String, Object>emptyMap());
    testDefinition.setTestType(TestType.AUTHENTICATED_USER);
    // most tests just set the salt to be the same as the test name
    testDefinition.setSalt(testName);
    testDefinition.setBuckets(INACTIVE_CONTROL_TEST_BUCKETS);

    updateAllocations(RANGES_50_50);

    final int effBuckets = INACTIVE_CONTROL_TEST_BUCKETS.size() - 1;
    counts = new int[effBuckets];
    hashes = new int[effBuckets];
}
 
Example #2
Source File: TestRandomTestChooser.java    From proctor with Apache License 2.0 6 votes vote down vote up
static RandomTestChooser initializeRandomTestChooser(final List<Range> ranges, final List<TestBucket> buckets) {
    final ExpressionFactory expressionFactory = new ExpressionFactoryImpl();

    final FunctionMapper functionMapper = RuleEvaluator.FUNCTION_MAPPER;

    final ConsumableTestDefinition testDefinition = new ConsumableTestDefinition();
    testDefinition.setConstants(Collections.emptyMap());

    testDefinition.setBuckets(buckets);

    final List<Allocation> allocations = Lists.newArrayList();
    allocations.add(new Allocation("${}", ranges, "#A1"));
    testDefinition.setAllocations(allocations);

    final RandomTestChooser rtc = new RandomTestChooser(expressionFactory, functionMapper, "testName", testDefinition);
    return rtc;
}
 
Example #3
Source File: TestAttributeParser.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private String evalAttr(String expression, char quote) {

        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ELContextImpl ctx = new ELContextImpl(exprFactory);
        ctx.setFunctionMapper(new TesterFunctions.FMapper());
        ValueExpression ve = exprFactory.createValueExpression(ctx,
                AttributeParser.getUnquoted(expression, quote, false, false,
                        false, false),
                String.class);
        return (String) ve.getValue(ctx);
    }
 
Example #4
Source File: TestAttributeParser.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private String evalAttr(String expression, char quote) {

        ELContextImpl ctx = new ELContextImpl();
        ctx.setFunctionMapper(new FMapper());
        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ValueExpression ve = exprFactory.createValueExpression(ctx,
                AttributeParser.getUnquoted(expression, quote, false, false,
                        false, false),
                String.class);
        return (String) ve.getValue(ctx);
    }
 
Example #5
Source File: TestAttributeParser.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private String evalAttr(String expression, char quote) {

        ELContextImpl ctx = new ELContextImpl();
        ctx.setFunctionMapper(new FMapper());
        ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
        ValueExpression ve = exprFactory.createValueExpression(ctx,
                AttributeParser.getUnquoted(expression, quote, false, false,
                        false, false),
                String.class);
        return (String) ve.getValue(ctx);
    }
 
Example #6
Source File: BenchmarkEl.java    From proctor with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args) {
    final FunctionMapper functionMapper = new LibraryFunctionMapperBuilder().add("proctor", ProctorRuleFunctions.class).build();

    final ExpressionFactory expressionFactory = new ExpressionFactoryImpl();

    final CompositeELResolver elResolver = new CompositeELResolver();
    elResolver.add(new ArrayELResolver());
    elResolver.add(new ListELResolver());
    elResolver.add(new BeanELResolver());
    elResolver.add(new MapELResolver());

    final Map<String, Object> values = Maps.newLinkedHashMap();
    values.put("countries", Sets.newHashSet("AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "JJ", "KK", "LL", "MM"));
    values.put("AA", "AA");
    values.put("CC", "CC");
    values.put("NN", "NN");
    values.put("ZZ", "ZZ");
    values.put("I1", 239235);
    values.put("I2", 569071142);
    values.put("I3", -189245);
    values.put("D1", 129835.12512);
    values.put("D2", -9582.9385);
    values.put("D3", 98982223.598731412);
    values.put("BT", Boolean.TRUE);
    values.put("BF", Boolean.FALSE);
    values.put("GLOOP", "");

    final String[] expressions = {
            "${proctor:contains(countries, AA) || proctor:contains(countries, CC) || D2 < I3 && BF}",
            "${! proctor:contains(countries, ZZ) && I1 < I2 && empty GLOOP}",
            "${I2 - I3 + D3 - D1}",
            "${NN == '0' && ZZ == 'ZZ'}",
            "${BT != BF}",
    };

    final int iterations = 100*1000;
    long elapsed = -System.currentTimeMillis();
    for (int i = 0; i < iterations; i++) {
        final Map<String, ValueExpression> localContext = ProctorUtils.convertToValueExpressionMap(expressionFactory, values);
        final VariableMapper variableMapper = new MulticontextReadOnlyVariableMapper(localContext);

        final ELContext elContext = new ELContext() {
            @Override
            public ELResolver getELResolver() {
                return elResolver;
            }

            @Override
            public FunctionMapper getFunctionMapper() {
                return functionMapper;
            }

            @Override
            public VariableMapper getVariableMapper() {
                return variableMapper;
            }
        };

        for (int j = 0; j < expressions.length; j++) {
            final ValueExpression ve = expressionFactory.createValueExpression(elContext, expressions[j], Object.class);
            final Object result = ve.getValue(elContext);
            if (i % 10000 == 0) {
                System.out.println(result);
            }
        }
    }
    elapsed += System.currentTimeMillis();

    final int total = iterations * expressions.length;
    System.out.println(total + " expressions in " + elapsed + " ms (average " + (elapsed/(((double) total))) + " ms/expression)");
}