[java-identity-provider] branch master updated: Refactor to rely on base class.
Scott Cantor
cantor.2 at osu.edu
Tue Aug 27 10:16:06 EDT 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=5f200157c251cfe39c4947408cdcc7a44e94bba3
The following commit(s) were added to refs/heads/master by this push:
new 5f20015 Refactor to rely on base class.
5f20015 is described below
commit 5f200157c251cfe39c4947408cdcc7a44e94bba3
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Tue Aug 27 10:16:03 2019 -0400
Refactor to rely on base class.
---
.../SpringExpressionContextLookupFunction.java | 53 ++++------------------
.../SpringExpressionContextLookupFunctionTest.java | 34 +++++++++++++-
2 files changed, 40 insertions(+), 47 deletions(-)
diff --git a/idp-profile-api/src/main/java/net/shibboleth/idp/profile/context/navigate/SpringExpressionContextLookupFunction.java b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/context/navigate/SpringExpressionContextLookupFunction.java
index e3fe776..96ab8e4 100644
--- a/idp-profile-api/src/main/java/net/shibboleth/idp/profile/context/navigate/SpringExpressionContextLookupFunction.java
+++ b/idp-profile-api/src/main/java/net/shibboleth/idp/profile/context/navigate/SpringExpressionContextLookupFunction.java
@@ -34,17 +34,11 @@ import org.slf4j.LoggerFactory;
* which calls out to a Spring Expression.
*
* @param <T> the specific type of context
+ * @param <U> output type
* @since 3.3.0
*/
-public class SpringExpressionContextLookupFunction<T extends BaseContext>
- implements ContextDataLookupFunction<T, Object> {
-
- /**
- * The object that does the work.
- * In Future versions this should be replaced with inheritance.
- */
- @Deprecated
- private final SpringExpressionFunction<T, Object> embeddedObject;
+public class SpringExpressionContextLookupFunction<T extends BaseContext,U> extends SpringExpressionFunction<T,U>
+ implements ContextDataLookupFunction<T,U> {
/**
* Constructor.
@@ -54,8 +48,9 @@ public class SpringExpressionContextLookupFunction<T extends BaseContext>
*/
public SpringExpressionContextLookupFunction(@Nonnull @ParameterName(name="inClass") final Class<T> inClass,
@Nonnull @NotEmpty @ParameterName(name="expression") final String expression) {
- embeddedObject = new SpringExpressionFunction<>(expression);
- embeddedObject.setInputType(Constraint.isNotNull(inClass, "Supplied inputClass cannot be null"));
+ super(expression);
+ setInputType(Constraint.isNotNull(inClass, "Supplied inputClass cannot be null"));
+
if(!BaseContext.class.isAssignableFrom(inClass)) {
LoggerFactory.getLogger(SpringExpressionContextLookupFunction.class).
warn("InClass {} is not derived from {}", inClass, BaseContext.class);
@@ -71,41 +66,9 @@ public class SpringExpressionContextLookupFunction<T extends BaseContext>
*/
public SpringExpressionContextLookupFunction(@Nonnull @ParameterName(name="inClass") final Class<T> inClass,
@Nonnull @NotEmpty @ParameterName(name="expression") final String expression,
- @ParameterName(name="outputType") @Nullable final Class outputType) {
+ @ParameterName(name="outputType") @Nullable final Class<U> outputType) {
this(inClass, expression);
- embeddedObject.setOutputType(outputType);
- }
-
- /**
- * Return the custom (externally provided) object.
- *
- * @return the custom object
- */
- @Nullable public Object getCustomObject() {
- return embeddedObject.getCustomObject();
- }
-
- /**
- * Set the custom (externally provided) object.
- *
- * @param object the custom object
- */
- @Nullable public void setCustomObject(final Object object) {
- embeddedObject.setCustomObject(object);
- }
-
- /**
- * Set whether to hide exceptions in expression execution (default is false).
- *
- * @param flag flag to set
- */
- public void setHideExceptions(final boolean flag) {
- embeddedObject.setHideExceptions(flag);
- }
-
- /** {@inheritDoc} */
- @Nullable public Object apply(@Nullable final T context) {
- return embeddedObject.apply(context);
+ setOutputType(outputType);
}
}
\ No newline at end of file
diff --git a/idp-profile-api/src/test/java/net/shibboleth/idp/profile/context/navigate/SpringExpressionContextLookupFunctionTest.java b/idp-profile-api/src/test/java/net/shibboleth/idp/profile/context/navigate/SpringExpressionContextLookupFunctionTest.java
index 2f31fed..3e64a38 100644
--- a/idp-profile-api/src/test/java/net/shibboleth/idp/profile/context/navigate/SpringExpressionContextLookupFunctionTest.java
+++ b/idp-profile-api/src/test/java/net/shibboleth/idp/profile/context/navigate/SpringExpressionContextLookupFunctionTest.java
@@ -28,9 +28,39 @@ public class SpringExpressionContextLookupFunctionTest {
@Test public void simpleTest() {
- SpringExpressionContextLookupFunction<ProfileRequestContext> func =
+ SpringExpressionContextLookupFunction<ProfileRequestContext,Integer> func =
new SpringExpressionContextLookupFunction<>(ProfileRequestContext.class, "99", Integer.class);
- Assert.assertEquals(func.apply(null), 99);
+ Assert.assertEquals(func.apply(null), Integer.valueOf(99));
}
+ @Test public void customTest() {
+ SpringExpressionContextLookupFunction<ProfileRequestContext,Integer> func =
+ new SpringExpressionContextLookupFunction<>(ProfileRequestContext.class, "#custom + 1", Integer.class);
+ func.setCustomObject(Integer.valueOf(99));
+ Assert.assertEquals(func.apply(null), Integer.valueOf(100));
+ }
+
+ @Test public void invalidOutputTest() {
+ SpringExpressionContextLookupFunction<ProfileRequestContext,Integer> func =
+ new SpringExpressionContextLookupFunction<>(ProfileRequestContext.class, "'foo'", Integer.class);
+ func.setReturnOnError(-1);
+ Assert.assertEquals(func.apply(null), Integer.valueOf(-1));
+ }
+
+ @Test public void exceptionTest() {
+ SpringExpressionContextLookupFunction<ProfileRequestContext,Integer> func =
+ new SpringExpressionContextLookupFunction<>(ProfileRequestContext.class, "1/0", Integer.class);
+ func.setReturnOnError(-1);
+
+ try {
+ func.apply(null);
+ Assert.fail("Expression should have raised exception");
+ } catch (final Exception e) {
+
+ }
+
+ func.setHideExceptions(true);
+ Assert.assertEquals(func.apply(null), Integer.valueOf(-1));
+ }
+
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list