From 0a53e45d7f13abbb85ec63c97e4ce9559182389a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 20 Jul 2013 13:30:13 +1000 Subject: [PATCH] prepare test suite for mvn 3.1.x --- .../org/jvnet/hudson/test/HudsonTestCase.java | 10 +- .../java/hudson/maven/Maven3BuildTest.java | 258 ------------------ 2 files changed, 9 insertions(+), 259 deletions(-) delete mode 100755 test/src/test/java/hudson/maven/Maven3BuildTest.java diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index db7701ae7d..0abf3bb95d 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -545,7 +545,15 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { MavenInstallation m3 = new MavenInstallation("apache-maven-3.0.1",mvn.getHome(), NO_PROPERTIES); jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(m3); return m3; - } + } + + protected MavenInstallation configureMaven31() throws Exception { + MavenInstallation mvn = configureDefaultMaven("apache-maven-3.1.0", MavenInstallation.MAVEN_30); + + MavenInstallation m3 = new MavenInstallation("apache-maven-3.1.0",mvn.getHome(), NO_PROPERTIES); + jenkins.getDescriptorByType(Maven.DescriptorImpl.class).setInstallations(m3); + return m3; + } /** * Locates Maven2 and configure that as the only Maven in the system. diff --git a/test/src/test/java/hudson/maven/Maven3BuildTest.java b/test/src/test/java/hudson/maven/Maven3BuildTest.java deleted file mode 100755 index 09adf18b49..0000000000 --- a/test/src/test/java/hudson/maven/Maven3BuildTest.java +++ /dev/null @@ -1,258 +0,0 @@ -package hudson.maven; - -/* - * Olivier Lamy - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import hudson.Launcher; -import hudson.model.*; -import hudson.tasks.Maven.MavenInstallation; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; - -import hudson.tasks.test.AbstractTestResultAction; -import hudson.tasks.test.TestResultProjectAction; -import org.apache.commons.io.FileUtils; -import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.Email; -import org.jvnet.hudson.test.ExtractResourceSCM; -import org.jvnet.hudson.test.HudsonTestCase; - -/** - * @author Olivier Lamy - */ -public class Maven3BuildTest extends HudsonTestCase { - - public void testSimpleMaven3Build() throws Exception { - - MavenModuleSet m = createMavenProject(); - MavenInstallation mavenInstallation = configureMaven3(); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip"))); - m.setGoals( "clean install" ); - MavenModuleSetBuild b = buildAndAssertSuccess(m); - assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) ); - } - - public void testSimpleMaven3BuildRedeployPublisher() throws Exception { - - MavenModuleSet m = createMavenProject(); - MavenInstallation mavenInstallation = configureMaven3(); - m.setMaven( mavenInstallation.getName() ); - File repo = createTmpDir(); - FileUtils.cleanDirectory( repo ); - m.getReporters().add(new TestReporter()); - m.getPublishersList().add(new RedeployPublisher("",repo.toURI().toString(),true, false)); - m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip"))); - m.setGoals( "clean install" ); - MavenModuleSetBuild b = buildAndAssertSuccess(m); - assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) ); - File artifactDir = new File(repo,"com/mycompany/app/my-app/1.7-SNAPSHOT/"); - String[] files = artifactDir.list( new FilenameFilter() - { - - public boolean accept( File dir, String name ) - { - System.out.println("file name : " +name ); - return name.endsWith( ".jar" ); - } - }); - assertTrue("SNAPSHOT exist",!files[0].contains( "SNAPSHOT" )); - assertTrue("file not ended with -1.jar", files[0].endsWith( "-1.jar" )); - } - - public void testSiteBuildWithForkedMojo() throws Exception { - MavenModuleSet m = createMavenProject(); - MavenInstallation mavenInstallation = configureMaven3(); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("maven3-project.zip"))); - m.setGoals( "clean site" ); - MavenModuleSetBuild b = buildAndAssertSuccess(m); - assertTrue( MavenUtil.maven3orLater( b.getMavenVersionUsed() ) ); - } - - @Bug(value=8395) - public void testMaven3BuildWrongScope() throws Exception { - - File pom = new File(this.getClass().getResource("test-pom-8395.xml").toURI()); - MavenModuleSet m = createMavenProject(); - MavenInstallation mavenInstallation = configureMaven3(); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setRootPOM(pom.getAbsolutePath()); - m.setGoals( "clean validate" ); - MavenModuleSetBuild mmsb = m.scheduleBuild2( 0 ).get(); - assertBuildStatus( Result.FAILURE, mmsb ); - System.out.println("mmsb.getProject().getModules " + mmsb.getProject().getModules() ); - assertTrue( mmsb.getProject().getModules().isEmpty()); - } - - @Bug(value=8390) - public void testMaven3BuildWrongInheritence() throws Exception { - - MavenModuleSet m = createMavenProject(); - MavenInstallation mavenInstallation = configureMaven3(); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("incorrect-inheritence-testcase.zip"))); - m.setGoals( "clean validate" ); - MavenModuleSetBuild mmsb = m.scheduleBuild2( 0 ).get(); - assertBuildStatus( Result.FAILURE, mmsb ); - System.out.println("mmsb.getProject().getModules " + mmsb.getProject().getModules() ); - assertTrue( mmsb.getProject().getModules().isEmpty()); - } - - @Bug(value=8445) - public void testMavenSeveralModulesInDirectory() throws Exception { - - MavenModuleSet m = createMavenProject(); - MavenInstallation mavenInstallation = configureMaven3(); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("several-modules-in-directory.zip"))); - m.setGoals( "clean validate" ); - MavenModuleSetBuild mmsb = buildAndAssertSuccess(m); - assertFalse( mmsb.getProject().getModules().isEmpty()); - } - - @Email("https://groups.google.com/d/msg/hudson-users/Xhw00UopVN0/FA9YqDAIsSYJ") - public void testMavenWithDependencyVersionInEnvVar() throws Exception { - - MavenModuleSet m = createMavenProject(); - MavenInstallation mavenInstallation = configureMaven3(); - ParametersDefinitionProperty parametersDefinitionProperty = - new ParametersDefinitionProperty(new StringParameterDefinition( "JUNITVERSION", "3.8.2" )); - - m.addProperty( parametersDefinitionProperty ); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("envars-maven-project.zip"))); - m.setGoals( "clean test-compile" ); - MavenModuleSetBuild mmsb = buildAndAssertSuccess(m); - assertFalse( mmsb.getProject().getModules().isEmpty()); - } - - @Bug(8484) - public void testMultiModMavenNonRecursive() throws Exception { - MavenInstallation mavenInstallation = configureMaven3(); - MavenModuleSet m = createMavenProject(); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("maven-multimod.zip"))); - m.setGoals( "-N validate" ); - assertTrue("MavenModuleSet.isNonRecursive() should be true", m.isNonRecursive()); - buildAndAssertSuccess(m); - assertEquals("not only one module", 1, m.getModules().size()); - } - - @Bug(8573) - public void testBuildTimeStampProperty() throws Exception { - MavenInstallation mavenInstallation = configureMaven3(); - MavenModuleSet m = createMavenProject(); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-8573.zip"))); - m.setGoals( "process-resources" ); - buildAndAssertSuccess(m); - String content = m.getLastBuild().getWorkspace().child( "target/classes/test.txt" ).readToString(); - assertFalse( content.contains( "${maven.build.timestamp}") ); - assertFalse( content.contains( "${maven.build.timestamp}") ); - } - - @Bug(1557) - public void testDuplicateTestResults() throws Exception { - MavenInstallation mavenInstallation = configureMaven3(); - MavenModuleSet m = createMavenProject(); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-1557.zip"))); - m.setGoals("verify"); - buildAndAssertSuccess(m); - - int totalCount = m.getModules().iterator().next() - .getAction(TestResultProjectAction.class).getLastTestResultAction().getTotalCount(); - assertEquals(4, totalCount); - } - - @Bug(9326) - public void testTychoTestResults() throws Exception { - MavenInstallation mavenInstallation = configureMaven3(); - MavenModuleSet m = createMavenProject(); - m.setRootPOM( "org.foobar.build/pom.xml" ); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("JENKINS-9326.zip"),"foobar")); - m.setGoals("verify"); - buildAndAssertSuccess(m); - - System.out.println("modules size " + m.getModules()); - - - MavenModule testModule = null; - for (MavenModule mavenModule : m.getModules()) { - System.out.println("module " + mavenModule.getName() + "/" + mavenModule.getDisplayName()); - if ("org.foobar:org.foobar.test".equals( mavenModule.getName() )) testModule = mavenModule; - } - - AbstractTestResultAction trpa = testModule.getLastBuild().getTestResultAction(); - - int totalCount = trpa.getTotalCount(); - assertEquals(1, totalCount); - } - - @Bug(9326) - public void testTychoEclipseTestResults() throws Exception { - MavenInstallation mavenInstallation = configureMaven3(); - MavenModuleSet m = createMavenProject(); - m.setRootPOM( "org.foobar.build/pom.xml" ); - m.setMaven( mavenInstallation.getName() ); - m.getReporters().add(new TestReporter()); - m.setScm(new ExtractResourceSCM(getClass().getResource("foobar_eclipse_with_fix.zip"),"foobar_eclipse")); - m.setGoals("verify"); - buildAndAssertSuccess(m); - - System.out.println("modules size " + m.getModules()); - - - MavenModule testModule = null; - for (MavenModule mavenModule : m.getModules()) { - System.out.println("module " + mavenModule.getName() + "/" + mavenModule.getDisplayName()); - if ("org.foobar:org.foobar.test".equals( mavenModule.getName() )) testModule = mavenModule; - } - - AbstractTestResultAction trpa = testModule.getLastBuild().getTestResultAction(); - - int totalCount = trpa.getTotalCount(); - assertEquals(1, totalCount); - } - - private static class TestReporter extends MavenReporter { - @Override - public boolean end(MavenBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { - assertNotNull(build.getProject().getWorkspace()); - assertNotNull(build.getWorkspace()); - return true; - } - } - -} -- GitLab