Search in sources :

Example 1 with Trigger

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);
}
Also used : Trigger(hudson.triggers.Trigger) TimerTrigger(hudson.triggers.TimerTrigger) TimerTrigger(hudson.triggers.TimerTrigger) Test(org.junit.Test)

Example 2 with Trigger

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());
}
Also used : Trigger(hudson.triggers.Trigger) TimerTrigger(hudson.triggers.TimerTrigger) TimerTrigger(hudson.triggers.TimerTrigger) Test(org.junit.Test)

Example 3 with Trigger

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);
}
Also used : SC_INTERNAL_SERVER_ERROR(javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR) BuildTrigger(hudson.tasks.BuildTrigger) Trigger(hudson.triggers.Trigger) SCMTrigger(hudson.triggers.SCMTrigger) NullSCM(hudson.scm.NullSCM) IOException(java.io.IOException) File(java.io.File) Vector(java.util.Vector)

Example 4 with Trigger

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);
                }
            }
        }
    }
}
Also used : TriggerProjectProperty(org.hudsonci.model.project.property.TriggerProjectProperty) Trigger(hudson.triggers.Trigger) ICascadingJob(org.hudsonci.api.model.ICascadingJob) Job(hudson.model.Job)

Example 5 with Trigger

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();
}
Also used : Trigger(hudson.triggers.Trigger) SCMTrigger(hudson.triggers.SCMTrigger) TimerTrigger(hudson.triggers.TimerTrigger) SCMTrigger(hudson.triggers.SCMTrigger) TimerTrigger(hudson.triggers.TimerTrigger) TriggerDescriptor(hudson.triggers.TriggerDescriptor) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Trigger (hudson.triggers.Trigger)6 TimerTrigger (hudson.triggers.TimerTrigger)4 Test (org.junit.Test)4 SCMTrigger (hudson.triggers.SCMTrigger)2 Job (hudson.model.Job)1 NullSCM (hudson.scm.NullSCM)1 BuildTrigger (hudson.tasks.BuildTrigger)1 TriggerDescriptor (hudson.triggers.TriggerDescriptor)1 File (java.io.File)1 IOException (java.io.IOException)1 Vector (java.util.Vector)1 SC_INTERNAL_SERVER_ERROR (javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR)1 ICascadingJob (org.hudsonci.api.model.ICascadingJob)1 TriggerProjectProperty (org.hudsonci.model.project.property.TriggerProjectProperty)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1