Skip to content

Commit

Permalink
[SSHD-1041] Avoid overlapping test source (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored Jul 27, 2020
1 parent e8abc36 commit fb64ae5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,12 @@ public static Path resolve(Path root, Collection<String> children) {
* @see #detectTargetFolder(Path)
*/
public static Path detectTargetFolder(Class<?> anchor) {
return detectTargetFolder(getClassContainerLocationPath(anchor));
Path path = detectTargetFolder(getClassContainerLocationPath(anchor));
if (path == null) {
String basedir = System.getProperty("basedir");
path = detectTargetFolder(Paths.get(basedir, "target"));
}
return path;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.Key;
import java.security.KeyPair;
import java.security.interfaces.DSAParams;
Expand Down Expand Up @@ -201,12 +198,9 @@ protected Path detectSourcesFolder() throws IllegalStateException {
}

protected Path getTestResourcesFolder() {
try {
URL url = getClass().getResource(getClass().getSimpleName() + ".class");
return Paths.get(url.toURI()).getParent();
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Path target = detectTargetFolder();
String pkgFolder = getClass().getPackage().getName().replace('.', File.separatorChar);
return target.resolve("test-classes").resolve(pkgFolder);
}

protected Path getClassResourcesFolder(String resType /* test or main */) {
Expand Down
24 changes: 22 additions & 2 deletions sshd-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@
<optional>true</optional>
</dependency>

<!-- For ed25519 support -->
<!-- For ed25519 support -->
<dependency>
<groupId>net.i2p.crypto</groupId>
<artifactId>eddsa</artifactId>
<optional>true</optional>
</dependency>

<!-- test dependencies -->
<!-- test dependencies -->
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-common</artifactId>
Expand Down Expand Up @@ -153,6 +153,7 @@
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>small-test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
Expand All @@ -164,6 +165,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>big-test-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<classifier>reusable-tests</classifier>
<finalName>${project.build.finalName}-reusable</finalName>
<excludes>
<exclude>org/apache/sshd/util/test/**/*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
6 changes: 2 additions & 4 deletions sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Deque;
import java.util.EnumSet;
Expand All @@ -42,6 +40,7 @@
import org.apache.sshd.common.io.WritePendingException;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.common.util.io.IoUtils;
import org.apache.sshd.common.util.io.NoCloseOutputStream;
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
import org.apache.sshd.common.util.threads.ThreadUtils;
Expand Down Expand Up @@ -85,8 +84,7 @@ public WindowAdjustTest() {
public void setUp() throws Exception {
sshServer = setupTestServer();

byte[] msg = Files.readAllBytes(
Paths.get(getClass().getResource("/big-msg.txt").toURI()));
byte[] msg = IoUtils.toByteArray(getClass().getResourceAsStream("/big-msg.txt"));
sshServer.setShellFactory(
channel -> new FloodingAsyncCommand(msg, BIG_MSG_SEND_COUNT, END_FILE));

Expand Down
48 changes: 13 additions & 35 deletions sshd-mina/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-core</artifactId>
<version>${project.version}</version>
<classifier>reusable-tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.sshd</groupId>
<artifactId>sshd-common</artifactId>
Expand Down Expand Up @@ -120,40 +128,6 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${projectRoot}/sshd-core/src/test/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-resource</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${projectRoot}/sshd-core/src/test/resources</directory>
<targetPath>${project.build.testOutputDirectory}</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand All @@ -179,8 +153,12 @@
<exclude>**/AsyncAuthTest.java</exclude>
<exclude>**/AsyncAuthInteractiveTest.java</exclude>
</excludes>
<!-- No need to re-run core tests that do not involve session creation -->
<!-- No need to re-run core tests that do not involve session creation -->
<excludedGroups>org.apache.sshd.util.test.NoIoTestCase</excludedGroups>
<!-- Tests are located in the sshd-core reusable test jar -->
<dependenciesToScan>
<dependency>org.apache.sshd:sshd-core</dependency>
</dependenciesToScan>
</configuration>
</plugin>
<plugin>
Expand Down
38 changes: 4 additions & 34 deletions sshd-netty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,40 +136,6 @@

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${projectRoot}/sshd-core/src/test/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-resource</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${projectRoot}/sshd-core/src/test/resources</directory>
<targetPath>${project.build.testOutputDirectory}</targetPath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -207,6 +173,10 @@
</excludes>
<!-- No need to re-run core tests that do not involve session creation -->
<excludedGroups>org.apache.sshd.util.test.NoIoTestCase</excludedGroups>
<!-- Tests are located in the sshd-core reusable test jar -->
<dependenciesToScan>
<dependency>org.apache.sshd:sshd-core</dependency>
</dependenciesToScan>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit fb64ae5

Please sign in to comment.