@@ -0,0 +1,3490 @@
+/*%0A * The MIT License%0A *%0A * Copyright (c) 2004-2009, Sun Microsystems, Inc., Alan Harder%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the Software is%0A * furnished to do so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in%0A * all copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN%0A * THE SOFTWARE.%0A */%0Apackage hudson.tasks;%0A%0Aimport com.gargoylesoftware.htmlunit.html.HtmlForm;%0Aimport com.gargoylesoftware.htmlunit.html.HtmlPage;%0Aimport hudson.model.Build;%0Aimport hudson.model.Project;%0Aimport hudson.model.Result;%0Aimport org.jvnet.hudson.test.HudsonTestCase;%0Aimport org.jvnet.hudson.test.MockBuilder;%0A%0A/**%0A * Tests for hudson.tasks.BuildTrigger%0A * @author Alan.Harder@sun.com%0A */%0Apublic class BuildTriggerTest extends HudsonTestCase %7B%0A    private void doTriggerTest(boolean evenWhenUnstable, Result triggerResult,%0A            Result dontTriggerResult) throws Exception %7B%0A        Project p = createFreeStyleProject(),%0A                dp = createFreeStyleProject(%22downstream%22);%0A        p.getPublishersList().add(new BuildTrigger(%22downstream%22, evenWhenUnstable));%0A        p.getBuildersList().add(new MockBuilder(dontTriggerResult));%0A        hudson.rebuildDependencyGraph();%0A%0A        // Hm, no setQuietPeriod, have to submit form..%0A        WebClient webClient = new WebClient();%0A        HtmlPage page = webClient.getPage(dp,%22configure%22);%0A        HtmlForm form = page.getFormByName(%22config%22);%0A        form.getInputByName(%22hasCustomQuietPeriod%22).click();%0A        form.getInputByName(%22quiet_period%22).setValueAttribute(%220%22);%0A        submit(form);%0A        assertEquals(%22set quiet period%22, 0, dp.getQuietPeriod());%0A%0A        // First build should not trigger downstream job%0A        Build b = (Build)p.scheduleBuild2(0).get();%0A        for (int i = 0; i %3C 3; i++) %7B%0A            Thread.sleep(200);%0A            assertTrue(%22downstream build should not run!  upstream log: %22 + getLog(b),%0A                       !dp.isInQueue() && !dp.isBuilding() && dp.getLastBuild()==null);%0A        %7D%0A%0A        // Next build should trigger downstream job%0A        p.getBuildersList().replace(new MockBuilder(triggerResult));%0A        b = (Build)p.scheduleBuild2(0).get();%0A        // Wait for downstream build%0A        for (int i = 0; dp.getLastBuild()==null && i %3C 20; i++) Thread.sleep(100);%0A        assertNotNull(%22downstream build didn't run.. upstream log: %22 + getLog(b), dp.getLastBuild());%0A    %7D%0A%0A    public void testBuildTrigger() throws Exception %7B%0A        doTriggerTest(false, Result.SUCCESS, Result.UNSTABLE);%0A    %7D%0A%0A    public void testTriggerEvenWhenUnstable() throws Exception %7B%0A        doTriggerTest(true, Result.UNSTABLE, Result.FAILURE);%0A    %7D%0A%7D%0A

Add unit test for BuildTrigger