/** * Remove the system property that points to the web app root directory. * To be called on shutdown of the web application. * @param servletContext the servlet context of the web application * @see #setWebAppRootSystemProperty */ public static void removeWebAppRootSystemProperty(ServletContext servletContext) { Assert.notNull(servletContext, "ServletContext must not be null"); String param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM); String key = (param != null ? param : DEFAULT_WEB_APP_ROOT_KEY); System.getProperties().remove(key); }
@Override public void afterPropertiesSet() throws Exception { System.getProperties(); } }
public Object makeInstance() { System.getProperties(); return new Object(); } }
public static Object makeStaticInstance() { System.getProperties(); return new Object(); }
static boolean isAndroid() { return System.getProperties().getProperty("java.runtime.name").contains("Android"); } }
@After public void tearDown() { System.getProperties().remove("foo"); }
@Test public void testRecursiveFromSystemProperty() { System.setProperty("test.prop", "foo=${bar}"); System.setProperty("bar", "baz"); try { String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop}"); assertEquals("foo=baz", resolved); } finally { System.getProperties().remove("test.prop"); System.getProperties().remove("bar"); } }
@Test(expected = IllegalArgumentException.class) public void defaultProfileWithCircularPlaceholder() { System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}"); try { environment.getDefaultProfiles(); } finally { System.getProperties().remove(DEFAULT_PROFILES_PROPERTY_NAME); } }
@Test public void testSystemPropertyReplacement() { PropertyEditor editor = new ResourceEditor(); System.setProperty("test.prop", "foo"); try { editor.setAsText("${test.prop}-${bar}"); Resource resolved = (Resource) editor.getValue(); assertEquals("foo-${bar}", resolved.getFilename()); } finally { System.getProperties().remove("test.prop"); } }
@Test public void getActiveProfiles_fromSystemProperties() { System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, "foo"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItem("foo")); System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME); }
@Test public void testSystemPropertyReplacement() { PropertyEditor editor = new ResourceArrayPropertyEditor(); System.setProperty("test.prop", "foo"); try { editor.setAsText("${test.prop}-${bar}"); Resource[] resources = (Resource[]) editor.getValue(); assertEquals("foo-${bar}", resources[0].getFilename()); } finally { System.getProperties().remove("test.prop"); } }
@Test public void testReplaceFromSystemProperty() { System.setProperty("test.prop", "bar"); try { String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop}"); assertEquals("bar", resolved); } finally { System.getProperties().remove("test.prop"); } }
@Test public void testReplaceFromSystemPropertyWithExpressionContainingDefault() { System.setProperty("test.prop", "bar"); try { String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop:Y#{foo.bar}X}"); assertEquals("bar", resolved); } finally { System.getProperties().remove("test.prop"); } }
@Test public void testReplaceFromSystemPropertyWithDefault() { System.setProperty("test.prop", "bar"); try { String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop:foo}"); assertEquals("bar", resolved); } finally { System.getProperties().remove("test.prop"); } }
@Test public void testReplaceFromSystemPropertyWithExpressionDefault() { System.setProperty("test.prop", "bar"); try { String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop:#{foo.bar}}"); assertEquals("bar", resolved); } finally { System.getProperties().remove("test.prop"); } }
@Test public void getActiveProfiles_fromSystemProperties_withMulitpleProfiles_withWhitespace() { System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, " bar , baz "); // notice whitespace assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("bar", "baz")); System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME); }
@Test public void getActiveProfiles_fromSystemProperties_withMultipleProfiles() { System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, "foo,bar"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("foo", "bar")); System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME); }
@Test public void getActiveProfiles_systemPropertiesEmpty() { assertThat(environment.getActiveProfiles().length, is(0)); System.setProperty(ACTIVE_PROFILES_PROPERTY_NAME, ""); assertThat(environment.getActiveProfiles().length, is(0)); System.getProperties().remove(ACTIVE_PROFILES_PROPERTY_NAME); }
@Test(expected = IllegalArgumentException.class) public void testStrictSystemPropertyReplacement() { PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false); System.setProperty("test.prop", "foo"); try { editor.setAsText("${test.prop}-${bar}"); Resource resolved = (Resource) editor.getValue(); assertEquals("foo-${bar}", resolved.getFilename()); } finally { System.getProperties().remove("test.prop"); } }
@Test public void reservedDefaultProfile() { assertThat(environment.getDefaultProfiles(), equalTo(new String[]{RESERVED_DEFAULT_PROFILE_NAME})); System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "d0"); assertThat(environment.getDefaultProfiles(), equalTo(new String[]{"d0"})); environment.setDefaultProfiles("d1", "d2"); assertThat(environment.getDefaultProfiles(), equalTo(new String[]{"d1","d2"})); System.getProperties().remove(DEFAULT_PROFILES_PROPERTY_NAME); }