Permalink
Browse files

Fix Windows-related build issues

- Increase max heap size in gradle wrapper.
- Use MockProperties implementation to protect against security
  exceptions.
- Replace windows CRLF with LF in various tests.
- Increase Thread.sleep times to account for lack of precision on
  Windows.

Issue: SPR-9717
  • Loading branch information...
1 parent 94bb036 commit 8e7622bb8a6a078d92531b657f105cec953c4166 Phillip Webb committed with cbeams Sep 7, 2012
View
@@ -12,7 +12,7 @@ if "%OS%"=="Windows_NT" setlocal
set DEFAULT_JVM_OPTS=
@rem ADDED BY HAND -- DO NOT ACCIDENTALLY DELETE WHEN UPGRADING GRADLE WRAPPER!
-set GRADLE_OPTS=-XX:MaxPermSize=1024m -Xmx1024m %GRADLE_OPTS%
+set GRADLE_OPTS=-XX:MaxPermSize=1024m -Xmx1024m -XX:MaxHeapSize=256m %GRADLE_OPTS%
@rem END ADDED BY HAND
set DIRNAME=%~dp0
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -25,11 +25,15 @@
import static test.util.TestResourceUtils.qualifiedResource;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
+import java.util.prefs.PreferencesFactory;
import org.junit.Before;
import org.junit.Test;
@@ -52,19 +56,24 @@
* Unit tests for various {@link PropertyResourceConfigurer} implementations including:
* {@link PropertyPlaceholderConfigurer}, {@link PropertyOverrideConfigurer} and
* {@link PreferencesPlaceholderConfigurer}.
- *
+ *
* @see PropertyPlaceholderConfigurerTests
* @since 02.10.2003
* @author Juergen Hoeller
* @author Chris Beams
+ * @author Phillip Webb
*/
public final class PropertyResourceConfigurerTests {
+ static {
+ System.setProperty("java.util.prefs.PreferencesFactory", MockPreferencesFactory.class.getName());
+ }
+
private static final Class<?> CLASS = PropertyResourceConfigurerTests.class;
private static final Resource TEST_PROPS = qualifiedResource(CLASS, "test.properties");
private static final Resource XTEST_PROPS = qualifiedResource(CLASS, "xtest.properties"); // does not exist
private static final Resource TEST_PROPS_XML = qualifiedResource(CLASS, "test.properties.xml");
-
+
private DefaultListableBeanFactory factory;
@Before
@@ -808,4 +817,87 @@ protected String convertPropertyValue(String originalValue) {
}
}
+ /**
+ * {@link PreferencesFactory} to create {@link MockPreferences}.
+ */
+ public static class MockPreferencesFactory implements PreferencesFactory {
+
+ private Preferences systemRoot = new MockPreferences();
+
+ private Preferences userRoot = new MockPreferences();
+
+ public Preferences systemRoot() {
+ return systemRoot;
+ }
+
+ public Preferences userRoot() {
+ return userRoot;
+ }
+ }
+
+ /**
+ * Mock implementation of {@link Preferences} that behaves the same regardless of the
+ * underlying operating system and will never throw security exceptions.
+ */
+ public static class MockPreferences extends AbstractPreferences {
+
+ private static Map<String, String> values = new HashMap<String, String>();
+
+ private static Map<String, AbstractPreferences> children = new HashMap<String, AbstractPreferences>();
+
+ public MockPreferences() {
+ super(null, "");
+ }
+
+ protected MockPreferences(AbstractPreferences parent, String name) {
+ super(parent, name);
+ }
+
+ @Override
+ protected void putSpi(String key, String value) {
+ values.put(key, value);
+ }
+
+ @Override
+ protected String getSpi(String key) {
+ return values.get(key);
+ }
+
+ @Override
+ protected void removeSpi(String key) {
+ values.remove(key);
+ }
+
+ @Override
+ protected void removeNodeSpi() throws BackingStoreException {
+ }
+
+ @Override
+ protected String[] keysSpi() throws BackingStoreException {
+ return values.keySet().toArray(new String[values.size()]);
+ }
+
+ @Override
+ protected String[] childrenNamesSpi() throws BackingStoreException {
+ return children.keySet().toArray(new String[values.size()]);
+ }
+
+ @Override
+ protected AbstractPreferences childSpi(String name) {
+ AbstractPreferences child = children.get(name);
+ if (child == null) {
+ child = new MockPreferences(this, name);
+ children.put(name, child);
+ }
+ return child;
+ }
+
+ @Override
+ protected void syncSpi() throws BackingStoreException {
+ }
+
+ @Override
+ protected void flushSpi() throws BackingStoreException {
+ }
+ }
}
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2009 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -321,6 +321,7 @@ private String fetchMacro(String name) throws Exception {
ClassPathResource resource = new ClassPathResource("test.ftl", getClass());
assertTrue(resource.exists());
String all = FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
+ all = all.replace("\r\n", "\n");
String[] macros = StringUtils.delimitedListToStringArray(all, "\n\n");
for (String macro : macros) {
if (macro.startsWith(name)) {
@@ -156,7 +156,7 @@ public void renderWithPrettyPrint() throws Exception {
view.setPrettyPrint(true);
view.render(model, request, response);
- String result = response.getContentAsString();
+ String result = response.getContentAsString().replace("\r\n", "\n");
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
validateResult();
@@ -149,7 +149,7 @@ public void renderWithPrettyPrint() throws Exception {
view.setPrettyPrint(true);
view.render(model, request, response);
- String result = response.getContentAsString();
+ String result = response.getContentAsString().replace("\r\n", "\n");
assertTrue("Pretty printing not applied:\n" + result, result.startsWith("{\n \"foo\" : {\n "));
validateResult();
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2007 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -53,7 +53,7 @@
private MockHttpServletRequest request;
private MockHttpServletResponse response;
-
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -95,12 +95,12 @@ public void testSimpleRender() throws Exception {
Map<String,Object> model = new HashMap<String,Object>();
model.put("command", new TestBean("juergen", 99));
view.render(model, request, response);
- assertEquals("\nNAME\njuergen\n", response.getContentAsString());
+ assertEquals("\nNAME\njuergen\n", response.getContentAsString().replace("\r\n", "\n"));
}
@Test
- @Ignore // This works with Velocity 1.6.2
+ @Ignore // This works with Velocity 1.6.2
public void testSimpleRenderWithError() throws Exception {
thrown.expect(NestedServletException.class);
@@ -111,10 +111,10 @@ public boolean matchesSafely(Exception item) {
}
public void describeTo(Description description) {
description.appendText("exception has cause of MethodInvocationException");
-
+
}
- });
-
+ });
+
VelocityConfigurer vc = new VelocityConfigurer();
vc.setPreferFileSystemAccess(false);
vc.setVelocityPropertiesMap(Collections.<String,Object>singletonMap("runtime.references.strict", "true"));
@@ -143,10 +143,10 @@ public boolean matchesSafely(Exception item) {
}
public void describeTo(Description description) {
description.appendText("exception has cause of IOException");
-
+
}
- });
-
+ });
+
VelocityConfigurer vc = new VelocityConfigurer();
vc.setPreferFileSystemAccess(false);
vc.setVelocityPropertiesMap(Collections.<String,Object>singletonMap("runtime.references.strict", "true"));
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -84,7 +84,7 @@ public void succeedsWhenJdkProxyAndScheduledMethodIsPresentOnInterface() throws
ctx.register(Config.class, JdkProxyTxConfig.class, RepoConfigB.class);
ctx.refresh();
- Thread.sleep(10); // allow @Scheduled method to be called several times
+ Thread.sleep(30); // allow @Scheduled method to be called several times
MyRepositoryWithScheduledMethod repository = ctx.getBean(MyRepositoryWithScheduledMethod.class);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
@@ -179,4 +179,5 @@ public int getInvocationCount() {
return this.count.get();
}
}
-}
+}
+

0 comments on commit 8e7622b

Please sign in to comment.