From 167329ce0c5244b976513a0ce8c0433fdac7f6cb Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 24 Jan 2014 17:48:40 +0100 Subject: [PATCH] Added test for SpringProperties setFlag method Issue: SPR-9014 Issue: SPR-11297 (cherry picked from commit 23249cd) --- .../springframework/core/SpringProperties.java | 6 ++++-- .../core/env/StandardEnvironmentTests.java | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/SpringProperties.java b/spring-core/src/main/java/org/springframework/core/SpringProperties.java index fe6def84be..01813e2596 100644 --- a/spring-core/src/main/java/org/springframework/core/SpringProperties.java +++ b/spring-core/src/main/java/org/springframework/core/SpringProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,8 @@ import org.apache.commons.logging.LogFactory; */ public abstract class SpringProperties { + private static final String PROPERTIES_RESOURCE_LOCATION = "spring.properties"; + private static final Log logger = LogFactory.getLog(SpringProperties.class); private static final Properties localProperties = new Properties(); @@ -52,7 +54,7 @@ public abstract class SpringProperties { static { try { ClassLoader cl = SpringProperties.class.getClassLoader(); - URL url = cl.getResource("spring.properties"); + URL url = cl.getResource(PROPERTIES_RESOURCE_LOCATION); if (url != null) { logger.info("Found 'spring.properties' file in local classpath"); InputStream is = url.openStream(); diff --git a/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java b/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java index aa867709b5..01daf449dc 100644 --- a/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java +++ b/spring-core/src/test/java/org/springframework/core/env/StandardEnvironmentTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,15 +59,15 @@ public class StandardEnvironmentTests { child.setActiveProfiles("c1", "c2"); child.getPropertySources().addLast( new MockPropertySource("childMock") - .withProperty("childKey", "childVal") - .withProperty("bothKey", "childBothVal")); + .withProperty("childKey", "childVal") + .withProperty("bothKey", "childBothVal")); ConfigurableEnvironment parent = new StandardEnvironment(); parent.setActiveProfiles("p1", "p2"); parent.getPropertySources().addLast( new MockPropertySource("parentMock") - .withProperty("parentKey", "parentVal") - .withProperty("bothKey", "parentBothVal")); + .withProperty("parentKey", "parentVal") + .withProperty("bothKey", "parentBothVal")); assertThat(child.getProperty("childKey"), is("childVal")); assertThat(child.getProperty("parentKey"), nullValue()); @@ -354,6 +354,13 @@ public class StandardEnvironmentTests { SpringProperties.setProperty("spring.getenv.ignore", null); } + @Test + public void suppressGetenvAccessThroughSpringFlag() { + SpringProperties.setFlag("spring.getenv.ignore"); + assertTrue(environment.getSystemEnvironment().isEmpty()); + SpringProperties.setProperty("spring.getenv.ignore", null); + } + @Test public void getSystemProperties_withAndWithoutSecurityManager() { System.setProperty(ALLOWED_PROPERTY_NAME, ALLOWED_PROPERTY_VALUE); -- GitLab