Package hudson.maven

Source Code of hudson.maven.MavenProjectTest

/*
* The MIT License
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.maven;

import hudson.model.Item;
import hudson.model.Result;
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks.Shell;

import java.io.File;

import org.junit.Assert;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;

/**
* @author huybrechts
*/
public class MavenProjectTest extends HudsonTestCase {

    public void testOnMaster() throws Exception {
        MavenModuleSet project = createSimpleProject();
        project.setGoals("validate");

        buildAndAssertSuccess(project);
    }

    private MavenModuleSet createSimpleProject() throws Exception {
        return createProject("/simple-projects.zip");
    }

    private MavenModuleSet createProject(final String scmResource) throws Exception {
        MavenModuleSet project = createMavenProject();
        MavenInstallation mi = configureDefaultMaven();
        project.setScm(new ExtractResourceSCM(getClass().getResource(
                scmResource)));
        project.setMaven(mi.getName());
        return project;
    }

    public void testOnSlave() throws Exception {
        MavenModuleSet project = createSimpleProject();
        project.setGoals("validate");
        project.setAssignedLabel(createSlave().getSelfLabel());

        buildAndAssertSuccess(project);
    }

    /**
     * Check if the generated site is linked correctly.
     */
    @Bug(3497)
    public void testSiteBuild() throws Exception {
        MavenModuleSet project = createSimpleProject();
        project.setGoals("site");

        buildAndAssertSuccess(project);

        // this should succeed
        HudsonTestCase.WebClient wc = new WebClient();
        wc.getPage(project,"site");
        try {
            wc.getPage(project,"site/no-such-file");
            fail("should have resulted in 404");
        } catch (FailingHttpStatusCodeException e) {
            assertEquals(404,e.getStatusCode());
        }
    }

    /**
     * Check if the generated site is linked correctly for multi module projects.
     */
    public void testMultiModuleSiteBuild() throws Exception {
        MavenModuleSet project = createProject("maven-multimodule-site.zip");
        project.setGoals("site");

        buildAndAssertSuccess(project);

        // this should succeed
        HudsonTestCase.WebClient wc = new WebClient();
        wc.getPage(project, "site");
        wc.getPage(project, "site/core");
        wc.getPage(project, "site/client");
       
        //@Bug(7577): check that site generation succeeds also if only a single module is build
        MavenModule coreModule = project.getModule("mmtest:core");
        Assert.assertEquals("site", coreModule.getGoals());
        buildAndAssertSuccess(coreModule);
        wc.getPage(project, "site/core");
    }
   
    /**
     * Check if the the site goal will work when run from a slave.
     */
    @Bug(5943)
    public void testMultiModuleSiteBuildOnSlave() throws Exception {
        MavenModuleSet project = createProject("maven-multimodule-site.zip");
        project.setGoals("site");
        project.setAssignedLabel(createSlave().getSelfLabel());

        buildAndAssertSuccess(project);

        // this should succeed
        HudsonTestCase.WebClient wc = new WebClient();
        wc.getPage(project, "site");
        wc.getPage(project, "site/core");
        wc.getPage(project, "site/client");
    }

    @Bug(6779)
    public void testDeleteSetBuildDeletesModuleBuilds() throws Exception {
        MavenModuleSet project = createProject("maven-multimod.zip");
        project.setGoals("package");
        buildAndAssertSuccess(project);
        buildAndAssertSuccess(project.getModule("org.jvnet.hudson.main.test.multimod:moduleB"));
        buildAndAssertSuccess(project);
        assertEquals(2, project.getBuilds().size()); // Module build does not add a ModuleSetBuild
        project.getFirstBuild().delete();
        // A#1, B#1 and B#2 should all be deleted too
        assertEquals(1, project.getModule("org.jvnet.hudson.main.test.multimod:moduleA").getBuilds().size());
        assertEquals(1, project.getModule("org.jvnet.hudson.main.test.multimod:moduleB").getBuilds().size());
    }
    @Bug(7261)
    public void testAbsolutePathPom() throws Exception {
        File pom = new File(this.getClass().getResource("test-pom-7162.xml").toURI());
        MavenModuleSet project = createMavenProject();
        MavenInstallation mi = configureDefaultMaven();
        project.setMaven(mi.getName());
        project.setRootPOM(pom.getAbsolutePath());
        project.setGoals("install");
        buildAndAssertSuccess(project);
    }

    /**
     * Config roundtrip test around pre/post build step
     */
    public void testConfigRoundtrip() throws Exception {
        MavenModuleSet m = createMavenProject();
        Shell b1 = new Shell("1");
        Shell b2 = new Shell("2");
        m.getPrebuilders().add(b1);
        m.getPostbuilders().add(b2);
        configRoundtrip((Item)m);

        assertEquals(1,  m.getPrebuilders().size());
        assertNotSame(b1,m.getPrebuilders().get(Shell.class));
        assertEquals("1",m.getPrebuilders().get(Shell.class).getCommand());

        assertEquals(1,  m.getPostbuilders().size());
        assertNotSame(b2,m.getPostbuilders().get(Shell.class));
        assertEquals("2",m.getPostbuilders().get(Shell.class).getCommand());

        for (Result r : new Result[]{Result.SUCCESS, Result.UNSTABLE, Result.FAILURE}) {
            m.setRunPostStepsIfResult(r);
            configRoundtrip((Item)m);
            assertEquals(r,m.getRunPostStepsIfResult());
        }
    }
}
TOP

Related Classes of hudson.maven.MavenProjectTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.