aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-21 06:51:22 (EST)
committerWinston Prakash2011-12-01 20:46:49 (EST)
commitb96c8bf239394b707209fb8eefd93ad488d6da6d (patch)
treeeb52a3aa8d63e3b8cb6cb7daf697b2fb7ba3e9a8
parent892481f25828202e7f1f1099065c35bc84a481b0 (diff)
downloadorg.eclipse.hudson.core-b96c8bf239394b707209fb8eefd93ad488d6da6d.zip
org.eclipse.hudson.core-b96c8bf239394b707209fb8eefd93ad488d6da6d.tar.gz
org.eclipse.hudson.core-b96c8bf239394b707209fb8eefd93ad488d6da6d.tar.bz2
Implement getters and setters for jdkName, quietPeriod based on template project. Improve unit-tests
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java61
-rw-r--r--hudson-core/src/main/java/hudson/model/FreeStyleProject.java4
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java11
-rw-r--r--hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java313
4 files changed, 293 insertions, 96 deletions
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index 69866b6..1e5d03f 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -89,7 +89,9 @@ import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
+import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.stapler.ForwardToView;
@@ -513,7 +515,10 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public int getQuietPeriod() {
- return quietPeriod!=null ? quietPeriod : Hudson.getInstance().getQuietPeriod();
+ if (null != quietPeriod) {
+ return quietPeriod;
+ }
+ return hasParentTemplate() ? getTemplate().getQuietPeriod() : Hudson.getInstance().getQuietPeriod();
}
public int getScmCheckoutRetryCount() {
@@ -531,12 +536,33 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
/**
* Sets the custom quiet period of this project, or revert to the global default if null is given.
+ * @param seconds quit period
+ * @throws IOException if any.
*/
public void setQuietPeriod(Integer seconds) throws IOException {
- this.quietPeriod = seconds;
+ if (!(hasParentTemplate() && ObjectUtils.equals(getTemplate().getQuietPeriod(), seconds))) {
+ this.quietPeriod = seconds;
+ } else {
+ this.quietPeriod = null;
+ }
save();
}
+ /**
+ * Sets quietPeriod, Uses {@link NumberUtils#isNumber(String)} for checking seconds param. If seconds is not valid
+ * number, null will be set.
+ *
+ * @param seconds quiet period.
+ * @throws IOException if any.
+ */
+ protected void setQuietPeriod(String seconds) throws IOException {
+ Integer period = null;
+ if (NumberUtils.isNumber(seconds)) {
+ period = NumberUtils.createInteger(seconds);
+ }
+ setQuietPeriod(period);
+ }
+
public boolean hasCustomScmCheckoutRetryCount(){
return scmCheckoutRetryCount != null;
}
@@ -891,10 +917,20 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
/**
- * Gets the JDK that this project is configured with, or null.
+ * @return name of jdk chosen for current project. Could taken from parent
+ */
+ protected String getJDKName() {
+ if (StringUtils.isNotBlank(jdk)) {
+ return jdk;
+ }
+ return hasParentTemplate()? getTemplate().getJDKName() : null;
+ }
+
+ /**
+ * @return JDK that this project is configured with, or null.
*/
public JDK getJDK() {
- return Hudson.getInstance().getJDK(jdk);
+ return Hudson.getInstance().getJDK(getJDKName());
}
/**
@@ -906,7 +942,12 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public void setJDK(String jdk) {
- this.jdk = jdk;
+ if (!(hasParentTemplate()
+ && StringUtils.equalsIgnoreCase(getTemplate().getJDKName(), jdk))) {
+ this.jdk = jdk;
+ } else {
+ this.jdk = null;
+ }
}
public BuildAuthorizationToken getAuthToken() {
@@ -1446,6 +1487,13 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
/**
+ * @return list of {@link Trigger} elements.
+ */
+ public List<Trigger<?>> getTriggersList() {
+ return triggers;
+ }
+
+ /**
* Gets the specific trigger, or null if the propert is not configured for this job.
*/
public <T extends Trigger> T getTrigger(Class<T> clazz) {
@@ -1675,8 +1723,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
makeDisabled(null != req.getParameter("disable"));
setTemplateName(StringUtils.trimToNull(req.getParameter("templateName")));
setJDK(req.getParameter("jdk"));
- setQuietPeriod(null != req.getParameter("hasCustomQuietPeriod") ?
- Integer.parseInt(req.getParameter("quiet_period")) : null);
+ setQuietPeriod(null != req.getParameter("hasCustomQuietPeriod") ? req.getParameter("quiet_period") : null);
setScmCheckoutRetryCount(null != req.getParameter("hasCustomScmCheckoutRetryCount")
? Integer.parseInt(req.getParameter("scmCheckoutRetryCount")) : null);
setBlockBuildWhenDownstreamBuilding(null != req.getParameter("blockBuildWhenDownstreamBuilding"));
diff --git a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
index 9d80068..638ab8f 100644
--- a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
+++ b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
@@ -81,9 +81,9 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
* If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace
* is prepared.
*
- * @param customWorkspace customWorkspace.
+ * @param customWorkspace new custom workspace to set
* @since 1.320
- * @throws java.io.IOException exception if any.
+ * @throws IOException if any.
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
if (!(hasParentTemplate()
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index 3b73d4e..6319946 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -154,7 +154,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
*/
private transient JobT template;
- protected final ThreadLocal<Boolean> allowSave = new ThreadLocal<Boolean>() {
+ protected final transient ThreadLocal<Boolean> allowSave = new ThreadLocal<Boolean>() {
@Override
protected Boolean initialValue() {
return true;
@@ -1035,13 +1035,8 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
properties.clear();
JSONObject json = req.getSubmittedForm();
-
- if (req.getParameter("logrotate") != null) {
- logRotator = LogRotator.DESCRIPTOR.newInstance(req, json.getJSONObject("logrotate"));
- } else {
- logRotator = null;
-
- }
+ setLogRotator(req.getParameter("logrotate") != null ? LogRotator.DESCRIPTOR
+ .newInstance(req, json.getJSONObject("logrotate")) : null);
int i = 0;
for (JobPropertyDescriptor d : JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())) {
diff --git a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
index 657f571..bf75363 100644
--- a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
@@ -22,6 +22,7 @@ import hudson.security.AuthorizationStrategy;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import hudson.security.ProjectMatrixAuthorizationStrategy;
import hudson.tasks.LogRotator;
+import java.io.IOException;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -53,7 +54,7 @@ public class FreeStyleProjectTest {
@Test
public void testOnCreatedFromScratch(){
Hudson hudson = createMock(Hudson.class);
- expect(hudson.getNodes()).andReturn(Lists.<Node>newArrayList()).times(2);
+ expect(hudson.getNodes()).andReturn(Lists.<Node>newArrayList());
AuthorizationStrategy authorizationStrategy = createMock(ProjectMatrixAuthorizationStrategy.class);
expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
mockStatic(Hudson.class);
@@ -63,12 +64,7 @@ public class FreeStyleProjectTest {
mockStatic(User.class);
expect(User.current()).andReturn(user);
replayAll();
- MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject freeStyleProject = new FreeStyleProject(matrixProjectProject, "testJob"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCreatedFromScratch();
verifyAll();
assertNotNull(freeStyleProject.getCreationTime());
@@ -84,7 +80,7 @@ public class FreeStyleProjectTest {
@Test
public void testOnCreatedFromScratchGlobalMatrixAuthorizationStrategy(){
Hudson hudson = createMock(Hudson.class);
- expect(hudson.getNodes()).andReturn(Lists.<Node>newArrayList()).times(2);
+ expect(hudson.getNodes()).andReturn(Lists.<Node>newArrayList());
AuthorizationStrategy authorizationStrategy = createMock(GlobalMatrixAuthorizationStrategy.class);
expect(hudson.getAuthorizationStrategy()).andReturn(authorizationStrategy);
mockStatic(Hudson.class);
@@ -94,12 +90,7 @@ public class FreeStyleProjectTest {
mockStatic(User.class);
expect(User.current()).andReturn(user);
replayAll();
- MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject freeStyleProject = new FreeStyleProject(matrixProjectProject, "testJob"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCreatedFromScratch();
verifyAll();
assertNotNull(freeStyleProject.getCreationTime());
@@ -111,18 +102,13 @@ public class FreeStyleProjectTest {
@Test
public void testOnCreatedFromScratchAnonymousAuthentication(){
Hudson hudson = createMock(Hudson.class);
- expect(hudson.getNodes()).andReturn(Lists.<Node>newArrayList()).times(2);
+ expect(hudson.getNodes()).andReturn(Lists.<Node>newArrayList());
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
mockStatic(User.class);
expect(User.current()).andReturn(null);
replayAll();
- MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject freeStyleProject = new FreeStyleProject(matrixProjectProject, "testJob"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCreatedFromScratch();
verifyAll();
assertNotNull(freeStyleProject.getCreationTime());
@@ -145,11 +131,7 @@ public class FreeStyleProjectTest {
expect(User.current()).andReturn(user);
replayAll();
MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject freeStyleProject = new FreeStyleProject(matrixProjectProject, "testJob"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCopiedFrom(matrixProjectProject);
verifyAll();
assertEquals(freeStyleProject.getNextBuildNumber(), 1);
@@ -178,11 +160,7 @@ public class FreeStyleProjectTest {
expect(User.current()).andReturn(user);
replayAll();
MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject freeStyleProject = new FreeStyleProject(matrixProjectProject, "testJob"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCopiedFrom(matrixProjectProject);
verifyAll();
assertEquals(freeStyleProject.getNextBuildNumber(), 1);
@@ -202,11 +180,7 @@ public class FreeStyleProjectTest {
expect(User.current()).andReturn(null);
replayAll();
MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject freeStyleProject = new FreeStyleProject(matrixProjectProject, "testJob"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject freeStyleProject = new FreeStyleProjectMock("testJob");
freeStyleProject.onCopiedFrom(matrixProjectProject);
verifyAll();
assertEquals(freeStyleProject.getNextBuildNumber(), 1);
@@ -220,19 +194,10 @@ public class FreeStyleProjectTest {
@Test
public void testGetLogRotatorFromParent(){
- MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject parentProject = new FreeStyleProject(matrixProjectProject, "parent"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
parentProject.setLogRotator(new LogRotator(10,11,12,13));
- FreeStyleProject childProject1 = new FreeStyleProject(matrixProjectProject, "child1"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject childProject1 = new FreeStyleProjectMock("child1");
childProject1.setTemplate(parentProject);
LogRotator result = childProject1.getLogRotator();
assertNotNull(result);
@@ -241,20 +206,11 @@ public class FreeStyleProjectTest {
@Test
public void testGetLogRotatorFromChild(){
- MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject parentProject = new FreeStyleProject(matrixProjectProject, "parent"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
parentProject.setLogRotator(new LogRotator(10,10,10,10));
- FreeStyleProject childProject1 = new FreeStyleProject(matrixProjectProject, "child1"){
- @Override
- protected void updateTransientActions() {
- }
- };
- childProject1.setLogRotator(new LogRotator(20,20,20,20));
+ FreeStyleProject childProject1 = new FreeStyleProjectMock("child1");
+ childProject1.setLogRotator(new LogRotator(20, 20, 20, 20));
childProject1.setTemplate(parentProject);
LogRotator result = childProject1.getLogRotator();
assertNotNull(result);
@@ -263,19 +219,10 @@ public class FreeStyleProjectTest {
@Test
public void testSetLogRotatorValueEqualsWithParent(){
- MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
- FreeStyleProject parentProject = new FreeStyleProject(matrixProjectProject, "parent"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
parentProject.setLogRotator(new LogRotator(10,11,12,13));
- FreeStyleProject childProject1 = new FreeStyleProject(matrixProjectProject, "child1"){
- @Override
- protected void updateTransientActions() {
- }
- };
+ FreeStyleProject childProject1 = new FreeStyleProjectMock("child1");
childProject1.setTemplate(parentProject);
childProject1.setLogRotator(new LogRotator(10,11,12,13));
childProject1.setTemplate(null); // else log rotator will be taken from parent
@@ -284,16 +231,224 @@ public class FreeStyleProjectTest {
@Test
public void testSetLogRotatorParentNull(){
- MatrixProject matrixProjectProject = new MatrixProject("matrixProject");
-
- FreeStyleProject childProject1 = new FreeStyleProject(matrixProjectProject, "child1"){
- @Override
- protected void updateTransientActions() {
- }
- };
- childProject1.setLogRotator(new LogRotator(10,11,12,13));
+ FreeStyleProject childProject1 = new FreeStyleProjectMock("child1");
+ childProject1.setLogRotator(new LogRotator(10, 11, 12, 13));
assertNotNull(childProject1.getLogRotator());
}
-}
+ @Test
+ public void testSetCustomWorkspaceValueEqualsWithParent() throws IOException{
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ String customWorkspace = "/tmp";
+ parentProject.setCustomWorkspace(customWorkspace);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setCustomWorkspace(customWorkspace);
+ childProject.setTemplate(null);
+ assertNull(childProject.getCustomWorkspace());
+ }
+
+ @Test
+ public void testSetCustomWorkspaceValueNotEqualsWithParent() throws IOException{
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ String parentCustomWorkspace = "/tmp";
+ String childCustomWorkspace = "/tmp1";
+ parentProject.setCustomWorkspace(parentCustomWorkspace);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setCustomWorkspace(childCustomWorkspace);
+ assertEquals(childCustomWorkspace, childProject.getCustomWorkspace());
+ }
+
+ @Test
+ public void testSetCustomWorkspaceValueParentNull() throws IOException{
+ String childCustomWorkspace = "/tmp";
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setCustomWorkspace(childCustomWorkspace);
+ assertEquals(childCustomWorkspace, childProject.getCustomWorkspace());
+ }
+
+ @Test
+ public void testGetCustomWorkspace() throws IOException{
+ String customWorkspace = "/tmp";
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setCustomWorkspace(customWorkspace);
+ assertEquals(customWorkspace, childProject.getCustomWorkspace());
+
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setCustomWorkspace(customWorkspace);
+ childProject.setCustomWorkspace(" ");
+ childProject.setTemplate(parentProject);
+ assertEquals(customWorkspace, childProject.getCustomWorkspace());
+ parentProject.setCustomWorkspace(" ");
+ assertNull(childProject.getCustomWorkspace());
+ }
+
+ @Test
+ public void testSetJdkValueEqualsWithParent() throws IOException{
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ String jdkName = "sun-java5-jdk32";
+ parentProject.setJDK(jdkName);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setJDK(jdkName);
+ childProject.setTemplate(null);
+ assertNull(childProject.getJDKName());
+ }
+
+ @Test
+ public void testSetJdkValueNotEqualsWithParent() throws IOException{
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ String parentJdkName = "sun-java5-jdk32";
+ String childJdkName = "sun-java6-jdk32";
+ parentProject.setJDK(parentJdkName);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setJDK(childJdkName);
+ assertEquals(childJdkName, childProject.getJDKName());
+ }
+
+ @Test
+ public void testSetJdkValueParentNull() throws IOException{
+ String childJdkName = "sun-java6-jdk32";
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setJDK(childJdkName);
+ assertEquals(childJdkName, childProject.getJDKName());
+ }
+
+ @Test
+ public void testGetJdkName() throws IOException{
+ String JdkName = "sun-java6-jdk32";
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setJDK(JdkName);
+ assertEquals(JdkName, childProject.getJDKName());
+
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setJDK(JdkName);
+ childProject.setJDK(" ");
+ childProject.setTemplate(parentProject);
+ assertEquals(JdkName, childProject.getJDKName());
+ parentProject.setJDK(" ");
+ assertNull(childProject.getJDKName());
+ }
+
+ @Test
+ public void testSetQuietPeriodEqualsWithParent() throws IOException {
+ String quietPeriod = "10";
+ int globalQuietPeriod = 4;
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setQuietPeriod(quietPeriod);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setQuietPeriod(quietPeriod);
+ childProject.setTemplate(null);
+
+ Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getQuietPeriod()).andReturn(globalQuietPeriod);
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+ assertEquals(childProject.getQuietPeriod(), globalQuietPeriod);
+ verifyAll();
+ }
+ @Test
+ public void testSetQuietPeriodNotEqualsWithParent() throws IOException{
+ String parentQuietPeriod = "10";
+ String childQuietPeriod = "11";
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setQuietPeriod(parentQuietPeriod);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setQuietPeriod(childQuietPeriod);
+
+ Hudson hudson = createMock(Hudson.class);
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+ assertEquals( childProject.getQuietPeriod(), Integer.parseInt(childQuietPeriod));
+ verifyAll();
+ }
+
+ @Test
+ public void testSetQuietPeriodParentNull() throws IOException{
+ String quietPeriod = "10";
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setQuietPeriod(quietPeriod);
+ assertEquals(Integer.parseInt(quietPeriod), childProject.getQuietPeriod());
+ }
+
+ @Test
+ public void testSetInvalidQuietPeriod() throws IOException{
+ String quietPeriod = "asd10asdasd";
+ int globalQuietPeriod = 4;
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setQuietPeriod(quietPeriod);
+ Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getQuietPeriod()).andReturn(globalQuietPeriod).anyTimes();
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+ assertEquals(globalQuietPeriod, childProject.getQuietPeriod());
+ verifyAll();
+ }
+
+ @Test
+ public void testGetQuietPeriod() throws IOException{
+ String quietPeriodString = "10";
+ int globalQuietPeriod = 4;
+ int quietPeriod = Integer.parseInt(quietPeriodString);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getQuietPeriod()).andReturn(globalQuietPeriod).anyTimes();
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+
+ childProject.allowSave.set(false);
+ childProject.setQuietPeriod(quietPeriodString);
+ assertEquals(quietPeriod, childProject.getQuietPeriod());
+
+ parentProject.allowSave.set(false);
+ parentProject.setQuietPeriod(quietPeriodString);
+ childProject.setQuietPeriod(" ");
+ childProject.setTemplate(parentProject);
+ assertEquals(childProject.getQuietPeriod(), quietPeriod);
+
+ parentProject.setQuietPeriod(" ");
+ assertEquals(globalQuietPeriod, childProject.getQuietPeriod());
+ verifyAll();
+ }
+
+ private class FreeStyleProjectMock extends FreeStyleProject {
+
+ private FreeStyleProjectMock(String name) {
+ super((ItemGroup)null, name);
+ }
+
+ @Override
+ protected void updateTransientActions() {
+ }
+ }
+}