summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-24 09:38:36 (EST)
committer Winston Prakash2011-12-01 20:47:28 (EST)
commitce9c4600a31b6b6a8f703c171b22b67a5d414b53 (patch)
treec93b967b1f40c5b3a0a2cf1f1301350b6dcfeaf8
parent4f6a15c2a510be47a0d732a3ab4355b42c919fb3 (diff)
downloadorg.eclipse.hudson.core-ce9c4600a31b6b6a8f703c171b22b67a5d414b53.zip
org.eclipse.hudson.core-ce9c4600a31b6b6a8f703c171b22b67a5d414b53.tar.gz
org.eclipse.hudson.core-ce9c4600a31b6b6a8f703c171b22b67a5d414b53.tar.bz2
Introduce set of ProjectProperties tests based on ProjectPropertyTest class. Implement test cases for CopyOnWriteListProperty, BaseProjectProperty, DescribableListProjectProperty, ExternalProjectProperty. A few fixes.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/util/CascadingUtil.java8
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java5
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectProperty.java4
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java2
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/AxisListProjectPropertyTest.java69
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/BaseProjectPropertyTest.java370
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectPropertyTest.java120
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectPropertyTest.java141
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ExternalProjectPropertyTest.java75
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java410
10 files changed, 787 insertions, 417 deletions
diff --git a/hudson-core/src/main/java/hudson/util/CascadingUtil.java b/hudson-core/src/main/java/hudson/util/CascadingUtil.java
index fc72a72..22b822e 100644
--- a/hudson-core/src/main/java/hudson/util/CascadingUtil.java
+++ b/hudson-core/src/main/java/hudson/util/CascadingUtil.java
@@ -483,13 +483,13 @@ public class CascadingUtil {
//Iterate through cascading children and recursively update property for each child.
if (null != cascadingChildrenNames) {
for (String childName : cascadingChildrenNames) {
- AbstractProject childJob = (AbstractProject) Hudson.getInstance().getItem(childName);
+ Job childJob = (Job) Hudson.getInstance().getItem(childName);
//Check only direct children in order to avoid deep checking for properties overridden properties.
if (null != childJob && StringUtils.equals(job.getName(), childJob.getCascadingProjectName())) {
CopyOnWriteListProjectProperty childProperty = getCopyOnWriteListProjectProperty(childJob, key);
//If child value is equal to parent - mark this value as unmodified.
- if (!projectProperty.allowOverrideValue(childProperty.getValue(), pdProperties)) {
- projectProperty.setOverridden(false);
+ if (!childProperty.allowOverrideValue(childProperty.getValue(), pdProperties)) {
+ childProperty.setOverridden(false);
} else if (!childProperty.isOverridden()) {
//If child property was not overridden, update this property and cascading children if any.
setParameterDefinitionProperties(childJob, key, parameterDefinitionProperties);
@@ -498,4 +498,4 @@ public class CascadingUtil {
}
}
}
-}
+} \ No newline at end of file
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 9e796ed..4e8f5f7 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
@@ -151,16 +151,17 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
*
* @param value new value to be set.
* @param cascadingValue current cascading value.
- * @return true - if property was updated, false - otherwise.
+ * @return true - if property was updated, false - otherwise if value was cleared.
*/
protected boolean updateOriginalValue(T value, T cascadingValue) {
T candidateValue = null == value ? getDefaultValue() : value;
if (allowOverrideValue(cascadingValue, candidateValue)) {
setOriginalValue(value, true);
+ return true;
} else {
clearOriginalValue(value);
+ return false;
}
- return true;
}
/**
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectProperty.java
index 1c3c5ac..78a894a 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectProperty.java
@@ -18,7 +18,7 @@ import hudson.util.CopyOnWriteList;
import org.eclipse.hudson.api.model.IJob;
/**
- * Project property for CopyOnWriteList
+ * Project property for {@link CopyOnWriteList}
* <p/>
* Date: 11/1/11
*
@@ -39,7 +39,7 @@ public class CopyOnWriteListProjectProperty extends BaseProjectProperty<CopyOnWr
@Override
protected boolean returnOriginalValue() {
- return isOverridden() || (null != getOriginalValue() && !getOriginalValue().isEmpty());
+ return isOverridden() || !getOriginalValue().isEmpty();
}
@Override
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 1dc3aae..02884c1 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
@@ -46,7 +46,7 @@ public class DescribableListProjectProperty extends BaseProjectProperty<Describa
@Override
protected boolean returnOriginalValue() {
- return isOverridden() || (null != getOriginalValue() && !getOriginalValue().isEmpty());
+ return isOverridden() || !getOriginalValue().isEmpty();
}
@Override
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/AxisListProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/AxisListProjectPropertyTest.java
new file mode 100644
index 0000000..dd14dcc
--- /dev/null
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/AxisListProjectPropertyTest.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ *
+ * 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.matrix.AxisList;
+import hudson.model.FreeStyleProjectMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+
+/**
+ * Contains test-cases for {@link AxisListProjectProperty}.
+ * <p/>
+ * Date: 11/4/11
+ *
+ * @author Nikita Levyankov
+ */
+public class AxisListProjectPropertyTest {
+
+ private AxisListProjectProperty property;
+
+ @Before
+ public void setUp() {
+ final String propertyKey = "propertyKey";
+ FreeStyleProjectMock project = new FreeStyleProjectMock("project");
+ property = new AxisListProjectProperty(project);
+ property.setKey(propertyKey);
+ }
+
+ /**
+ * Verify constructor
+ */
+ @Test
+ public void testConstructor() {
+ try {
+ new AxisListProjectProperty(null);
+ fail("Null should be handled by AxisListProjectProperty constructor.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ }
+
+ /**
+ * Verify {@link CopyOnWriteListProjectProperty#getDefaultValue()} method.
+ */
+ @Test
+ public void testAxisListProjectPropertyGetDefaultValue() {
+ AxisList defaultValue = property.getDefaultValue();
+ assertNotNull(defaultValue);
+ assertTrue(defaultValue.isEmpty());
+ }
+}
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
new file mode 100644
index 0000000..7b495d8
--- /dev/null
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/BaseProjectPropertyTest.java
@@ -0,0 +1,370 @@
+/*******************************************************************************
+ *
+ * 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.matrix.Axis;
+import hudson.matrix.AxisList;
+import hudson.model.FreeStyleProjectMock;
+import hudson.tasks.JavadocArchiver;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
+/**
+ * Contains test-cases for {@link BaseProjectProperty}.
+ * <p/>
+ * Date: 11/4/11
+ *
+ * @author Nikita Levyankov
+ */
+@SuppressWarnings("unchecked")
+public class BaseProjectPropertyTest {
+ private final String propertyKey = "propertyKey";
+
+ private BaseProjectProperty property;
+ private FreeStyleProjectMock project;
+ private FreeStyleProjectMock parent;
+
+ @Before
+ public void setUp() {
+ parent = new FreeStyleProjectMock("parent");
+ project = new FreeStyleProjectMock("project");
+
+ property = new BaseProjectProperty(project);
+ property.setKey(propertyKey);
+ }
+
+ /**
+ * Verify constructor
+ */
+ @Test
+ public void testConstructor() {
+ try {
+ new BaseProjectProperty(null);
+ fail("Null should be handled by BaseProjectProperty constructor.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ assertNotNull(property.getJob());
+ assertEquals(project, property.getJob());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#setJob(org.hudsonci.api.model.IJob)} method.
+ */
+ @Test
+ public void testSetJob() {
+ try {
+ property.setJob(null);
+ fail("Null is not allowed.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ assertNotNull(property.getJob());
+ assertEquals(project, property.getJob());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#prepareValue(Object)} method.
+ */
+ @Test
+ public void testPrepareValue() {
+ //BaseProject property doesn't perform any changes with value.
+ assertNull(property.prepareValue(null));
+ Object value = new Object();
+ assertTrue(value == property.prepareValue(value));
+ }
+
+
+ /**
+ * Verify {@link BaseProjectProperty#getDefaultValue()} method.
+ */
+ @Test
+ public void testGetDefaultValue() {
+ assertNull(property.getDefaultValue());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#allowOverrideValue(Object, Object)} method.
+ */
+ @Test
+ public void testAllowOverrideValue() {
+ assertFalse(property.allowOverrideValue(null, null));
+ assertTrue(property.allowOverrideValue(new Object(), null));
+ assertTrue(property.allowOverrideValue(null, new Object()));
+ //Test properties that don't have correct equals methods
+ assertFalse(property.allowOverrideValue(new JavadocArchiver("", false), new JavadocArchiver("", false)));
+ assertTrue(property.allowOverrideValue(new JavadocArchiver("", true), new JavadocArchiver("", false)));
+ //Object with transient filds should be taken into account
+ assertTrue(property.allowOverrideValue(new AxisList(new Axis("DB", "mysql")), new AxisList()));
+ assertTrue(property.allowOverrideValue(new AxisList(new Axis("DB", "mysql")),
+ new AxisList(new Axis("DB", "mysql", "mssql"))));
+ assertTrue(property.allowOverrideValue(new AxisList(new Axis("DB", "mysql")),
+ new AxisList(new Axis("DB", "mssql"))));
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#getCascadingValue()} method.
+ */
+ @Test
+ public void testGetCascadingValue() {
+ String parentValue = "parentValue";
+ //If project doesn't have cascading project - default value is used as cascading value.
+ assertEquals(property.getDefaultValue(), property.getCascadingValue());
+
+ project.setCascadingProject(parent);
+ property = new BaseProjectProperty(project);
+ property.setKey(propertyKey);
+ //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);
+ //If project has cascading project and cascading value is set - property value will be used.
+ assertEquals(parentProperty.getOriginalValue(), property.getCascadingValue());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#getOriginalValue()} method.
+ */
+ @Test
+ public void testGetOriginalValue() {
+ assertNull(property.getOriginalValue());
+ Object value = new Object();
+ property.setKey(propertyKey);
+ property.setValue(value);
+ assertEquals(value, property.getOriginalValue());
+ property.setValue(null);
+ assertNull(property.getOriginalValue());
+ }
+
+ /**
+ * Property should have not null property key.
+ */
+ @Test
+ public void testNullPropertyKey() {
+ BaseProjectProperty property = new BaseProjectProperty(project);
+ try {
+ property.setValue("value");
+ fail("PropertyKey shouldn't be null while calling setValue");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_PROPERTY_KEY_EXCEPTION, e.getMessage());
+ }
+ try {
+ property.getCascadingValue();
+ fail("PropertyKey shouldn't be null while calling getCascadingValue()");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_PROPERTY_KEY_EXCEPTION, e.getMessage());
+ }
+ try {
+ property.getValue();
+ fail("PropertyKey shouldn't be null while calling getValue()");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_PROPERTY_KEY_EXCEPTION, e.getMessage());
+ }
+
+ property.setKey("key");
+ try {
+ property.setValue("value");
+ property.getCascadingValue();
+ property.getValue();
+ } catch (Exception e) {
+ fail("PropertyKey is valid");
+ }
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#resetValue()} method.
+ */
+ @Test
+ public void testResetValue() {
+ property.setKey(propertyKey);
+ property.setValue(new Object());
+ property.setOverridden(true);
+ assertNotNull(property.getOriginalValue());
+ assertTrue(property.isOverridden());
+ property.resetValue();
+ assertNull(property.getOriginalValue());
+ assertFalse(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#setOverridden(boolean)}, {@link BaseProjectProperty#isOverridden()} methods.
+ */
+ @Test
+ public void testGetSetOverridden() {
+ //By default property isOverridden flag is set to false.
+ assertFalse(property.isOverridden());
+ //Test if flag is configured as expected. Set true/false values and check whether they are set correctly.
+ property.setOverridden(true);
+ assertTrue(property.isOverridden());
+ property.setOverridden(false);
+ assertFalse(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#returnOriginalValue()} method.
+ */
+ @Test
+ public void testReturnOriginalValue() {
+ //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());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#setValue(Object)} method.
+ */
+ @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());
+
+ Object value = 12345;
+ property.setValue(value);
+ //If project doesn't have cascading - default boolean value is used for propertyOverridden flag
+ 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
+ property.setValue(null);
+ assertTrue(property.isOverridden());
+ String overriddenValue = "newValue";
+ property.setValue(overriddenValue);
+ assertTrue(property.isOverridden());
+
+ //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);
+ //Reset current property to null
+ assertNull(property.getOriginalValue());
+ //Cascading value is equal to current - reset flag to false.
+ assertFalse(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#setOriginalValue(Object, boolean)} method.
+ */
+ @Test
+ public void testSetOriginalValue() {
+ Object originalValue = new Object();
+ //Prepare property original value and mark it as overridden
+ property.setOriginalValue(originalValue, true);
+ assertEquals(originalValue, property.getOriginalValue());
+ assertTrue(property.isOverridden());
+
+ //Prepare property original value and set overridden flag to false.
+ originalValue = new Object();
+ property.setOriginalValue(originalValue, false);
+ assertEquals(originalValue, property.getOriginalValue());
+ assertFalse(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#clearOriginalValue(Object)} method.
+ */
+ @Test
+ public void testClearOriginalValue() {
+ Object originalValue = new Object();
+ //Prepare property original value
+ property.setOriginalValue(originalValue, true);
+ assertEquals(originalValue, property.getOriginalValue());
+ assertTrue(property.isOverridden());
+ property.clearOriginalValue(null);
+ //original value should be null and not overridden.
+ assertNull(property.getOriginalValue());
+ assertFalse(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#updateOriginalValue(Object, Object)} method.
+ */
+ @Test
+ public void testUpdateOriginalValue() {
+ Integer cascadingValue = 10;
+ Integer candidateValue = 11;
+ property.setOriginalValue(1, false);
+ assertFalse(property.isOverridden());
+ assertNotNull(property.getOriginalValue());
+ //If candidate value is not equal to cascading value - update original value and mark it as overridden
+ boolean result = property.updateOriginalValue(candidateValue, cascadingValue);
+ assertTrue(result);
+ assertTrue(property.isOverridden());
+ assertEquals(candidateValue, property.getOriginalValue());
+
+ //If candidate value is equal to cascading value - clear original value and mark it non-overridden
+ result = property.updateOriginalValue(cascadingValue, cascadingValue);
+ assertFalse(result);
+ assertFalse(property.isOverridden());
+ assertNull(property.getOriginalValue());
+
+
+ }
+
+ /**
+ * Verify {@link BaseProjectProperty#getValue()} method.
+ */
+ @Test
+ public void testGetValue() {
+ Integer propertyValue = 10;
+ property.setValue(propertyValue);
+ //if value is not null - return it
+ assertEquals(propertyValue, property.getValue());
+ property.setValue(null);
+ assertNull(property.getValue());
+
+ BaseProjectProperty parentProperty = new BaseProjectProperty(parent);
+ parentProperty.setKey(propertyKey);
+ parentProperty.setValue(propertyValue);
+ parent.putProjectProperty(propertyKey, parentProperty);
+
+ 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());
+
+ property.setOverridden(true);
+ //Property is overridden - return current value even if it is null.
+ assertNull(property.getOriginalValue());
+ assertNull(property.getValue());
+ }
+}
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectPropertyTest.java
new file mode 100644
index 0000000..ca6cdb0
--- /dev/null
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/CopyOnWriteListProjectPropertyTest.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ *
+ * 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.model.FreeStyleProjectMock;
+import hudson.util.CopyOnWriteList;
+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.assertTrue;
+import static junit.framework.Assert.fail;
+
+/**
+ * Contains test-cases for {@link CopyOnWriteListProjectProperty}.
+ * <p/>
+ * Date: 11/4/11
+ *
+ * @author Nikita Levyankov
+ */
+@SuppressWarnings("unchecked")
+public class CopyOnWriteListProjectPropertyTest {
+
+ private CopyOnWriteListProjectProperty property;
+
+ @Before
+ public void setUp() {
+ final String propertyKey = "propertyKey";
+ FreeStyleProjectMock project = new FreeStyleProjectMock("project");
+ property = new CopyOnWriteListProjectProperty(project);
+ property.setKey(propertyKey);
+ }
+
+ /**
+ * Verify constructor
+ */
+ @Test
+ public void testConstructor() {
+ try {
+ new CopyOnWriteListProjectProperty(null);
+ fail("Null should be handled by CopyOnWriteListProjectProperty constructor.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ }
+
+ /**
+ * Verify {@link CopyOnWriteListProjectProperty#getDefaultValue()} method.
+ */
+ @Test
+ public void testGetDefaultValue() {
+ CopyOnWriteList defaultValue = property.getDefaultValue();
+ assertNotNull(defaultValue);
+ //Default value should be initialized and stored as original value
+ assertTrue(property.getOriginalValue() == defaultValue);
+ assertFalse(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link CopyOnWriteListProjectProperty#getOriginalValue()} method.
+ */
+ @Test
+ public void testGetOriginalValue() {
+ //Original value is not initialized. Default value will be used instead. Shouldn't be null
+ CopyOnWriteList originalValue = property.getOriginalValue();
+ assertNotNull(originalValue);
+ //Value was set, so return it without modification
+ assertTrue(originalValue == property.getOriginalValue());
+ }
+
+ /**
+ * Verify {@link CopyOnWriteListProjectProperty#returnOriginalValue()} method.
+ */
+ @Test
+ public void testReturnOriginalValue() {
+ //Return cascading is property is not overridden and is empty.
+ assertFalse(property.returnOriginalValue());
+
+ //Return properties' originalValue if it was overridden
+ property.setOverridden(true);
+ assertTrue(property.returnOriginalValue());
+ //If property has not empty value - return it (basically for non-cascadable projects)
+ property.setOriginalValue(new CopyOnWriteList(Arrays.asList(new Object())), false);
+ assertTrue(property.returnOriginalValue());
+ //If property has not empty value and was overridden - return it
+ property.setOriginalValue(new CopyOnWriteList(Arrays.asList(new Object())), true);
+ assertTrue(property.returnOriginalValue());
+ }
+
+ /**
+ * Verify {@link CopyOnWriteListProjectProperty#clearOriginalValue(hudson.util.CopyOnWriteList)} method.
+ */
+ @Test
+ public void testClearOriginalValue() {
+ //Overridden flag should be cleared to false. Pre-set true value
+ property.setOverridden(true);
+ assertTrue(property.isOverridden());
+ CopyOnWriteList originalValue = new CopyOnWriteList(Arrays.asList(new Object()));
+ property.clearOriginalValue(originalValue);
+ //Original value should be set with overridden flag == false
+ assertFalse(property.isOverridden());
+ assertTrue(originalValue == property.getOriginalValue());
+ }
+}
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectPropertyTest.java
new file mode 100644
index 0000000..447b887
--- /dev/null
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectPropertyTest.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ *
+ * 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.model.FreeStyleProjectMock;
+import hudson.tasks.Shell;
+import hudson.util.DescribableList;
+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.assertTrue;
+import static junit.framework.Assert.fail;
+
+/**
+ * Contains test-cases for {@link DescribableListProjectProperty}.
+ * <p/>
+ * Date: 11/4/11
+ *
+ * @author Nikita Levyankov
+ */
+@SuppressWarnings("unchecked")
+public class DescribableListProjectPropertyTest {
+
+ private FreeStyleProjectMock project;
+ private FreeStyleProjectMock parent;
+ private DescribableListProjectProperty property;
+
+ @Before
+ public void setUp() {
+ project = new FreeStyleProjectMock("project");
+ parent = new FreeStyleProjectMock("parent");
+
+ final String propertyKey = "propertyKey";
+ property = new DescribableListProjectProperty(project);
+ property.setKey(propertyKey);
+ }
+
+ /**
+ * Verify constructor
+ */
+ @Test
+ public void testConstructor() {
+ try {
+ new DescribableListProjectProperty(null);
+ fail("Null should be handled by DescribableListProjectProperty constructor.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ }
+
+ /**
+ * Verify {@link DescribableListProjectProperty#getDefaultValue()} method.
+ */
+ @Test
+ public void testGetDefaultValue() {
+ DescribableList defaultValue = property.getDefaultValue();
+ assertNotNull(defaultValue);
+ //Default value should be initialized and stored as original value
+ assertTrue(property.getOriginalValue() == defaultValue);
+ assertFalse(property.isOverridden());
+ }
+
+ /**
+ * Verify {@link CopyOnWriteListProjectProperty#getOriginalValue()} method.
+ */
+ @Test
+ public void testGetOriginalValue() {
+ //Original value is not initialized. Default value will be used instead. Shouldn't be null
+ DescribableList originalValue = property.getOriginalValue();
+ assertNotNull(originalValue);
+ //Value was set, so return it without modification
+ assertTrue(originalValue == property.getOriginalValue());
+ }
+
+ /**
+ * Verify {@link CopyOnWriteListProjectProperty#returnOriginalValue()} method.
+ */
+ @Test
+ public void testReturnOriginalValue() {
+ //Return cascading is property is not overridden and is empty.
+ assertFalse(property.returnOriginalValue());
+
+ //Return properties' originalValue if it was overridden
+ property.setOverridden(true);
+ assertTrue(property.returnOriginalValue());
+ //If property has not empty value - return it (basically for non-cascadable projects)
+ property.setOriginalValue(new DescribableList(project, Arrays.asList(new Object())), false);
+ assertTrue(property.returnOriginalValue());
+ //If property has not empty value and was overridden - return it
+ property.setOriginalValue(new DescribableList(project, Arrays.asList(new Object())), true);
+ assertTrue(property.returnOriginalValue());
+ }
+
+ /**
+ * Verify {@link CopyOnWriteListProjectProperty#allowOverrideValue(Object, Object)} method.
+ */
+ @Test
+ public void testAllowOverrideValue() {
+ //Don't need to override null values and equal lists
+ assertFalse(property.allowOverrideValue(null, null));
+ assertFalse(property.allowOverrideValue(new DescribableList(project), new DescribableList(project)));
+ //Don't need to override Describable lists which has same Describable#data values, even if owners are not equal.
+ assertFalse(property.allowOverrideValue(new DescribableList(project), new DescribableList(project)));
+ assertFalse(property.allowOverrideValue(new DescribableList(project), new DescribableList(parent)));
+ DescribableList describableList1 = new DescribableList(project,
+ Arrays.asList(new Shell("echo 'test3'"), new Shell("echo 'test2'")));
+ DescribableList describableList2 = new DescribableList(project,
+ Arrays.asList(new Shell("echo 'test2'"), new Shell("echo 'test3'")));
+ assertFalse(property.allowOverrideValue(describableList1, describableList2));
+
+ DescribableList describableList3 = new DescribableList(parent, describableList2.toList());
+ assertFalse(property.allowOverrideValue(describableList1, describableList3));
+
+ //Allow override if cascading or candidate are null
+ assertTrue(property.allowOverrideValue(null, new DescribableList(project)));
+ assertTrue(property.allowOverrideValue(new DescribableList(project), null));
+
+ assertTrue(property.allowOverrideValue(new DescribableList(project),
+ new DescribableList(project, Arrays.asList(new Shell("echo 'test1'")))));
+ assertTrue(property.allowOverrideValue(new DescribableList(project, Arrays.asList(new Shell("echo 'test1'"))),
+ new DescribableList(project)));
+ }
+
+}
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
new file mode 100644
index 0000000..a8f62a9
--- /dev/null
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ExternalProjectPropertyTest.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ *
+ * 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.model.FreeStyleProjectMock;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.*;
+
+/**
+ * Contains test-cases for {@link ExternalProjectProperty}.
+ * <p/>
+ * Date: 11/4/11
+ *
+ * @author Nikita Levyankov
+ */
+@SuppressWarnings("unchecked")
+public class ExternalProjectPropertyTest {
+
+ private ExternalProjectProperty property;
+ private FreeStyleProjectMock project;
+
+ @Before
+ public void setUp() {
+ project = new FreeStyleProjectMock("project");
+ final String propertyKey = "propertyKey";
+ property = new ExternalProjectProperty(project);
+ property.setKey(propertyKey);
+ }
+
+ /**
+ * Verify constructor
+ */
+ @Test
+ public void testConstructor() {
+ try {
+ new ExternalProjectProperty(null);
+ fail("Null should be handled by ExternalProjectProperty constructor.");
+ } catch (Exception e) {
+ assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
+ }
+ }
+
+ /**
+ * Verify {@link ExternalProjectProperty#updateOriginalValue(Object, Object)} method.
+ */
+ @Test
+ public void testUpdateOriginalValue() {
+ //If property is not modified, than it shouldn't be updated.
+ assertFalse(property.isModified());
+ assertFalse(property.updateOriginalValue(new Object(), new Object()));
+
+ //If property is modified, than BaseProjectProperty#updateOriginalValue method will be called.
+ //Result will be true, because in this case property value will be updated.
+ property.setModified(true);
+ assertTrue(property.isModified());
+ assertFalse(property.updateOriginalValue(new Object(), new Object()));
+ assertTrue(property.updateOriginalValue(new Object(), project));
+
+ }
+}
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 76c8c00..b5e4e41 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
@@ -59,29 +59,11 @@ import static junit.framework.Assert.fail;
@SuppressWarnings("unchecked")
public class ProjectPropertyTest {
private FreeStyleProjectMock project;
- private FreeStyleProjectMock parent;
private final String propertyKey = "propertyKey";
@Before
public void setUp() {
project = new FreeStyleProjectMock("project");
- parent = new FreeStyleProjectMock("parent");
- }
-
- /**
- * Verify all constructors for ProjectProperties hierarchy.
- */
- @Test
- public void testBaseProjectConstructor() {
- try {
- new BaseProjectProperty(null);
- fail("Null should be handled by BaseProjectProperty constructor.");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
- }
- BaseProjectProperty property = new BaseProjectProperty(project);
- assertNotNull(property.getJob());
- assertEquals(project, property.getJob());
}
@Test
@@ -125,26 +107,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testDescribableListProjectPropertyConstructor() {
- try {
- new DescribableListProjectProperty(null);
- fail("Null should be handled by DescribableListProjectProperty constructor.");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
- }
- }
-
- @Test
- public void testAxisListProjectPropertyConstructor() {
- try {
- new AxisListProjectProperty(null);
- fail("Null should be handled by AxisListProjectProperty constructor.");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
- }
- }
-
- @Test
public void testSCMProjectPropertyConstructor() {
try {
new SCMProjectProperty(null);
@@ -155,16 +117,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testExternalProjectPropertyConstructor() {
- try {
- new ExternalProjectProperty(null);
- fail("Null should be handled by ExternalProjectProperty constructor.");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
- }
- }
-
- @Test
public void testTriggerProjectPropertyConstructor() {
try {
new TriggerProjectProperty(null);
@@ -174,18 +126,6 @@ public class ProjectPropertyTest {
}
}
- /**
- * Checks prepareValue method.
- */
- @Test
- public void testBaseProjectPropertyPrepareValue() {
- //BaseProject property doesn't perform any changes with value.
- BaseProjectProperty property = new BaseProjectProperty(project);
- assertNull(property.prepareValue(null));
- Object value = new Object();
- assertEquals(value, property.prepareValue(value));
- }
-
@Test
public void testBooleanProjectPropertyPrepareValue() {
//Boolean property acts as BaseProperty
@@ -225,15 +165,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testAxisListProjectPropertyPrepareValue() {
- //Boolean property acts as BaseProperty
- BaseProjectProperty property = new AxisListProjectProperty(project);
- assertNull(property.prepareValue(null));
- AxisList value = new AxisList();
- assertEquals(value, property.prepareValue(value));
- }
-
- @Test
public void testSCMProjectPropertyPrepareValue() {
//Boolean property acts as BaseProperty
BaseProjectProperty property = new SCMProjectProperty(project);
@@ -242,15 +173,6 @@ public class ProjectPropertyTest {
assertEquals(value, property.prepareValue(value));
}
- /**
- * Verify getDefaultValue method.
- */
- @Test
- public void testBaseProjectPropertyGetDefaultValue() {
- BaseProjectProperty property = new BaseProjectProperty(project);
- assertNull(property.getDefaultValue());
- }
-
@Test
public void testStringProjectPropertyGetDefaultValue() {
BaseProjectProperty property = new StringProjectProperty(project);
@@ -276,38 +198,11 @@ public class ProjectPropertyTest {
}
@Test
- public void testAxisListProjectPropertyGetDefaultValue() {
- AxisListProjectProperty property = new AxisListProjectProperty(project);
- assertEquals(property.getDefaultValue().size(), 0);
- }
-
- @Test
- public void testDescribableListProjectPropertyGetDefaultValue() {
- BaseProjectProperty property = new DescribableListProjectProperty(project);
- assertNotNull(property.getDefaultValue());
- }
-
-
- @Test
- public void testScmtProjectPropertyGetDefaultValue() {
+ public void testScmProjectPropertyGetDefaultValue() {
BaseProjectProperty property = new SCMProjectProperty(project);
assertEquals(new NullSCM(), property.getDefaultValue());
}
- /**
- * Verify allowOverrideValue method.
- */
- @Test
- public void testBaseProjectPropertyAllowOverrideValue() {
- BaseProjectProperty property = new BaseProjectProperty(project);
- assertFalse(property.allowOverrideValue(null, null));
- assertTrue(property.allowOverrideValue(new Object(), null));
- assertTrue(property.allowOverrideValue(null, new Object()));
- //Test properties that don't have correct equals methods
- assertFalse(property.allowOverrideValue(new JavadocArchiver("", false), new JavadocArchiver("", false)));
- assertTrue(property.allowOverrideValue(new JavadocArchiver("", true), new JavadocArchiver("", false)));
- }
-
@Test
public void testBooleanProjectPropertyAllowOverrideValue() {
BaseProjectProperty property = new BooleanProjectProperty(project);
@@ -349,45 +244,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testDescribableListProjectPropertyAllowOverrideValue() throws IOException {
- BaseProjectProperty property = new DescribableListProjectProperty(project);
- //Don't need to override null values
- assertFalse(property.allowOverrideValue(null, null));
- //Allow override if cascading or candidate are null
- assertTrue(property.allowOverrideValue(new DescribableList(project), null));
- assertTrue(property.allowOverrideValue(null, new DescribableList(project)));
- //Don't need to override Describable lists which has same Describable#data values, even if owners are not equal.
- assertFalse(property.allowOverrideValue(new DescribableList(project), new DescribableList(project)));
- assertFalse(property.allowOverrideValue(new DescribableList(project), new DescribableList(parent)));
- DescribableList describableList1 = new DescribableList(project);
- DescribableList describableList2 = new DescribableList(project);
- describableList1.add(new Shell("echo 'test3'"));
- describableList1.add(new Shell("echo 'test2'"));
- describableList2.add(new Shell("echo 'test2'"));
- describableList2.add(new Shell("echo 'test3'"));
- assertFalse(property.allowOverrideValue(describableList1, describableList2));
-
- DescribableList describableList3 = new DescribableList(parent);
- describableList3.replaceBy(describableList2.toList());
- assertFalse(property.allowOverrideValue(describableList1, describableList3));
-
- describableList2.add(new Shell("echo 'test1'"));
- assertTrue(property.allowOverrideValue(describableList1, describableList2));
- }
-
- @Test
- public void testAxisListProjectPropertyAllowOverrideValue() {
- BaseProjectProperty property = new AxisListProjectProperty(project);
- assertFalse(property.allowOverrideValue(null, null));
- assertTrue(property.allowOverrideValue(new AxisList(), null));
- assertTrue(property.allowOverrideValue(null, new AxisList()));
- assertTrue(property.allowOverrideValue(new AxisList(new Axis("DB", "mysql")), new AxisList()));
- assertTrue(property.allowOverrideValue(new AxisList(new Axis("DB", "mysql")),
- new AxisList(new Axis("DB", "mysql", "mssql"))));
- assertTrue(property.allowOverrideValue(new AxisList(new Axis("DB", "mysql")),
- new AxisList(new Axis("DB", "mssql"))));
- }
- @Test
public void testSCMProjectPropertyAllowOverrideValue() {
BaseProjectProperty property = new SCMProjectProperty(project);
assertFalse(property.allowOverrideValue(null, null));
@@ -396,52 +252,6 @@ public class ProjectPropertyTest {
assertTrue(property.allowOverrideValue(new NullSCM(), new FakeSCM()));
}
-
- /**
- * Verify getCascadingValue method.
- */
- @Test
- public void testBaseProjectPropertyGetCascadingValue() {
- String parentValue = "parentValue";
-
- BaseProjectProperty property = new BaseProjectProperty(project);
- property.setKey(propertyKey);
- //If project doesn't have cascading project - default value is used as cascading value.
- assertEquals(property.getDefaultValue(), property.getCascadingValue());
-
- project.setCascadingProject(parent);
- property = new BaseProjectProperty(project);
- property.setKey(propertyKey);
- //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);
- //If project has cascading project and cascading value is set - property value will be used.
- assertEquals(parentProperty.getOriginalValue(), property.getCascadingValue());
- }
-
- /**
- * Verify getOriginalValue method.
- */
- @Test
- public void testBaseProjectPropertyGetOriginalValue() {
- BaseProjectProperty property = new BaseProjectProperty(project);
- assertNull(property.getOriginalValue());
- Object value = new Object();
- property.setKey(propertyKey);
- property.setValue(value);
- assertEquals(value, property.getOriginalValue());
- property.setValue(null);
- assertNull(property.getOriginalValue());
- }
-
@Test
public void testIntegerProjectPropertyGetOriginalValue() {
int value = 10;
@@ -481,16 +291,6 @@ public class ProjectPropertyTest {
}
@Test
- public void testAxisListProjectPropertyGetOriginalValue() {
- AxisList value = new AxisList();
- value.add(new Axis("DB", "mysql"));
- BaseProjectProperty property = new AxisListProjectProperty(project);
- property.setKey(propertyKey);
- property.setValue(value);
- assertEquals(value, property.getOriginalValue());
- }
-
- @Test
public void testScmProjectPropertyGetOriginalValue() {
SCM value = new NullSCM();
BaseProjectProperty property = new SCMProjectProperty(project);
@@ -500,212 +300,6 @@ public class ProjectPropertyTest {
}
/**
- * Verify setValue method.
- */
- @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());
-
- Object value = 12345;
- property.setValue(value);
- //If project doesn't have cascading - default boolean value is used for propertyOverridden flag
- 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
- property.setValue(null);
- assertTrue(property.isOverridden());
- String overriddenValue = "newValue";
- property.setValue(overriddenValue);
- assertTrue(property.isOverridden());
-
- //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);
- //Reset current property to null
- assertNull(property.getOriginalValue());
- //Cascading value is equal to current - reset flag to false.
- assertFalse(property.isOverridden());
- }
-
- @Test
- public void testGetValue() {
- Integer propertyValue = 10;
- IntegerProjectProperty property = new IntegerProjectProperty(project);
- property.setKey(propertyKey);
- property.setValue(propertyValue);
- //if value is not null - return it
- assertEquals(propertyValue, property.getValue());
- property.setValue(null);
- assertNull(property.getOriginalValue());
-
- //if current value is set to null and property is not overridden - defaultValue (Zero) will be taken
- Integer value = property.getValue();
- assertNotNull(value);
- assertFalse(property.isOverridden());
- assertEquals(property.getDefaultValue(), value);
-
- property.setOverridden(true);
- //If property is overridden - return its actual value.
- assertNull(property.getValue());
-
- IntegerProjectProperty parentProperty = new IntegerProjectProperty(parent);
- parentProperty.setKey(propertyKey);
- parentProperty.setValue(propertyValue);
- parent.putProjectProperty(propertyKey, parentProperty);
-
- project.setCascadingProject(parent);
- property = new IntegerProjectProperty(project);
- property.setKey(propertyKey);
- //if current value is null and is not overridden value, take from cascading
- assertNull(property.getOriginalValue());
- assertEquals(propertyValue, property.getValue());
-
- property.setOverridden(true);
- //Property is overridden - return current value even if it is null.
- assertNull(property.getOriginalValue());
- assertNull(property.getValue());
- }
-
- /**
- * Property should have not null property key.
- */
- @Test
- public void testNullPropertyKey() {
- BaseProjectProperty property = new BaseProjectProperty(project);
- try {
- property.setValue("value");
- fail("PropertyKey shouldn't be null while calling setValue");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_PROPERTY_KEY_EXCEPTION, e.getMessage());
- }
- try {
- property.getCascadingValue();
- fail("PropertyKey shouldn't be null while calling getCascadingValue()");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_PROPERTY_KEY_EXCEPTION, e.getMessage());
- }
- try {
- property.getValue();
- fail("PropertyKey shouldn't be null while calling getValue()");
- } catch (Exception e) {
- assertEquals(BaseProjectProperty.INVALID_PROPERTY_KEY_EXCEPTION, e.getMessage());
- }
-
- property.setKey("key");
- try {
- property.setValue("value");
- property.getCascadingValue();
- property.getValue();
- } catch (Exception e) {
- fail("PropertyKey is valid");
- }
- }
-
- /**
- * Resets project property value,
- */
- @Test
- public void testResetValue() {
- BaseProjectProperty property = new BaseProjectProperty(project);
- property.setKey(propertyKey);
- property.setValue(new Object());
- property.setOverridden(true);
- assertNotNull(property.getOriginalValue());
- assertTrue(property.isOverridden());
- property.resetValue();
- assertNull(property.getOriginalValue());
- assertFalse(property.isOverridden());
- }
-
- /**
- * Test setOverridden method.
- */
- @Test
- public void testSetPropertyOverridden() {
- BaseProjectProperty property = new BaseProjectProperty(project);
- //By default property isOverridden flag is set to false.
- assertFalse(property.isOverridden());
- //Test if flag is configured as expected. Set true/false values and check whether they are set correctly.
- property.setOverridden(true);
- assertTrue(property.isOverridden());
- property.setOverridden(false);
- 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.
- *
- * @throws IOException if any.
- */
- @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());
- }
-
- /**
- * Test updateOriginalValue method for ExternalProjectProperty.
- */
- @Test
- public void testExternalProjectPropertyUpdateOriginalValue() {
- ExternalProjectProperty property = new ExternalProjectProperty(project);
- //If property is not modified, than it shouldn't be updated.
- assertFalse(property.isModified());
- assertFalse(property.updateOriginalValue(new Object(), new Object()));
-
- //If property is modified, than BaseProjectProperty#updateOriginalValue method will be called.
- //Result will be true, because in this case property value will be updated.
- property.setModified(true);
- assertTrue(property.isModified());
- assertTrue(property.updateOriginalValue(new Object(), new Object()));
-
- }
-
- /**
* Test 1updateOriginalValue method for TriggerProjectProperty.
*
* @throws ANTLRException if any
@@ -721,7 +315,7 @@ public class ProjectPropertyTest {
//If trigger property value equals to cascading be sure that sets original value instead of cascading.
assertEquals(property.getOriginalValue(), originalTrigger);
- cascadingTrigger= new TimerTrigger("*/2 * * * *");
+ cascadingTrigger = new TimerTrigger("*/2 * * * *");
property.updateOriginalValue(originalTrigger, cascadingTrigger);
assertTrue(property.isOverridden());
assertEquals(property.getOriginalValue(), originalTrigger);