提交 96ec7a26 编写于 作者: N Nicolas De loof 提交者: GitHub

Merge pull request #2562 from ydubreuil/enhance-systempropertiestest

Enhance tests of jenkins.util.SystemProperties
......@@ -23,11 +23,13 @@
*/
package jenkins.util;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import net.sourceforge.htmlunit.corejs.javascript.RhinoSecurityManager;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.hamcrest.Matchers;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
......@@ -60,11 +62,30 @@ public class SystemPropertiesTest {
SystemProperties.getString("foo.bar"), equalTo("myVal"));
}
@Test
public void shouldInitializeFromWebAppProperty() throws Exception {
assertThat("Property is undefined before test",
SystemProperties.getString("foo.bar"), equalTo(null));
setWebAppInitParameter("foo.bar", "myVal");
assertThat("Web App property should assign the value",
SystemProperties.getString("foo.bar"), equalTo("myVal"));
}
@Test
public void shouldUseSystemPropertyAsAHighPriority() throws Exception {
ServletContext c = j.jenkins.servletContext;
setWebAppInitParameter("install-wizard-path", "myVal1");
System.setProperty("install-wizard-path", "myVal2");
assertThat("System property should take system property with a high priority",
SystemProperties.getString("install-wizard-path"), equalTo("myVal2"));
}
/**
* Hack to set a web app initial parameter afterwards. Only works with Jetty.
* @param property property to set
* @param value value of the property
*/
protected void setWebAppInitParameter(String property, String value) {
Assume.assumeThat(j.jenkins.servletContext, Matchers.instanceOf(ContextHandler.Context.class));
((ContextHandler.Context)j.jenkins.servletContext).getContextHandler().getInitParams().put(property, value);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册