Fix system environment tests on all platforms
Issue: SPR-8245
This commit is contained in:
parent
a1b7af5c9c
commit
385d8e9482
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,7 +31,6 @@ import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
|
|
@ -229,7 +228,6 @@ public class PropertyPlaceholderConfigurerTests {
|
||||||
assertThat(bf.getBean(TestBean.class).getSex(), is("${key2}"));
|
assertThat(bf.getBean(TestBean.class).getSex(), is("${key2}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore // fails on windows
|
|
||||||
@Test
|
@Test
|
||||||
public void nullValueIsPreserved() {
|
public void nullValueIsPreserved() {
|
||||||
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
|
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
|
||||||
|
|
@ -247,6 +245,7 @@ public class PropertyPlaceholderConfigurerTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Map<String, String> getModifiableSystemEnvironment() {
|
private static Map<String, String> getModifiableSystemEnvironment() {
|
||||||
|
// for os x / linux
|
||||||
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
||||||
Map<String, String> env = System.getenv();
|
Map<String, String> env = System.getenv();
|
||||||
for (Class<?> cl : classes) {
|
for (Class<?> cl : classes) {
|
||||||
|
|
@ -255,12 +254,45 @@ public class PropertyPlaceholderConfigurerTests {
|
||||||
Field field = cl.getDeclaredField("m");
|
Field field = cl.getDeclaredField("m");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object obj = field.get(env);
|
Object obj = field.get(env);
|
||||||
return (Map<String, String>) obj;
|
if (obj != null && obj.getClass().getName().equals("java.lang.ProcessEnvironment$StringEnvironment")) {
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for windows
|
||||||
|
Class<?> processEnvironmentClass;
|
||||||
|
try {
|
||||||
|
processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
|
||||||
|
theCaseInsensitiveEnvironmentField.setAccessible(true);
|
||||||
|
Object obj = theCaseInsensitiveEnvironmentField.get(null);
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// do nothing
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
|
||||||
|
theEnvironmentField.setAccessible(true);
|
||||||
|
Object obj = theEnvironmentField.get(null);
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// do nothing
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.mock.env.MockPropertySource;
|
import org.springframework.mock.env.MockPropertySource;
|
||||||
|
|
||||||
|
|
@ -175,7 +174,6 @@ public class EnvironmentTests {
|
||||||
assertThat(environment.acceptsProfiles("p1"), is(true));
|
assertThat(environment.acceptsProfiles("p1"), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore // fails on windows
|
|
||||||
@Test
|
@Test
|
||||||
public void getSystemProperties_withAndWithoutSecurityManager() {
|
public void getSystemProperties_withAndWithoutSecurityManager() {
|
||||||
System.setProperty(ALLOWED_PROPERTY_NAME, ALLOWED_PROPERTY_VALUE);
|
System.setProperty(ALLOWED_PROPERTY_NAME, ALLOWED_PROPERTY_VALUE);
|
||||||
|
|
@ -293,6 +291,7 @@ public class EnvironmentTests {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Map<String, String> getModifiableSystemEnvironment() {
|
private static Map<String, String> getModifiableSystemEnvironment() {
|
||||||
|
// for os x / linux
|
||||||
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
||||||
Map<String, String> env = System.getenv();
|
Map<String, String> env = System.getenv();
|
||||||
for (Class<?> cl : classes) {
|
for (Class<?> cl : classes) {
|
||||||
|
|
@ -301,12 +300,45 @@ public class EnvironmentTests {
|
||||||
Field field = cl.getDeclaredField("m");
|
Field field = cl.getDeclaredField("m");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Object obj = field.get(env);
|
Object obj = field.get(env);
|
||||||
return (Map<String, String>) obj;
|
if (obj != null && obj.getClass().getName().equals("java.lang.ProcessEnvironment$StringEnvironment")) {
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for windows
|
||||||
|
Class<?> processEnvironmentClass;
|
||||||
|
try {
|
||||||
|
processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
|
||||||
|
theCaseInsensitiveEnvironmentField.setAccessible(true);
|
||||||
|
Object obj = theCaseInsensitiveEnvironmentField.get(null);
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// do nothing
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
|
||||||
|
theEnvironmentField.setAccessible(true);
|
||||||
|
Object obj = theEnvironmentField.get(null);
|
||||||
|
return (Map<String, String>) obj;
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
// do nothing
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue