[spring-extensions] branch maint-5 updated: IDP-1326 Conditional resources and windows native separators.

Rod Widdowson rdw at steadingsoftware.com
Mon Sep 17 08:12:19 EDT 2018


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch maint-5
in repository spring-extensions.

View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=b49bb151ef7ee3df6d7b33429ca6e913a9339cdf

The following commit(s) were added to refs/heads/maint-5 by this push:
       new  b49bb15   IDP-1326 Conditional resources and windows native separators.
b49bb15 is described below

commit b49bb151ef7ee3df6d7b33429ca6e913a9339cdf
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Sep 17 13:10:17 2018 +0100

    IDP-1326 Conditional resources and windows native separators.
    
    https://issues.shibboleth.net/jira/browse/IDP-1326
    
    Code to allow investigation.
---
 .../shibboleth/ext/spring/resource/Idp1326.java    | 103 +++++++++++++++++++++
 .../ext/spring/resource/idp1326-import.xml         |  12 +++
 .../net/shibboleth/ext/spring/resource/idp1326.xml |  11 +++
 3 files changed, 126 insertions(+)

diff --git a/src/test/java/net/shibboleth/ext/spring/resource/Idp1326.java b/src/test/java/net/shibboleth/ext/spring/resource/Idp1326.java
new file mode 100644
index 0000000..cbe6db8
--- /dev/null
+++ b/src/test/java/net/shibboleth/ext/spring/resource/Idp1326.java
@@ -0,0 +1,103 @@
+/*
+ * 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.resource;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.Collection;
+
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.core.env.StandardEnvironment;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.mock.env.MockPropertySource;
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import net.shibboleth.ext.spring.context.FilesystemGenericApplicationContext;
+import net.shibboleth.ext.spring.util.SchemaTypeAwareXMLBeanDefinitionReader;
+
+/**
+ *
+ */
+public class Idp1326{
+    
+    private String parentAsString;
+    private String separator;
+    private Resource resource;
+    
+    @BeforeClass public void getFileSystemDetails() throws IOException {
+        resource = new ClassPathResource("net/shibboleth/ext/spring/resource/idp1326.xml");
+        final Path path = resource.getFile().toPath();
+        
+        separator = path.getFileSystem().getSeparator();
+        Assert.assertEquals(separator.length(), 1);
+        parentAsString = path.getParent().toAbsolutePath().toString();
+    }
+    
+
+    /*
+     * Fails on Windows
+     */
+    @Test(enabled=false) public void testPropFileNative() {
+        testPropFile(parentAsString);
+    }
+    
+    @Test public void testPropFileJava() {
+        final StringBuilder sb = new StringBuilder(parentAsString);
+        if (!"/".equals(separator)) {
+            int i = sb.indexOf(separator);
+            while (i > 0) {
+                sb.replace(i, i+1, "/");
+                i = sb.indexOf(separator);
+            }
+        }
+        testPropFile(sb.toString());
+    }
+
+    
+    private void testPropFile(String idpHome) {
+        
+        GenericApplicationContext context = new FilesystemGenericApplicationContext();
+        
+        final MutablePropertySources propertySources = context.getEnvironment().getPropertySources();
+        final MockPropertySource mockEnvVars = new MockPropertySource();
+        mockEnvVars.setProperty("idp.home", idpHome);
+        
+        propertySources.replace(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, mockEnvVars);
+        
+        final PropertySourcesPlaceholderConfigurer placeholderConfig = new PropertySourcesPlaceholderConfigurer();
+        placeholderConfig.setPlaceholderPrefix("%{");
+        placeholderConfig.setPlaceholderSuffix("}");
+        placeholderConfig.setPropertySources(propertySources);
+        
+        context.addBeanFactoryPostProcessor(placeholderConfig);
+
+        final SchemaTypeAwareXMLBeanDefinitionReader beanDefinitionReader = new SchemaTypeAwareXMLBeanDefinitionReader(context);
+        beanDefinitionReader.loadBeanDefinitions(resource);
+        
+        context.refresh();
+        final Collection<String> beans = context.getBeansOfType(String.class).values();
+        Assert.assertEquals(beans.size(), 1);
+
+        Assert.assertEquals(beans.iterator().next(), idpHome);
+    }
+}
diff --git a/src/test/resources/net/shibboleth/ext/spring/resource/idp1326-import.xml b/src/test/resources/net/shibboleth/ext/spring/resource/idp1326-import.xml
new file mode 100644
index 0000000..4d0cffb
--- /dev/null
+++ b/src/test/resources/net/shibboleth/ext/spring/resource/idp1326-import.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:p="http://www.springframework.org/schema/p"
+       xmlns:c="http://www.springframework.org/schema/c"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <bean id="rodTest" 
+            class="java.lang.String"
+            c:_0="%{idp.home}"/>
+
+</beans>
diff --git a/src/test/resources/net/shibboleth/ext/spring/resource/idp1326.xml b/src/test/resources/net/shibboleth/ext/spring/resource/idp1326.xml
new file mode 100644
index 0000000..85fff45
--- /dev/null
+++ b/src/test/resources/net/shibboleth/ext/spring/resource/idp1326.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:p="http://www.springframework.org/schema/p"
+       xmlns:c="http://www.springframework.org/schema/c"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <import resource="conditional:${idp.home}/idp1326-import.xml" />
+
+
+</beans>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list