[java-shib-shared] branch main updated: JSSH-22 Consider returning null from Spring boolean converters
Rod Widdowson
rdw at steadingsoftware.com
Wed Feb 1 13:16:32 UTC 2023
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-shib-shared.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=7140c44c294b01b287d533c2641751ed55f34d8d
The following commit(s) were added to refs/heads/main by this push:
new 7140c44c JSSH-22 Consider returning null from Spring boolean converters
7140c44c is described below
commit 7140c44c294b01b287d533c2641751ed55f34d8d
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Feb 1 11:29:37 2023 +0000
JSSH-22 Consider returning null from Spring boolean converters
https://shibboleth.atlassian.net/browse/JSSH-22
Behavior test as outlined in the case.
---
.../StringBooleanToPredicateConverterTest.java | 204 +++++++++++++++++++++
.../shared/spring/config/predicateConverter.xml | 36 ++++
2 files changed, 240 insertions(+)
diff --git a/shib-spring/src/test/java/net/shibboleth/shared/spring/config/StringBooleanToPredicateConverterTest.java b/shib-spring/src/test/java/net/shibboleth/shared/spring/config/StringBooleanToPredicateConverterTest.java
new file mode 100644
index 00000000..44f6d054
--- /dev/null
+++ b/shib-spring/src/test/java/net/shibboleth/shared/spring/config/StringBooleanToPredicateConverterTest.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.shared.spring.config;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.List;
+import java.util.function.Predicate;
+
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
+import org.testng.annotations.Test;
+
+/**
+ *
+ */
+ at ContextConfiguration({"predicateConverter.xml"})
+public class StringBooleanToPredicateConverterTest extends AbstractTestNGSpringContextTests {
+
+ static final boolean ALWAYS_PREDICATE = true;
+
+ @Test public void integerTest() {
+ assert(applicationContext != null);
+ FourProps bean = applicationContext.getBean("integer", FourProps.class);
+ if (!ALWAYS_PREDICATE) {
+ assertEquals(bean.getNameAsInt(), 1);
+ assertNull(bean.getNameAsList());
+ assertNull(bean.getNameAsString());
+ assertNull(bean.getNameAsPredicate());
+ } else {
+ assertFalse(bean.nameAsPredicate.test(null));
+ }
+ }
+
+ @Test public void stringTest() {
+ assert(applicationContext != null);
+ FourProps bean = applicationContext.getBean("string", FourProps.class);
+ if (!ALWAYS_PREDICATE) {
+ assertEquals(bean.getNameAsString(), "string");
+ assertNull(bean.getNameAsList());
+ assertNull(bean.getNameAsInt());
+ assertNull(bean.getNameAsPredicate());
+ } else {
+ assertFalse(bean.nameAsPredicate.test(null));
+ }
+ }
+
+ @Test public void predTrueTest() {
+ assert(applicationContext != null);
+ FourProps bean = applicationContext.getBean("predTrue", FourProps.class);
+ assertTrue(bean.getNameAsPredicate().test(null));
+ assertNull(bean.getNameAsList());
+ assertNull(bean.getNameAsString());
+ assertNull(bean.getNameAsInt());
+ }
+
+ @Test public void predFalseTest() {
+ assert(applicationContext != null);
+ FourProps bean = applicationContext.getBean("predFalse", FourProps.class);
+ assertFalse(bean.getNameAsPredicate().test(null));
+ assertNull(bean.getNameAsList());
+ assertNull(bean.getNameAsString());
+ assertNull(bean.getNameAsInt());
+ }
+
+ @Test public void listTest() {
+ assert(applicationContext != null);
+ FourProps bean = applicationContext.getBean("list", FourProps.class);
+ if (!ALWAYS_PREDICATE) {
+ assertEquals(bean.getNameAsList().size(), 2);
+ assertNull(bean.getNameAsInt());
+ assertNull(bean.getNameAsString());
+ assertNull(bean.getNameAsPredicate());
+ } else {
+ assertFalse(bean.nameAsPredicate.test(null));
+ }
+ }
+
+ @Test public void predOnlyTest() {
+ assert(applicationContext != null);
+ OneProp bean = applicationContext.getBean("predOnly", OneProp.class);
+ assertTrue(bean.getNameAsPredicate().test(null));
+ }
+
+ @Test(enabled = false) public void stringOnlyTest() {
+ assert(applicationContext != null);
+ try {
+ final OneProp bean = applicationContext.getBean("stringOnly", OneProp.class);
+ if (!ALWAYS_PREDICATE) {
+ fail();
+ } else {
+ assertFalse(bean.nameAsPredicate.test(null));
+ }
+ } catch (final BeanCreationException b) {
+ assertFalse(ALWAYS_PREDICATE);
+ }
+ }
+
+ public static class FourProps {
+ private String nameAsString;
+
+ private Integer nameAsInt;
+
+ private Predicate<?> nameAsPredicate;
+
+ private List<String> nameAsList;
+
+ /** Setter.
+ * @param input The nameAsInt to set.
+ */
+ public void setName(final Integer input) {
+ nameAsInt = input;
+ }
+
+ /** Setter.
+ * @param input The nameAsString to set.
+ */
+ public void setName(final String input) {
+ nameAsString = input;
+ }
+
+ /** Setter.
+ * @param input The nameAsPredicate to set.
+ */
+ public void setName(final Predicate<?> input) {
+ nameAsPredicate = input;
+ }
+
+ /** Setter.
+ * @param input The nameAsList to set.
+ */
+ public void setNameAsList(List<String> input) {
+ nameAsList = input;
+ }
+
+ /** Getter.
+ * @return Returns the nameAsInt.
+ */
+ public Integer getNameAsInt() {
+ return nameAsInt;
+ }
+
+ /** Getter.
+ * @return Returns the nameAsPredicate.
+ */
+ public Predicate<?> getNameAsPredicate() {
+ return nameAsPredicate;
+ }
+
+ /** Getter.
+ * @return Returns the nameAsString.
+ */
+ public String getNameAsString() {
+ return nameAsString;
+ }
+
+ /** Getter.
+ * @return Returns the nameAsList.
+ */
+ public List<String> getNameAsList() {
+ return nameAsList;
+ }
+ }
+
+ public static class OneProp {
+ private Predicate<?> nameAsPredicate;
+
+ /**
+ * @param input The nameAsPredicate to set.
+ */
+ public void setName(final Predicate<?> input) {
+ nameAsPredicate = input;
+ }
+
+ /**
+ * @return Returns the nameAsPredicate.
+ */
+ public Predicate<?> getNameAsPredicate() {
+ return nameAsPredicate;
+ }
+
+ }
+
+}
diff --git a/shib-spring/src/test/resources/net/shibboleth/shared/spring/config/predicateConverter.xml b/shib-spring/src/test/resources/net/shibboleth/shared/spring/config/predicateConverter.xml
new file mode 100644
index 00000000..bc85e112
--- /dev/null
+++ b/shib-spring/src/test/resources/net/shibboleth/shared/spring/config/predicateConverter.xml
@@ -0,0 +1,36 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:c="http://www.springframework.org/schema/c"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
+ default-lazy-init="true"
+ default-init-method="initialize"
+ default-destroy-method="destroy">
+
+ <bean id="conversionService" destroy-method=""
+ class="org.springframework.context.support.ConversionServiceFactoryBean">
+ <property name="converters">
+ <set>
+ <bean class="net.shibboleth.shared.spring.config.StringToIPRangeConverter" destroy-method=""/>
+ <bean class="net.shibboleth.shared.spring.config.BooleanToPredicateConverter" destroy-method=""/>
+ <bean class="net.shibboleth.shared.spring.config.StringBooleanToPredicateConverter" destroy-method=""/>
+ <bean class="net.shibboleth.shared.spring.config.StringToResourceConverter" destroy-method=""/>
+ <bean class="net.shibboleth.shared.spring.config.StringToDurationConverter" destroy-method=""/>
+ </set>
+ </property>
+ </bean>
+
+ <bean destroy-method="" id="integer" class="net.shibboleth.shared.spring.config.StringBooleanToPredicateConverterTest.FourProps" p:name="1"/>
+ <bean destroy-method="" id="predTrue" class="net.shibboleth.shared.spring.config.StringBooleanToPredicateConverterTest.FourProps" p:name="true"/>
+ <bean destroy-method="" id="predFalse" class="net.shibboleth.shared.spring.config.StringBooleanToPredicateConverterTest.FourProps" p:name="false"/>
+ <bean destroy-method="" id="string" class="net.shibboleth.shared.spring.config.StringBooleanToPredicateConverterTest.FourProps" p:name="string"/>
+ <bean destroy-method="" id="list" class="net.shibboleth.shared.spring.config.StringBooleanToPredicateConverterTest.FourProps" p:name="#{{'a', 'b'}}"/>
+
+ <bean destroy-method="" id="predOnly" class="net.shibboleth.shared.spring.config.StringBooleanToPredicateConverterTest.OneProp" p:name="true"/>
+ <bean destroy-method="" id="stringOnly" class="net.shibboleth.shared.spring.config.StringBooleanToPredicateConverterTest.OneProp" p:name="string"/>
+
+</beans>
\ 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