aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-25 03:12:36 (EST)
committerWinston Prakash2011-12-01 20:47:35 (EST)
commit2cd86fee1b22c2d69a1e6552934ad421c36d4ea6 (patch)
treec7ca823bede540add755aa38e5ed50090bbf0688
parent9143ac90cdc030f475b469a14ec4bb9b22681700 (diff)
downloadorg.eclipse.hudson.core-2cd86fee1b22c2d69a1e6552934ad421c36d4ea6.zip
org.eclipse.hudson.core-2cd86fee1b22c2d69a1e6552934ad421c36d4ea6.tar.gz
org.eclipse.hudson.core-2cd86fee1b22c2d69a1e6552934ad421c36d4ea6.tar.bz2
Improve SCM cascading handling: Inherit SCM if it wasn't configured. Speed-up code: drop instanceof checking. Implement unit-tests for new logic
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/Items.java3
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java19
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java5
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java27
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java9
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java11
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java11
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/BaseProjectPropertyTest.java88
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ExternalProjectPropertyTest.java16
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java134
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/SCMProjectPropertyTest.java126
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/TriggerProjectPropertyTest.java110
12 files changed, 387 insertions, 172 deletions
diff --git a/hudson-core/src/main/java/hudson/model/Items.java b/hudson-core/src/main/java/hudson/model/Items.java
index ccae37d..39fa2eb 100644
--- a/hudson-core/src/main/java/hudson/model/Items.java
+++ b/hudson-core/src/main/java/hudson/model/Items.java
@@ -28,6 +28,7 @@ import org.eclipse.hudson.api.model.project.property.ExternalProjectProperty;
import org.eclipse.hudson.api.model.project.property.IntegerProjectProperty;
import org.eclipse.hudson.api.model.project.property.LogRotatorProjectProperty;
import org.eclipse.hudson.api.model.project.property.ResultProjectProperty;
+import org.eclipse.hudson.api.model.project.property.SCMProjectProperty;
import org.eclipse.hudson.api.model.project.property.StringProjectProperty;
import hudson.matrix.MatrixProject;
import hudson.matrix.MatrixConfiguration;
@@ -140,6 +141,7 @@ public class Items {
XSTREAM.alias("matrix-config",MatrixConfiguration.class);
//aliases for project properties.
+ //TODO: think about migrating to xstream's annotations.
XSTREAM.alias("base-property", BaseProjectProperty.class);
XSTREAM.alias("external-property", ExternalProjectProperty.class);
XSTREAM.alias("trigger-property", TriggerProjectProperty.class);
@@ -148,6 +150,7 @@ public class Items {
XSTREAM.alias("string-property", StringProjectProperty.class);
XSTREAM.alias("log-rotator-property", LogRotatorProjectProperty.class);
XSTREAM.alias("result-property", ResultProjectProperty.class);
+ XSTREAM.alias("scm-property", SCMProjectProperty.class);
XSTREAM.alias("copy-write-list-property", CopyOnWriteListProjectProperty.class);
XSTREAM.alias("axis-list-property", AxisListProjectProperty.class);
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index 51e9e1c..f1e0d8a 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -89,7 +89,6 @@ import net.sf.json.JSONObject;
import org.eclipse.hudson.api.model.IJob;
import org.eclipse.hudson.api.model.IProjectProperty;
import org.eclipse.hudson.api.model.project.property.ExternalProjectProperty;
-import org.eclipse.hudson.api.model.project.property.TriggerProjectProperty;
import org.jvnet.localizer.Localizable;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
@@ -99,8 +98,7 @@ import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
-import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
-import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
+import static javax.servlet.http.HttpServletResponse.*;
/**
* A job is an runnable entity under the monitoring of Hudson.
@@ -1572,16 +1570,11 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
} else if (!StringUtils.equalsIgnoreCase(this.cascadingProjectName, cascadingProjectName)) {
CascadingUtil.unlinkProjectFromCascadingParents(cascadingProject, name);
this.cascadingProjectName = cascadingProjectName;
- this.cascadingProject = (JobT) Functions.getItemByName(Hudson.getInstance().getAllItems(this.getClass()),
+ cascadingProject = (JobT) Functions.getItemByName(Hudson.getInstance().getAllItems(this.getClass()),
cascadingProjectName);
CascadingUtil.linkCascadingProjectsToChild(cascadingProject, name);
for (IProjectProperty property : jobProperties.values()) {
- if (property instanceof ExternalProjectProperty) {
- property.setOverridden(((ExternalProjectProperty) property).isModified());
- } else {
- property.setOverridden(
- property.allowOverrideValue(property.getCascadingValue(), property.getValue()));
- }
+ property.onCascadingProjectChanged();
}
}
}
@@ -1617,11 +1610,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
this.cascadingProject = null;
this.cascadingProjectName = null;
for (IProjectProperty property : jobProperties.values()) {
- if (property instanceof TriggerProjectProperty && !property.isOverridden() && property.getValue() != null) {
- ((TriggerProjectProperty) property).getValue().stop();
- property.resetValue();
- }
- property.setOverridden(false);
+ property.onCascadingProjectChanged();
}
}
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java
index 4761346..9f72dd7 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java
@@ -109,4 +109,9 @@ public interface IProjectProperty<T> extends Serializable {
* @param overridden true - mark property as overridden, false - otherwise.
*/
void setOverridden(boolean overridden);
+
+ /**
+ * Method that is called while changing cascading parent. Update property internal states.l
+ */
+ void onCascadingProjectChanged();
}
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 4e8f5f7..3049460 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
@@ -217,4 +217,31 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
public T getOriginalValue() {
return originalValue;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public final void onCascadingProjectChanged() {
+ if (getJob().hasCascadingProject()) {
+ onCascadingProjectSet();
+ } else {
+ onCascadingProjectRemoved();
+ }
+ }
+
+ /**
+ * Executes when cascading parent is cleared. Default implementation marks property as not overridden.
+ */
+ protected void onCascadingProjectRemoved() {
+ setOverridden(false);
+ }
+
+ /**
+ * Executes when cascading project is set. Default implementation compares cascading and current value.
+ * If values are not equal - mark property as overridden.
+ */
+ protected void onCascadingProjectSet() {
+ setOverridden(allowOverrideValue(getCascadingValue(), getValue()));
+ }
}
+
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java
index b171edd..76e3e84 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java
@@ -67,4 +67,13 @@ public class ExternalProjectProperty<T> extends BaseProjectProperty<T> {
protected boolean updateOriginalValue(T value, T cascadingValue) {
return isModified() && super.updateOriginalValue(value, cascadingValue);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onCascadingProjectSet() {
+ setOverridden(isModified());
+ }
}
+
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java
index f2bdbea..52ce352 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/SCMProjectProperty.java
@@ -31,8 +31,19 @@ public class SCMProjectProperty extends BaseProjectProperty<SCM> {
super(job);
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public SCM getDefaultValue() {
return new NullSCM();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean returnOriginalValue() {
+ return isOverridden() || (null != getOriginalValue() && !getDefaultValue().equals(getOriginalValue()));
+ }
}
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java
index 84e4eb5..9b3a006 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/TriggerProjectProperty.java
@@ -34,4 +34,15 @@ public class TriggerProjectProperty extends BaseProjectProperty<Trigger> {
protected void clearOriginalValue(Trigger originalValue) {
setOriginalValue(originalValue, false);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onCascadingProjectRemoved() {
+ if (isOverridden() && null != getValue()) {
+ getValue().stop();
+ resetValue();
+ }
+ }
}
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/BaseProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/BaseProjectPropertyTest.java
index 7b495d8..8a61150 100644
--- a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/BaseProjectPropertyTest.java
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/BaseProjectPropertyTest.java
@@ -36,8 +36,10 @@ public class BaseProjectPropertyTest {
private final String propertyKey = "propertyKey";
private BaseProjectProperty property;
+ private BaseProjectProperty parentProperty;
private FreeStyleProjectMock project;
private FreeStyleProjectMock parent;
+ private String parentPropertyValue = "parentValue";
@Before
public void setUp() {
@@ -46,6 +48,10 @@ public class BaseProjectPropertyTest {
property = new BaseProjectProperty(project);
property.setKey(propertyKey);
+ parentProperty = new BaseProjectProperty(parent);
+ parentProperty.setKey(propertyKey);
+ parentProperty.setValue(parentPropertyValue);
+ parent.putProjectProperty(propertyKey, parentProperty);
}
/**
@@ -122,7 +128,7 @@ public class BaseProjectPropertyTest {
*/
@Test
public void testGetCascadingValue() {
- String parentValue = "parentValue";
+ parentProperty.setValue(null);
//If project doesn't have cascading project - default value is used as cascading value.
assertEquals(property.getDefaultValue(), property.getCascadingValue());
@@ -132,14 +138,10 @@ public class BaseProjectPropertyTest {
//If project has cascading project and cascading value is not set - default value is used.
assertEquals(property.getDefaultValue(), property.getCascadingValue());
- BaseProjectProperty parentProperty = new BaseProjectProperty(parent);
- parentProperty.setKey(propertyKey);
- parentProperty.setValue(parentValue);
- parent.putProjectProperty(propertyKey, parentProperty);
project.setCascadingProject(parent);
property = new BaseProjectProperty(project);
property.setKey(propertyKey);
- property.setValue(parentValue);
+ property.setValue(parentPropertyValue);
//If project has cascading project and cascading value is set - property value will be used.
assertEquals(parentProperty.getOriginalValue(), property.getCascadingValue());
}
@@ -242,9 +244,6 @@ public class BaseProjectPropertyTest {
*/
@Test
public void testSetValue() {
- BaseProjectProperty property = new BaseProjectProperty(project);
- property.setKey(propertyKey);
- property.setValue(null);
//If project doesn't have cascading - default boolean value is used for propertyOverridden flag
assertFalse(property.isOverridden());
assertNull(property.getOriginalValue());
@@ -255,11 +254,6 @@ public class BaseProjectPropertyTest {
assertFalse(property.isOverridden());
assertEquals(value, property.getOriginalValue());
- String parentValue = "equalValue";
- BaseProjectProperty parentProperty = new BaseProjectProperty(parent);
- parentProperty.setKey(propertyKey);
- parentProperty.setValue(parentValue);
- parent.putProjectProperty(propertyKey, parentProperty);
project.setCascadingProject(parent);
//If value set to null, need to check whether default value is equals to cascading
@@ -272,7 +266,7 @@ public class BaseProjectPropertyTest {
//Check whether current value is not null, after setting equal-to-cascading value current will be null
assertNotNull(property.getOriginalValue());
assertTrue(property.isOverridden());
- property.setValue(parentValue);
+ property.setValue(parentPropertyValue);
//Reset current property to null
assertNull(property.getOriginalValue());
//Cascading value is equal to current - reset flag to false.
@@ -343,28 +337,74 @@ public class BaseProjectPropertyTest {
*/
@Test
public void testGetValue() {
- Integer propertyValue = 10;
- property.setValue(propertyValue);
+ property.setValue(parentPropertyValue);
//if value is not null - return it
- assertEquals(propertyValue, property.getValue());
+ assertEquals(parentPropertyValue, property.getValue());
property.setValue(null);
assertNull(property.getValue());
- BaseProjectProperty parentProperty = new BaseProjectProperty(parent);
- parentProperty.setKey(propertyKey);
- parentProperty.setValue(propertyValue);
- parent.putProjectProperty(propertyKey, parentProperty);
-
+ parentProperty.setValue(parentPropertyValue);
project.setCascadingProject(parent);
property = new BaseProjectProperty(project);
property.setKey(propertyKey);
//if current value is null and is not overridden value, take from cascading
assertNull(property.getOriginalValue());
- assertEquals(propertyValue, property.getValue());
+ assertEquals(parentPropertyValue, property.getValue());
property.setOverridden(true);
//Property is overridden - return current value even if it is null.
assertNull(property.getOriginalValue());
assertNull(property.getValue());
}
+
+ /**
+ * Verify {@link BaseProjectProperty#onCascadingProjectRemoved()} method.
+ */
+ @Test
+ public void testOnCascadingProjectRemoved() {
+ //Overridden flag should be set to false when cascading project was removed
+ property.setOverridden(true);
+ property.onCascadingProjectRemoved();
+ assertFalse(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#onCascadingProjectRemoved()} method.
+ */
+ @Test
+ public void testOnCascadingProjectSet() {
+ property.setValue(parentPropertyValue);
+ project.setCascadingProject(parent);
+ //If parent value equals to current value - isOverridden flag should be set to false.
+ property.setOverridden(true);
+ assertTrue(property.isOverridden());
+ assertFalse(property.allowOverrideValue(parentProperty.getOriginalValue(), property.getValue()));
+ property.onCascadingProjectSet();
+ assertFalse(property.isOverridden());
+
+ property.setValue("newValue");
+ assertTrue(property.allowOverrideValue(parentProperty.getOriginalValue(), property.getValue()));
+ property.onCascadingProjectSet();
+ assertTrue(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#onCascadingProjectChanged()} method.
+ */
+ @Test
+ public void testOnCascadingProjectChanged() {
+ //Overridden flag should be set to false when cascading project was removed
+ property.setOverridden(true);
+ property.onCascadingProjectChanged();
+ assertFalse(property.isOverridden());
+
+ property.setValue(parentPropertyValue);
+ project.setCascadingProject(parent);
+ //If parent value equals to current value - isOverridden flag should be set to false.
+ property.setOverridden(true);
+ assertTrue(property.isOverridden());
+ assertFalse(property.allowOverrideValue(parentProperty.getOriginalValue(), property.getValue()));
+ property.onCascadingProjectChanged();
+ assertFalse(property.isOverridden());
+ }
}
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ExternalProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ExternalProjectPropertyTest.java
index a8f62a9..83dd24e 100644
--- a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ExternalProjectPropertyTest.java
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ExternalProjectPropertyTest.java
@@ -70,6 +70,22 @@ public class ExternalProjectPropertyTest {
assertTrue(property.isModified());
assertFalse(property.updateOriginalValue(new Object(), new Object()));
assertTrue(property.updateOriginalValue(new Object(), project));
+ }
+ /**
+ * Verify {@link ExternalProjectProperty#onCascadingProjectSet()} method.
+ */
+ @Test
+ public void testOnCascadingProjectSet() {
+ assertFalse(property.isModified());
+ assertFalse(property.isOverridden());
+ //When cascading project was set, isModified should equal to isOverridden
+ property.onCascadingProjectSet();
+ assertEquals(property.isModified(), property.isOverridden());
+
+ property.setModified(Boolean.TRUE);
+ property.onCascadingProjectSet();
+ assertTrue(property.isModified());
+ assertEquals(property.isModified(), property.isOverridden());
}
}
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 b5e4e41..6ee0bb5 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
@@ -15,39 +15,12 @@
package org.eclipse.hudson.api.model.project.property;
-import antlr.ANTLRException;
-import hudson.FilePath;
-import hudson.Launcher;
-import hudson.matrix.Axis;
-import hudson.matrix.AxisList;
-import hudson.model.AbstractBuild;
-import hudson.model.AbstractProject;
-import hudson.model.BuildListener;
import hudson.model.FreeStyleProjectMock;
-import hudson.model.TaskListener;
-import hudson.scm.ChangeLogParser;
-import hudson.scm.NullSCM;
-import hudson.scm.PollingResult;
-import hudson.scm.SCM;
-import hudson.scm.SCMRevisionState;
-import hudson.tasks.JavadocArchiver;
import hudson.tasks.LogRotator;
-import hudson.tasks.Shell;
-import hudson.triggers.TimerTrigger;
-import hudson.triggers.Trigger;
-import hudson.util.DescribableList;
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.fail;
+import static junit.framework.Assert.*;
/**
* Contains test-cases for IProjectProperty and its' implementations.
@@ -107,26 +80,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testSCMProjectPropertyConstructor() {
- try {
- new SCMProjectProperty(null);
- fail("Null should be handled by SCMProjectProperty constructor.");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
- }
- }
-
- @Test
- public void testTriggerProjectPropertyConstructor() {
- try {
- new TriggerProjectProperty(null);
- fail("Null should be handled by TriggerProjectProperty constructor.");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
- }
- }
-
- @Test
public void testBooleanProjectPropertyPrepareValue() {
//Boolean property acts as BaseProperty
BaseProjectProperty property = new BooleanProjectProperty(project);
@@ -165,15 +118,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testSCMProjectPropertyPrepareValue() {
- //Boolean property acts as BaseProperty
- BaseProjectProperty property = new SCMProjectProperty(project);
- assertNull(property.prepareValue(null));
- SCM value = new NullSCM();
- assertEquals(value, property.prepareValue(value));
- }
-
- @Test
public void testStringProjectPropertyGetDefaultValue() {
BaseProjectProperty property = new StringProjectProperty(project);
assertNull(property.getDefaultValue());
@@ -198,12 +142,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testScmProjectPropertyGetDefaultValue() {
- BaseProjectProperty property = new SCMProjectProperty(project);
- assertEquals(new NullSCM(), property.getDefaultValue());
- }
-
- @Test
public void testBooleanProjectPropertyAllowOverrideValue() {
BaseProjectProperty property = new BooleanProjectProperty(project);
assertFalse(property.allowOverrideValue(null, null));
@@ -244,15 +182,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testSCMProjectPropertyAllowOverrideValue() {
- BaseProjectProperty property = new SCMProjectProperty(project);
- assertFalse(property.allowOverrideValue(null, null));
- assertTrue(property.allowOverrideValue(new NullSCM(), null));
- assertTrue(property.allowOverrideValue(null, new NullSCM()));
- assertTrue(property.allowOverrideValue(new NullSCM(), new FakeSCM()));
- }
-
- @Test
public void testIntegerProjectPropertyGetOriginalValue() {
int value = 10;
BaseProjectProperty property = new IntegerProjectProperty(project);
@@ -289,65 +218,4 @@ public class ProjectPropertyTest {
property.setValue(value);
assertEquals(value, property.getOriginalValue());
}
-
- @Test
- public void testScmProjectPropertyGetOriginalValue() {
- SCM value = new NullSCM();
- BaseProjectProperty property = new SCMProjectProperty(project);
- property.setKey(propertyKey);
- property.setValue(value);
- assertEquals(value, property.getOriginalValue());
- }
-
- /**
- * Test 1updateOriginalValue method for TriggerProjectProperty.
- *
- * @throws ANTLRException if any
- */
- @Test
- public void testTriggerProjectPropertyUpdateOriginalValue() throws ANTLRException {
- TriggerProjectProperty property = new TriggerProjectProperty(project);
- Trigger originalTrigger = new TimerTrigger("* * * * *");
- Trigger cascadingTrigger = new TimerTrigger("* * * * *");
- property.updateOriginalValue(originalTrigger, cascadingTrigger);
- //Property isn't overridden because of values equal.
- assertFalse(property.isOverridden());
- //If trigger property value equals to cascading be sure that sets original value instead of cascading.
- assertEquals(property.getOriginalValue(), originalTrigger);
-
- cascadingTrigger = new TimerTrigger("*/2 * * * *");
- property.updateOriginalValue(originalTrigger, cascadingTrigger);
- assertTrue(property.isOverridden());
- assertEquals(property.getOriginalValue(), originalTrigger);
- }
-
- private class FakeSCM extends SCM {
- @Override
- public SCMRevisionState calcRevisionsFromBuild(AbstractBuild<?, ?> build, Launcher launcher,
- TaskListener listener)
- throws IOException, InterruptedException {
- return null;
- }
-
- @Override
- protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project, Launcher launcher,
- FilePath workspace, TaskListener listener,
- SCMRevisionState baseline)
- throws IOException, InterruptedException {
- return null;
- }
-
- @Override
- public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace,
- BuildListener listener,
- File changelogFile) throws IOException, InterruptedException {
- return false;
- }
-
- @Override
- public ChangeLogParser createChangeLogParser() {
- return null;
- }
- }
-
}
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/SCMProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/SCMProjectPropertyTest.java
new file mode 100644
index 0000000..74b44c3
--- /dev/null
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/SCMProjectPropertyTest.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ *
+ * 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 org.eclipse.hudson.api.model.project.property;
+
+import hudson.FilePath;
+import hudson.Launcher;
+import hudson.model.AbstractBuild;
+import hudson.model.AbstractProject;
+import hudson.model.BuildListener;
+import hudson.model.FreeStyleProjectMock;
+import hudson.model.TaskListener;
+import hudson.scm.ChangeLogParser;
+import hudson.scm.NullSCM;
+import hudson.scm.PollingResult;
+import hudson.scm.SCM;
+import hudson.scm.SCMRevisionState;
+import java.io.File;
+import java.io.IOException;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
+/**
+ * Contains test-cases for {@link SCMProjectProperty}.
+ * <p/>
+ * Date: 11/17/11
+ *
+ * @author Nikita Levyankov
+ */
+public class SCMProjectPropertyTest {
+
+ private SCMProjectProperty property;
+ private FreeStyleProjectMock project;
+
+ @Before
+ public void setUp() {
+ project = new FreeStyleProjectMock("project");
+ final String propertyKey = "propertyKey";
+ property = new SCMProjectProperty(project);
+ property.setKey(propertyKey);
+ }
+
+ /**
+ * Verify constructor
+ */
+ @Test
+ public void testConstructor() {
+ try {
+ new SCMProjectProperty(null);
+ fail("Null should be handled by SCMProjectProperty constructor.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ }
+
+ /**
+ * Verify {@link SCMProjectProperty#getDefaultValue()} method.
+ */
+ @Test
+ public void testGetDefaultValue() {
+ assertEquals(new NullSCM(), property.getDefaultValue());
+ }
+
+ /**
+ * Verify {@link SCMProjectProperty#returnOriginalValue()} method.
+ */
+ @Test
+ public void testReturnOriginalValue() {
+ //If property is marked as overridden or original value is not null and not equals to default value,
+ //than original should be used.
+ property.setOverridden(true);
+ assertTrue(property.returnOriginalValue());
+ property.setOriginalValue(new FakeSCM(), false);
+ assertTrue(property.returnOriginalValue());
+
+ //If property is not marked as overridden and original value is null or equals to default value - use cascading.
+ property.setOriginalValue(property.getDefaultValue(), false);
+ assertFalse(property.returnOriginalValue());
+ property.setOriginalValue(null, false);
+ assertFalse(property.returnOriginalValue());
+
+ }
+
+ private class FakeSCM extends SCM {
+ @Override
+ public SCMRevisionState calcRevisionsFromBuild(AbstractBuild<?, ?> build, Launcher launcher,
+ TaskListener listener)
+ throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project, Launcher launcher,
+ FilePath workspace, TaskListener listener,
+ SCMRevisionState baseline)
+ throws IOException, InterruptedException {
+ return null;
+ }
+
+ @Override
+ public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace,
+ BuildListener listener,
+ File changelogFile) throws IOException, InterruptedException {
+ return false;
+ }
+
+ @Override
+ public ChangeLogParser createChangeLogParser() {
+ return null;
+ }
+ }
+
+}
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/TriggerProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/TriggerProjectPropertyTest.java
new file mode 100644
index 0000000..b0f9c6a
--- /dev/null
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/TriggerProjectPropertyTest.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ *
+ * 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 org.eclipse.hudson.api.model.project.property;
+
+import antlr.ANTLRException;
+import hudson.model.FreeStyleProjectMock;
+import hudson.triggers.TimerTrigger;
+import hudson.triggers.Trigger;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
+/**
+ * Contains test-cases for {@link TriggerProjectProperty}.
+ * <p/>
+ * Date: 11/17/11
+ *
+ * @author Nikita Levyankov
+ */
+public class TriggerProjectPropertyTest {
+
+ private TriggerProjectProperty property;
+
+ @Before
+ public void setUp() {
+ final String propertyKey = "propertyKey";
+ FreeStyleProjectMock project = new FreeStyleProjectMock("project");
+ property = new TriggerProjectProperty(project);
+ property.setKey(propertyKey);
+ }
+
+ @Test
+ public void testConstructor() {
+ try {
+ new TriggerProjectProperty(null);
+ fail("Null should be handled by TriggerProjectProperty constructor.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ }
+
+ /**
+ * Verify {@link TriggerProjectProperty#clearOriginalValue(hudson.triggers.Trigger)} method.
+ *
+ * @throws antlr.ANTLRException if any
+ */
+ @Test
+ public void testClearOriginalValue() throws ANTLRException {
+ //Overridden flag should be cleared to false. Pre-set true value
+ property.setOverridden(true);
+ assertTrue(property.isOverridden());
+ Trigger trigger = new TimerTrigger("* * * * *");
+ property.clearOriginalValue(trigger);
+ //Original value should be set with overridden flag == false
+ assertFalse(property.isOverridden());
+ assertTrue(trigger == property.getOriginalValue());
+ }
+
+
+ /**
+ * Test updateOriginalValue method for TriggerProjectProperty.
+ *
+ * @throws antlr.ANTLRException if any
+ */
+ @Test
+ public void testUpdateOriginalValue() throws ANTLRException {
+ Trigger originalTrigger = new TimerTrigger("* * * * *");
+ Trigger cascadingTrigger = new TimerTrigger("* * * * *");
+ property.updateOriginalValue(originalTrigger, cascadingTrigger);
+ //Property isn't overridden because of values equal.
+ assertFalse(property.isOverridden());
+ //If trigger property value equals to cascading be sure that sets original value instead of cascading.
+ assertEquals(property.getOriginalValue(), originalTrigger);
+
+ cascadingTrigger = new TimerTrigger("*/2 * * * *");
+ property.updateOriginalValue(originalTrigger, cascadingTrigger);
+ assertTrue(property.isOverridden());
+ assertEquals(property.getOriginalValue(), originalTrigger);
+ }
+
+ /**
+ * Verify {@link TriggerProjectProperty#onCascadingProjectRemoved()} method.
+ *
+ * @throws antlr.ANTLRException if any
+ */
+ @Test
+ public void testOnCascadingProjectRemoved() throws ANTLRException {
+ Trigger trigger = new TimerTrigger("* * * * *");
+ property.setOriginalValue(trigger, false);
+ assertTrue(trigger == property.getOriginalValue());
+ assertFalse(property.isOverridden());
+ property.onCascadingProjectRemoved();
+ assertFalse(property.isOverridden());
+ assertTrue(trigger == property.getOriginalValue());
+ }
+
+}