Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#74] integration tests #81

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
name: Verify
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v3
with:
ff-goal: '-P run-its install' # site use project version for reporting
verify-goal: '-P run-its install' # should be the same as for first build
ff-goal: '-ntp -P run-its verify' # site use project version for reporting
verify-goal: '-ntp -P run-its verify' # should be the same as for first build

deploy:
name: Deploy
Expand Down
50 changes: 43 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,18 @@
<mojo.java.target>8</mojo.java.target>
<wagon.api.version>3.0.0</wagon.api.version>

<takari-plugin-testing.version>2.9.0</takari-plugin-testing.version>
<takari-lifecycle-plugin.version>1.12.2</takari-lifecycle-plugin.version>
<!-- Test plugins -->
<takari-plugin-testing.version>2.9.2</takari-plugin-testing.version>
<takari-lifecycle-plugin.version>2.0.0</takari-lifecycle-plugin.version>

<ftpserver.version>1.1.1</ftpserver.version>
<project.build.outputTimestamp>2022-01-18T09:14:02Z</project.build.outputTimestamp>

<!-- logging -->
<dependency.slf4j.version>1.7.9</dependency.slf4j.version>

<!-- Test dependencies -->
<dependency.jetty.version>9.4.51.v20230217</dependency.jetty.version>
<ftpserver.version>1.1.1</ftpserver.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -181,7 +188,13 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.9</version>
<version>${dependency.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${dependency.slf4j.version}</version>
<scope>test</scope>
</dependency>

<!-- needed to debug plugin under m2e -->
Expand Down Expand Up @@ -210,12 +223,21 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${dependency.jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
<version>${dependency.jetty.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>

<defaultGoal>install</defaultGoal>

<pluginManagement>
<plugins>
<plugin>
Expand Down Expand Up @@ -297,6 +319,20 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ private void disconnectWagon( Wagon wagon )
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ public void execute()
protected abstract void execute( Wagon wagon )
throws MojoExecutionException, WagonException, IOException;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ protected WagonFileSet getWagonFileSet( String fromDir, String includes, String
{
return WagonUtils.getWagonFileSet( fromDir, includes, excludes, caseSensitive, toDir );
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/mojo/wagon/CopyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ protected void copy( Wagon srcWagon, Wagon targetWagon )
wagonCopy.copy( srcWagon, fileSet, targetWagon, optimize, this.getLog() );
}

}
}
2 changes: 1 addition & 1 deletion src/main/java/org/codehaus/mojo/wagon/ExistMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ protected void execute( Wagon wagon )
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ protected void copy( Wagon srcWagon, Wagon targetWagon )
mavenRepoMerger.merge( srcWagon, targetWagon, optimize, this.getLog() );
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.util.Arrays;

import org.apache.maven.plugin.logging.Log;
import org.apache.maven.shared.model.fileset.FileSet;
import org.apache.maven.shared.model.fileset.util.FileSetManager;
import org.apache.maven.wagon.CommandExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.io.IOException;

import org.apache.maven.plugin.logging.Log;
import org.apache.maven.shared.model.fileset.FileSet;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.WagonException;
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/org/codehaus/mojo/wagon/AbstractJettyIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.codehaus.mojo.wagon;

import java.io.IOException;
import java.nio.file.Path;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.junit.After;
import org.junit.Before;

public abstract class AbstractJettyIT {

private Server server;
private int port;

@Before
public void runJetty() throws Exception {
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
connector.setHost("localhost");
server.addConnector(connector);

ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setResourceBase(getDirectoryToServe().toString());

HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
server.setHandler(handlers);

server.start();
this.port = connector.getLocalPort();
}


@After
public void tearDown() throws Exception {
server.stop();
}

protected int getServerPort() {
return this.port;
}

protected abstract Path getDirectoryToServe() throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import java.io.File;

import java.io.IOException;
import java.nio.file.Path;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -17,17 +20,21 @@

@RunWith( MavenJUnitTestRunner.class )
@MavenVersions( { "3.6.3" } )
public class Wagon334MojoHttpTest
public class Wagon334MojoHttpIT extends AbstractJettyIT
{
@Rule
public final TestResources resources = new TestResources();

public final MavenRuntime maven;
private final MavenRuntimeBuilder mavenBuilder;
public MavenRuntime maven;

public Wagon334MojoHttpTest(MavenRuntimeBuilder builder )
throws Exception
{
this.maven = builder.withCliOptions( "-B" ).build();
public Wagon334MojoHttpIT(MavenRuntimeBuilder builder ) {
this.mavenBuilder = builder.withCliOptions( "-B" );
}

@Before
public void setPort() throws Exception {
this.maven = this.mavenBuilder.withCliOptions( "-Dserver.port=" + getServerPort() ).build();
}

@Test
Expand All @@ -46,4 +53,10 @@ public void testDownload()
Assert.assertTrue( new File(downloadDir, "commons-dbutils-1.2-bin.tar.gz.asc.md5" ).exists() );
Assert.assertTrue( new File(downloadDir, "commons-dbutils-1.2-bin.tar.gz.asc.sha1" ).exists() );
}

@Override
protected Path getDirectoryToServe() throws IOException {
return resources.getBasedir("http-download-02").toPath()
.resolve("files");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package org.codehaus.mojo.wagon;

import io.takari.maven.testing.TestResources;
import io.takari.maven.testing.executor.MavenExecution;
import io.takari.maven.testing.executor.MavenExecutionResult;
import io.takari.maven.testing.executor.MavenRuntime;
import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
import java.io.File;

import org.apache.ftpserver.ConnectionConfigFactory;
import org.apache.ftpserver.FtpServer;
import org.apache.ftpserver.FtpServerFactory;
Expand All @@ -15,25 +21,17 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import io.takari.maven.testing.TestResources;
import io.takari.maven.testing.executor.MavenExecution;
import io.takari.maven.testing.executor.MavenExecutionResult;
import io.takari.maven.testing.executor.MavenRuntime;
import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;

@RunWith( MavenJUnitTestRunner.class )
@MavenVersions( { "3.2.5" } )
public class WagonMojoFtpBasicTest
public class WagonMojoFtpBasicIT
{
@Rule
public final TestResources resources = new TestResources();

public final MavenRuntime maven;
public final FtpServer ftpServer;

public WagonMojoFtpBasicTest( MavenRuntimeBuilder builder )
public WagonMojoFtpBasicIT( MavenRuntimeBuilder builder )
throws Exception
{
this.ftpServer = createFtp();
Expand All @@ -60,9 +58,9 @@ public void testFtpBasic()
MavenExecution mavenExec = maven.forProject( projDir );
MavenExecutionResult result = mavenExec.execute( "clean", "verify" );
result.assertErrorFreeLog();
Assert.assertTrue( new File( result.getBasedir(), "target/it/WagonMojoFtpBasicTest.class" ).exists() );
Assert.assertTrue( new File( result.getBasedir(), "target/it/single-dir/WagonMojoFtpBasicTest.class" ).exists() );
Assert.assertTrue( new File( result.getBasedir(), "target/it/single-dir/WagonMojoHttpTest.class" ).exists() );
Assert.assertTrue( new File( result.getBasedir(), "target/it/" + this.getClass().getSimpleName() + ".class" ).exists() );
Assert.assertTrue( new File( result.getBasedir(), "target/it/single-dir/"+ this.getClass().getSimpleName() + ".class" ).exists() );
Assert.assertTrue( new File( result.getBasedir(), "target/it/single-dir/" + this.getClass().getSimpleName() + ".class" ).exists() );

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package org.codehaus.mojo.wagon;

import java.io.File;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static java.util.Objects.requireNonNull;

import io.takari.maven.testing.TestResources;
import io.takari.maven.testing.executor.MavenExecution;
Expand All @@ -14,20 +9,36 @@
import io.takari.maven.testing.executor.MavenRuntime.MavenRuntimeBuilder;
import io.takari.maven.testing.executor.MavenVersions;
import io.takari.maven.testing.executor.junit.MavenJUnitTestRunner;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith( MavenJUnitTestRunner.class )
@MavenVersions( { "3.2.5" } )
public class WagonMojoHttpTest
public class WagonMojoHttpIT extends AbstractJettyIT
{
@Rule
public final TestResources resources = new TestResources();
private final MavenRuntimeBuilder mavenBuilder;

public final MavenRuntime maven;
public MavenRuntime maven;

public WagonMojoHttpTest( MavenRuntimeBuilder builder )
public WagonMojoHttpIT( MavenRuntimeBuilder builder )
throws Exception
{
this.maven = builder.withCliOptions( "-B" ).build();
this.mavenBuilder = builder.withCliOptions( "-B" );
}

@Before
public void setPort() throws Exception {
this.maven = this.mavenBuilder.withCliOptions( "-Dserver.port=" + getServerPort() ).build();
}

@Test
Expand All @@ -41,6 +52,12 @@ public void testDownload()
result.assertErrorFreeLog();

Assert.assertTrue( new File( result.getBasedir(),
"target/it/http-download/1.1/commons-dbutils-1.1-sources.jar" ).exists() );
"target/it/http-download/1.1/commons-dbutils-1.1-sources.txt" ).exists() );
}

@Override
protected Path getDirectoryToServe() throws IOException {
return resources.getBasedir("http-download").toPath()
.resolve("files");
}
}
Loading