use of hudson.triggers.Trigger in project hudson-2.x by hudson.
the class TriggerProjectPropertyTest method testUpdateOriginalValue.
/**
* Test updateOriginalValue method for TriggerProjectProperty.
*
* @throws antlr.ANTLRException if any
*/
@Test
public void testUpdateOriginalValue() throws ANTLRException {
Trigger originalTrigger = new TimerTrigger("* * * * *");
Trigger cascadingTrigger = new TimerTrigger("* * * * *");
property.updateOriginalValue(originalTrigger, cascadingTrigger);
//Property isn't overridden because of values equal.
assertFalse(property.isOverridden());
//If trigger property value equals to cascading be sure that sets original value instead of cascading.
assertEquals(property.getOriginalValue(), originalTrigger);
cascadingTrigger = new TimerTrigger("*/2 * * * *");
property.updateOriginalValue(originalTrigger, cascadingTrigger);
assertTrue(property.isOverridden());
assertEquals(property.getOriginalValue(), originalTrigger);
}
use of hudson.triggers.Trigger in project hudson-2.x by hudson.
the class TriggerProjectPropertyTest method testClearOriginalValue.
/**
* Verify {@link TriggerProjectProperty#clearOriginalValue(hudson.triggers.Trigger)} method.
*
* @throws antlr.ANTLRException if any
*/
@Test
public void testClearOriginalValue() throws ANTLRException {
//Overridden flag should be cleared to false. Pre-set true value
property.setOverridden(true);
assertTrue(property.isOverridden());
Trigger trigger = new TimerTrigger("* * * * *");
property.clearOriginalValue(trigger);
//Original value should be set with overridden flag == false
assertFalse(property.isOverridden());
assertTrue(trigger == property.getOriginalValue());
}
use of hudson.triggers.Trigger in project hudson-2.x by hudson.
the class AbstractProject method onLoad.
@Override
public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
super.onLoad(parent, name);
this.builds = new RunMap<R>();
this.builds.load(this, new Constructor<R>() {
public R create(File dir) throws IOException {
return loadBuild(dir);
}
});
// boolean! Can't tell if xml file contained false..
if (enableRemoteTrigger)
OldDataMonitor.report(this, "1.77");
for (Trigger t : getTriggerDescribableList()) {
t.start(this, false);
}
if (scm == null)
// perhaps it was pointing to a plugin that no longer exists.
scm = new NullSCM();
if (transientActions == null)
// happens when loaded from disk
transientActions = new Vector<Action>();
updateTransientActions();
getTriggerDescribableList().setOwner(this);
}
use of hudson.triggers.Trigger in project hudson-2.x by hudson.
the class CascadingUtil method setChildrenTrigger.
/**
* Sets trigger for job and all its children if necessary.
*
* @param job parentJob
* @param descriptor trigger descriptor
* @param key trigger property key
* @param req stapler request
* @param json submited json
* @throws Descriptor.FormException if incorrect parameters
*/
@SuppressWarnings("unchecked")
public static void setChildrenTrigger(Job job, TriggerDescriptor descriptor, String key, StaplerRequest req, JSONObject json) throws Descriptor.FormException {
TriggerProjectProperty property = CascadingUtil.getTriggerProjectProperty(job, key);
if (property.getValue() != null) {
property.getValue().stop();
}
Trigger trigger = null;
if (json.has(key)) {
trigger = descriptor.newInstance(req, json.getJSONObject(key));
trigger.start(job, true);
}
property.setValue(trigger);
Set<String> cascadingChildrenNames = job.getCascadingChildrenNames();
if (null != cascadingChildrenNames) {
for (String childName : cascadingChildrenNames) {
Job childJob = (Job) Hudson.getInstance().getItem(childName);
if (null != childJob && StringUtils.equals(job.getName(), childJob.getCascadingProjectName())) {
TriggerProjectProperty childProperty = CascadingUtil.getTriggerProjectProperty(childJob, key);
if (!childProperty.isOverridden()) {
setChildrenTrigger(childJob, descriptor, key, req, json);
} else if (!childProperty.allowOverrideValue(trigger, childProperty.getValue())) {
childProperty.setOverridden(false);
}
}
}
}
}
use of hudson.triggers.Trigger in project hudson-2.x by hudson.
the class LegacyProjectTest method testConvertLegacyTriggers.
/**
* Tests unmarshalling FreeStyleProject configuration and checks whether Triggers properties
* from Job are configured.
*
* @throws Exception if any.
*/
@Test
public void testConvertLegacyTriggers() throws Exception {
AbstractProject project = (AbstractProject) Items.getConfigFile(config).read();
project.setAllowSave(false);
project.initProjectProperties();
Hudson hudson = createMock(Hudson.class);
String scmTriggerPropertyKey = "hudson-trigger-SCMTrigger";
TriggerDescriptor scmTriggerDescriptor = createMock(SCMTrigger.DescriptorImpl.class);
expect(scmTriggerDescriptor.getJsonSafeClassName()).andReturn(scmTriggerPropertyKey);
expect(hudson.getDescriptorOrDie(SCMTrigger.class)).andReturn(scmTriggerDescriptor);
String timerTriggerPropertyKey = "hudson-trigger-TimerTrigger";
TriggerDescriptor timerTriggerDescriptor = createMock(TimerTrigger.DescriptorImpl.class);
expect(timerTriggerDescriptor.getJsonSafeClassName()).andReturn(timerTriggerPropertyKey);
expect(hudson.getDescriptorOrDie(TimerTrigger.class)).andReturn(timerTriggerDescriptor);
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
replayAll();
project.setAllowSave(false);
project.initProjectProperties();
assertNull(project.getProperty(scmTriggerPropertyKey));
assertNull(project.getProperty(timerTriggerPropertyKey));
project.convertTriggerProperties();
assertNotNull(project.getProperty(scmTriggerPropertyKey));
Trigger trigger = (Trigger) project.getProperty(scmTriggerPropertyKey).getValue();
assertEquals("5 * * * *", trigger.getSpec());
assertNotNull(project.getProperty(timerTriggerPropertyKey));
trigger = (Trigger) project.getProperty(timerTriggerPropertyKey).getValue();
assertEquals("*/10 * * * *", trigger.getSpec());
verifyAll();
}
Aggregations