summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-23 10:14:34 (EST)
committer Winston Prakash2011-12-01 20:47:13 (EST)
commit2aacc1883050fb7ed94fa5bddcecaddedd8a8319 (patch)
tree3e75cee741b2e3c1b15f6379a35d86ae2517cb16
parentdf4bfa0953b32134fa4af838421bf93a885c3ac2 (diff)
downloadorg.eclipse.hudson.core-2aacc1883050fb7ed94fa5bddcecaddedd8a8319.zip
org.eclipse.hudson.core-2aacc1883050fb7ed94fa5bddcecaddedd8a8319.tar.gz
org.eclipse.hudson.core-2aacc1883050fb7ed94fa5bddcecaddedd8a8319.tar.bz2
Introduce returnOriginalValue method for PP class. Add ability to override this method in subclasses in order to provide flexible mechanism of value handling. Increase test coverage. Implement test class for DescribableListUtil class
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/BaseBuildableProject.java2
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java2
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java11
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java5
-rw-r--r--hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java98
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java40
-rw-r--r--hudson-war/src/main/webapp/scripts/hudson-behavior.js1
7 files changed, 156 insertions, 3 deletions
diff --git a/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java b/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
index 109dcd3..d6e3f58 100644
--- a/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
+++ b/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
@@ -244,7 +244,7 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P,B>,B
}
protected void convertBuildersProjectProperty() {
- if (null == getProperty(BUILDERS_PROPERTY_NAME)) {
+ if (null != builders && null == getProperty(BUILDERS_PROPERTY_NAME)) {
setBuilders(builders);
builders = null;
}
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index b51d30d..a5e6e5a 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -1247,7 +1247,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
JSONObject json = req.getSubmittedForm();
setLogRotator(req.getParameter("logrotate") != null ? LogRotator.DESCRIPTOR
- .newInstance(req, json.getJSONObject("logrotate")) : null);
+ .newInstance(req, json.getJSONObject("logrotate")) : null, false);
int i = 0;
for (JobPropertyDescriptor d : JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())) {
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java
index 0a506de..3397c3d 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java
@@ -121,13 +121,22 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
* {@inheritDoc}
*/
public T getValue() {
- if (isOverridden() || null != originalValue) {
+ if (returnOriginalValue()) {
return getOriginalValue();
}
return getCascadingValue();
}
/**
+ * Checks whether original or cascading value should be used.
+ *
+ * @return true to use original value, false - cascading value.
+ */
+ protected boolean returnOriginalValue() {
+ return isOverridden() || null != originalValue;
+ }
+
+ /**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java
index c2414cc..90b9ad6 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java
@@ -42,5 +42,10 @@ public class DescribableListProjectProperty extends BaseProjectProperty<Describa
|| !CollectionUtils.isEqualCollection(cascadingValue.toList(), candidateValue.toList()));
}
+ @Override
+ protected boolean returnOriginalValue() {
+ return isOverridden() || (null != getOriginalValue() && !getOriginalValue().isEmpty());
+ }
}
+
diff --git a/hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java b/hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java
new file mode 100644
index 0000000..8d819ff
--- /dev/null
+++ b/hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 2011 Oracle Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *
+ * Nikita Levyankov
+ *
+ *******************************************************************************/
+package hudson.util;
+
+import hudson.model.Descriptor;
+import hudson.model.FreeStyleProject;
+import hudson.model.Hudson;
+import hudson.tasks.Mailer;
+import hudson.tasks.Publisher;
+import java.io.IOException;
+import java.util.Map;
+import org.eclipse.hudson.api.model.IJob;
+import org.eclipse.hudson.api.model.project.property.BaseProjectProperty;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.expect;
+import static org.powermock.api.easymock.PowerMock.createMock;
+import static org.powermock.api.easymock.PowerMock.mockStatic;
+import static org.powermock.api.easymock.PowerMock.replayAll;
+
+/**
+ * Test for DescribableListUtil class
+ * </p>
+ * Date: 10/20/2011
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({Hudson.class, FreeStyleProject.class, Mailer.DescriptorImpl.class})
+public class DescribableListUtilTest {
+
+ private IJob job;
+
+ @Test
+ public void testConvertToProjectProperties1() {
+ prepareJob();
+ DescribableList<Publisher, Descriptor<Publisher>> list = null;
+ Map<String, BaseProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
+ assertNotNull(map);
+ assertTrue(map.isEmpty());
+ }
+
+ @Test
+ public void testConvertToProjectProperties2() {
+ prepareJob();
+ DescribableList<Publisher, Descriptor<Publisher>> list
+ = new DescribableList<Publisher, Descriptor<Publisher>>();
+ Map<String, BaseProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
+ assertNotNull(map);
+ assertTrue(map.isEmpty());
+ }
+
+ @Test
+ public void testConvertToProjectProperties3() throws IOException {
+ Hudson hudson = createMock(Hudson.class);
+ Mailer.DescriptorImpl descriptor = createMock(Mailer.DescriptorImpl.class);
+ String mailerName = "hudson-tasks-Mailer";
+ expect(descriptor.getJsonSafeClassName()).andReturn(mailerName);
+ expect(hudson.getDescriptorOrDie(Mailer.class)).andReturn(descriptor);
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ prepareJob();
+
+ DescribableList<Publisher, Descriptor<Publisher>> list
+ = new DescribableList<Publisher, Descriptor<Publisher>>();
+
+ list.add(new Mailer());
+
+ Map<String, BaseProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
+ assertNotNull(map);
+ assertEquals(map.size(), 1);
+ assertNotNull(map.get(mailerName));
+ assertEquals(map.get(mailerName).getValue().getClass(), Mailer.class);
+
+ }
+
+ public void prepareJob() {
+ job = createMock(FreeStyleProject.class);
+ expect(job.hasCascadingProject()).andReturn(false);
+ replayAll();
+ }
+}
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
index f544a6d..e3b958a 100644
--- a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
@@ -35,6 +35,7 @@ import hudson.tasks.Shell;
import hudson.util.DescribableList;
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
@@ -608,6 +609,45 @@ public class ProjectPropertyTest {
assertFalse(property.isOverridden());
}
+ /**
+ * Test returnOriginalValue method for BaseProjectProperty.
+ */
+ @Test
+ public void testBaseProjectPropertyReturnOriginalValue() {
+ BaseProjectProperty property = new BaseProjectProperty(project);
+ //False - If isOverridden flag is false and original value is null
+ assertFalse(property.returnOriginalValue());
+ property.setOverridden(true);
+ //True - If isOverridden flag is true or original value is not null
+ assertTrue(property.returnOriginalValue());
+ property.setOriginalValue(new Object(), false);
+ assertTrue(property.returnOriginalValue());
+ }
+
+ /**
+ * Test returnOriginalValue method for DescribableListProjectProperty.
+ */
+ @Test
+ public void testDescribableListProjectPropertyReturnOriginalValue() throws IOException{
+ DescribableListProjectProperty property = new DescribableListProjectProperty(project);
+ //False - If isOverridden flag is false and original value is null
+ assertFalse(property.returnOriginalValue());
+
+ //False - If isOverridden flag is false and Describable list is null or empty
+ property.setOriginalValue(null, false);
+ assertFalse(property.returnOriginalValue());
+ property.setOriginalValue(new DescribableList(project), false);
+ assertFalse(property.returnOriginalValue());
+
+ //True - If isOverridden flag is true or original value is not null
+ property.setOverridden(true);
+ assertTrue(property.returnOriginalValue());
+
+ DescribableList originalValue = new DescribableList(project, Arrays.asList(new Object()));
+ property.setOriginalValue(originalValue, false);
+ assertTrue(property.returnOriginalValue());
+ }
+
private class FakeSCM extends SCM {
@Override
public SCMRevisionState calcRevisionsFromBuild(AbstractBuild<?, ?> build, Launcher launcher,
diff --git a/hudson-war/src/main/webapp/scripts/hudson-behavior.js b/hudson-war/src/main/webapp/scripts/hudson-behavior.js
index e052b46..fb1c4e6 100644
--- a/hudson-war/src/main/webapp/scripts/hudson-behavior.js
+++ b/hudson-war/src/main/webapp/scripts/hudson-behavior.js
@@ -1404,6 +1404,7 @@ var repeatableSupport = {
if(children.length==1) {
children[0].addClassName("repeated-chunk first last only");
} else {
+ Element.removeClassName(children[0], "last only");
children[0].addClassName("repeated-chunk first");
for(var i=1; i<children.length-1; i++)
children[i].addClassName("repeated-chunk middle");