DATACMNS-1108 - Polishing.
Move loop to Set lookup, update Javadoc and remove unused imports. Original Pull Request: #454
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.data.spel;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.expression.spel.SpelNode;
|
||||
import org.springframework.expression.spel.standard.SpelExpression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
@@ -27,6 +26,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
* Unit tests for {@link ExpressionDependencies}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class ExpressionDependenciesUnitTests {
|
||||
|
||||
@@ -74,6 +74,20 @@ class ExpressionDependenciesUnitTests {
|
||||
"principal");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1108
|
||||
void shouldExtractAll() {
|
||||
|
||||
String expression = "hello().hasRole(principal.emailAddress, principal.somethingElse).somethingElse()";
|
||||
|
||||
SpelExpression spelExpression = (SpelExpression) PARSER.parseExpression(expression);
|
||||
SpelNode ast = spelExpression.getAST();
|
||||
|
||||
ExpressionDependencies dependencies = ExpressionDependencies.discover(ast, false);
|
||||
|
||||
assertThat(dependencies).extracting(ExpressionDependencies.ExpressionDependency::getSymbol).containsOnly("hello",
|
||||
"hasRole", "principal", "emailAddress", "somethingElse");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1108
|
||||
void shouldMergeDependencies() {
|
||||
|
||||
|
||||
@@ -21,12 +21,10 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.data.spel.spi.EvaluationContextExtension;
|
||||
import org.springframework.data.spel.spi.ReactiveEvaluationContextExtension;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -37,6 +35,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
* Unit tests for {@link ReactiveExtensionAwareEvaluationContextProvider}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class ReactiveExtensionAwareEvaluationContextProviderUnitTests {
|
||||
|
||||
@@ -108,7 +107,7 @@ class ReactiveExtensionAwareEvaluationContextProviderUnitTests {
|
||||
ExpressionDependencies dependencies = ExpressionDependencies.discover(expression);
|
||||
|
||||
ReactiveExtensionAwareEvaluationContextProvider provider = new ReactiveExtensionAwareEvaluationContextProvider(
|
||||
Collections.singletonList(GenericReactiveExtension.INSTANCE));
|
||||
Arrays.asList(SampleReactiveExtension.INSTANCE, GenericReactiveExtension.INSTANCE));
|
||||
|
||||
provider.getEvaluationContextLater(new Object[0], dependencies).map(expression::getValue) //
|
||||
.as(StepVerifier::create) //
|
||||
@@ -116,6 +115,58 @@ class ReactiveExtensionAwareEvaluationContextProviderUnitTests {
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(GenericModelRoot.creationCounter).hasValue(1);
|
||||
assertThat(SecurityExpressionRoot.creationCounter).hasValue(0);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1108
|
||||
void doesNotLoadExtensionForDirectCall() {
|
||||
|
||||
Expression expression = PARSER.parseExpression(
|
||||
"T(org.springframework.data.spel.ReactiveExtensionAwareEvaluationContextProviderUnitTests.WithStaticRole).hasRole('ADMIN')");
|
||||
ExpressionDependencies dependencies = ExpressionDependencies.discover(expression);
|
||||
|
||||
ReactiveExtensionAwareEvaluationContextProvider provider = new ReactiveExtensionAwareEvaluationContextProvider(
|
||||
Arrays.asList(SampleReactiveExtension.INSTANCE, GenericReactiveExtension.INSTANCE));
|
||||
|
||||
provider.getEvaluationContextLater(new Object[0], dependencies).map(expression::getValue) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(GenericModelRoot.creationCounter).hasValue(1);
|
||||
assertThat(SecurityExpressionRoot.creationCounter).hasValue(0);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1108
|
||||
void loadsExtensionEvenWhenRootObjectMethodMatches() {
|
||||
|
||||
Expression expression = PARSER.parseExpression("principal.name");
|
||||
ExpressionDependencies dependencies = ExpressionDependencies.discover(expression);
|
||||
|
||||
ReactiveExtensionAwareEvaluationContextProvider provider = new ReactiveExtensionAwareEvaluationContextProvider(
|
||||
Arrays.asList(SampleReactiveExtension.INSTANCE, GenericReactiveExtension.INSTANCE));
|
||||
|
||||
provider.getEvaluationContextLater(new WithRole(), dependencies).map(expression::getValue) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext("Walter") //
|
||||
.verifyComplete();
|
||||
|
||||
assertThat(GenericModelRoot.creationCounter).hasValue(1);
|
||||
assertThat(SecurityExpressionRoot.creationCounter).hasValue(1);
|
||||
}
|
||||
|
||||
public static class WithStaticRole {
|
||||
|
||||
public static boolean hasRole(String arg) {
|
||||
return arg.equals("ADMIN");
|
||||
}
|
||||
}
|
||||
|
||||
public static class WithRole {
|
||||
|
||||
public Object getPrincipal() {
|
||||
return new MyPrincipal("Jesse");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,14 +267,20 @@ class ReactiveExtensionAwareEvaluationContextProviderUnitTests {
|
||||
}
|
||||
|
||||
public Object getPrincipal() {
|
||||
return new MyPrincipal();
|
||||
return new MyPrincipal("Walter");
|
||||
}
|
||||
}
|
||||
|
||||
static class MyPrincipal {
|
||||
|
||||
private final String name;
|
||||
|
||||
public MyPrincipal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Walter";
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user