Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.SimpleDateFormat;

import org.apache.maven.wagon.observers.ChecksumObserver;
import org.apache.maven.wagon.resource.Resource;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -71,14 +72,9 @@ public void testFailedGetToStream() throws Exception {

destFile.deleteOnExit();

OutputStream stream = null;

try {
stream = new FileOutputStream(destFile);
try (OutputStream stream = new FileOutputStream(destFile)) {
wagon.getToStream("fubar.txt", stream);
fail("File was found when it shouldn't have been");
stream.close();
stream = null;
} catch (ResourceDoesNotExistException e) {
// expected
assertTrue(true);
Expand All @@ -87,8 +83,6 @@ public void testFailedGetToStream() throws Exception {

wagon.disconnect();

IOUtil.close(stream);

tearDownWagonTestingFixtures();
}
}
Expand Down Expand Up @@ -163,13 +157,10 @@ public void testFailedGetIfNewerToStream() throws Exception {
wagon.connect(testRepository, getAuthInfo());
destFile = FileTestUtils.createUniqueFile(getName(), getName());
destFile.deleteOnExit();
OutputStream stream = null;
try {
stream = new FileOutputStream(destFile);

try (OutputStream stream = new FileOutputStream(destFile)) {
wagon.getIfNewerToStream("fubar.txt", stream, 0);
fail("File was found when it shouldn't have been");
stream.close();
stream = null;
} catch (ResourceDoesNotExistException e) {
// expected
assertTrue(true);
Expand All @@ -178,8 +169,6 @@ public void testFailedGetIfNewerToStream() throws Exception {

wagon.disconnect();

IOUtil.close(stream);

tearDownWagonTestingFixtures();
}
}
Expand All @@ -202,22 +191,22 @@ protected void streamRoundTripTesting() throws Exception {

assertEquals("6b144b7285ffd6b0bc8300da162120b9", checksumObserver.getActualChecksum(), "compare checksums");

// Now compare the conents of the artifact that was placed in
// Now compare the contents of the artifact that was placed in
// the repository with the contents of the artifact that was
// retrieved from the repository.

String sourceContent = FileUtils.fileRead(sourceFile);
byte[] sourceContent = Files.readAllBytes(sourceFile.toPath());

String destContent = FileUtils.fileRead(destFile);
byte[] destContent = Files.readAllBytes(destFile.toPath());

assertEquals(sourceContent, destContent);
assertArrayEquals(sourceContent, destContent);
}

private int putStream() throws Exception {
String content = "test-resource.txt\n";
sourceFile = new File(FileTestUtils.getTestOutputDir(), "test-resource");
sourceFile.getParentFile().mkdirs();
FileUtils.fileWrite(sourceFile.getAbsolutePath(), content);
Files.write(sourceFile.toPath().toAbsolutePath(), content.getBytes(StandardCharsets.UTF_8));

StreamingWagon wagon = (StreamingWagon) getWagon();

Expand All @@ -227,17 +216,10 @@ private int putStream() throws Exception {

connectWagon(wagon);

InputStream stream = null;

try {
stream = new FileInputStream(sourceFile);
try (InputStream stream = new FileInputStream(sourceFile)) {
wagon.putFromStream(stream, resource, sourceFile.length(), sourceFile.lastModified());
stream.close();
stream = null;
} catch (Exception e) {
logger.error("error while putting resources to the FTP Server", e);
} finally {
IOUtil.close(stream);
}

disconnectWagon(wagon);
Expand All @@ -258,17 +240,10 @@ private void getStream(int expectedSize) throws Exception {

connectWagon(wagon);

OutputStream stream = null;

try {
stream = new FileOutputStream(destFile);
try (OutputStream stream = new FileOutputStream(destFile)) {
wagon.getToStream(this.resource, stream);
stream.close();
stream = null;
} catch (Exception e) {
logger.error("error while reading resources from the FTP Server", e);
} finally {
IOUtil.close(stream);
}

disconnectWagon(wagon);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -56,6 +57,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -132,22 +134,22 @@
private String testName;

/** Replaces TestCase.getName(), which the subclasses use to build unique file names. */
protected final String getName() {

Check warning on line 137 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

return testName;
}

/** Was inherited from PlexusTestCase; plexus-testing keeps it on PlexusExtension. */
protected static File getTestFile(String path) {

Check warning on line 142 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

Check warning on line 142 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

no @PARAM for path
return PlexusExtension.getTestFile(path);
}

/** Was inherited from PlexusTestCase; plexus-testing keeps it on PlexusExtension. */
protected static String getTestPath(String path) {

Check warning on line 147 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

Check warning on line 147 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

no @PARAM for path
return PlexusExtension.getTestPath(path);
}

/** Was inherited from PlexusTestCase; plexus-testing keeps it on PlexusExtension. */
protected static String getBasedir() {

Check warning on line 152 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

return PlexusExtension.getBasedir();
}

Expand Down Expand Up @@ -176,7 +178,7 @@
* URL of the repository. For a complete test it should point to a non existing folder so we also check for the
* creation of new folders in the remote site. <p/> return the URL of the repository as specified by Wagon syntax
*/
protected abstract String getTestRepositoryUrl() throws IOException;

Check warning on line 181 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1


/**
* Protocol id of the Wagon to use, eg. <code>scp</code>, <code>ftp</code>
Expand All @@ -201,7 +203,7 @@
// Create the test repository for the wagon we are testing.
// ----------------------------------------------------------------------

testRepository = new Repository();

Check warning on line 206 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

Check warning on line 206 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

Check warning on line 206 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

Check warning on line 206 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

Check warning on line 206 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

testRepository.setUrl(getTestRepositoryUrl());

Expand Down Expand Up @@ -371,9 +373,9 @@
// the repository with the contents of the artifact that was
// retrieved from the repository.

String sourceContent = FileUtils.fileRead(sourceFile);
String destContent = FileUtils.fileRead(destFile);
assertEquals(sourceContent, destContent);
byte[] sourceContent = Files.readAllBytes(sourceFile.toPath());
byte[] destContent = Files.readAllBytes(destFile.toPath());
assertArrayEquals(sourceContent, destContent);
} else {
assertNull(checksumObserver.getActualChecksum(), "check checksum is null");

Expand Down Expand Up @@ -624,7 +626,7 @@
private void writeTestFile(String child) throws IOException {
File dir = new File(sourceFile, child);
dir.getParentFile().mkdirs();
FileUtils.fileWrite(dir.getAbsolutePath(), child);
Files.write(dir.toPath().toAbsolutePath(), child.getBytes());
}

@Test
Expand Down Expand Up @@ -835,7 +837,7 @@
protected void putFile(String resourceName, String testFileName, String content) throws Exception {
sourceFile = new File(FileTestUtils.getTestOutputDir(), testFileName);
sourceFile.getParentFile().mkdirs();
FileUtils.fileWrite(sourceFile.getAbsolutePath(), content);
Files.write(sourceFile.toPath().toAbsolutePath(), content.getBytes());

Wagon wagon = getWagon();

Expand Down Expand Up @@ -990,15 +992,13 @@

assertEquals(TEST_CKSUM, checksumObserver.getActualChecksum(), "compare checksums");

// Now compare the conents of the artifact that was placed in
// Now compare the contents of the artifact that was placed in
// the repository with the contents of the artifact that was
// retrieved from the repository.

String sourceContent = FileUtils.fileRead(sourceFile);

String destContent = FileUtils.fileRead(destFile);

assertEquals(sourceContent, destContent);
byte[] sourceContent = Files.readAllBytes(sourceFile.toPath());
byte[] destContent = Files.readAllBytes(destFile.toPath());
assertArrayEquals(sourceContent, destContent);
}

// ----------------------------------------------------------------------
Expand All @@ -1010,7 +1010,7 @@

path.mkdirs();

Repository repository = new Repository();

Check warning on line 1013 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

Check warning on line 1013 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

Check warning on line 1013 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

Check warning on line 1013 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

Check warning on line 1013 in wagon-provider-test/src/main/java/org/apache/maven/wagon/WagonTestCase.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

Repository() in org.apache.maven.wagon.repository.Repository has been deprecated

repository.setUrl(url);

Expand Down
Loading
Loading