[spring-extensions] 03/04: IDP-1047 Add tests for @ParameterName Annotation
Rod Widdowson
rdw at steadingsoftware.com
Mon Sep 19 12:24:35 EDT 2016
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch master
in repository spring-extensions.
View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=c3756b3aa168b4fe75fecfe8c9464dcacd72f524
commit c3756b3aa168b4fe75fecfe8c9464dcacd72f524
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Sep 19 16:00:02 2016 +0100
IDP-1047 Add tests for @ParameterName Annotation
https://issues.shibboleth.net/jira/browse/IDP-1047
Test first. Then add code.
---
.../net/shibboleth/ext/spring/util/ParamClass.java | 37 +++++++++++
.../spring/util/ParameterNameAnnotationTest.java | 76 ++++++++++++++++++++++
.../net/shibboleth/ext/spring/util/paramBeans.xml | 9 +++
3 files changed, 122 insertions(+)
diff --git a/src/test/java/net/shibboleth/ext/spring/util/ParamClass.java b/src/test/java/net/shibboleth/ext/spring/util/ParamClass.java
new file mode 100644
index 0000000..751e040
--- /dev/null
+++ b/src/test/java/net/shibboleth/ext/spring/util/ParamClass.java
@@ -0,0 +1,37 @@
+/*
+ * 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.ext.spring.util;
+
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+
+/**
+ * simple bean.
+ */
+public class ParamClass {
+
+ private final String p1;
+ private final String p2;
+
+ public ParamClass(@ParameterName(name="param1") final String param2, @ParameterName(name="param2") final String param1) {
+ p1 = param2;
+ p2 = param1;
+ }
+
+ public String getP1() {return p1;}
+ public String getP2() {return p2;}
+}
diff --git a/src/test/java/net/shibboleth/ext/spring/util/ParameterNameAnnotationTest.java b/src/test/java/net/shibboleth/ext/spring/util/ParameterNameAnnotationTest.java
new file mode 100644
index 0000000..5f74e11
--- /dev/null
+++ b/src/test/java/net/shibboleth/ext/spring/util/ParameterNameAnnotationTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.ext.spring.util;
+
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.support.GenericApplicationContext;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ *
+ */
+public class ParameterNameAnnotationTest {
+
+ @Test public void testNoAnnotationFilter() {
+
+ final GenericApplicationContext context = new GenericApplicationContext();
+ final XmlBeanDefinitionReader beanDefinitionReader = new SchemaTypeAwareXMLBeanDefinitionReader(context);
+
+ beanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
+ beanDefinitionReader.loadBeanDefinitions("net/shibboleth/ext/spring/util/paramBeans.xml");
+ context.refresh();
+
+ final ParamClass byNumber = context.getBean("TheBeanRemainsTheSame", ParamClass.class);
+ Assert.assertEquals(byNumber.getP1(), "Param the First");
+ Assert.assertEquals(byNumber.getP2(), "Param the Second");
+
+ final ParamClass byId = context.getBean("InThroughTheOutBean", ParamClass.class);
+
+ //
+ // Swapped
+ //
+ Assert.assertEquals(byId.getP2(), "Param the First");
+ Assert.assertEquals(byId.getP1(), "Param the Second");
+
+ }
+
+ @Test(enabled=false) public void testWithAnnotationFilter() {
+
+ final GenericApplicationContext context = new GenericApplicationContext();
+ final XmlBeanDefinitionReader beanDefinitionReader = new SchemaTypeAwareXMLBeanDefinitionReader(context);
+
+ beanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
+ beanDefinitionReader.loadBeanDefinitions("net/shibboleth/ext/spring/util/paramBeans.xml");
+ context.refresh();
+
+ final ParamClass byNumber = context.getBean("TheBeanRemainsTheSame", ParamClass.class);
+ Assert.assertEquals(byNumber.getP1(), "Param the First");
+ Assert.assertEquals(byNumber.getP2(), "Param the Second");
+
+ final ParamClass byId = context.getBean("InThroughTheOutBean", ParamClass.class);
+
+ //
+ // Swapped
+ //
+ Assert.assertEquals(byId.getP1(), "Param the First");
+ Assert.assertEquals(byId.getP2(), "Param the Second");
+
+ }
+
+}
diff --git a/src/test/resources/net/shibboleth/ext/spring/util/paramBeans.xml b/src/test/resources/net/shibboleth/ext/spring/util/paramBeans.xml
new file mode 100644
index 0000000..9009f54
--- /dev/null
+++ b/src/test/resources/net/shibboleth/ext/spring/util/paramBeans.xml
@@ -0,0 +1,9 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ 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">
+
+ <bean id="TheBeanRemainsTheSame" class="net.shibboleth.ext.spring.util.ParamClass" c:_0="Param the First" c:_1="Param the Second"/>
+
+ <bean id="InThroughTheOutBean" class="net.shibboleth.ext.spring.util.ParamClass" c:param1="Param the First" c:param2="Param the Second"/>
+
+</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