diff --git a/pom.xml b/pom.xml index 7530f8b1..7e181ee7 100644 --- a/pom.xml +++ b/pom.xml @@ -128,12 +128,6 @@ org.jenkins-ci.plugins ssh-credentials - - hudson.plugins - project-inheritance - 21.04.03 - true - org.jenkins-ci.plugins job-dsl diff --git a/src/main/java/hudson/plugins/promoted_builds/inheritance/JobPropertyImplSelector.java b/src/main/java/hudson/plugins/promoted_builds/inheritance/JobPropertyImplSelector.java deleted file mode 100644 index b74d5940..00000000 --- a/src/main/java/hudson/plugins/promoted_builds/inheritance/JobPropertyImplSelector.java +++ /dev/null @@ -1,68 +0,0 @@ - -package hudson.plugins.promoted_builds.inheritance; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import hudson.Extension; -import hudson.model.JobProperty; - -import hudson.plugins.project_inheritance.projects.InheritanceProject; -import hudson.plugins.project_inheritance.projects.inheritance.InheritanceSelector; - -import hudson.plugins.promoted_builds.JobPropertyImpl; - -/** - * - * @author Jacek Tomaka - * @since TODO - */ -@Extension(optional=true) -public class JobPropertyImplSelector extends InheritanceSelector> { - private static final long serialVersionUID = 1L; - private static final Logger logger = Logger.getLogger(JobPropertyImplSelector.class.getName()); - - @Override - public boolean isApplicableFor(Class clazz){ - return JobProperty.class.isAssignableFrom(clazz); - } - - @Override - public InheritanceSelector.MODE getModeFor(Class clazz){ - if (JobPropertyImpl.class.isAssignableFrom(clazz)) return MODE.USE_LAST; - return MODE.NOT_RESPONSIBLE; - } - - @Override - public String getObjectIdentifier(JobProperty obj){ - if ( obj!=null && JobPropertyImpl.class.getName().equals(obj.getClass().getName())){ - return JobPropertyImplSelector.class.getName(); - } - return null; - } - - @Override - public JobPropertyImpl merge(JobProperty prior, JobProperty latter, InheritanceProject caller){ - return null; - } - - @Override - public JobProperty handleSingleton(JobProperty jobProperty, InheritanceProject caller){ - if (jobProperty == null || caller == null) return jobProperty; - if (caller.isAbstract) return jobProperty; - - if (!JobPropertyImpl.class.isAssignableFrom(jobProperty.getClass())) return jobProperty; - - - JobPropertyImpl jobPropertyImpl = (JobPropertyImpl)jobProperty; - - try { - JobPropertyImpl newJobProperty = new JobPropertyImpl(jobPropertyImpl, caller); - return newJobProperty; - } catch (Exception ex){ - logger.log(Level.WARNING, "Error during hacking up JobPropertyImpl", ex ); - } - return jobProperty; - } -} - diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/DownstreamPassConditionInheritanceTest.java b/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/DownstreamPassConditionInheritanceTest.java deleted file mode 100644 index 94c8ff8e..00000000 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/DownstreamPassConditionInheritanceTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * The MIT License - * - * Copyright 2015 Franta Mejta - * - * 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.promoted_builds.conditions.inheritance; - -import static org.junit.Assert.*; -import org.junit.Rule; -import org.junit.Test; - -import hudson.model.Result; -import hudson.plugins.project_inheritance.projects.InheritanceBuild; -import hudson.plugins.project_inheritance.projects.InheritanceProject.IMode; -import hudson.plugins.promoted_builds.JobPropertyImpl; -import hudson.plugins.promoted_builds.PromotedBuildAction; -import hudson.plugins.promoted_builds.PromotionProcess; -import hudson.plugins.promoted_builds.Status; -import hudson.plugins.promoted_builds.conditions.DownstreamPassCondition; -import hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectRule; -import hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair; -import hudson.tasks.BuildTrigger; -import org.jvnet.hudson.test.Issue; - -public final class DownstreamPassConditionInheritanceTest { - - @Rule - public InheritanceProjectRule j = new InheritanceProjectRule(); - - @Test - @Issue("JENKINS-7739") - public void shouldEvaluateUpstreamRecursively() throws Exception { - final InheritanceProjectsPair pair1 = j.createInheritanceProjectDerivedWithBase(); - final InheritanceProjectsPair pair2 = j.createInheritanceProjectDerivedWithBase(); - final InheritanceProjectsPair pair3 = j.createInheritanceProjectDerivedWithBase(); - - - final JobPropertyImpl property = new JobPropertyImpl(pair1.getBase()); - pair1.getBase().addProperty(property); - - final PromotionProcess process = property.addProcess("promotion"); - process.conditions.add(new DownstreamPassCondition(pair3.getDerived().getFullName())); - - pair1.getDerived().getPublishersList().add(new BuildTrigger(pair2.getDerived().getFullName(), Result.SUCCESS)); - pair2.getDerived().getPublishersList().add(new BuildTrigger(pair3.getDerived().getFullName(), Result.SUCCESS)); - j.jenkins.rebuildDependencyGraph(); - - final InheritanceBuild run1 = j.buildAndAssertSuccess(pair1.getDerived()); - j.assertBuildStatusSuccess(run1); - j.waitUntilNoActivity(); - j.assertBuildStatusSuccess(pair2.getDerived().getLastBuild()); - j.waitUntilNoActivity(); - final InheritanceBuild run3 = j.assertBuildStatusSuccess(pair3.getDerived().getLastBuild()); - j.waitUntilNoActivity(); - - //We cannot assume that the process will contain builds because the process added to base project is different to the one in derived. - JobPropertyImpl jobProperty = pair1.getDerived().getProperty(JobPropertyImpl.class, - /*Forcing inheritance as temporary hack for inheritance plugin 1.53 - because that version of the plugin uses inheritance only for certain predefined cases: - -specific methods on the call stack - -url paths. - This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40 - */ - IMode.INHERIT_FORCED); - - assertNotNull("derived jobProperty is null", jobProperty); - PromotionProcess processDerived = jobProperty.getItem("promotion"); - - assertEquals("fingerprint relation", run3.getUpstreamRelationship(pair1.getDerived()), -1); - assertFalse("no promotion process", processDerived.getBuilds().isEmpty()); - - final PromotedBuildAction action = run1.getAction(PromotedBuildAction.class); - assertNotNull("no promoted action", action); - - final Status promotion = action.getPromotion("promotion"); - assertNotNull("promotion not found", promotion); - assertTrue("promotion not successful", promotion.isPromotionSuccessful()); - } - -} diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/ManualConditionInheritanceTest.java b/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/ManualConditionInheritanceTest.java deleted file mode 100644 index 8cf92f15..00000000 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/ManualConditionInheritanceTest.java +++ /dev/null @@ -1,203 +0,0 @@ -package hudson.plugins.promoted_builds.conditions.inheritance; - -import hudson.ExtensionList; -import hudson.model.ParameterDefinition; -import hudson.model.ParameterValue; -import hudson.model.Descriptor; -import hudson.model.StringParameterDefinition; -import hudson.plugins.project_inheritance.projects.InheritanceBuild; -import hudson.plugins.project_inheritance.projects.InheritanceProject.IMode; -import hudson.plugins.promoted_builds.JobPropertyImpl; -import hudson.plugins.promoted_builds.PromotedBuildAction; -import hudson.plugins.promoted_builds.Promotion; -import hudson.plugins.promoted_builds.PromotionProcess; - -import hudson.plugins.promoted_builds.conditions.ManualCondition; -import hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval; -import hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectRule; -import hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.SortedMap; - -import org.htmlunit.html.HtmlInput; -import org.junit.Rule; -import org.junit.Test; - -import jenkins.model.Jenkins; - -import org.htmlunit.html.HtmlElement; -import org.htmlunit.html.HtmlForm; -import org.htmlunit.html.HtmlPage; - -/** - * @author Jacek Tomaka - */ -public class ManualConditionInheritanceTest { - @Rule - public InheritanceProjectRule j = new InheritanceProjectRule(); - public static List getFormsByName(HtmlPage page, String name){ - List forms=new ArrayList(); - for (HtmlForm f:page.getForms()){ - if (name.equals(f.getNameAttribute())){ - forms.add(f); - } - } - return forms; - } - public static List getFormParameters(HtmlForm form){ - return form.getElementsByAttribute("div", "name", "parameter"); - } - @Test - public void testManualPromotionProcess() throws Exception { - InheritanceProjectsPair inheritanceProjectsPair = j.createInheritanceProjectDerivedWithBase(); - - ExtensionList list=Jenkins.get().getExtensionList(Descriptor.class); - list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class)); - JobPropertyImpl base = new JobPropertyImpl(inheritanceProjectsPair.getBase()); - inheritanceProjectsPair.getBase().addProperty(base); - PromotionProcess foo = base.addProcess("foo"); - - ManualCondition condition=new ManualCondition(); - condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter")); - condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter")); - foo.conditions.add(condition); - - InheritanceBuild b1 = j.assertBuildStatusSuccess(inheritanceProjectsPair.getDerived().scheduleBuild2(0)); - - // promote a build - - List paramValues = condition.createDefaultValues(); - //try to add duplicate values - paramValues.addAll(condition.createDefaultValues()); - //We cannot assume that the process will contain builds because the process added to base project is different to the one in derived. - JobPropertyImpl jobProperty = inheritanceProjectsPair.getDerived().getProperty(JobPropertyImpl.class, - /*Forcing inheritance as temporary hack for inheritance plugin 1.53 - because that version of the plugin uses inheritance only for certain predefined cases: - -specific methods on the call stack - -url paths. - This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40 - */ - IMode.INHERIT_FORCED); - assertNotNull("derived jobProperty is null", jobProperty); - PromotionProcess fooDerived = jobProperty.getItem("foo"); - - j.assertBuildStatusSuccess(condition.approve(b1, fooDerived, paramValues)); - ManualApproval manualApproval=b1.getAction(ManualApproval.class); - assertNotNull(manualApproval); - - PromotedBuildAction statuses=b1.getAction(PromotedBuildAction.class); - assertNotNull(statuses); - assertNotNull(statuses.getPromotions()); - assertFalse(statuses.getPromotions().isEmpty()); - } - - - @Test - public void testManualPromotionProcessViaWebClient() throws Exception { - InheritanceProjectsPair inheritanceProjectsPair = j.createInheritanceProjectDerivedWithBase(); - - ExtensionList list=Jenkins.get().getExtensionList(Descriptor.class); - list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class)); - JobPropertyImpl base = new JobPropertyImpl(inheritanceProjectsPair.getBase()); - inheritanceProjectsPair.getDerived().addProperty(base); - PromotionProcess foo = base.addProcess("foo"); - ManualCondition condition=new ManualCondition(); - condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_1", "bogus_value_1", "Bog parameter")); - condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter")); - foo.conditions.add(condition); - - InheritanceBuild b1 = j.assertBuildStatusSuccess(inheritanceProjectsPair.getDerived().scheduleBuild2(0)); - assertNull(b1.getAction(ManualApproval.class)); - HtmlPage page=j.createWebClient().getPage(b1, "promotion"); - //Approve Promotion - List forms=getFormsByName(page, "approve"); - assertFalse(forms.isEmpty()); - assertEquals(1, forms.size()); - - HtmlForm form=forms.get(0); - List parameters=getFormParameters(form); - assertEquals(parameters.size(), condition.getParameterDefinitions().size()); - for(HtmlElement param:parameters){ - HtmlInput v = (HtmlInput) param.getElementsByAttribute("input", "name", "value").get(0); - v.setValue(v.getValue() + "1"); - } - j.submit(forms.get(0)); - j.waitUntilNoActivity(); - //We cannot assume that the process will contain builds because the process added to base project is different to the one in derived. - final JobPropertyImpl jobProperty = inheritanceProjectsPair.getDerived().getProperty(JobPropertyImpl.class, - /*Forcing inheritance as temporary hack for inheritance plugin 1.53 - because that version of the plugin uses inheritance only for certain predefined cases: - -specific methods on the call stack - -url paths. - This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40 - */ - IMode.INHERIT_FORCED); - assertNotNull("derived jobProperty is null", jobProperty); - final PromotionProcess fooDerived = jobProperty.getItem("foo"); - ManualApproval approval=b1.getAction(ManualApproval.class); - assertNotNull(approval); - SortedMap builds=fooDerived.getBuildsAsMap(); - assertNotNull(builds); - assertEquals(1, builds.size()); - - //Re-Execute approved promotion - page=j.createWebClient().getPage(b1, "promotion"); - forms=getFormsByName(page,"build"); - assertFalse(forms.isEmpty()); - assertEquals(1, forms.size()); - form=forms.get(0); - parameters=getFormParameters(form); - assertEquals(parameters.size(), condition.getParameterDefinitions().size()); - - for(HtmlElement param:parameters){ - HtmlInput v = (HtmlInput) param.getElementsByAttribute("input", "name", "value").get(0); - v.setValue(v.getValue() + "2"); - } - j.submit(form); - j.waitUntilNoActivity(); - final JobPropertyImpl jobProperty2 = inheritanceProjectsPair.getDerived().getProperty(JobPropertyImpl.class, - /*Forcing inheritance as temporary hack for inheritance plugin 1.53 - because that version of the plugin uses inheritance only for certain predefined cases: - -specific methods on the call stack - -url paths. - This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40 - */ - IMode.INHERIT_FORCED); - assertNotNull("derived jobProperty is null", jobProperty2); - final PromotionProcess fooDerived2 = jobProperty2.getItem("foo"); - - builds=fooDerived2.getBuildsAsMap(); - assertEquals(2, builds.size()); - List actions=b1.getActions(ManualApproval.class); - assertEquals(1, actions.size()); - - PromotedBuildAction buildActions=b1.getAction(PromotedBuildAction.class); - int buildIndex=1; - String valueSufix="1"; - List promotions=new ArrayList(); - promotions.addAll(builds.values()); - - Collections.reverse(promotions); - for (Promotion build:promotions){ - List values=build.getParameterDefinitionsWithValue(); - assertEquals(values.size(), condition.getParameterDefinitions().size()); - for (ParameterDefinition v:values){ - assertTrue(v instanceof StringParameterDefinition); - String pvalue=((StringParameterDefinition)v).getDefaultValue(); - assertTrue(pvalue.endsWith(valueSufix)); - } - buildIndex++; - valueSufix+=buildIndex; - } - - } -} diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/SelfPromotionInheritanceTest.java b/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/SelfPromotionInheritanceTest.java deleted file mode 100644 index 2558da22..00000000 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/SelfPromotionInheritanceTest.java +++ /dev/null @@ -1,222 +0,0 @@ -package hudson.plugins.promoted_builds.conditions.inheritance; - -import hudson.model.Cause; -import hudson.model.ParametersAction; -import hudson.model.ParametersDefinitionProperty; -import hudson.model.Result; -import hudson.model.StringParameterDefinition; -import hudson.model.StringParameterValue; -import hudson.model.TaskListener; -import hudson.plugins.project_inheritance.projects.InheritanceBuild; -import hudson.plugins.project_inheritance.projects.InheritanceProject.IMode; -import hudson.plugins.promoted_builds.JobPropertyImpl; -import hudson.plugins.promoted_builds.PromotedBuildAction; -import hudson.plugins.promoted_builds.Promotion; -import hudson.plugins.promoted_builds.PromotionProcess; -import hudson.plugins.promoted_builds.conditions.FixedResultBuilder; -import hudson.plugins.promoted_builds.conditions.SelfPromotionCondition; -import hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectRule; -import hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair; - -import static hudson.plugins.promoted_builds.util.ItemListenerHelper.fireItemListeners; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.junit.Rule; -import org.junit.Test; -import org.jvnet.hudson.test.Issue; - - -/** - * @author Jacek Tomaka - */ -public class SelfPromotionInheritanceTest { - @Rule - public InheritanceProjectRule j = new InheritanceProjectRule(); - @Test - public void testBasic() throws Exception { - InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase(); - - // promote if the downstream passes - JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase()); - inheritanceProjectPair.getBase().addProperty(promotion); - - PromotionProcess promo1 = promotion.addProcess("promo1"); - promo1.conditions.add(new SelfPromotionCondition(false)); - - PromotionProcess promo2 = promotion.addProcess("promo2"); - promo2.conditions.add(new SelfPromotionCondition(false)); - - - InheritanceBuild b = j.assertBuildStatusSuccess(inheritanceProjectPair.getDerived().scheduleBuild2(0)); - - // internally, the promotion is still an asynchronous process. It just happens - // right away after the build is complete. - j.waitUntilNoActivity(); - - // rebind - promotion = inheritanceProjectPair.getDerived().getProperty(JobPropertyImpl.class, - /*Forcing inheritance as temporary hack for inheritance plugin 1.53 - because that version of the plugin uses inheritance only for certain predefined cases: - -specific methods on the call stack - -url paths. - This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40 - */ - IMode.INHERIT_FORCED); - promo1 = promotion.getItem("promo1"); - promo2 = promotion.getItem("promo2"); - - - // verify that both promotions happened - Promotion pb = promo1.getBuilds().get(0); - assertSame(pb.getTargetBuildOrFail(),b); - - pb = promo2.getBuilds().get(0); - assertSame(pb.getTargetBuildOrFail(),b); - - PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0); - assertTrue(badge.contains(promo1)); - assertTrue(badge.contains(promo2)); - } - @Test - public void testUnstable() throws Exception { - InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase(); - - // promote if the downstream passes - JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase()); - inheritanceProjectPair.getBase().addProperty(promotion); - - PromotionProcess promo1 = promotion.addProcess("promo1"); - promo1.conditions.add(new SelfPromotionCondition(false)); - - PromotionProcess promo2 = promotion.addProcess("promo2"); - promo2.conditions.add(new SelfPromotionCondition(true)); - - - - inheritanceProjectPair.getDerived().getBuildersList().add(unstableBuilder()); - InheritanceBuild b = j.assertBuildStatus(Result.UNSTABLE, inheritanceProjectPair.getDerived().scheduleBuild2(0).get()); - j.waitUntilNoActivity(); - // rebind - promotion = inheritanceProjectPair.getDerived().getProperty(JobPropertyImpl.class, - /*Forcing inheritance as temporary hack for inheritance plugin 1.53 - because that version of the plugin uses inheritance only for certain predefined cases: - -specific methods on the call stack - -url paths. - This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40 - */ - IMode.INHERIT_FORCED); - promo1 = promotion.getItem("promo1"); - promo2 = promotion.getItem("promo2"); - // internally, the promotion is still an asynchronous process. It just happens - // right away after the build is complete. - - - // verify that only one promotions happened - assertTrue(promo1.getBuilds().isEmpty()); - - Promotion pb = promo2.getBuilds().get(0); - assertSame(pb.getTargetBuildOrFail(),b); - - PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0); - assertFalse(badge.contains(promo1)); - assertTrue(badge.contains(promo2)); - } - - @Test - public void testFailure() throws Exception { - InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase(); - - // promote if the downstream passes - JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase()); - inheritanceProjectPair.getBase().addProperty(promotion); - - PromotionProcess promo1 = promotion.addProcess("promo1"); - promo1.conditions.add(new SelfPromotionCondition(false)); - - PromotionProcess promo2 = promotion.addProcess("promo2"); - promo2.conditions.add(new SelfPromotionCondition(true)); - - inheritanceProjectPair.getDerived().getBuildersList().add(failureBuilder()); - InheritanceBuild b = j.assertBuildStatus(Result.FAILURE, inheritanceProjectPair.getDerived().scheduleBuild2(0).get()); - - // internally, the promotion is still an asynchronous process. It just happens - // right away after the build is complete. - j.waitUntilNoActivity(); - - // rebind - promotion = inheritanceProjectPair.getDerived().getProperty(JobPropertyImpl.class, - /*Forcing inheritance as temporary hack for inheritance plugin 1.53 - because that version of the plugin uses inheritance only for certain predefined cases: - -specific methods on the call stack - -url paths. - This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40 - */ - IMode.INHERIT_FORCED); - promo1 = promotion.getItem("promo1"); - promo2 = promotion.getItem("promo2"); - - - // verify that neither promotions happened - assertTrue("promo1 did not occur", promo1.getBuilds().isEmpty()); - assertTrue("promo2 did not occur", promo2.getBuilds().isEmpty()); - - PromotedBuildAction badge = (PromotedBuildAction) b.getBadgeActions().get(0); - assertFalse(badge.contains(promo1)); - assertFalse(badge.contains(promo2)); - } - - @Test - @Issue("JENKINS-22679") - public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception { - String paramName = "param"; - - InheritanceProjectsPair inheritanceProjectPair = j.createInheritanceProjectDerivedWithBase(); - - // promote if the downstream passes - JobPropertyImpl promotion = new JobPropertyImpl(inheritanceProjectPair.getBase()); - inheritanceProjectPair.getBase().addProperty(promotion); - - // TODO review this property asignment after https://issues.jenkins-ci.org/browse/JENKINS-34831 is fixed - inheritanceProjectPair.getBase().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, ""))); - inheritanceProjectPair.getDerived().addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, ""))); - PromotionProcess promo1 = promotion.addProcess("promo1"); - promo1.conditions.add(new SelfPromotionCondition(false)); - - // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+ - fireItemListeners(); - - String paramValue = "someString"; - j.assertBuildStatusSuccess(inheritanceProjectPair.getDerived().scheduleBuild2(0, new Cause.UserCause(), - new ParametersAction(new StringParameterValue(paramName, paramValue)))); - // internally, the promotion is still an asynchronous process. It just happens - // right away after the build is complete. - j.waitUntilNoActivity(); - - // rebind - promotion = inheritanceProjectPair.getDerived().getProperty(JobPropertyImpl.class, - /*Forcing inheritance as temporary hack for inheritance plugin 1.53 - because that version of the plugin uses inheritance only for certain predefined cases: - -specific methods on the call stack - -url paths. - This has been changed as pull request https://github.com/i-m-c/jenkins-inheritance-plugin/pull/40 - */ - IMode.INHERIT_FORCED); - promo1 = promotion.getItem("promo1"); - - // verify that the promotion's environment contains the parameter from the target build. - Promotion pb = promo1.getBuildByNumber(1); - assertEquals(paramValue, pb.getEnvironment(TaskListener.NULL).get(paramName, null)); - } - - private FixedResultBuilder failureBuilder() { - return new FixedResultBuilder(Result.FAILURE); - } - - private FixedResultBuilder unstableBuilder() { - return new FixedResultBuilder(Result.UNSTABLE); - } - -} diff --git a/src/test/java/hudson/plugins/promoted_builds/inheritance/helpers/InheritanceProjectRule.java b/src/test/java/hudson/plugins/promoted_builds/inheritance/helpers/InheritanceProjectRule.java deleted file mode 100644 index af3fd938..00000000 --- a/src/test/java/hudson/plugins/promoted_builds/inheritance/helpers/InheritanceProjectRule.java +++ /dev/null @@ -1,28 +0,0 @@ -package hudson.plugins.promoted_builds.inheritance.helpers; - -import java.io.IOException; - -import org.jvnet.hudson.test.JenkinsRule; - -import hudson.plugins.project_inheritance.projects.InheritanceProject; -import hudson.plugins.project_inheritance.projects.references.SimpleProjectReference; - -public class InheritanceProjectRule extends JenkinsRule { - InheritanceProject createInheritanceProject() throws IOException{ - return createInheritanceProject(createUniqueProjectName()); - } - InheritanceProject createInheritanceProject(String name) throws IOException{ - return jenkins.createProject(InheritanceProject.class, name); - } - /** - * Returns BASE,DERIVED projects - * @throws IOException - */ - public InheritanceProjectsPair createInheritanceProjectDerivedWithBase() throws IOException{ - String baseProjectName = createUniqueProjectName(); - InheritanceProject base = createInheritanceProject(baseProjectName); - InheritanceProject derived = createInheritanceProject(); - derived.addParentReference(new SimpleProjectReference(baseProjectName)); - return new InheritanceProjectsPair(base, derived); - } -} diff --git a/src/test/java/hudson/plugins/promoted_builds/inheritance/helpers/InheritanceProjectsPair.java b/src/test/java/hudson/plugins/promoted_builds/inheritance/helpers/InheritanceProjectsPair.java deleted file mode 100644 index 3c839064..00000000 --- a/src/test/java/hudson/plugins/promoted_builds/inheritance/helpers/InheritanceProjectsPair.java +++ /dev/null @@ -1,22 +0,0 @@ -package hudson.plugins.promoted_builds.inheritance.helpers; - -import hudson.plugins.project_inheritance.projects.InheritanceProject; -/** - * @author Jacek Tomaka - */ -public class InheritanceProjectsPair { - - private InheritanceProject base; - private InheritanceProject derived; - public InheritanceProject getBase() { - return base; - } - public InheritanceProject getDerived() { - return derived; - } - - public InheritanceProjectsPair(InheritanceProject base, InheritanceProject derived){ - this.base = base; - this.derived = derived; - } -}