| author | akozak | 2011-11-21 09:00:23 (EST) |
|---|---|---|
| committer | Winston Prakash | 2011-12-01 20:46:52 (EST) |
| commit | 4b72dcf2295bd2dbeba66859dc7ea5daa6937e96 (patch) (side-by-side diff) | |
| tree | 10ee4473f521c1b926084a781b41f13f694b07ba | |
| parent | 5ddaa0c59afc72b070417ff2e926a66ac919e60f (diff) | |
| download | org.eclipse.hudson.core-4b72dcf2295bd2dbeba66859dc7ea5daa6937e96.zip org.eclipse.hudson.core-4b72dcf2295bd2dbeba66859dc7ea5daa6937e96.tar.gz org.eclipse.hudson.core-4b72dcf2295bd2dbeba66859dc7ea5daa6937e96.tar.bz2 | |
Added unit tests, cobertura-maven-plugin, upgraded version of powermock, small fixes.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
| -rw-r--r-- | hudson-core/pom.xml | 42 | ||||
| -rw-r--r-- | hudson-core/src/main/java/hudson/matrix/MatrixProject.java | 16 | ||||
| -rw-r--r-- | hudson-core/src/main/java/hudson/model/Job.java | 10 | ||||
| -rw-r--r-- | hudson-core/src/test/java/hudson/matrix/MatrixProjectTest.java | 277 | ||||
| -rw-r--r-- | pom.xml | 2 |
5 files changed, 332 insertions, 15 deletions
diff --git a/hudson-core/pom.xml b/hudson-core/pom.xml index 4fb3428..37679e1 100644 --- a/hudson-core/pom.xml +++ b/hudson-core/pom.xml @@ -305,6 +305,48 @@ </plugins> </reporting> </profile> + + <profile> + <id>CI</id> + <activation> + <property> + <name>BUILD_NUMBER</name> + </property> + </activation> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + <version>2.5.1</version> + <configuration> + <check> + <branchRate>80</branchRate> + <lineRate>80</lineRate> + <haltOnFailure>true</haltOnFailure> + <totalBranchRate>80</totalBranchRate> + <totalLineRate>80</totalLineRate> + <packageLineRate>80</packageLineRate> + <packageBranchRate>80</packageBranchRate> + </check> + <formats> + <format>xml</format> + </formats> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>cobertura</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + </build> + </profile> </profiles> <dependencies> diff --git a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java index 5540d45..eab80fd 100644 --- a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java +++ b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java @@ -102,10 +102,11 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i /** * The filter that is applied to combinations. It is a Groovy if condition. * This can be null, which means "true". + * Package visible for the tests only. * * @see #getCombinationFilter() */ - private volatile String combinationFilter; + volatile String combinationFilter; /** * List of active {@link Builder}s configured for this project. @@ -140,15 +141,17 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i Boolean runSequentially; /** - * Filter to select a number of combinations to build first + * Filter to select a number of combinations to build first. + * Package visible for the tests only. */ - private String touchStoneCombinationFilter; + String touchStoneCombinationFilter; /** * Required result on the touchstone combinations, in order to - * continue with the rest + * continue with the rest. + * Package visible for the tests only. */ - private Result touchStoneResultCondition; + Result touchStoneResultCondition; /** * See {@link #setCustomWorkspace(String)}. @@ -221,7 +224,6 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i } else { this.combinationFilter = null; } - // TODO verify me rebuildConfigurations(); save(); } @@ -467,7 +469,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i /** * Rebuilds the {@link #configurations} list and {@link #activeConfigurations}. */ - private void rebuildConfigurations() throws IOException { + void rebuildConfigurations() throws IOException { { // backward compatibility check to see if there's any data in the old structure // if so, bring them to the newer structure. diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java index 445634e..a8478e9 100644 --- a/hudson-core/src/main/java/hudson/model/Job.java +++ b/hudson-core/src/main/java/hudson/model/Job.java @@ -154,7 +154,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R */ protected transient JobT template; - protected transient volatile ThreadLocal<Boolean> allowSave = new ThreadLocal<Boolean>() { + protected transient ThreadLocal<Boolean> allowSave = new ThreadLocal<Boolean>() { @Override protected Boolean initialValue() { return true; @@ -179,6 +179,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R throws IOException { super.onLoad(parent, name); template = (JobT) Functions.getItemByName(Hudson.getInstance().getAllItems(this.getClass()), templateName); + //TODO investigate why allowSave is null if (null == allowSave) {// Initialize property if null. allowSave = new ThreadLocal<Boolean>() { @Override @@ -1252,10 +1253,9 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R */ @SuppressWarnings({"unchecked"}) public JobT getTemplate() { -//TODO enable me -// if (template == null) { -// template = (JobT) Functions.getItemByName(Hudson.getInstance().getAllItems(this.getClass()), templateName); -// } + if (StringUtils.isNotBlank(templateName) && template == null) { + template = (JobT) Functions.getItemByName(Hudson.getInstance().getAllItems(this.getClass()), templateName); + } return template; } diff --git a/hudson-core/src/test/java/hudson/matrix/MatrixProjectTest.java b/hudson-core/src/test/java/hudson/matrix/MatrixProjectTest.java index 3b312db..4bf0b84 100644 --- a/hudson-core/src/test/java/hudson/matrix/MatrixProjectTest.java +++ b/hudson-core/src/test/java/hudson/matrix/MatrixProjectTest.java @@ -14,11 +14,11 @@ *******************************************************************************/ package hudson.matrix; +import hudson.model.Result; import java.io.IOException; import org.junit.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Test for {@link hudson.matrix.MatrixProject} @@ -95,6 +95,274 @@ public class MatrixProjectTest { assertTrue(childProject1.isRunSequentially()); } + @Test + public void testGetCombinationFilterChildValue() throws IOException { + String parentCombinationFilter = "parent_filter"; + String childCombinationFilter = "child_filter"; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setCombinationFilter(parentCombinationFilter); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setCombinationFilter(childCombinationFilter); + childProject1.setTemplate(parentProject); + assertEquals(childProject1.getCombinationFilter(), childCombinationFilter); + } + + @Test + public void testGetCombinationFilterParentValue() throws IOException { + String parentCombinationFilter = "parent_filter"; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setCombinationFilter(parentCombinationFilter); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + assertEquals(childProject1.getCombinationFilter(), parentCombinationFilter); + } + + @Test + public void testSetCombinationFilterDifferentValues() throws IOException { + String parentCombinationFilter = "parent_filter"; + String childCombinationFilter = "child_filter"; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setCombinationFilter(parentCombinationFilter); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + childProject1.setCombinationFilter(childCombinationFilter); + assertEquals(childProject1.combinationFilter, childCombinationFilter); + } + + @Test + public void testSetCombinationFilterTheSameValues() throws IOException { + String combinationFilter = "filter"; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setCombinationFilter(combinationFilter); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + childProject1.setCombinationFilter(combinationFilter); + assertNull(childProject1.combinationFilter); + assertEquals(childProject1.getCombinationFilter(), combinationFilter); + } + + @Test + public void testSetCombinationFilterParentNull() throws IOException { + String combinationFilter = "filter"; + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setCombinationFilter(combinationFilter); + assertEquals(childProject1.combinationFilter, combinationFilter); + assertEquals(childProject1.getCombinationFilter(), combinationFilter); + } + + @Test + public void testGetTouchStoneCombinationFilterChildValue() throws IOException { + String parentCombinationFilter = "parent_filter"; + String childCombinationFilter = "child_filter"; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setTouchStoneCombinationFilter(parentCombinationFilter); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTouchStoneCombinationFilter(childCombinationFilter); + childProject1.setTemplate(parentProject); + assertEquals(childProject1.getTouchStoneCombinationFilter(), childCombinationFilter); + } + + @Test + public void testGetTouchStoneCombinationFilterParentValue() throws IOException { + String parentCombinationFilter = "parent_filter"; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setTouchStoneCombinationFilter(parentCombinationFilter); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + assertEquals(childProject1.getTouchStoneCombinationFilter(), parentCombinationFilter); + } + + @Test + public void testSetTouchStoneCombinationFilterDifferentValues() throws IOException { + String parentCombinationFilter = "parent_filter"; + String childCombinationFilter = "child_filter"; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setTouchStoneCombinationFilter(parentCombinationFilter); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + childProject1.setTouchStoneCombinationFilter(childCombinationFilter); + assertEquals(childProject1.touchStoneCombinationFilter, childCombinationFilter); + } + + @Test + public void testSetTouchStoneCombinationFilterTheSameValues() throws IOException { + String combinationFilter = "filter"; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setTouchStoneCombinationFilter(combinationFilter); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + childProject1.setTouchStoneCombinationFilter(combinationFilter); + assertNull(childProject1.touchStoneCombinationFilter); + assertEquals(childProject1.getTouchStoneCombinationFilter(), combinationFilter); + } + + @Test + public void testSetTouchStoneCombinationFilterParentNull() throws IOException { + String combinationFilter = "filter"; + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTouchStoneCombinationFilter(combinationFilter); + assertEquals(childProject1.touchStoneCombinationFilter, combinationFilter); + assertEquals(childProject1.getTouchStoneCombinationFilter(), combinationFilter); + } + //touchStoneResultCondition + @Test + public void testGetTouchStoneResultConditionChildValue() throws IOException { + Result parentResultCondition = Result.SUCCESS; + Result childResultCondition = Result.FAILURE; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setTouchStoneResultCondition(parentResultCondition); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTouchStoneResultCondition(childResultCondition); + childProject1.setTemplate(parentProject); + assertEquals(childProject1.getTouchStoneResultCondition(), childResultCondition); + } + + @Test + public void testGetTouchStoneResultConditionParentValue() throws IOException { + Result parentResultCondition = Result.SUCCESS; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setTouchStoneResultCondition(parentResultCondition); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + assertEquals(childProject1.getTouchStoneResultCondition(), parentResultCondition); + } + + @Test + public void testSetTouchStoneResultConditionDifferentValues() throws IOException { + Result parentResultCondition = Result.SUCCESS; + Result childResultCondition = Result.FAILURE; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setTouchStoneResultCondition(parentResultCondition); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + childProject1.setTouchStoneResultCondition(childResultCondition); + assertEquals(childProject1.touchStoneResultCondition, childResultCondition); + } + + @Test + public void testSetTouchStoneResultConditionTheSameValues() throws IOException { + Result parentResultCondition = Result.SUCCESS; + MatrixProject parentProject = new MatrixProjectMock("parent"); + parentProject.setAllowSave(false); + parentProject.setTouchStoneResultCondition(parentResultCondition); + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTemplate(parentProject); + childProject1.setTouchStoneResultCondition(parentResultCondition); + assertNull(childProject1.touchStoneResultCondition); + assertEquals(childProject1.getTouchStoneResultCondition(), parentResultCondition); + } + + @Test + public void testSetTouchStoneResultConditionParentNull() throws IOException { + Result childResultCondition = Result.FAILURE; + + MatrixProject childProject1 = new MatrixProject("child1"){ + @Override + void rebuildConfigurations() throws IOException { + } + }; + childProject1.setAllowSave(false); + childProject1.setTouchStoneResultCondition(childResultCondition); + assertEquals(childProject1.touchStoneResultCondition, childResultCondition); + assertEquals(childProject1.getTouchStoneResultCondition(), childResultCondition); + } + + private class MatrixProjectMock extends MatrixProject { private MatrixProjectMock(String name) { @@ -104,5 +372,10 @@ public class MatrixProjectTest { @Override protected void updateTransientActions() { } + + @Override + void rebuildConfigurations() throws IOException { + } } } + @@ -92,7 +92,7 @@ <junit.version>4.8.1</junit.version> <easymock.version>3.0</easymock.version> <mockito-core.version>1.8.5</mockito-core.version> - <powermock.version>1.4.9</powermock.version> + <powermock.version>1.4.10</powermock.version> <!--Plugins--> <maven-antrun-extended-plugin.version>1.42</maven-antrun-extended-plugin.version> |

