Search in sources :

Example 1 with TimerTrigger

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

the class CascadingTriggersTest method testSetChildrenTriggerOverridden.

/**
     * Tests if trigger property correctly marked as overridden.
     *
     * @throws Exception if any.
     */
@Test
public void testSetChildrenTriggerOverridden() throws Exception {
    CascadingUtil.setChildrenTrigger(p1, descriptor, propertyKey, req, json);
    CascadingUtil.getTriggerProjectProperty(p2, propertyKey).setValue(new TimerTrigger("*/2 * * * *"));
    CascadingUtil.setChildrenTrigger(p1, descriptor, propertyKey, req, json);
    assertTrue(CascadingUtil.getTriggerProjectProperty(p2, propertyKey).isOverridden());
    verifyAll();
}
Also used : TimerTrigger(hudson.triggers.TimerTrigger) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with TimerTrigger

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

the class CascadingTriggersTest method testSetChildrenTriggerOverridenFalse.

/**
     * Tests if trigger property marked as non overridden when its value match the cascading value.
     *
     * @throws Exception if any
     */
@Test
public void testSetChildrenTriggerOverridenFalse() throws Exception {
    CascadingUtil.setChildrenTrigger(p1, descriptor, propertyKey, req, json);
    CascadingUtil.getTriggerProjectProperty(p2, propertyKey).setValue(new TimerTrigger("*/2 * * * *"));
    CascadingUtil.setChildrenTrigger(p1, descriptor, propertyKey, req, json);
    assertTrue(CascadingUtil.getTriggerProjectProperty(p2, propertyKey).isOverridden());
    CascadingUtil.getTriggerProjectProperty(p2, propertyKey).setValue(new TimerTrigger("* * * * *"));
    CascadingUtil.setChildrenTrigger(p1, descriptor, propertyKey, req, json);
    assertFalse(CascadingUtil.getTriggerProjectProperty(p2, propertyKey).isOverridden());
    verifyAll();
}
Also used : TimerTrigger(hudson.triggers.TimerTrigger) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with TimerTrigger

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

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

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

the class CascadingTriggersTest method setUp.

@Before
public void setUp() throws Exception {
    p1 = new FreeStyleProjectMock("p1");
    p2 = new FreeStyleProjectMock("p2");
    p3 = new FreeStyleProjectMock("p3");
    p2.setCascadingProject(p1);
    CascadingUtil.linkCascadingProjectsToChild(p1, "p2");
    p3.setCascadingProject(p2);
    CascadingUtil.linkCascadingProjectsToChild(p2, "p3");
    descriptor = new TimerTrigger.DescriptorImpl();
    propertyKey = descriptor.getJsonSafeClassName();
    req = createMock(StaplerRequest.class);
    json = new JSONObject();
    JSONObject refspec = new JSONObject();
    refspec.put("refspec", "* * * * *");
    json.put(propertyKey, refspec);
    expect(req.bindJSON(TimerTrigger.class, refspec)).andReturn(new TimerTrigger("* * * * *")).anyTimes();
    mockStatic(Hudson.class);
    Hudson hudson = createMock(Hudson.class);
    expect(hudson.getDescriptorOrDie(TimerTrigger.class)).andReturn(descriptor).anyTimes();
    expect(hudson.getItem("p2")).andReturn(p2).anyTimes();
    expect(hudson.getItem("p3")).andReturn(p3).anyTimes();
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replay(Hudson.class, hudson, req);
}
Also used : FreeStyleProjectMock(hudson.model.FreeStyleProjectMock) JSONObject(net.sf.json.JSONObject) Hudson(hudson.model.Hudson) StaplerRequest(org.kohsuke.stapler.StaplerRequest) TimerTrigger(hudson.triggers.TimerTrigger) Before(org.junit.Before)

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