JexlSelector implements Selector { @Override public boolean evaluate(final VariableSource source) { return TRUE.equals(expression.evaluate(asJexlContext(source))); } JexlSelector(final JexlExpression expression); @Override boolean evaluate(final VariableSource source); @Override void toSql(final SelectorSqlBuilder sqlBuilder); @Override String toString(); static final String TYPE; }
@Test public void testComponentFormatHappy() { Selector selector = buildSelector("component.format == 'maven2'"); assertTrue(selector.evaluate(source)); }
@Test public void testComponentFormatSad() { Selector selector = buildSelector("component.format == 'nuget'"); assertFalse(selector.evaluate(source)); }
@Test public void testAssetNameHappy() { Selector selector = buildSelector("asset.name =~ '^jun.+'"); assertTrue(selector.evaluate(source)); }
@Test public void testAssetNameSad() { Selector selector = buildSelector("asset.name =~ '^jun.+' and asset.group =~ '^jun.+'"); assertFalse(selector.evaluate(source)); }
@Test public void testXHappy() { Selector selector = buildSelector("X == true and Y == false"); assertTrue(selector.evaluate(source)); }
@Test public void testStringToUppercase() { Selector selector = buildSelector("someString.toUpperCase() == 'FOOBAR'"); assertTrue(selector.evaluate(source)); }
@Test public void testMap() { Selector selector = buildSelector("someMap['a'] == 'alfa'"); assertTrue(selector.evaluate(source)); }
@Test(expected = JexlException.class) public void testNoConstructor() { Selector selector = buildSelector("new('" + JexlSelector.class.getName() + "', 'path = \\'/bar\\'')"); selector.evaluate(source); }
@Test(expected = JexlException.class) public void testMethodsBlocked() { Selector selector = buildSelector("writeableMap.put('foo', 'xxx')"); selector.evaluate(source); }
@Test(expected = JexlException.class) public void testWriteBlocked() { Selector selector = buildSelector("writeableObj.foo = 'xxx'"); selector.evaluate(source); }