Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-14759] Job created by posting config.xml to /createIte…
…m does not set GitHub webhook.
- Loading branch information
Showing
8 changed files
with
177 additions
and
7 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
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
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
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
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
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
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
138 changes: 138 additions & 0 deletions
138
test/src/test/java/hudson/triggers/TriggerStartTest.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,138 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2012 Jesse Glick. | ||
* | ||
* 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.triggers; | ||
|
||
import hudson.model.AbstractProject; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.model.Item; | ||
import hudson.model.Items; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ObjectStreamException; | ||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.xml.transform.Source; | ||
import javax.xml.transform.stream.StreamSource; | ||
import static org.junit.Assert.*; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Bug; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.TestExtension; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
@Bug(14759) | ||
public class TriggerStartTest { | ||
|
||
@Rule public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test public void loadCallsStartFalse() throws Exception { | ||
FreeStyleProject p = j.createFreeStyleProject(); | ||
MockTrigger t = new MockTrigger(); | ||
p.addTrigger(t); | ||
p.save(); | ||
p = (FreeStyleProject) Items.load(p.getParent(), p.getRootDir()); | ||
t = p.getTrigger(MockTrigger.class); | ||
assertNotNull(t); | ||
assertEquals("[false]", t.calls.toString()); | ||
} | ||
|
||
@Test public void submitCallsStartTrue() throws Exception { | ||
FreeStyleProject p = j.createFreeStyleProject(); | ||
MockTrigger t = new MockTrigger(); | ||
p.addTrigger(t); | ||
p.save(); | ||
p = j.configRoundtrip(p); | ||
t = p.getTrigger(MockTrigger.class); | ||
assertNotNull(t); | ||
assertEquals("[true]", t.calls.toString()); | ||
} | ||
|
||
@Test public void updateByXmlCallsStartTrue() throws Exception { | ||
FreeStyleProject p = j.createFreeStyleProject(); | ||
String xml = p.getConfigFile().asString(); | ||
xml = xml.replace(" <triggers class=\"vector\"/>\n", triggersSection()); | ||
Source newXML = new StreamSource(new StringReader(xml)); | ||
p.updateByXml(newXML); | ||
MockTrigger t = p.getTrigger(MockTrigger.class); | ||
assertNotNull(t); | ||
assertEquals("[true]", t.calls.toString()); | ||
} | ||
|
||
@Test public void createProjectFromXmlCallsStartTrue() throws Exception { | ||
FreeStyleProject p = (FreeStyleProject) j.jenkins.createProjectFromXML("whatever", new ByteArrayInputStream(("<project>\n <builders/>\n <publishers/>\n <buildWrappers/>\n" + triggersSection() + "</project>").getBytes())); | ||
MockTrigger t = p.getTrigger(MockTrigger.class); | ||
assertNotNull(t); | ||
assertEquals("[true]", t.calls.toString()); | ||
} | ||
|
||
@Test public void copyCallsStartTrue() throws Exception { | ||
AbstractProject<?,?> p = j.createFreeStyleProject(); | ||
MockTrigger t = new MockTrigger(); | ||
p.addTrigger(t); | ||
p.save(); | ||
p = j.jenkins.copy(p, "nue"); | ||
t = p.getTrigger(MockTrigger.class); | ||
assertNotNull(t); | ||
assertEquals("[true]", t.calls.toString()); | ||
} | ||
|
||
private String triggersSection() { | ||
String tagname = MockTrigger.class.getName().replace("$", "_-"); | ||
return " <triggers class=\"vector\">\n <" + tagname + ">\n <spec/>\n </" + tagname + ">\n </triggers>\n"; | ||
} | ||
|
||
public static class MockTrigger extends Trigger<Item> { | ||
|
||
public transient List<Boolean> calls = new ArrayList<Boolean>(); | ||
|
||
@DataBoundConstructor public MockTrigger() {} | ||
|
||
@Override public void start(Item project, boolean newInstance) { | ||
super.start(project, newInstance); | ||
calls.add(newInstance); | ||
} | ||
|
||
@Override protected Object readResolve() throws ObjectStreamException { | ||
calls = new ArrayList<Boolean>(); | ||
return super.readResolve(); | ||
} | ||
|
||
@TestExtension | ||
public static class DescriptorImpl extends TriggerDescriptor { | ||
|
||
@Override public boolean isApplicable(Item item) { | ||
return true; | ||
} | ||
|
||
@Override public String getDisplayName() { | ||
return "mock trigger"; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |