Skip to content
Permalink
Browse files

[JENKINS-36894][JENKINS-36860] Add PreviousShortcut

  • Loading branch information
ikedam committed Aug 7, 2016
1 parent ba043e1 commit 913ae0cc48beed87e4bc4652609c57262ecd1260
@@ -61,6 +61,7 @@
* {@code null} if there's no builds.
* @return combinations to check.
*/
@Nonnull
public abstract Collection<Combination> getCombinations(
@Nonnull MatrixProject project,
@CheckForNull MatrixBuild build
@@ -73,6 +74,7 @@
* @param build the target build
* @return comma-separated list of combination indices
*/
@Nonnull
public final String getCombinationsData(
@Nonnull final MatrixProject project,
@CheckForNull MatrixBuild build
@@ -121,6 +123,7 @@ public All() {
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public Collection<Combination> getCombinations(
@Nonnull MatrixProject project,
@@ -139,6 +142,7 @@ public Combination apply(MatrixConfiguration c) {
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public String getName() {
return getDescriptor().getDisplayName();
@@ -147,6 +151,7 @@ public String getName() {
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public String getId() {
return "All";
@@ -181,6 +186,7 @@ public None() {
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public Collection<Combination> getCombinations(
@Nonnull MatrixProject project,
@@ -192,6 +198,7 @@ public None() {
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public String getName() {
return getDescriptor().getDisplayName();
@@ -200,6 +207,7 @@ public String getName() {
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public String getId() {
return "None";
@@ -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";
}
}
}
@@ -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");
}
}

0 comments on commit 913ae0c

Please sign in to comment.
You can’t perform that action at this time.