Search in sources :

Example 6 with TimerTrigger

use of hudson.triggers.TimerTrigger 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)

Example 7 with TimerTrigger

use of hudson.triggers.TimerTrigger in project hudson-2.x by hudson.

the class TriggerProjectPropertyTest method testOnCascadingProjectRemoved.

/**
     * Verify {@link TriggerProjectProperty#onCascadingProjectRemoved()} method.
     *
     * @throws antlr.ANTLRException if any
     */
@Test
public void testOnCascadingProjectRemoved() throws ANTLRException {
    Trigger trigger = new TimerTrigger("* * * * *");
    property.setOriginalValue(trigger, false);
    assertTrue(trigger == property.getOriginalValue());
    assertFalse(property.isOverridden());
    property.onCascadingProjectRemoved();
    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)

Aggregations

TimerTrigger (hudson.triggers.TimerTrigger)7 Test (org.junit.Test)6 Trigger (hudson.triggers.Trigger)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 FreeStyleProjectMock (hudson.model.FreeStyleProjectMock)1 Hudson (hudson.model.Hudson)1 SCMTrigger (hudson.triggers.SCMTrigger)1 TriggerDescriptor (hudson.triggers.TriggerDescriptor)1 JSONObject (net.sf.json.JSONObject)1 Before (org.junit.Before)1 StaplerRequest (org.kohsuke.stapler.StaplerRequest)1