public String getMessage() { return message.getExpressionString(); } }
public String getMessage() { return description.getExpressionString(); }
public String getMessage() { return message.getExpressionString(); }
public String getDescription() { return description.getExpressionString(); }
public String getDescription() { return description.getExpressionString(); }
public String getMessage() { return message.getExpressionString(); }
@Override public String toString() { return authorizeExpression.getExpressionString(); } }
public static boolean evaluateAsBoolean(Expression expr, EvaluationContext ctx) { try { return ((Boolean) expr.getValue(ctx, Boolean.class)).booleanValue(); } catch (EvaluationException e) { throw new IllegalArgumentException("Failed to evaluate expression '" + expr.getExpressionString() + "'", e); } } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); Expression authorize = getAuthorizeExpression(); Expression filter = getFilterExpression(); sb.append("[authorize: '").append( authorize == null ? "null" : authorize.getExpressionString()); sb.append("', filter: '") .append(filter == null ? "null" : filter.getExpressionString()) .append("']"); return sb.toString(); } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); Expression authorize = getAuthorizeExpression(); Expression filter = getFilterExpression(); sb.append("[authorize: '").append( authorize == null ? "null" : authorize.getExpressionString()); sb.append("', filter: '").append( filter == null ? "null" : filter.getExpressionString()); sb.append("', filterTarget: '").append(filterTarget).append("']"); return sb.toString(); } }
/** * Output an indented representation of the expression syntax tree to the specified output stream. * @param printStream the output stream to print into * @param expression the expression to be displayed */ public static void printAbstractSyntaxTree(PrintStream printStream, Expression expression) { printStream.println("===> Expression '" + expression.getExpressionString() + "' - AST start"); printAST(printStream, ((SpelExpression) expression).getAST(), ""); printStream.println("===> Expression '" + expression.getExpressionString() + "' - AST end"); }
@Test public void toStringUsesExpressionString() { when(expression.getExpressionString()).thenReturn("toString"); assertThat(attribute.toString()).isEqualTo(expression.getExpressionString()); } }
@Test public void methodWithPreFilterOnlyIsAllowed() { ConfigAttribute[] attrs = mds.getAttributes(voidImpl3).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("permitAll"); assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("somePreFilterExpression"); }
@Test public void mixedClassAndMethodPreAnnotationsAreBothIncluded() { ConfigAttribute[] attrs = mds.getAttributes(voidImpl2).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression"); assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("somePreFilterExpression"); }
@Test public void methodWithPostFilterOnlyIsAllowed() { ConfigAttribute[] attrs = mds.getAttributes(listImpl1).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(2); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); assertThat(attrs[1] instanceof PostInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; PostInvocationExpressionAttribute post = (PostInvocationExpressionAttribute) attrs[1]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("permitAll"); assertThat(post.getFilterExpression()).isNotNull(); assertThat(post.getFilterExpression().getExpressionString()).isEqualTo("somePostFilterExpression"); }
@Test public void interfaceAttributesAreIncluded() { ConfigAttribute[] attrs = mds.getAttributes(notherListImpl1).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("interfaceMethodAuthzExpression"); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("interfacePreFilterExpression"); }
@Test public void classAttributesTakesPrecedeceOverInterfaceAttributes() { ConfigAttribute[] attrs = mds.getAttributes(notherListImpl2).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("interfaceMethodAuthzExpression"); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("classMethodPreFilterExpression"); }
@Test public void classLevelPreAnnotationIsPickedUpWhenNoMethodLevelExists() throws Exception { ConfigAttribute[] attrs = mds.getAttributes(voidImpl1).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression"); assertThat(pre.getFilterExpression()).isNull(); }
@Test public void proxyFactoryInterfaceAttributesFound() throws Exception { MockMethodInvocation mi = MethodInvocationFactory.createSec2150MethodInvocation(); Collection<ConfigAttribute> attributes = mds.getAttributes(mi); assertThat(attributes).hasSize(1); Expression expression = (Expression) ReflectionTestUtils.getField(attributes .iterator().next(), "authorizeExpression"); assertThat(expression.getExpressionString()).isEqualTo("hasRole('ROLE_PERSON')"); }
Expression[] exprs = cse.getExpressions(); assertEquals(3,exprs.length); assertEquals("listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1]==3]",exprs[1].getExpressionString()); s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class); assertEquals("hello world",s);