Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-36894][JENKINS-36860] Add PreviousShortcut
- Loading branch information
Showing
3 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/hudson/plugins/matrix_configuration_parameter/shortcut/PreviousShortcut.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2016 IKEDA Yasuyuki | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package hudson.plugins.matrix_configuration_parameter.shortcut; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
|
||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import com.google.common.base.Function; | ||
import com.google.common.collect.Lists; | ||
|
||
import hudson.Extension; | ||
import hudson.matrix.Combination; | ||
import hudson.matrix.MatrixBuild; | ||
import hudson.matrix.MatrixProject; | ||
import hudson.matrix.MatrixRun; | ||
|
||
/** | ||
* Shortcut to check combinations used in the previous build | ||
*/ | ||
public class PreviousShortcut extends MatrixCombinationsShortcut { | ||
@DataBoundConstructor | ||
public PreviousShortcut() { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Nonnull | ||
@Override | ||
public Collection<Combination> getCombinations( | ||
@Nonnull MatrixProject project, | ||
@CheckForNull MatrixBuild build | ||
) { | ||
if (build == null) { | ||
return Collections.emptyList(); | ||
} | ||
return Lists.transform( | ||
build.getExactRuns(), | ||
new Function<MatrixRun, Combination>() { | ||
public Combination apply(MatrixRun r) { | ||
return r.getParent().getCombination(); | ||
} | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Nonnull | ||
@Override | ||
public String getName() { | ||
return getDescriptor().getDisplayName(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Nonnull | ||
@Override | ||
public String getId() { | ||
return "Previous"; | ||
} | ||
|
||
/** | ||
* Descriptor for {@link PreviousShortcut} | ||
*/ | ||
@Extension | ||
public static class DescriptorImpl extends MatrixCombinationsShortcutDescriptor { | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public String getDisplayName() { | ||
return "Previous"; | ||
} | ||
} | ||
} |
187 changes: 187 additions & 0 deletions
187
...est/java/hudson/plugins/matrix_configuration_parameter/shortcut/PreviousShortcutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2016 IKEDA Yasuyuki | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package hudson.plugins.matrix_configuration_parameter.shortcut; | ||
|
||
import static org.junit.Assert.assertNull; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule.WebClient; | ||
|
||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
|
||
import hudson.matrix.AxisList; | ||
import hudson.matrix.Combination; | ||
import hudson.matrix.MatrixBuild; | ||
import hudson.matrix.MatrixProject; | ||
import hudson.matrix.TextAxis; | ||
import hudson.model.Item; | ||
import hudson.model.ParametersDefinitionProperty; | ||
import hudson.model.Result; | ||
import hudson.plugins.matrix_configuration_parameter.ConditionalFailBuilder; | ||
import hudson.plugins.matrix_configuration_parameter.MatrixCombinationsJenkinsRule; | ||
import hudson.plugins.matrix_configuration_parameter.MatrixCombinationsParameterDefinition; | ||
|
||
/** | ||
* Tests for {@link PreviousShortcut} | ||
*/ | ||
public class PreviousShortcutTest { | ||
@ClassRule | ||
public static MatrixCombinationsJenkinsRule j = new MatrixCombinationsJenkinsRule(); | ||
|
||
@Test | ||
public void testConfiguration() throws Exception { | ||
AxisList axes = new AxisList(new TextAxis("axis1", "value1", "value2", "value3")); | ||
MatrixProject p = j.createMatrixProject(); | ||
p.setAxes(axes); | ||
MatrixCombinationsParameterDefinition def = new MatrixCombinationsParameterDefinition( | ||
"COMBINATIONS", | ||
"", | ||
"", | ||
Arrays.<MatrixCombinationsShortcut>asList(new PreviousShortcut()) | ||
); | ||
p.addProperty(new ParametersDefinitionProperty(def)); | ||
|
||
j.configRoundtrip((Item)p); | ||
|
||
j.assertEqualDataBoundBeans( | ||
def, | ||
p.getProperty(ParametersDefinitionProperty.class).getParameterDefinition("COMBINATIONS") | ||
); | ||
} | ||
|
||
@Test | ||
public void testCheckLastBuild() throws Exception { | ||
AxisList axes = new AxisList(new TextAxis("axis1", "value1", "value2", "value3")); | ||
MatrixProject p = j.createMatrixProject(); | ||
p.setAxes(axes); | ||
MatrixCombinationsParameterDefinition def = new MatrixCombinationsParameterDefinition( | ||
"COMBINATIONS", | ||
"", | ||
"", | ||
Arrays.<MatrixCombinationsShortcut>asList(new PreviousShortcut()) | ||
); | ||
p.addProperty(new ParametersDefinitionProperty(def)); | ||
p.getBuildersList().add(new ConditionalFailBuilder("${axis1}", "value2")); | ||
|
||
MatrixBuild b1 = p.scheduleBuild2(0).get(); | ||
|
||
j.assertBuildStatus(Result.SUCCESS, b1.getExactRun(new Combination(axes, "value1"))); | ||
j.assertBuildStatus(Result.FAILURE, b1.getExactRun(new Combination(axes, "value2"))); | ||
j.assertBuildStatus(Result.SUCCESS, b1.getExactRun(new Combination(axes, "value3"))); | ||
|
||
p.setCombinationFilter("axis1 != 'value3'"); | ||
|
||
MatrixBuild b2 = p.scheduleBuild2(0).get(); | ||
|
||
j.assertBuildStatus(Result.SUCCESS, b2.getExactRun(new Combination(axes, "value1"))); | ||
j.assertBuildStatus(Result.FAILURE, b2.getExactRun(new Combination(axes, "value2"))); | ||
assertNull(b2.getExactRun(new Combination(axes, "value3"))); | ||
|
||
p.setCombinationFilter(""); | ||
|
||
WebClient wc = j.createAllow405WebClient(); | ||
HtmlPage page = wc.getPage(p, "build"); | ||
|
||
j.clickShortcut(page, "Previous"); | ||
|
||
j.assertCombinationChecked(page, true, axes, "value1"); | ||
j.assertCombinationChecked(page, true, axes, "value2"); | ||
j.assertCombinationChecked(page, false, axes, "value3"); | ||
} | ||
|
||
@Test | ||
public void testCheckNoLastBuild() throws Exception { | ||
AxisList axes = new AxisList(new TextAxis("axis1", "value1", "value2", "value3")); | ||
MatrixProject p = j.createMatrixProject(); | ||
p.setAxes(axes); | ||
MatrixCombinationsParameterDefinition def = new MatrixCombinationsParameterDefinition( | ||
"COMBINATIONS", | ||
"", | ||
"", | ||
Arrays.<MatrixCombinationsShortcut>asList(new PreviousShortcut()) | ||
); | ||
p.addProperty(new ParametersDefinitionProperty(def)); | ||
p.setCombinationFilter("axis1 != 'value3'"); | ||
p.getBuildersList().add(new ConditionalFailBuilder("${axis1}", "value2")); | ||
|
||
WebClient wc = j.createAllow405WebClient(); | ||
HtmlPage page = wc.getPage(p, "build"); | ||
|
||
j.clickShortcut(page, "Previous"); | ||
|
||
j.assertCombinationChecked(page, false, axes, "value1"); | ||
j.assertCombinationChecked(page, false, axes, "value2"); | ||
j.assertCombinationChecked(page, false, axes, "value3"); | ||
} | ||
|
||
@Test | ||
public void testCheckRebuild() throws Exception { | ||
AxisList axes = new AxisList(new TextAxis("axis1", "value1", "value2", "value3")); | ||
MatrixProject p = j.createMatrixProject(); | ||
p.setAxes(axes); | ||
MatrixCombinationsParameterDefinition def = new MatrixCombinationsParameterDefinition( | ||
"COMBINATIONS", | ||
"", | ||
"", | ||
Arrays.<MatrixCombinationsShortcut>asList(new PreviousShortcut()) | ||
); | ||
p.addProperty(new ParametersDefinitionProperty(def)); | ||
p.getBuildersList().add(new ConditionalFailBuilder("${axis1}", "value2")); | ||
|
||
MatrixBuild b1 = p.scheduleBuild2(0).get(); | ||
|
||
j.assertBuildStatus(Result.SUCCESS, b1.getExactRun(new Combination(axes, "value1"))); | ||
j.assertBuildStatus(Result.FAILURE, b1.getExactRun(new Combination(axes, "value2"))); | ||
j.assertBuildStatus(Result.SUCCESS, b1.getExactRun(new Combination(axes, "value3"))); | ||
|
||
p.setCombinationFilter("axis1 != 'value3'"); | ||
|
||
MatrixBuild b2 = p.scheduleBuild2(0).get(); | ||
|
||
j.assertBuildStatus(Result.SUCCESS, b2.getExactRun(new Combination(axes, "value1"))); | ||
j.assertBuildStatus(Result.FAILURE, b2.getExactRun(new Combination(axes, "value2"))); | ||
assertNull(b2.getExactRun(new Combination(axes, "value3"))); | ||
|
||
p.setCombinationFilter(""); | ||
|
||
MatrixBuild b3 = p.scheduleBuild2(0).get(); | ||
|
||
j.assertBuildStatus(Result.SUCCESS, b3.getExactRun(new Combination(axes, "value1"))); | ||
j.assertBuildStatus(Result.FAILURE, b3.getExactRun(new Combination(axes, "value2"))); | ||
j.assertBuildStatus(Result.SUCCESS, b3.getExactRun(new Combination(axes, "value3"))); | ||
|
||
WebClient wc = j.createAllow405WebClient(); | ||
HtmlPage page = wc.getPage(b2, "rebuild"); | ||
|
||
j.clickShortcut(page, "Previous"); | ||
|
||
j.assertCombinationChecked(page, true, axes, "value1"); | ||
j.assertCombinationChecked(page, true, axes, "value2"); | ||
j.assertCombinationChecked(page, false, axes, "value3"); | ||
} | ||
} |